OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 26 matching lines...) Expand all Loading... |
37 #include "cctest.h" | 37 #include "cctest.h" |
38 | 38 |
39 using namespace v8::internal; | 39 using namespace v8::internal; |
40 | 40 |
41 | 41 |
42 typedef int (*F0)(); | 42 typedef int (*F0)(); |
43 typedef int (*F1)(int x); | 43 typedef int (*F1)(int x); |
44 typedef int (*F2)(int x, int y); | 44 typedef int (*F2)(int x, int y); |
45 | 45 |
46 | 46 |
47 static v8::Persistent<v8::Context> env; | |
48 | |
49 | |
50 static void InitializeVM() { | |
51 if (env.IsEmpty()) { | |
52 env = v8::Context::New(); | |
53 } | |
54 } | |
55 | |
56 | |
57 #define __ assm. | 47 #define __ assm. |
58 | 48 |
59 TEST(AssemblerIa320) { | 49 TEST(AssemblerIa320) { |
60 InitializeVM(); | 50 CcTest::InitializeVM(); |
61 Isolate* isolate = reinterpret_cast<Isolate*>(env->GetIsolate()); | 51 Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate()); |
62 HandleScope scope(isolate); | 52 HandleScope scope(isolate); |
63 | 53 |
64 v8::internal::byte buffer[256]; | 54 v8::internal::byte buffer[256]; |
65 Assembler assm(isolate, buffer, sizeof buffer); | 55 Assembler assm(isolate, buffer, sizeof buffer); |
66 | 56 |
67 __ mov(eax, Operand(esp, 4)); | 57 __ mov(eax, Operand(esp, 4)); |
68 __ add(eax, Operand(esp, 8)); | 58 __ add(eax, Operand(esp, 8)); |
69 __ ret(0); | 59 __ ret(0); |
70 | 60 |
71 CodeDesc desc; | 61 CodeDesc desc; |
72 assm.GetCode(&desc); | 62 assm.GetCode(&desc); |
73 Object* code = isolate->heap()->CreateCode( | 63 Object* code = isolate->heap()->CreateCode( |
74 desc, | 64 desc, |
75 Code::ComputeFlags(Code::STUB), | 65 Code::ComputeFlags(Code::STUB), |
76 Handle<Code>())->ToObjectChecked(); | 66 Handle<Code>())->ToObjectChecked(); |
77 CHECK(code->IsCode()); | 67 CHECK(code->IsCode()); |
78 #ifdef OBJECT_PRINT | 68 #ifdef OBJECT_PRINT |
79 Code::cast(code)->Print(); | 69 Code::cast(code)->Print(); |
80 #endif | 70 #endif |
81 F2 f = FUNCTION_CAST<F2>(Code::cast(code)->entry()); | 71 F2 f = FUNCTION_CAST<F2>(Code::cast(code)->entry()); |
82 int res = f(3, 4); | 72 int res = f(3, 4); |
83 ::printf("f() = %d\n", res); | 73 ::printf("f() = %d\n", res); |
84 CHECK_EQ(7, res); | 74 CHECK_EQ(7, res); |
85 } | 75 } |
86 | 76 |
87 | 77 |
88 TEST(AssemblerIa321) { | 78 TEST(AssemblerIa321) { |
89 InitializeVM(); | 79 CcTest::InitializeVM(); |
90 Isolate* isolate = reinterpret_cast<Isolate*>(env->GetIsolate()); | 80 Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate()); |
91 HandleScope scope(isolate); | 81 HandleScope scope(isolate); |
92 | 82 |
93 v8::internal::byte buffer[256]; | 83 v8::internal::byte buffer[256]; |
94 Assembler assm(isolate, buffer, sizeof buffer); | 84 Assembler assm(isolate, buffer, sizeof buffer); |
95 Label L, C; | 85 Label L, C; |
96 | 86 |
97 __ mov(edx, Operand(esp, 4)); | 87 __ mov(edx, Operand(esp, 4)); |
98 __ xor_(eax, eax); // clear eax | 88 __ xor_(eax, eax); // clear eax |
99 __ jmp(&C); | 89 __ jmp(&C); |
100 | 90 |
(...skipping 17 matching lines...) Expand all Loading... |
118 Code::cast(code)->Print(); | 108 Code::cast(code)->Print(); |
119 #endif | 109 #endif |
120 F1 f = FUNCTION_CAST<F1>(Code::cast(code)->entry()); | 110 F1 f = FUNCTION_CAST<F1>(Code::cast(code)->entry()); |
121 int res = f(100); | 111 int res = f(100); |
122 ::printf("f() = %d\n", res); | 112 ::printf("f() = %d\n", res); |
123 CHECK_EQ(5050, res); | 113 CHECK_EQ(5050, res); |
124 } | 114 } |
125 | 115 |
126 | 116 |
127 TEST(AssemblerIa322) { | 117 TEST(AssemblerIa322) { |
128 InitializeVM(); | 118 CcTest::InitializeVM(); |
129 Isolate* isolate = reinterpret_cast<Isolate*>(env->GetIsolate()); | 119 Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate()); |
130 HandleScope scope(isolate); | 120 HandleScope scope(isolate); |
131 | 121 |
132 v8::internal::byte buffer[256]; | 122 v8::internal::byte buffer[256]; |
133 Assembler assm(isolate, buffer, sizeof buffer); | 123 Assembler assm(isolate, buffer, sizeof buffer); |
134 Label L, C; | 124 Label L, C; |
135 | 125 |
136 __ mov(edx, Operand(esp, 4)); | 126 __ mov(edx, Operand(esp, 4)); |
137 __ mov(eax, 1); | 127 __ mov(eax, 1); |
138 __ jmp(&C); | 128 __ jmp(&C); |
139 | 129 |
(...skipping 23 matching lines...) Expand all Loading... |
163 F1 f = FUNCTION_CAST<F1>(Code::cast(code)->entry()); | 153 F1 f = FUNCTION_CAST<F1>(Code::cast(code)->entry()); |
164 int res = f(10); | 154 int res = f(10); |
165 ::printf("f() = %d\n", res); | 155 ::printf("f() = %d\n", res); |
166 CHECK_EQ(3628800, res); | 156 CHECK_EQ(3628800, res); |
167 } | 157 } |
168 | 158 |
169 | 159 |
170 typedef int (*F3)(float x); | 160 typedef int (*F3)(float x); |
171 | 161 |
172 TEST(AssemblerIa323) { | 162 TEST(AssemblerIa323) { |
173 InitializeVM(); | 163 CcTest::InitializeVM(); |
174 if (!CpuFeatures::IsSupported(SSE2)) return; | 164 if (!CpuFeatures::IsSupported(SSE2)) return; |
175 | 165 |
176 Isolate* isolate = reinterpret_cast<Isolate*>(env->GetIsolate()); | 166 Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate()); |
177 HandleScope scope(isolate); | 167 HandleScope scope(isolate); |
178 | 168 |
179 v8::internal::byte buffer[256]; | 169 v8::internal::byte buffer[256]; |
180 Assembler assm(isolate, buffer, sizeof buffer); | 170 Assembler assm(isolate, buffer, sizeof buffer); |
181 | 171 |
182 CHECK(CpuFeatures::IsSupported(SSE2)); | 172 CHECK(CpuFeatures::IsSupported(SSE2)); |
183 { CpuFeatureScope fscope(&assm, SSE2); | 173 { CpuFeatureScope fscope(&assm, SSE2); |
184 __ cvttss2si(eax, Operand(esp, 4)); | 174 __ cvttss2si(eax, Operand(esp, 4)); |
185 __ ret(0); | 175 __ ret(0); |
186 } | 176 } |
(...skipping 12 matching lines...) Expand all Loading... |
199 F3 f = FUNCTION_CAST<F3>(code->entry()); | 189 F3 f = FUNCTION_CAST<F3>(code->entry()); |
200 int res = f(static_cast<float>(-3.1415)); | 190 int res = f(static_cast<float>(-3.1415)); |
201 ::printf("f() = %d\n", res); | 191 ::printf("f() = %d\n", res); |
202 CHECK_EQ(-3, res); | 192 CHECK_EQ(-3, res); |
203 } | 193 } |
204 | 194 |
205 | 195 |
206 typedef int (*F4)(double x); | 196 typedef int (*F4)(double x); |
207 | 197 |
208 TEST(AssemblerIa324) { | 198 TEST(AssemblerIa324) { |
209 InitializeVM(); | 199 CcTest::InitializeVM(); |
210 if (!CpuFeatures::IsSupported(SSE2)) return; | 200 if (!CpuFeatures::IsSupported(SSE2)) return; |
211 | 201 |
212 Isolate* isolate = reinterpret_cast<Isolate*>(env->GetIsolate()); | 202 Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate()); |
213 HandleScope scope(isolate); | 203 HandleScope scope(isolate); |
214 | 204 |
215 v8::internal::byte buffer[256]; | 205 v8::internal::byte buffer[256]; |
216 Assembler assm(isolate, buffer, sizeof buffer); | 206 Assembler assm(isolate, buffer, sizeof buffer); |
217 | 207 |
218 CHECK(CpuFeatures::IsSupported(SSE2)); | 208 CHECK(CpuFeatures::IsSupported(SSE2)); |
219 CpuFeatureScope fscope(&assm, SSE2); | 209 CpuFeatureScope fscope(&assm, SSE2); |
220 __ cvttsd2si(eax, Operand(esp, 4)); | 210 __ cvttsd2si(eax, Operand(esp, 4)); |
221 __ ret(0); | 211 __ ret(0); |
222 | 212 |
(...skipping 10 matching lines...) Expand all Loading... |
233 code->instruction_start() + code->instruction_size()); | 223 code->instruction_start() + code->instruction_size()); |
234 F4 f = FUNCTION_CAST<F4>(code->entry()); | 224 F4 f = FUNCTION_CAST<F4>(code->entry()); |
235 int res = f(2.718281828); | 225 int res = f(2.718281828); |
236 ::printf("f() = %d\n", res); | 226 ::printf("f() = %d\n", res); |
237 CHECK_EQ(2, res); | 227 CHECK_EQ(2, res); |
238 } | 228 } |
239 | 229 |
240 | 230 |
241 static int baz = 42; | 231 static int baz = 42; |
242 TEST(AssemblerIa325) { | 232 TEST(AssemblerIa325) { |
243 InitializeVM(); | 233 CcTest::InitializeVM(); |
244 Isolate* isolate = reinterpret_cast<Isolate*>(env->GetIsolate()); | 234 Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate()); |
245 HandleScope scope(isolate); | 235 HandleScope scope(isolate); |
246 | 236 |
247 v8::internal::byte buffer[256]; | 237 v8::internal::byte buffer[256]; |
248 Assembler assm(isolate, buffer, sizeof buffer); | 238 Assembler assm(isolate, buffer, sizeof buffer); |
249 | 239 |
250 __ mov(eax, Operand(reinterpret_cast<intptr_t>(&baz), RelocInfo::NONE32)); | 240 __ mov(eax, Operand(reinterpret_cast<intptr_t>(&baz), RelocInfo::NONE32)); |
251 __ ret(0); | 241 __ ret(0); |
252 | 242 |
253 CodeDesc desc; | 243 CodeDesc desc; |
254 assm.GetCode(&desc); | 244 assm.GetCode(&desc); |
255 Code* code = Code::cast(isolate->heap()->CreateCode( | 245 Code* code = Code::cast(isolate->heap()->CreateCode( |
256 desc, | 246 desc, |
257 Code::ComputeFlags(Code::STUB), | 247 Code::ComputeFlags(Code::STUB), |
258 Handle<Code>())->ToObjectChecked()); | 248 Handle<Code>())->ToObjectChecked()); |
259 F0 f = FUNCTION_CAST<F0>(code->entry()); | 249 F0 f = FUNCTION_CAST<F0>(code->entry()); |
260 int res = f(); | 250 int res = f(); |
261 CHECK_EQ(42, res); | 251 CHECK_EQ(42, res); |
262 } | 252 } |
263 | 253 |
264 | 254 |
265 typedef double (*F5)(double x, double y); | 255 typedef double (*F5)(double x, double y); |
266 | 256 |
267 TEST(AssemblerIa326) { | 257 TEST(AssemblerIa326) { |
268 InitializeVM(); | 258 CcTest::InitializeVM(); |
269 if (!CpuFeatures::IsSupported(SSE2)) return; | 259 if (!CpuFeatures::IsSupported(SSE2)) return; |
270 | 260 |
271 Isolate* isolate = reinterpret_cast<Isolate*>(env->GetIsolate()); | 261 Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate()); |
272 HandleScope scope(isolate); | 262 HandleScope scope(isolate); |
273 v8::internal::byte buffer[256]; | 263 v8::internal::byte buffer[256]; |
274 Assembler assm(isolate, buffer, sizeof buffer); | 264 Assembler assm(isolate, buffer, sizeof buffer); |
275 | 265 |
276 CpuFeatureScope fscope(&assm, SSE2); | 266 CpuFeatureScope fscope(&assm, SSE2); |
277 __ movdbl(xmm0, Operand(esp, 1 * kPointerSize)); | 267 __ movdbl(xmm0, Operand(esp, 1 * kPointerSize)); |
278 __ movdbl(xmm1, Operand(esp, 3 * kPointerSize)); | 268 __ movdbl(xmm1, Operand(esp, 3 * kPointerSize)); |
279 __ addsd(xmm0, xmm1); | 269 __ addsd(xmm0, xmm1); |
280 __ mulsd(xmm0, xmm1); | 270 __ mulsd(xmm0, xmm1); |
281 __ subsd(xmm0, xmm1); | 271 __ subsd(xmm0, xmm1); |
(...skipping 22 matching lines...) Expand all Loading... |
304 F5 f = FUNCTION_CAST<F5>(code->entry()); | 294 F5 f = FUNCTION_CAST<F5>(code->entry()); |
305 double res = f(2.2, 1.1); | 295 double res = f(2.2, 1.1); |
306 ::printf("f() = %f\n", res); | 296 ::printf("f() = %f\n", res); |
307 CHECK(2.29 < res && res < 2.31); | 297 CHECK(2.29 < res && res < 2.31); |
308 } | 298 } |
309 | 299 |
310 | 300 |
311 typedef double (*F6)(int x); | 301 typedef double (*F6)(int x); |
312 | 302 |
313 TEST(AssemblerIa328) { | 303 TEST(AssemblerIa328) { |
314 InitializeVM(); | 304 CcTest::InitializeVM(); |
315 if (!CpuFeatures::IsSupported(SSE2)) return; | 305 if (!CpuFeatures::IsSupported(SSE2)) return; |
316 | 306 |
317 Isolate* isolate = reinterpret_cast<Isolate*>(env->GetIsolate()); | 307 Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate()); |
318 HandleScope scope(isolate); | 308 HandleScope scope(isolate); |
319 v8::internal::byte buffer[256]; | 309 v8::internal::byte buffer[256]; |
320 Assembler assm(isolate, buffer, sizeof buffer); | 310 Assembler assm(isolate, buffer, sizeof buffer); |
321 CpuFeatureScope fscope(&assm, SSE2); | 311 CpuFeatureScope fscope(&assm, SSE2); |
322 __ mov(eax, Operand(esp, 4)); | 312 __ mov(eax, Operand(esp, 4)); |
323 __ cvtsi2sd(xmm0, eax); | 313 __ cvtsi2sd(xmm0, eax); |
324 // Copy xmm0 to st(0) using eight bytes of stack. | 314 // Copy xmm0 to st(0) using eight bytes of stack. |
325 __ sub(esp, Immediate(8)); | 315 __ sub(esp, Immediate(8)); |
326 __ movdbl(Operand(esp, 0), xmm0); | 316 __ movdbl(Operand(esp, 0), xmm0); |
327 __ fld_d(Operand(esp, 0)); | 317 __ fld_d(Operand(esp, 0)); |
(...skipping 13 matching lines...) Expand all Loading... |
341 double res = f(12); | 331 double res = f(12); |
342 | 332 |
343 ::printf("f() = %f\n", res); | 333 ::printf("f() = %f\n", res); |
344 CHECK(11.99 < res && res < 12.001); | 334 CHECK(11.99 < res && res < 12.001); |
345 } | 335 } |
346 | 336 |
347 | 337 |
348 typedef int (*F7)(double x, double y); | 338 typedef int (*F7)(double x, double y); |
349 | 339 |
350 TEST(AssemblerIa329) { | 340 TEST(AssemblerIa329) { |
351 InitializeVM(); | 341 CcTest::InitializeVM(); |
352 Isolate* isolate = reinterpret_cast<Isolate*>(env->GetIsolate()); | 342 Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate()); |
353 HandleScope scope(isolate); | 343 HandleScope scope(isolate); |
354 v8::internal::byte buffer[256]; | 344 v8::internal::byte buffer[256]; |
355 MacroAssembler assm(isolate, buffer, sizeof buffer); | 345 MacroAssembler assm(isolate, buffer, sizeof buffer); |
356 enum { kEqual = 0, kGreater = 1, kLess = 2, kNaN = 3, kUndefined = 4 }; | 346 enum { kEqual = 0, kGreater = 1, kLess = 2, kNaN = 3, kUndefined = 4 }; |
357 Label equal_l, less_l, greater_l, nan_l; | 347 Label equal_l, less_l, greater_l, nan_l; |
358 __ fld_d(Operand(esp, 3 * kPointerSize)); | 348 __ fld_d(Operand(esp, 3 * kPointerSize)); |
359 __ fld_d(Operand(esp, 1 * kPointerSize)); | 349 __ fld_d(Operand(esp, 1 * kPointerSize)); |
360 __ FCmp(); | 350 __ FCmp(); |
361 __ j(parity_even, &nan_l); | 351 __ j(parity_even, &nan_l); |
362 __ j(equal, &equal_l); | 352 __ j(equal, &equal_l); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 F7 f = FUNCTION_CAST<F7>(Code::cast(code)->entry()); | 387 F7 f = FUNCTION_CAST<F7>(Code::cast(code)->entry()); |
398 CHECK_EQ(kLess, f(1.1, 2.2)); | 388 CHECK_EQ(kLess, f(1.1, 2.2)); |
399 CHECK_EQ(kEqual, f(2.2, 2.2)); | 389 CHECK_EQ(kEqual, f(2.2, 2.2)); |
400 CHECK_EQ(kGreater, f(3.3, 2.2)); | 390 CHECK_EQ(kGreater, f(3.3, 2.2)); |
401 CHECK_EQ(kNaN, f(OS::nan_value(), 1.1)); | 391 CHECK_EQ(kNaN, f(OS::nan_value(), 1.1)); |
402 } | 392 } |
403 | 393 |
404 | 394 |
405 TEST(AssemblerIa3210) { | 395 TEST(AssemblerIa3210) { |
406 // Test chaining of label usages within instructions (issue 1644). | 396 // Test chaining of label usages within instructions (issue 1644). |
407 InitializeVM(); | 397 CcTest::InitializeVM(); |
408 Isolate* isolate = reinterpret_cast<Isolate*>(env->GetIsolate()); | 398 Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate()); |
409 HandleScope scope(isolate); | 399 HandleScope scope(isolate); |
410 Assembler assm(isolate, NULL, 0); | 400 Assembler assm(isolate, NULL, 0); |
411 | 401 |
412 Label target; | 402 Label target; |
413 __ j(equal, &target); | 403 __ j(equal, &target); |
414 __ j(not_equal, &target); | 404 __ j(not_equal, &target); |
415 __ bind(&target); | 405 __ bind(&target); |
416 __ nop(); | 406 __ nop(); |
417 } | 407 } |
418 | 408 |
419 | 409 |
420 TEST(AssemblerMultiByteNop) { | 410 TEST(AssemblerMultiByteNop) { |
421 InitializeVM(); | 411 CcTest::InitializeVM(); |
422 Isolate* isolate = reinterpret_cast<Isolate*>(env->GetIsolate()); | 412 Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate()); |
423 HandleScope scope(isolate); | 413 HandleScope scope(isolate); |
424 v8::internal::byte buffer[1024]; | 414 v8::internal::byte buffer[1024]; |
425 Assembler assm(isolate, buffer, sizeof(buffer)); | 415 Assembler assm(isolate, buffer, sizeof(buffer)); |
426 __ push(ebx); | 416 __ push(ebx); |
427 __ push(ecx); | 417 __ push(ecx); |
428 __ push(edx); | 418 __ push(edx); |
429 __ push(edi); | 419 __ push(edi); |
430 __ push(esi); | 420 __ push(esi); |
431 __ mov(eax, 1); | 421 __ mov(eax, 1); |
432 __ mov(ebx, 2); | 422 __ mov(ebx, 2); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 | 469 |
480 F0 f = FUNCTION_CAST<F0>(code->entry()); | 470 F0 f = FUNCTION_CAST<F0>(code->entry()); |
481 int res = f(); | 471 int res = f(); |
482 CHECK_EQ(42, res); | 472 CHECK_EQ(42, res); |
483 } | 473 } |
484 | 474 |
485 | 475 |
486 | 476 |
487 | 477 |
488 #undef __ | 478 #undef __ |
OLD | NEW |