64e21e1cf1a71e4c9cad4e42784be32287a36121
[libcds.git] / cds / compiler / gcc / ia64 / bitop.h
1 //$$CDS-header$$
2
3 #ifndef __CDS_COMPILER_GCC_IA64_BITOP_H
4 #define __CDS_COMPILER_GCC_IA64_BITOP_H
5
6 //@cond none
7 namespace cds {
8     namespace bitop { namespace platform { namespace gcc { namespace ia64 {
9
10         // MSB - return index (1..32) of most significant bit in x. If x == 0 return 0
11 #        define cds_bitop_msb32_DEFINED
12         static inline int msb32( atomic32u_t nArg )
13         {
14             if ( !nArg )
15                 return 0;
16             atomic64u_t x = nArg;
17             x |= x >> 1;
18             x |= x >> 2;
19             x |= x >> 4;
20             x |= x >> 8;
21             x |= x >> 16;
22
23             atomic64u_t    nRes;
24             asm __volatile__( "popcnt %0=%1\n\t" : "=r" (nRes) : "r" (x) );
25             return (int) nRes;
26         }
27
28         // It is not compiled on HP-UX. Why?..
29 #if CDS_OS_TYPE != CDS_OS_HPUX
30         // MSB - return index (0..31) of most significant bit in nArg.
31         // !!! nArg != 0
32 #        define cds_bitop_msb32nz_DEFINED
33         static inline int msb32nz( atomic32u_t nArg )
34         {
35             assert( nArg != 0 );
36             long double d = nArg;
37             long nExp;
38             asm __volatile__("getf.exp %0=%1\n\t" : "=r"(nExp) : "f"(d));
39             return (int) (nExp - 0xffff);
40         }
41
42         // MSB - return index (0..63) of most significant bit in nArg.
43         // !!! nArg != 0
44 #        define cds_bitop_msb64nz_DEFINED
45         static inline int msb64nz( atomic64u_t nArg )
46         {
47             assert( nArg != 0 );
48             long double d = nArg;
49             long nExp;
50             asm __volatile__("getf.exp %0=%1\n\t" : "=r" (nExp) : "f" (d));
51             return (int) (nExp - 0xffff);
52         }
53 #endif    // #if CDS_OS_TYPE != CDS_OS_HPUX
54
55     }} // namespace gcc::ia64
56
57     using namespace gcc::ia64;
58
59 }}}    // namespace cds::bitop::platform
60 //@endcond
61
62 #endif // #ifndef __CDS_COMPILER_GCC_IA64_BITOP_H