|
| 1 | +/* |
| 2 | + * Copyright (c) 2024, 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 | +/** |
| 25 | +* @test |
| 26 | +* @summary Test Float16 vector conversion chain. |
| 27 | +* @requires vm.compiler2.enabled |
| 28 | +* @library /test/lib / |
| 29 | +* @run driver compiler.vectorization.TestFloat16VectorConvChain |
| 30 | +*/ |
| 31 | + |
| 32 | +package compiler.vectorization; |
| 33 | + |
| 34 | +import compiler.lib.ir_framework.*; |
| 35 | +import java.util.Random; |
| 36 | +import java.util.Arrays; |
| 37 | + |
| 38 | + |
| 39 | +public class TestFloat16VectorConvChain { |
| 40 | + |
| 41 | + @Test |
| 42 | + @IR(counts = {IRNode.VECTOR_CAST_HF2F, IRNode.VECTOR_SIZE_ANY, ">= 1", IRNode.VECTOR_CAST_F2HF, IRNode.VECTOR_SIZE_ANY, " >= 1"}) |
| 43 | + public static void test(short [] res, short [] src1, short [] src2) { |
| 44 | + for (int i = 0; i < res.length; i++) { |
| 45 | + res[i] = (short)Float.float16ToFloat(Float.floatToFloat16(Float.float16ToFloat(src1[i]) + Float.float16ToFloat(src2[i]))); |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + @Run(test = {"test"}) |
| 50 | + @Warmup(1000) |
| 51 | + public static void micro() { |
| 52 | + short [] res = new short[1024]; |
| 53 | + short [] src1 = new short[1024]; |
| 54 | + short [] src2 = new short[1024]; |
| 55 | + Arrays.fill(src1, (short)Float.floatToFloat16(1.0f)); |
| 56 | + Arrays.fill(src2, (short)Float.floatToFloat16(2.0f)); |
| 57 | + for (int i = 0; i < 1000; i++) { |
| 58 | + test(res, src1, src2); |
| 59 | + } |
| 60 | + } |
| 61 | + |
| 62 | + public static void main(String [] args) { |
| 63 | + TestFramework.run(TestFloat16VectorConvChain.class); |
| 64 | + } |
| 65 | +} |
0 commit comments