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

Unified Diff: runtime/vm/intermediate_language_x64.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
Index: runtime/vm/intermediate_language_x64.cc
===================================================================
--- runtime/vm/intermediate_language_x64.cc (revision 34704)
+++ runtime/vm/intermediate_language_x64.cc (working copy)
@@ -4668,53 +4668,82 @@
if (InputCount() == 2) {
ASSERT(locs()->in(1).fpu_reg() == XMM1);
}
- // 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);
+ // }
XmmRegister base = locs()->in(0).fpu_reg();
XmmRegister exp = locs()->in(1).fpu_reg();
XmmRegister result = locs()->out(0).fpu_reg();
Register temp = locs()->temp(kObjectTempIndex).reg();
XmmRegister zero_temp = locs()->temp(kDoubleTempIndex).fpu_reg();
- // Check if exponent is 0.0 -> return 1.0;
+ Label do_call, check_base, return_nan;
__ LoadObject(temp, Double::ZoneHandle(Double::NewCanonical(0)), PP);
__ movsd(zero_temp, FieldAddress(temp, Double::value_offset()));
__ LoadObject(temp, Double::ZoneHandle(Double::NewCanonical(1)), PP);
__ movsd(result, FieldAddress(temp, Double::value_offset()));
- // 'result' contains 1.0.
- Label exp_is_nan;
+
+ // exponent == 0.0 -> return 1.0;
__ comisd(exp, zero_temp);
- __ j(PARITY_EVEN, &exp_is_nan, Assembler::kNearJump); // NaN.
- __ j(EQUAL, &skip_call, Assembler::kNearJump); // exp is 0, result is 1.0.
+ __ j(PARITY_EVEN, &check_base, Assembler::kNearJump);
+ __ j(EQUAL, &skip_call, Assembler::kNearJump); // 'result' is 1.0.
- Label base_is_nan;
- // Checks if base == 1.0.
+ __ Bind(&check_base);
+ // Note: 'exp' could be NaN.
+
+ // base == 1.0 -> return 1.0;
__ comisd(base, result);
- __ j(PARITY_EVEN, &base_is_nan, Assembler::kNearJump);
- __ j(EQUAL, &skip_call, Assembler::kNearJump); // base and result are 1.0
- __ jmp(&do_call, Assembler::kNearJump);
+ __ j(PARITY_EVEN, &return_nan, Assembler::kNearJump);
+ __ j(EQUAL, &skip_call, Assembler::kNearJump);
+ // Note: 'base' could be NaN.
+ __ comisd(exp, base);
+ // Neither 'exp' nor 'base' is NaN.
+ __ j(PARITY_ODD, &do_call, Assembler::kNearJump);
+ // Return NaN.
+ __ Bind(&return_nan);
+ __ LoadObject(temp, Double::ZoneHandle(Double::NewCanonical(NAN)), PP);
+ __ movsd(result, FieldAddress(temp, Double::value_offset()));
+ __ jmp(&skip_call);
- __ Bind(&base_is_nan);
- // Returns NaN.
- __ movsd(result, base);
+ Label do_pow, return_zero;
+ __ Bind(&do_call);
+ // Before calling check if we could use sqrt instead of pow.
+ __ LoadObject(temp,
+ Double::ZoneHandle(Double::NewCanonical(-INFINITY)), PP);
+ __ movsd(result, FieldAddress(temp, Double::value_offset()));
+ // base == -Infinity -> call pow;
+ __ comisd(base, result);
+ __ j(EQUAL, &do_pow, Assembler::kNearJump);
+
+ // exponent == 0.5 ?
+ __ LoadObject(temp, Double::ZoneHandle(Double::NewCanonical(0.5)), PP);
+ __ movsd(result, FieldAddress(temp, Double::value_offset()));
+ __ comisd(exp, result);
+ __ j(NOT_EQUAL, &do_pow, Assembler::kNearJump);
+
+ // base == 0 -> return 0;
+ __ comisd(base, zero_temp);
+ __ j(EQUAL, &return_zero, Assembler::kNearJump);
+
+ __ sqrtsd(result, base);
__ jmp(&skip_call, Assembler::kNearJump);
- __ Bind(&exp_is_nan);
- // Checks if base == 1.0.
- __ comisd(base, result);
- __ j(PARITY_EVEN, &base_is_nan, Assembler::kNearJump);
- __ j(EQUAL, &skip_call, Assembler::kNearJump); // base and result are 1.0
- __ movsd(result, exp); // result is NaN
- __ jmp(&skip_call, Assembler::kNearJump);
+ __ Bind(&return_zero);
+ __ movsd(result, zero_temp);
+ __ jmp(&skip_call);
+
+ __ Bind(&do_pow);
}
- __ Bind(&do_call);
__ CallRuntime(TargetFunction(), InputCount());
__ movaps(locs()->out(0).fpu_reg(), XMM0);
__ Bind(&skip_call);

Powered by Google App Engine
This is Rietveld 408576698