2 This file is a part of libcds - Concurrent Data Structures library
4 (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2017
6 Source code repo: http://github.com/khizmax/libcds/
7 Download: http://sourceforge.net/projects/libcds/files/
9 Redistribution and use in source and binary forms, with or without
10 modification, are permitted provided that the following conditions are met:
12 * Redistributions of source code must retain the above copyright notice, this
13 list of conditions and the following disclaimer.
15 * Redistributions in binary form must reproduce the above copyright notice,
16 this list of conditions and the following disclaimer in the documentation
17 and/or other materials provided with the distribution.
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #ifndef CDSLIB_COMPILER_VC_AMD64_BITOP_H
32 #define CDSLIB_COMPILER_VC_AMD64_BITOP_H
37 math.h(136) : warning C4985: 'ceil': attributes not present on previous declaration.
38 intrin.h(142) : see declaration of 'ceil'
40 See http://connect.microsoft.com/VisualStudio/feedback/details/381422/warning-of-attributes-not-present-on-previous-declaration-on-ceil-using-both-math-h-and-intrin-h
42 # pragma warning(push)
43 # pragma warning(disable: 4985)
50 #pragma intrinsic(_BitScanReverse)
51 #pragma intrinsic(_BitScanForward)
52 #pragma intrinsic(_BitScanReverse64)
53 #pragma intrinsic(_BitScanForward64)
57 namespace bitop { namespace platform { namespace vc { namespace amd64 {
59 // MSB - return index (1..32) of most significant bit in nArg. If nArg == 0 return 0
60 # define cds_bitop_msb32_DEFINED
61 static inline int msb32( uint32_t nArg )
64 if ( _BitScanReverse( &nIndex, nArg ))
65 return (int) nIndex + 1;
69 # define cds_bitop_msb32nz_DEFINED
70 static inline int msb32nz( uint32_t nArg )
74 _BitScanReverse( &nIndex, nArg );
78 // LSB - return index (1..32) of least significant bit in nArg. If nArg == 0 return -1U
79 # define cds_bitop_lsb32_DEFINED
80 static inline int lsb32( uint32_t nArg )
83 if ( _BitScanForward( &nIndex, nArg ))
84 return (int) nIndex + 1;
88 # define cds_bitop_lsb32nz_DEFINED
89 static inline int lsb32nz( uint32_t nArg )
93 _BitScanForward( &nIndex, nArg );
98 # define cds_bitop_msb64_DEFINED
99 static inline int msb64( uint64_t nArg )
101 unsigned long nIndex;
102 if ( _BitScanReverse64( &nIndex, nArg ))
103 return (int) nIndex + 1;
107 # define cds_bitop_msb64nz_DEFINED
108 static inline int msb64nz( uint64_t nArg )
111 unsigned long nIndex;
112 _BitScanReverse64( &nIndex, nArg );
116 # define cds_bitop_lsb64_DEFINED
117 static inline int lsb64( uint64_t nArg )
119 unsigned long nIndex;
120 if ( _BitScanForward64( &nIndex, nArg ))
121 return (int) nIndex + 1;
125 # define cds_bitop_lsb64nz_DEFINED
126 static inline int lsb64nz( uint64_t nArg )
129 unsigned long nIndex;
130 _BitScanForward64( &nIndex, nArg );
134 # define cds_bitop_complement32_DEFINED
135 static inline bool complement32( uint32_t * pArg, unsigned int nBit )
137 return _bittestandcomplement( reinterpret_cast<long *>( pArg ), nBit ) != 0;
140 # define cds_bitop_complement64_DEFINED
141 static inline bool complement64( uint64_t * pArg, unsigned int nBit )
143 return _bittestandcomplement64( reinterpret_cast<__int64 *>( pArg ), nBit ) != 0;
147 }} // namespace vc::amd64
149 using namespace vc::amd64;
151 }}} // namespace cds::bitop::platform
154 #endif // #ifndef CDSLIB_COMPILER_VC_AMD64_BITOP_H