Index: src/x64/codegen-x64.cc |
diff --git a/src/x64/codegen-x64.cc b/src/x64/codegen-x64.cc |
index 911f3cb64aa10d229629b8611a8a57974ffd79d8..6731e9eba86a5fe2e4826e9b21eba8249076fb9b 100644 |
--- a/src/x64/codegen-x64.cc |
+++ b/src/x64/codegen-x64.cc |
@@ -30,6 +30,38 @@ |
#define __ masm. |
+ |
+ |
+UnaryMathFunctionWithIsolate CreateExpFunction(Isolate* isolate) { |
+ size_t actual_size; |
+ byte* buffer = |
+ static_cast<byte*>(base::OS::Allocate(1 * KB, &actual_size, true)); |
+ if (buffer == nullptr) return nullptr; |
+ ExternalReference::InitializeMathExpData(); |
+ |
+ MacroAssembler masm(isolate, buffer, static_cast<int>(actual_size), |
+ CodeObjectRequired::kNo); |
+ // xmm0: raw double input. |
+ XMMRegister input = xmm0; |
+ XMMRegister result = xmm1; |
+ __ pushq(rax); |
+ __ pushq(rbx); |
+ |
+ MathExpGenerator::EmitMathExp(&masm, input, result, xmm2, rax, rbx); |
+ |
+ __ popq(rbx); |
+ __ popq(rax); |
+ __ Movsd(xmm0, result); |
+ __ Ret(); |
+ |
+ CodeDesc desc; |
+ masm.GetCode(&desc); |
+ DCHECK(!RelocInfo::RequiresRelocation(desc)); |
+ |
+ Assembler::FlushICache(isolate, buffer, actual_size); |
+ base::OS::ProtectCode(buffer, actual_size); |
+ return FUNCTION_CAST<UnaryMathFunctionWithIsolate>(buffer); |
+} |
UnaryMathFunctionWithIsolate CreateSqrtFunction(Isolate* isolate) { |
@@ -467,6 +499,59 @@ |
__ bind(&done); |
} |
+ |
+void MathExpGenerator::EmitMathExp(MacroAssembler* masm, |
+ XMMRegister input, |
+ XMMRegister result, |
+ XMMRegister double_scratch, |
+ Register temp1, |
+ Register temp2) { |
+ DCHECK(!input.is(result)); |
+ DCHECK(!input.is(double_scratch)); |
+ DCHECK(!result.is(double_scratch)); |
+ DCHECK(!temp1.is(temp2)); |
+ DCHECK(ExternalReference::math_exp_constants(0).address() != NULL); |
+ DCHECK(!masm->serializer_enabled()); // External references not serializable. |
+ |
+ Label done; |
+ |
+ __ Move(kScratchRegister, ExternalReference::math_exp_constants(0)); |
+ __ Movsd(double_scratch, Operand(kScratchRegister, 0 * kDoubleSize)); |
+ __ Xorpd(result, result); |
+ __ Ucomisd(double_scratch, input); |
+ __ j(above_equal, &done); |
+ __ Ucomisd(input, Operand(kScratchRegister, 1 * kDoubleSize)); |
+ __ Movsd(result, Operand(kScratchRegister, 2 * kDoubleSize)); |
+ __ j(above_equal, &done); |
+ __ Movsd(double_scratch, Operand(kScratchRegister, 3 * kDoubleSize)); |
+ __ Movsd(result, Operand(kScratchRegister, 4 * kDoubleSize)); |
+ __ Mulsd(double_scratch, input); |
+ __ Addsd(double_scratch, result); |
+ __ Movq(temp2, double_scratch); |
+ __ Subsd(double_scratch, result); |
+ __ Movsd(result, Operand(kScratchRegister, 6 * kDoubleSize)); |
+ __ leaq(temp1, Operand(temp2, 0x1ff800)); |
+ __ andq(temp2, Immediate(0x7ff)); |
+ __ shrq(temp1, Immediate(11)); |
+ __ Mulsd(double_scratch, Operand(kScratchRegister, 5 * kDoubleSize)); |
+ __ Move(kScratchRegister, ExternalReference::math_exp_log_table()); |
+ __ shlq(temp1, Immediate(52)); |
+ __ orq(temp1, Operand(kScratchRegister, temp2, times_8, 0)); |
+ __ Move(kScratchRegister, ExternalReference::math_exp_constants(0)); |
+ __ Subsd(double_scratch, input); |
+ __ Movsd(input, double_scratch); |
+ __ Subsd(result, double_scratch); |
+ __ Mulsd(input, double_scratch); |
+ __ Mulsd(result, input); |
+ __ Movq(input, temp1); |
+ __ Mulsd(result, Operand(kScratchRegister, 7 * kDoubleSize)); |
+ __ Subsd(result, double_scratch); |
+ __ Addsd(result, Operand(kScratchRegister, 8 * kDoubleSize)); |
+ __ Mulsd(result, input); |
+ |
+ __ bind(&done); |
+} |
+ |
#undef __ |