Path: blob/master/test/hotspot/jtreg/compiler/floatingpoint/TestFMA.java
41149 views
/*1* Copyright (c) 2016, Red Hat, Inc. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @bug 816233826* @summary intrinsify fused mac operations27* @run main/othervm -XX:-BackgroundCompilation -XX:-BackgroundCompilation -XX:-UseOnStackReplacement TestFMA28*29*/3031import java.lang.annotation.Retention;32import java.lang.annotation.RetentionPolicy;33import java.lang.reflect.Method;34import java.lang.reflect.Modifier;3536// Test all fused mac instructions that can be generated37public class TestFMA {3839@Test(args = {5.0F, 10.0F, 7.0F}, res = 57.0F)40static float test1(float a, float b, float c) {41return Math.fma(a, b, c);42}4344@Test(args = {5.0D, 10.0D, 7.0D}, res = 57.0D)45static double test2(double a, double b, double c) {46return Math.fma(a, b, c);47}4849@Test(args = {5.0F, 10.0F, 7.0F}, res = -43.0F)50static float test3(float a, float b, float c) {51return Math.fma(-a, b, c);52}5354@Test(args = {5.0D, 10.0D, 7.0D}, res = -43.0D)55static double test4(double a, double b, double c) {56return Math.fma(-a, b, c);57}5859@Test(args = {5.0F, 10.0F, 7.0F}, res = -43.0F)60static float test5(float a, float b, float c) {61return Math.fma(a, -b, c);62}6364@Test(args = {5.0D, 10.0D, 7.0D}, res = -43.0D)65static double test6(double a, double b, double c) {66return Math.fma(a, -b, c);67}6869@Test(args = {5.0F, 10.0F, 7.0F}, res = -57.0F)70static float test7(float a, float b, float c) {71return Math.fma(-a, b, -c);72}7374@Test(args = {5.0D, 10.0D, 7.0D}, res = -57.0D)75static double test8(double a, double b, double c) {76return Math.fma(-a, b, -c);77}7879@Test(args = {5.0F, 10.0F, 7.0F}, res = -57.0F)80static float test9(float a, float b, float c) {81return Math.fma(a, -b, -c);82}8384@Test(args = {5.0D, 10.0D, 7.0D}, res = -57.0D)85static double test10(double a, double b, double c) {86return Math.fma(a, -b, -c);87}8889@Test(args = {5.0F, 10.0F, 7.0F}, res = 43.0F)90static float test11(float a, float b, float c) {91return Math.fma(a, b, -c);92}9394@Test(args = {5.0D, 10.0D, 7.0D}, res = 43.0D)95static double test12(double a, double b, double c) {96return Math.fma(a, b, -c);97}9899static public void main(String[] args) throws Exception {100TestFMA t = new TestFMA();101for (Method m : t.getClass().getDeclaredMethods()) {102if (m.getName().matches("test[0-9]+?")) {103t.doTest(m);104}105}106}107108@Retention(RetentionPolicy.RUNTIME)109@interface Test {110double[] args();111double res();112}113114void doTest(Method m) throws Exception {115String name = m.getName();116System.out.println("Testing " + name);117Class retType = m.getReturnType();118Test test = m.getAnnotation(Test.class);119double[] args = test.args();120double expected = test.res();121122for (int i = 0; i < 20000; i++) {123if (retType == double.class) {124Object res = m.invoke(null, (double)args[0], (double)args[1], (double)args[2]);125if ((double)res != expected) {126throw new RuntimeException(name + " failed : " + (double)res + " != " + expected);127}128} else {129Object res = m.invoke(null, (float)args[0], (float)args[1], (float)args[2]);130if ((float)res != (float)expected) {131throw new RuntimeException(name + " failed : " + (float)res + " != " + (float)expected);132}133}134}135}136}137138139