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

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

Issue 148153010: Synchronize with r15701. (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-assembler-arm.cc ('k') | test/cctest/test-compare-nil-ic-stub.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28 #include <stdlib.h>
29
30 #include <limits>
31
32 #include "v8.h"
33
34 #include "cctest.h"
35 #include "code-stubs.h"
36 #include "factory.h"
37 #include "macro-assembler.h"
38 #include "platform.h"
39
40 #if __GNUC__
41 #define STDCALL __attribute__((stdcall))
42 #else
43 #define STDCALL __stdcall
44 #endif
45
46 using namespace v8::internal;
47
48
49 typedef int32_t STDCALL ConvertDToIFuncType(double input);
50 typedef ConvertDToIFuncType* ConvertDToIFunc;
51
52
53 int STDCALL ConvertDToICVersion(double d) {
54 Address double_ptr = reinterpret_cast<Address>(&d);
55 uint32_t exponent_bits = Memory::uint32_at(double_ptr + kDoubleSize / 2);
56 int32_t shifted_mask = static_cast<int32_t>(Double::kExponentMask >> 32);
57 int32_t exponent = (((exponent_bits & shifted_mask) >>
58 (Double::kPhysicalSignificandSize - 32)) -
59 HeapNumber::kExponentBias);
60 uint32_t unsigned_exponent = static_cast<uint32_t>(exponent);
61 int result = 0;
62 uint32_t max_exponent =
63 static_cast<uint32_t>(Double::kPhysicalSignificandSize);
64 if (unsigned_exponent >= max_exponent) {
65 if ((exponent - Double::kPhysicalSignificandSize) < 32) {
66 result = Memory::uint32_at(double_ptr) <<
67 (exponent - Double::kPhysicalSignificandSize);
68 }
69 } else {
70 uint64_t big_result =
71 (BitCast<uint64_t>(d) & Double::kSignificandMask) | Double::kHiddenBit;
72 big_result = big_result >> (Double::kPhysicalSignificandSize - exponent);
73 result = static_cast<uint32_t>(big_result);
74 }
75 if (static_cast<int32_t>(exponent_bits) < 0) {
76 return (0 - result);
77 } else {
78 return result;
79 }
80 }
81
82
83 void RunOneTruncationTestWithTest(ConvertDToIFunc func,
84 double from,
85 double raw) {
86 uint64_t to = static_cast<int64_t>(raw);
87 int result = (*func)(from);
88 CHECK_EQ(static_cast<int>(to), result);
89 }
90
91
92 // #define NaN and Infinity so that it's possible to cut-and-paste these tests
93 // directly to a .js file and run them.
94 #define NaN (OS::nan_value())
95 #define Infinity (std::numeric_limits<double>::infinity())
96 #define RunOneTruncationTest(p1, p2) RunOneTruncationTestWithTest(func, p1, p2)
97
98 void RunAllTruncationTests(ConvertDToIFunc func) {
99 RunOneTruncationTest(0, 0);
100 RunOneTruncationTest(0.5, 0);
101 RunOneTruncationTest(-0.5, 0);
102 RunOneTruncationTest(1.5, 1);
103 RunOneTruncationTest(-1.5, -1);
104 RunOneTruncationTest(5.5, 5);
105 RunOneTruncationTest(-5.0, -5);
106 RunOneTruncationTest(NaN, 0);
107 RunOneTruncationTest(Infinity, 0);
108 RunOneTruncationTest(-NaN, 0);
109 RunOneTruncationTest(-Infinity, 0);
110
111 RunOneTruncationTest(4.5036e+15, 0x1635E000);
112 RunOneTruncationTest(-4.5036e+15, -372629504);
113
114 RunOneTruncationTest(4503603922337791.0, -1);
115 RunOneTruncationTest(-4503603922337791.0, 1);
116 RunOneTruncationTest(4503601774854143.0, 2147483647);
117 RunOneTruncationTest(-4503601774854143.0, -2147483647);
118 RunOneTruncationTest(9007207844675582.0, -2);
119 RunOneTruncationTest(-9007207844675582.0, 2);
120 RunOneTruncationTest(2.4178527921507624e+24, -536870912);
121 RunOneTruncationTest(-2.4178527921507624e+24, 536870912);
122 RunOneTruncationTest(2.417853945072267e+24, -536870912);
123 RunOneTruncationTest(-2.417853945072267e+24, 536870912);
124
125 RunOneTruncationTest(4.8357055843015248e+24, -1073741824);
126 RunOneTruncationTest(-4.8357055843015248e+24, 1073741824);
127 RunOneTruncationTest(4.8357078901445341e+24, -1073741824);
128 RunOneTruncationTest(-4.8357078901445341e+24, 1073741824);
129
130 RunOneTruncationTest(9.6714111686030497e+24, -2147483648.0);
131 RunOneTruncationTest(-9.6714111686030497e+24, -2147483648.0);
132 RunOneTruncationTest(9.6714157802890681e+24, -2147483648.0);
133 RunOneTruncationTest(-9.6714157802890681e+24, -2147483648.0);
134 }
135
136 #undef NaN
137 #undef Infinity
138 #undef RunOneTruncationTest
139
140 #define __ assm.
141
142 ConvertDToIFunc MakeConvertDToIFuncTrampoline(Isolate* isolate,
143 Register source_reg,
144 Register destination_reg) {
145 // Allocate an executable page of memory.
146 size_t actual_size;
147 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize,
148 &actual_size,
149 true));
150 CHECK(buffer);
151 HandleScope handles(isolate);
152 MacroAssembler assm(isolate, buffer, static_cast<int>(actual_size));
153 assm.set_allow_stub_calls(false);
154 int offset =
155 source_reg.is(esp) ? 0 : (HeapNumber::kValueOffset - kSmiTagSize);
156 DoubleToIStub stub(source_reg, destination_reg, offset, true);
157 byte* start = stub.GetCode(isolate)->instruction_start();
158
159 __ push(ebx);
160 __ push(ecx);
161 __ push(edx);
162 __ push(esi);
163 __ push(edi);
164
165 if (!source_reg.is(esp)) {
166 __ lea(source_reg, MemOperand(esp, 6 * kPointerSize - offset));
167 }
168
169 int param_offset = 7 * kPointerSize;
170 // Save registers make sure they don't get clobbered.
171 int reg_num = 0;
172 for (;reg_num < Register::NumAllocatableRegisters(); ++reg_num) {
173 Register reg = Register::from_code(reg_num);
174 if (!reg.is(esp) && !reg.is(ebp) && !reg.is(destination_reg)) {
175 __ push(reg);
176 param_offset += kPointerSize;
177 }
178 }
179
180 // Re-push the double argument
181 __ push(MemOperand(esp, param_offset));
182 __ push(MemOperand(esp, param_offset));
183
184 // Call through to the actual stub
185 __ call(start, RelocInfo::EXTERNAL_REFERENCE);
186
187 __ add(esp, Immediate(kDoubleSize));
188
189 // Make sure no registers have been unexpectedly clobbered
190 for (--reg_num; reg_num >= 0; --reg_num) {
191 Register reg = Register::from_code(reg_num);
192 if (!reg.is(esp) && !reg.is(ebp) && !reg.is(destination_reg)) {
193 __ cmp(reg, MemOperand(esp, 0));
194 __ Assert(equal, "register was clobbered");
195 __ add(esp, Immediate(kPointerSize));
196 }
197 }
198
199 __ mov(eax, destination_reg);
200
201 __ pop(edi);
202 __ pop(esi);
203 __ pop(edx);
204 __ pop(ecx);
205 __ pop(ebx);
206
207 __ ret(kDoubleSize);
208
209 CodeDesc desc;
210 assm.GetCode(&desc);
211 return reinterpret_cast<ConvertDToIFunc>(
212 reinterpret_cast<intptr_t>(buffer));
213 }
214
215 #undef __
216
217
218 static Isolate* GetIsolateFrom(LocalContext* context) {
219 return reinterpret_cast<Isolate*>((*context)->GetIsolate());
220 }
221
222
223 TEST(ConvertDToI) {
224 CcTest::InitializeVM();
225 LocalContext context;
226 Isolate* isolate = GetIsolateFrom(&context);
227 HandleScope scope(isolate);
228
229 #if DEBUG
230 // Verify that the tests actually work with the C version. In the release
231 // code, the compiler optimizes it away because it's all constant, but does it
232 // wrong, triggering an assert on gcc.
233 RunAllTruncationTests(&ConvertDToICVersion);
234 #endif
235
236 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, esp, eax));
237 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, esp, ebx));
238 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, esp, ecx));
239 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, esp, edx));
240 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, esp, edi));
241 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, esp, esi));
242 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, eax, eax));
243 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, eax, ebx));
244 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, eax, ecx));
245 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, eax, edx));
246 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, eax, edi));
247 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, eax, esi));
248 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, ebx, eax));
249 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, ebx, ebx));
250 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, ebx, ecx));
251 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, ebx, edx));
252 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, ebx, edi));
253 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, ebx, esi));
254 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, ecx, eax));
255 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, ecx, ebx));
256 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, ecx, ecx));
257 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, ecx, edx));
258 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, ecx, edi));
259 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, ecx, esi));
260 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, edx, eax));
261 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, edx, ebx));
262 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, edx, ecx));
263 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, edx, edx));
264 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, edx, edi));
265 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, edx, esi));
266 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, esi, eax));
267 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, esi, ebx));
268 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, esi, ecx));
269 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, esi, edx));
270 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, esi, edi));
271 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, esi, esi));
272 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, edi, eax));
273 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, edi, ebx));
274 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, edi, ecx));
275 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, edi, edx));
276 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, edi, edi));
277 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, edi, esi));
278 }
OLDNEW
« no previous file with comments | « test/cctest/test-assembler-arm.cc ('k') | test/cctest/test-compare-nil-ic-stub.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698