[base] Consolidate IsPowerOfTwo{32,64} and IS_POWER_OF_TWO
There is just one version now, called IsPowerOfTwo. It accepts any integral type. There is one slight semantical change: Called with kMinInt, it previously returned true, because the argument was implicitly casted to an unsigned. It's now (correctly) returning false, so I had to add special handlings of kMinInt in machine-operator-reducer before calling IsPowerOfTwo on that value. R=mlippautz@chromium.org,mstarzinger@chromium.org,jgruber@chromium.org,ishell@chromium.org,yangguo@chromium.org Change-Id: Idc112a89034cdc8c03365b778b33b1c29fefb38d Reviewed-on: https://chromium-review.googlesource.com/568140 Reviewed-by: Igor Sheludko <ishell@chromium.org> Reviewed-by: Michael Starzinger <mstarzinger@chromium.org> Reviewed-by: Michael Lippautz <mlippautz@chromium.org> Reviewed-by: Yang Guo <yangguo@chromium.org> Commit-Queue: Clemens Hammacher <clemensh@chromium.org> Cr-Commit-Position: refs/heads/master@{#46627}
This commit is contained in:
parent
69e7be8539
commit
7c00e15bc9
@ -53,7 +53,7 @@ char* StrNDup(const char* str, int n) {
|
||||
|
||||
void* AlignedAlloc(size_t size, size_t alignment) {
|
||||
DCHECK_LE(V8_ALIGNOF(void*), alignment);
|
||||
DCHECK(base::bits::IsPowerOfTwo64(alignment));
|
||||
DCHECK(base::bits::IsPowerOfTwo(alignment));
|
||||
void* ptr;
|
||||
#if V8_OS_WIN
|
||||
ptr = _aligned_malloc(size, alignment);
|
||||
|
@ -618,7 +618,7 @@ void Assembler::GetCode(Isolate* isolate, CodeDesc* desc) {
|
||||
|
||||
|
||||
void Assembler::Align(int m) {
|
||||
DCHECK(m >= 4 && base::bits::IsPowerOfTwo32(m));
|
||||
DCHECK(m >= 4 && base::bits::IsPowerOfTwo(m));
|
||||
DCHECK((pc_offset() & (kInstrSize - 1)) == 0);
|
||||
while ((pc_offset() & (m - 1)) != 0) {
|
||||
nop();
|
||||
|
@ -822,7 +822,7 @@ void CEntryStub::Generate(MacroAssembler* masm) {
|
||||
if (FLAG_debug_code) {
|
||||
if (frame_alignment > kPointerSize) {
|
||||
Label alignment_as_expected;
|
||||
DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
|
||||
DCHECK(base::bits::IsPowerOfTwo(frame_alignment));
|
||||
__ tst(sp, Operand(frame_alignment_mask));
|
||||
__ b(eq, &alignment_as_expected);
|
||||
// Don't use Check here, as it will call Runtime_Abort re-entering here.
|
||||
@ -2249,7 +2249,7 @@ void ProfileEntryHookStub::Generate(MacroAssembler* masm) {
|
||||
int frame_alignment = masm->ActivationFrameAlignment();
|
||||
if (frame_alignment > kPointerSize) {
|
||||
__ mov(r5, sp);
|
||||
DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
|
||||
DCHECK(base::bits::IsPowerOfTwo(frame_alignment));
|
||||
__ and_(sp, sp, Operand(-frame_alignment));
|
||||
}
|
||||
|
||||
|
@ -309,7 +309,7 @@ void MacroAssembler::And(Register dst, Register src1, const Operand& src2,
|
||||
} else if (!(src2.InstructionsRequired(this) == 1) &&
|
||||
!src2.MustOutputRelocInfo(this) &&
|
||||
CpuFeatures::IsSupported(ARMv7) &&
|
||||
base::bits::IsPowerOfTwo32(src2.immediate() + 1)) {
|
||||
base::bits::IsPowerOfTwo(src2.immediate() + 1)) {
|
||||
CpuFeatureScope scope(this, ARMv7);
|
||||
ubfx(dst, src1, 0,
|
||||
WhichPowerOf2(static_cast<uint32_t>(src2.immediate()) + 1), cond);
|
||||
@ -1448,7 +1448,7 @@ void MacroAssembler::EnterExitFrame(bool save_doubles, int stack_space,
|
||||
const int frame_alignment = MacroAssembler::ActivationFrameAlignment();
|
||||
sub(sp, sp, Operand((stack_space + 1) * kPointerSize));
|
||||
if (frame_alignment > 0) {
|
||||
DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
|
||||
DCHECK(base::bits::IsPowerOfTwo(frame_alignment));
|
||||
and_(sp, sp, Operand(-frame_alignment));
|
||||
}
|
||||
|
||||
@ -3175,7 +3175,7 @@ void TurboAssembler::PrepareCallCFunction(int num_reg_arguments,
|
||||
// and the original value of sp.
|
||||
mov(scratch, sp);
|
||||
sub(sp, sp, Operand((stack_passed_arguments + 1) * kPointerSize));
|
||||
DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
|
||||
DCHECK(base::bits::IsPowerOfTwo(frame_alignment));
|
||||
and_(sp, sp, Operand(-frame_alignment));
|
||||
str(scratch, MemOperand(sp, stack_passed_arguments * kPointerSize));
|
||||
} else {
|
||||
@ -3242,7 +3242,7 @@ void TurboAssembler::CallCFunctionHelper(Register function,
|
||||
int frame_alignment = base::OS::ActivationFrameAlignment();
|
||||
int frame_alignment_mask = frame_alignment - 1;
|
||||
if (frame_alignment > kPointerSize) {
|
||||
DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
|
||||
DCHECK(base::bits::IsPowerOfTwo(frame_alignment));
|
||||
Label alignment_as_expected;
|
||||
tst(sp, Operand(frame_alignment_mask));
|
||||
b(eq, &alignment_as_expected);
|
||||
|
@ -643,7 +643,7 @@ void Assembler::GetCode(Isolate* isolate, CodeDesc* desc) {
|
||||
|
||||
|
||||
void Assembler::Align(int m) {
|
||||
DCHECK(m >= 4 && base::bits::IsPowerOfTwo32(m));
|
||||
DCHECK(m >= 4 && base::bits::IsPowerOfTwo(m));
|
||||
while ((pc_offset() & (m - 1)) != 0) {
|
||||
nop();
|
||||
}
|
||||
@ -4566,7 +4566,7 @@ bool Assembler::IsImmLogical(uint64_t value,
|
||||
}
|
||||
|
||||
// If the repeat period d is not a power of two, it can't be encoded.
|
||||
if (!IS_POWER_OF_TWO(d)) {
|
||||
if (!base::bits::IsPowerOfTwo(d)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -233,7 +233,7 @@ struct VRegister : public CPURegister {
|
||||
};
|
||||
|
||||
static VRegister Create(int reg_code, int reg_size, int lane_count = 1) {
|
||||
DCHECK(base::bits::IsPowerOfTwo32(lane_count) && (lane_count <= 16));
|
||||
DCHECK(base::bits::IsPowerOfTwo(lane_count) && (lane_count <= 16));
|
||||
VRegister v(CPURegister::Create(reg_code, reg_size, CPURegister::kVRegister,
|
||||
lane_count));
|
||||
DCHECK(v.IsValidVRegister());
|
||||
|
@ -1046,7 +1046,7 @@ void MacroAssembler::AlignAndSetCSPForFrame() {
|
||||
int sp_alignment = ActivationFrameAlignment();
|
||||
// AAPCS64 mandates at least 16-byte alignment.
|
||||
DCHECK(sp_alignment >= 16);
|
||||
DCHECK(base::bits::IsPowerOfTwo32(sp_alignment));
|
||||
DCHECK(base::bits::IsPowerOfTwo(sp_alignment));
|
||||
Bic(csp, StackPointer(), sp_alignment - 1);
|
||||
SetStackPointer(csp);
|
||||
}
|
||||
@ -1304,7 +1304,7 @@ void TurboAssembler::Claim(int64_t count, uint64_t unit_size) {
|
||||
|
||||
void TurboAssembler::Claim(const Register& count, uint64_t unit_size) {
|
||||
if (unit_size == 0) return;
|
||||
DCHECK(base::bits::IsPowerOfTwo64(unit_size));
|
||||
DCHECK(base::bits::IsPowerOfTwo(unit_size));
|
||||
|
||||
const int shift = CountTrailingZeros(unit_size, kXRegSizeInBits);
|
||||
const Operand size(count, LSL, shift);
|
||||
@ -1323,7 +1323,7 @@ void TurboAssembler::Claim(const Register& count, uint64_t unit_size) {
|
||||
|
||||
|
||||
void MacroAssembler::ClaimBySMI(const Register& count_smi, uint64_t unit_size) {
|
||||
DCHECK(unit_size == 0 || base::bits::IsPowerOfTwo64(unit_size));
|
||||
DCHECK(unit_size == 0 || base::bits::IsPowerOfTwo(unit_size));
|
||||
const int shift = CountTrailingZeros(unit_size, kXRegSizeInBits) - kSmiShift;
|
||||
const Operand size(count_smi,
|
||||
(shift >= 0) ? (LSL) : (LSR),
|
||||
@ -1362,7 +1362,7 @@ void TurboAssembler::Drop(int64_t count, uint64_t unit_size) {
|
||||
|
||||
void TurboAssembler::Drop(const Register& count, uint64_t unit_size) {
|
||||
if (unit_size == 0) return;
|
||||
DCHECK(base::bits::IsPowerOfTwo64(unit_size));
|
||||
DCHECK(base::bits::IsPowerOfTwo(unit_size));
|
||||
|
||||
const int shift = CountTrailingZeros(unit_size, kXRegSizeInBits);
|
||||
const Operand size(count, LSL, shift);
|
||||
@ -1384,7 +1384,7 @@ void TurboAssembler::Drop(const Register& count, uint64_t unit_size) {
|
||||
|
||||
|
||||
void MacroAssembler::DropBySMI(const Register& count_smi, uint64_t unit_size) {
|
||||
DCHECK(unit_size == 0 || base::bits::IsPowerOfTwo64(unit_size));
|
||||
DCHECK(unit_size == 0 || base::bits::IsPowerOfTwo(unit_size));
|
||||
const int shift = CountTrailingZeros(unit_size, kXRegSizeInBits) - kSmiShift;
|
||||
const Operand size(count_smi,
|
||||
(shift >= 0) ? (LSL) : (LSR),
|
||||
|
@ -74,7 +74,7 @@ int float16classify(float16 value) {
|
||||
}
|
||||
|
||||
int CountLeadingZeros(uint64_t value, int width) {
|
||||
DCHECK(base::bits::IsPowerOfTwo32(width) && (width <= 64));
|
||||
DCHECK(base::bits::IsPowerOfTwo(width) && (width <= 64));
|
||||
if (value == 0) {
|
||||
return width;
|
||||
}
|
||||
@ -83,7 +83,7 @@ int CountLeadingZeros(uint64_t value, int width) {
|
||||
|
||||
|
||||
int CountLeadingSignBits(int64_t value, int width) {
|
||||
DCHECK(base::bits::IsPowerOfTwo32(width) && (width <= 64));
|
||||
DCHECK(base::bits::IsPowerOfTwo(width) && (width <= 64));
|
||||
if (value >= 0) {
|
||||
return CountLeadingZeros(value, width) - 1;
|
||||
} else {
|
||||
|
@ -2023,7 +2023,7 @@ AsmType* AsmJsParser::ValidateCall() {
|
||||
if (!CheckForUnsigned(&mask)) {
|
||||
FAILn("Expected mask literal");
|
||||
}
|
||||
if (!base::bits::IsPowerOfTwo32(mask + 1)) {
|
||||
if (!base::bits::IsPowerOfTwo(mask + 1)) {
|
||||
FAILn("Expected power of 2 mask");
|
||||
}
|
||||
current_function_builder_->EmitI32Const(mask);
|
||||
|
@ -1948,7 +1948,7 @@ void Assembler::RecordDebugBreakSlot(RelocInfo::Mode mode) {
|
||||
|
||||
|
||||
void Assembler::DataAlign(int m) {
|
||||
DCHECK(m >= 2 && base::bits::IsPowerOfTwo32(m));
|
||||
DCHECK(m >= 2 && base::bits::IsPowerOfTwo(m));
|
||||
while ((pc_offset() & (m - 1)) != 0) {
|
||||
db(0);
|
||||
}
|
||||
|
@ -6,6 +6,7 @@
|
||||
#define V8_BASE_BITS_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <type_traits>
|
||||
|
||||
#include "src/base/base-export.h"
|
||||
#include "src/base/macros.h"
|
||||
@ -168,14 +169,10 @@ inline unsigned CountTrailingZeros64(uint64_t value) {
|
||||
DEFINE_32_64_OVERLOADS(CountTrailingZeros)
|
||||
|
||||
// Returns true iff |value| is a power of 2.
|
||||
constexpr inline bool IsPowerOfTwo32(uint32_t value) {
|
||||
return value && !(value & (value - 1));
|
||||
}
|
||||
|
||||
|
||||
// Returns true iff |value| is a power of 2.
|
||||
constexpr inline bool IsPowerOfTwo64(uint64_t value) {
|
||||
return value && !(value & (value - 1));
|
||||
template <typename T,
|
||||
typename = typename std::enable_if<std::is_integral<T>::value>::type>
|
||||
constexpr inline bool IsPowerOfTwo(T value) {
|
||||
return value > 0 && (value & (value - 1)) == 0;
|
||||
}
|
||||
|
||||
// RoundUpToPowerOfTwo32(value) returns the smallest power of two which is
|
||||
|
@ -297,7 +297,7 @@ template <typename Key, typename Value, typename MatchFun,
|
||||
typename TemplateHashMapImpl<Key, Value, MatchFun, AllocationPolicy>::Entry*
|
||||
TemplateHashMapImpl<Key, Value, MatchFun, AllocationPolicy>::Probe(
|
||||
const Key& key, uint32_t hash) const {
|
||||
DCHECK(base::bits::IsPowerOfTwo32(capacity_));
|
||||
DCHECK(base::bits::IsPowerOfTwo(capacity_));
|
||||
size_t i = hash & (capacity_ - 1);
|
||||
DCHECK(i < capacity_);
|
||||
|
||||
@ -333,7 +333,7 @@ template <typename Key, typename Value, typename MatchFun,
|
||||
class AllocationPolicy>
|
||||
void TemplateHashMapImpl<Key, Value, MatchFun, AllocationPolicy>::Initialize(
|
||||
uint32_t capacity, AllocationPolicy allocator) {
|
||||
DCHECK(base::bits::IsPowerOfTwo32(capacity));
|
||||
DCHECK(base::bits::IsPowerOfTwo(capacity));
|
||||
map_ = reinterpret_cast<Entry*>(allocator.New(capacity * sizeof(Entry)));
|
||||
if (map_ == nullptr) {
|
||||
FATAL("Out of memory: HashMap::Initialize");
|
||||
|
@ -201,9 +201,6 @@ struct Use {
|
||||
(void)unused_tmp_array_for_use_macro; \
|
||||
} while (false)
|
||||
|
||||
#define IS_POWER_OF_TWO(x) ((x) != 0 && (((x) & ((x) - 1)) == 0))
|
||||
|
||||
|
||||
// Define our own macros for writing 64-bit constants. This is less fragile
|
||||
// than defining __STDC_CONSTANT_MACROS before including <stdint.h>, and it
|
||||
// works on compilers that don't have it (like MSVC).
|
||||
@ -295,7 +292,8 @@ inline T AddressFrom(intptr_t x) {
|
||||
// Return the largest multiple of m which is <= x.
|
||||
template <typename T>
|
||||
inline T RoundDown(T x, intptr_t m) {
|
||||
DCHECK(IS_POWER_OF_TWO(m));
|
||||
// m must be a power of two.
|
||||
DCHECK(m != 0 && ((m & (m - 1)) == 0));
|
||||
return AddressFrom<T>(OffsetFrom(x) & -m);
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,7 @@
|
||||
|
||||
#include <new>
|
||||
|
||||
#include "src/base/bits.h"
|
||||
#include "src/base/macros.h"
|
||||
#include "src/base/platform/mutex.h"
|
||||
#include "src/base/platform/time.h"
|
||||
@ -82,7 +83,7 @@ int RandomNumberGenerator::NextInt(int max) {
|
||||
DCHECK_LT(0, max);
|
||||
|
||||
// Fast path if max is a power of 2.
|
||||
if (IS_POWER_OF_TWO(max)) {
|
||||
if (bits::IsPowerOfTwo(max)) {
|
||||
return static_cast<int>((max * static_cast<int64_t>(Next(31))) >> 31);
|
||||
}
|
||||
|
||||
|
@ -101,7 +101,7 @@ Node* CollectionsBuiltinsAssembler::AllocateOrderedHashTable() {
|
||||
static const int kDataTableStartIndex =
|
||||
CollectionType::kHashTableStartIndex + kBucketCount;
|
||||
|
||||
STATIC_ASSERT(base::bits::IsPowerOfTwo32(kCapacity));
|
||||
STATIC_ASSERT(base::bits::IsPowerOfTwo(kCapacity));
|
||||
STATIC_ASSERT(kCapacity <= CollectionType::kMaxCapacity);
|
||||
|
||||
// Allocate the table and add the proper map.
|
||||
|
@ -1363,14 +1363,14 @@ void InstructionSelector::VisitInt32Mul(Node* node) {
|
||||
Int32BinopMatcher m(node);
|
||||
if (m.right().HasValue() && m.right().Value() > 0) {
|
||||
int32_t value = m.right().Value();
|
||||
if (base::bits::IsPowerOfTwo32(value - 1)) {
|
||||
if (base::bits::IsPowerOfTwo(value - 1)) {
|
||||
Emit(kArmAdd | AddressingModeField::encode(kMode_Operand2_R_LSL_I),
|
||||
g.DefineAsRegister(node), g.UseRegister(m.left().node()),
|
||||
g.UseRegister(m.left().node()),
|
||||
g.TempImmediate(WhichPowerOf2(value - 1)));
|
||||
return;
|
||||
}
|
||||
if (value < kMaxInt && base::bits::IsPowerOfTwo32(value + 1)) {
|
||||
if (value < kMaxInt && base::bits::IsPowerOfTwo(value + 1)) {
|
||||
Emit(kArmRsb | AddressingModeField::encode(kMode_Operand2_R_LSL_I),
|
||||
g.DefineAsRegister(node), g.UseRegister(m.left().node()),
|
||||
g.UseRegister(m.left().node()),
|
||||
|
@ -417,16 +417,16 @@ Condition FlagsConditionToCondition(FlagsCondition condition) {
|
||||
|
||||
} // namespace
|
||||
|
||||
#define ASSEMBLE_BOUNDS_CHECK(offset, length, out_of_bounds) \
|
||||
do { \
|
||||
if (length.IsImmediate() && \
|
||||
base::bits::IsPowerOfTwo64(length.ImmediateValue())) { \
|
||||
__ Tst(offset, ~(length.ImmediateValue() - 1)); \
|
||||
__ B(ne, out_of_bounds); \
|
||||
} else { \
|
||||
__ Cmp(offset, length); \
|
||||
__ B(hs, out_of_bounds); \
|
||||
} \
|
||||
#define ASSEMBLE_BOUNDS_CHECK(offset, length, out_of_bounds) \
|
||||
do { \
|
||||
if (length.IsImmediate() && \
|
||||
base::bits::IsPowerOfTwo(length.ImmediateValue())) { \
|
||||
__ Tst(offset, ~(length.ImmediateValue() - 1)); \
|
||||
__ B(ne, out_of_bounds); \
|
||||
} else { \
|
||||
__ Cmp(offset, length); \
|
||||
__ B(hs, out_of_bounds); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define ASSEMBLE_CHECKED_LOAD_FLOAT(width) \
|
||||
|
@ -531,7 +531,7 @@ int32_t LeftShiftForReducedMultiply(Matcher* m) {
|
||||
DCHECK(m->IsInt32Mul() || m->IsInt64Mul());
|
||||
if (m->right().HasValue() && m->right().Value() >= 3) {
|
||||
uint64_t value_minus_one = m->right().Value() - 1;
|
||||
if (base::bits::IsPowerOfTwo64(value_minus_one)) {
|
||||
if (base::bits::IsPowerOfTwo(value_minus_one)) {
|
||||
return WhichPowerOf2_64(value_minus_one);
|
||||
}
|
||||
}
|
||||
|
@ -102,7 +102,7 @@ void GapResolver::Resolve(ParallelMove* moves) {
|
||||
}
|
||||
|
||||
if (!kSimpleFPAliasing) {
|
||||
if (reps && !base::bits::IsPowerOfTwo32(reps)) {
|
||||
if (reps && !base::bits::IsPowerOfTwo(reps)) {
|
||||
// Start with the smallest FP moves, so we never encounter smaller moves
|
||||
// in the middle of a cycle of larger moves.
|
||||
if ((reps & kFloat32Bit) != 0) {
|
||||
|
@ -1999,7 +1999,7 @@ Reduction JSBuiltinReducer::ReduceObjectCreate(Node* node) {
|
||||
Handle<Map> map(isolate()->heap()->hash_table_map(), isolate());
|
||||
int capacity =
|
||||
NameDictionary::ComputeCapacity(NameDictionary::kInitialCapacity);
|
||||
DCHECK(base::bits::IsPowerOfTwo32(capacity));
|
||||
DCHECK(base::bits::IsPowerOfTwo(capacity));
|
||||
int length = NameDictionary::EntryToIndex(capacity);
|
||||
int size = NameDictionary::SizeFor(length);
|
||||
|
||||
|
@ -800,7 +800,7 @@ Reduction MachineOperatorReducer::ReduceInt32Div(Node* node) {
|
||||
int32_t const divisor = m.right().Value();
|
||||
Node* const dividend = m.left().node();
|
||||
Node* quotient = dividend;
|
||||
if (base::bits::IsPowerOfTwo32(Abs(divisor))) {
|
||||
if (divisor == kMinInt || base::bits::IsPowerOfTwo(Abs(divisor))) {
|
||||
uint32_t const shift = WhichPowerOf2Abs(divisor);
|
||||
DCHECK_NE(0u, shift);
|
||||
if (shift > 1) {
|
||||
@ -840,7 +840,7 @@ Reduction MachineOperatorReducer::ReduceUint32Div(Node* node) {
|
||||
if (m.right().HasValue()) {
|
||||
Node* const dividend = m.left().node();
|
||||
uint32_t const divisor = m.right().Value();
|
||||
if (base::bits::IsPowerOfTwo32(divisor)) { // x / 2^n => x >> n
|
||||
if (base::bits::IsPowerOfTwo(divisor)) { // x / 2^n => x >> n
|
||||
node->ReplaceInput(1, Uint32Constant(WhichPowerOf2(m.right().Value())));
|
||||
node->TrimInputCount(2);
|
||||
NodeProperties::ChangeOp(node, machine()->Word32Shr());
|
||||
@ -866,8 +866,8 @@ Reduction MachineOperatorReducer::ReduceInt32Mod(Node* node) {
|
||||
}
|
||||
if (m.right().HasValue()) {
|
||||
Node* const dividend = m.left().node();
|
||||
int32_t const divisor = Abs(m.right().Value());
|
||||
if (base::bits::IsPowerOfTwo32(divisor)) {
|
||||
uint32_t const divisor = Abs(m.right().Value());
|
||||
if (base::bits::IsPowerOfTwo(divisor)) {
|
||||
uint32_t const mask = divisor - 1;
|
||||
Node* const zero = Int32Constant(0);
|
||||
Diamond d(graph(), common(),
|
||||
@ -903,7 +903,7 @@ Reduction MachineOperatorReducer::ReduceUint32Mod(Node* node) {
|
||||
if (m.right().HasValue()) {
|
||||
Node* const dividend = m.left().node();
|
||||
uint32_t const divisor = m.right().Value();
|
||||
if (base::bits::IsPowerOfTwo32(divisor)) { // x % 2^n => x & 2^n-1
|
||||
if (base::bits::IsPowerOfTwo(divisor)) { // x % 2^n => x & 2^n-1
|
||||
node->ReplaceInput(1, Uint32Constant(m.right().Value() - 1));
|
||||
node->TrimInputCount(2);
|
||||
NodeProperties::ChangeOp(node, machine()->Word32And());
|
||||
|
@ -2938,7 +2938,7 @@ void CodeGenerator::AssembleArchBoolean(Instruction* instr,
|
||||
if (instr->arch_opcode() == kMipsTst) {
|
||||
cc = FlagsConditionToConditionTst(condition);
|
||||
if (instr->InputAt(1)->IsImmediate() &&
|
||||
base::bits::IsPowerOfTwo32(i.InputOperand(1).immediate())) {
|
||||
base::bits::IsPowerOfTwo(i.InputOperand(1).immediate())) {
|
||||
uint16_t pos =
|
||||
base::bits::CountTrailingZeros32(i.InputOperand(1).immediate());
|
||||
__ Ext(result, i.InputRegister(0), pos, 1);
|
||||
|
@ -731,19 +731,19 @@ void InstructionSelector::VisitInt32Mul(Node* node) {
|
||||
Int32BinopMatcher m(node);
|
||||
if (m.right().HasValue() && m.right().Value() > 0) {
|
||||
int32_t value = m.right().Value();
|
||||
if (base::bits::IsPowerOfTwo32(value)) {
|
||||
if (base::bits::IsPowerOfTwo(value)) {
|
||||
Emit(kMipsShl | AddressingModeField::encode(kMode_None),
|
||||
g.DefineAsRegister(node), g.UseRegister(m.left().node()),
|
||||
g.TempImmediate(WhichPowerOf2(value)));
|
||||
return;
|
||||
}
|
||||
if (base::bits::IsPowerOfTwo32(value - 1)) {
|
||||
if (base::bits::IsPowerOfTwo(value - 1)) {
|
||||
Emit(kMipsLsa, g.DefineAsRegister(node), g.UseRegister(m.left().node()),
|
||||
g.UseRegister(m.left().node()),
|
||||
g.TempImmediate(WhichPowerOf2(value - 1)));
|
||||
return;
|
||||
}
|
||||
if (base::bits::IsPowerOfTwo32(value + 1)) {
|
||||
if (base::bits::IsPowerOfTwo(value + 1)) {
|
||||
InstructionOperand temp = g.TempRegister();
|
||||
Emit(kMipsShl | AddressingModeField::encode(kMode_None), temp,
|
||||
g.UseRegister(m.left().node()),
|
||||
|
@ -379,26 +379,26 @@ FPUCondition FlagsConditionToConditionCmpFPU(bool& predicate,
|
||||
}
|
||||
|
||||
} // namespace
|
||||
#define ASSEMBLE_BOUNDS_CHECK_REGISTER(offset, length, out_of_bounds) \
|
||||
do { \
|
||||
if (!length.is_reg() && base::bits::IsPowerOfTwo64(length.immediate())) { \
|
||||
__ And(kScratchReg, offset, Operand(~(length.immediate() - 1))); \
|
||||
__ Branch(USE_DELAY_SLOT, out_of_bounds, ne, kScratchReg, \
|
||||
Operand(zero_reg)); \
|
||||
} else { \
|
||||
__ Branch(USE_DELAY_SLOT, out_of_bounds, hs, offset, length); \
|
||||
} \
|
||||
#define ASSEMBLE_BOUNDS_CHECK_REGISTER(offset, length, out_of_bounds) \
|
||||
do { \
|
||||
if (!length.is_reg() && base::bits::IsPowerOfTwo(length.immediate())) { \
|
||||
__ And(kScratchReg, offset, Operand(~(length.immediate() - 1))); \
|
||||
__ Branch(USE_DELAY_SLOT, out_of_bounds, ne, kScratchReg, \
|
||||
Operand(zero_reg)); \
|
||||
} else { \
|
||||
__ Branch(USE_DELAY_SLOT, out_of_bounds, hs, offset, length); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define ASSEMBLE_BOUNDS_CHECK_IMMEDIATE(offset, length, out_of_bounds) \
|
||||
do { \
|
||||
if (!length.is_reg() && base::bits::IsPowerOfTwo64(length.immediate())) { \
|
||||
__ Or(kScratchReg, zero_reg, Operand(offset)); \
|
||||
__ And(kScratchReg, kScratchReg, Operand(~(length.immediate() - 1))); \
|
||||
__ Branch(out_of_bounds, ne, kScratchReg, Operand(zero_reg)); \
|
||||
} else { \
|
||||
__ Branch(out_of_bounds, ls, length.rm(), Operand(offset)); \
|
||||
} \
|
||||
#define ASSEMBLE_BOUNDS_CHECK_IMMEDIATE(offset, length, out_of_bounds) \
|
||||
do { \
|
||||
if (!length.is_reg() && base::bits::IsPowerOfTwo(length.immediate())) { \
|
||||
__ Or(kScratchReg, zero_reg, Operand(offset)); \
|
||||
__ And(kScratchReg, kScratchReg, Operand(~(length.immediate() - 1))); \
|
||||
__ Branch(out_of_bounds, ne, kScratchReg, Operand(zero_reg)); \
|
||||
} else { \
|
||||
__ Branch(out_of_bounds, ls, length.rm(), Operand(offset)); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define ASSEMBLE_CHECKED_LOAD_FLOAT(width, asm_instr) \
|
||||
@ -3224,7 +3224,7 @@ void CodeGenerator::AssembleArchBoolean(Instruction* instr,
|
||||
if (instr->arch_opcode() == kMips64Tst) {
|
||||
cc = FlagsConditionToConditionTst(condition);
|
||||
if (instr->InputAt(1)->IsImmediate() &&
|
||||
base::bits::IsPowerOfTwo64(i.InputOperand(1).immediate())) {
|
||||
base::bits::IsPowerOfTwo(i.InputOperand(1).immediate())) {
|
||||
uint16_t pos =
|
||||
base::bits::CountTrailingZeros64(i.InputOperand(1).immediate());
|
||||
__ Dext(result, i.InputRegister(0), pos, 1);
|
||||
|
@ -980,19 +980,19 @@ void InstructionSelector::VisitInt32Mul(Node* node) {
|
||||
Int32BinopMatcher m(node);
|
||||
if (m.right().HasValue() && m.right().Value() > 0) {
|
||||
int32_t value = m.right().Value();
|
||||
if (base::bits::IsPowerOfTwo32(value)) {
|
||||
if (base::bits::IsPowerOfTwo(value)) {
|
||||
Emit(kMips64Shl | AddressingModeField::encode(kMode_None),
|
||||
g.DefineAsRegister(node), g.UseRegister(m.left().node()),
|
||||
g.TempImmediate(WhichPowerOf2(value)));
|
||||
return;
|
||||
}
|
||||
if (base::bits::IsPowerOfTwo32(value - 1)) {
|
||||
if (base::bits::IsPowerOfTwo(value - 1)) {
|
||||
Emit(kMips64Lsa, g.DefineAsRegister(node), g.UseRegister(m.left().node()),
|
||||
g.UseRegister(m.left().node()),
|
||||
g.TempImmediate(WhichPowerOf2(value - 1)));
|
||||
return;
|
||||
}
|
||||
if (base::bits::IsPowerOfTwo32(value + 1)) {
|
||||
if (base::bits::IsPowerOfTwo(value + 1)) {
|
||||
InstructionOperand temp = g.TempRegister();
|
||||
Emit(kMips64Shl | AddressingModeField::encode(kMode_None), temp,
|
||||
g.UseRegister(m.left().node()),
|
||||
@ -1037,20 +1037,20 @@ void InstructionSelector::VisitInt64Mul(Node* node) {
|
||||
// TODO(dusmil): Add optimization for shifts larger than 32.
|
||||
if (m.right().HasValue() && m.right().Value() > 0) {
|
||||
int32_t value = static_cast<int32_t>(m.right().Value());
|
||||
if (base::bits::IsPowerOfTwo32(value)) {
|
||||
if (base::bits::IsPowerOfTwo(value)) {
|
||||
Emit(kMips64Dshl | AddressingModeField::encode(kMode_None),
|
||||
g.DefineAsRegister(node), g.UseRegister(m.left().node()),
|
||||
g.TempImmediate(WhichPowerOf2(value)));
|
||||
return;
|
||||
}
|
||||
if (base::bits::IsPowerOfTwo32(value - 1)) {
|
||||
if (base::bits::IsPowerOfTwo(value - 1)) {
|
||||
// Dlsa macro will handle the shifting value out of bound cases.
|
||||
Emit(kMips64Dlsa, g.DefineAsRegister(node),
|
||||
g.UseRegister(m.left().node()), g.UseRegister(m.left().node()),
|
||||
g.TempImmediate(WhichPowerOf2(value - 1)));
|
||||
return;
|
||||
}
|
||||
if (base::bits::IsPowerOfTwo32(value + 1)) {
|
||||
if (base::bits::IsPowerOfTwo(value + 1)) {
|
||||
InstructionOperand temp = g.TempRegister();
|
||||
Emit(kMips64Dshl | AddressingModeField::encode(kMode_None), temp,
|
||||
g.UseRegister(m.left().node()),
|
||||
|
@ -105,7 +105,7 @@ class OperandSet {
|
||||
}
|
||||
|
||||
static bool HasMixedFPReps(int reps) {
|
||||
return reps && !base::bits::IsPowerOfTwo32(reps);
|
||||
return reps && !base::bits::IsPowerOfTwo(reps);
|
||||
}
|
||||
|
||||
ZoneVector<InstructionOperand>* set_;
|
||||
|
@ -175,8 +175,7 @@ struct FloatMatcher final : public ValueMatcher<T, kOpcode> {
|
||||
return false;
|
||||
}
|
||||
Double value = Double(this->Value());
|
||||
return !value.IsInfinite() &&
|
||||
base::bits::IsPowerOfTwo64(value.Significand());
|
||||
return !value.IsInfinite() && base::bits::IsPowerOfTwo(value.Significand());
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -5,6 +5,7 @@
|
||||
#ifndef V8_REGISTER_ALLOCATOR_H_
|
||||
#define V8_REGISTER_ALLOCATOR_H_
|
||||
|
||||
#include "src/base/bits.h"
|
||||
#include "src/base/compiler-specific.h"
|
||||
#include "src/compiler/instruction.h"
|
||||
#include "src/globals.h"
|
||||
@ -159,8 +160,8 @@ class LifetimePosition final {
|
||||
static const int kHalfStep = 2;
|
||||
static const int kStep = 2 * kHalfStep;
|
||||
|
||||
// Code relies on kStep and kHalfStep being a power of two.
|
||||
STATIC_ASSERT(IS_POWER_OF_TWO(kHalfStep));
|
||||
static_assert(base::bits::IsPowerOfTwo(kHalfStep),
|
||||
"Code relies on kStep and kHalfStep being a power of two");
|
||||
|
||||
explicit LifetimePosition(int value) : value_(value) {}
|
||||
|
||||
|
@ -1310,7 +1310,7 @@ bool TryMatchShiftFromMul(InstructionSelector* selector, Node* node) {
|
||||
Node* left = m.left().node();
|
||||
Node* right = m.right().node();
|
||||
if (g.CanBeImmediate(right, OperandMode::kInt32Imm) &&
|
||||
base::bits::IsPowerOfTwo64(g.GetImmediate(right))) {
|
||||
base::bits::IsPowerOfTwo(g.GetImmediate(right))) {
|
||||
int power = 63 - base::bits::CountLeadingZeros64(g.GetImmediate(right));
|
||||
bool doZeroExt = DoZeroExtForResult(node);
|
||||
bool canEliminateZeroExt = ProduceWord32Result(left);
|
||||
|
@ -424,7 +424,7 @@ double InternalStringToInt(UnicodeCache* unicode_cache,
|
||||
return JunkStringValue();
|
||||
}
|
||||
|
||||
if (base::bits::IsPowerOfTwo32(radix)) {
|
||||
if (base::bits::IsPowerOfTwo(radix)) {
|
||||
switch (radix) {
|
||||
case 2:
|
||||
return InternalStringToIntDouble<1>(
|
||||
|
@ -634,8 +634,8 @@ static inline Handle<String> MakeOrFindTwoCharacterString(Isolate* isolate,
|
||||
// when building the new string.
|
||||
if (static_cast<unsigned>(c1 | c2) <= String::kMaxOneByteCharCodeU) {
|
||||
// We can do this.
|
||||
DCHECK(base::bits::IsPowerOfTwo32(String::kMaxOneByteCharCodeU +
|
||||
1)); // because of this.
|
||||
DCHECK(base::bits::IsPowerOfTwo(String::kMaxOneByteCharCodeU +
|
||||
1)); // because of this.
|
||||
Handle<SeqOneByteString> str =
|
||||
isolate->factory()->NewRawOneByteString(2).ToHandleChecked();
|
||||
uint8_t* dest = str->GetChars();
|
||||
|
@ -2161,7 +2161,7 @@ Code* InnerPointerToCodeCache::GcSafeFindCodeForInnerPointer(
|
||||
InnerPointerToCodeCache::InnerPointerToCodeCacheEntry*
|
||||
InnerPointerToCodeCache::GetCacheEntry(Address inner_pointer) {
|
||||
isolate_->counters()->pc_to_code()->Increment();
|
||||
DCHECK(base::bits::IsPowerOfTwo32(kInnerPointerToCodeCacheSize));
|
||||
DCHECK(base::bits::IsPowerOfTwo(kInnerPointerToCodeCacheSize));
|
||||
uint32_t hash = ComputeIntegerHash(ObjectAddressForHashing(inner_pointer));
|
||||
uint32_t index = hash & (kInnerPointerToCodeCacheSize - 1);
|
||||
InnerPointerToCodeCacheEntry* entry = cache(index);
|
||||
|
@ -230,7 +230,7 @@ class MachOSection : public DebugSectionBase<MachOSectionHeader> {
|
||||
uint32_t flags)
|
||||
: name_(name), segment_(segment), align_(align), flags_(flags) {
|
||||
if (align_ != 0) {
|
||||
DCHECK(base::bits::IsPowerOfTwo32(align));
|
||||
DCHECK(base::bits::IsPowerOfTwo(align));
|
||||
align_ = WhichPowerOf2(align_);
|
||||
}
|
||||
}
|
||||
|
@ -35,8 +35,7 @@ void SequentialMarkingDeque::StartUsing() {
|
||||
size_t size = FLAG_force_marking_deque_overflows
|
||||
? 64 * kPointerSize
|
||||
: backing_store_committed_size_;
|
||||
DCHECK(
|
||||
base::bits::IsPowerOfTwo32(static_cast<uint32_t>(size / kPointerSize)));
|
||||
DCHECK(base::bits::IsPowerOfTwo(static_cast<uint32_t>(size / kPointerSize)));
|
||||
mask_ = static_cast<int>((size / kPointerSize) - 1);
|
||||
top_ = bottom_ = 0;
|
||||
overflowed_ = false;
|
||||
|
@ -1157,7 +1157,7 @@ size_t MemoryAllocator::CodePageAreaEndOffset() {
|
||||
|
||||
intptr_t MemoryAllocator::GetCommitPageSize() {
|
||||
if (FLAG_v8_os_page_size != 0) {
|
||||
DCHECK(base::bits::IsPowerOfTwo32(FLAG_v8_os_page_size));
|
||||
DCHECK(base::bits::IsPowerOfTwo(FLAG_v8_os_page_size));
|
||||
return FLAG_v8_os_page_size * KB;
|
||||
} else {
|
||||
return base::OS::CommitPageSize();
|
||||
@ -1688,7 +1688,7 @@ void PagedSpace::Verify(ObjectVisitor* visitor) {
|
||||
bool NewSpace::SetUp(size_t initial_semispace_capacity,
|
||||
size_t maximum_semispace_capacity) {
|
||||
DCHECK(initial_semispace_capacity <= maximum_semispace_capacity);
|
||||
DCHECK(base::bits::IsPowerOfTwo32(
|
||||
DCHECK(base::bits::IsPowerOfTwo(
|
||||
static_cast<uint32_t>(maximum_semispace_capacity)));
|
||||
|
||||
to_space_.SetUp(initial_semispace_capacity, maximum_semispace_capacity);
|
||||
|
@ -2847,7 +2847,7 @@ class MapSpace : public PagedSpace {
|
||||
: PagedSpace(heap, id, NOT_EXECUTABLE) {}
|
||||
|
||||
int RoundSizeDownToObjectAlignment(int size) override {
|
||||
if (base::bits::IsPowerOfTwo32(Map::kSize)) {
|
||||
if (base::bits::IsPowerOfTwo(Map::kSize)) {
|
||||
return RoundDown(size, Map::kSize);
|
||||
} else {
|
||||
return (size / Map::kSize) * Map::kSize;
|
||||
|
@ -375,7 +375,7 @@ void Assembler::GetCode(Isolate* isolate, CodeDesc* desc) {
|
||||
|
||||
|
||||
void Assembler::Align(int m) {
|
||||
DCHECK(base::bits::IsPowerOfTwo32(m));
|
||||
DCHECK(base::bits::IsPowerOfTwo(m));
|
||||
int mask = m - 1;
|
||||
int addr = pc_offset();
|
||||
Nop((m - (addr & mask)) & mask);
|
||||
|
@ -1036,7 +1036,7 @@ void MacroAssembler::EnterExitFrameEpilogue(int argc, bool save_doubles) {
|
||||
// Get the required frame alignment for the OS.
|
||||
const int kFrameAlignment = base::OS::ActivationFrameAlignment();
|
||||
if (kFrameAlignment > 0) {
|
||||
DCHECK(base::bits::IsPowerOfTwo32(kFrameAlignment));
|
||||
DCHECK(base::bits::IsPowerOfTwo(kFrameAlignment));
|
||||
and_(esp, -kFrameAlignment);
|
||||
}
|
||||
|
||||
@ -1495,7 +1495,7 @@ void MacroAssembler::BooleanBitTest(Register object,
|
||||
int field_offset,
|
||||
int bit_index) {
|
||||
bit_index += kSmiTagSize + kSmiShiftSize;
|
||||
DCHECK(base::bits::IsPowerOfTwo32(kBitsPerByte));
|
||||
DCHECK(base::bits::IsPowerOfTwo(kBitsPerByte));
|
||||
int byte_index = bit_index / kBitsPerByte;
|
||||
int byte_bit_index = bit_index & (kBitsPerByte - 1);
|
||||
test_b(FieldOperand(object, field_offset + byte_index),
|
||||
@ -2315,7 +2315,7 @@ void TurboAssembler::CheckStackAlignment() {
|
||||
int frame_alignment = base::OS::ActivationFrameAlignment();
|
||||
int frame_alignment_mask = frame_alignment - 1;
|
||||
if (frame_alignment > kPointerSize) {
|
||||
DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
|
||||
DCHECK(base::bits::IsPowerOfTwo(frame_alignment));
|
||||
Label alignment_as_expected;
|
||||
test(esp, Immediate(frame_alignment_mask));
|
||||
j(zero, &alignment_as_expected);
|
||||
@ -2478,7 +2478,7 @@ void TurboAssembler::PrepareCallCFunction(int num_arguments, Register scratch) {
|
||||
// and the original value of esp.
|
||||
mov(scratch, esp);
|
||||
sub(esp, Immediate((num_arguments + 1) * kPointerSize));
|
||||
DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
|
||||
DCHECK(base::bits::IsPowerOfTwo(frame_alignment));
|
||||
and_(esp, -frame_alignment);
|
||||
mov(Operand(esp, num_arguments * kPointerSize), scratch);
|
||||
} else {
|
||||
|
@ -21,8 +21,8 @@ StubCache::StubCache(Isolate* isolate, Code::Kind ic_kind)
|
||||
}
|
||||
|
||||
void StubCache::Initialize() {
|
||||
DCHECK(base::bits::IsPowerOfTwo32(kPrimaryTableSize));
|
||||
DCHECK(base::bits::IsPowerOfTwo32(kSecondaryTableSize));
|
||||
DCHECK(base::bits::IsPowerOfTwo(kPrimaryTableSize));
|
||||
DCHECK(base::bits::IsPowerOfTwo(kSecondaryTableSize));
|
||||
Clear();
|
||||
}
|
||||
|
||||
|
@ -150,7 +150,7 @@ Handle<FixedArray> ConstantArrayBuilder::ToFixedArray(Isolate* isolate) {
|
||||
for (const ConstantArraySlice* slice : idx_slice_) {
|
||||
DCHECK_EQ(slice->reserved(), 0);
|
||||
DCHECK(array_index == 0 ||
|
||||
base::bits::IsPowerOfTwo32(static_cast<uint32_t>(array_index)));
|
||||
base::bits::IsPowerOfTwo(static_cast<uint32_t>(array_index)));
|
||||
#if DEBUG
|
||||
// Different slices might contain the same element due to reservations, but
|
||||
// all elements within a slice should be unique. If this DCHECK fails, then
|
||||
|
@ -352,7 +352,7 @@ void Assembler::GetCode(Isolate* isolate, CodeDesc* desc) {
|
||||
|
||||
|
||||
void Assembler::Align(int m) {
|
||||
DCHECK(m >= 4 && base::bits::IsPowerOfTwo32(m));
|
||||
DCHECK(m >= 4 && base::bits::IsPowerOfTwo(m));
|
||||
EmitForbiddenSlotInstruction();
|
||||
while ((pc_offset() & (m - 1)) != 0) {
|
||||
nop();
|
||||
|
@ -2417,7 +2417,7 @@ void ProfileEntryHookStub::Generate(MacroAssembler* masm) {
|
||||
int frame_alignment = masm->ActivationFrameAlignment();
|
||||
if (frame_alignment > kPointerSize) {
|
||||
__ mov(s5, sp);
|
||||
DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
|
||||
DCHECK(base::bits::IsPowerOfTwo(frame_alignment));
|
||||
__ And(sp, sp, Operand(-frame_alignment));
|
||||
}
|
||||
__ Subu(sp, sp, kCArgsSlotsSize);
|
||||
|
@ -5351,7 +5351,7 @@ void MacroAssembler::EnterExitFrame(bool save_doubles, int stack_space,
|
||||
// The stack must be allign to 0 modulo 8 for stores with sdc1.
|
||||
DCHECK(kDoubleSize == frame_alignment);
|
||||
if (frame_alignment > 0) {
|
||||
DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
|
||||
DCHECK(base::bits::IsPowerOfTwo(frame_alignment));
|
||||
And(sp, sp, Operand(-frame_alignment)); // Align stack.
|
||||
}
|
||||
int space = FPURegister::kMaxNumRegisters * kDoubleSize;
|
||||
@ -5369,7 +5369,7 @@ void MacroAssembler::EnterExitFrame(bool save_doubles, int stack_space,
|
||||
DCHECK(stack_space >= 0);
|
||||
Subu(sp, sp, Operand((stack_space + 2) * kPointerSize));
|
||||
if (frame_alignment > 0) {
|
||||
DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
|
||||
DCHECK(base::bits::IsPowerOfTwo(frame_alignment));
|
||||
And(sp, sp, Operand(-frame_alignment)); // Align stack.
|
||||
}
|
||||
|
||||
@ -5454,7 +5454,7 @@ void MacroAssembler::AssertStackIsAligned() {
|
||||
|
||||
if (frame_alignment > kPointerSize) {
|
||||
Label alignment_as_expected;
|
||||
DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
|
||||
DCHECK(base::bits::IsPowerOfTwo(frame_alignment));
|
||||
andi(at, sp, frame_alignment_mask);
|
||||
Branch(&alignment_as_expected, eq, at, Operand(zero_reg));
|
||||
// Don't use Check here, as it will call Runtime_Abort re-entering here.
|
||||
@ -5939,7 +5939,7 @@ void TurboAssembler::PrepareCallCFunction(int num_reg_arguments,
|
||||
// and the original value of sp.
|
||||
mov(scratch, sp);
|
||||
Subu(sp, sp, Operand((stack_passed_arguments + 1) * kPointerSize));
|
||||
DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
|
||||
DCHECK(base::bits::IsPowerOfTwo(frame_alignment));
|
||||
And(sp, sp, Operand(-frame_alignment));
|
||||
sw(scratch, MemOperand(sp, stack_passed_arguments * kPointerSize));
|
||||
} else {
|
||||
@ -6002,7 +6002,7 @@ void TurboAssembler::CallCFunctionHelper(Register function_base,
|
||||
int frame_alignment = base::OS::ActivationFrameAlignment();
|
||||
int frame_alignment_mask = frame_alignment - 1;
|
||||
if (frame_alignment > kPointerSize) {
|
||||
DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
|
||||
DCHECK(base::bits::IsPowerOfTwo(frame_alignment));
|
||||
Label alignment_as_expected;
|
||||
And(at, sp, Operand(frame_alignment_mask));
|
||||
Branch(&alignment_as_expected, eq, at, Operand(zero_reg));
|
||||
|
@ -333,7 +333,7 @@ void Assembler::GetCode(Isolate* isolate, CodeDesc* desc) {
|
||||
|
||||
|
||||
void Assembler::Align(int m) {
|
||||
DCHECK(m >= 4 && base::bits::IsPowerOfTwo32(m));
|
||||
DCHECK(m >= 4 && base::bits::IsPowerOfTwo(m));
|
||||
EmitForbiddenSlotInstruction();
|
||||
while ((pc_offset() & (m - 1)) != 0) {
|
||||
nop();
|
||||
|
@ -2420,7 +2420,7 @@ void ProfileEntryHookStub::Generate(MacroAssembler* masm) {
|
||||
int frame_alignment = masm->ActivationFrameAlignment();
|
||||
if (frame_alignment > kPointerSize) {
|
||||
__ mov(s5, sp);
|
||||
DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
|
||||
DCHECK(base::bits::IsPowerOfTwo(frame_alignment));
|
||||
__ And(sp, sp, Operand(-frame_alignment));
|
||||
}
|
||||
|
||||
|
@ -1611,7 +1611,7 @@ int TurboAssembler::InstrCountForLi64Bit(int64_t value) {
|
||||
((value >> 31) & 0x1ffff) == ((0x20000 - bit31) & 0x1ffff) &&
|
||||
kArchVariant == kMips64r6) {
|
||||
return 2;
|
||||
} else if (base::bits::IsPowerOfTwo64(value + 1)) {
|
||||
} else if (base::bits::IsPowerOfTwo(value + 1)) {
|
||||
return 2;
|
||||
} else {
|
||||
int shift_cnt = base::bits::CountTrailingZeros64(value);
|
||||
@ -1733,7 +1733,7 @@ void TurboAssembler::li_optimized(Register rd, Operand j, LiFlags mode) {
|
||||
// 16 MSBs contain a signed 16-bit number.
|
||||
daddiu(rd, zero_reg, j.immediate() & kImm16Mask);
|
||||
dati(rd, ((j.immediate() >> 48) + bit31) & kImm16Mask);
|
||||
} else if (base::bits::IsPowerOfTwo64(j.immediate() + 1)) {
|
||||
} else if (base::bits::IsPowerOfTwo(j.immediate() + 1)) {
|
||||
// 64-bit values which have their "n" MSBs set to one, and their
|
||||
// "64-n" LSBs set to zero. "n" must meet the restrictions 0 < n < 64.
|
||||
int shift_cnt = 64 - base::bits::CountTrailingZeros64(j.immediate() + 1);
|
||||
@ -5828,7 +5828,7 @@ void MacroAssembler::EnterExitFrame(bool save_doubles, int stack_space,
|
||||
DCHECK(stack_space >= 0);
|
||||
Dsubu(sp, sp, Operand((stack_space + 2) * kPointerSize));
|
||||
if (frame_alignment > 0) {
|
||||
DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
|
||||
DCHECK(base::bits::IsPowerOfTwo(frame_alignment));
|
||||
And(sp, sp, Operand(-frame_alignment)); // Align stack.
|
||||
}
|
||||
|
||||
@ -5915,7 +5915,7 @@ void MacroAssembler::AssertStackIsAligned() {
|
||||
|
||||
if (frame_alignment > kPointerSize) {
|
||||
Label alignment_as_expected;
|
||||
DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
|
||||
DCHECK(base::bits::IsPowerOfTwo(frame_alignment));
|
||||
andi(at, sp, frame_alignment_mask);
|
||||
Branch(&alignment_as_expected, eq, at, Operand(zero_reg));
|
||||
// Don't use Check here, as it will call Runtime_Abort re-entering here.
|
||||
@ -6460,7 +6460,7 @@ void TurboAssembler::PrepareCallCFunction(int num_reg_arguments,
|
||||
// and the original value of sp.
|
||||
mov(scratch, sp);
|
||||
Dsubu(sp, sp, Operand((stack_passed_arguments + 1) * kPointerSize));
|
||||
DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
|
||||
DCHECK(base::bits::IsPowerOfTwo(frame_alignment));
|
||||
And(sp, sp, Operand(-frame_alignment));
|
||||
Sd(scratch, MemOperand(sp, stack_passed_arguments * kPointerSize));
|
||||
} else {
|
||||
@ -6510,7 +6510,7 @@ void TurboAssembler::CallCFunctionHelper(Register function,
|
||||
int frame_alignment = base::OS::ActivationFrameAlignment();
|
||||
int frame_alignment_mask = frame_alignment - 1;
|
||||
if (frame_alignment > kPointerSize) {
|
||||
DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
|
||||
DCHECK(base::bits::IsPowerOfTwo(frame_alignment));
|
||||
Label alignment_as_expected;
|
||||
And(at, sp, Operand(frame_alignment_mask));
|
||||
Branch(&alignment_as_expected, eq, at, Operand(zero_reg));
|
||||
|
@ -16441,7 +16441,7 @@ Handle<Derived> HashTable<Derived, Shape>::New(
|
||||
MinimumCapacity capacity_option) {
|
||||
DCHECK(0 <= at_least_space_for);
|
||||
DCHECK_IMPLIES(capacity_option == USE_CUSTOM_MINIMUM_CAPACITY,
|
||||
base::bits::IsPowerOfTwo32(at_least_space_for));
|
||||
base::bits::IsPowerOfTwo(at_least_space_for));
|
||||
|
||||
int capacity = (capacity_option == USE_CUSTOM_MINIMUM_CAPACITY)
|
||||
? at_least_space_for
|
||||
|
@ -114,7 +114,7 @@ class V8_EXPORT_PRIVATE HashTableBase : public NON_EXPORTED_BASE(FixedArray) {
|
||||
|
||||
// Returns probe entry.
|
||||
static uint32_t GetProbe(uint32_t hash, uint32_t number, uint32_t size) {
|
||||
DCHECK(base::bits::IsPowerOfTwo32(size));
|
||||
DCHECK(base::bits::IsPowerOfTwo(size));
|
||||
return (hash + GetProbeOffset(number)) & (size - 1);
|
||||
}
|
||||
|
||||
@ -214,7 +214,7 @@ class HashTable : public HashTableBase {
|
||||
private:
|
||||
// Ensure that kMaxRegularCapacity yields a non-large object dictionary.
|
||||
STATIC_ASSERT(EntryToIndex(kMaxRegularCapacity) < kMaxRegularLength);
|
||||
STATIC_ASSERT(v8::base::bits::IsPowerOfTwo32(kMaxRegularCapacity));
|
||||
STATIC_ASSERT(v8::base::bits::IsPowerOfTwo(kMaxRegularCapacity));
|
||||
static const int kMaxRegularEntry = kMaxRegularCapacity / kEntrySize;
|
||||
static const int kMaxRegularIndex = EntryToIndex(kMaxRegularEntry);
|
||||
STATIC_ASSERT(OffsetOfElementAt(kMaxRegularIndex) <
|
||||
|
@ -107,7 +107,8 @@ class Name : public HeapObject {
|
||||
// Check that kMaxCachedArrayIndexLength + 1 is a power of two so we
|
||||
// could use a mask to test if the length of string is less than or equal to
|
||||
// kMaxCachedArrayIndexLength.
|
||||
STATIC_ASSERT(IS_POWER_OF_TWO(kMaxCachedArrayIndexLength + 1));
|
||||
static_assert(base::bits::IsPowerOfTwo(kMaxCachedArrayIndexLength + 1),
|
||||
"(kMaxCachedArrayIndexLength + 1) must be power of two");
|
||||
|
||||
// When any of these bits is set then the hash field does not contain a cached
|
||||
// array index.
|
||||
|
@ -5,6 +5,7 @@
|
||||
#ifndef V8_OBJECTS_STRING_H_
|
||||
#define V8_OBJECTS_STRING_H_
|
||||
|
||||
#include "src/base/bits.h"
|
||||
#include "src/objects/name.h"
|
||||
|
||||
// Has to be the last include (doesn't have include guards):
|
||||
@ -824,7 +825,8 @@ class ConsStringIterator {
|
||||
static const int kStackSize = 32;
|
||||
// Use a mask instead of doing modulo operations for stack wrapping.
|
||||
static const int kDepthMask = kStackSize - 1;
|
||||
STATIC_ASSERT(IS_POWER_OF_TWO(kStackSize));
|
||||
static_assert(base::bits::IsPowerOfTwo(kStackSize),
|
||||
"kStackSize must be power of two");
|
||||
static inline int OffsetForDepth(int depth);
|
||||
|
||||
inline void PushLeft(ConsString* string);
|
||||
|
@ -268,7 +268,7 @@ void Assembler::GetCode(Isolate* isolate, CodeDesc* desc) {
|
||||
|
||||
|
||||
void Assembler::Align(int m) {
|
||||
DCHECK(m >= 4 && base::bits::IsPowerOfTwo32(m));
|
||||
DCHECK(m >= 4 && base::bits::IsPowerOfTwo(m));
|
||||
DCHECK((pc_offset() & (kInstrSize - 1)) == 0);
|
||||
while ((pc_offset() & (m - 1)) != 0) {
|
||||
nop();
|
||||
|
@ -2377,7 +2377,7 @@ void ProfileEntryHookStub::Generate(MacroAssembler* masm) {
|
||||
int frame_alignment = masm->ActivationFrameAlignment();
|
||||
if (frame_alignment > kPointerSize) {
|
||||
__ mr(r15, sp);
|
||||
DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
|
||||
DCHECK(base::bits::IsPowerOfTwo(frame_alignment));
|
||||
__ ClearRightImm(sp, sp, Operand(WhichPowerOf2(frame_alignment)));
|
||||
}
|
||||
|
||||
|
@ -1184,7 +1184,7 @@ void MacroAssembler::EnterExitFrame(bool save_doubles, int stack_space,
|
||||
// function.
|
||||
const int frame_alignment = ActivationFrameAlignment();
|
||||
if (frame_alignment > kPointerSize) {
|
||||
DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
|
||||
DCHECK(base::bits::IsPowerOfTwo(frame_alignment));
|
||||
ClearRightImm(sp, sp, Operand(WhichPowerOf2(frame_alignment)));
|
||||
}
|
||||
li(r0, Operand::Zero());
|
||||
@ -2797,7 +2797,7 @@ void MacroAssembler::PrepareCallCFunction(int num_reg_arguments,
|
||||
// -- preserving original value of sp.
|
||||
mr(scratch, sp);
|
||||
addi(sp, sp, Operand(-(stack_passed_arguments + 1) * kPointerSize));
|
||||
DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
|
||||
DCHECK(base::bits::IsPowerOfTwo(frame_alignment));
|
||||
ClearRightImm(sp, sp, Operand(WhichPowerOf2(frame_alignment)));
|
||||
StoreP(scratch, MemOperand(sp, stack_passed_arguments * kPointerSize));
|
||||
} else {
|
||||
|
@ -1091,7 +1091,7 @@ void RegExpMacroAssemblerMIPS::CallCheckStackGuardState(Register scratch) {
|
||||
// Align the stack pointer and save the original sp value on the stack.
|
||||
__ mov(scratch, sp);
|
||||
__ Subu(sp, sp, Operand(kPointerSize));
|
||||
DCHECK(base::bits::IsPowerOfTwo32(stack_alignment));
|
||||
DCHECK(base::bits::IsPowerOfTwo(stack_alignment));
|
||||
__ And(sp, sp, Operand(-stack_alignment));
|
||||
__ sw(scratch, MemOperand(sp));
|
||||
|
||||
|
@ -1129,7 +1129,7 @@ void RegExpMacroAssemblerMIPS::CallCheckStackGuardState(Register scratch) {
|
||||
// Align the stack pointer and save the original sp value on the stack.
|
||||
__ mov(scratch, sp);
|
||||
__ Dsubu(sp, sp, Operand(kPointerSize));
|
||||
DCHECK(base::bits::IsPowerOfTwo32(stack_alignment));
|
||||
DCHECK(base::bits::IsPowerOfTwo(stack_alignment));
|
||||
__ And(sp, sp, Operand(-stack_alignment));
|
||||
__ Sd(scratch, MemOperand(sp));
|
||||
|
||||
|
@ -1101,7 +1101,7 @@ void RegExpMacroAssemblerPPC::CallCheckStackGuardState(Register scratch) {
|
||||
// -- preserving original value of sp.
|
||||
__ mr(scratch, sp);
|
||||
__ addi(sp, sp, Operand(-(stack_passed_arguments + 1) * kPointerSize));
|
||||
DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
|
||||
DCHECK(base::bits::IsPowerOfTwo(frame_alignment));
|
||||
__ ClearRightImm(sp, sp, Operand(WhichPowerOf2(frame_alignment)));
|
||||
__ StoreP(scratch, MemOperand(sp, stack_passed_arguments * kPointerSize));
|
||||
} else {
|
||||
|
@ -360,7 +360,7 @@ void Assembler::GetCode(Isolate* isloate, CodeDesc* desc) {
|
||||
}
|
||||
|
||||
void Assembler::Align(int m) {
|
||||
DCHECK(m >= 4 && base::bits::IsPowerOfTwo32(m));
|
||||
DCHECK(m >= 4 && base::bits::IsPowerOfTwo(m));
|
||||
while ((pc_offset() & (m - 1)) != 0) {
|
||||
nop(0);
|
||||
}
|
||||
|
@ -2323,7 +2323,7 @@ void ProfileEntryHookStub::Generate(MacroAssembler* masm) {
|
||||
int frame_alignment = masm->ActivationFrameAlignment();
|
||||
if (frame_alignment > kPointerSize) {
|
||||
__ LoadRR(r7, sp);
|
||||
DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
|
||||
DCHECK(base::bits::IsPowerOfTwo(frame_alignment));
|
||||
__ ClearRightImm(sp, sp, Operand(WhichPowerOf2(frame_alignment)));
|
||||
}
|
||||
|
||||
|
@ -2541,7 +2541,7 @@ void MacroAssembler::PrepareCallCFunction(int num_reg_arguments,
|
||||
// -- preserving original value of sp.
|
||||
LoadRR(scratch, sp);
|
||||
lay(sp, MemOperand(sp, -(stack_passed_arguments + 1) * kPointerSize));
|
||||
DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
|
||||
DCHECK(base::bits::IsPowerOfTwo(frame_alignment));
|
||||
ClearRightImm(sp, sp, Operand(WhichPowerOf2(frame_alignment)));
|
||||
StoreP(scratch, MemOperand(sp, (stack_passed_arguments)*kPointerSize));
|
||||
} else {
|
||||
@ -2627,7 +2627,7 @@ void MacroAssembler::CheckPageFlag(
|
||||
DCHECK(cc == ne || cc == eq);
|
||||
ClearRightImm(scratch, object, Operand(kPageSizeBits));
|
||||
|
||||
if (base::bits::IsPowerOfTwo32(mask)) {
|
||||
if (base::bits::IsPowerOfTwo(mask)) {
|
||||
// If it's a power of two, we can use Test-Under-Mask Memory-Imm form
|
||||
// which allows testing of a single byte in memory.
|
||||
int32_t byte_offset = 4;
|
||||
@ -3922,7 +3922,7 @@ void MacroAssembler::AndP(Register dst, Register src, const Operand& opnd) {
|
||||
// than power of 2, we have consecutive bits of 1.
|
||||
// Special case: If shift_value is zero, we cannot use RISBG, as it requires
|
||||
// selection of at least 1 bit.
|
||||
if ((0 != shifted_value) && base::bits::IsPowerOfTwo64(shifted_value + 1)) {
|
||||
if ((0 != shifted_value) && base::bits::IsPowerOfTwo(shifted_value + 1)) {
|
||||
int startBit =
|
||||
base::bits::CountLeadingZeros64(shifted_value) - trailing_zeros;
|
||||
int endBit = 63 - trailing_zeros;
|
||||
|
@ -6,6 +6,7 @@
|
||||
#define V8_SNAPSHOT_SERIALIZER_COMMON_H_
|
||||
|
||||
#include "src/address-map.h"
|
||||
#include "src/base/bits.h"
|
||||
#include "src/external-reference-table.h"
|
||||
#include "src/globals.h"
|
||||
#include "src/visitors.h"
|
||||
@ -63,7 +64,7 @@ class HotObjectsList {
|
||||
static const int kSize = 8;
|
||||
|
||||
private:
|
||||
STATIC_ASSERT(IS_POWER_OF_TWO(kSize));
|
||||
static_assert(base::bits::IsPowerOfTwo(kSize), "kSize must be power of two");
|
||||
static const int kSizeMask = kSize - 1;
|
||||
HeapObject* circular_queue_[kSize];
|
||||
int index_;
|
||||
|
@ -55,7 +55,7 @@ inline bool CStringEquals(const char* s1, const char* s2) {
|
||||
|
||||
// X must be a power of 2. Returns the number of trailing zeros.
|
||||
inline int WhichPowerOf2(uint32_t x) {
|
||||
DCHECK(base::bits::IsPowerOfTwo32(x));
|
||||
DCHECK(base::bits::IsPowerOfTwo(x));
|
||||
int bits = 0;
|
||||
#ifdef DEBUG
|
||||
uint32_t original_x = x;
|
||||
@ -86,7 +86,7 @@ inline int WhichPowerOf2(uint32_t x) {
|
||||
|
||||
// X must be a power of 2. Returns the number of trailing zeros.
|
||||
inline int WhichPowerOf2_64(uint64_t x) {
|
||||
DCHECK(base::bits::IsPowerOfTwo64(x));
|
||||
DCHECK(base::bits::IsPowerOfTwo(x));
|
||||
int bits = 0;
|
||||
#ifdef DEBUG
|
||||
uint64_t original_x = x;
|
||||
|
@ -351,7 +351,7 @@ void Assembler::GetCode(Isolate* isolate, CodeDesc* desc) {
|
||||
|
||||
|
||||
void Assembler::Align(int m) {
|
||||
DCHECK(base::bits::IsPowerOfTwo32(m));
|
||||
DCHECK(base::bits::IsPowerOfTwo(m));
|
||||
int delta = (m - (pc_offset() & (m - 1))) & (m - 1);
|
||||
Nop(delta);
|
||||
}
|
||||
|
@ -539,7 +539,7 @@ void TurboAssembler::CheckStackAlignment() {
|
||||
int frame_alignment = base::OS::ActivationFrameAlignment();
|
||||
int frame_alignment_mask = frame_alignment - 1;
|
||||
if (frame_alignment > kPointerSize) {
|
||||
DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
|
||||
DCHECK(base::bits::IsPowerOfTwo(frame_alignment));
|
||||
Label alignment_as_expected;
|
||||
testp(rsp, Immediate(frame_alignment_mask));
|
||||
j(zero, &alignment_as_expected, Label::kNear);
|
||||
@ -4115,7 +4115,7 @@ void MacroAssembler::EnterExitFrameEpilogue(int arg_stack_space,
|
||||
// Get the required frame alignment for the OS.
|
||||
const int kFrameAlignment = base::OS::ActivationFrameAlignment();
|
||||
if (kFrameAlignment > 0) {
|
||||
DCHECK(base::bits::IsPowerOfTwo32(kFrameAlignment));
|
||||
DCHECK(base::bits::IsPowerOfTwo(kFrameAlignment));
|
||||
DCHECK(is_int8(kFrameAlignment));
|
||||
andp(rsp, Immediate(-kFrameAlignment));
|
||||
}
|
||||
@ -4604,7 +4604,7 @@ void TurboAssembler::PrepareCallCFunction(int num_arguments) {
|
||||
|
||||
// Make stack end at alignment and allocate space for arguments and old rsp.
|
||||
movp(kScratchRegister, rsp);
|
||||
DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
|
||||
DCHECK(base::bits::IsPowerOfTwo(frame_alignment));
|
||||
int argument_slots_on_stack =
|
||||
ArgumentStackSlotsForCFunctionCall(num_arguments);
|
||||
subp(rsp, Immediate((argument_slots_on_stack + 1) * kRegisterSize));
|
||||
|
@ -253,7 +253,7 @@ void Assembler::GetCode(CodeDesc* desc) {
|
||||
|
||||
|
||||
void Assembler::Align(int m) {
|
||||
DCHECK(base::bits::IsPowerOfTwo32(m));
|
||||
DCHECK(base::bits::IsPowerOfTwo(m));
|
||||
int mask = m - 1;
|
||||
int addr = pc_offset();
|
||||
Nop((m - (addr & mask)) & mask);
|
||||
|
@ -946,7 +946,7 @@ void MacroAssembler::EnterExitFrameEpilogue(int argc, bool save_doubles) {
|
||||
// Get the required frame alignment for the OS.
|
||||
const int kFrameAlignment = base::OS::ActivationFrameAlignment();
|
||||
if (kFrameAlignment > 0) {
|
||||
DCHECK(base::bits::IsPowerOfTwo32(kFrameAlignment));
|
||||
DCHECK(base::bits::IsPowerOfTwo(kFrameAlignment));
|
||||
and_(esp, -kFrameAlignment);
|
||||
}
|
||||
|
||||
@ -1402,7 +1402,7 @@ void MacroAssembler::BooleanBitTest(Register object,
|
||||
int field_offset,
|
||||
int bit_index) {
|
||||
bit_index += kSmiTagSize + kSmiShiftSize;
|
||||
DCHECK(base::bits::IsPowerOfTwo32(kBitsPerByte));
|
||||
DCHECK(base::bits::IsPowerOfTwo(kBitsPerByte));
|
||||
int byte_index = bit_index / kBitsPerByte;
|
||||
int byte_bit_index = bit_index & (kBitsPerByte - 1);
|
||||
test_b(FieldOperand(object, field_offset + byte_index),
|
||||
@ -2064,7 +2064,7 @@ void MacroAssembler::CheckStackAlignment() {
|
||||
int frame_alignment = base::OS::ActivationFrameAlignment();
|
||||
int frame_alignment_mask = frame_alignment - 1;
|
||||
if (frame_alignment > kPointerSize) {
|
||||
DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
|
||||
DCHECK(base::bits::IsPowerOfTwo(frame_alignment));
|
||||
Label alignment_as_expected;
|
||||
test(esp, Immediate(frame_alignment_mask));
|
||||
j(zero, &alignment_as_expected);
|
||||
@ -2221,7 +2221,7 @@ void MacroAssembler::PrepareCallCFunction(int num_arguments, Register scratch) {
|
||||
// and the original value of esp.
|
||||
mov(scratch, esp);
|
||||
sub(esp, Immediate((num_arguments + 1) * kPointerSize));
|
||||
DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
|
||||
DCHECK(base::bits::IsPowerOfTwo(frame_alignment));
|
||||
and_(esp, -frame_alignment);
|
||||
mov(Operand(esp, num_arguments * kPointerSize), scratch);
|
||||
} else {
|
||||
|
@ -86,30 +86,30 @@ TEST(Bits, CountTrailingZeros64) {
|
||||
|
||||
|
||||
TEST(Bits, IsPowerOfTwo32) {
|
||||
EXPECT_FALSE(IsPowerOfTwo32(0U));
|
||||
EXPECT_FALSE(IsPowerOfTwo(0U));
|
||||
TRACED_FORRANGE(uint32_t, shift, 0, 31) {
|
||||
EXPECT_TRUE(IsPowerOfTwo32(1U << shift));
|
||||
EXPECT_FALSE(IsPowerOfTwo32((1U << shift) + 5U));
|
||||
EXPECT_FALSE(IsPowerOfTwo32(~(1U << shift)));
|
||||
EXPECT_TRUE(IsPowerOfTwo(1U << shift));
|
||||
EXPECT_FALSE(IsPowerOfTwo((1U << shift) + 5U));
|
||||
EXPECT_FALSE(IsPowerOfTwo(~(1U << shift)));
|
||||
}
|
||||
TRACED_FORRANGE(uint32_t, shift, 2, 31) {
|
||||
EXPECT_FALSE(IsPowerOfTwo32((1U << shift) - 1U));
|
||||
EXPECT_FALSE(IsPowerOfTwo((1U << shift) - 1U));
|
||||
}
|
||||
EXPECT_FALSE(IsPowerOfTwo32(0xffffffff));
|
||||
EXPECT_FALSE(IsPowerOfTwo(0xffffffff));
|
||||
}
|
||||
|
||||
|
||||
TEST(Bits, IsPowerOfTwo64) {
|
||||
EXPECT_FALSE(IsPowerOfTwo64(0U));
|
||||
EXPECT_FALSE(IsPowerOfTwo(V8_UINT64_C(0)));
|
||||
TRACED_FORRANGE(uint32_t, shift, 0, 63) {
|
||||
EXPECT_TRUE(IsPowerOfTwo64(V8_UINT64_C(1) << shift));
|
||||
EXPECT_FALSE(IsPowerOfTwo64((V8_UINT64_C(1) << shift) + 5U));
|
||||
EXPECT_FALSE(IsPowerOfTwo64(~(V8_UINT64_C(1) << shift)));
|
||||
EXPECT_TRUE(IsPowerOfTwo(V8_UINT64_C(1) << shift));
|
||||
EXPECT_FALSE(IsPowerOfTwo((V8_UINT64_C(1) << shift) + 5U));
|
||||
EXPECT_FALSE(IsPowerOfTwo(~(V8_UINT64_C(1) << shift)));
|
||||
}
|
||||
TRACED_FORRANGE(uint32_t, shift, 2, 63) {
|
||||
EXPECT_FALSE(IsPowerOfTwo64((V8_UINT64_C(1) << shift) - 1U));
|
||||
EXPECT_FALSE(IsPowerOfTwo((V8_UINT64_C(1) << shift) - 1U));
|
||||
}
|
||||
EXPECT_FALSE(IsPowerOfTwo64(V8_UINT64_C(0xffffffffffffffff)));
|
||||
EXPECT_FALSE(IsPowerOfTwo(V8_UINT64_C(0xffffffffffffffff)));
|
||||
}
|
||||
|
||||
|
||||
|
@ -1050,14 +1050,14 @@ TEST_F(MachineOperatorReducerTest, Int32DivWithConstant) {
|
||||
}
|
||||
TRACED_FOREACH(int32_t, divisor, kInt32Values) {
|
||||
if (divisor < 0) {
|
||||
if (base::bits::IsPowerOfTwo32(-divisor)) continue;
|
||||
if (divisor == kMinInt || base::bits::IsPowerOfTwo(-divisor)) continue;
|
||||
Reduction const r = Reduce(graph()->NewNode(
|
||||
machine()->Int32Div(), p0, Int32Constant(divisor), graph()->start()));
|
||||
ASSERT_TRUE(r.Changed());
|
||||
EXPECT_THAT(r.replacement(), IsInt32Sub(IsInt32Constant(0),
|
||||
IsTruncatingDiv(p0, -divisor)));
|
||||
} else if (divisor > 0) {
|
||||
if (base::bits::IsPowerOfTwo32(divisor)) continue;
|
||||
if (base::bits::IsPowerOfTwo(divisor)) continue;
|
||||
Reduction const r = Reduce(graph()->NewNode(
|
||||
machine()->Int32Div(), p0, Int32Constant(divisor), graph()->start()));
|
||||
ASSERT_TRUE(r.Changed());
|
||||
@ -1215,7 +1215,7 @@ TEST_F(MachineOperatorReducerTest, Int32ModWithConstant) {
|
||||
graph()->start())))));
|
||||
}
|
||||
TRACED_FOREACH(int32_t, divisor, kInt32Values) {
|
||||
if (divisor == 0 || base::bits::IsPowerOfTwo32(Abs(divisor))) continue;
|
||||
if (divisor == 0 || base::bits::IsPowerOfTwo(Abs(divisor))) continue;
|
||||
Reduction const r = Reduce(graph()->NewNode(
|
||||
machine()->Int32Mod(), p0, Int32Constant(divisor), graph()->start()));
|
||||
ASSERT_TRUE(r.Changed());
|
||||
|
Loading…
Reference in New Issue
Block a user