Lines Matching refs:value
24 // CountPopulation(value) returns the number of bits set in |value|.
27 typename std::enable_if<std::is_unsigned<T>::value && sizeof(T) <= 8,
29 CountPopulation(T value) {
32 return sizeof(T) == 8 ? __builtin_popcountll(static_cast<uint64_t>(value))
33 : __builtin_popcount(static_cast<uint32_t>(value));
40 value = ((value >> 1) & mask[0]) + (value & mask[0]);
42 value = ((value >> 2) & mask[1]) + (value & mask[1]);
44 value = ((value >> 4) & mask[2]) + (value & mask[2]);
48 // result, so there's no need to mask value anymore, since there's no
50 if (sizeof(T) > 1) value = (value >> (sizeof(T) > 1 ? 8 : 0)) + value;
52 if (sizeof(T) > 2) value = (value >> (sizeof(T) > 2 ? 16 : 0)) + value;
54 if (sizeof(T) > 4) value = (value >> (sizeof(T) > 4 ? 32 : 0)) + value;
56 return static_cast<unsigned>(value & 0xff);
60 // ReverseBits(value) returns |value| in reverse bit order.
62 T ReverseBits(T value) {
63 STATIC_ASSERT((sizeof(value) == 1) || (sizeof(value) == 2) ||
64 (sizeof(value) == 4) || (sizeof(value) == 8));
66 for (unsigned i = 0; i < (sizeof(value) * 8); i++) {
67 result = (result << 1) | (value & 1);
68 value >>= 1;
73 // CountLeadingZeros(value) returns the number of zero bits following the most
74 // significant 1 bit in |value| if |value| is non-zero, otherwise it returns
78 typename std::enable_if<std::is_unsigned<T>::value && sizeof(T) <= 8,
80 CountLeadingZeros(T value) {
83 return value == 0
86 ? __builtin_clzll(static_cast<uint64_t>(value))
87 : __builtin_clz(static_cast<uint32_t>(value)) - (32 - bits);
91 if (bits == 1) return static_cast<unsigned>(value) ^ 1;
92 T upper_half = value >> (bits / 2);
93 T next_value = upper_half != 0 ? upper_half : value;
100 inline constexpr unsigned CountLeadingZeros32(uint32_t value) {
101 return CountLeadingZeros(value);
103 inline constexpr unsigned CountLeadingZeros64(uint64_t value) {
104 return CountLeadingZeros(value);
107 // CountTrailingZeros(value) returns the number of zero bits preceding the
108 // least significant 1 bit in |value| if |value| is non-zero, otherwise it
111 // |value| is guaranteed to be non-zero.
114 typename std::enable_if<std::is_integral<T>::value && sizeof(T) <= 8,
116 CountTrailingZeros(T value) {
118 return value == 0 ? bits
119 : bits == 64 ? __builtin_ctzll(static_cast<uint64_t>(value))
120 : __builtin_ctz(static_cast<uint32_t>(value));
126 U u = value;
131 inline constexpr unsigned CountTrailingZeros32(uint32_t value) {
132 return CountTrailingZeros(value);
134 inline constexpr unsigned CountTrailingZeros64(uint64_t value) {
135 return CountTrailingZeros(value);
138 // CountTrailingZerosNonZero(value) returns the number of zero bits preceding
139 // the least significant 1 bit in |value| if |value| is non-zero, otherwise the
141 // See CountTrailingZeros for an alternative version that allows |value| == 0.
144 typename std::enable_if<std::is_integral<T>::value && sizeof(T) <= 8,
146 CountTrailingZerosNonZero(T value) {
147 DCHECK_NE(0, value);
149 return bits == 64 ? __builtin_ctzll(static_cast<uint64_t>(value))
150 : __builtin_ctz(static_cast<uint32_t>(value));
152 return CountTrailingZeros<T, bits>(value);
156 // Returns true iff |value| is a power of 2.
158 typename = typename std::enable_if<std::is_integral<T>::value ||
159 std::is_enum<T>::value>::type>
160 constexpr inline bool IsPowerOfTwo(T value) {
161 return value > 0 && (value & (value - 1)) == 0;
166 typename = typename std::enable_if<std::is_integral<T>::value>::type>
167 inline constexpr int WhichPowerOfTwo(T value) {
168 DCHECK(IsPowerOfTwo(value));
171 return sizeof(T) == 8 ? __builtin_ctzll(static_cast<uint64_t>(value))
172 : __builtin_ctz(static_cast<uint32_t>(value));
178 U u = value;
183 // RoundUpToPowerOfTwo32(value) returns the smallest power of two which is
184 // greater than or equal to |value|. If you pass in a |value| that is already a
185 // power of two, it is returned as is. |value| must be less than or equal to
189 V8_BASE_EXPORT uint32_t RoundUpToPowerOfTwo32(uint32_t value);
190 // Same for 64 bit integers. |value| must be <= 2^63
191 V8_BASE_EXPORT uint64_t RoundUpToPowerOfTwo64(uint64_t value);
193 inline size_t RoundUpToPowerOfTwo(size_t value) {
195 return RoundUpToPowerOfTwo64(value);
199 return RoundUpToPowerOfTwo32(static_cast<uint32_t>(value));
203 // RoundDownToPowerOfTwo32(value) returns the greatest power of two which is
204 // less than or equal to |value|. If you pass in a |value| that is already a
206 inline uint32_t RoundDownToPowerOfTwo32(uint32_t value) {
207 if (value > 0x80000000u) return 0x80000000u;
208 uint32_t result = RoundUpToPowerOfTwo32(value);
209 if (result > value) result >>= 1;
215 inline constexpr uint32_t RotateRight32(uint32_t value, uint32_t shift) {
216 return (value >> shift) | (value << ((32 - shift) & 31));
220 inline constexpr uint32_t RotateLeft32(uint32_t value, uint32_t shift) {
221 return (value << shift) | (value >> ((32 - shift) & 31));
225 inline constexpr uint64_t RotateRight64(uint64_t value, uint64_t shift) {
226 return (value >> shift) | (value << ((64 - shift) & 63));
230 inline constexpr uint64_t RotateLeft64(uint64_t value, uint64_t shift) {
231 return (value << shift) | (value >> ((64 - shift) & 63));
292 // adds the accumulate value |acc|.