< prev index next >

test/hotspot/jtreg/compiler/vectorization/runner/ArrayTypeConvertTest.java

Print this page

 44  *                   -XX:+WhiteBoxAPI
 45  *                   compiler.vectorization.runner.ArrayTypeConvertTest nCOH_yAV
 46  *
 47  * @run main/othervm -Xbootclasspath/a:.
 48  *                   -XX:+UnlockDiagnosticVMOptions
 49  *                   -XX:+WhiteBoxAPI
 50  *                   compiler.vectorization.runner.ArrayTypeConvertTest yCOH_nAV
 51  *
 52  * @run main/othervm -Xbootclasspath/a:.
 53  *                   -XX:+UnlockDiagnosticVMOptions
 54  *                   -XX:+WhiteBoxAPI
 55  *                   compiler.vectorization.runner.ArrayTypeConvertTest yCOH_yAV
 56  */
 57 
 58 package compiler.vectorization.runner;
 59 
 60 import compiler.lib.ir_framework.*;
 61 
 62 // Explanation about AlignVector: we require 8-byte alignment of all addresses.
 63 // But the array base offset changes with UseCompactObjectHeaders.
 64 // This means it affects the alignment constraints.
 65 
 66 public class ArrayTypeConvertTest extends VectorizationTestRunner {
 67 
 68     // We must pass the flags directly to the test-VM, and not the driver vm in the @run above.
 69     @Override
 70     protected String[] testVMFlags(String[] args) {
 71         return switch (args[0]) {
 72             case "nCOH_nAV" -> new String[]{"-XX:-UseCompactObjectHeaders", "-XX:-AlignVector"};
 73             case "nCOH_yAV" -> new String[]{"-XX:-UseCompactObjectHeaders", "-XX:+AlignVector"};
 74             case "yCOH_nAV" -> new String[]{"-XX:+UseCompactObjectHeaders", "-XX:-AlignVector"};
 75             case "yCOH_yAV" -> new String[]{"-XX:+UseCompactObjectHeaders", "-XX:+AlignVector"};
 76             default -> { throw new RuntimeException("Test argument not recognized: " + args[0]); }
 77         };
 78     }
 79 
 80     private static final int SIZE = 543;
 81 
 82     private   byte[] bytes;
 83     private  short[] shorts;
 84     private   char[] chars;

217         for (int i = 0; i < SIZE; i++) {
218             res[i] = (float) longs[i];
219         }
220         return res;
221     }
222 
223     @Test
224     @IR(applyIfCPUFeatureOr = {"asimd", "true", "avx512dq", "true", "rvv", "true"},
225         counts = {IRNode.VECTOR_CAST_L2D, IRNode.VECTOR_SIZE + "min(max_long, max_double)", ">0"})
226     public double[] convertLongToDouble() {
227         double[] res = new double[SIZE];
228         for (int i = 0; i < SIZE; i++) {
229             res[i] = (double) longs[i];
230         }
231         return res;
232     }
233 
234     // ---------------- Convert Subword-I to F/D ----------------
235     @Test
236     @IR(applyIfCPUFeatureOr = {"asimd", "true", "avx2", "true", "rvv", "true"},
237         applyIfOr = {"AlignVector", "false", "UseCompactObjectHeaders", "false"},
238         counts = {IRNode.VECTOR_CAST_S2F, IRNode.VECTOR_SIZE + "min(max_short, max_float)", ">0"})
239     public float[] convertShortToFloat() {
240         float[] res = new float[SIZE];
241         for (int i = 0; i < SIZE; i++) {
242             res[i] = (float) shorts[i];
243             // AlignVector=true requires that all vector load/store are 8-byte aligned.
244             // F_adr = base + UNSAFE.ARRAY_FLOAT_BASE_OFFSET + 4*i
245             //                = 16 (UseCompactObjectHeaders=false)    -> i % 2 = 0
246             //                = 12 (UseCompactObjectHeaders=true )    -> i % 2 = 1
247             // S_adr = base + UNSAFE.ARRAY_SHORT_BASE_OFFSET + 2*i
248             //                = 16 (UseCompactObjectHeaders=false)    -> i % 4 = 0  -> can align both
249             //                = 12 (UseCompactObjectHeaders=true )    -> i % 4 = 2  -> cannot align both
250         }
251         return res;
252     }
253 
254     @Test
255     @IR(applyIfCPUFeature = {"rvv", "true"},
256         applyIf = {"MaxVectorSize", ">=32"},
257         counts = {IRNode.VECTOR_CAST_S2D, IRNode.VECTOR_SIZE + "min(max_short, max_double)", ">0"})
258     @IR(applyIfCPUFeatureOr = {"asimd", "true", "avx", "true"},
259         applyIf = {"MaxVectorSize", ">=16"},
260         counts = {IRNode.VECTOR_CAST_S2D, IRNode.VECTOR_SIZE + "min(max_short, max_double)", ">0"})
261     public double[] convertShortToDouble() {
262         double[] res = new double[SIZE];
263         for (int i = 0; i < SIZE; i++) {
264             res[i] = (double) shorts[i];
265         }
266         return res;
267     }
268 
269     @Test

