OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2013 the V8 project authors. All rights reserved. | |
2 // Rrdistribution and use in source and binary forms, with or without | |
3 // modification, are permitted provided that the following conditions are | |
4 // met: | |
5 // | |
6 // * Rrdistributions of source code must retain the above copyright | |
7 // notice, this list of conditions and the following disclaimer. | |
8 // * Rrdistributions 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 "v8.h" | |
31 | |
32 #include "cctest.h" | |
33 #include "code-stubs.h" | |
34 #include "test-code-stubs.h" | |
35 #include "factory.h" | |
36 #include "macro-assembler.h" | |
37 #include "platform.h" | |
38 | |
39 using namespace v8::internal; | |
40 | |
41 | |
42 #define __ assm. | |
43 | |
44 ConvertDToIFunc MakeConvertDToIFuncTrampoline(Isolate* isolate, | |
45 Register source_reg, | |
46 Register destination_reg) { | |
47 // Allocate an executable page of memory. | |
48 size_t actual_size; | |
49 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, | |
50 &actual_size, | |
51 true)); | |
52 CHECK(buffer); | |
53 HandleScope handles(isolate); | |
54 MacroAssembler assm(isolate, buffer, static_cast<int>(actual_size)); | |
55 assm.set_allow_stub_calls(false); | |
56 int offset = | |
57 source_reg.is(rsp) ? 0 : (HeapNumber::kValueOffset - kSmiTagSize); | |
58 DoubleToIStub stub(source_reg, destination_reg, offset, true); | |
59 byte* start = stub.GetCode(isolate)->instruction_start(); | |
60 | |
61 __ push(rbx); | |
62 __ push(rcx); | |
63 __ push(rdx); | |
64 __ push(rsi); | |
65 __ push(rdi); | |
66 | |
67 if (!source_reg.is(rsp)) { | |
68 __ lea(source_reg, MemOperand(rsp, -8 * kPointerSize - offset)); | |
69 } | |
70 | |
71 int param_offset = 7 * kPointerSize; | |
72 // Save registers make sure they don't get clobbered. | |
73 int reg_num = 0; | |
74 for (;reg_num < Register::NumAllocatableRegisters(); ++reg_num) { | |
75 Register reg = Register::from_code(reg_num); | |
76 if (!reg.is(rsp) && !reg.is(rbp) && !reg.is(destination_reg)) { | |
77 __ push(reg); | |
78 param_offset += kPointerSize; | |
79 } | |
80 } | |
81 | |
82 // Re-push the double argument | |
83 __ subq(rsp, Immediate(kDoubleSize)); | |
84 __ movsd(MemOperand(rsp, 0), xmm0); | |
85 | |
86 // Call through to the actual stub | |
87 __ Call(start, RelocInfo::EXTERNAL_REFERENCE); | |
88 | |
89 __ addq(rsp, Immediate(kDoubleSize)); | |
90 | |
91 // Make sure no registers have been unexpectedly clobbered | |
92 for (--reg_num; reg_num >= 0; --reg_num) { | |
93 Register reg = Register::from_code(reg_num); | |
94 if (!reg.is(rsp) && !reg.is(rbp) && !reg.is(destination_reg)) { | |
95 __ cmpq(reg, MemOperand(rsp, 0)); | |
96 __ Assert(equal, "register was clobbered"); | |
97 __ addq(rsp, Immediate(kPointerSize)); | |
98 } | |
99 } | |
100 | |
101 __ movq(rax, destination_reg); | |
102 | |
103 __ pop(rdi); | |
104 __ pop(rsi); | |
105 __ pop(rdx); | |
106 __ pop(rcx); | |
107 __ pop(rbx); | |
108 | |
109 __ ret(0); | |
110 | |
111 CodeDesc desc; | |
112 assm.GetCode(&desc); | |
113 return reinterpret_cast<ConvertDToIFunc>( | |
114 reinterpret_cast<intptr_t>(buffer)); | |
115 } | |
116 | |
117 #undef __ | |
118 | |
119 | |
120 static Isolate* GetIsolateFrom(LocalContext* context) { | |
121 return reinterpret_cast<Isolate*>((*context)->GetIsolate()); | |
122 } | |
123 | |
124 | |
125 TEST(ConvertDToI) { | |
126 CcTest::InitializeVM(); | |
127 LocalContext context; | |
128 Isolate* isolate = GetIsolateFrom(&context); | |
129 HandleScope scope(isolate); | |
130 | |
131 #if DEBUG | |
132 // Verify that the tests actually work with the C version. In the release | |
133 // code, the compiler optimizes it away because it's all constant, but does it | |
134 // wrong, triggering an assert on gcc. | |
135 RunAllTruncationTests(&ConvertDToICVersion); | |
136 #endif | |
137 | |
Yang
2013/07/18 14:54:38
Why not make it something like
Register source_reg
| |
138 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, rsp, rax)); | |
139 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, rsp, rbx)); | |
140 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, rsp, rcx)); | |
141 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, rsp, rdx)); | |
142 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, rsp, rdi)); | |
143 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, rsp, rsi)); | |
144 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, rax, rax)); | |
145 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, rax, rbx)); | |
146 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, rax, rcx)); | |
147 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, rax, rdx)); | |
148 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, rax, rdi)); | |
149 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, rax, rsi)); | |
150 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, rbx, rax)); | |
151 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, rbx, rbx)); | |
152 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, rbx, rcx)); | |
153 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, rbx, rdx)); | |
154 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, rbx, rdi)); | |
155 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, rbx, rsi)); | |
156 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, rcx, rax)); | |
157 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, rcx, rbx)); | |
158 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, rcx, rcx)); | |
159 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, rcx, rdx)); | |
160 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, rcx, rdi)); | |
161 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, rcx, rsi)); | |
162 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, rdx, rax)); | |
163 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, rdx, rbx)); | |
164 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, rdx, rcx)); | |
165 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, rdx, rdx)); | |
166 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, rdx, rdi)); | |
167 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, rdx, rsi)); | |
168 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, rsi, rax)); | |
169 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, rsi, rbx)); | |
170 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, rsi, rcx)); | |
171 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, rsi, rdx)); | |
172 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, rsi, rdi)); | |
173 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, rsi, rsi)); | |
174 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, rdi, rax)); | |
175 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, rdi, rbx)); | |
176 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, rdi, rcx)); | |
177 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, rdi, rdx)); | |
178 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, rdi, rdi)); | |
179 RunAllTruncationTests(MakeConvertDToIFuncTrampoline(isolate, rdi, rsi)); | |
180 } | |
OLD | NEW |