Commit 40da0e5e authored by bmeurer@chromium.org's avatar bmeurer@chromium.org

Use the "enum hack" to fix the SmiTagging constants.

The "enum hack" (see Item 2 of "Effective C++") is the only known
portable way to define constant integral values within template
classes. Fixes the weird work-arounds required for certain GCC
versions.

R=jarin@chromium.org, rossberg@chromium.org

Review URL: https://codereview.chromium.org/527603002

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@23550 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 5fe360b9
......@@ -5606,8 +5606,9 @@ V8_INLINE internal::Object* IntToSmi(int value) {
// Smi constants for 32-bit systems.
template <> struct SmiTagging<4> {
static const int kSmiShiftSize = 0;
static const int kSmiValueSize = 31;
enum { kSmiShiftSize = 0, kSmiValueSize = 31 };
static int SmiShiftSize() { return kSmiShiftSize; }
static int SmiValueSize() { return kSmiValueSize; }
V8_INLINE static int SmiToInt(const internal::Object* value) {
int shift_bits = kSmiTagSize + kSmiShiftSize;
// Throw away top 32 bits and shift down (requires >> to be sign extending).
......@@ -5634,8 +5635,9 @@ template <> struct SmiTagging<4> {
// Smi constants for 64-bit systems.
template <> struct SmiTagging<8> {
static const int kSmiShiftSize = 31;
static const int kSmiValueSize = 32;
enum { kSmiShiftSize = 31, kSmiValueSize = 32 };
static int SmiShiftSize() { return kSmiShiftSize; }
static int SmiValueSize() { return kSmiValueSize; }
V8_INLINE static int SmiToInt(const internal::Object* value) {
int shift_bits = kSmiTagSize + kSmiShiftSize;
// Shift down and throw away top 32 bits.
......
......@@ -50,28 +50,16 @@ Node* ChangeLowering::HeapNumberValueIndexConstant() {
Node* ChangeLowering::SmiMaxValueConstant() {
// TODO(turbofan): Work-around for weird GCC 4.6 linker issue:
// src/compiler/change-lowering.cc:46: undefined reference to
// `v8::internal::SmiTagging<4u>::kSmiValueSize'
// src/compiler/change-lowering.cc:46: undefined reference to
// `v8::internal::SmiTagging<8u>::kSmiValueSize'
STATIC_ASSERT(SmiTagging<4>::kSmiValueSize == 31);
STATIC_ASSERT(SmiTagging<8>::kSmiValueSize == 32);
const int smi_value_size = machine()->is64() ? 32 : 31;
const int smi_value_size = machine()->is32() ? SmiTagging<4>::SmiValueSize()
: SmiTagging<8>::SmiValueSize();
return jsgraph()->Int32Constant(
-(static_cast<int>(0xffffffffu << (smi_value_size - 1)) + 1));
}
Node* ChangeLowering::SmiShiftBitsConstant() {
// TODO(turbofan): Work-around for weird GCC 4.6 linker issue:
// src/compiler/change-lowering.cc:46: undefined reference to
// `v8::internal::SmiTagging<4u>::kSmiShiftSize'
// src/compiler/change-lowering.cc:46: undefined reference to
// `v8::internal::SmiTagging<8u>::kSmiShiftSize'
STATIC_ASSERT(SmiTagging<4>::kSmiShiftSize == 0);
STATIC_ASSERT(SmiTagging<8>::kSmiShiftSize == 31);
const int smi_shift_size = machine()->is64() ? 31 : 0;
const int smi_shift_size = machine()->is32() ? SmiTagging<4>::SmiShiftSize()
: SmiTagging<8>::SmiShiftSize();
return jsgraph()->Int32Constant(smi_shift_size + kSmiTagSize);
}
......
......@@ -59,24 +59,12 @@ class ChangeLoweringTest : public GraphTest {
}
int SmiShiftAmount() const { return kSmiTagSize + SmiShiftSize(); }
int SmiShiftSize() const {
// TODO(turbofan): Work-around for weird GCC 4.6 linker issue:
// src/compiler/change-lowering.cc:46: undefined reference to
// `v8::internal::SmiTagging<4u>::kSmiShiftSize'
// src/compiler/change-lowering.cc:46: undefined reference to
// `v8::internal::SmiTagging<8u>::kSmiShiftSize'
STATIC_ASSERT(SmiTagging<4>::kSmiShiftSize == 0);
STATIC_ASSERT(SmiTagging<8>::kSmiShiftSize == 31);
return Is32() ? 0 : 31;
return Is32() ? SmiTagging<4>::SmiShiftSize()
: SmiTagging<8>::SmiShiftSize();
}
int SmiValueSize() const {
// TODO(turbofan): Work-around for weird GCC 4.6 linker issue:
// src/compiler/change-lowering.cc:46: undefined reference to
// `v8::internal::SmiTagging<4u>::kSmiValueSize'
// src/compiler/change-lowering.cc:46: undefined reference to
// `v8::internal::SmiTagging<8u>::kSmiValueSize'
STATIC_ASSERT(SmiTagging<4>::kSmiValueSize == 31);
STATIC_ASSERT(SmiTagging<8>::kSmiValueSize == 32);
return Is32() ? 31 : 32;
return Is32() ? SmiTagging<4>::SmiValueSize()
: SmiTagging<8>::SmiValueSize();
}
Node* Parameter(int32_t index = 0) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment