Revision: 10067
Author: [email protected]
Date: Fri Nov 25 05:15:31 2011
Log: Implement Math.tan in generated code.
Review URL: http://codereview.chromium.org/8700004
http://code.google.com/p/v8/source/detail?r=10067
Modified:
/branches/bleeding_edge/src/arm/code-stubs-arm.cc
/branches/bleeding_edge/src/arm/full-codegen-arm.cc
/branches/bleeding_edge/src/arm/lithium-codegen-arm.cc
/branches/bleeding_edge/src/arm/lithium-codegen-arm.h
/branches/bleeding_edge/src/assembler.cc
/branches/bleeding_edge/src/assembler.h
/branches/bleeding_edge/src/hydrogen.cc
/branches/bleeding_edge/src/ia32/assembler-ia32.cc
/branches/bleeding_edge/src/ia32/assembler-ia32.h
/branches/bleeding_edge/src/ia32/code-stubs-ia32.cc
/branches/bleeding_edge/src/ia32/full-codegen-ia32.cc
/branches/bleeding_edge/src/ia32/lithium-codegen-ia32.cc
/branches/bleeding_edge/src/ia32/lithium-codegen-ia32.h
/branches/bleeding_edge/src/math.js
/branches/bleeding_edge/src/runtime.h
/branches/bleeding_edge/src/x64/assembler-x64.cc
/branches/bleeding_edge/src/x64/assembler-x64.h
/branches/bleeding_edge/src/x64/code-stubs-x64.cc
/branches/bleeding_edge/src/x64/full-codegen-x64.cc
/branches/bleeding_edge/src/x64/lithium-codegen-x64.cc
/branches/bleeding_edge/src/x64/lithium-codegen-x64.h
=======================================
--- /branches/bleeding_edge/src/arm/code-stubs-arm.cc Thu Nov 24 10:36:24
2011
+++ /branches/bleeding_edge/src/arm/code-stubs-arm.cc Fri Nov 25 05:15:31
2011
@@ -3272,6 +3272,8 @@
__ cmp(r3, r5);
__ b(ne, &calculate);
// Cache hit. Load result, cleanup and return.
+ Counters* counters = masm->isolate()->counters();
+ __ IncrementCounter(counters->transcendental_cache_hit(), 1);
if (tagged) {
// Pop input value from stack and load result into r0.
__ pop();
@@ -3284,6 +3286,7 @@
} // if (CpuFeatures::IsSupported(VFP3))
__ bind(&calculate);
+ __ IncrementCounter(counters->transcendental_cache_miss(), 1);
if (tagged) {
__ bind(&invalid_cache);
ExternalReference runtime_function =
@@ -3370,6 +3373,10 @@
case TranscendentalCache::COS:
__
CallCFunction(ExternalReference::math_cos_double_function(isolate),
0, 1);
+ break;
+ case TranscendentalCache::TAN:
+ __
CallCFunction(ExternalReference::math_tan_double_function(isolate),
+ 0, 1);
break;
case TranscendentalCache::LOG:
__
CallCFunction(ExternalReference::math_log_double_function(isolate),
@@ -3388,6 +3395,7 @@
// Add more cases when necessary.
case TranscendentalCache::SIN: return Runtime::kMath_sin;
case TranscendentalCache::COS: return Runtime::kMath_cos;
+ case TranscendentalCache::TAN: return Runtime::kMath_tan;
case TranscendentalCache::LOG: return Runtime::kMath_log;
default:
UNIMPLEMENTED();
=======================================
--- /branches/bleeding_edge/src/arm/full-codegen-arm.cc Thu Nov 24 07:17:04
2011
+++ /branches/bleeding_edge/src/arm/full-codegen-arm.cc Fri Nov 25 05:15:31
2011
@@ -3129,6 +3129,18 @@
__ CallStub(&stub);
context()->Plug(r0);
}
+
+
+void FullCodeGenerator::EmitMathTan(CallRuntime* expr) {
+ // Load the argument on the stack and call the stub.
+ TranscendentalCacheStub stub(TranscendentalCache::TAN,
+ TranscendentalCacheStub::TAGGED);
+ ZoneList<Expression*>* args = expr->arguments();
+ ASSERT(args->length() == 1);
+ VisitForStackValue(args->at(0));
+ __ CallStub(&stub);
+ context()->Plug(r0);
+}
void FullCodeGenerator::EmitMathLog(CallRuntime* expr) {
=======================================
--- /branches/bleeding_edge/src/arm/lithium-codegen-arm.cc Thu Nov 24
07:17:04 2011
+++ /branches/bleeding_edge/src/arm/lithium-codegen-arm.cc Fri Nov 25
05:15:31 2011
@@ -3168,6 +3168,14 @@
TranscendentalCacheStub::UNTAGGED);
CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr);
}
+
+
+void LCodeGen::DoMathTan(LUnaryMathOperation* instr) {
+ ASSERT(ToDoubleRegister(instr->result()).is(d2));
+ TranscendentalCacheStub stub(TranscendentalCache::TAN,
+ TranscendentalCacheStub::UNTAGGED);
+ CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr);
+}
void LCodeGen::DoMathCos(LUnaryMathOperation* instr) {
@@ -3209,6 +3217,9 @@
case kMathSin:
DoMathSin(instr);
break;
+ case kMathTan:
+ DoMathTan(instr);
+ break;
case kMathLog:
DoMathLog(instr);
break;
=======================================
--- /branches/bleeding_edge/src/arm/lithium-codegen-arm.h Thu Nov 24
07:17:04 2011
+++ /branches/bleeding_edge/src/arm/lithium-codegen-arm.h Fri Nov 25
05:15:31 2011
@@ -242,6 +242,7 @@
void DoMathSqrt(LUnaryMathOperation* instr);
void DoMathPowHalf(LUnaryMathOperation* instr);
void DoMathLog(LUnaryMathOperation* instr);
+ void DoMathTan(LUnaryMathOperation* instr);
void DoMathCos(LUnaryMathOperation* instr);
void DoMathSin(LUnaryMathOperation* instr);
=======================================
--- /branches/bleeding_edge/src/assembler.cc Thu Oct 20 05:27:10 2011
+++ /branches/bleeding_edge/src/assembler.cc Fri Nov 25 05:15:31 2011
@@ -1049,6 +1049,11 @@
static double math_cos_double(double x) {
return cos(x);
}
+
+
+static double math_tan_double(double x) {
+ return tan(x);
+}
static double math_log_double(double x) {
@@ -1070,6 +1075,14 @@
FUNCTION_ADDR(math_cos_double),
BUILTIN_FP_CALL));
}
+
+
+ExternalReference ExternalReference::math_tan_double_function(
+ Isolate* isolate) {
+ return ExternalReference(Redirect(isolate,
+ FUNCTION_ADDR(math_tan_double),
+ BUILTIN_FP_CALL));
+}
ExternalReference ExternalReference::math_log_double_function(
=======================================
--- /branches/bleeding_edge/src/assembler.h Fri Oct 21 03:37:56 2011
+++ /branches/bleeding_edge/src/assembler.h Fri Nov 25 05:15:31 2011
@@ -652,6 +652,7 @@
static ExternalReference math_sin_double_function(Isolate* isolate);
static ExternalReference math_cos_double_function(Isolate* isolate);
+ static ExternalReference math_tan_double_function(Isolate* isolate);
static ExternalReference math_log_double_function(Isolate* isolate);
Address address() const {return reinterpret_cast<Address>(address_);}
=======================================
--- /branches/bleeding_edge/src/hydrogen.cc Fri Nov 25 01:36:31 2011
+++ /branches/bleeding_edge/src/hydrogen.cc Fri Nov 25 05:15:31 2011
@@ -6647,6 +6647,18 @@
Drop(1);
return ast_context()->ReturnInstruction(result, call->id());
}
+
+
+void HGraphBuilder::GenerateMathTan(CallRuntime* call) {
+ ASSERT_EQ(1, call->arguments()->length());
+ CHECK_ALIVE(VisitArgumentList(call->arguments()));
+ HValue* context = environment()->LookupContext();
+ HCallStub* result =
+ new(zone()) HCallStub(context, CodeStub::TranscendentalCache, 1);
+ result->set_transcendental_type(TranscendentalCache::TAN);
+ Drop(1);
+ return ast_context()->ReturnInstruction(result, call->id());
+}
void HGraphBuilder::GenerateMathLog(CallRuntime* call) {
=======================================
--- /branches/bleeding_edge/src/ia32/assembler-ia32.cc Wed Nov 2 01:32:40
2011
+++ /branches/bleeding_edge/src/ia32/assembler-ia32.cc Fri Nov 25 05:15:31
2011
@@ -1624,6 +1624,13 @@
EMIT(0xD9);
EMIT(0xFE);
}
+
+
+void Assembler::fptan() {
+ EnsureSpace ensure_space(this);
+ EMIT(0xD9);
+ EMIT(0xF2);
+}
void Assembler::fyl2x() {
=======================================
--- /branches/bleeding_edge/src/ia32/assembler-ia32.h Wed Nov 2 01:32:40
2011
+++ /branches/bleeding_edge/src/ia32/assembler-ia32.h Fri Nov 25 05:15:31
2011
@@ -924,6 +924,7 @@
void fchs();
void fcos();
void fsin();
+ void fptan();
void fyl2x();
void fadd(int i);
=======================================
--- /branches/bleeding_edge/src/ia32/code-stubs-ia32.cc Thu Nov 24 10:36:24
2011
+++ /branches/bleeding_edge/src/ia32/code-stubs-ia32.cc Fri Nov 25 05:15:31
2011
@@ -2485,6 +2485,8 @@
__ cmp(edx, Operand(ecx, kIntSize));
__ j(not_equal, &cache_miss, Label::kNear);
// Cache hit!
+ Counters* counters = masm->isolate()->counters();
+ __ IncrementCounter(counters->transcendental_cache_hit(), 1);
__ mov(eax, Operand(ecx, 2 * kIntSize));
if (tagged) {
__ fstp(0);
@@ -2495,6 +2497,7 @@
}
__ bind(&cache_miss);
+ __ IncrementCounter(counters->transcendental_cache_miss(), 1);
// Update cache with new value.
// We are short on registers, so use no_reg as scratch.
// This gives slightly larger code.
@@ -2566,6 +2569,7 @@
switch (type_) {
case TranscendentalCache::SIN: return Runtime::kMath_sin;
case TranscendentalCache::COS: return Runtime::kMath_cos;
+ case TranscendentalCache::TAN: return Runtime::kMath_tan;
case TranscendentalCache::LOG: return Runtime::kMath_log;
default:
UNIMPLEMENTED();
@@ -2579,7 +2583,9 @@
// Input value is on FP stack, and also in ebx/edx.
// Input value is possibly in xmm1.
// Address of result (a newly allocated HeapNumber) may be in eax.
- if (type_ == TranscendentalCache::SIN || type_ ==
TranscendentalCache::COS) {
+ if (type_ == TranscendentalCache::SIN ||
+ type_ == TranscendentalCache::COS ||
+ type_ == TranscendentalCache::TAN) {
// Both fsin and fcos require arguments in the range +/-2^63 and
// return NaN for infinities and NaN. They can share all code except
// the actual fsin/fcos operation.
@@ -2650,6 +2656,12 @@
case TranscendentalCache::COS:
__ fcos();
break;
+ case TranscendentalCache::TAN:
+ // FPTAN calculates tangent onto st(0) and pushes 1.0 onto the
+ // FP register stack.
+ __ fptan();
+ __ fstp(0); // Pop FP register stack.
+ break;
default:
UNREACHABLE();
}
=======================================
--- /branches/bleeding_edge/src/ia32/full-codegen-ia32.cc Thu Nov 24
07:17:04 2011
+++ /branches/bleeding_edge/src/ia32/full-codegen-ia32.cc Fri Nov 25
05:15:31 2011
@@ -3080,6 +3080,18 @@
__ CallStub(&stub);
context()->Plug(eax);
}
+
+
+void FullCodeGenerator::EmitMathTan(CallRuntime* expr) {
+ // Load the argument on the stack and call the stub.
+ TranscendentalCacheStub stub(TranscendentalCache::TAN,
+ TranscendentalCacheStub::TAGGED);
+ ZoneList<Expression*>* args = expr->arguments();
+ ASSERT(args->length() == 1);
+ VisitForStackValue(args->at(0));
+ __ CallStub(&stub);
+ context()->Plug(eax);
+}
void FullCodeGenerator::EmitMathLog(CallRuntime* expr) {
=======================================
--- /branches/bleeding_edge/src/ia32/lithium-codegen-ia32.cc Thu Nov 24
07:17:04 2011
+++ /branches/bleeding_edge/src/ia32/lithium-codegen-ia32.cc Fri Nov 25
05:15:31 2011
@@ -3032,6 +3032,14 @@
__ add(Operand(esp), Immediate(kDoubleSize));
__ bind(&done);
}
+
+
+void LCodeGen::DoMathTan(LUnaryMathOperation* instr) {
+ ASSERT(ToDoubleRegister(instr->result()).is(xmm1));
+ TranscendentalCacheStub stub(TranscendentalCache::TAN,
+ TranscendentalCacheStub::UNTAGGED);
+ CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr);
+}
void LCodeGen::DoMathCos(LUnaryMathOperation* instr) {
@@ -3073,6 +3081,9 @@
case kMathSin:
DoMathSin(instr);
break;
+ case kMathTan:
+ DoMathTan(instr);
+ break;
case kMathLog:
DoMathLog(instr);
break;
=======================================
--- /branches/bleeding_edge/src/ia32/lithium-codegen-ia32.h Thu Nov 24
07:17:04 2011
+++ /branches/bleeding_edge/src/ia32/lithium-codegen-ia32.h Fri Nov 25
05:15:31 2011
@@ -241,6 +241,7 @@
void DoMathSqrt(LUnaryMathOperation* instr);
void DoMathPowHalf(LUnaryMathOperation* instr);
void DoMathLog(LUnaryMathOperation* instr);
+ void DoMathTan(LUnaryMathOperation* instr);
void DoMathCos(LUnaryMathOperation* instr);
void DoMathSin(LUnaryMathOperation* instr);
=======================================
--- /branches/bleeding_edge/src/math.js Tue Nov 15 01:44:57 2011
+++ /branches/bleeding_edge/src/math.js Fri Nov 25 05:15:31 2011
@@ -189,7 +189,7 @@
// ECMA 262 - 15.8.2.18
function MathTan(x) {
if (!IS_NUMBER(x)) x = NonNumberToNumber(x);
- return %Math_tan(x);
+ return %_MathTan(x);
}
=======================================
--- /branches/bleeding_edge/src/runtime.h Thu Nov 24 07:17:04 2011
+++ /branches/bleeding_edge/src/runtime.h Fri Nov 25 05:15:31 2011
@@ -505,6 +505,7 @@
F(MathPow, 2,
1) \
F(MathSin, 1,
1) \
F(MathCos, 1,
1) \
+ F(MathTan, 1,
1) \
F(MathSqrt, 1,
1) \
F(MathLog, 1,
1) \
F(IsRegExpEquivalent, 2,
1) \
=======================================
--- /branches/bleeding_edge/src/x64/assembler-x64.cc Mon Sep 19 11:36:47
2011
+++ /branches/bleeding_edge/src/x64/assembler-x64.cc Fri Nov 25 05:15:31
2011
@@ -2297,6 +2297,13 @@
emit(0xD9);
emit(0xFE);
}
+
+
+void Assembler::fptan() {
+ EnsureSpace ensure_space(this);
+ emit(0xD9);
+ emit(0xF2);
+}
void Assembler::fyl2x() {
=======================================
--- /branches/bleeding_edge/src/x64/assembler-x64.h Fri Nov 11 05:48:14 2011
+++ /branches/bleeding_edge/src/x64/assembler-x64.h Fri Nov 25 05:15:31 2011
@@ -1275,6 +1275,7 @@
void fsin();
void fcos();
+ void fptan();
void fyl2x();
void frndint();
=======================================
--- /branches/bleeding_edge/src/x64/code-stubs-x64.cc Thu Nov 24 10:36:24
2011
+++ /branches/bleeding_edge/src/x64/code-stubs-x64.cc Fri Nov 25 05:15:31
2011
@@ -1607,6 +1607,8 @@
__ cmpq(rbx, Operand(rcx, 0));
__ j(not_equal, &cache_miss, Label::kNear);
// Cache hit!
+ Counters* counters = masm->isolate()->counters();
+ __ IncrementCounter(counters->transcendental_cache_hit(), 1);
__ movq(rax, Operand(rcx, 2 * kIntSize));
if (tagged) {
__ fstp(0); // Clear FPU stack.
@@ -1617,6 +1619,7 @@
}
__ bind(&cache_miss);
+ __ IncrementCounter(counters->transcendental_cache_miss(), 1);
// Update cache with new value.
if (tagged) {
__ AllocateHeapNumber(rax, rdi, &runtime_call_clear_stack);
@@ -1683,6 +1686,7 @@
// Add more cases when necessary.
case TranscendentalCache::SIN: return Runtime::kMath_sin;
case TranscendentalCache::COS: return Runtime::kMath_cos;
+ case TranscendentalCache::TAN: return Runtime::kMath_tan;
case TranscendentalCache::LOG: return Runtime::kMath_log;
default:
UNIMPLEMENTED();
@@ -1698,7 +1702,9 @@
// rcx: Pointer to cache entry. Must be preserved.
// st(0): Input double
Label done;
- if (type_ == TranscendentalCache::SIN || type_ ==
TranscendentalCache::COS) {
+ if (type_ == TranscendentalCache::SIN ||
+ type_ == TranscendentalCache::COS ||
+ type_ == TranscendentalCache::TAN) {
// Both fsin and fcos require arguments in the range +/-2^63 and
// return NaN for infinities and NaN. They can share all code except
// the actual fsin/fcos operation.
@@ -1768,6 +1774,12 @@
case TranscendentalCache::COS:
__ fcos();
break;
+ case TranscendentalCache::TAN:
+ // FPTAN calculates tangent onto st(0) and pushes 1.0 onto the
+ // FP register stack.
+ __ fptan();
+ __ fstp(0); // Pop FP register stack.
+ break;
default:
UNREACHABLE();
}
=======================================
--- /branches/bleeding_edge/src/x64/full-codegen-x64.cc Thu Nov 24 07:17:04
2011
+++ /branches/bleeding_edge/src/x64/full-codegen-x64.cc Fri Nov 25 05:15:31
2011
@@ -3013,6 +3013,18 @@
__ CallStub(&stub);
context()->Plug(rax);
}
+
+
+void FullCodeGenerator::EmitMathTan(CallRuntime* expr) {
+ // Load the argument on the stack and call the stub.
+ TranscendentalCacheStub stub(TranscendentalCache::TAN,
+ TranscendentalCacheStub::TAGGED);
+ ZoneList<Expression*>* args = expr->arguments();
+ ASSERT(args->length() == 1);
+ VisitForStackValue(args->at(0));
+ __ CallStub(&stub);
+ context()->Plug(rax);
+}
void FullCodeGenerator::EmitMathLog(CallRuntime* expr) {
=======================================
--- /branches/bleeding_edge/src/x64/lithium-codegen-x64.cc Thu Nov 24
07:17:04 2011
+++ /branches/bleeding_edge/src/x64/lithium-codegen-x64.cc Fri Nov 25
05:15:31 2011
@@ -2917,6 +2917,14 @@
TranscendentalCacheStub::UNTAGGED);
CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr);
}
+
+
+void LCodeGen::DoMathTan(LUnaryMathOperation* instr) {
+ ASSERT(ToDoubleRegister(instr->result()).is(xmm1));
+ TranscendentalCacheStub stub(TranscendentalCache::TAN,
+ TranscendentalCacheStub::UNTAGGED);
+ CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr);
+}
void LCodeGen::DoMathCos(LUnaryMathOperation* instr) {
@@ -2958,6 +2966,9 @@
case kMathSin:
DoMathSin(instr);
break;
+ case kMathTan:
+ DoMathTan(instr);
+ break;
case kMathLog:
DoMathLog(instr);
break;
=======================================
--- /branches/bleeding_edge/src/x64/lithium-codegen-x64.h Thu Nov 24
07:17:04 2011
+++ /branches/bleeding_edge/src/x64/lithium-codegen-x64.h Fri Nov 25
05:15:31 2011
@@ -231,6 +231,7 @@
void DoMathSqrt(LUnaryMathOperation* instr);
void DoMathPowHalf(LUnaryMathOperation* instr);
void DoMathLog(LUnaryMathOperation* instr);
+ void DoMathTan(LUnaryMathOperation* instr);
void DoMathCos(LUnaryMathOperation* instr);
void DoMathSin(LUnaryMathOperation* instr);
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev