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 {
static const int kJSObjectHeaderSize = 3 * kApiPointerSize;
static const int kFixedArrayHeaderSize = 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 kStringEncodingMask = 0x4;
static const int kExternalTwoByteRepresentationTag = 0x02;
......
......@@ -1505,12 +1505,6 @@ static Handle<JSObject> ResolveBuiltinIdHolder(Handle<Context> native_context,
.ToHandleChecked(); \
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() {
HandleScope scope(isolate());
......@@ -1557,26 +1551,6 @@ void Genesis::InstallNativeFunctions() {
INSTALL_NATIVE(Symbol, "symbolIterator", iterator_symbol);
INSTALL_NATIVE(Symbol, "symbolUnscopables", unscopables_symbol);
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)
// Heap constants.
Type* Typer::Visitor::TypeConstant(Handle<Object> value) {
if (value->IsJSFunction() && JSFunction::cast(*value)->IsBuiltin() &&
!context().is_null()) {
Handle<Context> native =
handle(context().ToHandleChecked()->native_context(), isolate());
if (*value == native->math_abs_fun()) {
return typer_->number_fun1_; // TODO(rossberg): can't express overloading
} else if (*value == native->math_acos_fun()) {
return typer_->number_fun1_;
} else if (*value == native->math_asin_fun()) {
return typer_->number_fun1_;
} else if (*value == native->math_atan_fun()) {
return typer_->number_fun1_;
} else if (*value == native->math_atan2_fun()) {
return typer_->number_fun2_;
} else if (*value == native->math_ceil_fun()) {
return typer_->weakint_fun1_;
} else if (*value == native->math_cos_fun()) {
return typer_->number_fun1_;
} else if (*value == native->math_exp_fun()) {
return typer_->number_fun1_;
} else if (*value == native->math_floor_fun()) {
return typer_->weakint_fun1_;
} else if (*value == native->math_imul_fun()) {
return typer_->imul_fun_;
} else if (*value == native->math_log_fun()) {
return typer_->number_fun1_;
} else if (*value == native->math_pow_fun()) {
return typer_->number_fun2_;
} else if (*value == native->math_random_fun()) {
return typer_->random_fun_;
} else if (*value == native->math_round_fun()) {
return typer_->weakint_fun1_;
} else if (*value == native->math_sin_fun()) {
return typer_->number_fun1_;
} else if (*value == native->math_sqrt_fun()) {
return typer_->number_fun1_;
} else if (*value == native->math_tan_fun()) {
return typer_->number_fun1_;
} else if (*value == native->array_buffer_fun()) {
return typer_->array_buffer_fun_;
} else if (*value == native->int8_array_fun()) {
return typer_->int8_array_fun_;
} else if (*value == native->int16_array_fun()) {
return typer_->int16_array_fun_;
} else if (*value == native->int32_array_fun()) {
return typer_->int32_array_fun_;
} else if (*value == native->uint8_array_fun()) {
return typer_->uint8_array_fun_;
} else if (*value == native->uint16_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_;
if (value->IsJSFunction()) {
if (JSFunction::cast(*value)->shared()->HasBuiltinFunctionId()) {
switch (JSFunction::cast(*value)->shared()->builtin_function_id()) {
// TODO(rossberg): can't express overloading
case kMathAbs:
return typer_->number_fun1_;
case kMathAcos:
return typer_->number_fun1_;
case kMathAsin:
return typer_->number_fun1_;
case kMathAtan:
return typer_->number_fun1_;
case kMathAtan2:
return typer_->number_fun2_;
case kMathCeil:
return typer_->weakint_fun1_;
case kMathCos:
return typer_->number_fun1_;
case kMathExp:
return typer_->number_fun1_;
case kMathFloor:
return typer_->weakint_fun1_;
case kMathImul:
return typer_->imul_fun_;
case kMathLog:
return typer_->number_fun1_;
case kMathPow:
return typer_->number_fun2_;
case kMathRandom:
return typer_->random_fun_;
case kMathRound:
return typer_->weakint_fun1_;
case kMathSin:
return typer_->number_fun1_;
case kMathSqrt:
return typer_->number_fun1_;
case kMathTan:
return typer_->number_fun1_;
default:
break;
}
} else if (JSFunction::cast(*value)->IsBuiltin() && !context().is_null()) {
Handle<Context> native =
handle(context().ToHandleChecked()->native_context(), isolate());
if (*value == native->array_buffer_fun()) {
return typer_->array_buffer_fun_;
} else if (*value == native->int8_array_fun()) {
return typer_->int8_array_fun_;
} else if (*value == native->int16_array_fun()) {
return typer_->int16_array_fun_;
} else if (*value == native->int32_array_fun()) {
return typer_->int32_array_fun_;
} else if (*value == native->uint8_array_fun()) {
return typer_->uint8_array_fun_;
} else if (*value == native->uint16_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());
......
......@@ -101,25 +101,6 @@ enum BindingFlags {
V(GLOBAL_EVAL_FUN_INDEX, JSFunction, global_eval_fun) \
V(INSTANTIATE_FUN_INDEX, JSFunction, instantiate_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(UINT8_ARRAY_FUN_INDEX, JSFunction, uint8_array_fun) \
V(INT8_ARRAY_FUN_INDEX, JSFunction, int8_array_fun) \
......@@ -312,25 +293,6 @@ class Context: public FixedArray {
GLOBAL_EVAL_FUN_INDEX,
INSTANTIATE_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,
UINT8_ARRAY_FUN_INDEX,
INT8_ARRAY_FUN_INDEX,
......
......@@ -6548,6 +6548,7 @@ class Script: public Struct {
V(String.prototype, charCodeAt, StringCharCodeAt) \
V(String.prototype, charAt, StringCharAt) \
V(String, fromCharCode, StringFromCharCode) \
V(Math, random, MathRandom) \
V(Math, floor, MathFloor) \
V(Math, round, MathRound) \
V(Math, ceil, MathCeil) \
......@@ -6558,6 +6559,13 @@ class Script: public Struct {
V(Math, pow, MathPow) \
V(Math, max, MathMax) \
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, clz32, MathClz32) \
V(Math, fround, MathFround)
......
......@@ -35,6 +35,18 @@ class JSBuiltinReducerTest : public GraphTest {
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_; }
private:
......@@ -60,7 +72,7 @@ Type* const kNumberTypes[] = {
TEST_F(JSBuiltinReducerTest, MathAbs) {
Handle<JSFunction> f(isolate()->context()->math_abs_fun());
Handle<JSFunction> f = MathFunction("abs");
TRACED_FOREACH(Type*, t0, kNumberTypes) {
Node* p0 = Parameter(t0, 0);
......@@ -94,7 +106,7 @@ TEST_F(JSBuiltinReducerTest, MathAbs) {
TEST_F(JSBuiltinReducerTest, MathSqrt) {
Handle<JSFunction> f(isolate()->context()->math_sqrt_fun());
Handle<JSFunction> f = MathFunction("sqrt");
TRACED_FOREACH(Type*, t0, kNumberTypes) {
Node* p0 = Parameter(t0, 0);
......@@ -115,7 +127,7 @@ TEST_F(JSBuiltinReducerTest, MathSqrt) {
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* call =
......@@ -129,7 +141,7 @@ TEST_F(JSBuiltinReducerTest, MathMax0) {
TEST_F(JSBuiltinReducerTest, MathMax1) {
Handle<JSFunction> f(isolate()->context()->math_max_fun());
Handle<JSFunction> f = MathFunction("max");
TRACED_FOREACH(Type*, t0, kNumberTypes) {
Node* p0 = Parameter(t0, 0);
......@@ -146,7 +158,7 @@ TEST_F(JSBuiltinReducerTest, MathMax1) {
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*, t1, kNumberTypes) {
......@@ -182,7 +194,7 @@ TEST_F(JSBuiltinReducerTest, MathMax2) {
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*, t1, kNumberTypes) {
......@@ -211,13 +223,7 @@ TEST_F(JSBuiltinReducerTest, MathImul) {
TEST_F(JSBuiltinReducerTest, MathFround) {
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(
"fround")).ToHandleChecked());
Handle<JSFunction> f = MathFunction("fround");
TRACED_FOREACH(Type*, t0, kNumberTypes) {
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