| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/x64/codegen-x64.h" | 5 #include "src/x64/codegen-x64.h" |
| 6 | 6 |
| 7 #if V8_TARGET_ARCH_X64 | 7 #if V8_TARGET_ARCH_X64 |
| 8 | 8 |
| 9 #include "src/codegen.h" | 9 #include "src/codegen.h" |
| 10 #include "src/macro-assembler.h" | 10 #include "src/macro-assembler.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 void StubRuntimeCallHelper::AfterCall(MacroAssembler* masm) const { | 25 void StubRuntimeCallHelper::AfterCall(MacroAssembler* masm) const { |
| 26 masm->LeaveFrame(StackFrame::INTERNAL); | 26 masm->LeaveFrame(StackFrame::INTERNAL); |
| 27 DCHECK(masm->has_frame()); | 27 DCHECK(masm->has_frame()); |
| 28 masm->set_has_frame(false); | 28 masm->set_has_frame(false); |
| 29 } | 29 } |
| 30 | 30 |
| 31 | 31 |
| 32 #define __ masm. | 32 #define __ masm. |
| 33 | 33 |
| 34 | 34 |
| 35 UnaryMathFunctionWithIsolate CreateExpFunction(Isolate* isolate) { | |
| 36 size_t actual_size; | |
| 37 byte* buffer = | |
| 38 static_cast<byte*>(base::OS::Allocate(1 * KB, &actual_size, true)); | |
| 39 if (buffer == nullptr) return nullptr; | |
| 40 ExternalReference::InitializeMathExpData(); | |
| 41 | |
| 42 MacroAssembler masm(isolate, buffer, static_cast<int>(actual_size), | |
| 43 CodeObjectRequired::kNo); | |
| 44 // xmm0: raw double input. | |
| 45 XMMRegister input = xmm0; | |
| 46 XMMRegister result = xmm1; | |
| 47 __ pushq(rax); | |
| 48 __ pushq(rbx); | |
| 49 | |
| 50 MathExpGenerator::EmitMathExp(&masm, input, result, xmm2, rax, rbx); | |
| 51 | |
| 52 __ popq(rbx); | |
| 53 __ popq(rax); | |
| 54 __ Movsd(xmm0, result); | |
| 55 __ Ret(); | |
| 56 | |
| 57 CodeDesc desc; | |
| 58 masm.GetCode(&desc); | |
| 59 DCHECK(!RelocInfo::RequiresRelocation(desc)); | |
| 60 | |
| 61 Assembler::FlushICache(isolate, buffer, actual_size); | |
| 62 base::OS::ProtectCode(buffer, actual_size); | |
| 63 return FUNCTION_CAST<UnaryMathFunctionWithIsolate>(buffer); | |
| 64 } | |
| 65 | |
| 66 | |
| 67 UnaryMathFunctionWithIsolate CreateSqrtFunction(Isolate* isolate) { | 35 UnaryMathFunctionWithIsolate CreateSqrtFunction(Isolate* isolate) { |
| 68 size_t actual_size; | 36 size_t actual_size; |
| 69 // Allocate buffer in executable space. | 37 // Allocate buffer in executable space. |
| 70 byte* buffer = | 38 byte* buffer = |
| 71 static_cast<byte*>(base::OS::Allocate(1 * KB, &actual_size, true)); | 39 static_cast<byte*>(base::OS::Allocate(1 * KB, &actual_size, true)); |
| 72 if (buffer == nullptr) return nullptr; | 40 if (buffer == nullptr) return nullptr; |
| 73 | 41 |
| 74 MacroAssembler masm(isolate, buffer, static_cast<int>(actual_size), | 42 MacroAssembler masm(isolate, buffer, static_cast<int>(actual_size), |
| 75 CodeObjectRequired::kNo); | 43 CodeObjectRequired::kNo); |
| 76 // xmm0: raw double input. | 44 // xmm0: raw double input. |
| (...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 // One-byte string. | 460 // One-byte string. |
| 493 // Load the byte into the result register. | 461 // Load the byte into the result register. |
| 494 __ bind(&one_byte); | 462 __ bind(&one_byte); |
| 495 __ movzxbl(result, FieldOperand(string, | 463 __ movzxbl(result, FieldOperand(string, |
| 496 index, | 464 index, |
| 497 times_1, | 465 times_1, |
| 498 SeqOneByteString::kHeaderSize)); | 466 SeqOneByteString::kHeaderSize)); |
| 499 __ bind(&done); | 467 __ bind(&done); |
| 500 } | 468 } |
| 501 | 469 |
| 502 | |
| 503 void MathExpGenerator::EmitMathExp(MacroAssembler* masm, | |
| 504 XMMRegister input, | |
| 505 XMMRegister result, | |
| 506 XMMRegister double_scratch, | |
| 507 Register temp1, | |
| 508 Register temp2) { | |
| 509 DCHECK(!input.is(result)); | |
| 510 DCHECK(!input.is(double_scratch)); | |
| 511 DCHECK(!result.is(double_scratch)); | |
| 512 DCHECK(!temp1.is(temp2)); | |
| 513 DCHECK(ExternalReference::math_exp_constants(0).address() != NULL); | |
| 514 DCHECK(!masm->serializer_enabled()); // External references not serializable. | |
| 515 | |
| 516 Label done; | |
| 517 | |
| 518 __ Move(kScratchRegister, ExternalReference::math_exp_constants(0)); | |
| 519 __ Movsd(double_scratch, Operand(kScratchRegister, 0 * kDoubleSize)); | |
| 520 __ Xorpd(result, result); | |
| 521 __ Ucomisd(double_scratch, input); | |
| 522 __ j(above_equal, &done); | |
| 523 __ Ucomisd(input, Operand(kScratchRegister, 1 * kDoubleSize)); | |
| 524 __ Movsd(result, Operand(kScratchRegister, 2 * kDoubleSize)); | |
| 525 __ j(above_equal, &done); | |
| 526 __ Movsd(double_scratch, Operand(kScratchRegister, 3 * kDoubleSize)); | |
| 527 __ Movsd(result, Operand(kScratchRegister, 4 * kDoubleSize)); | |
| 528 __ Mulsd(double_scratch, input); | |
| 529 __ Addsd(double_scratch, result); | |
| 530 __ Movq(temp2, double_scratch); | |
| 531 __ Subsd(double_scratch, result); | |
| 532 __ Movsd(result, Operand(kScratchRegister, 6 * kDoubleSize)); | |
| 533 __ leaq(temp1, Operand(temp2, 0x1ff800)); | |
| 534 __ andq(temp2, Immediate(0x7ff)); | |
| 535 __ shrq(temp1, Immediate(11)); | |
| 536 __ Mulsd(double_scratch, Operand(kScratchRegister, 5 * kDoubleSize)); | |
| 537 __ Move(kScratchRegister, ExternalReference::math_exp_log_table()); | |
| 538 __ shlq(temp1, Immediate(52)); | |
| 539 __ orq(temp1, Operand(kScratchRegister, temp2, times_8, 0)); | |
| 540 __ Move(kScratchRegister, ExternalReference::math_exp_constants(0)); | |
| 541 __ Subsd(double_scratch, input); | |
| 542 __ Movsd(input, double_scratch); | |
| 543 __ Subsd(result, double_scratch); | |
| 544 __ Mulsd(input, double_scratch); | |
| 545 __ Mulsd(result, input); | |
| 546 __ Movq(input, temp1); | |
| 547 __ Mulsd(result, Operand(kScratchRegister, 7 * kDoubleSize)); | |
| 548 __ Subsd(result, double_scratch); | |
| 549 __ Addsd(result, Operand(kScratchRegister, 8 * kDoubleSize)); | |
| 550 __ Mulsd(result, input); | |
| 551 | |
| 552 __ bind(&done); | |
| 553 } | |
| 554 | |
| 555 #undef __ | 470 #undef __ |
| 556 | 471 |
| 557 | 472 |
| 558 CodeAgingHelper::CodeAgingHelper(Isolate* isolate) { | 473 CodeAgingHelper::CodeAgingHelper(Isolate* isolate) { |
| 559 USE(isolate); | 474 USE(isolate); |
| 560 DCHECK(young_sequence_.length() == kNoCodeAgeSequenceLength); | 475 DCHECK(young_sequence_.length() == kNoCodeAgeSequenceLength); |
| 561 // The sequence of instructions that is patched out for aging code is the | 476 // The sequence of instructions that is patched out for aging code is the |
| 562 // following boilerplate stack-building prologue that is found both in | 477 // following boilerplate stack-building prologue that is found both in |
| 563 // FUNCTION and OPTIMIZED_FUNCTION code: | 478 // FUNCTION and OPTIMIZED_FUNCTION code: |
| 564 CodePatcher patcher(isolate, young_sequence_.start(), | 479 CodePatcher patcher(isolate, young_sequence_.start(), |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 635 return Operand(base_reg_, argument_count_reg_, times_pointer_size, | 550 return Operand(base_reg_, argument_count_reg_, times_pointer_size, |
| 636 displacement_to_last_argument + (receiver - 1 - index) * kPointerSize); | 551 displacement_to_last_argument + (receiver - 1 - index) * kPointerSize); |
| 637 } | 552 } |
| 638 } | 553 } |
| 639 | 554 |
| 640 | 555 |
| 641 } // namespace internal | 556 } // namespace internal |
| 642 } // namespace v8 | 557 } // namespace v8 |
| 643 | 558 |
| 644 #endif // V8_TARGET_ARCH_X64 | 559 #endif // V8_TARGET_ARCH_X64 |
| OLD | NEW |