diff src/cpu/x86/vm/macroAssembler_x86.cpp @ 24010:5aaa43d91c73

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
author csahu
date Tue, 24 May 2016 17:49:06 +0530
parents daaf806995b3
children 371fd9bb8202
line wrap: on
line diff
--- a/src/cpu/x86/vm/macroAssembler_x86.cpp	Wed May 18 11:06:00 2016 +0200
+++ b/src/cpu/x86/vm/macroAssembler_x86.cpp	Tue May 24 17:49:06 2016 +0530
@@ -3202,7 +3202,24 @@
     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