< prev index next >

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

Print this page

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

237         for (int i = 0; i < SIZE; i++) {
238             res[i] = (float) longs[i];
239         }
240         return res;
241     }
242 
243     @Test
244     @IR(applyIfCPUFeatureOr = {"asimd", "true", "avx512dq", "true", "rvv", "true"},
245         counts = {IRNode.VECTOR_CAST_L2D, IRNode.VECTOR_SIZE + "min(max_long, max_double)", ">0"})
246     public double[] convertLongToDouble() {
247         double[] res = new double[SIZE];
248         for (int i = 0; i < SIZE; i++) {
249             res[i] = (double) longs[i];
250         }
251         return res;
252     }
253 
254     // ---------------- Convert Subword-I to F/D ----------------
255     @Test
256     @IR(applyIfCPUFeatureOr = {"asimd", "true", "avx2", "true", "rvv", "true"},
257         applyIfOr = {"AlignVector", "false", "UseCompactObjectHeaders", "false"},
258         counts = {IRNode.VECTOR_CAST_S2F, IRNode.VECTOR_SIZE + "min(max_short, max_float)", ">0"})
259     public float[] convertShortToFloat() {
260         float[] res = new float[SIZE];
261         for (int i = 0; i < SIZE; i++) {
262             res[i] = (float) shorts[i];
263             // AlignVector=true requires that all vector load/store are 8-byte aligned.
264             // F_adr = base + UNSAFE.ARRAY_FLOAT_BASE_OFFSET + 4*i
265             //                = 16 (UseCompactObjectHeaders=false)    -> i % 2 = 0
266             //                = 12 (UseCompactObjectHeaders=true )    -> i % 2 = 1
267             // S_adr = base + UNSAFE.ARRAY_SHORT_BASE_OFFSET + 2*i
268             //                = 16 (UseCompactObjectHeaders=false)    -> i % 4 = 0  -> can align both
269             //                = 12 (UseCompactObjectHeaders=true )    -> i % 4 = 2  -> cannot align both
270         }
271         return res;
272     }
273 
274     @Test
275     @IR(applyIfCPUFeature = {"rvv", "true"},
276         applyIf = {"MaxVectorSize", ">=32"},
277         counts = {IRNode.VECTOR_CAST_S2D, IRNode.VECTOR_SIZE + "min(max_short, max_double)", ">0"})
278     @IR(applyIfCPUFeatureOr = {"asimd", "true", "avx", "true"},
279         applyIf = {"MaxVectorSize", ">=16"},
280         counts = {IRNode.VECTOR_CAST_S2D, IRNode.VECTOR_SIZE + "min(max_short, max_double)", ">0"})
281     public double[] convertShortToDouble() {
282         double[] res = new double[SIZE];
283         for (int i = 0; i < SIZE; i++) {
284             res[i] = (double) shorts[i];
285         }
286         return res;
287     }
288 
289     @Test

