Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1594)

Unified Diff: runtime/vm/intermediate_language_arm.cc

Issue 220723017: Add optimization for pow(base, 0.5) to the other architectures as well. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | runtime/vm/intermediate_language_mips.cc » ('j') | runtime/vm/intermediate_language_mips.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/intermediate_language_arm.cc
===================================================================
--- runtime/vm/intermediate_language_arm.cc (revision 34704)
+++ runtime/vm/intermediate_language_arm.cc (working copy)
@@ -4930,41 +4930,84 @@
void InvokeMathCFunctionInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
// For pow-function return NaN if exponent is NaN.
- Label do_call, skip_call;
+ Label skip_call;
if (recognized_kind() == MethodRecognizer::kMathDoublePow) {
// Pseudo code:
- // if (exponent == 0.0) return 0.0;
+ // if (exponent == 0.0) return 1.0;
// if (base == 1.0) return 1.0;
// if (base.isNaN || exponent.isNaN) {
// return double.NAN;
// }
+ // if (base != -Infinity && exponent == 0.5) {
+ // if (base == 0.0) return 0.0;
+ // return sqrt(value);
+ // }
DRegister base = EvenDRegisterOf(locs()->in(0).fpu_reg());
DRegister exp = EvenDRegisterOf(locs()->in(1).fpu_reg());
DRegister result = EvenDRegisterOf(locs()->out(0).fpu_reg());
Register temp = locs()->temp(0).reg();
DRegister saved_base = EvenDRegisterOf(locs()->temp(1).fpu_reg());
ASSERT((base == result) && (result != saved_base));
- Label check_base_is_one;
- // Check if exponent is 0.0 -> return 1.0;
+
+ Label do_call, check_base, return_nan;
__ vmovd(saved_base, base);
__ LoadObject(temp, Double::ZoneHandle(Double::NewCanonical(0)));
zra 2014/04/03 17:04:46 __ LoadDImmediate(DTMP, 0.0);
srdjan 2014/04/03 19:33:18 Done.
__ LoadDFromOffset(DTMP, temp, Double::value_offset() - kHeapObjectTag);
__ LoadObject(temp, Double::ZoneHandle(Double::NewCanonical(1)));
zra 2014/04/03 17:04:46 __ LoadDImmediate(result, 1.0);
srdjan 2014/04/03 19:33:18 Done.
__ LoadDFromOffset(result, temp, Double::value_offset() - kHeapObjectTag);
+ // exponent == 0.0 -> return 1.0;
__ vcmpd(exp, DTMP);
__ vmstat();
- __ b(&check_base_is_one, VS); // NaN -> not zero.
+ __ b(&check_base, VS); // NaN -> check base.
__ b(&skip_call, EQ); // exp is 0.0, result is 1.0.
- __ Bind(&check_base_is_one);
+ __ Bind(&check_base);
+ // Note: 'exp' could be NaN.
+ // base == 1.0 -> return 1.0;
__ vcmpd(saved_base, result);
__ vmstat();
- __ vmovd(result, saved_base, VS); // base is NaN, return NaN.
- __ b(&skip_call, VS);
- __ b(&skip_call, EQ); // base and result are 1.0.
+ __ b(&return_nan, VS);
+ __ b(&skip_call, EQ); // base is 1.0, result is 1.0.
+
+ __ vcmpd(saved_base, exp);
+ __ b(&do_call, VC); // // Neither 'exp' nor 'base' is NaN.
+
+ __ Bind(&return_nan);
+ __ LoadObject(temp, Double::ZoneHandle(Double::NewCanonical(NAN)));
zra 2014/04/03 17:04:46 __ LoadDImmediate(result, NAN);
srdjan 2014/04/03 19:33:18 Done.
+ __ LoadDFromOffset(result, temp, Double::value_offset() - kHeapObjectTag);
+ __ b(&skip_call);
+
+ Label do_pow, return_zero;
+ __ Bind(&do_call);
zra 2014/04/03 17:04:46 Maybe rename label since we're checking for 0.5 no
srdjan 2014/04/03 19:33:18 Renamed to try_sqrt
+
+ // Before calling check if we could use sqrt instead of pow.
zra 2014/04/03 17:04:46 Before calling,
srdjan 2014/04/03 19:33:18 Done.
+ __ LoadObject(temp, Double::ZoneHandle(Double::NewCanonical(-INFINITY)));
zra 2014/04/03 17:04:46 __ LoadDImmediate(result, -INFINITY);
srdjan 2014/04/03 19:33:18 Done.
+ __ LoadDFromOffset(result, temp, Double::value_offset() - kHeapObjectTag);
+ // base == -Infinity -> call pow;
+ __ vcmpd(saved_base, result);
+ __ b(&do_pow, EQ);
+
+ // exponent == 0.5 ?
+ __ LoadObject(temp, Double::ZoneHandle(Double::NewCanonical(0.5)));
zra 2014/04/03 17:04:46 __ LoadDImmediate(result, 0.5);
srdjan 2014/04/03 19:33:18 Done.
+ __ LoadDFromOffset(result, temp, Double::value_offset() - kHeapObjectTag);
+ __ vcmpd(exp, result);
+ __ b(&do_pow, NE);
+
+ // base == 0 -> return 0;
+ __ vcmpd(base, DTMP);
+ __ b(&return_zero, EQ);
+
+ __ vsqrtd(result, saved_base);
+ __ b(&skip_call);
+
+ __ Bind(&return_zero);
+ __ vmovd(result, DTMP);
+ __ b(&skip_call);
+
+ __ Bind(&do_pow);
__ vmovd(base, saved_base); // Restore base.
}
- __ Bind(&do_call);
+
if (InputCount() == 2) {
// Args must be in D0 and D1, so move arg from Q1(== D3:D2) to D1.
__ vmovd(D1, D2);
« no previous file with comments | « no previous file | runtime/vm/intermediate_language_mips.cc » ('j') | runtime/vm/intermediate_language_mips.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698