< prev index next >

test/hotspot/jtreg/compiler/vectorization/TestFloatConversionsVectorNaN.java

Print this page

 48     private static short  [] sout;
 49     private static short  [] sinp;
 50     private static float  [] fout;
 51 
 52     public static void main(String args[]) {
 53         TestFramework framework = new TestFramework(TestFloatConversionsVectorNaN.class);
 54         framework.addFlags("-XX:-TieredCompilation", "-XX:CompileThresholdScaling=0.3");
 55         switch (args[0]) {
 56             case "nCOH_nAV" -> { framework.addFlags("-XX:+UnlockExperimentalVMOptions", "-XX:-UseCompactObjectHeaders", "-XX:-AlignVector"); }
 57             case "nCOH_yAV" -> { framework.addFlags("-XX:+UnlockExperimentalVMOptions", "-XX:-UseCompactObjectHeaders", "-XX:+AlignVector"); }
 58             case "yCOH_nAV" -> { framework.addFlags("-XX:+UnlockExperimentalVMOptions", "-XX:+UseCompactObjectHeaders", "-XX:-AlignVector"); }
 59             case "yCOH_yAV" -> { framework.addFlags("-XX:+UnlockExperimentalVMOptions", "-XX:+UseCompactObjectHeaders", "-XX:+AlignVector"); }
 60             default -> { throw new RuntimeException("Test argument not recognized: " + args[0]); }
 61         };
 62         framework.start();
 63         System.out.println("PASSED");
 64     }
 65 
 66     @Test
 67     @IR(counts = {IRNode.VECTOR_CAST_F2HF, IRNode.VECTOR_SIZE + "min(max_float, max_short)", "> 0"},
 68         applyIfOr = {"UseCompactObjectHeaders", "false", "AlignVector", "false"})
 69     public void test_float_float16(short[] sout, float[] finp) {
 70         for (int i = 0; i < finp.length; i++) {
 71             sout[i] = Float.floatToFloat16(finp[i]);
 72             // With AlignVector, we need 8-byte alignment of vector loads/stores.
 73             // UseCompactObjectHeaders=false                 UseCompactObjectHeaders=true
 74             // F_adr = base + 16 + 4*i   ->  i % 2 = 0       F_adr = base + 12 + 4*i   ->  i % 2 = 1
 75             // S_adr = base + 16 + 2*i   ->  i % 4 = 0       S_adr = base + 12 + 2*i   ->  i % 4 = 2
 76             // -> vectorize                                  -> no vectorization
 77         }
 78     }
 79 
 80     @Run(test = {"test_float_float16"}, mode = RunMode.STANDALONE)
 81     public void kernel_test_float_float16() {
 82         int errno = 0;
 83         finp = new float[ARRLEN];
 84         sout = new short[ARRLEN];
 85 
 86         // Setup
 87         for (int i = 0; i < ARRLEN; i++) {
 88             if (i%39 == 0) {
 89                 int x = 0x7f800000 + ((i/39) << 13);
 90                 x = (i%2 == 0) ? x : (x | 0x80000000);
 91                 finp[i] = Float.intBitsToFloat(x);
 92             } else {
 93                 finp[i] = (float) i * 1.4f;
 94             }
 95         }
 96         int ranges[][] = {

129     static int assertEquals(int idx, float f, short expected, short actual) {
130         HexFormat hf = HexFormat.of();
131         String msg = "floatToFloat16 wrong result: idx: " + idx + ", \t" + f +
132                      ",\t expected: " + hf.toHexDigits(expected) +
133                      ",\t actual: " + hf.toHexDigits(actual);
134         if ((expected & 0x7c00) != 0x7c00) {
135             if (expected != actual) {
136                 System.err.println(msg);
137                 return 1;
138             }
139         } else if ((expected & 0x3ff) != 0) {
140             if (((actual & 0x7c00) != 0x7c00) || (actual & 0x3ff) == 0) {
141                 System.err.println(msg);
142                 return 1;
143             }
144         }
145         return 0;
146     }
147 
148     @Test
149     @IR(counts = {IRNode.VECTOR_CAST_HF2F, IRNode.VECTOR_SIZE + "min(max_float, max_short)", "> 0"},
150         applyIfOr = {"UseCompactObjectHeaders", "false", "AlignVector", "false"})
151     public void test_float16_float(float[] fout, short[] sinp) {
152         for (int i = 0; i < sinp.length; i++) {
153             fout[i] = Float.float16ToFloat(sinp[i]);
154             // With AlignVector, we need 8-byte alignment of vector loads/stores.
155             // UseCompactObjectHeaders=false                 UseCompactObjectHeaders=true
156             // F_adr = base + 16 + 4*i   ->  i % 2 = 0       F_adr = base + 12 + 4*i   ->  i % 2 = 1
157             // S_adr = base + 16 + 2*i   ->  i % 4 = 0       S_adr = base + 12 + 2*i   ->  i % 4 = 2
158             // -> vectorize                                  -> no vectorization
159         }
160     }
161 
162     @Run(test = {"test_float16_float"}, mode = RunMode.STANDALONE)
163     public void kernel_test_float16_float() {
164         int errno = 0;
165         sinp = new short[ARRLEN];
166         fout = new float[ARRLEN];
167 
168         // Setup
169         for (int i = 0; i < ARRLEN; i++) {
170             if (i%39 == 0) {
171                 int x = 0x7c00 + i;
172                 x = (i%2 == 0) ? x : (x | 0x8000);
173                 sinp[i] = (short)x;
174             } else {
175                 sinp[i] = (short)i;
176             }
177         }
178 

 48     private static short  [] sout;
 49     private static short  [] sinp;
 50     private static float  [] fout;
 51 
 52     public static void main(String args[]) {
 53         TestFramework framework = new TestFramework(TestFloatConversionsVectorNaN.class);
 54         framework.addFlags("-XX:-TieredCompilation", "-XX:CompileThresholdScaling=0.3");
 55         switch (args[0]) {
 56             case "nCOH_nAV" -> { framework.addFlags("-XX:+UnlockExperimentalVMOptions", "-XX:-UseCompactObjectHeaders", "-XX:-AlignVector"); }
 57             case "nCOH_yAV" -> { framework.addFlags("-XX:+UnlockExperimentalVMOptions", "-XX:-UseCompactObjectHeaders", "-XX:+AlignVector"); }
 58             case "yCOH_nAV" -> { framework.addFlags("-XX:+UnlockExperimentalVMOptions", "-XX:+UseCompactObjectHeaders", "-XX:-AlignVector"); }
 59             case "yCOH_yAV" -> { framework.addFlags("-XX:+UnlockExperimentalVMOptions", "-XX:+UseCompactObjectHeaders", "-XX:+AlignVector"); }
 60             default -> { throw new RuntimeException("Test argument not recognized: " + args[0]); }
 61         };
 62         framework.start();
 63         System.out.println("PASSED");
 64     }
 65 
 66     @Test
 67     @IR(counts = {IRNode.VECTOR_CAST_F2HF, IRNode.VECTOR_SIZE + "min(max_float, max_short)", "> 0"},

 68     public void test_float_float16(short[] sout, float[] finp) {
 69         for (int i = 0; i < finp.length; i++) {
 70             sout[i] = Float.floatToFloat16(finp[i]);





 71         }
 72     }
 73 
 74     @Run(test = {"test_float_float16"}, mode = RunMode.STANDALONE)
 75     public void kernel_test_float_float16() {
 76         int errno = 0;
 77         finp = new float[ARRLEN];
 78         sout = new short[ARRLEN];
 79 
 80         // Setup
 81         for (int i = 0; i < ARRLEN; i++) {
 82             if (i%39 == 0) {
 83                 int x = 0x7f800000 + ((i/39) << 13);
 84                 x = (i%2 == 0) ? x : (x | 0x80000000);
 85                 finp[i] = Float.intBitsToFloat(x);
 86             } else {
 87                 finp[i] = (float) i * 1.4f;
 88             }
 89         }
 90         int ranges[][] = {

123     static int assertEquals(int idx, float f, short expected, short actual) {
124         HexFormat hf = HexFormat.of();
125         String msg = "floatToFloat16 wrong result: idx: " + idx + ", \t" + f +
126                      ",\t expected: " + hf.toHexDigits(expected) +
127                      ",\t actual: " + hf.toHexDigits(actual);
128         if ((expected & 0x7c00) != 0x7c00) {
129             if (expected != actual) {
130                 System.err.println(msg);
131                 return 1;
132             }
133         } else if ((expected & 0x3ff) != 0) {
134             if (((actual & 0x7c00) != 0x7c00) || (actual & 0x3ff) == 0) {
135                 System.err.println(msg);
136                 return 1;
137             }
138         }
139         return 0;
140     }
141 
142     @Test
143     @IR(counts = {IRNode.VECTOR_CAST_HF2F, IRNode.VECTOR_SIZE + "min(max_float, max_short)", "> 0"})

144     public void test_float16_float(float[] fout, short[] sinp) {
145         for (int i = 0; i < sinp.length; i++) {
146             fout[i] = Float.float16ToFloat(sinp[i]);





147         }
148     }
149 
150     @Run(test = {"test_float16_float"}, mode = RunMode.STANDALONE)
151     public void kernel_test_float16_float() {
152         int errno = 0;
153         sinp = new short[ARRLEN];
154         fout = new float[ARRLEN];
155 
156         // Setup
157         for (int i = 0; i < ARRLEN; i++) {
158             if (i%39 == 0) {
159                 int x = 0x7c00 + i;
160                 x = (i%2 == 0) ? x : (x | 0x8000);
161                 sinp[i] = (short)x;
162             } else {
163                 sinp[i] = (short)i;
164             }
165         }
166 
< prev index next >