mirror of
https://github.com/openjdk/jdk.git
synced 2026-04-04 20:18:49 +00:00
8265917: Different values computed by C2 and interpreter/C1 for Math.pow(x, 2.0) on x86_32
Reviewed-by: kvn, thartmann
This commit is contained in:
parent
e144104bb3
commit
889d246681
@ -2515,6 +2515,8 @@ ATTRIBUTE_ALIGNED(16) juint _static_const_table_pow[] =
|
||||
|
||||
};
|
||||
|
||||
ATTRIBUTE_ALIGNED(8) double _DOUBLE2 = 2.0;
|
||||
|
||||
//registers,
|
||||
// input: xmm0, xmm1
|
||||
// scratch: xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7
|
||||
@ -2538,10 +2540,12 @@ void MacroAssembler::fast_pow(XMMRegister xmm0, XMMRegister xmm1, XMMRegister xm
|
||||
Label L_2TAG_PACKET_48_0_2, L_2TAG_PACKET_49_0_2, L_2TAG_PACKET_50_0_2, L_2TAG_PACKET_51_0_2;
|
||||
Label L_2TAG_PACKET_52_0_2, L_2TAG_PACKET_53_0_2, L_2TAG_PACKET_54_0_2, L_2TAG_PACKET_55_0_2;
|
||||
Label L_2TAG_PACKET_56_0_2, L_2TAG_PACKET_57_0_2, L_2TAG_PACKET_58_0_2, start;
|
||||
Label L_NOT_DOUBLE2;
|
||||
|
||||
assert_different_registers(tmp, eax, ecx, edx);
|
||||
|
||||
address static_const_table_pow = (address)_static_const_table_pow;
|
||||
address DOUBLE2 = (address) &_DOUBLE2;
|
||||
|
||||
bind(start);
|
||||
subl(rsp, 120);
|
||||
@ -2549,6 +2553,15 @@ void MacroAssembler::fast_pow(XMMRegister xmm0, XMMRegister xmm1, XMMRegister xm
|
||||
lea(tmp, ExternalAddress(static_const_table_pow));
|
||||
movsd(xmm0, Address(rsp, 128));
|
||||
movsd(xmm1, Address(rsp, 136));
|
||||
|
||||
// Special case: pow(x, 2.0) => x * x
|
||||
ucomisd(xmm1, ExternalAddress(DOUBLE2));
|
||||
jccb(Assembler::notEqual, L_NOT_DOUBLE2);
|
||||
jccb(Assembler::parity, L_NOT_DOUBLE2);
|
||||
mulsd(xmm0, xmm0);
|
||||
jmp(L_2TAG_PACKET_21_0_2);
|
||||
|
||||
bind(L_NOT_DOUBLE2);
|
||||
xorpd(xmm2, xmm2);
|
||||
movl(eax, 16368);
|
||||
pinsrw(xmm2, eax, 3);
|
||||
|
||||
53
test/hotspot/jtreg/compiler/intrinsics/math/TestPow2Opt.java
Normal file
53
test/hotspot/jtreg/compiler/intrinsics/math/TestPow2Opt.java
Normal file
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8265917
|
||||
* @summary test the optimization of pow(x, 2.0)
|
||||
* @run main/othervm TestPow2Opt
|
||||
* @run main/othervm -Xint TestPow2Opt
|
||||
* @run main/othervm -Xbatch -XX:TieredStopAtLevel=1 TestPow2Opt
|
||||
* @run main/othervm -Xbatch -XX:-TieredCompilation TestPow2Opt
|
||||
*/
|
||||
|
||||
public class TestPow2Opt {
|
||||
|
||||
static void test(double a) {
|
||||
double r1 = a * a;
|
||||
double r2 = Math.pow(a, 2.0);
|
||||
if (r1 != r2) {
|
||||
throw new RuntimeException("pow(" + a + ", 2.0), expected: " + r1 + ", actual: " + r2);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
for (int j = 1; j < 100000; j++) {
|
||||
test(j * 1.0);
|
||||
test(1.0 / j);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user