Index: src/ia32/codegen-ia32.cc |
diff --git a/src/ia32/codegen-ia32.cc b/src/ia32/codegen-ia32.cc |
index 18e53641e676d2ba2ea35f2a3ba2af5640ca48cf..267fe5c596d2d14e13d8bfc25f722e26be3353b5 100644 |
--- a/src/ia32/codegen-ia32.cc |
+++ b/src/ia32/codegen-ia32.cc |
@@ -32,6 +32,43 @@ |
#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); |
+ // esp[1 * kPointerSize]: raw double input |
+ // esp[0 * kPointerSize]: return address |
+ { |
+ XMMRegister input = xmm1; |
+ XMMRegister result = xmm2; |
+ __ movsd(input, Operand(esp, 1 * kPointerSize)); |
+ __ push(eax); |
+ __ push(ebx); |
+ |
+ MathExpGenerator::EmitMathExp(&masm, input, result, xmm0, eax, ebx); |
+ |
+ __ pop(ebx); |
+ __ pop(eax); |
+ __ movsd(Operand(esp, 1 * kPointerSize), result); |
+ __ fld_d(Operand(esp, 1 * kPointerSize)); |
+ __ 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) { |
@@ -891,6 +928,64 @@ |
__ bind(&done); |
} |
+ |
+static Operand ExpConstant(int index) { |
+ return Operand::StaticVariable(ExternalReference::math_exp_constants(index)); |
+} |
+ |
+ |
+void MathExpGenerator::EmitMathExp(MacroAssembler* masm, |
+ XMMRegister input, |
+ XMMRegister result, |
+ XMMRegister double_scratch, |
+ Register temp1, |
+ Register temp2) { |
+ DCHECK(!input.is(double_scratch)); |
+ DCHECK(!input.is(result)); |
+ 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; |
+ |
+ __ movsd(double_scratch, ExpConstant(0)); |
+ __ xorpd(result, result); |
+ __ ucomisd(double_scratch, input); |
+ __ j(above_equal, &done); |
+ __ ucomisd(input, ExpConstant(1)); |
+ __ movsd(result, ExpConstant(2)); |
+ __ j(above_equal, &done); |
+ __ movsd(double_scratch, ExpConstant(3)); |
+ __ movsd(result, ExpConstant(4)); |
+ __ mulsd(double_scratch, input); |
+ __ addsd(double_scratch, result); |
+ __ movd(temp2, double_scratch); |
+ __ subsd(double_scratch, result); |
+ __ movsd(result, ExpConstant(6)); |
+ __ mulsd(double_scratch, ExpConstant(5)); |
+ __ subsd(double_scratch, input); |
+ __ subsd(result, double_scratch); |
+ __ movsd(input, double_scratch); |
+ __ mulsd(input, double_scratch); |
+ __ mulsd(result, input); |
+ __ mov(temp1, temp2); |
+ __ mulsd(result, ExpConstant(7)); |
+ __ subsd(result, double_scratch); |
+ __ add(temp1, Immediate(0x1ff800)); |
+ __ addsd(result, ExpConstant(8)); |
+ __ and_(temp2, Immediate(0x7ff)); |
+ __ shr(temp1, 11); |
+ __ shl(temp1, 20); |
+ __ movd(input, temp1); |
+ __ pshufd(input, input, static_cast<uint8_t>(0xe1)); // Order: 11 10 00 01 |
+ __ movsd(double_scratch, Operand::StaticArray( |
+ temp2, times_8, ExternalReference::math_exp_log_table())); |
+ __ orps(input, double_scratch); |
+ __ mulsd(result, input); |
+ __ bind(&done); |
+} |
+ |
#undef __ |