Index: src/mips64/codegen-mips64.cc |
diff --git a/src/mips64/codegen-mips64.cc b/src/mips64/codegen-mips64.cc |
index a8f58904014b0f6f5a1cd2ea99ecdd992973ecae..678f606cb5716135c0e66a135f35da0c3d390473 100644 |
--- a/src/mips64/codegen-mips64.cc |
+++ b/src/mips64/codegen-mips64.cc |
@@ -15,6 +15,59 @@ |
#define __ masm. |
+ |
+ |
+#if defined(USE_SIMULATOR) |
+byte* fast_exp_mips_machine_code = nullptr; |
+double fast_exp_simulator(double x, Isolate* isolate) { |
+ return Simulator::current(isolate)->CallFP(fast_exp_mips_machine_code, x, 0); |
+} |
+#endif |
+ |
+ |
+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); |
+ |
+ { |
+ DoubleRegister input = f12; |
+ DoubleRegister result = f0; |
+ DoubleRegister double_scratch1 = f4; |
+ DoubleRegister double_scratch2 = f6; |
+ Register temp1 = a4; |
+ Register temp2 = a5; |
+ Register temp3 = a6; |
+ |
+ __ MovFromFloatParameter(input); |
+ __ Push(temp3, temp2, temp1); |
+ MathExpGenerator::EmitMathExp( |
+ &masm, input, result, double_scratch1, double_scratch2, |
+ temp1, temp2, temp3); |
+ __ Pop(temp3, temp2, temp1); |
+ __ MovToFloatResult(result); |
+ __ Ret(); |
+ } |
+ |
+ CodeDesc desc; |
+ masm.GetCode(&desc); |
+ DCHECK(!RelocInfo::RequiresRelocation(desc)); |
+ |
+ Assembler::FlushICache(isolate, buffer, actual_size); |
+ base::OS::ProtectCode(buffer, actual_size); |
+ |
+#if !defined(USE_SIMULATOR) |
+ return FUNCTION_CAST<UnaryMathFunctionWithIsolate>(buffer); |
+#else |
+ fast_exp_mips_machine_code = buffer; |
+ return &fast_exp_simulator; |
+#endif |
+} |
#if defined(V8_HOST_ARCH_MIPS) |
@@ -1037,6 +1090,94 @@ |
__ bind(&done); |
} |
+ |
+static MemOperand ExpConstant(int index, Register base) { |
+ return MemOperand(base, index * kDoubleSize); |
+} |
+ |
+ |
+void MathExpGenerator::EmitMathExp(MacroAssembler* masm, |
+ DoubleRegister input, |
+ DoubleRegister result, |
+ DoubleRegister double_scratch1, |
+ DoubleRegister double_scratch2, |
+ Register temp1, |
+ Register temp2, |
+ Register temp3) { |
+ DCHECK(!input.is(result)); |
+ DCHECK(!input.is(double_scratch1)); |
+ DCHECK(!input.is(double_scratch2)); |
+ DCHECK(!result.is(double_scratch1)); |
+ DCHECK(!result.is(double_scratch2)); |
+ DCHECK(!double_scratch1.is(double_scratch2)); |
+ DCHECK(!temp1.is(temp2)); |
+ DCHECK(!temp1.is(temp3)); |
+ DCHECK(!temp2.is(temp3)); |
+ DCHECK(ExternalReference::math_exp_constants(0).address() != NULL); |
+ DCHECK(!masm->serializer_enabled()); // External references not serializable. |
+ |
+ Label zero, infinity, done; |
+ __ li(temp3, Operand(ExternalReference::math_exp_constants(0))); |
+ |
+ __ ldc1(double_scratch1, ExpConstant(0, temp3)); |
+ __ BranchF(&zero, NULL, ge, double_scratch1, input); |
+ |
+ __ ldc1(double_scratch2, ExpConstant(1, temp3)); |
+ __ BranchF(&infinity, NULL, ge, input, double_scratch2); |
+ |
+ __ ldc1(double_scratch1, ExpConstant(3, temp3)); |
+ __ ldc1(result, ExpConstant(4, temp3)); |
+ __ mul_d(double_scratch1, double_scratch1, input); |
+ __ add_d(double_scratch1, double_scratch1, result); |
+ __ FmoveLow(temp2, double_scratch1); |
+ __ sub_d(double_scratch1, double_scratch1, result); |
+ __ ldc1(result, ExpConstant(6, temp3)); |
+ __ ldc1(double_scratch2, ExpConstant(5, temp3)); |
+ __ mul_d(double_scratch1, double_scratch1, double_scratch2); |
+ __ sub_d(double_scratch1, double_scratch1, input); |
+ __ sub_d(result, result, double_scratch1); |
+ __ mul_d(double_scratch2, double_scratch1, double_scratch1); |
+ __ mul_d(result, result, double_scratch2); |
+ __ ldc1(double_scratch2, ExpConstant(7, temp3)); |
+ __ mul_d(result, result, double_scratch2); |
+ __ sub_d(result, result, double_scratch1); |
+ // Mov 1 in double_scratch2 as math_exp_constants_array[8] == 1. |
+ DCHECK(*reinterpret_cast<double*> |
+ (ExternalReference::math_exp_constants(8).address()) == 1); |
+ __ Move(double_scratch2, 1.); |
+ __ add_d(result, result, double_scratch2); |
+ __ dsrl(temp1, temp2, 11); |
+ __ Ext(temp2, temp2, 0, 11); |
+ __ Daddu(temp1, temp1, Operand(0x3ff)); |
+ |
+ // Must not call ExpConstant() after overwriting temp3! |
+ __ li(temp3, Operand(ExternalReference::math_exp_log_table())); |
+ __ Dlsa(temp3, temp3, temp2, 3); |
+ __ lwu(temp2, MemOperand(temp3, Register::kMantissaOffset)); |
+ __ lwu(temp3, MemOperand(temp3, Register::kExponentOffset)); |
+ // The first word is loaded is the lower number register. |
+ if (temp2.code() < temp3.code()) { |
+ __ dsll(at, temp1, 20); |
+ __ Or(temp1, temp3, at); |
+ __ Move(double_scratch1, temp2, temp1); |
+ } else { |
+ __ dsll(at, temp1, 20); |
+ __ Or(temp1, temp2, at); |
+ __ Move(double_scratch1, temp3, temp1); |
+ } |
+ __ mul_d(result, result, double_scratch1); |
+ __ BranchShort(&done); |
+ |
+ __ bind(&zero); |
+ __ Move(result, kDoubleRegZero); |
+ __ BranchShort(&done); |
+ |
+ __ bind(&infinity); |
+ __ ldc1(result, ExpConstant(2, temp3)); |
+ |
+ __ bind(&done); |
+} |
+ |
#ifdef DEBUG |
// nop(CODE_AGE_MARKER_NOP) |
static const uint32_t kCodeAgePatchFirstInstruction = 0x00010180; |