#include <sys/time.h>
#include <sys/stat.h>
-enum {
- arch_x86_64,
- arch_i386,
- arch_ppc,
- arch_ia64,
-};
-
-#if defined(__x86_64)
-#define BITS_PER_LONG 64
-static int arch = arch_x86_64;
-inline unsigned long ffz(unsigned long bitmask)
-{
- __asm__("bsfq %1,%0" :"=r" (bitmask) :"r" (~bitmask));
- return bitmask;
-}
-#elif defined (__i386__)
-#define BITS_PER_LONG 32
-static int arch = arch_i386;
-inline unsigned long ffz(unsigned long bitmask)
-{
- __asm__("bsfl %1,%0" :"=r" (bitmask) :"r" (~bitmask));
- return bitmask;
-}
-#elif defined (__powerpc__)
-#define BITS_PER_LONG 32
-static int arch = arch_ppc;
-inline int __ilog2(unsigned long bitmask)
-{
- int lz;
-
- asm ("cntlzw %0,%1" : "=r" (lz) : "r" (bitmask));
- return 31 - lz;
-}
-
-static inline int ffz(unsigned long bitmask)
-{
- if ((bitmask = ~bitmask) == 0)
- return 32;
- return __ilog2(bitmask & -bitmask);
-}
-#elif defined(__ia64__)
-#define BITS_PER_LONG 64
-static int arch = arch_ia64;
-#define ia64_popcnt(x) \
-({ \
- unsigned long ia64_intri_res; \
- asm ("popcnt %0=%1" : "=r" (ia64_intri_res) : "r" (x)); \
- ia64_intri_res; \
-})
-inline unsigned long ffz(unsigned long bitmask)
-{
- return ia64_popcnt(bitmask & (~bitmask - 1));
-}
-#else
-#error "Unsupported architecture"
-#endif
+#include "arch.h"
#if BITS_PER_LONG == 32
typedef unsigned long long u64;