Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(104)

Unified Diff: include/v8.h

Issue 287004: Remove dependency on V8_TARGET_ARCH in v8.h (Closed)
Patch Set: Created 11 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/v8.h
diff --git a/include/v8.h b/include/v8.h
index 25024d98df551ac7a1f8820e2091d0a9bb332249..577c3cf987e083d90190540b7e53ee3d80880996 100644
--- a/include/v8.h
+++ b/include/v8.h
@@ -2715,26 +2715,48 @@ class V8EXPORT Locker {
namespace internal {
+template <size_t ptr_size> struct SmiConstants;
+
+// Smi constants for 32-bit systems.
+template <> struct SmiConstants<4> {
+ static const int kSmiTag = 0;
Christian Plesner Hansen 2009/10/16 09:39:10 Some of these constants seems to be independent of
Lasse Reichstein 2009/10/16 10:19:11 Done. This required moving the templates below the
+ static const int kSmiTagSize = 1;
+ static const intptr_t kSmiTagMask = (1 << kSmiTagSize) - 1;
+ static const int kSmiShiftSize = 0;
+ static const int kSmiValueSize = 31;
+ static inline int SmiToInt(internal::Object* value) {
+ int shift_bits = kSmiTagSize + kSmiShiftSize;
+ // Throw away top 32 bits and shift down (requires >> to be sign extending).
+ return static_cast<int>(reinterpret_cast<intptr_t>(value)) >> shift_bits;
+ }
+};
+
+// Smi constants for 64-bit systems.
+template <> struct SmiConstants<8> {
+ static const int kSmiTag = 0;
+ static const int kSmiTagSize = 1;
+ static const intptr_t kSmiTagMask = (1 << kSmiTagSize) - 1;
+ static const int kSmiShiftSize = 31;
+ static const int kSmiValueSize = 32;
+ static inline int SmiToInt(internal::Object* value) {
+ int shift_bits = kSmiTagSize + kSmiShiftSize;
+ // Shift down and throw away top 32 bits.
+ return static_cast<int>(reinterpret_cast<intptr_t>(value) >> shift_bits);
+ }
+};
+
+
// Tag information for HeapObject.
const int kHeapObjectTag = 1;
const int kHeapObjectTagSize = 2;
const intptr_t kHeapObjectTagMask = (1 << kHeapObjectTagSize) - 1;
-#ifdef V8_TARGET_ARCH_X64
-// Tag information for Smi.
-const int kSmiTag = 0;
-const int kSmiTagSize = 1;
-const intptr_t kSmiTagMask = (1 << kSmiTagSize) - 1;
-const int kSmiShiftSize = 31;
-const int kSmiValueSize = 32;
-#else
// Tag information for Smi.
-const int kSmiTag = 0;
-const int kSmiTagSize = 1;
-const intptr_t kSmiTagMask = (1 << kSmiTagSize) - 1;
-const int kSmiShiftSize = 0;
-const int kSmiValueSize = 31;
-#endif
+const int kSmiTag = SmiConstants<sizeof(void*)>::kSmiTag;
+const int kSmiTagSize = SmiConstants<sizeof(void*)>::kSmiTagSize;
+const intptr_t kSmiTagMask = SmiConstants<sizeof(void*)>::kSmiTagMask;
+const int kSmiShiftSize = SmiConstants<sizeof(void*)>::kSmiShiftSize;
+const int kSmiValueSize = SmiConstants<sizeof(void*)>::kSmiValueSize;
/**
* This class exports constants and functionality from within v8 that
@@ -2771,15 +2793,7 @@ class Internals {
}
static inline int SmiValue(internal::Object* value) {
-#ifdef V8_TARGET_ARCH_X64
- int shift_bits = kSmiTagSize + kSmiShiftSize;
- // Shift down and throw away top 32 bits.
- return static_cast<int>(reinterpret_cast<intptr_t>(value) >> shift_bits);
-#else
- int shift_bits = kSmiTagSize + kSmiShiftSize;
- // Throw away top 32 bits and shift down (requires >> to be sign extending).
- return static_cast<int>(reinterpret_cast<intptr_t>(value)) >> shift_bits;
-#endif
+ return SmiConstants<sizeof(void*)>::SmiToInt(value);
}
static inline bool IsExternalTwoByteString(int instance_type) {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698