"src/base/atomicops_internals_x86_gcc.cc",
"src/base/atomicops_internals_x86_gcc.h",
"src/base/atomicops_internals_x86_msvc.h",
+ "src/base/bits.cc",
"src/base/bits.h",
"src/base/build_config.h",
"src/base/cpu.cc",
#include "src/allocation.h"
#include <stdlib.h> // For free, malloc.
+#include "src/base/bits.h"
#include "src/base/logging.h"
#include "src/base/platform/platform.h"
#include "src/utils.h"
void* AlignedAlloc(size_t size, size_t alignment) {
- DCHECK(IsPowerOf2(alignment) && alignment >= V8_ALIGNOF(void*)); // NOLINT
+ DCHECK_LE(V8_ALIGNOF(void*), alignment);
+ DCHECK(base::bits::IsPowerOfTwo32(alignment));
void* ptr;
#if V8_OS_WIN
ptr = _aligned_malloc(size, alignment);
#if V8_TARGET_ARCH_ARM
#include "src/arm/assembler-arm-inl.h"
+#include "src/base/bits.h"
#include "src/base/cpu.h"
#include "src/macro-assembler.h"
#include "src/serialize.h"
void Assembler::Align(int m) {
- DCHECK(m >= 4 && IsPowerOf2(m));
+ DCHECK(m >= 4 && base::bits::IsPowerOfTwo32(m));
while ((pc_offset() & (m - 1)) != 0) {
nop();
}
#if V8_TARGET_ARCH_ARM
+#include "src/base/bits.h"
#include "src/bootstrapper.h"
#include "src/code-stubs.h"
#include "src/codegen.h"
// Fast case of Heap::LookupSingleCharacterStringFromCode.
STATIC_ASSERT(kSmiTag == 0);
STATIC_ASSERT(kSmiShiftSize == 0);
- DCHECK(IsPowerOf2(String::kMaxOneByteCharCode + 1));
+ DCHECK(base::bits::IsPowerOfTwo32(String::kMaxOneByteCharCode + 1));
__ tst(code_,
Operand(kSmiTagMask |
((~String::kMaxOneByteCharCode) << kSmiTagSize)));
int frame_alignment = masm->ActivationFrameAlignment();
if (frame_alignment > kPointerSize) {
__ mov(r5, sp);
- DCHECK(IsPowerOf2(frame_alignment));
+ DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
__ and_(sp, sp, Operand(-frame_alignment));
}
#include "src/arm/lithium-codegen-arm.h"
#include "src/arm/lithium-gap-resolver-arm.h"
+#include "src/base/bits.h"
#include "src/code-stubs.h"
#include "src/hydrogen-osr.h"
Register dividend = ToRegister(instr->dividend());
int32_t divisor = instr->divisor();
Register result = ToRegister(instr->result());
- DCHECK(divisor == kMinInt || IsPowerOf2(Abs(divisor)));
+ DCHECK(divisor == kMinInt || base::bits::IsPowerOfTwo32(Abs(divisor)));
DCHECK(!result.is(dividend));
// Check for (0 / -x) that will produce negative zero.
int32_t mask = constant >> 31;
uint32_t constant_abs = (constant + mask) ^ mask;
- if (IsPowerOf2(constant_abs)) {
+ if (base::bits::IsPowerOfTwo32(constant_abs)) {
int32_t shift = WhichPowerOf2(constant_abs);
__ mov(result, Operand(left, LSL, shift));
// Correct the sign of the result is the constant is negative.
if (constant < 0) __ rsb(result, result, Operand::Zero());
- } else if (IsPowerOf2(constant_abs - 1)) {
+ } else if (base::bits::IsPowerOfTwo32(constant_abs - 1)) {
int32_t shift = WhichPowerOf2(constant_abs - 1);
__ add(result, left, Operand(left, LSL, shift));
// Correct the sign of the result is the constant is negative.
if (constant < 0) __ rsb(result, result, Operand::Zero());
- } else if (IsPowerOf2(constant_abs + 1)) {
+ } else if (base::bits::IsPowerOfTwo32(constant_abs + 1)) {
int32_t shift = WhichPowerOf2(constant_abs + 1);
__ rsb(result, left, Operand(left, LSL, shift));
// Correct the sign of the result is the constant is negative.
uint8_t tag;
instr->hydrogen()->GetCheckMaskAndTag(&mask, &tag);
- if (IsPowerOf2(mask)) {
- DCHECK(tag == 0 || IsPowerOf2(tag));
+ if (base::bits::IsPowerOfTwo32(mask)) {
+ DCHECK(tag == 0 || base::bits::IsPowerOfTwo32(tag));
__ tst(scratch, Operand(mask));
DeoptimizeIf(tag == 0 ? ne : eq, instr->environment());
} else {
#if V8_TARGET_ARCH_ARM
+#include "src/base/bits.h"
#include "src/bootstrapper.h"
#include "src/codegen.h"
#include "src/cpu-profiler.h"
} else if (!(src2.instructions_required(this) == 1) &&
!src2.must_output_reloc_info(this) &&
CpuFeatures::IsSupported(ARMv7) &&
- IsPowerOf2(src2.immediate() + 1)) {
+ base::bits::IsPowerOfTwo32(src2.immediate() + 1)) {
ubfx(dst, src1, 0,
WhichPowerOf2(static_cast<uint32_t>(src2.immediate()) + 1), cond);
} else {
const int frame_alignment = MacroAssembler::ActivationFrameAlignment();
sub(sp, sp, Operand((stack_space + 1) * kPointerSize));
if (frame_alignment > 0) {
- DCHECK(IsPowerOf2(frame_alignment));
+ DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
and_(sp, sp, Operand(-frame_alignment));
}
// and the original value of sp.
mov(scratch, sp);
sub(sp, sp, Operand((stack_passed_arguments + 1) * kPointerSize));
- DCHECK(IsPowerOf2(frame_alignment));
+ DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
and_(sp, sp, Operand(-frame_alignment));
str(scratch, MemOperand(sp, stack_passed_arguments * kPointerSize));
} else {
#define ARM64_DEFINE_REG_STATICS
#include "src/arm64/assembler-arm64-inl.h"
+#include "src/base/bits.h"
#include "src/base/cpu.h"
namespace v8 {
void Assembler::Align(int m) {
- DCHECK(m >= 4 && IsPowerOf2(m));
+ DCHECK(m >= 4 && base::bits::IsPowerOfTwo32(m));
while ((pc_offset() & (m - 1)) != 0) {
nop();
}
}
+void Assembler::EmitStringData(const char* string) {
+ size_t len = strlen(string) + 1;
+ DCHECK(RoundUp(len, kInstructionSize) <= static_cast<size_t>(kGap));
+ EmitData(string, len);
+ // Pad with NULL characters until pc_ is aligned.
+ const char pad[] = {'\0', '\0', '\0', '\0'};
+ STATIC_ASSERT(sizeof(pad) == kInstructionSize);
+ EmitData(pad, RoundUp(pc_offset(), kInstructionSize) - pc_offset());
+}
+
+
void Assembler::debug(const char* message, uint32_t code, Instr params) {
#ifdef USE_SIMULATOR
// Don't generate simulator specific code if we are building a snapshot, which
// Copy a string into the instruction stream, including the terminating NULL
// character. The instruction pointer (pc_) is then aligned correctly for
// subsequent instructions.
- void EmitStringData(const char * string) {
- size_t len = strlen(string) + 1;
- DCHECK(RoundUp(len, kInstructionSize) <= static_cast<size_t>(kGap));
- EmitData(string, len);
- // Pad with NULL characters until pc_ is aligned.
- const char pad[] = {'\0', '\0', '\0', '\0'};
- STATIC_ASSERT(sizeof(pad) == kInstructionSize);
- byte* next_pc = AlignUp(pc_, kInstructionSize);
- EmitData(&pad, next_pc - pc_);
- }
+ void EmitStringData(const char* string);
// Pseudo-instructions ------------------------------------------------------
int32_t constant_abs = Abs(constant);
if (!end_range_constant &&
- (small_constant ||
- (IsPowerOf2(constant_abs)) ||
- (!can_overflow && (IsPowerOf2(constant_abs + 1) ||
- IsPowerOf2(constant_abs - 1))))) {
+ (small_constant || (base::bits::IsPowerOfTwo32(constant_abs)) ||
+ (!can_overflow && (base::bits::IsPowerOfTwo32(constant_abs + 1) ||
+ base::bits::IsPowerOfTwo32(constant_abs - 1))))) {
LConstantOperand* right = UseConstant(most_const);
- bool need_register = IsPowerOf2(constant_abs) && !small_constant;
+ bool need_register =
+ base::bits::IsPowerOfTwo32(constant_abs) && !small_constant;
LOperand* left = need_register ? UseRegister(least_const)
: UseRegisterAtStart(least_const);
LInstruction* result =
#include "src/arm64/lithium-codegen-arm64.h"
#include "src/arm64/lithium-gap-resolver-arm64.h"
+#include "src/base/bits.h"
#include "src/code-stubs.h"
#include "src/hydrogen-osr.h"
uint8_t tag;
instr->hydrogen()->GetCheckMaskAndTag(&mask, &tag);
- if (IsPowerOf2(mask)) {
+ if (base::bits::IsPowerOfTwo32(mask)) {
DCHECK((tag == 0) || (tag == mask));
if (tag == 0) {
DeoptimizeIfBitSet(scratch, MaskToBit(mask), instr->environment());
Register dividend = ToRegister32(instr->dividend());
int32_t divisor = instr->divisor();
Register result = ToRegister32(instr->result());
- DCHECK(divisor == kMinInt || IsPowerOf2(Abs(divisor)));
+ DCHECK(divisor == kMinInt || base::bits::IsPowerOfTwo32(Abs(divisor)));
DCHECK(!result.is(dividend));
// Check for (0 / -x) that will produce negative zero.
// can be done efficiently with shifted operands.
int32_t right_abs = Abs(right);
- if (IsPowerOf2(right_abs)) {
+ if (base::bits::IsPowerOfTwo32(right_abs)) {
int right_log2 = WhichPowerOf2(right_abs);
if (can_overflow) {
DCHECK(!can_overflow);
if (right >= 0) {
- if (IsPowerOf2(right - 1)) {
+ if (base::bits::IsPowerOfTwo32(right - 1)) {
// result = left + left << log2(right - 1)
__ Add(result, left, Operand(left, LSL, WhichPowerOf2(right - 1)));
- } else if (IsPowerOf2(right + 1)) {
+ } else if (base::bits::IsPowerOfTwo32(right + 1)) {
// result = -left + left << log2(right + 1)
__ Sub(result, left, Operand(left, LSL, WhichPowerOf2(right + 1)));
__ Neg(result, result);
UNREACHABLE();
}
} else {
- if (IsPowerOf2(-right + 1)) {
+ if (base::bits::IsPowerOfTwo32(-right + 1)) {
// result = left - left << log2(-right + 1)
__ Sub(result, left, Operand(left, LSL, WhichPowerOf2(-right + 1)));
- } else if (IsPowerOf2(-right - 1)) {
+ } else if (base::bits::IsPowerOfTwo32(-right - 1)) {
// result = -left - left << log2(-right - 1)
__ Add(result, left, Operand(left, LSL, WhichPowerOf2(-right - 1)));
__ Neg(result, result);
#include "src/arm64/assembler-arm64.h"
#include "src/arm64/instrument-arm64.h"
#include "src/arm64/macro-assembler-arm64.h"
+#include "src/base/bits.h"
namespace v8 {
void MacroAssembler::Claim(const Register& count, uint64_t unit_size) {
if (unit_size == 0) return;
- DCHECK(IsPowerOf2(unit_size));
+ DCHECK(base::bits::IsPowerOfTwo64(unit_size));
const int shift = CountTrailingZeros(unit_size, kXRegSizeInBits);
const Operand size(count, LSL, shift);
void MacroAssembler::ClaimBySMI(const Register& count_smi, uint64_t unit_size) {
- DCHECK(unit_size == 0 || IsPowerOf2(unit_size));
+ DCHECK(unit_size == 0 || base::bits::IsPowerOfTwo64(unit_size));
const int shift = CountTrailingZeros(unit_size, kXRegSizeInBits) - kSmiShift;
const Operand size(count_smi,
(shift >= 0) ? (LSL) : (LSR),
void MacroAssembler::Drop(const Register& count, uint64_t unit_size) {
if (unit_size == 0) return;
- DCHECK(IsPowerOf2(unit_size));
+ DCHECK(base::bits::IsPowerOfTwo64(unit_size));
const int shift = CountTrailingZeros(unit_size, kXRegSizeInBits);
const Operand size(count, LSL, shift);
void MacroAssembler::DropBySMI(const Register& count_smi, uint64_t unit_size) {
- DCHECK(unit_size == 0 || IsPowerOf2(unit_size));
+ DCHECK(unit_size == 0 || base::bits::IsPowerOfTwo64(unit_size));
const int shift = CountTrailingZeros(unit_size, kXRegSizeInBits) - kSmiShift;
const Operand size(count_smi,
(shift >= 0) ? (LSL) : (LSR),
#if V8_TARGET_ARCH_ARM64
+#include "src/base/bits.h"
#include "src/bootstrapper.h"
#include "src/codegen.h"
#include "src/cpu-profiler.h"
int sp_alignment = ActivationFrameAlignment();
// The ABI mandates at least 16-byte alignment.
DCHECK(sp_alignment >= 16);
- DCHECK(IsPowerOf2(sp_alignment));
+ DCHECK(base::bits::IsPowerOfTwo32(sp_alignment));
// The current stack pointer is a callee saved register, and is preserved
// across the call.
#include "src/globals.h"
#include "src/arm64/assembler-arm64-inl.h"
+#include "src/base/bits.h"
// Simulator specific helpers.
#if USE_SIMULATOR
int sp_alignment = ActivationFrameAlignment();
// AAPCS64 mandates at least 16-byte alignment.
DCHECK(sp_alignment >= 16);
- DCHECK(IsPowerOf2(sp_alignment));
+ DCHECK(base::bits::IsPowerOfTwo32(sp_alignment));
Bic(csp, StackPointer(), sp_alignment - 1);
SetStackPointer(csp);
}
#include "src/base/macros.h"
#include "testing/gtest-support.h"
+#ifdef DEBUG
+#define DISABLE_IN_RELEASE(Name) Name
+#else
+#define DISABLE_IN_RELEASE(Name) DISABLED_##Name
+#endif
+
namespace v8 {
namespace base {
namespace bits {
-TEST(BitsTest, CountPopulation32) {
+TEST(Bits, CountPopulation32) {
EXPECT_EQ(0u, CountPopulation32(0));
EXPECT_EQ(1u, CountPopulation32(1));
EXPECT_EQ(8u, CountPopulation32(0x11111111));
}
-TEST(BitsTest, CountLeadingZeros32) {
+TEST(Bits, CountLeadingZeros32) {
EXPECT_EQ(32u, CountLeadingZeros32(0));
EXPECT_EQ(31u, CountLeadingZeros32(1));
TRACED_FORRANGE(uint32_t, shift, 0, 31) {
}
-TEST(BitsTest, CountTrailingZeros32) {
+TEST(Bits, CountTrailingZeros32) {
EXPECT_EQ(32u, CountTrailingZeros32(0));
EXPECT_EQ(31u, CountTrailingZeros32(0x80000000));
TRACED_FORRANGE(uint32_t, shift, 0, 31) {
}
-TEST(BitsTest, RotateRight32) {
+TEST(Bits, IsPowerOfTwo32) {
+ EXPECT_FALSE(IsPowerOfTwo32(0U));
+ TRACED_FORRANGE(uint32_t, shift, 0, 31) {
+ EXPECT_TRUE(IsPowerOfTwo32(1U << shift));
+ EXPECT_FALSE(IsPowerOfTwo32((1U << shift) + 5U));
+ EXPECT_FALSE(IsPowerOfTwo32(~(1U << shift)));
+ }
+ TRACED_FORRANGE(uint32_t, shift, 2, 31) {
+ EXPECT_FALSE(IsPowerOfTwo32((1U << shift) - 1U));
+ }
+ EXPECT_FALSE(IsPowerOfTwo32(0xffffffff));
+}
+
+
+TEST(Bits, IsPowerOfTwo64) {
+ EXPECT_FALSE(IsPowerOfTwo64(0U));
+ 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)));
+ }
+ TRACED_FORRANGE(uint32_t, shift, 2, 63) {
+ EXPECT_FALSE(IsPowerOfTwo64((V8_UINT64_C(1) << shift) - 1U));
+ }
+ EXPECT_FALSE(IsPowerOfTwo64(V8_UINT64_C(0xffffffffffffffff)));
+}
+
+
+TEST(Bits, RoundUpToPowerOfTwo32) {
+ TRACED_FORRANGE(uint32_t, shift, 0, 31) {
+ EXPECT_EQ(1u << shift, RoundUpToPowerOfTwo32(1u << shift));
+ }
+ EXPECT_EQ(0u, RoundUpToPowerOfTwo32(0));
+ EXPECT_EQ(4u, RoundUpToPowerOfTwo32(3));
+ EXPECT_EQ(0x80000000u, RoundUpToPowerOfTwo32(0x7fffffffu));
+}
+
+
+TEST(BitsDeathTest, DISABLE_IN_RELEASE(RoundUpToPowerOfTwo32)) {
+ ASSERT_DEATH({ RoundUpToPowerOfTwo32(0x80000001u); }, "0x80000000");
+}
+
+
+TEST(Bits, RoundDownToPowerOfTwo32) {
+ TRACED_FORRANGE(uint32_t, shift, 0, 31) {
+ EXPECT_EQ(1u << shift, RoundDownToPowerOfTwo32(1u << shift));
+ }
+ EXPECT_EQ(0u, RoundDownToPowerOfTwo32(0));
+ EXPECT_EQ(4u, RoundDownToPowerOfTwo32(5));
+ EXPECT_EQ(0x80000000u, RoundDownToPowerOfTwo32(0x80000001u));
+}
+
+
+TEST(Bits, RotateRight32) {
TRACED_FORRANGE(uint32_t, shift, 0, 31) {
EXPECT_EQ(0u, RotateRight32(0u, shift));
}
}
-TEST(BitsTest, RotateRight64) {
+TEST(Bits, RotateRight64) {
TRACED_FORRANGE(uint64_t, shift, 0, 63) {
EXPECT_EQ(0u, RotateRight64(0u, shift));
}
--- /dev/null
+// Copyright 2014 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "src/base/bits.h"
+#include "src/base/logging.h"
+
+namespace v8 {
+namespace base {
+namespace bits {
+
+uint32_t RoundUpToPowerOfTwo32(uint32_t value) {
+ DCHECK_LE(value, 0x80000000u);
+ value = value - 1;
+ value = value | (value >> 1);
+ value = value | (value >> 2);
+ value = value | (value >> 4);
+ value = value | (value >> 8);
+ value = value | (value >> 16);
+ return value + 1;
+}
+
+} // namespace bits
+} // namespace base
+} // namespace v8
}
+// Returns true iff |value| is a power of 2.
+inline bool IsPowerOfTwo32(uint32_t value) {
+ return value && !(value & (value - 1));
+}
+
+
+// Returns true iff |value| is a power of 2.
+inline bool IsPowerOfTwo64(uint64_t value) {
+ return value && !(value & (value - 1));
+}
+
+
+// RoundUpToPowerOfTwo32(value) returns the smallest power of two which is
+// greater than or equal to |value|. If you pass in a |value| that is already a
+// power of two, it is returned as is. |value| must be less than or equal to
+// 0x80000000u. Implementation is from "Hacker's Delight" by Henry S. Warren,
+// Jr., figure 3-3, page 48, where the function is called clp2.
+uint32_t RoundUpToPowerOfTwo32(uint32_t value);
+
+
+// RoundDownToPowerOfTwo32(value) returns the greatest power of two which is
+// less than or equal to |value|. If you pass in a |value| that is already a
+// power of two, it is returned as is.
+inline uint32_t RoundDownToPowerOfTwo32(uint32_t value) {
+ if (value > 0x80000000u) return 0x80000000u;
+ uint32_t result = RoundUpToPowerOfTwo32(value);
+ if (result > value) result >>= 1;
+ return result;
+}
+
+
inline uint32_t RotateRight32(uint32_t value, uint32_t shift) {
if (shift == 0) return value;
return (value >> shift) | (value << (32 - shift));
#define IS_POWER_OF_TWO(x) ((x) != 0 && (((x) & ((x) - 1)) == 0))
-// Returns true iff x is a power of 2. Cannot be used with the maximally
-// negative value of the type T (the -1 overflows).
-template <typename T>
-inline bool IsPowerOf2(T x) {
- return IS_POWER_OF_TWO(x);
-}
-
-
// 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).
// Return the largest multiple of m which is <= x.
template <typename T>
inline T RoundDown(T x, intptr_t m) {
- DCHECK(IsPowerOf2(m));
+ DCHECK(IS_POWER_OF_TWO(m));
return AddressFrom<T>(OffsetFrom(x) & -m);
}
}
-// Increment a pointer until it has the specified alignment.
-// This works like RoundUp, but it works correctly on pointer types where
-// sizeof(*pointer) might not be 1.
-template<class T>
-T AlignUp(T pointer, size_t alignment) {
- DCHECK(sizeof(pointer) == sizeof(uintptr_t));
- uintptr_t pointer_raw = reinterpret_cast<uintptr_t>(pointer);
- return reinterpret_cast<T>(RoundUp(pointer_raw, alignment));
-}
-
-
template <typename T, typename U>
inline bool IsAligned(T value, U alignment) {
return (value & (alignment - 1)) == 0;
}
-// Returns the smallest power of two which is >= x. If you pass in a
-// number that is already a power of two, it is returned as is.
-// Implementation is from "Hacker's Delight" by Henry S. Warren, Jr.,
-// figure 3-3, page 48, where the function is called clp2.
-inline uint32_t RoundUpToPowerOf2(uint32_t x) {
- DCHECK(x <= 0x80000000u);
- x = x - 1;
- x = x | (x >> 1);
- x = x | (x >> 2);
- x = x | (x >> 4);
- x = x | (x >> 8);
- x = x | (x >> 16);
- return x + 1;
-}
-
-
-inline uint32_t RoundDownToPowerOf2(uint32_t x) {
- uint32_t rounded_up = RoundUpToPowerOf2(x);
- if (rounded_up > x) return rounded_up >> 1;
- return rounded_up;
-}
-
-
// Returns current value of top of the stack. Works correctly with ASAN.
DISABLE_ASAN
inline uintptr_t GetCurrentStackPosition() {
Int32BinopMatcher m(node);
if (m.right().HasValue() && m.right().Value() > 0) {
int32_t value = m.right().Value();
- if (IsPowerOf2(value - 1)) {
+ if (base::bits::IsPowerOfTwo32(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 && IsPowerOf2(value + 1)) {
+ if (value < kMaxInt && base::bits::IsPowerOfTwo32(value + 1)) {
Emit(kArmRsb | AddressingModeField::encode(kMode_Operand2_R_LSL_I),
g.DefineAsRegister(node), g.UseRegister(m.left().node()),
g.UseRegister(m.left().node()),
#ifndef V8_COMPILER_MACHINE_TYPE_H_
#define V8_COMPILER_MACHINE_TYPE_H_
+#include "src/base/bits.h"
#include "src/globals.h"
namespace v8 {
// Gets only the representation of the given type.
inline MachineType RepresentationOf(MachineType machine_type) {
int result = machine_type & kRepMask;
- CHECK(IsPowerOf2(result));
+ CHECK(base::bits::IsPowerOfTwo32(result));
return static_cast<MachineType>(result);
}
#ifndef V8_COMPILER_REPRESENTATION_CHANGE_H_
#define V8_COMPILER_REPRESENTATION_CHANGE_H_
+#include "src/base/bits.h"
#include "src/compiler/js-graph.h"
#include "src/compiler/machine-operator.h"
#include "src/compiler/node-properties-inl.h"
Node* GetRepresentationFor(Node* node, MachineTypeUnion output_type,
MachineTypeUnion use_type) {
- if (!IsPowerOf2(output_type & kRepMask)) {
+ if (!base::bits::IsPowerOfTwo32(output_type & kRepMask)) {
// There should be only one output representation.
return TypeError(node, output_type, use_type);
}
#include "src/compiler/simplified-lowering.h"
+#include "src/base/bits.h"
#include "src/compiler/common-operator.h"
#include "src/compiler/graph-inl.h"
#include "src/compiler/node-properties-inl.h"
// Every node should have at most one output representation. Note that
// phis can have 0, if they have not been used in a representation-inducing
// instruction.
- DCHECK((output & kRepMask) == 0 || IsPowerOf2(output & kRepMask));
+ DCHECK((output & kRepMask) == 0 ||
+ base::bits::IsPowerOfTwo32(output & kRepMask));
GetInfo(node)->output = output;
}
// ----------------------------------------------------------------------------
// Extra POSIX/ANSI functions for Win32/MSVC.
+#include "src/base/bits.h"
#include "src/base/platform/platform.h"
#include "src/conversions.h"
#include "src/double.h"
return JunkStringValue();
}
- if (IsPowerOf2(radix)) {
+ if (base::bits::IsPowerOfTwo32(radix)) {
switch (radix) {
case 2:
return InternalStringToIntDouble<1>(
#include "src/factory.h"
#include "src/allocation-site-scopes.h"
+#include "src/base/bits.h"
#include "src/conversions.h"
#include "src/isolate-inl.h"
#include "src/macro-assembler.h"
// when building the new string.
if (static_cast<unsigned>(c1 | c2) <= String::kMaxOneByteCharCodeU) {
// We can do this.
- DCHECK(IsPowerOf2(String::kMaxOneByteCharCodeU + 1)); // because of this.
+ DCHECK(base::bits::IsPowerOfTwo32(String::kMaxOneByteCharCodeU +
+ 1)); // because of this.
Handle<SeqOneByteString> str =
isolate->factory()->NewRawOneByteString(2).ToHandleChecked();
uint8_t* dest = str->GetChars();
InnerPointerToCodeCache::InnerPointerToCodeCacheEntry*
InnerPointerToCodeCache::GetCacheEntry(Address inner_pointer) {
isolate_->counters()->pc_to_code()->Increment();
- DCHECK(IsPowerOf2(kInnerPointerToCodeCacheSize));
+ DCHECK(base::bits::IsPowerOfTwo32(kInnerPointerToCodeCacheSize));
uint32_t hash = ComputeIntegerHash(
static_cast<uint32_t>(reinterpret_cast<uintptr_t>(inner_pointer)),
v8::internal::kZeroHashSeed);
#ifdef ENABLE_GDB_JIT_INTERFACE
#include "src/v8.h"
+#include "src/base/bits.h"
#include "src/base/platform/platform.h"
#include "src/bootstrapper.h"
#include "src/compiler.h"
S_ATTR_PURE_INSTRUCTIONS = 0x80000000u
};
- MachOSection(const char* name,
- const char* segment,
- uintptr_t align,
+ MachOSection(const char* name, const char* segment, uint32_t align,
uint32_t flags)
- : name_(name),
- segment_(segment),
- align_(align),
- flags_(flags) {
+ : name_(name), segment_(segment), align_(align), flags_(flags) {
if (align_ != 0) {
- DCHECK(IsPowerOf2(align));
+ DCHECK(base::bits::IsPowerOfTwo32(align));
align_ = WhichPowerOf2(align_);
}
}
private:
const char* name_;
const char* segment_;
- uintptr_t align_;
+ uint32_t align_;
uint32_t flags_;
};
#define V8_HASHMAP_H_
#include "src/allocation.h"
+#include "src/base/bits.h"
#include "src/base/logging.h"
#include "src/utils.h"
TemplateHashMapImpl<AllocationPolicy>::Probe(void* key, uint32_t hash) {
DCHECK(key != NULL);
- DCHECK(IsPowerOf2(capacity_));
+ DCHECK(base::bits::IsPowerOfTwo32(capacity_));
Entry* p = map_ + (hash & (capacity_ - 1));
const Entry* end = map_end();
DCHECK(map_ <= p && p < end);
template<class AllocationPolicy>
void TemplateHashMapImpl<AllocationPolicy>::Initialize(
uint32_t capacity, AllocationPolicy allocator) {
- DCHECK(IsPowerOf2(capacity));
+ DCHECK(base::bits::IsPowerOfTwo32(capacity));
map_ = reinterpret_cast<Entry*>(allocator.New(capacity * sizeof(Entry)));
if (map_ == NULL) {
v8::internal::FatalProcessOutOfMemory("HashMap::Initialize");
#include "src/accessors.h"
#include "src/api.h"
+#include "src/base/bits.h"
#include "src/base/once.h"
#include "src/base/utils/random-number-generator.h"
#include "src/bootstrapper.h"
// The new space size must be a power of two to support single-bit testing
// for containment.
- max_semi_space_size_ = RoundUpToPowerOf2(max_semi_space_size_);
- reserved_semispace_size_ = RoundUpToPowerOf2(reserved_semispace_size_);
+ max_semi_space_size_ =
+ base::bits::RoundUpToPowerOfTwo32(max_semi_space_size_);
+ reserved_semispace_size_ =
+ base::bits::RoundUpToPowerOfTwo32(reserved_semispace_size_);
if (FLAG_min_semi_space_size > 0) {
int initial_semispace_size = FLAG_min_semi_space_size * MB;
#ifndef V8_HEAP_MARK_COMPACT_H_
#define V8_HEAP_MARK_COMPACT_H_
+#include "src/base/bits.h"
#include "src/heap/spaces.h"
namespace v8 {
HeapObject** obj_low = reinterpret_cast<HeapObject**>(low);
HeapObject** obj_high = reinterpret_cast<HeapObject**>(high);
array_ = obj_low;
- mask_ = RoundDownToPowerOf2(static_cast<int>(obj_high - obj_low)) - 1;
+ mask_ = base::bits::RoundDownToPowerOfTwo32(
+ static_cast<uint32_t>(obj_high - obj_low)) -
+ 1;
top_ = bottom_ = 0;
overflowed_ = false;
}
#include "src/v8.h"
+#include "src/base/bits.h"
#include "src/base/platform/platform.h"
#include "src/full-codegen.h"
#include "src/heap/mark-compact.h"
LOG(heap()->isolate(), NewEvent("InitialChunk", chunk_base_, chunk_size_));
DCHECK(initial_semispace_capacity <= maximum_semispace_capacity);
- DCHECK(IsPowerOf2(maximum_semispace_capacity));
+ DCHECK(base::bits::IsPowerOfTwo32(maximum_semispace_capacity));
// Allocate and set up the histogram arrays if necessary.
allocated_histogram_ = NewArray<HistogramInfo>(LAST_TYPE + 1);
#include "src/allocation.h"
#include "src/base/atomicops.h"
+#include "src/base/bits.h"
#include "src/base/platform/mutex.h"
#include "src/hashmap.h"
#include "src/list.h"
static const int kMaxMapPageIndex = 1 << 16;
virtual int RoundSizeDownToObjectAlignment(int size) {
- if (IsPowerOf2(Map::kSize)) {
+ if (base::bits::IsPowerOfTwo32(Map::kSize)) {
return RoundDown(size, Map::kSize);
} else {
return (size / Map::kSize) * Map::kSize;
: PagedSpace(heap, max_capacity, id, NOT_EXECUTABLE) {}
virtual int RoundSizeDownToObjectAlignment(int size) {
- if (IsPowerOf2(Cell::kSize)) {
+ if (base::bits::IsPowerOfTwo32(Cell::kSize)) {
return RoundDown(size, Cell::kSize);
} else {
return (size / Cell::kSize) * Cell::kSize;
: PagedSpace(heap, max_capacity, id, NOT_EXECUTABLE) {}
virtual int RoundSizeDownToObjectAlignment(int size) {
- if (IsPowerOf2(PropertyCell::kSize)) {
+ if (base::bits::IsPowerOfTwo32(PropertyCell::kSize)) {
return RoundDown(size, PropertyCell::kSize);
} else {
return (size / PropertyCell::kSize) * PropertyCell::kSize;
#include "src/v8.h"
#include "src/allocation.h"
+#include "src/base/bits.h"
#include "src/code-stubs.h"
#include "src/conversions.h"
#include "src/data-flow.h"
bool RightIsPowerOf2() {
if (!right()->IsInteger32Constant()) return false;
int32_t value = right()->GetInteger32Constant();
- return IsPowerOf2(value) || IsPowerOf2(-value);
+ if (value < 0) {
+ return base::bits::IsPowerOfTwo32(static_cast<uint32_t>(-value));
+ }
+ return base::bits::IsPowerOfTwo32(static_cast<uint32_t>(value));
}
DECLARE_ABSTRACT_INSTRUCTION(BinaryOperation)
#if V8_TARGET_ARCH_IA32
+#include "src/base/bits.h"
#include "src/base/cpu.h"
#include "src/disassembler.h"
#include "src/macro-assembler.h"
void Assembler::Align(int m) {
- DCHECK(IsPowerOf2(m));
+ DCHECK(base::bits::IsPowerOfTwo32(m));
int mask = m - 1;
int addr = pc_offset();
Nop((m - (addr & mask)) & mask);
#if V8_TARGET_ARCH_IA32
+#include "src/base/bits.h"
#include "src/bootstrapper.h"
#include "src/code-stubs.h"
#include "src/codegen.h"
// Fast case of Heap::LookupSingleCharacterStringFromCode.
STATIC_ASSERT(kSmiTag == 0);
STATIC_ASSERT(kSmiShiftSize == 0);
- DCHECK(IsPowerOf2(String::kMaxOneByteCharCode + 1));
+ DCHECK(base::bits::IsPowerOfTwo32(String::kMaxOneByteCharCode + 1));
__ test(code_,
Immediate(kSmiTagMask |
((~String::kMaxOneByteCharCode) << kSmiTagSize)));
#if V8_TARGET_ARCH_IA32
+#include "src/base/bits.h"
#include "src/code-stubs.h"
#include "src/codegen.h"
#include "src/deoptimizer.h"
Register dividend = ToRegister(instr->dividend());
int32_t divisor = instr->divisor();
Register result = ToRegister(instr->result());
- DCHECK(divisor == kMinInt || IsPowerOf2(Abs(divisor)));
+ DCHECK(divisor == kMinInt || base::bits::IsPowerOfTwo32(Abs(divisor)));
DCHECK(!result.is(dividend));
// Check for (0 / -x) that will produce negative zero.
uint8_t tag;
instr->hydrogen()->GetCheckMaskAndTag(&mask, &tag);
- if (IsPowerOf2(mask)) {
- DCHECK(tag == 0 || IsPowerOf2(tag));
+ if (base::bits::IsPowerOfTwo32(mask)) {
+ DCHECK(tag == 0 || base::bits::IsPowerOfTwo32(tag));
__ test_b(FieldOperand(temp, Map::kInstanceTypeOffset), mask);
DeoptimizeIf(tag == 0 ? not_zero : zero, instr->environment());
} else {
#if V8_TARGET_ARCH_IA32
+#include "src/base/bits.h"
#include "src/bootstrapper.h"
#include "src/codegen.h"
#include "src/cpu-profiler.h"
// Get the required frame alignment for the OS.
const int kFrameAlignment = base::OS::ActivationFrameAlignment();
if (kFrameAlignment > 0) {
- DCHECK(IsPowerOf2(kFrameAlignment));
+ DCHECK(base::bits::IsPowerOfTwo32(kFrameAlignment));
and_(esp, -kFrameAlignment);
}
int field_offset,
int bit_index) {
bit_index += kSmiTagSize + kSmiShiftSize;
- DCHECK(IsPowerOf2(kBitsPerByte));
+ DCHECK(base::bits::IsPowerOfTwo32(kBitsPerByte));
int byte_index = bit_index / kBitsPerByte;
int byte_bit_index = bit_index & (kBitsPerByte - 1);
test_b(FieldOperand(object, field_offset + byte_index),
int frame_alignment = base::OS::ActivationFrameAlignment();
int frame_alignment_mask = frame_alignment - 1;
if (frame_alignment > kPointerSize) {
- DCHECK(IsPowerOf2(frame_alignment));
+ DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
Label alignment_as_expected;
test(esp, Immediate(frame_alignment_mask));
j(zero, &alignment_as_expected);
// and the original value of esp.
mov(scratch, esp);
sub(esp, Immediate((num_arguments + 1) * kPointerSize));
- DCHECK(IsPowerOf2(frame_alignment));
+ DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
and_(esp, -frame_alignment);
mov(Operand(esp, num_arguments * kPointerSize), scratch);
} else {
#include "src/accessors.h"
#include "src/api.h"
#include "src/arguments.h"
+#include "src/base/bits.h"
#include "src/codegen.h"
#include "src/conversions.h"
#include "src/execution.h"
int32_t fixed_right_arg_value = 0;
bool has_fixed_right_arg =
op_ == Token::MOD && right->ToInt32(&fixed_right_arg_value) &&
- fixed_right_arg_value > 0 && IsPowerOf2(fixed_right_arg_value) &&
+ fixed_right_arg_value > 0 &&
+ base::bits::IsPowerOfTwo32(fixed_right_arg_value) &&
FixedRightArgValueField::is_valid(WhichPowerOf2(fixed_right_arg_value)) &&
(left_kind_ == SMI || left_kind_ == INT32) &&
(result_kind_ == NONE || !fixed_right_arg_.has_value);
#include "src/v8.h"
+#include "src/base/bits.h"
#include "src/ic/stub-cache.h"
#include "src/type-info.h"
void StubCache::Initialize() {
- DCHECK(IsPowerOf2(kPrimaryTableSize));
- DCHECK(IsPowerOf2(kSecondaryTableSize));
+ DCHECK(base::bits::IsPowerOfTwo32(kPrimaryTableSize));
+ DCHECK(base::bits::IsPowerOfTwo32(kSecondaryTableSize));
Clear();
}
#define V8_OBJECTS_INL_H_
#include "src/base/atomicops.h"
+#include "src/base/bits.h"
#include "src/contexts.h"
#include "src/conversions-inl.h"
#include "src/elements.h"
template<typename Derived, typename Shape, typename Key>
int HashTable<Derived, Shape, Key>::ComputeCapacity(int at_least_space_for) {
const int kMinCapacity = 32;
- int capacity = RoundUpToPowerOf2(at_least_space_for * 2);
+ int capacity = base::bits::RoundUpToPowerOfTwo32(at_least_space_for * 2);
if (capacity < kMinCapacity) {
capacity = kMinCapacity; // Guarantee min capacity.
}
#include "src/allocation-site-scopes.h"
#include "src/api.h"
#include "src/arguments.h"
+#include "src/base/bits.h"
#include "src/bootstrapper.h"
#include "src/code-stubs.h"
#include "src/codegen.h"
MinimumCapacity capacity_option,
PretenureFlag pretenure) {
DCHECK(0 <= at_least_space_for);
- DCHECK(!capacity_option || IsPowerOf2(at_least_space_for));
+ DCHECK(!capacity_option || base::bits::IsPowerOfTwo32(at_least_space_for));
int capacity = (capacity_option == USE_CUSTOM_MINIMUM_CAPACITY)
? at_least_space_for
: ComputeCapacity(at_least_space_for);
// from number of buckets. If we decide to change kLoadFactor
// to something other than 2, capacity should be stored as another
// field of this object.
- capacity = RoundUpToPowerOf2(Max(kMinCapacity, capacity));
+ capacity = base::bits::RoundUpToPowerOfTwo32(Max(kMinCapacity, capacity));
if (capacity > kMaxCapacity) {
v8::internal::Heap::FatalProcessOutOfMemory("invalid table size", true);
}
#include "src/allocation.h"
#include "src/assert-scope.h"
+#include "src/base/bits.h"
#include "src/builtins.h"
#include "src/checks.h"
#include "src/elements-kind.h"
// Returns probe entry.
static uint32_t GetProbe(uint32_t hash, uint32_t number, uint32_t size) {
- DCHECK(IsPowerOf2(size));
+ DCHECK(base::bits::IsPowerOfTwo32(size));
return (hash + GetProbeOffset(number)) & (size - 1);
}
#include "include/v8.h"
#include "src/allocation.h"
+#include "src/base/bits.h"
#include "src/base/logging.h"
#include "src/base/macros.h"
#include "src/base/platform/platform.h"
// X must be a power of 2. Returns the number of trailing zeros.
inline int WhichPowerOf2(uint32_t x) {
- DCHECK(IsPowerOf2(x));
+ DCHECK(base::bits::IsPowerOfTwo32(x));
int bits = 0;
#ifdef DEBUG
int original_x = x;
#if V8_TARGET_ARCH_X64
+#include "src/base/bits.h"
#include "src/macro-assembler.h"
#include "src/serialize.h"
void Assembler::Align(int m) {
- DCHECK(IsPowerOf2(m));
+ DCHECK(base::bits::IsPowerOfTwo32(m));
int delta = (m - (pc_offset() & (m - 1))) & (m - 1);
Nop(delta);
}
#if V8_TARGET_ARCH_X64
+#include "src/base/bits.h"
#include "src/code-stubs.h"
#include "src/hydrogen-osr.h"
#include "src/x64/lithium-codegen-x64.h"
Register dividend = ToRegister(instr->dividend());
int32_t divisor = instr->divisor();
Register result = ToRegister(instr->result());
- DCHECK(divisor == kMinInt || IsPowerOf2(Abs(divisor)));
+ DCHECK(divisor == kMinInt || base::bits::IsPowerOfTwo32(Abs(divisor)));
DCHECK(!result.is(dividend));
// Check for (0 / -x) that will produce negative zero.
uint8_t tag;
instr->hydrogen()->GetCheckMaskAndTag(&mask, &tag);
- if (IsPowerOf2(mask)) {
- DCHECK(tag == 0 || IsPowerOf2(tag));
+ if (base::bits::IsPowerOfTwo32(mask)) {
+ DCHECK(tag == 0 || base::bits::IsPowerOfTwo32(tag));
__ testb(FieldOperand(kScratchRegister, Map::kInstanceTypeOffset),
Immediate(mask));
DeoptimizeIf(tag == 0 ? not_zero : zero, instr->environment());
#if V8_TARGET_ARCH_X64
+#include "src/base/bits.h"
#include "src/bootstrapper.h"
#include "src/codegen.h"
#include "src/cpu-profiler.h"
int frame_alignment = base::OS::ActivationFrameAlignment();
int frame_alignment_mask = frame_alignment - 1;
if (frame_alignment > kPointerSize) {
- DCHECK(IsPowerOf2(frame_alignment));
+ DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
Label alignment_as_expected;
testp(rsp, Immediate(frame_alignment_mask));
j(zero, &alignment_as_expected, Label::kNear);
// Get the required frame alignment for the OS.
const int kFrameAlignment = base::OS::ActivationFrameAlignment();
if (kFrameAlignment > 0) {
- DCHECK(IsPowerOf2(kFrameAlignment));
+ DCHECK(base::bits::IsPowerOfTwo32(kFrameAlignment));
DCHECK(is_int8(kFrameAlignment));
andp(rsp, Immediate(-kFrameAlignment));
}
// Make stack end at alignment and allocate space for arguments and old rsp.
movp(kScratchRegister, rsp);
- DCHECK(IsPowerOf2(frame_alignment));
+ DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
int argument_slots_on_stack =
ArgumentStackSlotsForCFunctionCall(num_arguments);
subp(rsp, Immediate((argument_slots_on_stack + 1) * kRegisterSize));
'../../src/base/atomicops_internals_x86_gcc.cc',
'../../src/base/atomicops_internals_x86_gcc.h',
'../../src/base/atomicops_internals_x86_msvc.h',
+ '../../src/base/bits.cc',
'../../src/base/bits.h',
'../../src/base/build_config.h',
'../../src/base/compiler-specific.h',