]> git.proxmox.com Git - mirror_spl.git/commitdiff
Add functions and macros as used upstream.
authorTim Chase <tim@chase2k.com>
Sun, 27 Apr 2014 01:56:03 +0000 (20:56 -0500)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Tue, 22 Jul 2014 16:47:48 +0000 (09:47 -0700)
Added highbit64() and howmany() which are used in recent upstream
code.  Both highbit() and highbit64() should at some point be
re-factored to use the optimized fls() and fls64() functions.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Prakash Surya <surya1@llnl.gov>
Signed-off-by: Tim Chase <tim@chase2k.com>
Closes #363

include/sys/sysmacros.h
module/spl/spl-generic.c

index e73c7fd1e89f3c9afac177d73f6ed2216f8c9601..565fc5600043c7264de121425d3667d3970b9865 100644 (file)
@@ -150,6 +150,7 @@ extern unsigned long spl_hostid;
 
 /* Missing misc functions */
 extern int highbit(unsigned long i);
+extern int highbit64(uint64_t i);
 extern uint32_t zone_get_hostid(void *zone);
 extern void spl_setup(void);
 extern void spl_cleanup(void);
@@ -172,6 +173,9 @@ extern void spl_cleanup(void);
 #ifndef roundup
 #define roundup(x, y)          ((((x) + ((y) - 1)) / (y)) * (y))
 #endif
+#ifndef howmany
+#define howmany(x, y)          (((x) + ((y) - 1)) / (y))
+#endif
 
 /*
  * Compatibility macros/typedefs needed for Solaris -> Linux port
index 4f0842b1a069aa933ff14b350c4ad6a890c03cd6..6cb73ddb70e3d991adb37db5385218bf6b6634fc 100644 (file)
@@ -97,6 +97,36 @@ highbit(unsigned long i)
 }
 EXPORT_SYMBOL(highbit);
 
+int
+highbit64(uint64_t i)
+{
+        register int h = 1;
+        SENTRY;
+
+        if (i == 0)
+                SRETURN(0);
+        if (i & 0xffffffff00000000ull) {
+                h += 32; i >>= 32;
+        }
+        if (i & 0xffff0000) {
+                h += 16; i >>= 16;
+        }
+        if (i & 0xff00) {
+                h += 8; i >>= 8;
+        }
+        if (i & 0xf0) {
+                h += 4; i >>= 4;
+        }
+        if (i & 0xc) {
+                h += 2; i >>= 2;
+        }
+        if (i & 0x2) {
+                h += 1;
+        }
+        SRETURN(h);
+}
+EXPORT_SYMBOL(highbit64);
+
 #if BITS_PER_LONG == 32
 /*
  * Support 64/64 => 64 division on a 32-bit platform.  While the kernel