Remove premordial math functions from native context.

R=rossberg@chromium.org

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

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@24471 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent f4e40915
...@@ -5909,7 +5909,7 @@ class Internals { ...@@ -5909,7 +5909,7 @@ class Internals {
static const int kJSObjectHeaderSize = 3 * kApiPointerSize; static const int kJSObjectHeaderSize = 3 * kApiPointerSize;
static const int kFixedArrayHeaderSize = 2 * kApiPointerSize; static const int kFixedArrayHeaderSize = 2 * kApiPointerSize;
static const int kContextHeaderSize = 2 * kApiPointerSize; static const int kContextHeaderSize = 2 * kApiPointerSize;
static const int kContextEmbedderDataIndex = 95; static const int kContextEmbedderDataIndex = 76;
static const int kFullStringRepresentationMask = 0x07; static const int kFullStringRepresentationMask = 0x07;
static const int kStringEncodingMask = 0x4; static const int kStringEncodingMask = 0x4;
static const int kExternalTwoByteRepresentationTag = 0x02; static const int kExternalTwoByteRepresentationTag = 0x02;
......
...@@ -1505,12 +1505,6 @@ static Handle<JSObject> ResolveBuiltinIdHolder(Handle<Context> native_context, ...@@ -1505,12 +1505,6 @@ static Handle<JSObject> ResolveBuiltinIdHolder(Handle<Context> native_context,
.ToHandleChecked(); \ .ToHandleChecked(); \
native_context()->set_##var(Type::cast(*var##_native)); native_context()->set_##var(Type::cast(*var##_native));
#define INSTALL_NATIVE_MATH(name) \
{ \
Handle<Object> fun = \
ResolveBuiltinIdHolder(native_context(), "Math." #name); \
native_context()->set_math_##name##_fun(JSFunction::cast(*fun)); \
}
void Genesis::InstallNativeFunctions() { void Genesis::InstallNativeFunctions() {
HandleScope scope(isolate()); HandleScope scope(isolate());
...@@ -1557,26 +1551,6 @@ void Genesis::InstallNativeFunctions() { ...@@ -1557,26 +1551,6 @@ void Genesis::InstallNativeFunctions() {
INSTALL_NATIVE(Symbol, "symbolIterator", iterator_symbol); INSTALL_NATIVE(Symbol, "symbolIterator", iterator_symbol);
INSTALL_NATIVE(Symbol, "symbolUnscopables", unscopables_symbol); INSTALL_NATIVE(Symbol, "symbolUnscopables", unscopables_symbol);
INSTALL_NATIVE(JSFunction, "ArrayValues", array_values_iterator); INSTALL_NATIVE(JSFunction, "ArrayValues", array_values_iterator);
INSTALL_NATIVE_MATH(abs)
INSTALL_NATIVE_MATH(acos)
INSTALL_NATIVE_MATH(asin)
INSTALL_NATIVE_MATH(atan)
INSTALL_NATIVE_MATH(atan2)
INSTALL_NATIVE_MATH(ceil)
INSTALL_NATIVE_MATH(cos)
INSTALL_NATIVE_MATH(exp)
INSTALL_NATIVE_MATH(floor)
INSTALL_NATIVE_MATH(imul)
INSTALL_NATIVE_MATH(log)
INSTALL_NATIVE_MATH(max)
INSTALL_NATIVE_MATH(min)
INSTALL_NATIVE_MATH(pow)
INSTALL_NATIVE_MATH(random)
INSTALL_NATIVE_MATH(round)
INSTALL_NATIVE_MATH(sin)
INSTALL_NATIVE_MATH(sqrt)
INSTALL_NATIVE_MATH(tan)
} }
......
...@@ -824,62 +824,69 @@ MACHINE_OP_LIST(DEFINE_METHOD) ...@@ -824,62 +824,69 @@ MACHINE_OP_LIST(DEFINE_METHOD)
// Heap constants. // Heap constants.
Type* Typer::Visitor::TypeConstant(Handle<Object> value) { Type* Typer::Visitor::TypeConstant(Handle<Object> value) {
if (value->IsJSFunction() && JSFunction::cast(*value)->IsBuiltin() && if (value->IsJSFunction()) {
!context().is_null()) { if (JSFunction::cast(*value)->shared()->HasBuiltinFunctionId()) {
Handle<Context> native = switch (JSFunction::cast(*value)->shared()->builtin_function_id()) {
handle(context().ToHandleChecked()->native_context(), isolate()); // TODO(rossberg): can't express overloading
if (*value == native->math_abs_fun()) { case kMathAbs:
return typer_->number_fun1_; // TODO(rossberg): can't express overloading return typer_->number_fun1_;
} else if (*value == native->math_acos_fun()) { case kMathAcos:
return typer_->number_fun1_; return typer_->number_fun1_;
} else if (*value == native->math_asin_fun()) { case kMathAsin:
return typer_->number_fun1_; return typer_->number_fun1_;
} else if (*value == native->math_atan_fun()) { case kMathAtan:
return typer_->number_fun1_; return typer_->number_fun1_;
} else if (*value == native->math_atan2_fun()) { case kMathAtan2:
return typer_->number_fun2_; return typer_->number_fun2_;
} else if (*value == native->math_ceil_fun()) { case kMathCeil:
return typer_->weakint_fun1_; return typer_->weakint_fun1_;
} else if (*value == native->math_cos_fun()) { case kMathCos:
return typer_->number_fun1_; return typer_->number_fun1_;
} else if (*value == native->math_exp_fun()) { case kMathExp:
return typer_->number_fun1_; return typer_->number_fun1_;
} else if (*value == native->math_floor_fun()) { case kMathFloor:
return typer_->weakint_fun1_; return typer_->weakint_fun1_;
} else if (*value == native->math_imul_fun()) { case kMathImul:
return typer_->imul_fun_; return typer_->imul_fun_;
} else if (*value == native->math_log_fun()) { case kMathLog:
return typer_->number_fun1_; return typer_->number_fun1_;
} else if (*value == native->math_pow_fun()) { case kMathPow:
return typer_->number_fun2_; return typer_->number_fun2_;
} else if (*value == native->math_random_fun()) { case kMathRandom:
return typer_->random_fun_; return typer_->random_fun_;
} else if (*value == native->math_round_fun()) { case kMathRound:
return typer_->weakint_fun1_; return typer_->weakint_fun1_;
} else if (*value == native->math_sin_fun()) { case kMathSin:
return typer_->number_fun1_; return typer_->number_fun1_;
} else if (*value == native->math_sqrt_fun()) { case kMathSqrt:
return typer_->number_fun1_; return typer_->number_fun1_;
} else if (*value == native->math_tan_fun()) { case kMathTan:
return typer_->number_fun1_; return typer_->number_fun1_;
} else if (*value == native->array_buffer_fun()) { default:
return typer_->array_buffer_fun_; break;
} else if (*value == native->int8_array_fun()) { }
return typer_->int8_array_fun_; } else if (JSFunction::cast(*value)->IsBuiltin() && !context().is_null()) {
} else if (*value == native->int16_array_fun()) { Handle<Context> native =
return typer_->int16_array_fun_; handle(context().ToHandleChecked()->native_context(), isolate());
} else if (*value == native->int32_array_fun()) { if (*value == native->array_buffer_fun()) {
return typer_->int32_array_fun_; return typer_->array_buffer_fun_;
} else if (*value == native->uint8_array_fun()) { } else if (*value == native->int8_array_fun()) {
return typer_->uint8_array_fun_; return typer_->int8_array_fun_;
} else if (*value == native->uint16_array_fun()) { } else if (*value == native->int16_array_fun()) {
return typer_->uint16_array_fun_; return typer_->int16_array_fun_;
} else if (*value == native->uint32_array_fun()) { } else if (*value == native->int32_array_fun()) {
return typer_->uint32_array_fun_; return typer_->int32_array_fun_;
} else if (*value == native->float32_array_fun()) { } else if (*value == native->uint8_array_fun()) {
return typer_->float32_array_fun_; return typer_->uint8_array_fun_;
} else if (*value == native->float64_array_fun()) { } else if (*value == native->uint16_array_fun()) {
return typer_->float64_array_fun_; return typer_->uint16_array_fun_;
} else if (*value == native->uint32_array_fun()) {
return typer_->uint32_array_fun_;
} else if (*value == native->float32_array_fun()) {
return typer_->float32_array_fun_;
} else if (*value == native->float64_array_fun()) {
return typer_->float64_array_fun_;
}
} }
} }
return Type::Constant(value, zone()); return Type::Constant(value, zone());
......
...@@ -101,25 +101,6 @@ enum BindingFlags { ...@@ -101,25 +101,6 @@ enum BindingFlags {
V(GLOBAL_EVAL_FUN_INDEX, JSFunction, global_eval_fun) \ V(GLOBAL_EVAL_FUN_INDEX, JSFunction, global_eval_fun) \
V(INSTANTIATE_FUN_INDEX, JSFunction, instantiate_fun) \ V(INSTANTIATE_FUN_INDEX, JSFunction, instantiate_fun) \
V(CONFIGURE_INSTANCE_FUN_INDEX, JSFunction, configure_instance_fun) \ V(CONFIGURE_INSTANCE_FUN_INDEX, JSFunction, configure_instance_fun) \
V(MATH_ABS_FUN_INDEX, JSFunction, math_abs_fun) \
V(MATH_ACOS_FUN_INDEX, JSFunction, math_acos_fun) \
V(MATH_ASIN_FUN_INDEX, JSFunction, math_asin_fun) \
V(MATH_ATAN_FUN_INDEX, JSFunction, math_atan_fun) \
V(MATH_ATAN2_FUN_INDEX, JSFunction, math_atan2_fun) \
V(MATH_CEIL_FUN_INDEX, JSFunction, math_ceil_fun) \
V(MATH_COS_FUN_INDEX, JSFunction, math_cos_fun) \
V(MATH_EXP_FUN_INDEX, JSFunction, math_exp_fun) \
V(MATH_FLOOR_FUN_INDEX, JSFunction, math_floor_fun) \
V(MATH_IMUL_FUN_INDEX, JSFunction, math_imul_fun) \
V(MATH_LOG_FUN_INDEX, JSFunction, math_log_fun) \
V(MATH_MAX_FUN_INDEX, JSFunction, math_max_fun) \
V(MATH_MIN_FUN_INDEX, JSFunction, math_min_fun) \
V(MATH_POW_FUN_INDEX, JSFunction, math_pow_fun) \
V(MATH_RANDOM_FUN_INDEX, JSFunction, math_random_fun) \
V(MATH_ROUND_FUN_INDEX, JSFunction, math_round_fun) \
V(MATH_SIN_FUN_INDEX, JSFunction, math_sin_fun) \
V(MATH_SQRT_FUN_INDEX, JSFunction, math_sqrt_fun) \
V(MATH_TAN_FUN_INDEX, JSFunction, math_tan_fun) \
V(ARRAY_BUFFER_FUN_INDEX, JSFunction, array_buffer_fun) \ V(ARRAY_BUFFER_FUN_INDEX, JSFunction, array_buffer_fun) \
V(UINT8_ARRAY_FUN_INDEX, JSFunction, uint8_array_fun) \ V(UINT8_ARRAY_FUN_INDEX, JSFunction, uint8_array_fun) \
V(INT8_ARRAY_FUN_INDEX, JSFunction, int8_array_fun) \ V(INT8_ARRAY_FUN_INDEX, JSFunction, int8_array_fun) \
...@@ -312,25 +293,6 @@ class Context: public FixedArray { ...@@ -312,25 +293,6 @@ class Context: public FixedArray {
GLOBAL_EVAL_FUN_INDEX, GLOBAL_EVAL_FUN_INDEX,
INSTANTIATE_FUN_INDEX, INSTANTIATE_FUN_INDEX,
CONFIGURE_INSTANCE_FUN_INDEX, CONFIGURE_INSTANCE_FUN_INDEX,
MATH_ABS_FUN_INDEX,
MATH_ACOS_FUN_INDEX,
MATH_ASIN_FUN_INDEX,
MATH_ATAN_FUN_INDEX,
MATH_ATAN2_FUN_INDEX,
MATH_CEIL_FUN_INDEX,
MATH_COS_FUN_INDEX,
MATH_EXP_FUN_INDEX,
MATH_FLOOR_FUN_INDEX,
MATH_IMUL_FUN_INDEX,
MATH_LOG_FUN_INDEX,
MATH_MAX_FUN_INDEX,
MATH_MIN_FUN_INDEX,
MATH_POW_FUN_INDEX,
MATH_RANDOM_FUN_INDEX,
MATH_ROUND_FUN_INDEX,
MATH_SIN_FUN_INDEX,
MATH_SQRT_FUN_INDEX,
MATH_TAN_FUN_INDEX,
ARRAY_BUFFER_FUN_INDEX, ARRAY_BUFFER_FUN_INDEX,
UINT8_ARRAY_FUN_INDEX, UINT8_ARRAY_FUN_INDEX,
INT8_ARRAY_FUN_INDEX, INT8_ARRAY_FUN_INDEX,
......
...@@ -6548,6 +6548,7 @@ class Script: public Struct { ...@@ -6548,6 +6548,7 @@ class Script: public Struct {
V(String.prototype, charCodeAt, StringCharCodeAt) \ V(String.prototype, charCodeAt, StringCharCodeAt) \
V(String.prototype, charAt, StringCharAt) \ V(String.prototype, charAt, StringCharAt) \
V(String, fromCharCode, StringFromCharCode) \ V(String, fromCharCode, StringFromCharCode) \
V(Math, random, MathRandom) \
V(Math, floor, MathFloor) \ V(Math, floor, MathFloor) \
V(Math, round, MathRound) \ V(Math, round, MathRound) \
V(Math, ceil, MathCeil) \ V(Math, ceil, MathCeil) \
...@@ -6558,6 +6559,13 @@ class Script: public Struct { ...@@ -6558,6 +6559,13 @@ class Script: public Struct {
V(Math, pow, MathPow) \ V(Math, pow, MathPow) \
V(Math, max, MathMax) \ V(Math, max, MathMax) \
V(Math, min, MathMin) \ V(Math, min, MathMin) \
V(Math, cos, MathCos) \
V(Math, sin, MathSin) \
V(Math, tan, MathTan) \
V(Math, acos, MathAcos) \
V(Math, asin, MathAsin) \
V(Math, atan, MathAtan) \
V(Math, atan2, MathAtan2) \
V(Math, imul, MathImul) \ V(Math, imul, MathImul) \
V(Math, clz32, MathClz32) \ V(Math, clz32, MathClz32) \
V(Math, fround, MathFround) V(Math, fround, MathFround)
......
...@@ -35,6 +35,18 @@ class JSBuiltinReducerTest : public GraphTest { ...@@ -35,6 +35,18 @@ class JSBuiltinReducerTest : public GraphTest {
return n; return n;
} }
Handle<JSFunction> MathFunction(const char* name) {
Handle<Object> m =
JSObject::GetProperty(isolate()->global_object(),
isolate()->factory()->NewStringFromAsciiChecked(
"Math")).ToHandleChecked();
Handle<JSFunction> f = Handle<JSFunction>::cast(
JSObject::GetProperty(
m, isolate()->factory()->NewStringFromAsciiChecked(name))
.ToHandleChecked());
return f;
}
JSOperatorBuilder* javascript() { return &javascript_; } JSOperatorBuilder* javascript() { return &javascript_; }
private: private:
...@@ -60,7 +72,7 @@ Type* const kNumberTypes[] = { ...@@ -60,7 +72,7 @@ Type* const kNumberTypes[] = {
TEST_F(JSBuiltinReducerTest, MathAbs) { TEST_F(JSBuiltinReducerTest, MathAbs) {
Handle<JSFunction> f(isolate()->context()->math_abs_fun()); Handle<JSFunction> f = MathFunction("abs");
TRACED_FOREACH(Type*, t0, kNumberTypes) { TRACED_FOREACH(Type*, t0, kNumberTypes) {
Node* p0 = Parameter(t0, 0); Node* p0 = Parameter(t0, 0);
...@@ -94,7 +106,7 @@ TEST_F(JSBuiltinReducerTest, MathAbs) { ...@@ -94,7 +106,7 @@ TEST_F(JSBuiltinReducerTest, MathAbs) {
TEST_F(JSBuiltinReducerTest, MathSqrt) { TEST_F(JSBuiltinReducerTest, MathSqrt) {
Handle<JSFunction> f(isolate()->context()->math_sqrt_fun()); Handle<JSFunction> f = MathFunction("sqrt");
TRACED_FOREACH(Type*, t0, kNumberTypes) { TRACED_FOREACH(Type*, t0, kNumberTypes) {
Node* p0 = Parameter(t0, 0); Node* p0 = Parameter(t0, 0);
...@@ -115,7 +127,7 @@ TEST_F(JSBuiltinReducerTest, MathSqrt) { ...@@ -115,7 +127,7 @@ TEST_F(JSBuiltinReducerTest, MathSqrt) {
TEST_F(JSBuiltinReducerTest, MathMax0) { TEST_F(JSBuiltinReducerTest, MathMax0) {
Handle<JSFunction> f(isolate()->context()->math_max_fun()); Handle<JSFunction> f = MathFunction("max");
Node* fun = HeapConstant(Unique<HeapObject>::CreateUninitialized(f)); Node* fun = HeapConstant(Unique<HeapObject>::CreateUninitialized(f));
Node* call = Node* call =
...@@ -129,7 +141,7 @@ TEST_F(JSBuiltinReducerTest, MathMax0) { ...@@ -129,7 +141,7 @@ TEST_F(JSBuiltinReducerTest, MathMax0) {
TEST_F(JSBuiltinReducerTest, MathMax1) { TEST_F(JSBuiltinReducerTest, MathMax1) {
Handle<JSFunction> f(isolate()->context()->math_max_fun()); Handle<JSFunction> f = MathFunction("max");
TRACED_FOREACH(Type*, t0, kNumberTypes) { TRACED_FOREACH(Type*, t0, kNumberTypes) {
Node* p0 = Parameter(t0, 0); Node* p0 = Parameter(t0, 0);
...@@ -146,7 +158,7 @@ TEST_F(JSBuiltinReducerTest, MathMax1) { ...@@ -146,7 +158,7 @@ TEST_F(JSBuiltinReducerTest, MathMax1) {
TEST_F(JSBuiltinReducerTest, MathMax2) { TEST_F(JSBuiltinReducerTest, MathMax2) {
Handle<JSFunction> f(isolate()->context()->math_max_fun()); Handle<JSFunction> f = MathFunction("max");
TRACED_FOREACH(Type*, t0, kNumberTypes) { TRACED_FOREACH(Type*, t0, kNumberTypes) {
TRACED_FOREACH(Type*, t1, kNumberTypes) { TRACED_FOREACH(Type*, t1, kNumberTypes) {
...@@ -182,7 +194,7 @@ TEST_F(JSBuiltinReducerTest, MathMax2) { ...@@ -182,7 +194,7 @@ TEST_F(JSBuiltinReducerTest, MathMax2) {
TEST_F(JSBuiltinReducerTest, MathImul) { TEST_F(JSBuiltinReducerTest, MathImul) {
Handle<JSFunction> f(isolate()->context()->math_imul_fun()); Handle<JSFunction> f = MathFunction("imul");
TRACED_FOREACH(Type*, t0, kNumberTypes) { TRACED_FOREACH(Type*, t0, kNumberTypes) {
TRACED_FOREACH(Type*, t1, kNumberTypes) { TRACED_FOREACH(Type*, t1, kNumberTypes) {
...@@ -211,13 +223,7 @@ TEST_F(JSBuiltinReducerTest, MathImul) { ...@@ -211,13 +223,7 @@ TEST_F(JSBuiltinReducerTest, MathImul) {
TEST_F(JSBuiltinReducerTest, MathFround) { TEST_F(JSBuiltinReducerTest, MathFround) {
Handle<Object> m = Handle<JSFunction> f = MathFunction("fround");
JSObject::GetProperty(isolate()->global_object(),
isolate()->factory()->NewStringFromAsciiChecked(
"Math")).ToHandleChecked();
Handle<JSFunction> f = Handle<JSFunction>::cast(
JSObject::GetProperty(m, isolate()->factory()->NewStringFromAsciiChecked(
"fround")).ToHandleChecked());
TRACED_FOREACH(Type*, t0, kNumberTypes) { TRACED_FOREACH(Type*, t0, kNumberTypes) {
Node* p0 = Parameter(t0, 0); Node* p0 = Parameter(t0, 0);
......
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