8210461: AArch64: Math.cos intrinsic gives incorrect results
authordpochepk
Fri, 14 Sep 2018 14:24:00 +0300
changeset 51739 7bed934d439e
parent 51738 606e039bd655
child 51740 f79cfb07f13f
8210461: AArch64: Math.cos intrinsic gives incorrect results Reviewed-by: aph
src/hotspot/cpu/aarch64/macroAssembler_aarch64_trig.cpp
test/hotspot/jtreg/compiler/intrinsics/math/Test8210461.java
--- a/src/hotspot/cpu/aarch64/macroAssembler_aarch64_trig.cpp	Thu Sep 13 11:07:40 2018 +0200
+++ b/src/hotspot/cpu/aarch64/macroAssembler_aarch64_trig.cpp	Fri Sep 14 14:24:00 2018 +0300
@@ -1004,7 +1004,7 @@
           br(LT, Z_IS_LESS_THAN_TWO24B);
           fmuld(v1, v18, v17);                               // twon24*z
           frintzd(v1, v1);                                   // v1 = (double)(int)(v1)
-          fmaddd(v2, v10, v1, v18);
+          fmsubd(v2, v10, v1, v18);
           fcvtzdw(tmp3, v1);                                 // (int)fw
           fcvtzdw(tmp2, v2);                                 // double to int
           strw(tmp2, Address(iqBase, jz, Address::lsl(2)));
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/compiler/intrinsics/math/Test8210461.java	Fri Sep 14 14:24:00 2018 +0300
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, Cavium (by BELLSOFT). 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 8210461
+ * @summary Math cos instrinsic returns incorrect result for large value
+ *
+ * @run main/othervm compiler.intrinsics.math.Test8210461
+ */
+
+package compiler.intrinsics.math;
+
+import java.util.Arrays;
+
+public class Test8210461 {
+    private static final double[] testCases = new double[] {
+        1647100.0d,
+        16471000.0d,
+        164710000.0d
+    };
+
+    public static void main(String[] args) {
+        Arrays.stream(testCases).forEach(Test8210461::test);
+    }
+
+    private static void test(double arg) {
+        double strictResult = StrictMath.cos(arg);
+        double mathResult = Math.cos(arg);
+        if (Math.abs(strictResult - mathResult) > Math.ulp(strictResult))
+            throw new AssertionError(mathResult + " while expecting " + strictResult);
+    }
+}