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

Side by Side Diff: test/cctest/test-code-stubs.cc

Issue 151163005: A64: Synchronize with r16356. (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/a64
Patch Set: Created 6 years, 10 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « test/cctest/test-code-stubs.h ('k') | test/cctest/test-code-stubs-arm.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 24 matching lines...) Expand all
35 #include "code-stubs.h" 35 #include "code-stubs.h"
36 #include "test-code-stubs.h" 36 #include "test-code-stubs.h"
37 #include "factory.h" 37 #include "factory.h"
38 #include "macro-assembler.h" 38 #include "macro-assembler.h"
39 #include "platform.h" 39 #include "platform.h"
40 40
41 using namespace v8::internal; 41 using namespace v8::internal;
42 42
43 43
44 int STDCALL ConvertDToICVersion(double d) { 44 int STDCALL ConvertDToICVersion(double d) {
45 Address double_ptr = reinterpret_cast<Address>(&d); 45 union { double d; uint32_t u[2]; } dbl;
46 uint32_t exponent_bits = Memory::uint32_at(double_ptr + kDoubleSize / 2); 46 dbl.d = d;
47 uint32_t exponent_bits = dbl.u[1];
47 int32_t shifted_mask = static_cast<int32_t>(Double::kExponentMask >> 32); 48 int32_t shifted_mask = static_cast<int32_t>(Double::kExponentMask >> 32);
48 int32_t exponent = (((exponent_bits & shifted_mask) >> 49 int32_t exponent = (((exponent_bits & shifted_mask) >>
49 (Double::kPhysicalSignificandSize - 32)) - 50 (Double::kPhysicalSignificandSize - 32)) -
50 HeapNumber::kExponentBias); 51 HeapNumber::kExponentBias);
51 uint32_t unsigned_exponent = static_cast<uint32_t>(exponent); 52 uint32_t unsigned_exponent = static_cast<uint32_t>(exponent);
52 int result = 0; 53 int result = 0;
53 uint32_t max_exponent = 54 uint32_t max_exponent =
54 static_cast<uint32_t>(Double::kPhysicalSignificandSize); 55 static_cast<uint32_t>(Double::kPhysicalSignificandSize);
55 if (unsigned_exponent >= max_exponent) { 56 if (unsigned_exponent >= max_exponent) {
56 if ((exponent - Double::kPhysicalSignificandSize) < 32) { 57 if ((exponent - Double::kPhysicalSignificandSize) < 32) {
57 result = Memory::uint32_at(double_ptr) << 58 result = dbl.u[0] << (exponent - Double::kPhysicalSignificandSize);
58 (exponent - Double::kPhysicalSignificandSize);
59 } 59 }
60 } else { 60 } else {
61 uint64_t big_result = 61 uint64_t big_result =
62 (BitCast<uint64_t>(d) & Double::kSignificandMask) | Double::kHiddenBit; 62 (BitCast<uint64_t>(d) & Double::kSignificandMask) | Double::kHiddenBit;
63 big_result = big_result >> (Double::kPhysicalSignificandSize - exponent); 63 big_result = big_result >> (Double::kPhysicalSignificandSize - exponent);
64 result = static_cast<uint32_t>(big_result); 64 result = static_cast<uint32_t>(big_result);
65 } 65 }
66 if (static_cast<int32_t>(exponent_bits) < 0) { 66 if (static_cast<int32_t>(exponent_bits) < 0) {
67 return (0 - result); 67 return (0 - result);
68 } else { 68 } else {
69 return result; 69 return result;
70 } 70 }
71 } 71 }
72 72
73 73
74 void RunOneTruncationTestWithTest(ConvertDToIFunc func, 74 void RunOneTruncationTestWithTest(ConvertDToICallWrapper callWrapper,
75 ConvertDToIFunc func,
75 double from, 76 double from,
76 double raw) { 77 double raw) {
77 uint64_t to = static_cast<int64_t>(raw); 78 uint64_t to = static_cast<int64_t>(raw);
78 int result = (*func)(from); 79 int result = (*callWrapper)(func, from);
79 CHECK_EQ(static_cast<int>(to), result); 80 CHECK_EQ(static_cast<int>(to), result);
80 } 81 }
81 82
82 83
84 int32_t DefaultCallWrapper(ConvertDToIFunc func,
85 double from) {
86 return (*func)(from);
87 }
88
89
83 // #define NaN and Infinity so that it's possible to cut-and-paste these tests 90 // #define NaN and Infinity so that it's possible to cut-and-paste these tests
84 // directly to a .js file and run them. 91 // directly to a .js file and run them.
85 #define NaN (OS::nan_value()) 92 #define NaN (OS::nan_value())
86 #define Infinity (std::numeric_limits<double>::infinity()) 93 #define Infinity (std::numeric_limits<double>::infinity())
87 #define RunOneTruncationTest(p1, p2) RunOneTruncationTestWithTest(func, p1, p2) 94 #define RunOneTruncationTest(p1, p2) \
95 RunOneTruncationTestWithTest(callWrapper, func, p1, p2)
96
88 97
89 void RunAllTruncationTests(ConvertDToIFunc func) { 98 void RunAllTruncationTests(ConvertDToIFunc func) {
99 RunAllTruncationTests(DefaultCallWrapper, func);
100 }
101
102
103 void RunAllTruncationTests(ConvertDToICallWrapper callWrapper,
104 ConvertDToIFunc func) {
90 RunOneTruncationTest(0, 0); 105 RunOneTruncationTest(0, 0);
91 RunOneTruncationTest(0.5, 0); 106 RunOneTruncationTest(0.5, 0);
92 RunOneTruncationTest(-0.5, 0); 107 RunOneTruncationTest(-0.5, 0);
93 RunOneTruncationTest(1.5, 1); 108 RunOneTruncationTest(1.5, 1);
94 RunOneTruncationTest(-1.5, -1); 109 RunOneTruncationTest(-1.5, -1);
95 RunOneTruncationTest(5.5, 5); 110 RunOneTruncationTest(5.5, 5);
96 RunOneTruncationTest(-5.0, -5); 111 RunOneTruncationTest(-5.0, -5);
97 RunOneTruncationTest(NaN, 0); 112 RunOneTruncationTest(NaN, 0);
98 RunOneTruncationTest(Infinity, 0); 113 RunOneTruncationTest(Infinity, 0);
99 RunOneTruncationTest(-NaN, 0); 114 RunOneTruncationTest(-NaN, 0);
(...skipping 21 matching lines...) Expand all
121 136
122 RunOneTruncationTest(9.6714111686030497e+24, -2147483648.0); 137 RunOneTruncationTest(9.6714111686030497e+24, -2147483648.0);
123 RunOneTruncationTest(-9.6714111686030497e+24, -2147483648.0); 138 RunOneTruncationTest(-9.6714111686030497e+24, -2147483648.0);
124 RunOneTruncationTest(9.6714157802890681e+24, -2147483648.0); 139 RunOneTruncationTest(9.6714157802890681e+24, -2147483648.0);
125 RunOneTruncationTest(-9.6714157802890681e+24, -2147483648.0); 140 RunOneTruncationTest(-9.6714157802890681e+24, -2147483648.0);
126 } 141 }
127 142
128 #undef NaN 143 #undef NaN
129 #undef Infinity 144 #undef Infinity
130 #undef RunOneTruncationTest 145 #undef RunOneTruncationTest
OLDNEW
« no previous file with comments | « test/cctest/test-code-stubs.h ('k') | test/cctest/test-code-stubs-arm.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698