OLD | NEW |
1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 | 92 |
93 | 93 |
94 static void InitializeVM() { | 94 static void InitializeVM() { |
95 if (env.IsEmpty()) { | 95 if (env.IsEmpty()) { |
96 env = v8::Context::New(); | 96 env = v8::Context::New(); |
97 } | 97 } |
98 } | 98 } |
99 | 99 |
100 | 100 |
101 TEST(AssemblerX64ReturnOperation) { | 101 TEST(AssemblerX64ReturnOperation) { |
102 OS::Setup(); | 102 OS::SetUp(); |
103 // Allocate an executable page of memory. | 103 // Allocate an executable page of memory. |
104 size_t actual_size; | 104 size_t actual_size; |
105 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, | 105 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, |
106 &actual_size, | 106 &actual_size, |
107 true)); | 107 true)); |
108 CHECK(buffer); | 108 CHECK(buffer); |
109 Assembler assm(Isolate::Current(), buffer, static_cast<int>(actual_size)); | 109 Assembler assm(Isolate::Current(), buffer, static_cast<int>(actual_size)); |
110 | 110 |
111 // Assemble a simple function that copies argument 2 and returns it. | 111 // Assemble a simple function that copies argument 2 and returns it. |
112 __ movq(rax, arg2); | 112 __ movq(rax, arg2); |
113 __ nop(); | 113 __ nop(); |
114 __ ret(0); | 114 __ ret(0); |
115 | 115 |
116 CodeDesc desc; | 116 CodeDesc desc; |
117 assm.GetCode(&desc); | 117 assm.GetCode(&desc); |
118 // Call the function from C++. | 118 // Call the function from C++. |
119 int result = FUNCTION_CAST<F2>(buffer)(3, 2); | 119 int result = FUNCTION_CAST<F2>(buffer)(3, 2); |
120 CHECK_EQ(2, result); | 120 CHECK_EQ(2, result); |
121 } | 121 } |
122 | 122 |
123 TEST(AssemblerX64StackOperations) { | 123 TEST(AssemblerX64StackOperations) { |
124 OS::Setup(); | 124 OS::SetUp(); |
125 // Allocate an executable page of memory. | 125 // Allocate an executable page of memory. |
126 size_t actual_size; | 126 size_t actual_size; |
127 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, | 127 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, |
128 &actual_size, | 128 &actual_size, |
129 true)); | 129 true)); |
130 CHECK(buffer); | 130 CHECK(buffer); |
131 Assembler assm(Isolate::Current(), buffer, static_cast<int>(actual_size)); | 131 Assembler assm(Isolate::Current(), buffer, static_cast<int>(actual_size)); |
132 | 132 |
133 // Assemble a simple function that copies argument 2 and returns it. | 133 // Assemble a simple function that copies argument 2 and returns it. |
134 // We compile without stack frame pointers, so the gdb debugger shows | 134 // We compile without stack frame pointers, so the gdb debugger shows |
(...skipping 11 matching lines...) Expand all Loading... |
146 __ ret(0); | 146 __ ret(0); |
147 | 147 |
148 CodeDesc desc; | 148 CodeDesc desc; |
149 assm.GetCode(&desc); | 149 assm.GetCode(&desc); |
150 // Call the function from C++. | 150 // Call the function from C++. |
151 int result = FUNCTION_CAST<F2>(buffer)(3, 2); | 151 int result = FUNCTION_CAST<F2>(buffer)(3, 2); |
152 CHECK_EQ(2, result); | 152 CHECK_EQ(2, result); |
153 } | 153 } |
154 | 154 |
155 TEST(AssemblerX64ArithmeticOperations) { | 155 TEST(AssemblerX64ArithmeticOperations) { |
156 OS::Setup(); | 156 OS::SetUp(); |
157 // Allocate an executable page of memory. | 157 // Allocate an executable page of memory. |
158 size_t actual_size; | 158 size_t actual_size; |
159 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, | 159 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, |
160 &actual_size, | 160 &actual_size, |
161 true)); | 161 true)); |
162 CHECK(buffer); | 162 CHECK(buffer); |
163 Assembler assm(Isolate::Current(), buffer, static_cast<int>(actual_size)); | 163 Assembler assm(Isolate::Current(), buffer, static_cast<int>(actual_size)); |
164 | 164 |
165 // Assemble a simple function that adds arguments returning the sum. | 165 // Assemble a simple function that adds arguments returning the sum. |
166 __ movq(rax, arg2); | 166 __ movq(rax, arg2); |
167 __ addq(rax, arg1); | 167 __ addq(rax, arg1); |
168 __ ret(0); | 168 __ ret(0); |
169 | 169 |
170 CodeDesc desc; | 170 CodeDesc desc; |
171 assm.GetCode(&desc); | 171 assm.GetCode(&desc); |
172 // Call the function from C++. | 172 // Call the function from C++. |
173 int result = FUNCTION_CAST<F2>(buffer)(3, 2); | 173 int result = FUNCTION_CAST<F2>(buffer)(3, 2); |
174 CHECK_EQ(5, result); | 174 CHECK_EQ(5, result); |
175 } | 175 } |
176 | 176 |
177 TEST(AssemblerX64ImulOperation) { | 177 TEST(AssemblerX64ImulOperation) { |
178 OS::Setup(); | 178 OS::SetUp(); |
179 // Allocate an executable page of memory. | 179 // Allocate an executable page of memory. |
180 size_t actual_size; | 180 size_t actual_size; |
181 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, | 181 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, |
182 &actual_size, | 182 &actual_size, |
183 true)); | 183 true)); |
184 CHECK(buffer); | 184 CHECK(buffer); |
185 Assembler assm(Isolate::Current(), buffer, static_cast<int>(actual_size)); | 185 Assembler assm(Isolate::Current(), buffer, static_cast<int>(actual_size)); |
186 | 186 |
187 // Assemble a simple function that multiplies arguments returning the high | 187 // Assemble a simple function that multiplies arguments returning the high |
188 // word. | 188 // word. |
189 __ movq(rax, arg2); | 189 __ movq(rax, arg2); |
190 __ imul(arg1); | 190 __ imul(arg1); |
191 __ movq(rax, rdx); | 191 __ movq(rax, rdx); |
192 __ ret(0); | 192 __ ret(0); |
193 | 193 |
194 CodeDesc desc; | 194 CodeDesc desc; |
195 assm.GetCode(&desc); | 195 assm.GetCode(&desc); |
196 // Call the function from C++. | 196 // Call the function from C++. |
197 int result = FUNCTION_CAST<F2>(buffer)(3, 2); | 197 int result = FUNCTION_CAST<F2>(buffer)(3, 2); |
198 CHECK_EQ(0, result); | 198 CHECK_EQ(0, result); |
199 result = FUNCTION_CAST<F2>(buffer)(0x100000000l, 0x100000000l); | 199 result = FUNCTION_CAST<F2>(buffer)(0x100000000l, 0x100000000l); |
200 CHECK_EQ(1, result); | 200 CHECK_EQ(1, result); |
201 result = FUNCTION_CAST<F2>(buffer)(-0x100000000l, 0x100000000l); | 201 result = FUNCTION_CAST<F2>(buffer)(-0x100000000l, 0x100000000l); |
202 CHECK_EQ(-1, result); | 202 CHECK_EQ(-1, result); |
203 } | 203 } |
204 | 204 |
205 TEST(AssemblerX64MemoryOperands) { | 205 TEST(AssemblerX64MemoryOperands) { |
206 OS::Setup(); | 206 OS::SetUp(); |
207 // Allocate an executable page of memory. | 207 // Allocate an executable page of memory. |
208 size_t actual_size; | 208 size_t actual_size; |
209 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, | 209 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, |
210 &actual_size, | 210 &actual_size, |
211 true)); | 211 true)); |
212 CHECK(buffer); | 212 CHECK(buffer); |
213 Assembler assm(Isolate::Current(), buffer, static_cast<int>(actual_size)); | 213 Assembler assm(Isolate::Current(), buffer, static_cast<int>(actual_size)); |
214 | 214 |
215 // Assemble a simple function that copies argument 2 and returns it. | 215 // Assemble a simple function that copies argument 2 and returns it. |
216 __ push(rbp); | 216 __ push(rbp); |
(...skipping 13 matching lines...) Expand all Loading... |
230 __ ret(0); | 230 __ ret(0); |
231 | 231 |
232 CodeDesc desc; | 232 CodeDesc desc; |
233 assm.GetCode(&desc); | 233 assm.GetCode(&desc); |
234 // Call the function from C++. | 234 // Call the function from C++. |
235 int result = FUNCTION_CAST<F2>(buffer)(3, 2); | 235 int result = FUNCTION_CAST<F2>(buffer)(3, 2); |
236 CHECK_EQ(3, result); | 236 CHECK_EQ(3, result); |
237 } | 237 } |
238 | 238 |
239 TEST(AssemblerX64ControlFlow) { | 239 TEST(AssemblerX64ControlFlow) { |
240 OS::Setup(); | 240 OS::SetUp(); |
241 // Allocate an executable page of memory. | 241 // Allocate an executable page of memory. |
242 size_t actual_size; | 242 size_t actual_size; |
243 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, | 243 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, |
244 &actual_size, | 244 &actual_size, |
245 true)); | 245 true)); |
246 CHECK(buffer); | 246 CHECK(buffer); |
247 Assembler assm(Isolate::Current(), buffer, static_cast<int>(actual_size)); | 247 Assembler assm(Isolate::Current(), buffer, static_cast<int>(actual_size)); |
248 | 248 |
249 // Assemble a simple function that copies argument 1 and returns it. | 249 // Assemble a simple function that copies argument 1 and returns it. |
250 __ push(rbp); | 250 __ push(rbp); |
251 | 251 |
252 __ movq(rbp, rsp); | 252 __ movq(rbp, rsp); |
253 __ movq(rax, arg1); | 253 __ movq(rax, arg1); |
254 Label target; | 254 Label target; |
255 __ jmp(&target); | 255 __ jmp(&target); |
256 __ movq(rax, arg2); | 256 __ movq(rax, arg2); |
257 __ bind(&target); | 257 __ bind(&target); |
258 __ pop(rbp); | 258 __ pop(rbp); |
259 __ ret(0); | 259 __ ret(0); |
260 | 260 |
261 CodeDesc desc; | 261 CodeDesc desc; |
262 assm.GetCode(&desc); | 262 assm.GetCode(&desc); |
263 // Call the function from C++. | 263 // Call the function from C++. |
264 int result = FUNCTION_CAST<F2>(buffer)(3, 2); | 264 int result = FUNCTION_CAST<F2>(buffer)(3, 2); |
265 CHECK_EQ(3, result); | 265 CHECK_EQ(3, result); |
266 } | 266 } |
267 | 267 |
268 TEST(AssemblerX64LoopImmediates) { | 268 TEST(AssemblerX64LoopImmediates) { |
269 OS::Setup(); | 269 OS::SetUp(); |
270 // Allocate an executable page of memory. | 270 // Allocate an executable page of memory. |
271 size_t actual_size; | 271 size_t actual_size; |
272 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, | 272 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, |
273 &actual_size, | 273 &actual_size, |
274 true)); | 274 true)); |
275 CHECK(buffer); | 275 CHECK(buffer); |
276 Assembler assm(Isolate::Current(), buffer, static_cast<int>(actual_size)); | 276 Assembler assm(Isolate::Current(), buffer, static_cast<int>(actual_size)); |
277 // Assemble two loops using rax as counter, and verify the ending counts. | 277 // Assemble two loops using rax as counter, and verify the ending counts. |
278 Label Fail; | 278 Label Fail; |
279 __ movq(rax, Immediate(-3)); | 279 __ movq(rax, Immediate(-3)); |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 | 434 |
435 F0 f = FUNCTION_CAST<F0>(code->entry()); | 435 F0 f = FUNCTION_CAST<F0>(code->entry()); |
436 int res = f(); | 436 int res = f(); |
437 CHECK_EQ(42, res); | 437 CHECK_EQ(42, res); |
438 } | 438 } |
439 | 439 |
440 | 440 |
441 | 441 |
442 | 442 |
443 #undef __ | 443 #undef __ |
OLD | NEW |