359     }
360 
361     @Test
362     @IR(applyIfCPUFeatureOr = {"asimd", "true", "avx512dq", "true", "avx10_2", "true", "rvv", "true"},
363         counts = {IRNode.VECTOR_CAST_D2L, IRNode.VECTOR_SIZE + "min(max_double, max_long)", "> 0"})
364     @IR(counts = {IRNode.X86_VCAST_D2X, "> 0"},
365         applyIfCPUFeatureAnd = {"avx512dq", "true", "avx10_2", "false"})
366     @IR(counts = {IRNode.X86_VCAST_D2X_AVX10_2, "> 0"},
367         applyIfCPUFeature = {"avx10_2", "true"})
368     public long[] convertDoubleToLong() {
369         long[] res = new long[SIZE];
370         for (int i = 0; i < SIZE; i++) {
371             res[i] = (long) doubles[i];
372         }
373         return res;
374     }
375 
376     // ---------------- Convert F/D to Subword-I ----------------
377     @Test
378     @IR(applyIfCPUFeatureOr = {"asimd", "true", "avx2", "true", "avx10_2", "true", "rvv", "true"},
379         applyIfOr = {"AlignVector", "false", "UseCompactObjectHeaders", "false"},
380         counts = {IRNode.VECTOR_CAST_F2S, IRNode.VECTOR_SIZE + "min(max_float, max_short)", "> 0"})
381     @IR(counts = {IRNode.X86_VCAST_F2X, "> 0"},
382         applyIfOr = {"AlignVector", "false", "UseCompactObjectHeaders", "false"},
383         applyIfCPUFeatureAnd = {"avx2", "true", "avx10_2", "false"})
384     @IR(counts = {IRNode.X86_VCAST_F2X_AVX10_2, "> 0"},
385         applyIfOr = {"AlignVector", "false", "UseCompactObjectHeaders", "false"},
386         applyIfCPUFeature = {"avx10_2", "true"})
387     public short[] convertFloatToShort() {
388         short[] res = new short[SIZE];
389         for (int i = 0; i < SIZE; i++) {
390             res[i] = (short) floats[i];
391             // AlignVector=true requires that all vector load/store are 8-byte aligned.
392             // F_adr = base + UNSAFE.ARRAY_FLOAT_BASE_OFFSET + 4*i
393             //                = 16 (UseCompactObjectHeaders=false)    -> i % 2 = 0
394             //                = 12 (UseCompactObjectHeaders=true )    -> i % 2 = 1
395             // S_adr = base + UNSAFE.ARRAY_SHORT_BASE_OFFSET + 2*i
396             //                = 16 (UseCompactObjectHeaders=false)    -> i % 4 = 0  -> can align both
397             //                = 12 (UseCompactObjectHeaders=true )    -> i % 4 = 2  -> cannot align both
398         }
399         return res;
400     }
401 
402     @Test
403     @IR(applyIfCPUFeatureOr = {"asimd", "true", "avx2", "true", "avx10_2", "true", "rvv", "true"},
404         applyIfOr = {"AlignVector", "false", "UseCompactObjectHeaders", "false"},
405         counts = {IRNode.VECTOR_CAST_F2S, IRNode.VECTOR_SIZE + "min(max_float, max_char)", "> 0"})
406     @IR(counts = {IRNode.X86_VCAST_F2X, "> 0"},
407         applyIfOr = {"AlignVector", "false", "UseCompactObjectHeaders", "false"},
408         applyIfCPUFeatureAnd = {"avx2", "true", "avx10_2", "false"})
409     @IR(counts = {IRNode.X86_VCAST_F2X_AVX10_2, "> 0"},
410         applyIfOr = {"AlignVector", "false", "UseCompactObjectHeaders", "false"},
411         applyIfCPUFeature = {"avx10_2", "true"})
412     public char[] convertFloatToChar() {
413         char[] res = new char[SIZE];
414         for (int i = 0; i < SIZE; i++) {
415             res[i] = (char) floats[i];
416             // AlignVector=true requires that all vector load/store are 8-byte aligned.
417             // F_adr = base + UNSAFE.ARRAY_FLOAT_BASE_OFFSET + 4*i
418             //                = 16 (UseCompactObjectHeaders=false)    -> i % 2 = 0
419             //                = 12 (UseCompactObjectHeaders=true )    -> i % 2 = 1
420             // S_adr = base + UNSAFE.ARRAY_SHORT_BASE_OFFSET + 2*i
421             //                = 16 (UseCompactObjectHeaders=false)    -> i % 4 = 0  -> can align both
422             //                = 12 (UseCompactObjectHeaders=true )    -> i % 4 = 2  -> cannot align both
423         }
424         return res;
425     }
426 
427     @Test
428     @IR(applyIfCPUFeature = {"rvv", "true"},
429         applyIf = {"MaxVectorSize", ">=32"},
430         counts = {IRNode.VECTOR_CAST_D2S, IRNode.VECTOR_SIZE + "min(max_double, max_short)", "> 0"})
431     @IR(applyIfCPUFeatureOr = {"sve", "true", "avx", "true", "avx10_2", "true"},
432         applyIf = {"MaxVectorSize", ">=16"},
433         counts = {IRNode.VECTOR_CAST_D2S, IRNode.VECTOR_SIZE + "min(max_double, max_short)", "> 0"})
434     @IR(counts = {IRNode.X86_VCAST_D2X, "> 0"},
435         applyIf = {"MaxVectorSize", ">=16"},
436         applyIfCPUFeatureAnd = {"avx", "true", "avx10_2", "false"})
437     @IR(counts = {IRNode.X86_VCAST_D2X_AVX10_2, "> 0"},
438         applyIf = {"MaxVectorSize", ">=16"},
439         applyIfCPUFeature = {"avx10_2", "true"})
440     public short[] convertDoubleToShort() {
441         short[] res = new short[SIZE];
442         for (int i = 0; i < SIZE; i++) {

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

237         for (int i = 0; i < SIZE; i++) {
238             res[i] = (float) longs[i];
239         }
240         return res;
241     }
242 
243     @Test
244     @IR(applyIfCPUFeatureOr = {"asimd", "true", "avx512dq", "true", "rvv", "true"},
245         counts = {IRNode.VECTOR_CAST_L2D, IRNode.VECTOR_SIZE + "min(max_long, max_double)", ">0"})
246     public double[] convertLongToDouble() {
247         double[] res = new double[SIZE];
248         for (int i = 0; i < SIZE; i++) {
249             res[i] = (double) longs[i];
250         }
251         return res;
252     }
253 
254     // ---------------- Convert Subword-I to F/D ----------------
255     @Test
256     @IR(applyIfCPUFeatureOr = {"asimd", "true", "avx2", "true", "rvv", "true"},

257         counts = {IRNode.VECTOR_CAST_S2F, IRNode.VECTOR_SIZE + "min(max_short, max_float)", ">0"})
258     public float[] convertShortToFloat() {
259         float[] res = new float[SIZE];
260         for (int i = 0; i < SIZE; i++) {
261             res[i] = (float) shorts[i];







262         }
263         return res;
264     }
265 
266     @Test
267     @IR(applyIfCPUFeature = {"rvv", "true"},
268         applyIf = {"MaxVectorSize", ">=32"},
269         counts = {IRNode.VECTOR_CAST_S2D, IRNode.VECTOR_SIZE + "min(max_short, max_double)", ">0"})
270     @IR(applyIfCPUFeatureOr = {"asimd", "true", "avx", "true"},
271         applyIf = {"MaxVectorSize", ">=16"},
272         counts = {IRNode.VECTOR_CAST_S2D, IRNode.VECTOR_SIZE + "min(max_short, max_double)", ">0"})
273     public double[] convertShortToDouble() {
274         double[] res = new double[SIZE];
275         for (int i = 0; i < SIZE; i++) {
276             res[i] = (double) shorts[i];
277         }
278         return res;
279     }
280 
281     @Test

351     }
352 
353     @Test
354     @IR(applyIfCPUFeatureOr = {"asimd", "true", "avx512dq", "true", "avx10_2", "true", "rvv", "true"},
355         counts = {IRNode.VECTOR_CAST_D2L, IRNode.VECTOR_SIZE + "min(max_double, max_long)", "> 0"})
356     @IR(counts = {IRNode.X86_VCAST_D2X, "> 0"},
357         applyIfCPUFeatureAnd = {"avx512dq", "true", "avx10_2", "false"})
358     @IR(counts = {IRNode.X86_VCAST_D2X_AVX10_2, "> 0"},
359         applyIfCPUFeature = {"avx10_2", "true"})
360     public long[] convertDoubleToLong() {
361         long[] res = new long[SIZE];
362         for (int i = 0; i < SIZE; i++) {
363             res[i] = (long) doubles[i];
364         }
365         return res;
366     }
367 
368     // ---------------- Convert F/D to Subword-I ----------------
369     @Test
370     @IR(applyIfCPUFeatureOr = {"asimd", "true", "avx2", "true", "avx10_2", "true", "rvv", "true"},
371         applyIf = {"AlignVector", "false"},
372         counts = {IRNode.VECTOR_CAST_F2S, IRNode.VECTOR_SIZE + "min(max_float, max_short)", "> 0"})
373     @IR(counts = {IRNode.X86_VCAST_F2X, "> 0"},
374         applyIf = {"AlignVector", "false"},
375         applyIfCPUFeatureAnd = {"avx2", "true", "avx10_2", "false"})
376     @IR(counts = {IRNode.X86_VCAST_F2X_AVX10_2, "> 0"},
377         applyIf = {"AlignVector", "false"},
378         applyIfCPUFeature = {"avx10_2", "true"})
379     public short[] convertFloatToShort() {
380         short[] res = new short[SIZE];
381         for (int i = 0; i < SIZE; i++) {
382             res[i] = (short) floats[i];







383         }
384         return res;
385     }
386 
387     @Test
388     @IR(applyIfCPUFeatureOr = {"asimd", "true", "avx2", "true", "avx10_2", "true", "rvv", "true"},
389         applyIf = {"AlignVector", "false"},
390         counts = {IRNode.VECTOR_CAST_F2S, IRNode.VECTOR_SIZE + "min(max_float, max_char)", "> 0"})
391     @IR(counts = {IRNode.X86_VCAST_F2X, "> 0"},
392         applyIf = {"AlignVector", "false"},
393         applyIfCPUFeatureAnd = {"avx2", "true", "avx10_2", "false"})
394     @IR(counts = {IRNode.X86_VCAST_F2X_AVX10_2, "> 0"},
395         applyIf = {"AlignVector", "false"},
396         applyIfCPUFeature = {"avx10_2", "true"})
397     public char[] convertFloatToChar() {
398         char[] res = new char[SIZE];
399         for (int i = 0; i < SIZE; i++) {
400             res[i] = (char) floats[i];







401         }
402         return res;
403     }
404 
405     @Test
406     @IR(applyIfCPUFeature = {"rvv", "true"},
407         applyIf = {"MaxVectorSize", ">=32"},
408         counts = {IRNode.VECTOR_CAST_D2S, IRNode.VECTOR_SIZE + "min(max_double, max_short)", "> 0"})
409     @IR(applyIfCPUFeatureOr = {"sve", "true", "avx", "true", "avx10_2", "true"},
410         applyIf = {"MaxVectorSize", ">=16"},
411         counts = {IRNode.VECTOR_CAST_D2S, IRNode.VECTOR_SIZE + "min(max_double, max_short)", "> 0"})
412     @IR(counts = {IRNode.X86_VCAST_D2X, "> 0"},
413         applyIf = {"MaxVectorSize", ">=16"},
414         applyIfCPUFeatureAnd = {"avx", "true", "avx10_2", "false"})
415     @IR(counts = {IRNode.X86_VCAST_D2X_AVX10_2, "> 0"},
416         applyIf = {"MaxVectorSize", ">=16"},
417         applyIfCPUFeature = {"avx10_2", "true"})
418     public short[] convertDoubleToShort() {
419         short[] res = new short[SIZE];
420         for (int i = 0; i < SIZE; i++) {
< prev index next >