|
| 1 | +/* |
| 2 | + * Copyright (c) 2025, 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 | +package compiler.vectorapi; |
| 25 | + |
| 26 | +import jdk.incubator.vector.FloatVector; |
| 27 | +import jdk.incubator.vector.VectorOperators; |
| 28 | +import jdk.incubator.vector.VectorSpecies; |
| 29 | + |
| 30 | +/* |
| 31 | + * @test |
| 32 | + * @bug 8367333 |
| 33 | + * @requires vm.compiler2.enabled |
| 34 | + * @modules jdk.incubator.vector |
| 35 | + * @library /test/lib |
| 36 | + * |
| 37 | + * @run main/othervm -Xbatch -XX:-TieredCompilation |
| 38 | + * -XX:+UnlockDiagnosticVMOptions -XX:+StressIncrementalInlining |
| 39 | + * -XX:CompileCommand=quiet |
| 40 | + * -XX:CompileCommand=compileonly,compiler.vectorapi.TestVectorMathLib::test* |
| 41 | + * compiler.vectorapi.TestVectorMathLib |
| 42 | + */ |
| 43 | + |
| 44 | +public class TestVectorMathLib { |
| 45 | + private static final VectorSpecies SPECIES = FloatVector.SPECIES_PREFERRED; |
| 46 | + |
| 47 | + static FloatVector testTAN(FloatVector fv) { |
| 48 | + return fv.lanewise(VectorOperators.TAN); |
| 49 | + } |
| 50 | + static FloatVector testTANH(FloatVector fv) { |
| 51 | + return fv.lanewise(VectorOperators.TANH); |
| 52 | + } |
| 53 | + static FloatVector testSIN(FloatVector fv) { |
| 54 | + return fv.lanewise(VectorOperators.SIN); |
| 55 | + } |
| 56 | + static FloatVector testSINH(FloatVector fv) { |
| 57 | + return fv.lanewise(VectorOperators.SINH); |
| 58 | + } |
| 59 | + static FloatVector testCOS(FloatVector fv) { |
| 60 | + return fv.lanewise(VectorOperators.COS); |
| 61 | + } |
| 62 | + static FloatVector testCOSH(FloatVector fv) { |
| 63 | + return fv.lanewise(VectorOperators.COSH); |
| 64 | + } |
| 65 | + static FloatVector testASIN(FloatVector fv) { |
| 66 | + return fv.lanewise(VectorOperators.ASIN); |
| 67 | + } |
| 68 | + static FloatVector testACOS(FloatVector fv) { |
| 69 | + return fv.lanewise(VectorOperators.ACOS); |
| 70 | + } |
| 71 | + static FloatVector testATAN(FloatVector fv) { |
| 72 | + return fv.lanewise(VectorOperators.ATAN); |
| 73 | + } |
| 74 | + static FloatVector testATAN2(FloatVector fv) { |
| 75 | + return fv.lanewise(VectorOperators.ATAN2, fv); |
| 76 | + } |
| 77 | + static FloatVector testCBRT(FloatVector fv) { |
| 78 | + return fv.lanewise(VectorOperators.CBRT); |
| 79 | + } |
| 80 | + static FloatVector testLOG(FloatVector fv) { |
| 81 | + return fv.lanewise(VectorOperators.LOG); |
| 82 | + } |
| 83 | + static FloatVector testLOG10(FloatVector fv) { |
| 84 | + return fv.lanewise(VectorOperators.LOG10); |
| 85 | + } |
| 86 | + static FloatVector testLOG1P(FloatVector fv) { |
| 87 | + return fv.lanewise(VectorOperators.LOG1P); |
| 88 | + } |
| 89 | + static FloatVector testPOW(FloatVector fv) { |
| 90 | + return fv.lanewise(VectorOperators.POW, fv); |
| 91 | + } |
| 92 | + static FloatVector testEXP(FloatVector fv) { |
| 93 | + return fv.lanewise(VectorOperators.EXP); |
| 94 | + } |
| 95 | + static FloatVector testEXPM1(FloatVector fv) { |
| 96 | + return fv.lanewise(VectorOperators.EXPM1); |
| 97 | + } |
| 98 | + static FloatVector testHYPOT(FloatVector fv) { |
| 99 | + return fv.lanewise(VectorOperators.HYPOT, fv); |
| 100 | + } |
| 101 | + |
| 102 | + public static void main(String[] args) { |
| 103 | + FloatVector z = FloatVector.zero(SPECIES); |
| 104 | + for (int i = 0; i < 20_000; i++) { |
| 105 | + z.neg(); // unary |
| 106 | + z.add(z); // binary |
| 107 | + |
| 108 | + testTAN(z); |
| 109 | + testTANH(z); |
| 110 | + testSIN(z); |
| 111 | + testSINH(z); |
| 112 | + testCOS(z); |
| 113 | + testCOSH(z); |
| 114 | + testASIN(z); |
| 115 | + testACOS(z); |
| 116 | + testATAN(z); |
| 117 | + testATAN2(z); |
| 118 | + testCBRT(z); |
| 119 | + testLOG(z); |
| 120 | + testLOG10(z); |
| 121 | + testLOG1P(z); |
| 122 | + testPOW(z); |
| 123 | + testEXP(z); |
| 124 | + testEXPM1(z); |
| 125 | + testHYPOT(z); |
| 126 | + } |
| 127 | + |
| 128 | + System.out.println("TEST PASSED"); |
| 129 | + } |
| 130 | +} |
| 131 | + |
0 commit comments