From d117e9d9257f55b9d4b87744d72e13c6c2315f84 Mon Sep 17 00:00:00 2001 From: "yangguo@chromium.org" Date: Wed, 30 Nov 2011 16:47:54 +0000 Subject: [PATCH] MIPS: Implement Math.tan in generated code. Port r10067 (593c1ea) and r10069 (87a06dc). BUG= TEST= Review URL: http://codereview.chromium.org/8743009 Patch from Daniel Kalmar . git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@10098 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/mips/code-stubs-mips.cc | 18 +++++++++++++++--- src/mips/full-codegen-mips.cc | 13 +++++++++++++ src/mips/lithium-codegen-mips.cc | 11 +++++++++++ src/mips/lithium-codegen-mips.h | 1 + 4 files changed, 40 insertions(+), 3 deletions(-) diff --git a/src/mips/code-stubs-mips.cc b/src/mips/code-stubs-mips.cc index 679b23fffa..e7dda3faee 100644 --- a/src/mips/code-stubs-mips.cc +++ b/src/mips/code-stubs-mips.cc @@ -3360,6 +3360,9 @@ void TranscendentalCacheStub::Generate(MacroAssembler* masm) { __ Branch(&calculate, ne, a2, Operand(t0)); __ Branch(&calculate, ne, a3, Operand(t1)); // Cache hit. Load result, cleanup and return. + Counters* counters = masm->isolate()->counters(); + __ IncrementCounter( + counters->transcendental_cache_hit(), 1, scratch0, scratch1); if (tagged) { // Pop input value from stack and load result into v0. __ Drop(1); @@ -3372,6 +3375,9 @@ void TranscendentalCacheStub::Generate(MacroAssembler* masm) { } // if (CpuFeatures::IsSupported(FPU)) __ bind(&calculate); + Counters* counters = masm->isolate()->counters(); + __ IncrementCounter( + counters->transcendental_cache_miss(), 1, scratch0, scratch1); if (tagged) { __ bind(&invalid_cache); __ TailCallExternalReference(ExternalReference(RuntimeFunction(), @@ -3455,20 +3461,25 @@ void TranscendentalCacheStub::GenerateCallCFunction(MacroAssembler* masm, __ mov_d(f12, f4); } AllowExternalCallThatCantCauseGC scope(masm); + Isolate* isolate = masm->isolate(); switch (type_) { case TranscendentalCache::SIN: __ CallCFunction( - ExternalReference::math_sin_double_function(masm->isolate()), + ExternalReference::math_sin_double_function(isolate), 0, 1); break; case TranscendentalCache::COS: __ CallCFunction( - ExternalReference::math_cos_double_function(masm->isolate()), + 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(masm->isolate()), + ExternalReference::math_log_double_function(isolate), 0, 1); break; default: @@ -3484,6 +3495,7 @@ Runtime::FunctionId TranscendentalCacheStub::RuntimeFunction() { // 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(); diff --git a/src/mips/full-codegen-mips.cc b/src/mips/full-codegen-mips.cc index 4318b7a428..201e6b8e1c 100644 --- a/src/mips/full-codegen-mips.cc +++ b/src/mips/full-codegen-mips.cc @@ -3201,6 +3201,19 @@ void FullCodeGenerator::EmitMathCos(CallRuntime* expr) { } +void FullCodeGenerator::EmitMathTan(CallRuntime* expr) { + // Load the argument on the stack and call the stub. + TranscendentalCacheStub stub(TranscendentalCache::TAN, + TranscendentalCacheStub::TAGGED); + ZoneList* args = expr->arguments(); + ASSERT(args->length() == 1); + VisitForStackValue(args->at(0)); + __ mov(a0, result_register()); // Stub requires parameter in a0 and on tos. + __ CallStub(&stub); + context()->Plug(v0); +} + + void FullCodeGenerator::EmitMathLog(CallRuntime* expr) { // Load the argument on the stack and call the stub. TranscendentalCacheStub stub(TranscendentalCache::LOG, diff --git a/src/mips/lithium-codegen-mips.cc b/src/mips/lithium-codegen-mips.cc index e790798f77..c0879bbd91 100644 --- a/src/mips/lithium-codegen-mips.cc +++ b/src/mips/lithium-codegen-mips.cc @@ -3070,6 +3070,14 @@ void LCodeGen::DoMathLog(LUnaryMathOperation* instr) { } +void LCodeGen::DoMathTan(LUnaryMathOperation* instr) { + ASSERT(ToDoubleRegister(instr->result()).is(f4)); + TranscendentalCacheStub stub(TranscendentalCache::TAN, + TranscendentalCacheStub::UNTAGGED); + CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); +} + + void LCodeGen::DoMathCos(LUnaryMathOperation* instr) { ASSERT(ToDoubleRegister(instr->result()).is(f4)); TranscendentalCacheStub stub(TranscendentalCache::COS, @@ -3109,6 +3117,9 @@ void LCodeGen::DoUnaryMathOperation(LUnaryMathOperation* instr) { case kMathSin: DoMathSin(instr); break; + case kMathTan: + DoMathTan(instr); + break; case kMathLog: DoMathLog(instr); break; diff --git a/src/mips/lithium-codegen-mips.h b/src/mips/lithium-codegen-mips.h index ad11e3a5c6..c67b46be7e 100644 --- a/src/mips/lithium-codegen-mips.h +++ b/src/mips/lithium-codegen-mips.h @@ -242,6 +242,7 @@ class LCodeGen BASE_EMBEDDED { void DoMathSqrt(LUnaryMathOperation* instr); void DoMathPowHalf(LUnaryMathOperation* instr); void DoMathLog(LUnaryMathOperation* instr); + void DoMathTan(LUnaryMathOperation* instr); void DoMathCos(LUnaryMathOperation* instr); void DoMathSin(LUnaryMathOperation* instr);