hotspot/test/compiler/floatingpoint/TestFMA.java
author coleenp
Wed, 10 May 2017 14:03:33 +0000
changeset 46450 7a361ede7817
parent 42653 62a5d76872d4
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
42653
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
     1
/*
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
     2
 * Copyright (c) 2016, Red Hat, Inc. All rights reserved.
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
     4
 *
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
     7
 * published by the Free Software Foundation.
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
     8
 *
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    13
 * accompanied this code).
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    14
 *
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    18
 *
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    21
 * questions.
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    22
 */
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    23
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    24
/**
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    25
 * @test
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    26
 * @bug 8162338
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    27
 * @summary intrinsify fused mac operations
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    28
 * @run main/othervm -XX:-BackgroundCompilation -XX:-BackgroundCompilation -XX:-UseOnStackReplacement TestFMA
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    29
 *
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    30
 */
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    31
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    32
import java.lang.annotation.Retention;
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    33
import java.lang.annotation.RetentionPolicy;
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    34
import java.lang.reflect.Method;
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    35
import java.lang.reflect.Modifier;
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    36
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    37
// Test all fused mac instructions that can be generated
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    38
public class TestFMA {
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    39
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    40
    @Test(args = {5.0F, 10.0F, 7.0F}, res = 57.0F)
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    41
    static float test1(float a, float b, float c) {
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    42
        return Math.fma(a, b, c);
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    43
    }
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    44
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    45
    @Test(args = {5.0D, 10.0D, 7.0D}, res = 57.0D)
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    46
    static double test2(double a, double b, double c) {
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    47
        return Math.fma(a, b, c);
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    48
    }
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    49
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    50
    @Test(args = {5.0F, 10.0F, 7.0F}, res = -43.0F)
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    51
    static float test3(float a, float b, float c) {
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    52
        return Math.fma(-a, b, c);
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    53
    }
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    54
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    55
    @Test(args = {5.0D, 10.0D, 7.0D}, res = -43.0D)
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    56
    static double test4(double a, double b, double c) {
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    57
        return Math.fma(-a, b, c);
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    58
    }
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    59
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    60
    @Test(args = {5.0F, 10.0F, 7.0F}, res = -43.0F)
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    61
    static float test5(float a, float b, float c) {
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    62
        return Math.fma(a, -b, c);
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    63
    }
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    64
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    65
    @Test(args = {5.0D, 10.0D, 7.0D}, res = -43.0D)
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    66
    static double test6(double a, double b, double c) {
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    67
        return Math.fma(a, -b, c);
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    68
    }
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    69
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    70
    @Test(args = {5.0F, 10.0F, 7.0F}, res = -57.0F)
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    71
    static float test7(float a, float b, float c) {
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    72
        return Math.fma(-a, b, -c);
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    73
    }
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    74
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    75
    @Test(args = {5.0D, 10.0D, 7.0D}, res = -57.0D)
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    76
    static double test8(double a, double b, double c) {
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    77
        return Math.fma(-a, b, -c);
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    78
    }
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    79
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    80
    @Test(args = {5.0F, 10.0F, 7.0F}, res = -57.0F)
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    81
    static float test9(float a, float b, float c) {
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    82
        return Math.fma(a, -b, -c);
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    83
    }
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    84
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    85
    @Test(args = {5.0D, 10.0D, 7.0D}, res = -57.0D)
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    86
    static double test10(double a, double b, double c) {
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    87
        return Math.fma(a, -b, -c);
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    88
    }
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    89
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    90
    @Test(args = {5.0F, 10.0F, 7.0F}, res = 43.0F)
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    91
    static float test11(float a, float b, float c) {
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    92
        return Math.fma(a, b, -c);
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    93
    }
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    94
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    95
    @Test(args = {5.0D, 10.0D, 7.0D}, res = 43.0D)
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    96
    static double test12(double a, double b, double c) {
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    97
        return Math.fma(a, b, -c);
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    98
    }
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
    99
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
   100
    static public void main(String[] args) throws Exception {
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
   101
        TestFMA t = new TestFMA();
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
   102
        for (Method m : t.getClass().getDeclaredMethods()) {
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
   103
            if (m.getName().matches("test[0-9]+?")) {
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
   104
                t.doTest(m);
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
   105
            }
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
   106
        }
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
   107
    }
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
   108
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
   109
    @Retention(RetentionPolicy.RUNTIME)
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
   110
    @interface Test {
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
   111
        double[] args();
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
   112
        double res();
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
   113
    }
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
   114
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
   115
    void doTest(Method m) throws Exception {
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
   116
        String name = m.getName();
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
   117
        System.out.println("Testing " + name);
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
   118
        Class retType = m.getReturnType();
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
   119
        Test test = m.getAnnotation(Test.class);
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
   120
        double[] args = test.args();
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
   121
        double expected = test.res();
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
   122
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
   123
        for (int i = 0; i < 20000; i++) {
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
   124
            if (retType == double.class) {
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
   125
                Object res = m.invoke(null, (double)args[0], (double)args[1], (double)args[2]);
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
   126
                if ((double)res != expected) {
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
   127
                    throw new RuntimeException(name + " failed : " + (double)res + " != " + expected);
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
   128
                }
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
   129
            } else {
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
   130
                Object res = m.invoke(null, (float)args[0], (float)args[1], (float)args[2]);
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
   131
                if ((float)res != (float)expected) {
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
   132
                    throw new RuntimeException(name + " failed : " + (float)res + " != " + (float)expected);
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
   133
                }
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
   134
            }
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
   135
        }
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
   136
    }
62a5d76872d4 8162338: AArch64: Intrinsify fused mac operations
roland
parents:
diff changeset
   137
}