From f6d04e48e40018374d1c12d8ae508d72fcc24a58 Mon Sep 17 00:00:00 2001 From: csahu Date: Tue, 24 May 2016 17:49:06 +0530 Subject: 8063086: Math.pow yields different results upon repeated calls Summary: C2 treats x^2 as a special case and computes x * x while the interpreter and c1 don't have special case code for X^2. Reviewed-by: kvn --- src/cpu/x86/vm/macroAssembler_x86.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'src/cpu/x86') diff --git a/src/cpu/x86/vm/macroAssembler_x86.cpp b/src/cpu/x86/vm/macroAssembler_x86.cpp index e2ea04b79..30490d451 100644 --- a/src/cpu/x86/vm/macroAssembler_x86.cpp +++ b/src/cpu/x86/vm/macroAssembler_x86.cpp @@ -3202,7 +3202,24 @@ void MacroAssembler::pow_or_exp(bool is_exp, int num_fpu_regs_in_use) { jmp(done); } else { // Stack: X Y - Label x_negative, y_odd; + Label x_negative, y_not_2; + + static double two = 2.0; + ExternalAddress two_addr((address)&two); + + // constant maybe too far on 64 bit + lea(tmp2, two_addr); + fld_d(Address(tmp2, 0)); // Stack: 2 X Y + fcmp(tmp, 2, true, false); // Stack: X Y + jcc(Assembler::parity, y_not_2); + jcc(Assembler::notEqual, y_not_2); + + fxch(); fpop(); // Stack: X + fmul(0); // Stack: X*X + + jmp(done); + + bind(y_not_2); fldz(); // Stack: 0 X Y fcmp(tmp, 1, true, false); // Stack: X Y -- cgit v1.2.3