339     }
340 
341     @Test
342     @IR(applyIfCPUFeatureOr = {"asimd", "true", "avx512dq", "true", "avx10_2", "true", "rvv", "true"},
343         counts = {IRNode.VECTOR_CAST_D2L, IRNode.VECTOR_SIZE + "min(max_double, max_long)", "> 0"})
344     @IR(counts = {IRNode.X86_VCAST_D2X, "> 0"},
345         applyIfCPUFeatureAnd = {"avx512dq", "true", "avx10_2", "false"})
346     @IR(counts = {IRNode.X86_VCAST_D2X_AVX10, "> 0"},
347         applyIfCPUFeature = {"avx10_2", "true"})
348     public long[] convertDoubleToLong() {
349         long[] res = new long[SIZE];
350         for (int i = 0; i < SIZE; i++) {
351             res[i] = (long) doubles[i];
352         }
353         return res;
354     }
355 
356     // ---------------- Convert F/D to Subword-I ----------------
357     @Test
358     @IR(applyIfCPUFeatureOr = {"asimd", "true", "avx2", "true", "avx10_2", "true", "rvv", "true"},
359         applyIfOr = {"AlignVector", "false", "UseCompactObjectHeaders", "false"},
360         counts = {IRNode.VECTOR_CAST_F2S, IRNode.VECTOR_SIZE + "min(max_float, max_short)", "> 0"})
361     @IR(counts = {IRNode.X86_VCAST_F2X, "> 0"},
362         applyIfOr = {"AlignVector", "false", "UseCompactObjectHeaders", "false"},
363         applyIfCPUFeatureAnd = {"avx2", "true", "avx10_2", "false"})
364     @IR(counts = {IRNode.X86_VCAST_F2X_AVX10, "> 0"},
365         applyIfOr = {"AlignVector", "false", "UseCompactObjectHeaders", "false"},
366         applyIfCPUFeature = {"avx10_2", "true"})
367     public short[] convertFloatToShort() {
368         short[] res = new short[SIZE];
369         for (int i = 0; i < SIZE; i++) {
370             res[i] = (short) floats[i];
371             // AlignVector=true requires that all vector load/store are 8-byte aligned.
372             // F_adr = base + UNSAFE.ARRAY_FLOAT_BASE_OFFSET + 4*i
373             //                = 16 (UseCompactObjectHeaders=false)    -> i % 2 = 0
374             //                = 12 (UseCompactObjectHeaders=true )    -> i % 2 = 1
375             // S_adr = base + UNSAFE.ARRAY_SHORT_BASE_OFFSET + 2*i
376             //                = 16 (UseCompactObjectHeaders=false)    -> i % 4 = 0  -> can align both
377             //                = 12 (UseCompactObjectHeaders=true )    -> i % 4 = 2  -> cannot align both
378         }
379         return res;
380     }
381 
382     @Test
383     @IR(applyIfCPUFeatureOr = {"asimd", "true", "avx2", "true", "avx10_2", "true", "rvv", "true"},
384         applyIfOr = {"AlignVector", "false", "UseCompactObjectHeaders", "false"},
385         counts = {IRNode.VECTOR_CAST_F2S, IRNode.VECTOR_SIZE + "min(max_float, max_char)", "> 0"})
386     @IR(counts = {IRNode.X86_VCAST_F2X, "> 0"},
387         applyIfOr = {"AlignVector", "false", "UseCompactObjectHeaders", "false"},
388         applyIfCPUFeatureAnd = {"avx2", "true", "avx10_2", "false"})
389     @IR(counts = {IRNode.X86_VCAST_F2X_AVX10, "> 0"},
390         applyIfOr = {"AlignVector", "false", "UseCompactObjectHeaders", "false"},
391         applyIfCPUFeature = {"avx10_2", "true"})
392     public char[] convertFloatToChar() {
393         char[] res = new char[SIZE];
394         for (int i = 0; i < SIZE; i++) {
395             res[i] = (char) floats[i];
396             // AlignVector=true requires that all vector load/store are 8-byte aligned.
397             // F_adr = base + UNSAFE.ARRAY_FLOAT_BASE_OFFSET + 4*i
398             //                = 16 (UseCompactObjectHeaders=false)    -> i % 2 = 0
399             //                = 12 (UseCompactObjectHeaders=true )    -> i % 2 = 1
400             // S_adr = base + UNSAFE.ARRAY_SHORT_BASE_OFFSET + 2*i
401             //                = 16 (UseCompactObjectHeaders=false)    -> i % 4 = 0  -> can align both
402             //                = 12 (UseCompactObjectHeaders=true )    -> i % 4 = 2  -> cannot align both
403         }
404         return res;
405     }
406 
407     @Test
408     @IR(applyIfCPUFeature = {"rvv", "true"},
409         applyIf = {"MaxVectorSize", ">=32"},
410         counts = {IRNode.VECTOR_CAST_D2S, IRNode.VECTOR_SIZE + "min(max_double, max_short)", "> 0"})
411     @IR(applyIfCPUFeatureOr = {"sve", "true", "avx", "true", "avx10_2", "true"},
412         applyIf = {"MaxVectorSize", ">=16"},
413         counts = {IRNode.VECTOR_CAST_D2S, IRNode.VECTOR_SIZE + "min(max_double, max_short)", "> 0"})
414     @IR(counts = {IRNode.X86_VCAST_D2X, "> 0"},
415         applyIf = {"MaxVectorSize", ">=16"},
416         applyIfCPUFeatureAnd = {"avx", "true", "avx10_2", "false"})
417     @IR(counts = {IRNode.X86_VCAST_D2X_AVX10, "> 0"},
418         applyIf = {"MaxVectorSize", ">=16"},
419         applyIfCPUFeature = {"avx10_2", "true"})
420     public short[] convertDoubleToShort() {
421         short[] res = new short[SIZE];
422         for (int i = 0; i < SIZE; i++) {

 44  *                   -XX:+WhiteBoxAPI
 45  *                   compiler.vectorization.runner.ArrayTypeConvertTest nCOH_yAV
 46  *
 47  * @run main/othervm -Xbootclasspath/a:.
 48  *                   -XX:+UnlockDiagnosticVMOptions
 49  *                   -XX:+WhiteBoxAPI
 50  *                   compiler.vectorization.runner.ArrayTypeConvertTest yCOH_nAV
 51  *
 52  * @run main/othervm -Xbootclasspath/a:.
 53  *                   -XX:+UnlockDiagnosticVMOptions
 54  *                   -XX:+WhiteBoxAPI
 55  *                   compiler.vectorization.runner.ArrayTypeConvertTest yCOH_yAV
 56  */
 57 
 58 package compiler.vectorization.runner;
 59 
 60 import compiler.lib.ir_framework.*;
 61 
 62 // Explanation about AlignVector: we require 8-byte alignment of all addresses.
 63 // But the array base offset changes with UseCompactObjectHeaders.
 64 // It should, however, not affect the alignment constraints.
 65 
 66 public class ArrayTypeConvertTest extends VectorizationTestRunner {
 67 
 68     // We must pass the flags directly to the test-VM, and not the driver vm in the @run above.
 69     @Override
 70     protected String[] testVMFlags(String[] args) {
 71         return switch (args[0]) {
 72             case "nCOH_nAV" -> new String[]{"-XX:-UseCompactObjectHeaders", "-XX:-AlignVector"};
 73             case "nCOH_yAV" -> new String[]{"-XX:-UseCompactObjectHeaders", "-XX:+AlignVector"};
 74             case "yCOH_nAV" -> new String[]{"-XX:+UseCompactObjectHeaders", "-XX:-AlignVector"};
 75             case "yCOH_yAV" -> new String[]{"-XX:+UseCompactObjectHeaders", "-XX:+AlignVector"};
 76             default -> { throw new RuntimeException("Test argument not recognized: " + args[0]); }
 77         };
 78     }
 79 
 80     private static final int SIZE = 543;
 81 
 82     private   byte[] bytes;
 83     private  short[] shorts;
 84     private   char[] chars;

217         for (int i = 0; i < SIZE; i++) {
218             res[i] = (float) longs[i];
219         }
220         return res;
221     }
222 
223     @Test
224     @IR(applyIfCPUFeatureOr = {"asimd", "true", "avx512dq", "true", "rvv", "true"},
225         counts = {IRNode.VECTOR_CAST_L2D, IRNode.VECTOR_SIZE + "min(max_long, max_double)", ">0"})
226     public double[] convertLongToDouble() {
227         double[] res = new double[SIZE];
228         for (int i = 0; i < SIZE; i++) {
229             res[i] = (double) longs[i];
230         }
231         return res;
232     }
233 
234     // ---------------- Convert Subword-I to F/D ----------------
235     @Test
236     @IR(applyIfCPUFeatureOr = {"asimd", "true", "avx2", "true", "rvv", "true"},

237         counts = {IRNode.VECTOR_CAST_S2F, IRNode.VECTOR_SIZE + "min(max_short, max_float)", ">0"})
238     public float[] convertShortToFloat() {
239         float[] res = new float[SIZE];
240         for (int i = 0; i < SIZE; i++) {
241             res[i] = (float) shorts[i];







242         }
243         return res;
244     }
245 
246     @Test
247     @IR(applyIfCPUFeature = {"rvv", "true"},
248         applyIf = {"MaxVectorSize", ">=32"},
249         counts = {IRNode.VECTOR_CAST_S2D, IRNode.VECTOR_SIZE + "min(max_short, max_double)", ">0"})
250     @IR(applyIfCPUFeatureOr = {"asimd", "true", "avx", "true"},
251         applyIf = {"MaxVectorSize", ">=16"},
252         counts = {IRNode.VECTOR_CAST_S2D, IRNode.VECTOR_SIZE + "min(max_short, max_double)", ">0"})
253     public double[] convertShortToDouble() {
254         double[] res = new double[SIZE];
255         for (int i = 0; i < SIZE; i++) {
256             res[i] = (double) shorts[i];
257         }
258         return res;
259     }
260 
261     @Test

331     }
332 
333     @Test
334     @IR(applyIfCPUFeatureOr = {"asimd", "true", "avx512dq", "true", "avx10_2", "true", "rvv", "true"},
335         counts = {IRNode.VECTOR_CAST_D2L, IRNode.VECTOR_SIZE + "min(max_double, max_long)", "> 0"})
336     @IR(counts = {IRNode.X86_VCAST_D2X, "> 0"},
337         applyIfCPUFeatureAnd = {"avx512dq", "true", "avx10_2", "false"})
338     @IR(counts = {IRNode.X86_VCAST_D2X_AVX10, "> 0"},
339         applyIfCPUFeature = {"avx10_2", "true"})
340     public long[] convertDoubleToLong() {
341         long[] res = new long[SIZE];
342         for (int i = 0; i < SIZE; i++) {
343             res[i] = (long) doubles[i];
344         }
345         return res;
346     }
347 
348     // ---------------- Convert F/D to Subword-I ----------------
349     @Test
350     @IR(applyIfCPUFeatureOr = {"asimd", "true", "avx2", "true", "avx10_2", "true", "rvv", "true"},
351         applyIf = {"AlignVector", "false"},
352         counts = {IRNode.VECTOR_CAST_F2S, IRNode.VECTOR_SIZE + "min(max_float, max_short)", "> 0"})
353     @IR(counts = {IRNode.X86_VCAST_F2X, "> 0"},
354         applyIf = {"AlignVector", "false"},
355         applyIfCPUFeatureAnd = {"avx2", "true", "avx10_2", "false"})
356     @IR(counts = {IRNode.X86_VCAST_F2X_AVX10, "> 0"},
357         applyIf = {"AlignVector", "false"},
358         applyIfCPUFeature = {"avx10_2", "true"})
359     public short[] convertFloatToShort() {
360         short[] res = new short[SIZE];
361         for (int i = 0; i < SIZE; i++) {
362             res[i] = (short) floats[i];







363         }
364         return res;
365     }
366 
367     @Test
368     @IR(applyIfCPUFeatureOr = {"asimd", "true", "avx2", "true", "avx10_2", "true", "rvv", "true"},
369         applyIf = {"AlignVector", "false"},
370         counts = {IRNode.VECTOR_CAST_F2S, IRNode.VECTOR_SIZE + "min(max_float, max_char)", "> 0"})
371     @IR(counts = {IRNode.X86_VCAST_F2X, "> 0"},
372         applyIf = {"AlignVector", "false"},
373         applyIfCPUFeatureAnd = {"avx2", "true", "avx10_2", "false"})
374     @IR(counts = {IRNode.X86_VCAST_F2X_AVX10, "> 0"},
375         applyIf = {"AlignVector", "false"},
376         applyIfCPUFeature = {"avx10_2", "true"})
377     public char[] convertFloatToChar() {
378         char[] res = new char[SIZE];
379         for (int i = 0; i < SIZE; i++) {
380             res[i] = (char) floats[i];







381         }
382         return res;
383     }
384 
385     @Test
386     @IR(applyIfCPUFeature = {"rvv", "true"},
387         applyIf = {"MaxVectorSize", ">=32"},
388         counts = {IRNode.VECTOR_CAST_D2S, IRNode.VECTOR_SIZE + "min(max_double, max_short)", "> 0"})
389     @IR(applyIfCPUFeatureOr = {"sve", "true", "avx", "true", "avx10_2", "true"},
390         applyIf = {"MaxVectorSize", ">=16"},
391         counts = {IRNode.VECTOR_CAST_D2S, IRNode.VECTOR_SIZE + "min(max_double, max_short)", "> 0"})
392     @IR(counts = {IRNode.X86_VCAST_D2X, "> 0"},
393         applyIf = {"MaxVectorSize", ">=16"},
394         applyIfCPUFeatureAnd = {"avx", "true", "avx10_2", "false"})
395     @IR(counts = {IRNode.X86_VCAST_D2X_AVX10, "> 0"},
396         applyIf = {"MaxVectorSize", ">=16"},
397         applyIfCPUFeature = {"avx10_2", "true"})
398     public short[] convertDoubleToShort() {
399         short[] res = new short[SIZE];
400         for (int i = 0; i < SIZE; i++) {
< prev index next >