| 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/v8.h" | 5 #include "src/v8.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 17 matching lines...) Expand all Loading... |
| 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 UnaryMathFunction CreateExpFunction() { | 35 UnaryMathFunction CreateExpFunction() { |
| 36 if (!FLAG_fast_math) return &std::exp; | 36 if (!FLAG_fast_math) return &std::exp; |
| 37 size_t actual_size; | 37 size_t actual_size; |
| 38 byte* buffer = static_cast<byte*>(OS::Allocate(1 * KB, &actual_size, true)); | 38 byte* buffer = |
| 39 static_cast<byte*>(base::OS::Allocate(1 * KB, &actual_size, true)); |
| 39 if (buffer == NULL) return &std::exp; | 40 if (buffer == NULL) return &std::exp; |
| 40 ExternalReference::InitializeMathExpData(); | 41 ExternalReference::InitializeMathExpData(); |
| 41 | 42 |
| 42 MacroAssembler masm(NULL, buffer, static_cast<int>(actual_size)); | 43 MacroAssembler masm(NULL, buffer, static_cast<int>(actual_size)); |
| 43 // xmm0: raw double input. | 44 // xmm0: raw double input. |
| 44 XMMRegister input = xmm0; | 45 XMMRegister input = xmm0; |
| 45 XMMRegister result = xmm1; | 46 XMMRegister result = xmm1; |
| 46 __ pushq(rax); | 47 __ pushq(rax); |
| 47 __ pushq(rbx); | 48 __ pushq(rbx); |
| 48 | 49 |
| 49 MathExpGenerator::EmitMathExp(&masm, input, result, xmm2, rax, rbx); | 50 MathExpGenerator::EmitMathExp(&masm, input, result, xmm2, rax, rbx); |
| 50 | 51 |
| 51 __ popq(rbx); | 52 __ popq(rbx); |
| 52 __ popq(rax); | 53 __ popq(rax); |
| 53 __ movsd(xmm0, result); | 54 __ movsd(xmm0, result); |
| 54 __ Ret(); | 55 __ Ret(); |
| 55 | 56 |
| 56 CodeDesc desc; | 57 CodeDesc desc; |
| 57 masm.GetCode(&desc); | 58 masm.GetCode(&desc); |
| 58 ASSERT(!RelocInfo::RequiresRelocation(desc)); | 59 ASSERT(!RelocInfo::RequiresRelocation(desc)); |
| 59 | 60 |
| 60 CPU::FlushICache(buffer, actual_size); | 61 CpuFeatures::FlushICache(buffer, actual_size); |
| 61 OS::ProtectCode(buffer, actual_size); | 62 base::OS::ProtectCode(buffer, actual_size); |
| 62 return FUNCTION_CAST<UnaryMathFunction>(buffer); | 63 return FUNCTION_CAST<UnaryMathFunction>(buffer); |
| 63 } | 64 } |
| 64 | 65 |
| 65 | 66 |
| 66 UnaryMathFunction CreateSqrtFunction() { | 67 UnaryMathFunction CreateSqrtFunction() { |
| 67 size_t actual_size; | 68 size_t actual_size; |
| 68 // Allocate buffer in executable space. | 69 // Allocate buffer in executable space. |
| 69 byte* buffer = static_cast<byte*>(OS::Allocate(1 * KB, | 70 byte* buffer = |
| 70 &actual_size, | 71 static_cast<byte*>(base::OS::Allocate(1 * KB, &actual_size, true)); |
| 71 true)); | |
| 72 if (buffer == NULL) return &std::sqrt; | 72 if (buffer == NULL) return &std::sqrt; |
| 73 | 73 |
| 74 MacroAssembler masm(NULL, buffer, static_cast<int>(actual_size)); | 74 MacroAssembler masm(NULL, buffer, static_cast<int>(actual_size)); |
| 75 // xmm0: raw double input. | 75 // xmm0: raw double input. |
| 76 // Move double input into registers. | 76 // Move double input into registers. |
| 77 __ sqrtsd(xmm0, xmm0); | 77 __ sqrtsd(xmm0, xmm0); |
| 78 __ Ret(); | 78 __ Ret(); |
| 79 | 79 |
| 80 CodeDesc desc; | 80 CodeDesc desc; |
| 81 masm.GetCode(&desc); | 81 masm.GetCode(&desc); |
| 82 ASSERT(!RelocInfo::RequiresRelocation(desc)); | 82 ASSERT(!RelocInfo::RequiresRelocation(desc)); |
| 83 | 83 |
| 84 CPU::FlushICache(buffer, actual_size); | 84 CpuFeatures::FlushICache(buffer, actual_size); |
| 85 OS::ProtectCode(buffer, actual_size); | 85 base::OS::ProtectCode(buffer, actual_size); |
| 86 return FUNCTION_CAST<UnaryMathFunction>(buffer); | 86 return FUNCTION_CAST<UnaryMathFunction>(buffer); |
| 87 } | 87 } |
| 88 | 88 |
| 89 | 89 |
| 90 #ifdef _WIN64 | 90 #ifdef _WIN64 |
| 91 typedef double (*ModuloFunction)(double, double); | 91 typedef double (*ModuloFunction)(double, double); |
| 92 // Define custom fmod implementation. | 92 // Define custom fmod implementation. |
| 93 ModuloFunction CreateModuloFunction() { | 93 ModuloFunction CreateModuloFunction() { |
| 94 size_t actual_size; | 94 size_t actual_size; |
| 95 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, | 95 byte* buffer = static_cast<byte*>( |
| 96 &actual_size, | 96 base::OS::Allocate(Assembler::kMinimalBufferSize, &actual_size, true)); |
| 97 true)); | |
| 98 CHECK(buffer); | 97 CHECK(buffer); |
| 99 Assembler masm(NULL, buffer, static_cast<int>(actual_size)); | 98 Assembler masm(NULL, buffer, static_cast<int>(actual_size)); |
| 100 // Generated code is put into a fixed, unmovable, buffer, and not into | 99 // Generated code is put into a fixed, unmovable, buffer, and not into |
| 101 // the V8 heap. We can't, and don't, refer to any relocatable addresses | 100 // the V8 heap. We can't, and don't, refer to any relocatable addresses |
| 102 // (e.g. the JavaScript nan-object). | 101 // (e.g. the JavaScript nan-object). |
| 103 | 102 |
| 104 // Windows 64 ABI passes double arguments in xmm0, xmm1 and | 103 // Windows 64 ABI passes double arguments in xmm0, xmm1 and |
| 105 // returns result in xmm0. | 104 // returns result in xmm0. |
| 106 // Argument backing space is allocated on the stack above | 105 // Argument backing space is allocated on the stack above |
| 107 // the return address. | 106 // the return address. |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 Label clear_exceptions; | 162 Label clear_exceptions; |
| 164 __ testb(rax, Immediate(0x3f /* Any Exception*/)); | 163 __ testb(rax, Immediate(0x3f /* Any Exception*/)); |
| 165 __ j(not_zero, &clear_exceptions); | 164 __ j(not_zero, &clear_exceptions); |
| 166 __ ret(0); | 165 __ ret(0); |
| 167 __ bind(&clear_exceptions); | 166 __ bind(&clear_exceptions); |
| 168 __ fnclex(); | 167 __ fnclex(); |
| 169 __ ret(0); | 168 __ ret(0); |
| 170 | 169 |
| 171 CodeDesc desc; | 170 CodeDesc desc; |
| 172 masm.GetCode(&desc); | 171 masm.GetCode(&desc); |
| 173 OS::ProtectCode(buffer, actual_size); | 172 base::OS::ProtectCode(buffer, actual_size); |
| 174 // Call the function from C++ through this pointer. | 173 // Call the function from C++ through this pointer. |
| 175 return FUNCTION_CAST<ModuloFunction>(buffer); | 174 return FUNCTION_CAST<ModuloFunction>(buffer); |
| 176 } | 175 } |
| 177 | 176 |
| 178 #endif | 177 #endif |
| 179 | 178 |
| 180 #undef __ | 179 #undef __ |
| 181 | 180 |
| 182 // ------------------------------------------------------------------------- | 181 // ------------------------------------------------------------------------- |
| 183 // Code generators | 182 // Code generators |
| (...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 658 } | 657 } |
| 659 | 658 |
| 660 | 659 |
| 661 void Code::PatchPlatformCodeAge(Isolate* isolate, | 660 void Code::PatchPlatformCodeAge(Isolate* isolate, |
| 662 byte* sequence, | 661 byte* sequence, |
| 663 Code::Age age, | 662 Code::Age age, |
| 664 MarkingParity parity) { | 663 MarkingParity parity) { |
| 665 uint32_t young_length = isolate->code_aging_helper()->young_sequence_length(); | 664 uint32_t young_length = isolate->code_aging_helper()->young_sequence_length(); |
| 666 if (age == kNoAgeCodeAge) { | 665 if (age == kNoAgeCodeAge) { |
| 667 isolate->code_aging_helper()->CopyYoungSequenceTo(sequence); | 666 isolate->code_aging_helper()->CopyYoungSequenceTo(sequence); |
| 668 CPU::FlushICache(sequence, young_length); | 667 CpuFeatures::FlushICache(sequence, young_length); |
| 669 } else { | 668 } else { |
| 670 Code* stub = GetCodeAgeStub(isolate, age, parity); | 669 Code* stub = GetCodeAgeStub(isolate, age, parity); |
| 671 CodePatcher patcher(sequence, young_length); | 670 CodePatcher patcher(sequence, young_length); |
| 672 patcher.masm()->call(stub->instruction_start()); | 671 patcher.masm()->call(stub->instruction_start()); |
| 673 patcher.masm()->Nop( | 672 patcher.masm()->Nop( |
| 674 kNoCodeAgeSequenceLength - Assembler::kShortCallInstructionLength); | 673 kNoCodeAgeSequenceLength - Assembler::kShortCallInstructionLength); |
| 675 } | 674 } |
| 676 } | 675 } |
| 677 | 676 |
| 678 | 677 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 693 // argument_count_reg_ * times_pointer_size + (receiver - 1) * kPointerSize. | 692 // argument_count_reg_ * times_pointer_size + (receiver - 1) * kPointerSize. |
| 694 return Operand(base_reg_, argument_count_reg_, times_pointer_size, | 693 return Operand(base_reg_, argument_count_reg_, times_pointer_size, |
| 695 displacement_to_last_argument + (receiver - 1 - index) * kPointerSize); | 694 displacement_to_last_argument + (receiver - 1 - index) * kPointerSize); |
| 696 } | 695 } |
| 697 } | 696 } |
| 698 | 697 |
| 699 | 698 |
| 700 } } // namespace v8::internal | 699 } } // namespace v8::internal |
| 701 | 700 |
| 702 #endif // V8_TARGET_ARCH_X64 | 701 #endif // V8_TARGET_ARCH_X64 |
| OLD | NEW |