Take ARM big-endian floating point numbers into account in FastD2UI.
authorlrn@chromium.org <lrn@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Tue, 16 Mar 2010 12:20:52 +0000 (12:20 +0000)
committerlrn@chromium.org <lrn@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Tue, 16 Mar 2010 12:20:52 +0000 (12:20 +0000)
Review URL: http://codereview.chromium.org/996004

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@4144 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

src/conversions-inl.h

index f7210d5af9c47f7b7d3d650bc6ce7fd54546a776..3037085141b518628b7899fbda38e9f1a1c95371 100644 (file)
@@ -60,7 +60,8 @@ static inline int FastD2I(double x) {
 
 
 // The fast double-to-unsigned-int conversion routine does not guarantee
-// rounding towards zero.
+// rounding towards zero, or any reasonable value if the argument is larger
+// than what fits in an unsigned 32-bit integer.
 static inline unsigned int FastD2UI(double x) {
   // There is no unsigned version of lrint, so there is no fast path
   // in this function as there is in FastD2I. Using lrint doesn't work
@@ -77,7 +78,13 @@ static inline unsigned int FastD2UI(double x) {
   if (x < k2Pow52) {
     x += k2Pow52;
     uint32_t result;
-    memcpy(&result, &x, sizeof(result));  // Copy low 32 bits.
+#ifdef BIG_ENDIAN_FLOATING_POINT
+    Address mantissa_ptr = reinterpret_cast<Address>(&x) + kIntSize;
+#else
+    Address mantissa_ptr = reinterpret_cast<Address>(&x);
+#endif
+    // Copy least significant 32 bits of mantissa.
+    memcpy(&result, mantissa_ptr, sizeof(result));
     return negative ? ~result + 1 : result;
   }
   // Large number (outside uint32 range), Infinity or NaN.