Reviewers: Yang, danno, Paul Lind, kisg,

Description:
MIPS: avoid alignment issues in FillHeapNumberWithRandom.

Copy the value using memcpy on native MIPS targets to avoid unaligned memory
access.

BUG=
TEST=cctest test-random/CrankshaftRandom


Please review this at http://codereview.chromium.org/9617011/

Affected files:
  M src/v8.cc


Index: src/v8.cc
diff --git a/src/v8.cc b/src/v8.cc
index 003c75ce0b36b7567113cb0b3c1c191b3c36c24b..76546bab8874102a03fb17b536992b88e0e58e67 100644
--- a/src/v8.cc
+++ b/src/v8.cc
@@ -224,10 +224,19 @@ typedef union {
 Object* V8::FillHeapNumberWithRandom(Object* heap_number,
                                      Context* context) {
   uint64_t random_bits = Random(context);
+#ifdef V8_HOST_ARCH_MIPS
+  // Copy the value to a local variable to avoid alignment issues.
+  double_int_union num;
+  double_int_union* r = #
+  memcpy(r, heap_number + HeapNumber::kValueOffset - kHeapObjectTag,
+      sizeof(num));
+#else
   // Make a double* from address (heap_number + sizeof(double)).
   double_int_union* r = reinterpret_cast<double_int_union*>(
       reinterpret_cast<char*>(heap_number) +
       HeapNumber::kValueOffset - kHeapObjectTag);
+#endif
+
   // Convert 32 random bits to 0.(32 random bits) in a double
   // by computing:
   // ( 1.(20 0s)(32 random bits) x 2^20 ) - (1.0 x 2^20)).
@@ -236,6 +245,11 @@ Object* V8::FillHeapNumberWithRandom(Object* heap_number,
   r->uint64_t_value |=  random_bits;
   r->double_value -= binary_million;

+#ifdef V8_HOST_ARCH_MIPS
+  memcpy(heap_number + HeapNumber::kValueOffset - kHeapObjectTag, r,
+      sizeof(num));
+#endif
+
   return heap_number;
 }



--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to