3 #ifndef CDSLIB_COMPILER_GCC_X86_BITOP_H
4 #define CDSLIB_COMPILER_GCC_X86_BITOP_H
8 namespace bitop { namespace platform { namespace gcc { namespace x86 {
9 // MSB - return index (1..32) of most significant bit in nArg. If nArg == 0 return 0
10 # define cds_bitop_msb32_DEFINED
11 static inline int msb32( uint32_t nArg )
14 __asm__ __volatile__ (
15 "bsrl %[nArg], %[nRet] ;\n\t"
17 "xorl %[nRet], %[nRet] ;\n\t"
18 "subl $1, %[nRet] ;\n\t"
20 "addl $1, %[nRet] ;\n\t"
28 # define cds_bitop_msb32nz_DEFINED
29 static inline int msb32nz( uint32_t nArg )
33 __asm__ __volatile__ (
34 "bsrl %[nArg], %[nRet] ;"
42 // LSB - return index (0..31) of least significant bit in nArg. If nArg == 0 return -1U
43 # define cds_bitop_lsb32_DEFINED
44 static inline int lsb32( uint32_t nArg )
48 __asm__ __volatile__ (
49 "bsfl %[nArg], %[nRet] ;"
51 "xorl %[nRet], %[nRet] ;"
63 // LSB - return index (0..31) of least significant bit in nArg.
64 // Condition: nArg != 0
65 # define cds_bitop_lsb32nz_DEFINED
66 static inline int lsb32nz( uint32_t nArg )
70 __asm__ __volatile__ (
71 "bsfl %[nArg], %[nRet] ;"
79 }} // namespace gcc::x86
81 using namespace gcc::x86;
83 }}} // namespace cds::bitop::platform
86 #endif // #ifndef CDSLIB_ARH_X86_GCC_BITOP_H