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

Unified Diff: test/cctest/test-code-stubs.cc

Issue 18333012: x64 support for d-to-i (truncated) (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Feedback addressed Created 7 years, 5 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 | « test/cctest/test-code-stubs.h ('k') | test/cctest/test-code-stubs-ia32.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-code-stubs.cc
diff --git a/test/mjsunit/double-truncation.js b/test/cctest/test-code-stubs.cc
similarity index 54%
copy from test/mjsunit/double-truncation.js
copy to test/cctest/test-code-stubs.cc
index b43e1e6c6353ae0497667312fc6956b08148efa2..405069626bec4d076173f9a1441b62b3554e0498 100644
--- a/test/mjsunit/double-truncation.js
+++ b/test/cctest/test-code-stubs.cc
@@ -1,4 +1,4 @@
-// Copyright 2012 the V8 project authors. All rights reserved.
+// Copyright 2013 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
@@ -25,14 +25,68 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Flags: --allow-natives-syntax
+#include <stdlib.h>
-function RunOneTruncationTest(a, b) {
- var temp = a | 0;
- assertEquals(b, temp);
+#include <limits>
+
+#include "v8.h"
+
+#include "cctest.h"
+#include "code-stubs.h"
+#include "test-code-stubs.h"
+#include "factory.h"
+#include "macro-assembler.h"
+#include "platform.h"
+
+using namespace v8::internal;
+
+
+int STDCALL ConvertDToICVersion(double d) {
+ Address double_ptr = reinterpret_cast<Address>(&d);
+ uint32_t exponent_bits = Memory::uint32_at(double_ptr + kDoubleSize / 2);
+ int32_t shifted_mask = static_cast<int32_t>(Double::kExponentMask >> 32);
+ int32_t exponent = (((exponent_bits & shifted_mask) >>
+ (Double::kPhysicalSignificandSize - 32)) -
+ HeapNumber::kExponentBias);
+ uint32_t unsigned_exponent = static_cast<uint32_t>(exponent);
+ int result = 0;
+ uint32_t max_exponent =
+ static_cast<uint32_t>(Double::kPhysicalSignificandSize);
+ if (unsigned_exponent >= max_exponent) {
+ if ((exponent - Double::kPhysicalSignificandSize) < 32) {
+ result = Memory::uint32_at(double_ptr) <<
+ (exponent - Double::kPhysicalSignificandSize);
+ }
+ } else {
+ uint64_t big_result =
+ (BitCast<uint64_t>(d) & Double::kSignificandMask) | Double::kHiddenBit;
+ big_result = big_result >> (Double::kPhysicalSignificandSize - exponent);
+ result = static_cast<uint32_t>(big_result);
+ }
+ if (static_cast<int32_t>(exponent_bits) < 0) {
+ return (0 - result);
+ } else {
+ return result;
+ }
}
-function RunAllTruncationTests() {
+
+void RunOneTruncationTestWithTest(ConvertDToIFunc func,
+ double from,
+ double raw) {
+ uint64_t to = static_cast<int64_t>(raw);
+ int result = (*func)(from);
+ CHECK_EQ(static_cast<int>(to), result);
+}
+
+
+// #define NaN and Infinity so that it's possible to cut-and-paste these tests
+// directly to a .js file and run them.
+#define NaN (OS::nan_value())
+#define Infinity (std::numeric_limits<double>::infinity())
+#define RunOneTruncationTest(p1, p2) RunOneTruncationTestWithTest(func, p1, p2)
+
+void RunAllTruncationTests(ConvertDToIFunc func) {
RunOneTruncationTest(0, 0);
RunOneTruncationTest(0.5, 0);
RunOneTruncationTest(-0.5, 0);
@@ -65,14 +119,12 @@ function RunAllTruncationTests() {
RunOneTruncationTest(4.8357078901445341e+24, -1073741824);
RunOneTruncationTest(-4.8357078901445341e+24, 1073741824);
- RunOneTruncationTest(9.6714111686030497e+24, -2147483648);
- RunOneTruncationTest(-9.6714111686030497e+24, -2147483648);
- RunOneTruncationTest(9.6714157802890681e+24, -2147483648);
- RunOneTruncationTest(-9.6714157802890681e+24, -2147483648);
+ RunOneTruncationTest(9.6714111686030497e+24, -2147483648.0);
+ RunOneTruncationTest(-9.6714111686030497e+24, -2147483648.0);
+ RunOneTruncationTest(9.6714157802890681e+24, -2147483648.0);
+ RunOneTruncationTest(-9.6714157802890681e+24, -2147483648.0);
}
-RunAllTruncationTests();
-RunAllTruncationTests();
-%OptimizeFunctionOnNextCall(RunOneTruncationTest);
-RunAllTruncationTests();
-RunAllTruncationTests();
+#undef NaN
+#undef Infinity
+#undef RunOneTruncationTest
« no previous file with comments | « test/cctest/test-code-stubs.h ('k') | test/cctest/test-code-stubs-ia32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698