3 #ifndef CDSLIB_COMPILER_GCC_AMD64_BITOP_H
4 #define CDSLIB_COMPILER_GCC_AMD64_BITOP_H
8 namespace bitop { namespace platform { namespace gcc { namespace amd64 {
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 # define cds_bitop_msb64_DEFINED
80 static inline int msb64( atomic64u_unaligned nArg )
82 atomic64u_unaligned nRet;
84 "bsrq %[nArg], %[nRet] ;\n\t"
86 "xorq %[nRet], %[nRet] ;\n\t"
87 "subq $1, %[nRet] ;\n\t"
89 "addq $1, %[nRet] ;\n\t"
97 # define cds_bitop_msb64nz_DEFINED
98 static inline int msb64nz( atomic64u_unaligned nArg )
101 atomic64u_unaligned nRet;
102 __asm__ __volatile__ (
103 "bsrq %[nArg], %[nRet] ;"
111 // LSB - return index (0..31) of least significant bit in nArg. If nArg == 0 return -1U
112 # define cds_bitop_lsb64_DEFINED
113 static inline int lsb64( atomic64u_unaligned nArg )
116 atomic64u_unaligned nRet;
117 __asm__ __volatile__ (
118 "bsfq %[nArg], %[nRet] ;"
120 "xorq %[nRet], %[nRet] ;"
132 // LSB - return index (0..31) of least significant bit in nArg.
133 // Condition: nArg != 0
134 # define cds_bitop_lsb64nz_DEFINED
135 static inline int lsb64nz( atomic64u_unaligned nArg )
138 atomic64u_unaligned nRet;
139 __asm__ __volatile__ (
140 "bsfq %[nArg], %[nRet] ;"
149 }} // namespace gcc::amd64
151 using namespace gcc::amd64;
153 }}} // namespace cds::bitop::platform
157 #endif // #ifndef CDSLIB_COMPILER_GCC_AMD64_BITOP_H