Replacing some integral typedefs with standard types
[libcds.git] / cds / compiler / gcc / sparc / bitop.h
1 //$$CDS-header$$
2
3 #ifndef __CDS_COMPILER_GCC_SPARC_BITOP_H
4 #define __CDS_COMPILER_GCC_SPARC_BITOP_H
5
6 //@cond none
7 namespace cds {
8     namespace bitop { namespace platform { namespace gcc { namespace Sparc {
9
10         // MSB - return index (1..64) of most significant bit in nArg. If nArg == 0 return 0
11         // Source: UltraSPARC Architecture 2007
12         //
13         // Test result: this variant and its variation about 100 times slower then generic implementation :-(
14         static inline int sparc_msb64( atomic64u_t nArg )
15         {
16             atomic64u_t result;
17             asm volatile (
18                 "neg %[nArg], %[result] \n\t"
19                 "xnor %[nArg], %[result], %%g5 \n\t"
20                 "popc %%g5, %[result] \n\t"
21                 "movrz %[nArg], %%g0, %[result] \n\t"
22                 : [result] "=r" (result)
23                 : [nArg] "r" (nArg)
24                 : "g5"
25             );
26             return result;
27         }
28
29         // MSB - return index (1..32) of most significant bit in nArg. If nArg == 0 return 0
30         static inline int sparc_msb32( uint32_t nArg )
31         {
32             return sparc_msb64( (atomic64u_t) nArg );
33         }
34
35     }} // namespace gcc::Sparc
36
37     using namespace gcc::Sparc;
38
39 }}}    // namespace cds::bitop::platform
40 //@endcond
41
42 #endif // #ifndef __CDS_COMPILER_GCC_SPARC_BITOP_H