| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_X64. | 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_X64. |
| 6 #if defined(TARGET_ARCH_X64) | 6 #if defined(TARGET_ARCH_X64) |
| 7 | 7 |
| 8 #include "vm/intrinsifier.h" | 8 #include "vm/intrinsifier.h" |
| 9 | 9 |
| 10 #include "vm/assembler.h" | 10 #include "vm/assembler.h" |
| (...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 __ movq(RAX, FieldAddress(RAX, ByteArray::length_offset())); | 408 __ movq(RAX, FieldAddress(RAX, ByteArray::length_offset())); |
| 409 __ ret(); | 409 __ ret(); |
| 410 // Generate enough code to satisfy patchability constraint. | 410 // Generate enough code to satisfy patchability constraint. |
| 411 intptr_t offset = __ CodeSize(); | 411 intptr_t offset = __ CodeSize(); |
| 412 __ nop(JumpPattern::InstructionLength() - offset); | 412 __ nop(JumpPattern::InstructionLength() - offset); |
| 413 return true; | 413 return true; |
| 414 } | 414 } |
| 415 | 415 |
| 416 | 416 |
| 417 // Places the address of the ByteArray in RAX. | 417 // Places the address of the ByteArray in RAX. |
| 418 // Places the Smi index in RBX. | 418 // Places the Smi index in R12. |
| 419 // Tests if RBX contains an Smi, jumps to label fall_through if false. | 419 // Tests if R12 contains an Smi, jumps to label fall_through if false. |
| 420 // Tests if index in RBX is within bounds, jumps to label fall_through if not. | 420 // Tests if index in R12 is within bounds, jumps to label fall_through if not. |
| 421 // Leaves the index as an Smi in RBX. | 421 // Leaves the index as an Smi in R12. |
| 422 // Leaves the ByteArray address in RAX. | 422 // Leaves the ByteArray address in RAX. |
| 423 void TestByteArrayIndex(Assembler* assembler, Label* fall_through) { | 423 void TestByteArrayIndex(Assembler* assembler, Label* fall_through) { |
| 424 __ movq(RAX, Address(RSP, + 2 * kWordSize)); // Array. | 424 __ movq(RAX, Address(RSP, + 2 * kWordSize)); // Array. |
| 425 __ movq(RBX, Address(RSP, + 1 * kWordSize)); // Index. | 425 __ movq(R12, Address(RSP, + 1 * kWordSize)); // Index. |
| 426 __ testq(RBX, Immediate(kSmiTagMask)); | 426 __ testq(R12, Immediate(kSmiTagMask)); |
| 427 __ j(NOT_ZERO, fall_through, Assembler::kNearJump); // Non-smi index. | 427 __ j(NOT_ZERO, fall_through, Assembler::kNearJump); // Non-smi index. |
| 428 // Range check. | 428 // Range check. |
| 429 __ cmpq(RBX, FieldAddress(RAX, ByteArray::length_offset())); | 429 __ cmpq(R12, FieldAddress(RAX, ByteArray::length_offset())); |
| 430 // Runtime throws exception. | 430 // Runtime throws exception. |
| 431 __ j(ABOVE_EQUAL, fall_through, Assembler::kNearJump); | 431 __ j(ABOVE_EQUAL, fall_through, Assembler::kNearJump); |
| 432 } | 432 } |
| 433 |
| 434 |
| 435 // Operates in the same manner as TestByteArrayIndex. |
| 436 // This should be used only for setIndexed intrinsics. |
| 437 static void TestByteArraySetIndex(Assembler* assembler, Label* fall_through) { |
| 438 __ movq(RAX, Address(RSP, + 3 * kWordSize)); // Array. |
| 439 __ movq(R12, Address(RSP, + 2 * kWordSize)); // Index. |
| 440 __ testq(R12, Immediate(kSmiTagMask)); |
| 441 __ j(NOT_ZERO, fall_through, Assembler::kNearJump); // Non-smi index. |
| 442 // Range check. |
| 443 __ cmpq(R12, FieldAddress(RAX, ByteArray::length_offset())); |
| 444 // Runtime throws exception. |
| 445 __ j(ABOVE_EQUAL, fall_through, Assembler::kNearJump); |
| 446 } |
| 433 | 447 |
| 434 | 448 |
| 435 bool Intrinsifier::Int8Array_getIndexed(Assembler* assembler) { | 449 bool Intrinsifier::Int8Array_getIndexed(Assembler* assembler) { |
| 436 Label fall_through; | 450 Label fall_through; |
| 437 TestByteArrayIndex(assembler, &fall_through); | 451 TestByteArrayIndex(assembler, &fall_through); |
| 438 __ SmiUntag(RBX); | 452 __ SmiUntag(R12); |
| 439 __ movsxb(RAX, FieldAddress(RAX, | 453 __ movsxb(RAX, FieldAddress(RAX, |
| 440 RBX, | 454 R12, |
| 441 TIMES_1, | 455 TIMES_1, |
| 442 Int8Array::data_offset())); | 456 Int8Array::data_offset())); |
| 443 __ SmiTag(RAX); | 457 __ SmiTag(RAX); |
| 444 __ ret(); | 458 __ ret(); |
| 445 __ Bind(&fall_through); | 459 __ Bind(&fall_through); |
| 446 return false; | 460 return false; |
| 447 } | 461 } |
| 448 | 462 |
| 449 | 463 |
| 450 bool Intrinsifier::Uint8Array_getIndexed(Assembler* assembler) { | 464 bool Intrinsifier::Uint8Array_getIndexed(Assembler* assembler) { |
| 451 Label fall_through; | 465 Label fall_through; |
| 452 TestByteArrayIndex(assembler, &fall_through); | 466 TestByteArrayIndex(assembler, &fall_through); |
| 453 __ SmiUntag(RBX); | 467 __ SmiUntag(R12); |
| 454 __ movzxb(RAX, FieldAddress(RAX, | 468 __ movzxb(RAX, FieldAddress(RAX, |
| 455 RBX, | 469 R12, |
| 456 TIMES_1, | 470 TIMES_1, |
| 457 Uint8Array::data_offset())); | 471 Uint8Array::data_offset())); |
| 458 __ SmiTag(RAX); | 472 __ SmiTag(RAX); |
| 459 __ ret(); | 473 __ ret(); |
| 460 __ Bind(&fall_through); | 474 __ Bind(&fall_through); |
| 461 return false; | 475 return false; |
| 462 } | 476 } |
| 463 | 477 |
| 464 | 478 |
| 465 bool Intrinsifier::Int16Array_getIndexed(Assembler* assembler) { | 479 bool Intrinsifier::Int16Array_getIndexed(Assembler* assembler) { |
| 466 Label fall_through; | 480 Label fall_through; |
| 467 TestByteArrayIndex(assembler, &fall_through); | 481 TestByteArrayIndex(assembler, &fall_through); |
| 468 __ movsxw(RAX, FieldAddress(RAX, | 482 __ movsxw(RAX, FieldAddress(RAX, |
| 469 RBX, | 483 R12, |
| 470 TIMES_1, | 484 TIMES_1, |
| 471 Int16Array::data_offset())); | 485 Int16Array::data_offset())); |
| 472 __ SmiTag(RAX); | 486 __ SmiTag(RAX); |
| 473 __ ret(); | 487 __ ret(); |
| 474 __ Bind(&fall_through); | 488 __ Bind(&fall_through); |
| 475 return false; | 489 return false; |
| 476 } | 490 } |
| 477 | 491 |
| 478 | 492 |
| 479 bool Intrinsifier::Uint16Array_getIndexed(Assembler* assembler) { | 493 bool Intrinsifier::Uint16Array_getIndexed(Assembler* assembler) { |
| 480 Label fall_through; | 494 Label fall_through; |
| 481 TestByteArrayIndex(assembler, &fall_through); | 495 TestByteArrayIndex(assembler, &fall_through); |
| 482 __ movzxw(RAX, FieldAddress(RAX, | 496 __ movzxw(RAX, FieldAddress(RAX, |
| 483 RBX, | 497 R12, |
| 484 TIMES_1, | 498 TIMES_1, |
| 485 Uint16Array::data_offset())); | 499 Uint16Array::data_offset())); |
| 486 __ SmiTag(RAX); | 500 __ SmiTag(RAX); |
| 487 __ ret(); | 501 __ ret(); |
| 488 __ Bind(&fall_through); | 502 __ Bind(&fall_through); |
| 489 return false; | 503 return false; |
| 490 } | 504 } |
| 491 | 505 |
| 492 | 506 |
| 493 bool Intrinsifier::Int32Array_getIndexed(Assembler* assembler) { | 507 bool Intrinsifier::Int32Array_getIndexed(Assembler* assembler) { |
| 494 Label fall_through; | 508 Label fall_through; |
| 495 TestByteArrayIndex(assembler, &fall_through); | 509 TestByteArrayIndex(assembler, &fall_through); |
| 496 __ movsxl(RAX, FieldAddress(RAX, | 510 __ movsxl(RAX, FieldAddress(RAX, |
| 497 RBX, | 511 R12, |
| 498 TIMES_2, | 512 TIMES_2, |
| 499 Int32Array::data_offset())); | 513 Int32Array::data_offset())); |
| 500 __ SmiTag(RAX); | 514 __ SmiTag(RAX); |
| 501 __ ret(); | 515 __ ret(); |
| 502 __ Bind(&fall_through); | 516 __ Bind(&fall_through); |
| 503 return false; | 517 return false; |
| 504 } | 518 } |
| 505 | 519 |
| 506 | 520 |
| 507 bool Intrinsifier::Uint32Array_getIndexed(Assembler* assembler) { | 521 bool Intrinsifier::Uint32Array_getIndexed(Assembler* assembler) { |
| 508 Label fall_through; | 522 Label fall_through; |
| 509 TestByteArrayIndex(assembler, &fall_through); | 523 TestByteArrayIndex(assembler, &fall_through); |
| 510 __ movl(RAX, FieldAddress(RAX, | 524 __ movl(RAX, FieldAddress(RAX, |
| 511 RBX, | 525 R12, |
| 512 TIMES_2, | 526 TIMES_2, |
| 513 Uint32Array::data_offset())); | 527 Uint32Array::data_offset())); |
| 514 __ SmiTag(RAX); | 528 __ SmiTag(RAX); |
| 515 __ ret(); | 529 __ ret(); |
| 516 __ Bind(&fall_through); | 530 __ Bind(&fall_through); |
| 517 return false; | 531 return false; |
| 518 } | 532 } |
| 519 | 533 |
| 534 |
| 520 bool Intrinsifier::Float32Array_getIndexed(Assembler* assembler) { | 535 bool Intrinsifier::Float32Array_getIndexed(Assembler* assembler) { |
| 521 Label fall_through; | 536 Label fall_through; |
| 522 TestByteArrayIndex(assembler, &fall_through); | 537 TestByteArrayIndex(assembler, &fall_through); |
| 523 // After TestByteArrayIndex: | 538 // After TestByteArrayIndex: |
| 524 // * RAX has the base address of the byte array. | 539 // * RAX has the base address of the byte array. |
| 525 // * RBX has the index into the array. | 540 // * R12 has the index into the array. |
| 526 // RBX contains the SMI index which is shifted left by 1. | 541 // R12 contains the SMI index which is shifted left by 1. |
| 527 // This shift means we only multiply the index by 2 not 4 (sizeof float). | 542 // This shift means we only multiply the index by 2 not 4 (sizeof float). |
| 528 // Load single precision float into XMM7. | 543 // Load single precision float into XMM7. |
| 529 __ movss(XMM7, FieldAddress(RAX, RBX, TIMES_2, | 544 __ movss(XMM7, FieldAddress(RAX, R12, TIMES_2, |
| 530 Float32Array::data_offset())); | 545 Float32Array::data_offset())); |
| 531 // Convert into a double precision float. | 546 // Convert into a double precision float. |
| 532 __ cvtss2sd(XMM7, XMM7); | 547 __ cvtss2sd(XMM7, XMM7); |
| 533 // Allocate a double instance. | 548 // Allocate a double instance. |
| 534 const Class& double_class = Class::Handle( | 549 const Class& double_class = Class::Handle( |
| 535 Isolate::Current()->object_store()->double_class()); | 550 Isolate::Current()->object_store()->double_class()); |
| 536 AssemblerMacros::TryAllocate(assembler, | 551 AssemblerMacros::TryAllocate(assembler, |
| 537 double_class, | 552 double_class, |
| 538 &fall_through, | 553 &fall_through, |
| 539 Assembler::kNearJump, RAX); | 554 Assembler::kNearJump, RAX); |
| 540 // Store XMM7 into double instance. | 555 // Store XMM7 into double instance. |
| 541 __ movsd(FieldAddress(RAX, Double::value_offset()), XMM7); | 556 __ movsd(FieldAddress(RAX, Double::value_offset()), XMM7); |
| 542 __ ret(); | 557 __ ret(); |
| 543 __ Bind(&fall_through); | 558 __ Bind(&fall_through); |
| 544 return false; | 559 return false; |
| 545 } | 560 } |
| 546 | 561 |
| 562 |
| 547 bool Intrinsifier::Float32Array_setIndexed(Assembler* assembler) { | 563 bool Intrinsifier::Float32Array_setIndexed(Assembler* assembler) { |
| 548 return false; | 564 Label fall_through; |
| 565 TestByteArraySetIndex(assembler, &fall_through); |
| 566 // After TestByteArraySetIndex: |
| 567 // * RAX has the base address of the byte array. |
| 568 // * R12 has the index into the array. |
| 569 // R12 contains the SMI index which is shifted by 1. |
| 570 // This shift means we only multiply the index by 2 not 4 (sizeof float). |
| 571 __ movq(RDX, Address(RSP, + 1 * kWordSize)); // Value. |
| 572 // If RDX is not an instance of double, jump to fall through. |
| 573 __ CompareClassId(RDX, kDoubleCid); |
| 574 __ j(NOT_EQUAL, &fall_through); |
| 575 // Load double value into XMM7. |
| 576 __ movsd(XMM7, FieldAddress(RDX, Double::value_offset())); |
| 577 // Convert from double precision float to single precision float. |
| 578 __ cvtsd2ss(XMM7, XMM7); |
| 579 // Store into array. |
| 580 __ movss(FieldAddress(RAX, R12, TIMES_2, Float32Array::data_offset()), XMM7); |
| 581 // End fast path. |
| 582 __ ret(); |
| 583 __ Bind(&fall_through); |
| 584 return false; |
| 549 } | 585 } |
| 550 | 586 |
| 551 | 587 |
| 552 // Tests if two top most arguments are smis, jumps to label not_smi if not. | 588 // Tests if two top most arguments are smis, jumps to label not_smi if not. |
| 553 // Topmost argument is in RAX. | 589 // Topmost argument is in RAX. |
| 554 static void TestBothArgumentsSmis(Assembler* assembler, Label* not_smi) { | 590 static void TestBothArgumentsSmis(Assembler* assembler, Label* not_smi) { |
| 555 __ movq(RAX, Address(RSP, + 1 * kWordSize)); | 591 __ movq(RAX, Address(RSP, + 1 * kWordSize)); |
| 556 __ movq(RCX, Address(RSP, + 2 * kWordSize)); | 592 __ movq(RCX, Address(RSP, + 2 * kWordSize)); |
| 557 __ orq(RCX, RAX); | 593 __ orq(RCX, RAX); |
| 558 __ testq(RCX, Immediate(kSmiTagMask)); | 594 __ testq(RCX, Immediate(kSmiTagMask)); |
| (...skipping 857 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1416 __ LoadObject(RAX, bool_true); | 1452 __ LoadObject(RAX, bool_true); |
| 1417 __ ret(); | 1453 __ ret(); |
| 1418 return true; | 1454 return true; |
| 1419 } | 1455 } |
| 1420 | 1456 |
| 1421 #undef __ | 1457 #undef __ |
| 1422 | 1458 |
| 1423 } // namespace dart | 1459 } // namespace dart |
| 1424 | 1460 |
| 1425 #endif // defined TARGET_ARCH_X64 | 1461 #endif // defined TARGET_ARCH_X64 |
| OLD | NEW |