Reviewers: jarin,
Message:
PTAL
Description:
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.
Please review this at https://codereview.chromium.org/527603002/
SVN Base: [email protected]:v8/v8.git@master
Affected files (+12, -36 lines):
M include/v8.h
M src/compiler/change-lowering.cc
M test/compiler-unittests/change-lowering-unittest.cc
Index: include/v8.h
diff --git a/include/v8.h b/include/v8.h
index
cbe8edd59b59349f1492d68853c21ca79f9f122b..d2f3ba2869d668d5e581a5176ea92fea96d1b626
100644
--- a/include/v8.h
+++ b/include/v8.h
@@ -5606,8 +5606,7 @@ 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 };
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 +5633,7 @@ 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 };
V8_INLINE static int SmiToInt(const internal::Object* value) {
int shift_bits = kSmiTagSize + kSmiShiftSize;
// Shift down and throw away top 32 bits.
Index: src/compiler/change-lowering.cc
diff --git a/src/compiler/change-lowering.cc
b/src/compiler/change-lowering.cc
index
c2805bb0a329b463536b0deef8edadc6fa567d47..91a26d4aea4dfaa40b5b9fb83a102067c16af2b0
100644
--- a/src/compiler/change-lowering.cc
+++ b/src/compiler/change-lowering.cc
@@ -50,28 +50,18 @@ 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() ? static_cast<int>(SmiTagging<4>::kSmiValueSize)
+ : static_cast<int>(SmiTagging<8>::kSmiValueSize);
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()->is64() ? static_cast<int>(SmiTagging<4>::kSmiShiftSize)
+ : static_cast<int>(SmiTagging<8>::kSmiShiftSize);
return jsgraph()->Int32Constant(smi_shift_size + kSmiTagSize);
}
Index: test/compiler-unittests/change-lowering-unittest.cc
diff --git a/test/compiler-unittests/change-lowering-unittest.cc
b/test/compiler-unittests/change-lowering-unittest.cc
index
4ea125a5f4cd20b51b01f1d30443f4dc64ca1bfb..7938d50954e17283b4edbc1f8f20c9acd784cb5f
100644
--- a/test/compiler-unittests/change-lowering-unittest.cc
+++ b/test/compiler-unittests/change-lowering-unittest.cc
@@ -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() ? static_cast<int>(SmiTagging<4>::kSmiShiftSize)
+ : static_cast<int>(SmiTagging<8>::kSmiShiftSize);
}
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() ? static_cast<int>(SmiTagging<4>::kSmiValueSize)
+ : static_cast<int>(SmiTagging<8>::kSmiValueSize);
}
Node* Parameter(int32_t index = 0) {
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.