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:+UnlockExperimentalVMOptions", "-XX:-UseCompactObjectHeaders", "-XX:-AlignVector"};
73 case "nCOH_yAV" -> new String[]{"-XX:+UnlockExperimentalVMOptions", "-XX:-UseCompactObjectHeaders", "-XX:+AlignVector"};
74 case "yCOH_nAV" -> new String[]{"-XX:+UnlockExperimentalVMOptions", "-XX:+UseCompactObjectHeaders", "-XX:-AlignVector"};
75 case "yCOH_yAV" -> new String[]{"-XX:+UnlockExperimentalVMOptions", "-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(applyIfCPUFeatureOr = {"sve", "true", "avx2", "true", "rvv", "true"},
256 applyIf = {"MaxVectorSize", ">=32"},
257 counts = {IRNode.VECTOR_CAST_S2D, IRNode.VECTOR_SIZE + "min(max_short, max_double)", ">0"})
258 public double[] convertShortToDouble() {
259 double[] res = new double[SIZE];
260 for (int i = 0; i < SIZE; i++) {
261 res[i] = (double) shorts[i];
262 }
263 return res;
264 }
265
266 @Test
267 @IR(failOn = {IRNode.STORE_VECTOR})
268 // Subword vector casts do not work currently, see JDK-8342095.
269 // Assert the vectorization failure so that we are reminded to update
320 for (int i = 0; i < SIZE; i++) {
321 res[i] = (int) doubles[i];
322 }
323 return res;
324 }
325
326 @Test
327 @IR(applyIfCPUFeatureOr = {"asimd", "true", "avx512dq", "true", "rvv", "true"},
328 counts = {IRNode.VECTOR_CAST_D2L, IRNode.VECTOR_SIZE + "min(max_double, max_long)", ">0"})
329 public long[] convertDoubleToLong() {
330 long[] res = new long[SIZE];
331 for (int i = 0; i < SIZE; i++) {
332 res[i] = (long) doubles[i];
333 }
334 return res;
335 }
336
337 // ---------------- Convert F/D to Subword-I ----------------
338 @Test
339 @IR(applyIfCPUFeatureOr = {"asimd", "true", "avx2", "true", "rvv", "true"},
340 applyIfOr = {"AlignVector", "false", "UseCompactObjectHeaders", "false"},
341 counts = {IRNode.VECTOR_CAST_F2S, IRNode.VECTOR_SIZE + "min(max_float, max_short)", ">0"})
342 public short[] convertFloatToShort() {
343 short[] res = new short[SIZE];
344 for (int i = 0; i < SIZE; i++) {
345 res[i] = (short) floats[i];
346 // AlignVector=true requires that all vector load/store are 8-byte aligned.
347 // F_adr = base + UNSAFE.ARRAY_FLOAT_BASE_OFFSET + 4*i
348 // = 16 (UseCompactObjectHeaders=false) -> i % 2 = 0
349 // = 12 (UseCompactObjectHeaders=true ) -> i % 2 = 1
350 // S_adr = base + UNSAFE.ARRAY_SHORT_BASE_OFFSET + 2*i
351 // = 16 (UseCompactObjectHeaders=false) -> i % 4 = 0 -> can align both
352 // = 12 (UseCompactObjectHeaders=true ) -> i % 4 = 2 -> cannot align both
353 }
354 return res;
355 }
356
357 @Test
358 @IR(applyIfCPUFeatureOr = {"asimd", "true", "avx2", "true", "rvv", "true"},
359 applyIfOr = {"AlignVector", "false", "UseCompactObjectHeaders", "false"},
360 counts = {IRNode.VECTOR_CAST_F2S, IRNode.VECTOR_SIZE + "min(max_float, max_char)", ">0"})
361 public char[] convertFloatToChar() {
362 char[] res = new char[SIZE];
363 for (int i = 0; i < SIZE; i++) {
364 res[i] = (char) floats[i];
365 // AlignVector=true requires that all vector load/store are 8-byte aligned.
366 // F_adr = base + UNSAFE.ARRAY_FLOAT_BASE_OFFSET + 4*i
367 // = 16 (UseCompactObjectHeaders=false) -> i % 2 = 0
368 // = 12 (UseCompactObjectHeaders=true ) -> i % 2 = 1
369 // S_adr = base + UNSAFE.ARRAY_SHORT_BASE_OFFSET + 2*i
370 // = 16 (UseCompactObjectHeaders=false) -> i % 4 = 0 -> can align both
371 // = 12 (UseCompactObjectHeaders=true ) -> i % 4 = 2 -> cannot align both
372 }
373 return res;
374 }
375
376 @Test
377 @IR(applyIfCPUFeatureOr = {"sve", "true", "avx", "true", "rvv", "true"},
378 applyIf = {"MaxVectorSize", ">=32"},
379 counts = {IRNode.VECTOR_CAST_D2S, IRNode.VECTOR_SIZE + "min(max_double, max_short)", ">0"})
380 public short[] convertDoubleToShort() {
381 short[] res = new short[SIZE];
382 for (int i = 0; i < SIZE; i++) {
383 res[i] = (short) doubles[i];
384 }
385 return res;
386 }
387
388 @Test
389 @IR(applyIfCPUFeatureOr = {"sve", "true", "avx", "true", "rvv", "true"},
390 applyIf = {"MaxVectorSize", ">=32"},
391 counts = {IRNode.VECTOR_CAST_D2S, IRNode.VECTOR_SIZE + "min(max_double, max_char)", ">0"})
|
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:+UnlockExperimentalVMOptions", "-XX:-UseCompactObjectHeaders", "-XX:-AlignVector"};
73 case "nCOH_yAV" -> new String[]{"-XX:+UnlockExperimentalVMOptions", "-XX:-UseCompactObjectHeaders", "-XX:+AlignVector"};
74 case "yCOH_nAV" -> new String[]{"-XX:+UnlockExperimentalVMOptions", "-XX:+UseCompactObjectHeaders", "-XX:-AlignVector"};
75 case "yCOH_yAV" -> new String[]{"-XX:+UnlockExperimentalVMOptions", "-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(applyIfCPUFeatureOr = {"sve", "true", "avx2", "true", "rvv", "true"},
248 applyIf = {"MaxVectorSize", ">=32"},
249 counts = {IRNode.VECTOR_CAST_S2D, IRNode.VECTOR_SIZE + "min(max_short, max_double)", ">0"})
250 public double[] convertShortToDouble() {
251 double[] res = new double[SIZE];
252 for (int i = 0; i < SIZE; i++) {
253 res[i] = (double) shorts[i];
254 }
255 return res;
256 }
257
258 @Test
259 @IR(failOn = {IRNode.STORE_VECTOR})
260 // Subword vector casts do not work currently, see JDK-8342095.
261 // Assert the vectorization failure so that we are reminded to update
312 for (int i = 0; i < SIZE; i++) {
313 res[i] = (int) doubles[i];
314 }
315 return res;
316 }
317
318 @Test
319 @IR(applyIfCPUFeatureOr = {"asimd", "true", "avx512dq", "true", "rvv", "true"},
320 counts = {IRNode.VECTOR_CAST_D2L, IRNode.VECTOR_SIZE + "min(max_double, max_long)", ">0"})
321 public long[] convertDoubleToLong() {
322 long[] res = new long[SIZE];
323 for (int i = 0; i < SIZE; i++) {
324 res[i] = (long) doubles[i];
325 }
326 return res;
327 }
328
329 // ---------------- Convert F/D to Subword-I ----------------
330 @Test
331 @IR(applyIfCPUFeatureOr = {"asimd", "true", "avx2", "true", "rvv", "true"},
332 counts = {IRNode.VECTOR_CAST_F2S, IRNode.VECTOR_SIZE + "min(max_float, max_short)", ">0"})
333 public short[] convertFloatToShort() {
334 short[] res = new short[SIZE];
335 for (int i = 0; i < SIZE; i++) {
336 res[i] = (short) floats[i];
337 }
338 return res;
339 }
340
341 @Test
342 @IR(applyIfCPUFeatureOr = {"asimd", "true", "avx2", "true", "rvv", "true"},
343 counts = {IRNode.VECTOR_CAST_F2S, IRNode.VECTOR_SIZE + "min(max_float, max_char)", ">0"})
344 public char[] convertFloatToChar() {
345 char[] res = new char[SIZE];
346 for (int i = 0; i < SIZE; i++) {
347 res[i] = (char) floats[i];
348 }
349 return res;
350 }
351
352 @Test
353 @IR(applyIfCPUFeatureOr = {"sve", "true", "avx", "true", "rvv", "true"},
354 applyIf = {"MaxVectorSize", ">=32"},
355 counts = {IRNode.VECTOR_CAST_D2S, IRNode.VECTOR_SIZE + "min(max_double, max_short)", ">0"})
356 public short[] convertDoubleToShort() {
357 short[] res = new short[SIZE];
358 for (int i = 0; i < SIZE; i++) {
359 res[i] = (short) doubles[i];
360 }
361 return res;
362 }
363
364 @Test
365 @IR(applyIfCPUFeatureOr = {"sve", "true", "avx", "true", "rvv", "true"},
366 applyIf = {"MaxVectorSize", ">=32"},
367 counts = {IRNode.VECTOR_CAST_D2S, IRNode.VECTOR_SIZE + "min(max_double, max_char)", ">0"})
|