27 requires(std::is_unsigned<T>::value &&
sizeof(
T) <= 8)
29 static_assert(
sizeof(
T) <= 8);
30#if V8_HAS_BUILTIN_POPCOUNT
31 return sizeof(
T) == 8 ? __builtin_popcountll(
static_cast<uint64_t
>(value))
32 : __builtin_popcount(
static_cast<uint32_t
>(value));
36 constexpr uint64_t
mask[] = {0x5555555555555555, 0x3333333333333333,
39 value = ((value >> 1) &
mask[0]) + (value &
mask[0]);
41 value = ((value >> 2) &
mask[1]) + (value &
mask[1]);
43 value = ((value >> 4) &
mask[2]) + (value &
mask[2]);
49 if (
sizeof(T) > 1) value = (value >> (
sizeof(
T) > 1 ? 8 : 0)) + value;
51 if (
sizeof(T) > 2) value = (value >> (
sizeof(
T) > 2 ? 16 : 0)) + value;
53 if (
sizeof(T) > 4) value = (value >> (
sizeof(
T) > 4 ? 32 : 0)) + value;
55 return static_cast<unsigned>(value & 0xff);
62 static_assert((
sizeof(
value) == 1) || (
sizeof(
value) == 2) ||
65 for (
unsigned i = 0;
i < (
sizeof(
value) * 8);
i++) {
75 static_assert((
sizeof(
value) == 1) || (
sizeof(
value) == 2) ||
78 for (
unsigned i = 0;
i <
sizeof(
value);
i++) {
86inline constexpr std::make_unsigned_t<T>
Unsigned(T value) {
87 static_assert(std::is_signed_v<T>);
88 return static_cast<std::make_unsigned_t<T>
>(
value);
91inline constexpr std::make_signed_t<T>
Signed(T value) {
92 static_assert(std::is_unsigned_v<T>);
93 return static_cast<std::make_signed_t<T>
>(
value);
99template <
typename T,
unsigned bits = sizeof(T) * 8>
101 requires(std::is_unsigned<T>::value &&
sizeof(
T) <= 8)
103 static_assert(bits > 0,
"invalid instantiation");
104#if V8_HAS_BUILTIN_CLZ
108 ? __builtin_clzll(
static_cast<uint64_t
>(value))
109 : __builtin_clz(
static_cast<uint32_t
>(value)) - (32 - bits);
113 if (bits == 1)
return static_cast<unsigned>(
value) ^ 1;
114 T upper_half = value >> (bits / 2);
115 T next_value = upper_half != 0 ? upper_half :
value;
116 unsigned add = upper_half != 0 ? 0 : bits / 2;
117 constexpr unsigned next_bits = bits == 1 ? 1 : bits / 2;
133 static_assert(std::is_signed_v<T>);
143template <
typename T,
unsigned bits = sizeof(T) * 8>
145 requires(std::is_integral<T>::value &&
sizeof(
T) <= 8)
147#if V8_HAS_BUILTIN_CTZ
148 return value == 0 ? bits
149 : bits == 64 ? __builtin_ctzll(
static_cast<uint64_t
>(value))
150 : __builtin_ctz(
static_cast<uint32_t
>(value));
155 using U =
typename std::make_unsigned<T>::type;
172template <
typename T,
unsigned bits = sizeof(T) * 8>
174 requires(std::is_integral<T>::value &&
sizeof(
T) <= 8)
177#if V8_HAS_BUILTIN_CTZ
178 return bits == 64 ? __builtin_ctzll(
static_cast<uint64_t
>(value))
179 : __builtin_ctz(
static_cast<uint32_t
>(value));
188 requires(std::is_integral<T>::value || std::is_enum<T>::value)
190 return value > 0 && (value & (value - 1)) == 0;
196 requires std::is_integral<T>::value
199#if V8_HAS_BUILTIN_CTZ
200 static_assert(
sizeof(
T) <= 8);
201 return sizeof(
T) == 8 ? __builtin_ctzll(
static_cast<uint64_t
>(value))
202 : __builtin_ctz(
static_cast<uint32_t
>(value));
207 using U =
typename std::make_unsigned<T>::type;
223#if V8_HAS_BUILTIN_CLZ || V8_CC_MSVC
230 value |= value >> 16;
239#if V8_HAS_BUILTIN_CLZ
246 value |= value >> 16;
247 value |= value >> 32;
253 if (
sizeof(
size_t) ==
sizeof(uint64_t)) {
266 if (value > 0x80000000u)
return 0x80000000u;
275 return (value >> shift) | (value << ((32 - shift) & 31));
279inline constexpr uint32_t
RotateLeft32(uint32_t value, uint32_t shift) {
280 return (value << shift) | (value >> ((32 - shift) & 31));
285 return (value >> shift) | (value << ((64 - shift) & 63));
289inline constexpr uint64_t
RotateLeft64(uint64_t value, uint64_t shift) {
290 return (value << shift) | (value >> ((64 - shift) & 63));
297#if V8_HAS_BUILTIN_SADD_OVERFLOW
298 return __builtin_sadd_overflow(lhs, rhs, val);
300 uint32_t res =
static_cast<uint32_t
>(lhs) +
static_cast<uint32_t
>(rhs);
302 return ((res ^ lhs) & (res ^ rhs) & (1U << 31)) != 0;
311#if V8_HAS_BUILTIN_SSUB_OVERFLOW
312 return __builtin_ssub_overflow(lhs, rhs, val);
314 uint32_t res =
static_cast<uint32_t
>(lhs) -
static_cast<uint32_t
>(rhs);
316 return ((res ^ lhs) & (res ^ ~rhs) & (1U << 31)) != 0;
324#if V8_HAS_BUILTIN_SMUL_OVERFLOW
325 return __builtin_smul_overflow(lhs, rhs, val);
328 int64_t
result = int64_t{lhs} * int64_t{rhs};
329 *val =
static_cast<int32_t
>(
result);
330 using limits = std::numeric_limits<int32_t>;
331 return result < limits::min() ||
result > limits::max();
339#if V8_HAS_BUILTIN_ADD_OVERFLOW
340 return __builtin_add_overflow(lhs, rhs, val);
342 uint64_t res =
static_cast<uint64_t
>(lhs) +
static_cast<uint64_t
>(rhs);
344 return ((res ^ lhs) & (res ^ rhs) & (1ULL << 63)) != 0;
353#if V8_HAS_BUILTIN_SUB_OVERFLOW
354 return __builtin_sub_overflow(lhs, rhs, val);
356 uint64_t res =
static_cast<uint64_t
>(lhs) -
static_cast<uint64_t
>(rhs);
358 return ((res ^ lhs) & (res ^ ~rhs) & (1ULL << 63)) != 0;
366#if V8_HAS_BUILTIN_MUL_OVERFLOW
367 return __builtin_mul_overflow(lhs, rhs, val);
370 static_cast<uint64_t
>(rhs));
375 if ((res == INT64_MIN && lhs == -1)) {
379 return lhs != 0 && (res / lhs) != rhs;
433#if V8_HAS_BUILTIN_SADD_OVERFLOW
434 return __builtin_uadd_overflow(lhs, rhs, val);
437 return *val < (lhs | rhs);
445 return rhs ? lhs / rhs : 0u;
451 return rhs ? lhs / rhs : 0u;
457 return rhs ? lhs % rhs : 0u;
463 return rhs ? lhs % rhs : 0u;
469 return static_cast<int32_t
>(
static_cast<uint32_t
>(lhs) +
470 static_cast<uint32_t
>(rhs));
474 return static_cast<int32_t
>(-
static_cast<uint32_t
>(
x));
ZoneVector< RpoNumber > & result
constexpr unsigned CountLeadingZeros(T value)
int32_t SignedMulHighAndAdd32(int32_t lhs, int32_t rhs, int32_t acc)
bool SignedAddOverflow64(int64_t lhs, int64_t rhs, int64_t *val)
constexpr uint64_t RotateRight64(uint64_t value, uint64_t shift)
V8_BASE_EXPORT constexpr uint64_t RoundUpToPowerOfTwo64(uint64_t value)
int32_t SignedMulHigh32(int32_t lhs, int32_t rhs)
constexpr uint32_t RotateLeft32(uint32_t value, uint32_t shift)
constexpr unsigned CountTrailingZeros64(uint64_t value)
uint32_t RoundDownToPowerOfTwo32(uint32_t value)
constexpr unsigned CountTrailingZeros32(uint32_t value)
int32_t SignedDiv32(int32_t lhs, int32_t rhs)
constexpr unsigned CountLeadingZeros64(uint64_t value)
int64_t SignedDiv64(int64_t lhs, int64_t rhs)
bool SignedSubOverflow64(int64_t lhs, int64_t rhs, int64_t *val)
constexpr unsigned CountTrailingZeros(T value)
constexpr unsigned CountPopulation(T value)
uint32_t UnsignedMulHigh32(uint32_t lhs, uint32_t rhs)
int64_t SignedMulHigh64(int64_t u, int64_t v)
constexpr bool IsPowerOfTwo(T value)
constexpr std::make_signed_t< T > Signed(T value)
int32_t WraparoundNeg32(int32_t x)
uint32_t UnsignedDiv32(uint32_t lhs, uint32_t rhs)
uint32_t UnsignedMod32(uint32_t lhs, uint32_t rhs)
constexpr uint64_t RotateLeft64(uint64_t value, uint64_t shift)
constexpr uint32_t RotateRight32(uint32_t value, uint32_t shift)
V8_BASE_EXPORT constexpr int BitWidth(T x)
constexpr std::make_unsigned_t< T > Unsigned(T value)
constexpr unsigned CountLeadingZeros32(uint32_t value)
constexpr unsigned CountLeadingSignBits(T value)
int64_t SignedMod64(int64_t lhs, int64_t rhs)
uint64_t UnsignedDiv64(uint64_t lhs, uint64_t rhs)
bool UnsignedAddOverflow32(uint32_t lhs, uint32_t rhs, uint32_t *val)
int32_t WraparoundAdd32(int32_t lhs, int32_t rhs)
bool SignedAddOverflow32(int32_t lhs, int32_t rhs, int32_t *val)
uint64_t UnsignedMod64(uint64_t lhs, uint64_t rhs)
constexpr unsigned CountTrailingZerosNonZero(T value)
int32_t SignedMod32(int32_t lhs, int32_t rhs)
int64_t SignedSaturatedSub64(int64_t lhs, int64_t rhs)
bool SignedSubOverflow32(int32_t lhs, int32_t rhs, int32_t *val)
bool SignedMulOverflow32(int32_t lhs, int32_t rhs, int32_t *val)
uint64_t UnsignedMulHigh64(uint64_t u, uint64_t v)
V8_BASE_EXPORT constexpr uint32_t RoundUpToPowerOfTwo32(uint32_t value)
bool SignedMulOverflow64(int64_t lhs, int64_t rhs, int64_t *val)
constexpr size_t RoundUpToPowerOfTwo(size_t value)
int64_t SignedSaturatedAdd64(int64_t lhs, int64_t rhs)
constexpr int WhichPowerOfTwo(T value)
V8_INLINE Dest bit_cast(Source const &source)
#define DCHECK_LE(v1, v2)
#define DCHECK_NE(v1, v2)
#define DCHECK(condition)
std::unique_ptr< ValueMirror > value