| OLD | NEW |
| 1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ | 1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
| 2 /* This Source Code Form is subject to the terms of the Mozilla Public | 2 /* This Source Code Form is subject to the terms of the Mozilla Public |
| 3 * License, v. 2.0. If a copy of the MPL was not distributed with this | 3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 5 | 5 |
| 6 #ifndef prbit_h___ | 6 #ifndef prbit_h___ |
| 7 #define prbit_h___ | 7 #define prbit_h___ |
| 8 | 8 |
| 9 #include "prtypes.h" | 9 #include "prtypes.h" |
| 10 PR_BEGIN_EXTERN_C | 10 PR_BEGIN_EXTERN_C |
| 11 | 11 |
| 12 /* replace compare/jump/add/shift sequence with x86 BSF/BSR instruction */ | 12 /* |
| 13 #if defined(_WIN32) && (_MSC_VER >= 1300) && (defined(_M_IX86) || defined(_M_AMD
64)) | 13 ** Replace compare/jump/add/shift sequence with compiler built-in/intrinsic |
| 14 ** functions. |
| 15 */ |
| 16 #if defined(_WIN32) && (_MSC_VER >= 1300) && \ |
| 17 (defined(_M_IX86) || defined(_M_AMD64) || defined(_M_ARM)) |
| 14 unsigned char _BitScanForward(unsigned long * Index, unsigned long Mask); | 18 unsigned char _BitScanForward(unsigned long * Index, unsigned long Mask); |
| 15 unsigned char _BitScanReverse(unsigned long * Index, unsigned long Mask); | 19 unsigned char _BitScanReverse(unsigned long * Index, unsigned long Mask); |
| 16 # pragma intrinsic(_BitScanForward,_BitScanReverse) | 20 # pragma intrinsic(_BitScanForward,_BitScanReverse) |
| 17 __forceinline static int __prBitScanForward32(unsigned int val) | 21 __forceinline static int __prBitScanForward32(unsigned int val) |
| 18 { | 22 { |
| 19 unsigned long idx; | 23 unsigned long idx; |
| 20 _BitScanForward(&idx, (unsigned long)val); | 24 _BitScanForward(&idx, (unsigned long)val); |
| 21 return( (int)idx ); | 25 return( (int)idx ); |
| 22 } | 26 } |
| 23 __forceinline static int __prBitScanReverse32(unsigned int val) | 27 __forceinline static int __prBitScanReverse32(unsigned int val) |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 ** (a << 4) | (a >> 28) is frequently used instead. Most compilers convert | 130 ** (a << 4) | (a >> 28) is frequently used instead. Most compilers convert |
| 127 ** this to a rotate instruction, but MSVC doesn't without a little help. | 131 ** this to a rotate instruction, but MSVC doesn't without a little help. |
| 128 ** To get MSVC to generate a rotate instruction, we have to use the _rotl | 132 ** To get MSVC to generate a rotate instruction, we have to use the _rotl |
| 129 ** or _rotr intrinsic and use a pragma to make it inline. | 133 ** or _rotr intrinsic and use a pragma to make it inline. |
| 130 ** | 134 ** |
| 131 ** Note: MSVC in VS2005 will do an inline rotate instruction on the above | 135 ** Note: MSVC in VS2005 will do an inline rotate instruction on the above |
| 132 ** construct. | 136 ** construct. |
| 133 */ | 137 */ |
| 134 | 138 |
| 135 #if defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_AMD64) || \ | 139 #if defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_AMD64) || \ |
| 136 defined(_M_X64)) | 140 defined(_M_X64) || defined(_M_ARM)) |
| 137 #include <stdlib.h> | 141 #include <stdlib.h> |
| 138 #pragma intrinsic(_rotl, _rotr) | 142 #pragma intrinsic(_rotl, _rotr) |
| 139 #define PR_ROTATE_LEFT32(a, bits) _rotl(a, bits) | 143 #define PR_ROTATE_LEFT32(a, bits) _rotl(a, bits) |
| 140 #define PR_ROTATE_RIGHT32(a, bits) _rotr(a, bits) | 144 #define PR_ROTATE_RIGHT32(a, bits) _rotr(a, bits) |
| 141 #else | 145 #else |
| 142 #define PR_ROTATE_LEFT32(a, bits) (((a) << (bits)) | ((a) >> (32 - (bits)))) | 146 #define PR_ROTATE_LEFT32(a, bits) (((a) << (bits)) | ((a) >> (32 - (bits)))) |
| 143 #define PR_ROTATE_RIGHT32(a, bits) (((a) >> (bits)) | ((a) << (32 - (bits)))) | 147 #define PR_ROTATE_RIGHT32(a, bits) (((a) >> (bits)) | ((a) << (32 - (bits)))) |
| 144 #endif | 148 #endif |
| 145 | 149 |
| 146 PR_END_EXTERN_C | 150 PR_END_EXTERN_C |
| 147 #endif /* prbit_h___ */ | 151 #endif /* prbit_h___ */ |
| OLD | NEW |