From: Jens Axboe Date: Tue, 8 Nov 2005 19:10:13 +0000 (+0100) Subject: [PATCH] drivescan/misc: arch stuff X-Git-Url: https://git.kernel.dk/?a=commitdiff_plain;h=6b2a251b4ffd5e039cdc18f14dd92c182d17fb9b;p=disktools.git [PATCH] drivescan/misc: arch stuff --- diff --git a/arch-alpha.h b/arch-alpha.h index 84eea86..49c7b1b 100644 --- a/arch-alpha.h +++ b/arch-alpha.h @@ -1,6 +1,10 @@ #ifndef ARCH_ALPHA_H #define ARCH_ALPHA_H +static int arch = arch_alpha; + +#define BITS_PER_LONG (64) + #ifndef __NR_ioprio_set #define __NR_ioprio_set 442 #define __NR_ioprio_get 443 diff --git a/arch-ia64.h b/arch-ia64.h index af9f649..ea6d7dd 100644 --- a/arch-ia64.h +++ b/arch-ia64.h @@ -1,6 +1,10 @@ #ifndef ARCH_IA64_H #define ARCH_IA64_H +static int arch = arch_ia64; + +#define BITS_PER_LONG (64) + #ifndef __NR_ioprio_set #define __NR_ioprio_set 1274 #define __NR_ioprio_get 1275 diff --git a/arch-ppc.h b/arch-ppc.h index e822027..a5c6a59 100644 --- a/arch-ppc.h +++ b/arch-ppc.h @@ -1,6 +1,10 @@ #ifndef ARCH_PPC_H #define ARCH_PPH_H +static int arch = arch_ppc; + +#define BITS_PER_LONG (32) + #ifndef __NR_ioprio_set #define __NR_ioprio_set 273 #define __NR_ioprio_get 274 diff --git a/arch-s390.h b/arch-s390.h index 4616ed0..54d9354 100644 --- a/arch-s390.h +++ b/arch-s390.h @@ -1,6 +1,10 @@ #ifndef ARCH_S390_H #define ARCH_S390_H +static int arch = arch_s390; + +#define BITS_PER_LONG (64) + #ifndef __NR_ioprio_set #define __NR_ioprio_set 282 #define __NR_ioprio_get 283 diff --git a/arch-x86.h b/arch-x86.h index 39b77cc..483e60c 100644 --- a/arch-x86.h +++ b/arch-x86.h @@ -1,6 +1,9 @@ #ifndef ARCH_X86_H #define ARCH_X86_H +static int arch = arch_i386; + +#define BITS_PER_LONG (32) #ifndef __NR_ioprio_set #define __NR_ioprio_set 289 diff --git a/arch-x86_64.h b/arch-x86_64.h index aca1385..2ef5365 100644 --- a/arch-x86_64.h +++ b/arch-x86_64.h @@ -1,6 +1,10 @@ #ifndef ARCH_X86_64_h #define ARCH_X86_64_h +static int arch = arch_x86_64; + +#define BITS_PER_LONG (64) + #ifndef __NR_ioprio_set #define __NR_ioprio_set 251 #define __NR_ioprio_get 252 diff --git a/arch.h b/arch.h index 3288416..c6adf41 100644 --- a/arch.h +++ b/arch.h @@ -1,6 +1,15 @@ #ifndef ARCH_H #define ARCH_H +enum { + arch_x86_64, + arch_i386, + arch_ppc, + arch_ia64, + arch_s390, + arch_alpha, +}; + #if defined(__i386__) #include "arch-x86.h" #elif defined(__x86_64__) diff --git a/drivescan.c b/drivescan.c index 3d10df7..e4299ed 100644 --- a/drivescan.c +++ b/drivescan.c @@ -18,62 +18,7 @@ #include #include -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;