hotspot/test/compiler/intrinsics/mathexact/MulExactIRepeatTest.java
author vdeshpande
Fri, 26 Aug 2016 12:20:09 -0700
changeset 41362 e09e871860a7
parent 40059 c2304140ed64
child 40631 ed82623d7831
permissions -rw-r--r--
8154122: Intrinsify fused mac operations Summary: added FMA intrinsics on x86 Reviewed-by: kvn, aph, darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
21105
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
     1
/*
29678
dd2f3932c21e 8075586: Add @modules as needed to the open hotspot tests
ykantser
parents: 27453
diff changeset
     2
 * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
21105
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
     4
 *
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
     7
 * published by the Free Software Foundation.
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
     8
 *
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    13
 * accompanied this code).
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    14
 *
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    18
 *
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    21
 * questions.
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    22
 */
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    23
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    24
/*
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    25
 * @test
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    26
 * @bug 8026844
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    27
 * @summary Test repeating multiplyExact
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 36851
diff changeset
    28
 * @library /testlibrary /
36851
03e2f4d0a421 8153737: Unsupported Module
chegar
parents: 30604
diff changeset
    29
 * @modules java.base/jdk.internal.misc
29678
dd2f3932c21e 8075586: Add @modules as needed to the open hotspot tests
ykantser
parents: 27453
diff changeset
    30
 *          java.management
21105
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    31
 *
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 36851
diff changeset
    32
 * @run main compiler.intrinsics.mathexact.MulExactIRepeatTest
21105
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    33
 */
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    34
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 36851
diff changeset
    35
package compiler.intrinsics.mathexact;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 36851
diff changeset
    36
30604
b8d532cb6420 8067013: Rename the com.oracle.java.testlibary package
ykantser
parents: 29678
diff changeset
    37
import jdk.test.lib.Utils;
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 36851
diff changeset
    38
27453
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents: 22911
diff changeset
    39
import java.util.Random;
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents: 22911
diff changeset
    40
21105
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    41
public class MulExactIRepeatTest {
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    42
    public static void main(String[] args) {
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    43
        runTest(new Verify.MulExactI());
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    44
    }
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    45
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    46
    public static int nonExact(int x, int y, Verify.BinaryMethod method) {
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    47
        int result = method.unchecked(x, y);
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    48
        result += method.unchecked(x, y);
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    49
        result += method.unchecked(x, y);
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    50
        result += method.unchecked(x, y);
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    51
        return result;
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    52
    }
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    53
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    54
    public static void runTest(Verify.BinaryMethod method) {
27453
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents: 22911
diff changeset
    55
        Random rnd = Utils.getRandomInstance();
21105
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    56
        for (int i = 0; i < 50000; ++i) {
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    57
            int x = Integer.MAX_VALUE - 10;
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    58
            int y = Integer.MAX_VALUE - 10 + rnd.nextInt(5);
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    59
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    60
            int c = rnd.nextInt() / 10;
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    61
            int d = rnd.nextInt(9);
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    62
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    63
            int a = catchingExact(x, y, method);
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    64
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    65
            if (a != 36) {
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    66
                throw new RuntimeException("a != 36 : " + a);
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    67
            }
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    68
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    69
            int b = nonExact(c, d, method);
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    70
            int n = exact(c, d, method);
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    71
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    72
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    73
            if (n != b) {
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    74
                throw new RuntimeException("n != b : " + n + " != " + b);
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    75
            }
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    76
        }
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    77
    }
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    78
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    79
    public static int exact(int x, int y, Verify.BinaryMethod method) {
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    80
        int result = 0;
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    81
        result += method.checkMethod(x, y);
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    82
        result += method.checkMethod(x, y);
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    83
        result += method.checkMethod(x, y);
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    84
        result += method.checkMethod(x, y);
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    85
        return result;
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    86
    }
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    87
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    88
    public static int catchingExact(int x, int y, Verify.BinaryMethod method) {
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    89
        int result = 0;
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    90
        try {
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    91
            result += 5;
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    92
            result = method.checkMethod(x, y);
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    93
        } catch (ArithmeticException e) {
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    94
            result += 1;
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    95
        }
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    96
        try {
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    97
            result += 6;
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    98
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
    99
            result += method.checkMethod(x, y);
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
   100
        } catch (ArithmeticException e) {
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
   101
            result += 2;
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
   102
        }
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
   103
        try {
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
   104
            result += 7;
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
   105
            result += method.checkMethod(x, y);
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
   106
        } catch (ArithmeticException e) {
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
   107
            result += 3;
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
   108
        }
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
   109
        try {
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
   110
            result += 8;
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
   111
            result += method.checkMethod(x, y);
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
   112
        } catch (ArithmeticException e) {
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
   113
            result += 4;
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
   114
        }
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
   115
        return result;
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
   116
    }
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents:
diff changeset
   117
}