Skip to content

Commit c089214

Browse files
Xubo ZhangSandhya Viswanathan
authored andcommitted
8255368: Math.exp() gives wrong result for large values on x86 32-bit platforms
Reviewed-by: darcy, kvn
1 parent 7ecf070 commit c089214

File tree

2 files changed

+72
-8
lines changed

2 files changed

+72
-8
lines changed

src/hotspot/cpu/x86/macroAssembler_x86_exp.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ void MacroAssembler::fast_exp(XMMRegister xmm0, XMMRegister xmm1, XMMRegister xm
493493
subl(rsp, 120);
494494
movl(Address(rsp, 64), tmp);
495495
lea(tmp, ExternalAddress(static_const_table));
496-
movdqu(xmm0, Address(rsp, 128));
496+
movsd(xmm0, Address(rsp, 128));
497497
unpcklpd(xmm0, xmm0);
498498
movdqu(xmm1, Address(tmp, 64)); // 0x652b82feUL, 0x40571547UL, 0x652b82feUL, 0x40571547UL
499499
movdqu(xmm6, Address(tmp, 48)); // 0x00000000UL, 0x43380000UL, 0x00000000UL, 0x43380000UL
@@ -585,18 +585,18 @@ void MacroAssembler::fast_exp(XMMRegister xmm0, XMMRegister xmm1, XMMRegister xm
585585
pextrw(ecx, xmm0, 3);
586586
andl(ecx, 32752);
587587
cmpl(ecx, 32752);
588-
jcc(Assembler::greaterEqual, L_2TAG_PACKET_3_0_2);
588+
jcc(Assembler::aboveEqual, L_2TAG_PACKET_3_0_2);
589589
cmpl(ecx, 0);
590590
jcc(Assembler::equal, L_2TAG_PACKET_4_0_2);
591591
jmp(L_2TAG_PACKET_2_0_2);
592592
cmpl(ecx, INT_MIN);
593-
jcc(Assembler::less, L_2TAG_PACKET_3_0_2);
593+
jcc(Assembler::below, L_2TAG_PACKET_3_0_2);
594594
cmpl(ecx, -1064950997);
595-
jcc(Assembler::less, L_2TAG_PACKET_2_0_2);
596-
jcc(Assembler::greater, L_2TAG_PACKET_4_0_2);
595+
jcc(Assembler::below, L_2TAG_PACKET_2_0_2);
596+
jcc(Assembler::above, L_2TAG_PACKET_4_0_2);
597597
movl(edx, Address(rsp, 128));
598598
cmpl(edx, -17155601);
599-
jcc(Assembler::less, L_2TAG_PACKET_2_0_2);
599+
jcc(Assembler::below, L_2TAG_PACKET_2_0_2);
600600
jmp(L_2TAG_PACKET_4_0_2);
601601

602602
bind(L_2TAG_PACKET_3_0_2);
@@ -614,10 +614,10 @@ void MacroAssembler::fast_exp(XMMRegister xmm0, XMMRegister xmm1, XMMRegister xm
614614

615615
bind(L_2TAG_PACKET_7_0_2);
616616
cmpl(eax, 2146435072);
617-
jcc(Assembler::greaterEqual, L_2TAG_PACKET_8_0_2);
617+
jcc(Assembler::aboveEqual, L_2TAG_PACKET_8_0_2);
618618
movl(eax, Address(rsp, 132));
619619
cmpl(eax, INT_MIN);
620-
jcc(Assembler::greaterEqual, L_2TAG_PACKET_9_0_2);
620+
jcc(Assembler::aboveEqual, L_2TAG_PACKET_9_0_2);
621621
movsd(xmm0, Address(tmp, 1208)); // 0xffffffffUL, 0x7fefffffUL
622622
mulsd(xmm0, xmm0);
623623
movl(edx, 14);
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright (c) 2011,2020, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
/*
25+
* @test
26+
* @bug 8255368
27+
* @summary Tests corner cases of Math.exp
28+
*/
29+
30+
public class ExpCornerCaseTests {
31+
private ExpCornerCaseTests(){}
32+
33+
public static void main(String... args) {
34+
int failures = 0;
35+
36+
failures += testExpCornerCases();
37+
38+
if (failures > 0) {
39+
System.err.printf("Testing exp corner cases incurred %d failures.%n", failures);
40+
throw new RuntimeException();
41+
}
42+
}
43+
44+
private static int testExpCornerCases() {
45+
int failures = 0;
46+
double [][] testCases = {
47+
{+0x4.0p8, Double.POSITIVE_INFINITY},
48+
{+0x2.71p12, Double.POSITIVE_INFINITY},
49+
};
50+
51+
for (double[] testCase : testCases) {
52+
failures += testExp(testCase[0], testCase[1]);
53+
}
54+
55+
return failures;
56+
}
57+
58+
private static int testExp(double input, double expected) {
59+
int failures = 0;
60+
failures += Tests.test("StrictMath.exp", input, StrictMath.exp(input), expected);
61+
failures += Tests.test("Math.exp", input, Math.exp(input), expected);
62+
return failures;
63+
}
64+
}

0 commit comments

Comments
 (0)