36
package compiler.vectorization;
38
import compiler.lib.ir_framework.*;
39
import jdk.test.lib.Asserts;
41
public class TestFloatConversionsVector {
42
private static final int ARRLEN = 1024;
43
private static final int ITERS = 11000;
44
private static float [] finp;
45
private static short [] sout;
46
private static short [] sinp;
47
private static float [] fout;
49
public static void main(String args[]) {
50
TestFramework.runWithFlags("-XX:-TieredCompilation",
51
"-XX:CompileThresholdScaling=0.3");
52
System.out.println("PASSED");
56
@IR(counts = {IRNode.VECTOR_CAST_F2HF, IRNode.VECTOR_SIZE + "min(max_float, max_short)", "> 0"})
57
public void test_float_float16(short[] sout, float[] finp) {
58
for (int i = 0; i < finp.length; i++) {
59
sout[i] = Float.floatToFloat16(finp[i]);
64
public void test_float_float16_strided(short[] sout, float[] finp) {
65
for (int i = 0; i < finp.length/2; i++) {
66
sout[i*2] = Float.floatToFloat16(finp[i*2]);
70
@Run(test = {"test_float_float16", "test_float_float16_strided"}, mode = RunMode.STANDALONE)
71
public void kernel_test_float_float16() {
72
finp = new float[ARRLEN];
73
sout = new short[ARRLEN];
75
for (int i = 0; i < ARRLEN; i++) {
76
finp[i] = (float) i * 1.4f;
79
for (int i = 0; i < ITERS; i++) {
80
test_float_float16(sout, finp);
84
for (int i = 0; i < ARRLEN; i++) {
85
Asserts.assertEquals(Float.floatToFloat16(finp[i]), sout[i]);
88
for (int i = 0; i < ITERS; i++) {
89
test_float_float16_strided(sout, finp);
93
for (int i = 0; i < ARRLEN/2; i++) {
94
Asserts.assertEquals(Float.floatToFloat16(finp[i*2]), sout[i*2]);
99
@IR(counts = {IRNode.VECTOR_CAST_HF2F, IRNode.VECTOR_SIZE + "min(max_float, max_short)", "> 0"})
100
public void test_float16_float(float[] fout, short[] sinp) {
101
for (int i = 0; i < sinp.length; i++) {
102
fout[i] = Float.float16ToFloat(sinp[i]);
107
public void test_float16_float_strided(float[] fout, short[] sinp) {
108
for (int i = 0; i < sinp.length/2; i++) {
109
fout[i*2] = Float.float16ToFloat(sinp[i*2]);
113
@Run(test = {"test_float16_float", "test_float16_float_strided"}, mode = RunMode.STANDALONE)
114
public void kernel_test_float16_float() {
115
sinp = new short[ARRLEN];
116
fout = new float[ARRLEN];
118
for (int i = 0; i < ARRLEN; i++) {
122
for (int i = 0; i < ITERS; i++) {
123
test_float16_float(fout, sinp);
127
for (int i = 0; i < ARRLEN; i++) {
128
Asserts.assertEquals(Float.float16ToFloat(sinp[i]), fout[i]);
131
for (int i = 0; i < ITERS; i++) {
132
test_float16_float_strided(fout, sinp);
136
for (int i = 0; i < ARRLEN/2; i++) {
137
Asserts.assertEquals(Float.float16ToFloat(sinp[i*2]), fout[i*2]);