Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(126)

Side by Side Diff: mozilla/nsprpub/pr/include/prbit.h

Issue 14249009: Change the NSS and NSPR source tree to the new directory structure to be (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/nss/
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « mozilla/nsprpub/pr/include/pratom.h ('k') | mozilla/nsprpub/pr/include/prclist.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
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/. */
5
6 #ifndef prbit_h___
7 #define prbit_h___
8
9 #include "prtypes.h"
10 PR_BEGIN_EXTERN_C
11
12 /* replace compare/jump/add/shift sequence with x86 BSF/BSR instruction */
13 #if defined(_WIN32) && (_MSC_VER >= 1300) && (defined(_M_IX86) || defined(_M_AMD 64))
14 unsigned char _BitScanForward(unsigned long * Index, unsigned long Mask);
15 unsigned char _BitScanReverse(unsigned long * Index, unsigned long Mask);
16 # pragma intrinsic(_BitScanForward,_BitScanReverse)
17 __forceinline static int __prBitScanForward32(unsigned int val)
18 {
19 unsigned long idx;
20 _BitScanForward(&idx, (unsigned long)val);
21 return( (int)idx );
22 }
23 __forceinline static int __prBitScanReverse32(unsigned int val)
24 {
25 unsigned long idx;
26 _BitScanReverse(&idx, (unsigned long)val);
27 return( (int)(31-idx) );
28 }
29 # define pr_bitscan_ctz32(val) __prBitScanForward32(val)
30 # define pr_bitscan_clz32(val) __prBitScanReverse32(val)
31 # define PR_HAVE_BUILTIN_BITSCAN32
32 #elif ((__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) && \
33 (defined(__i386__) || defined(__x86_64__) || defined(__arm__))
34 # define pr_bitscan_ctz32(val) __builtin_ctz(val)
35 # define pr_bitscan_clz32(val) __builtin_clz(val)
36 # define PR_HAVE_BUILTIN_BITSCAN32
37 #endif /* MSVC || GCC */
38
39 /*
40 ** A prbitmap_t is a long integer that can be used for bitmaps
41 */
42 typedef unsigned long prbitmap_t;
43
44 #define PR_TEST_BIT(_map,_bit) \
45 ((_map)[(_bit)>>PR_BITS_PER_LONG_LOG2] & (1L << ((_bit) & (PR_BITS_PER_LONG- 1))))
46 #define PR_SET_BIT(_map,_bit) \
47 ((_map)[(_bit)>>PR_BITS_PER_LONG_LOG2] |= (1L << ((_bit) & (PR_BITS_PER_LONG -1))))
48 #define PR_CLEAR_BIT(_map,_bit) \
49 ((_map)[(_bit)>>PR_BITS_PER_LONG_LOG2] &= ~(1L << ((_bit) & (PR_BITS_PER_LON G-1))))
50
51 /*
52 ** Compute the log of the least power of 2 greater than or equal to n
53 */
54 NSPR_API(PRIntn) PR_CeilingLog2(PRUint32 i);
55
56 /*
57 ** Compute the log of the greatest power of 2 less than or equal to n
58 */
59 NSPR_API(PRIntn) PR_FloorLog2(PRUint32 i);
60
61 /*
62 ** Macro version of PR_CeilingLog2: Compute the log of the least power of
63 ** 2 greater than or equal to _n. The result is returned in _log2.
64 */
65 #ifdef PR_HAVE_BUILTIN_BITSCAN32
66 #define PR_CEILING_LOG2(_log2,_n) \
67 PR_BEGIN_MACRO \
68 PRUint32 j_ = (PRUint32)(_n); \
69 (_log2) = (j_ <= 1 ? 0 : 32 - pr_bitscan_clz32(j_ - 1)); \
70 PR_END_MACRO
71 #else
72 #define PR_CEILING_LOG2(_log2,_n) \
73 PR_BEGIN_MACRO \
74 PRUint32 j_ = (PRUint32)(_n); \
75 (_log2) = 0; \
76 if ((j_) & ((j_)-1)) \
77 (_log2) += 1; \
78 if ((j_) >> 16) \
79 (_log2) += 16, (j_) >>= 16; \
80 if ((j_) >> 8) \
81 (_log2) += 8, (j_) >>= 8; \
82 if ((j_) >> 4) \
83 (_log2) += 4, (j_) >>= 4; \
84 if ((j_) >> 2) \
85 (_log2) += 2, (j_) >>= 2; \
86 if ((j_) >> 1) \
87 (_log2) += 1; \
88 PR_END_MACRO
89 #endif /* PR_HAVE_BUILTIN_BITSCAN32 */
90
91 /*
92 ** Macro version of PR_FloorLog2: Compute the log of the greatest power of
93 ** 2 less than or equal to _n. The result is returned in _log2.
94 **
95 ** This is equivalent to finding the highest set bit in the word.
96 */
97 #ifdef PR_HAVE_BUILTIN_BITSCAN32
98 #define PR_FLOOR_LOG2(_log2,_n) \
99 PR_BEGIN_MACRO \
100 PRUint32 j_ = (PRUint32)(_n); \
101 (_log2) = 31 - pr_bitscan_clz32((j_) | 1); \
102 PR_END_MACRO
103 #else
104 #define PR_FLOOR_LOG2(_log2,_n) \
105 PR_BEGIN_MACRO \
106 PRUint32 j_ = (PRUint32)(_n); \
107 (_log2) = 0; \
108 if ((j_) >> 16) \
109 (_log2) += 16, (j_) >>= 16; \
110 if ((j_) >> 8) \
111 (_log2) += 8, (j_) >>= 8; \
112 if ((j_) >> 4) \
113 (_log2) += 4, (j_) >>= 4; \
114 if ((j_) >> 2) \
115 (_log2) += 2, (j_) >>= 2; \
116 if ((j_) >> 1) \
117 (_log2) += 1; \
118 PR_END_MACRO
119 #endif /* PR_HAVE_BUILTIN_BITSCAN32 */
120
121 /*
122 ** Macros for rotate left and right. The argument 'a' must be an unsigned
123 ** 32-bit integer type such as PRUint32.
124 **
125 ** There is no rotate operation in the C Language, so the construct
126 ** (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.
128 ** 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.
130 **
131 ** Note: MSVC in VS2005 will do an inline rotate instruction on the above
132 ** construct.
133 */
134
135 #if defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_AMD64) || \
136 defined(_M_X64))
137 #include <stdlib.h>
138 #pragma intrinsic(_rotl, _rotr)
139 #define PR_ROTATE_LEFT32(a, bits) _rotl(a, bits)
140 #define PR_ROTATE_RIGHT32(a, bits) _rotr(a, bits)
141 #else
142 #define PR_ROTATE_LEFT32(a, bits) (((a) << (bits)) | ((a) >> (32 - (bits))))
143 #define PR_ROTATE_RIGHT32(a, bits) (((a) >> (bits)) | ((a) << (32 - (bits))))
144 #endif
145
146 PR_END_EXTERN_C
147 #endif /* prbit_h___ */
OLDNEW
« no previous file with comments | « mozilla/nsprpub/pr/include/pratom.h ('k') | mozilla/nsprpub/pr/include/prclist.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698