OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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/arm64/codegen-arm64.h" | 5 #include "src/arm64/codegen-arm64.h" |
6 | 6 |
7 #if V8_TARGET_ARCH_ARM64 | 7 #if V8_TARGET_ARCH_ARM64 |
8 | 8 |
9 #include "src/arm64/simulator-arm64.h" | 9 #include "src/arm64/simulator-arm64.h" |
10 #include "src/codegen.h" | 10 #include "src/codegen.h" |
11 #include "src/macro-assembler.h" | 11 #include "src/macro-assembler.h" |
12 | 12 |
13 namespace v8 { | 13 namespace v8 { |
14 namespace internal { | 14 namespace internal { |
15 | 15 |
16 #define __ ACCESS_MASM(masm) | 16 #define __ ACCESS_MASM(masm) |
17 | 17 |
18 #if defined(USE_SIMULATOR) | 18 #if defined(USE_SIMULATOR) |
19 byte* fast_exp_arm64_machine_code = NULL; | 19 byte* fast_exp_arm64_machine_code = nullptr; |
20 double fast_exp_simulator(double x) { | 20 double fast_exp_simulator(double x, Isolate* isolate) { |
21 Simulator * simulator = Simulator::current(Isolate::Current()); | 21 Simulator * simulator = Simulator::current(isolate); |
22 Simulator::CallArgument args[] = { | 22 Simulator::CallArgument args[] = { |
23 Simulator::CallArgument(x), | 23 Simulator::CallArgument(x), |
24 Simulator::CallArgument::End() | 24 Simulator::CallArgument::End() |
25 }; | 25 }; |
26 return simulator->CallDouble(fast_exp_arm64_machine_code, args); | 26 return simulator->CallDouble(fast_exp_arm64_machine_code, args); |
27 } | 27 } |
28 #endif | 28 #endif |
29 | 29 |
30 | 30 |
31 UnaryMathFunction CreateExpFunction() { | 31 UnaryMathFunctionWithIsolate CreateExpFunction(Isolate* isolate) { |
32 if (!FLAG_fast_math) return &std::exp; | |
33 | |
34 // Use the Math.exp implemetation in MathExpGenerator::EmitMathExp() to create | 32 // Use the Math.exp implemetation in MathExpGenerator::EmitMathExp() to create |
35 // an AAPCS64-compliant exp() function. This will be faster than the C | 33 // an AAPCS64-compliant exp() function. This will be faster than the C |
36 // library's exp() function, but probably less accurate. | 34 // library's exp() function, but probably less accurate. |
37 size_t actual_size; | 35 size_t actual_size; |
38 byte* buffer = | 36 byte* buffer = |
39 static_cast<byte*>(base::OS::Allocate(1 * KB, &actual_size, true)); | 37 static_cast<byte*>(base::OS::Allocate(1 * KB, &actual_size, true)); |
40 if (buffer == NULL) return &std::exp; | 38 if (buffer == nullptr) return nullptr; |
41 | 39 |
42 ExternalReference::InitializeMathExpData(); | 40 ExternalReference::InitializeMathExpData(); |
43 MacroAssembler masm(NULL, buffer, static_cast<int>(actual_size)); | 41 MacroAssembler masm(nullptr, buffer, static_cast<int>(actual_size)); |
44 masm.SetStackPointer(csp); | 42 masm.SetStackPointer(csp); |
45 | 43 |
46 // The argument will be in d0 on entry. | 44 // The argument will be in d0 on entry. |
47 DoubleRegister input = d0; | 45 DoubleRegister input = d0; |
48 // Use other caller-saved registers for all other values. | 46 // Use other caller-saved registers for all other values. |
49 DoubleRegister result = d1; | 47 DoubleRegister result = d1; |
50 DoubleRegister double_temp1 = d2; | 48 DoubleRegister double_temp1 = d2; |
51 DoubleRegister double_temp2 = d3; | 49 DoubleRegister double_temp2 = d3; |
52 Register temp1 = x10; | 50 Register temp1 = x10; |
53 Register temp2 = x11; | 51 Register temp2 = x11; |
54 Register temp3 = x12; | 52 Register temp3 = x12; |
55 | 53 |
56 MathExpGenerator::EmitMathExp(&masm, input, result, | 54 MathExpGenerator::EmitMathExp(&masm, input, result, |
57 double_temp1, double_temp2, | 55 double_temp1, double_temp2, |
58 temp1, temp2, temp3); | 56 temp1, temp2, temp3); |
59 // Move the result to the return register. | 57 // Move the result to the return register. |
60 masm.Fmov(d0, result); | 58 masm.Fmov(d0, result); |
61 masm.Ret(); | 59 masm.Ret(); |
62 | 60 |
63 CodeDesc desc; | 61 CodeDesc desc; |
64 masm.GetCode(&desc); | 62 masm.GetCode(&desc); |
65 DCHECK(!RelocInfo::RequiresRelocation(desc)); | 63 DCHECK(!RelocInfo::RequiresRelocation(desc)); |
66 | 64 |
67 Assembler::FlushICacheWithoutIsolate(buffer, actual_size); | 65 Assembler::FlushICache(isolate, buffer, actual_size); |
68 base::OS::ProtectCode(buffer, actual_size); | 66 base::OS::ProtectCode(buffer, actual_size); |
69 | 67 |
70 #if !defined(USE_SIMULATOR) | 68 #if !defined(USE_SIMULATOR) |
71 return FUNCTION_CAST<UnaryMathFunction>(buffer); | 69 return FUNCTION_CAST<UnaryMathFunctionWithIsolate>(buffer); |
72 #else | 70 #else |
73 fast_exp_arm64_machine_code = buffer; | 71 fast_exp_arm64_machine_code = buffer; |
74 return &fast_exp_simulator; | 72 return &fast_exp_simulator; |
75 #endif | 73 #endif |
76 } | 74 } |
77 | 75 |
78 | 76 |
79 UnaryMathFunction CreateSqrtFunction() { | 77 UnaryMathFunction CreateSqrtFunction() { |
80 return &std::sqrt; | 78 return &std::sqrt; |
81 } | 79 } |
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
631 | 629 |
632 __ Bind(&done); | 630 __ Bind(&done); |
633 } | 631 } |
634 | 632 |
635 #undef __ | 633 #undef __ |
636 | 634 |
637 } // namespace internal | 635 } // namespace internal |
638 } // namespace v8 | 636 } // namespace v8 |
639 | 637 |
640 #endif // V8_TARGET_ARCH_ARM64 | 638 #endif // V8_TARGET_ARCH_ARM64 |
OLD | NEW |