| 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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 int res = f(10); | 145 int res = f(10); |
| 146 ::printf("f() = %d\n", res); | 146 ::printf("f() = %d\n", res); |
| 147 CHECK_EQ(3628800, res); | 147 CHECK_EQ(3628800, res); |
| 148 } | 148 } |
| 149 | 149 |
| 150 | 150 |
| 151 typedef int (*F3)(float x); | 151 typedef int (*F3)(float x); |
| 152 | 152 |
| 153 TEST(AssemblerIa323) { | 153 TEST(AssemblerIa323) { |
| 154 CcTest::InitializeVM(); | 154 CcTest::InitializeVM(); |
| 155 if (!CpuFeatures::IsSupported(SSE2)) return; | |
| 156 | 155 |
| 157 Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate()); | 156 Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate()); |
| 158 HandleScope scope(isolate); | 157 HandleScope scope(isolate); |
| 159 | 158 |
| 160 v8::internal::byte buffer[256]; | 159 v8::internal::byte buffer[256]; |
| 161 Assembler assm(isolate, buffer, sizeof buffer); | 160 Assembler assm(isolate, buffer, sizeof buffer); |
| 162 | 161 |
| 163 CHECK(CpuFeatures::IsSupported(SSE2)); | 162 __ cvttss2si(eax, Operand(esp, 4)); |
| 164 { CpuFeatureScope fscope(&assm, SSE2); | 163 __ ret(0); |
| 165 __ cvttss2si(eax, Operand(esp, 4)); | |
| 166 __ ret(0); | |
| 167 } | |
| 168 | 164 |
| 169 CodeDesc desc; | 165 CodeDesc desc; |
| 170 assm.GetCode(&desc); | 166 assm.GetCode(&desc); |
| 171 Handle<Code> code = isolate->factory()->NewCode( | 167 Handle<Code> code = isolate->factory()->NewCode( |
| 172 desc, Code::ComputeFlags(Code::STUB), Handle<Code>()); | 168 desc, Code::ComputeFlags(Code::STUB), Handle<Code>()); |
| 173 // don't print the code - our disassembler can't handle cvttss2si | 169 // don't print the code - our disassembler can't handle cvttss2si |
| 174 // instead print bytes | 170 // instead print bytes |
| 175 Disassembler::Dump(stdout, | 171 Disassembler::Dump(stdout, |
| 176 code->instruction_start(), | 172 code->instruction_start(), |
| 177 code->instruction_start() + code->instruction_size()); | 173 code->instruction_start() + code->instruction_size()); |
| 178 F3 f = FUNCTION_CAST<F3>(code->entry()); | 174 F3 f = FUNCTION_CAST<F3>(code->entry()); |
| 179 int res = f(static_cast<float>(-3.1415)); | 175 int res = f(static_cast<float>(-3.1415)); |
| 180 ::printf("f() = %d\n", res); | 176 ::printf("f() = %d\n", res); |
| 181 CHECK_EQ(-3, res); | 177 CHECK_EQ(-3, res); |
| 182 } | 178 } |
| 183 | 179 |
| 184 | 180 |
| 185 typedef int (*F4)(double x); | 181 typedef int (*F4)(double x); |
| 186 | 182 |
| 187 TEST(AssemblerIa324) { | 183 TEST(AssemblerIa324) { |
| 188 CcTest::InitializeVM(); | 184 CcTest::InitializeVM(); |
| 189 if (!CpuFeatures::IsSupported(SSE2)) return; | |
| 190 | 185 |
| 191 Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate()); | 186 Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate()); |
| 192 HandleScope scope(isolate); | 187 HandleScope scope(isolate); |
| 193 | 188 |
| 194 v8::internal::byte buffer[256]; | 189 v8::internal::byte buffer[256]; |
| 195 Assembler assm(isolate, buffer, sizeof buffer); | 190 Assembler assm(isolate, buffer, sizeof buffer); |
| 196 | 191 |
| 197 CHECK(CpuFeatures::IsSupported(SSE2)); | |
| 198 CpuFeatureScope fscope(&assm, SSE2); | |
| 199 __ cvttsd2si(eax, Operand(esp, 4)); | 192 __ cvttsd2si(eax, Operand(esp, 4)); |
| 200 __ ret(0); | 193 __ ret(0); |
| 201 | 194 |
| 202 CodeDesc desc; | 195 CodeDesc desc; |
| 203 assm.GetCode(&desc); | 196 assm.GetCode(&desc); |
| 204 Handle<Code> code = isolate->factory()->NewCode( | 197 Handle<Code> code = isolate->factory()->NewCode( |
| 205 desc, Code::ComputeFlags(Code::STUB), Handle<Code>()); | 198 desc, Code::ComputeFlags(Code::STUB), Handle<Code>()); |
| 206 // don't print the code - our disassembler can't handle cvttsd2si | 199 // don't print the code - our disassembler can't handle cvttsd2si |
| 207 // instead print bytes | 200 // instead print bytes |
| 208 Disassembler::Dump(stdout, | 201 Disassembler::Dump(stdout, |
| (...skipping 25 matching lines...) Expand all Loading... |
| 234 F0 f = FUNCTION_CAST<F0>(code->entry()); | 227 F0 f = FUNCTION_CAST<F0>(code->entry()); |
| 235 int res = f(); | 228 int res = f(); |
| 236 CHECK_EQ(42, res); | 229 CHECK_EQ(42, res); |
| 237 } | 230 } |
| 238 | 231 |
| 239 | 232 |
| 240 typedef double (*F5)(double x, double y); | 233 typedef double (*F5)(double x, double y); |
| 241 | 234 |
| 242 TEST(AssemblerIa326) { | 235 TEST(AssemblerIa326) { |
| 243 CcTest::InitializeVM(); | 236 CcTest::InitializeVM(); |
| 244 if (!CpuFeatures::IsSupported(SSE2)) return; | |
| 245 | 237 |
| 246 Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate()); | 238 Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate()); |
| 247 HandleScope scope(isolate); | 239 HandleScope scope(isolate); |
| 248 v8::internal::byte buffer[256]; | 240 v8::internal::byte buffer[256]; |
| 249 Assembler assm(isolate, buffer, sizeof buffer); | 241 Assembler assm(isolate, buffer, sizeof buffer); |
| 250 | 242 |
| 251 CpuFeatureScope fscope(&assm, SSE2); | |
| 252 __ movsd(xmm0, Operand(esp, 1 * kPointerSize)); | 243 __ movsd(xmm0, Operand(esp, 1 * kPointerSize)); |
| 253 __ movsd(xmm1, Operand(esp, 3 * kPointerSize)); | 244 __ movsd(xmm1, Operand(esp, 3 * kPointerSize)); |
| 254 __ addsd(xmm0, xmm1); | 245 __ addsd(xmm0, xmm1); |
| 255 __ mulsd(xmm0, xmm1); | 246 __ mulsd(xmm0, xmm1); |
| 256 __ subsd(xmm0, xmm1); | 247 __ subsd(xmm0, xmm1); |
| 257 __ divsd(xmm0, xmm1); | 248 __ divsd(xmm0, xmm1); |
| 258 // Copy xmm0 to st(0) using eight bytes of stack. | 249 // Copy xmm0 to st(0) using eight bytes of stack. |
| 259 __ sub(esp, Immediate(8)); | 250 __ sub(esp, Immediate(8)); |
| 260 __ movsd(Operand(esp, 0), xmm0); | 251 __ movsd(Operand(esp, 0), xmm0); |
| 261 __ fld_d(Operand(esp, 0)); | 252 __ fld_d(Operand(esp, 0)); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 278 double res = f(2.2, 1.1); | 269 double res = f(2.2, 1.1); |
| 279 ::printf("f() = %f\n", res); | 270 ::printf("f() = %f\n", res); |
| 280 CHECK(2.29 < res && res < 2.31); | 271 CHECK(2.29 < res && res < 2.31); |
| 281 } | 272 } |
| 282 | 273 |
| 283 | 274 |
| 284 typedef double (*F6)(int x); | 275 typedef double (*F6)(int x); |
| 285 | 276 |
| 286 TEST(AssemblerIa328) { | 277 TEST(AssemblerIa328) { |
| 287 CcTest::InitializeVM(); | 278 CcTest::InitializeVM(); |
| 288 if (!CpuFeatures::IsSupported(SSE2)) return; | |
| 289 | 279 |
| 290 Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate()); | 280 Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate()); |
| 291 HandleScope scope(isolate); | 281 HandleScope scope(isolate); |
| 292 v8::internal::byte buffer[256]; | 282 v8::internal::byte buffer[256]; |
| 293 Assembler assm(isolate, buffer, sizeof buffer); | 283 Assembler assm(isolate, buffer, sizeof buffer); |
| 294 CpuFeatureScope fscope(&assm, SSE2); | |
| 295 __ mov(eax, Operand(esp, 4)); | 284 __ mov(eax, Operand(esp, 4)); |
| 296 __ cvtsi2sd(xmm0, eax); | 285 __ cvtsi2sd(xmm0, eax); |
| 297 // Copy xmm0 to st(0) using eight bytes of stack. | 286 // Copy xmm0 to st(0) using eight bytes of stack. |
| 298 __ sub(esp, Immediate(8)); | 287 __ sub(esp, Immediate(8)); |
| 299 __ movsd(Operand(esp, 0), xmm0); | 288 __ movsd(Operand(esp, 0), xmm0); |
| 300 __ fld_d(Operand(esp, 0)); | 289 __ fld_d(Operand(esp, 0)); |
| 301 __ add(esp, Immediate(8)); | 290 __ add(esp, Immediate(8)); |
| 302 __ ret(0); | 291 __ ret(0); |
| 303 CodeDesc desc; | 292 CodeDesc desc; |
| 304 assm.GetCode(&desc); | 293 assm.GetCode(&desc); |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate()); | 444 Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate()); |
| 456 HandleScope scope(isolate); | 445 HandleScope scope(isolate); |
| 457 | 446 |
| 458 CHECK(args[0]->IsArray()); | 447 CHECK(args[0]->IsArray()); |
| 459 v8::Local<v8::Array> vec = v8::Local<v8::Array>::Cast(args[0]); | 448 v8::Local<v8::Array> vec = v8::Local<v8::Array>::Cast(args[0]); |
| 460 CHECK_EQ(ELEMENT_COUNT, vec->Length()); | 449 CHECK_EQ(ELEMENT_COUNT, vec->Length()); |
| 461 | 450 |
| 462 v8::internal::byte buffer[256]; | 451 v8::internal::byte buffer[256]; |
| 463 Assembler assm(isolate, buffer, sizeof buffer); | 452 Assembler assm(isolate, buffer, sizeof buffer); |
| 464 | 453 |
| 465 ASSERT(CpuFeatures::IsSupported(SSE2)); | |
| 466 CpuFeatureScope fscope(&assm, SSE2); | |
| 467 | |
| 468 // Remove return address from the stack for fix stack frame alignment. | 454 // Remove return address from the stack for fix stack frame alignment. |
| 469 __ pop(ecx); | 455 __ pop(ecx); |
| 470 | 456 |
| 471 // Store input vector on the stack. | 457 // Store input vector on the stack. |
| 472 for (int i = 0; i < ELEMENT_COUNT; ++i) { | 458 for (int i = 0; i < ELEMENT_COUNT; ++i) { |
| 473 __ push(Immediate(vec->Get(i)->Int32Value())); | 459 __ push(Immediate(vec->Get(i)->Int32Value())); |
| 474 } | 460 } |
| 475 | 461 |
| 476 // Read vector into a xmm register. | 462 // Read vector into a xmm register. |
| 477 __ pxor(xmm0, xmm0); | 463 __ pxor(xmm0, xmm0); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 493 desc, Code::ComputeFlags(Code::STUB), Handle<Code>()); | 479 desc, Code::ComputeFlags(Code::STUB), Handle<Code>()); |
| 494 | 480 |
| 495 F0 f = FUNCTION_CAST<F0>(code->entry()); | 481 F0 f = FUNCTION_CAST<F0>(code->entry()); |
| 496 int res = f(); | 482 int res = f(); |
| 497 args.GetReturnValue().Set(v8::Integer::New(CcTest::isolate(), res)); | 483 args.GetReturnValue().Set(v8::Integer::New(CcTest::isolate(), res)); |
| 498 } | 484 } |
| 499 | 485 |
| 500 | 486 |
| 501 TEST(StackAlignmentForSSE2) { | 487 TEST(StackAlignmentForSSE2) { |
| 502 CcTest::InitializeVM(); | 488 CcTest::InitializeVM(); |
| 503 if (!CpuFeatures::IsSupported(SSE2)) return; | |
| 504 | |
| 505 CHECK_EQ(0, OS::ActivationFrameAlignment() % 16); | 489 CHECK_EQ(0, OS::ActivationFrameAlignment() % 16); |
| 506 | 490 |
| 507 v8::Isolate* isolate = CcTest::isolate(); | 491 v8::Isolate* isolate = CcTest::isolate(); |
| 508 v8::HandleScope handle_scope(isolate); | 492 v8::HandleScope handle_scope(isolate); |
| 509 v8::Handle<v8::ObjectTemplate> global_template = | 493 v8::Handle<v8::ObjectTemplate> global_template = |
| 510 v8::ObjectTemplate::New(isolate); | 494 v8::ObjectTemplate::New(isolate); |
| 511 global_template->Set(v8_str("do_sse2"), | 495 global_template->Set(v8_str("do_sse2"), |
| 512 v8::FunctionTemplate::New(isolate, DoSSE2)); | 496 v8::FunctionTemplate::New(isolate, DoSSE2)); |
| 513 | 497 |
| 514 LocalContext env(NULL, global_template); | 498 LocalContext env(NULL, global_template); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 533 // The mask should be 0b1000. | 517 // The mask should be 0b1000. |
| 534 CHECK_EQ(8, result->Int32Value()); | 518 CHECK_EQ(8, result->Int32Value()); |
| 535 } | 519 } |
| 536 | 520 |
| 537 #undef ELEMENT_COUNT | 521 #undef ELEMENT_COUNT |
| 538 #endif // __GNUC__ | 522 #endif // __GNUC__ |
| 539 | 523 |
| 540 | 524 |
| 541 TEST(AssemblerIa32Extractps) { | 525 TEST(AssemblerIa32Extractps) { |
| 542 CcTest::InitializeVM(); | 526 CcTest::InitializeVM(); |
| 543 if (!CpuFeatures::IsSupported(SSE2) || | 527 if (!CpuFeatures::IsSupported(SSE4_1)) return; |
| 544 !CpuFeatures::IsSupported(SSE4_1)) return; | |
| 545 | 528 |
| 546 Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate()); | 529 Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate()); |
| 547 HandleScope scope(isolate); | 530 HandleScope scope(isolate); |
| 548 v8::internal::byte buffer[256]; | 531 v8::internal::byte buffer[256]; |
| 549 MacroAssembler assm(isolate, buffer, sizeof buffer); | 532 MacroAssembler assm(isolate, buffer, sizeof buffer); |
| 550 { CpuFeatureScope fscope2(&assm, SSE2); | 533 { CpuFeatureScope fscope41(&assm, SSE4_1); |
| 551 CpuFeatureScope fscope41(&assm, SSE4_1); | |
| 552 __ movsd(xmm1, Operand(esp, 4)); | 534 __ movsd(xmm1, Operand(esp, 4)); |
| 553 __ extractps(eax, xmm1, 0x1); | 535 __ extractps(eax, xmm1, 0x1); |
| 554 __ ret(0); | 536 __ ret(0); |
| 555 } | 537 } |
| 556 | 538 |
| 557 CodeDesc desc; | 539 CodeDesc desc; |
| 558 assm.GetCode(&desc); | 540 assm.GetCode(&desc); |
| 559 Handle<Code> code = isolate->factory()->NewCode( | 541 Handle<Code> code = isolate->factory()->NewCode( |
| 560 desc, Code::ComputeFlags(Code::STUB), Handle<Code>()); | 542 desc, Code::ComputeFlags(Code::STUB), Handle<Code>()); |
| 561 #ifdef OBJECT_PRINT | 543 #ifdef OBJECT_PRINT |
| 562 code->Print(); | 544 code->Print(); |
| 563 #endif | 545 #endif |
| 564 | 546 |
| 565 F4 f = FUNCTION_CAST<F4>(code->entry()); | 547 F4 f = FUNCTION_CAST<F4>(code->entry()); |
| 566 uint64_t value1 = V8_2PART_UINT64_C(0x12345678, 87654321); | 548 uint64_t value1 = V8_2PART_UINT64_C(0x12345678, 87654321); |
| 567 CHECK_EQ(0x12345678, f(uint64_to_double(value1))); | 549 CHECK_EQ(0x12345678, f(uint64_to_double(value1))); |
| 568 uint64_t value2 = V8_2PART_UINT64_C(0x87654321, 12345678); | 550 uint64_t value2 = V8_2PART_UINT64_C(0x87654321, 12345678); |
| 569 CHECK_EQ(0x87654321, f(uint64_to_double(value2))); | 551 CHECK_EQ(0x87654321, f(uint64_to_double(value2))); |
| 570 } | 552 } |
| 571 | 553 |
| 572 | 554 |
| 573 typedef int (*F8)(float x, float y); | 555 typedef int (*F8)(float x, float y); |
| 574 TEST(AssemblerIa32SSE) { | 556 TEST(AssemblerIa32SSE) { |
| 575 CcTest::InitializeVM(); | 557 CcTest::InitializeVM(); |
| 576 if (!CpuFeatures::IsSupported(SSE2)) return; | |
| 577 | 558 |
| 578 Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate()); | 559 Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate()); |
| 579 HandleScope scope(isolate); | 560 HandleScope scope(isolate); |
| 580 v8::internal::byte buffer[256]; | 561 v8::internal::byte buffer[256]; |
| 581 MacroAssembler assm(isolate, buffer, sizeof buffer); | 562 MacroAssembler assm(isolate, buffer, sizeof buffer); |
| 582 { | 563 { |
| 583 CpuFeatureScope fscope(&assm, SSE2); | |
| 584 __ movss(xmm0, Operand(esp, kPointerSize)); | 564 __ movss(xmm0, Operand(esp, kPointerSize)); |
| 585 __ movss(xmm1, Operand(esp, 2 * kPointerSize)); | 565 __ movss(xmm1, Operand(esp, 2 * kPointerSize)); |
| 586 __ shufps(xmm0, xmm0, 0x0); | 566 __ shufps(xmm0, xmm0, 0x0); |
| 587 __ shufps(xmm1, xmm1, 0x0); | 567 __ shufps(xmm1, xmm1, 0x0); |
| 588 __ movaps(xmm2, xmm1); | 568 __ movaps(xmm2, xmm1); |
| 589 __ addps(xmm2, xmm0); | 569 __ addps(xmm2, xmm0); |
| 590 __ mulps(xmm2, xmm1); | 570 __ mulps(xmm2, xmm1); |
| 591 __ subps(xmm2, xmm0); | 571 __ subps(xmm2, xmm0); |
| 592 __ divps(xmm2, xmm1); | 572 __ divps(xmm2, xmm1); |
| 593 __ cvttss2si(eax, xmm2); | 573 __ cvttss2si(eax, xmm2); |
| 594 __ ret(0); | 574 __ ret(0); |
| 595 } | 575 } |
| 596 | 576 |
| 597 CodeDesc desc; | 577 CodeDesc desc; |
| 598 assm.GetCode(&desc); | 578 assm.GetCode(&desc); |
| 599 Handle<Code> code = isolate->factory()->NewCode( | 579 Handle<Code> code = isolate->factory()->NewCode( |
| 600 desc, Code::ComputeFlags(Code::STUB), Handle<Code>()); | 580 desc, Code::ComputeFlags(Code::STUB), Handle<Code>()); |
| 601 #ifdef OBJECT_PRINT | 581 #ifdef OBJECT_PRINT |
| 602 code->Print(); | 582 code->Print(); |
| 603 #endif | 583 #endif |
| 604 | 584 |
| 605 F8 f = FUNCTION_CAST<F8>(code->entry()); | 585 F8 f = FUNCTION_CAST<F8>(code->entry()); |
| 606 CHECK_EQ(2, f(1.0, 2.0)); | 586 CHECK_EQ(2, f(1.0, 2.0)); |
| 607 } | 587 } |
| 608 | 588 |
| 609 | 589 |
| 610 #undef __ | 590 #undef __ |
| OLD | NEW |