Commit 0fb2edd1 authored by jochen's avatar jochen Committed by Commit bot

Make fast_exp take an Isolate* paramter

We still share the code globally, but if we wanted, it would be easy to
make it per isolate now

BUG=v8:2487
R=yangguo@chromium.org,jkummerow@chromium.org
LOG=n

Review URL: https://codereview.chromium.org/1468313004

Cr-Commit-Position: refs/heads/master@{#32217}
parent 062586db
......@@ -18,23 +18,22 @@ namespace internal {
#if defined(USE_SIMULATOR)
byte* fast_exp_arm_machine_code = NULL;
double fast_exp_simulator(double x) {
return Simulator::current(Isolate::Current())->CallFPReturnsDouble(
fast_exp_arm_machine_code, x, 0);
byte* fast_exp_arm_machine_code = nullptr;
double fast_exp_simulator(double x, Isolate* isolate) {
return Simulator::current(isolate)
->CallFPReturnsDouble(fast_exp_arm_machine_code, x, 0);
}
#endif
UnaryMathFunction CreateExpFunction() {
if (!FLAG_fast_math) return &std::exp;
UnaryMathFunctionWithIsolate CreateExpFunction(Isolate* isolate) {
size_t actual_size;
byte* buffer =
static_cast<byte*>(base::OS::Allocate(1 * KB, &actual_size, true));
if (buffer == NULL) return &std::exp;
if (buffer == nullptr) return nullptr;
ExternalReference::InitializeMathExpData();
MacroAssembler masm(NULL, buffer, static_cast<int>(actual_size));
MacroAssembler masm(nullptr, buffer, static_cast<int>(actual_size));
{
DwVfpRegister input = d0;
......@@ -67,11 +66,11 @@ UnaryMathFunction CreateExpFunction() {
masm.GetCode(&desc);
DCHECK(!RelocInfo::RequiresRelocation(desc));
Assembler::FlushICacheWithoutIsolate(buffer, actual_size);
Assembler::FlushICache(isolate, buffer, actual_size);
base::OS::ProtectCode(buffer, actual_size);
#if !defined(USE_SIMULATOR)
return FUNCTION_CAST<UnaryMathFunction>(buffer);
return FUNCTION_CAST<UnaryMathFunctionWithIsolate>(buffer);
#else
fast_exp_arm_machine_code = buffer;
return &fast_exp_simulator;
......
......@@ -16,9 +16,9 @@ namespace internal {
#define __ ACCESS_MASM(masm)
#if defined(USE_SIMULATOR)
byte* fast_exp_arm64_machine_code = NULL;
double fast_exp_simulator(double x) {
Simulator * simulator = Simulator::current(Isolate::Current());
byte* fast_exp_arm64_machine_code = nullptr;
double fast_exp_simulator(double x, Isolate* isolate) {
Simulator * simulator = Simulator::current(isolate);
Simulator::CallArgument args[] = {
Simulator::CallArgument(x),
Simulator::CallArgument::End()
......@@ -28,19 +28,17 @@ double fast_exp_simulator(double x) {
#endif
UnaryMathFunction CreateExpFunction() {
if (!FLAG_fast_math) return &std::exp;
UnaryMathFunctionWithIsolate CreateExpFunction(Isolate* isolate) {
// Use the Math.exp implemetation in MathExpGenerator::EmitMathExp() to create
// an AAPCS64-compliant exp() function. This will be faster than the C
// library's exp() function, but probably less accurate.
size_t actual_size;
byte* buffer =
static_cast<byte*>(base::OS::Allocate(1 * KB, &actual_size, true));
if (buffer == NULL) return &std::exp;
if (buffer == nullptr) return nullptr;
ExternalReference::InitializeMathExpData();
MacroAssembler masm(NULL, buffer, static_cast<int>(actual_size));
MacroAssembler masm(nullptr, buffer, static_cast<int>(actual_size));
masm.SetStackPointer(csp);
// The argument will be in d0 on entry.
......@@ -64,11 +62,11 @@ UnaryMathFunction CreateExpFunction() {
masm.GetCode(&desc);
DCHECK(!RelocInfo::RequiresRelocation(desc));
Assembler::FlushICacheWithoutIsolate(buffer, actual_size);
Assembler::FlushICache(isolate, buffer, actual_size);
base::OS::ProtectCode(buffer, actual_size);
#if !defined(USE_SIMULATOR)
return FUNCTION_CAST<UnaryMathFunction>(buffer);
return FUNCTION_CAST<UnaryMathFunctionWithIsolate>(buffer);
#else
fast_exp_arm64_machine_code = buffer;
return &fast_exp_simulator;
......
......@@ -73,15 +73,32 @@ double fast_##name(double x) { \
return (*fast_##name##_function)(x); \
}
UNARY_MATH_FUNCTION(exp, CreateExpFunction())
UNARY_MATH_FUNCTION(sqrt, CreateSqrtFunction())
#undef UNARY_MATH_FUNCTION
static UnaryMathFunctionWithIsolate fast_exp_function = NULL;
void lazily_initialize_fast_exp() {
if (fast_exp_function == NULL) {
init_fast_exp_function();
double std_exp(double x, Isolate* isolate) {
return std::exp(x);
}
void init_fast_exp_function(Isolate* isolate) {
if (FLAG_fast_math) fast_exp_function = CreateExpFunction(isolate);
if (!fast_exp_function) fast_exp_function = std_exp;
}
double fast_exp(double x, Isolate* isolate) {
return (*fast_exp_function)(x, isolate);
}
void lazily_initialize_fast_exp(Isolate* isolate) {
if (fast_exp_function == nullptr) {
init_fast_exp_function(isolate);
}
}
......
......@@ -90,20 +90,21 @@ class CodeGenerator {
// from the one we use in our generated code. Therefore we use the same
// generated code both in runtime and compiled code.
typedef double (*UnaryMathFunction)(double x);
typedef double (*UnaryMathFunctionWithIsolate)(double x, Isolate* isolate);
UnaryMathFunction CreateExpFunction();
UnaryMathFunctionWithIsolate CreateExpFunction(Isolate* isolate);
UnaryMathFunction CreateSqrtFunction();
double modulo(double x, double y);
// Custom implementation of math functions.
double fast_exp(double input);
double fast_exp(double input, Isolate* isolate);
double fast_sqrt(double input);
#ifdef _WIN64
void init_modulo_function();
#endif
void lazily_initialize_fast_exp();
void lazily_initialize_fast_exp(Isolate* isolate);
void init_fast_sqrt_function();
......
......@@ -4080,7 +4080,8 @@ HInstruction* HUnaryMathOperation::New(Isolate* isolate, Zone* zone,
}
switch (op) {
case kMathExp:
return H_CONSTANT_DOUBLE(fast_exp(d));
lazily_initialize_fast_exp(isolate);
return H_CONSTANT_DOUBLE(fast_exp(d, isolate));
case kMathLog:
return H_CONSTANT_DOUBLE(std::log(d));
case kMathSqrt:
......
......@@ -34,15 +34,14 @@ void StubRuntimeCallHelper::AfterCall(MacroAssembler* masm) const {
#define __ masm.
UnaryMathFunction CreateExpFunction() {
if (!FLAG_fast_math) return &std::exp;
UnaryMathFunctionWithIsolate CreateExpFunction(Isolate* isolate) {
size_t actual_size;
byte* buffer =
static_cast<byte*>(base::OS::Allocate(1 * KB, &actual_size, true));
if (buffer == NULL) return &std::exp;
if (buffer == nullptr) return nullptr;
ExternalReference::InitializeMathExpData();
MacroAssembler masm(NULL, buffer, static_cast<int>(actual_size));
MacroAssembler masm(nullptr, buffer, static_cast<int>(actual_size));
// esp[1 * kPointerSize]: raw double input
// esp[0 * kPointerSize]: return address
{
......@@ -65,9 +64,9 @@ UnaryMathFunction CreateExpFunction() {
masm.GetCode(&desc);
DCHECK(!RelocInfo::RequiresRelocation(desc));
Assembler::FlushICacheWithoutIsolate(buffer, actual_size);
Assembler::FlushICache(isolate, buffer, actual_size);
base::OS::ProtectCode(buffer, actual_size);
return FUNCTION_CAST<UnaryMathFunction>(buffer);
return FUNCTION_CAST<UnaryMathFunctionWithIsolate>(buffer);
}
......
......@@ -18,23 +18,21 @@ namespace internal {
#if defined(USE_SIMULATOR)
byte* fast_exp_mips_machine_code = NULL;
double fast_exp_simulator(double x) {
return Simulator::current(Isolate::Current())->CallFP(
fast_exp_mips_machine_code, x, 0);
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
UnaryMathFunction CreateExpFunction() {
if (!FLAG_fast_math) return &std::exp;
UnaryMathFunctionWithIsolate CreateExpFunction(Isolate* isolate) {
size_t actual_size;
byte* buffer =
static_cast<byte*>(base::OS::Allocate(1 * KB, &actual_size, true));
if (buffer == NULL) return &std::exp;
if (buffer == nullptr) return nullptr;
ExternalReference::InitializeMathExpData();
MacroAssembler masm(NULL, buffer, static_cast<int>(actual_size));
MacroAssembler masm(nullptr, buffer, static_cast<int>(actual_size));
{
DoubleRegister input = f12;
......@@ -63,7 +61,7 @@ UnaryMathFunction CreateExpFunction() {
base::OS::ProtectCode(buffer, actual_size);
#if !defined(USE_SIMULATOR)
return FUNCTION_CAST<UnaryMathFunction>(buffer);
return FUNCTION_CAST<UnaryMathFunctionWithIsolate>(buffer);
#else
fast_exp_mips_machine_code = buffer;
return &fast_exp_simulator;
......
......@@ -18,23 +18,21 @@ namespace internal {
#if defined(USE_SIMULATOR)
byte* fast_exp_mips_machine_code = NULL;
double fast_exp_simulator(double x) {
return Simulator::current(Isolate::Current())->CallFP(
fast_exp_mips_machine_code, x, 0);
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
UnaryMathFunction CreateExpFunction() {
if (!FLAG_fast_math) return &std::exp;
UnaryMathFunctionWithIsolate CreateExpFunction(Isolate* isolate) {
size_t actual_size;
byte* buffer =
static_cast<byte*>(base::OS::Allocate(1 * KB, &actual_size, true));
if (buffer == NULL) return &std::exp;
if (buffer == nullptr) return nullptr;
ExternalReference::InitializeMathExpData();
MacroAssembler masm(NULL, buffer, static_cast<int>(actual_size));
MacroAssembler masm(nullptr, buffer, static_cast<int>(actual_size));
{
DoubleRegister input = f12;
......@@ -63,7 +61,7 @@ UnaryMathFunction CreateExpFunction() {
base::OS::ProtectCode(buffer, actual_size);
#if !defined(USE_SIMULATOR)
return FUNCTION_CAST<UnaryMathFunction>(buffer);
return FUNCTION_CAST<UnaryMathFunctionWithIsolate>(buffer);
#else
fast_exp_mips_machine_code = buffer;
return &fast_exp_simulator;
......
......@@ -18,23 +18,22 @@ namespace internal {
#if defined(USE_SIMULATOR)
byte* fast_exp_ppc_machine_code = NULL;
double fast_exp_simulator(double x) {
return Simulator::current(Isolate::Current())
byte* fast_exp_ppc_machine_code = nullptr;
double fast_exp_simulator(double x, Isolate* isolate) {
return Simulator::current(isolate)
->CallFPReturnsDouble(fast_exp_ppc_machine_code, x, 0);
}
#endif
UnaryMathFunction CreateExpFunction() {
if (!FLAG_fast_math) return &std::exp;
UnaryMathFunctionWithIsolate CreateExpFunction(Isolate* isolate) {
size_t actual_size;
byte* buffer =
static_cast<byte*>(base::OS::Allocate(1 * KB, &actual_size, true));
if (buffer == NULL) return &std::exp;
if (buffer == nullptr) return nullptr;
ExternalReference::InitializeMathExpData();
MacroAssembler masm(NULL, buffer, static_cast<int>(actual_size));
MacroAssembler masm(nullptr, buffer, static_cast<int>(actual_size));
{
DoubleRegister input = d1;
......@@ -62,11 +61,11 @@ UnaryMathFunction CreateExpFunction() {
DCHECK(!RelocInfo::RequiresRelocation(desc));
#endif
Assembler::FlushICacheWithoutIsolate(buffer, actual_size);
Assembler::FlushICache(isolate, buffer, actual_size);
base::OS::ProtectCode(buffer, actual_size);
#if !defined(USE_SIMULATOR)
return FUNCTION_CAST<UnaryMathFunction>(buffer);
return FUNCTION_CAST<UnaryMathFunctionWithIsolate>(buffer);
#else
fast_exp_ppc_machine_code = buffer;
return &fast_exp_simulator;
......
......@@ -107,8 +107,8 @@ RUNTIME_FUNCTION(Runtime_MathExpRT) {
isolate->counters()->math_exp()->Increment();
CONVERT_DOUBLE_ARG_CHECKED(x, 0);
lazily_initialize_fast_exp();
return *isolate->factory()->NewNumber(fast_exp(x));
lazily_initialize_fast_exp(isolate);
return *isolate->factory()->NewNumber(fast_exp(x, isolate));
}
......
......@@ -32,15 +32,14 @@ void StubRuntimeCallHelper::AfterCall(MacroAssembler* masm) const {
#define __ masm.
UnaryMathFunction CreateExpFunction() {
if (!FLAG_fast_math) return &std::exp;
UnaryMathFunctionWithIsolate CreateExpFunction(Isolate* isolate) {
size_t actual_size;
byte* buffer =
static_cast<byte*>(base::OS::Allocate(1 * KB, &actual_size, true));
if (buffer == NULL) return &std::exp;
if (buffer == nullptr) return nullptr;
ExternalReference::InitializeMathExpData();
MacroAssembler masm(NULL, buffer, static_cast<int>(actual_size));
MacroAssembler masm(nullptr, buffer, static_cast<int>(actual_size));
// xmm0: raw double input.
XMMRegister input = xmm0;
XMMRegister result = xmm1;
......@@ -58,9 +57,9 @@ UnaryMathFunction CreateExpFunction() {
masm.GetCode(&desc);
DCHECK(!RelocInfo::RequiresRelocation(desc));
Assembler::FlushICacheWithoutIsolate(buffer, actual_size);
Assembler::FlushICache(isolate, buffer, actual_size);
base::OS::ProtectCode(buffer, actual_size);
return FUNCTION_CAST<UnaryMathFunction>(buffer);
return FUNCTION_CAST<UnaryMathFunctionWithIsolate>(buffer);
}
......
......@@ -36,7 +36,7 @@ void StubRuntimeCallHelper::AfterCall(MacroAssembler* masm) const {
UnaryMathFunction CreateExpFunction() {
// No SSE2 support
return &std::exp;
return nullptr;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment