Revision: 6388
Author: [email protected]
Date: Wed Jan 19 03:16:23 2011
Log: Using unsigned shifts and masks when dealing with 64-bit addresses.
BUG=v8:1037
Review URL: http://codereview.chromium.org/6242005
http://code.google.com/p/v8/source/detail?r=6388
Modified:
/branches/bleeding_edge/include/v8.h
/branches/bleeding_edge/src/api.cc
/branches/bleeding_edge/test/cctest/test-api.cc
=======================================
--- /branches/bleeding_edge/include/v8.h Thu Jan 13 07:56:33 2011
+++ /branches/bleeding_edge/include/v8.h Wed Jan 19 03:16:23 2011
@@ -3367,7 +3367,7 @@
// For 32-bit systems any 2 bytes aligned pointer can be encoded as smi
// with a plain reinterpret_cast.
- static const intptr_t kEncodablePointerMask = 0x1;
+ static const uintptr_t kEncodablePointerMask = 0x1;
static const int kPointerToSmiShift = 0;
};
@@ -3387,8 +3387,8 @@
// It might be not enough to cover stack allocated objects on some
platforms.
static const int kPointerAlignment = 3;
- static const intptr_t kEncodablePointerMask =
- ~(intptr_t(0xffffffff) << kPointerAlignment);
+ static const uintptr_t kEncodablePointerMask =
+ ~(uintptr_t(0xffffffff) << kPointerAlignment);
static const int kPointerToSmiShift =
kSmiTagSize + kSmiShiftSize - kPointerAlignment;
@@ -3397,7 +3397,7 @@
typedef SmiTagging<kApiPointerSize> PlatformSmiTagging;
const int kSmiShiftSize = PlatformSmiTagging::kSmiShiftSize;
const int kSmiValueSize = PlatformSmiTagging::kSmiValueSize;
-const intptr_t kEncodablePointerMask =
+const uintptr_t kEncodablePointerMask =
PlatformSmiTagging::kEncodablePointerMask;
const int kPointerToSmiShift = PlatformSmiTagging::kPointerToSmiShift;
@@ -3457,7 +3457,7 @@
}
static inline void* GetExternalPointerFromSmi(internal::Object* value) {
- const intptr_t address = reinterpret_cast<intptr_t>(value);
+ const uintptr_t address = reinterpret_cast<uintptr_t>(value);
return reinterpret_cast<void*>(address >> kPointerToSmiShift);
}
=======================================
--- /branches/bleeding_edge/src/api.cc Thu Jan 13 07:56:33 2011
+++ /branches/bleeding_edge/src/api.cc Wed Jan 19 03:16:23 2011
@@ -3267,14 +3267,14 @@
static bool CanBeEncodedAsSmi(void* ptr) {
- const intptr_t address = reinterpret_cast<intptr_t>(ptr);
+ const uintptr_t address = reinterpret_cast<uintptr_t>(ptr);
return ((address & i::kEncodablePointerMask) == 0);
}
static i::Smi* EncodeAsSmi(void* ptr) {
ASSERT(CanBeEncodedAsSmi(ptr));
- const intptr_t address = reinterpret_cast<intptr_t>(ptr);
+ const uintptr_t address = reinterpret_cast<uintptr_t>(ptr);
i::Smi* result = reinterpret_cast<i::Smi*>(address <<
i::kPointerToSmiShift);
ASSERT(i::Internals::HasSmiTag(result));
ASSERT_EQ(result, i::Smi::FromInt(result->value()));
=======================================
--- /branches/bleeding_edge/test/cctest/test-api.cc Fri Jan 14 05:14:26 2011
+++ /branches/bleeding_edge/test/cctest/test-api.cc Wed Jan 19 03:16:23 2011
@@ -874,6 +874,10 @@
TestExternalPointerWrapping();
#if defined(V8_HOST_ARCH_X64)
+ // Check a value with a leading 1 bit in x64 Smi encoding.
+ expected_ptr = reinterpret_cast<void*>(0x400000000);
+ TestExternalPointerWrapping();
+
expected_ptr = reinterpret_cast<void*>(0xdeadbeefdeadbeef);
TestExternalPointerWrapping();
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev