72 public class $vectorteststype$ extends AbstractVectorTest {
73
74 #if[MaxBit]
75 static final VectorSpecies<$Wideboxtype$> SPECIES =
76 $Type$Vector.SPECIES_MAX;
77 #else[MaxBit]
78 static final VectorSpecies<$Wideboxtype$> SPECIES =
79 $Type$Vector.SPECIES_$bits$;
80 #end[MaxBit]
81
82 static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100);
83
84 #if[MaxBit]
85 static VectorShape getMaxBit() {
86 return VectorShape.S_Max_BIT;
87 }
88
89 private static final int Max = 256; // juts so we can do N/$bits$
90 #end[MaxBit]
91
92 private static final $type$ CONST_SHIFT = $Boxtype$.SIZE / 2;
93
94 static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / $bits$);
95
96 interface FUnOp {
97 $type$ apply($type$ a);
98 }
99
100 static void assertArraysEquals($type$[] r, $type$[] a, FUnOp f) {
101 int i = 0;
102 try {
103 for (; i < a.length; i++) {
104 Assert.assertEquals(r[i], f.apply(a[i]));
105 }
106 } catch (AssertionError e) {
107 Assert.assertEquals(r[i], f.apply(a[i]), "at index #" + i + ", input = " + a[i]);
108 }
109 }
110
111 interface FUnArrayOp {
112 $type$[] apply($type$ a);
275 } else {
276 Assert.assertEquals(r[i], a[i], "at index #" + i);
277 }
278 }
279 }
280
281 static void assertRearrangeArraysEquals($type$[] r, $type$[] a, int[] order, int vector_len) {
282 int i = 0, j = 0;
283 try {
284 for (; i < a.length; i += vector_len) {
285 for (j = 0; j < vector_len; j++) {
286 Assert.assertEquals(r[i+j], a[i+order[i+j]]);
287 }
288 }
289 } catch (AssertionError e) {
290 int idx = i + j;
291 Assert.assertEquals(r[i+j], a[i+order[i+j]], "at index #" + idx + ", input = " + a[i+order[i+j]]);
292 }
293 }
294
295 static void assertSelectFromArraysEquals($type$[] r, $type$[] a, $type$[] order, int vector_len) {
296 int i = 0, j = 0;
297 try {
298 for (; i < a.length; i += vector_len) {
299 for (j = 0; j < vector_len; j++) {
300 Assert.assertEquals(r[i+j], a[i+(int)order[i+j]]);
301 }
302 }
303 } catch (AssertionError e) {
304 int idx = i + j;
305 Assert.assertEquals(r[i+j], a[i+(int)order[i+j]], "at index #" + idx + ", input = " + a[i+(int)order[i+j]]);
306 }
307 }
308
309 static void assertRearrangeArraysEquals($type$[] r, $type$[] a, int[] order, boolean[] mask, int vector_len) {
310 int i = 0, j = 0;
311 try {
312 for (; i < a.length; i += vector_len) {
313 for (j = 0; j < vector_len; j++) {
314 if (mask[j % SPECIES.length()])
1048 try {
1049 for (; i < r.length; i++) {
1050 Assert.assertEquals(r[i], (long)(a[i+offs]));
1051 }
1052 } catch (AssertionError e) {
1053 Assert.assertEquals(r[i], (long)(a[i+offs]), "at index #" + i + ", input = " + a[i+offs]);
1054 }
1055 }
1056 #end[byte]
1057
1058 static void assertArraysEquals(long[] r, $type$[] a, int offs) {
1059 int i = 0;
1060 try {
1061 for (; i < r.length; i++) {
1062 Assert.assertEquals(r[i], (long)(a[i+offs]));
1063 }
1064 } catch (AssertionError e) {
1065 Assert.assertEquals(r[i], (long)(a[i+offs]), "at index #" + i + ", input = " + a[i+offs]);
1066 }
1067 }
1068
1069 #if[!Double]
1070 static void assertArraysEquals(double[] r, $type$[] a, int offs) {
1071 int i = 0;
1072 try {
1073 for (; i < r.length; i++) {
1074 Assert.assertEquals(r[i], (double)(a[i+offs]));
1075 }
1076 } catch (AssertionError e) {
1077 Assert.assertEquals(r[i], (double)(a[i+offs]), "at index #" + i + ", input = " + a[i+offs]);
1078 }
1079 }
1080 #end[!Double]
1081
1082
1083 static $bitstype$ bits($type$ e) {
1084 return {#if[FP]? $Type$.$type$To$Bitstype$Bits(e): e};
1085 }
1086
1087 static final List<IntFunction<$type$[]>> $TYPE$_GENERATORS = List.of(
1088 withToString("$type$[-i * 5]", (int s) -> {
1089 return fill(s * BUFFER_REPS,
1090 i -> ($type$)(-i * 5));
1091 }),
1092 withToString("$type$[i * 5]", (int s) -> {
1093 return fill(s * BUFFER_REPS,
1094 i -> ($type$)(i * 5));
1095 }),
1096 withToString("$type$[i + 1]", (int s) -> {
1097 return fill(s * BUFFER_REPS,
1098 i -> ((($type$)(i + 1) == 0) ? 1 : ($type$)(i + 1)));
1099 }),
1100 withToString("$type$[cornerCaseValue(i)]", (int s) -> {
1101 return fill(s * BUFFER_REPS,
1102 i -> cornerCaseValue(i));
1156 return Stream.concat(lfa.stream(), Stream.of(fm)).toArray();
1157 })).
1158 toArray(Object[][]::new);
1159 }
1160
1161 @DataProvider
1162 public Object[][] $type$UnaryOpProvider() {
1163 return $TYPE$_GENERATORS.stream().
1164 map(f -> new Object[]{f}).
1165 toArray(Object[][]::new);
1166 }
1167
1168 @DataProvider
1169 public Object[][] $type$UnaryOpMaskProvider() {
1170 return BOOLEAN_MASK_GENERATORS.stream().
1171 flatMap(fm -> $TYPE$_GENERATORS.stream().map(fa -> {
1172 return new Object[] {fa, fm};
1173 })).
1174 toArray(Object[][]::new);
1175 }
1176
1177 #if[!Int]
1178 #if[!byteOrShort]
1179 @DataProvider
1180 public Object[][] $type$toIntUnaryOpProvider() {
1181 return INT_$TYPE$_GENERATORS.stream().
1182 map(f -> new Object[]{f}).
1183 toArray(Object[][]::new);
1184 }
1185 #end[!byteOrShort]
1186 #end[!Int]
1187
1188 #if[FP]
1189 @DataProvider
1190 public Object[][] $type$toLongUnaryOpProvider() {
1191 return LONG_$TYPE$_GENERATORS.stream().
1192 map(f -> new Object[]{f}).
1193 toArray(Object[][]::new);
1194 }
1195 #end[FP]
1196
1197 @DataProvider
1198 public Object[][] maskProvider() {
1199 return BOOLEAN_MASK_GENERATORS.stream().
1200 map(f -> new Object[]{f}).
1201 toArray(Object[][]::new);
1202 }
1203
1204 @DataProvider
1205 public Object[][] maskCompareOpProvider() {
1206 return BOOLEAN_MASK_COMPARE_GENERATOR_PAIRS.stream().map(List::toArray).
1207 toArray(Object[][]::new);
1208 }
1221 }
1222
1223 @DataProvider
1224 public Object[][] $type$UnaryOpShuffleProvider() {
1225 return INT_SHUFFLE_GENERATORS.stream().
1226 flatMap(fs -> $TYPE$_GENERATORS.stream().map(fa -> {
1227 return new Object[] {fa, fs};
1228 })).
1229 toArray(Object[][]::new);
1230 }
1231
1232 @DataProvider
1233 public Object[][] $type$UnaryOpShuffleMaskProvider() {
1234 return BOOLEAN_MASK_GENERATORS.stream().
1235 flatMap(fm -> INT_SHUFFLE_GENERATORS.stream().
1236 flatMap(fs -> $TYPE$_GENERATORS.stream().map(fa -> {
1237 return new Object[] {fa, fs, fm};
1238 }))).
1239 toArray(Object[][]::new);
1240 }
1241
1242 #if[!Int]
1243 static final List<BiFunction<Integer,Integer,$type$[]>> $TYPE$_SHUFFLE_GENERATORS = List.of(
1244 withToStringBi("shuffle[random]", (Integer l, Integer m) -> {
1245 $type$[] a = new $type$[l];
1246 #if[ByteMax]
1247 int upper = Math.min(Byte.MAX_VALUE + 1, m);
1248 #else[ByteMax]
1249 int upper = m;
1250 #end[ByteMax]
1251 for (int i = 0; i < 1; i++) {
1252 a[i] = ($type$)RAND.nextInt(upper);
1253 }
1254 return a;
1255 })
1256 );
1257
1258 @DataProvider
1259 public Object[][] $type$UnaryOpSelectFromProvider() {
1260 return $TYPE$_SHUFFLE_GENERATORS.stream().
1261 flatMap(fs -> $TYPE$_GENERATORS.stream().map(fa -> {
1262 return new Object[] {fa, fs};
1263 })).
1264 toArray(Object[][]::new);
1265 }
1266
1267 @DataProvider
1268 public Object[][] $type$UnaryOpSelectFromMaskProvider() {
1269 return BOOLEAN_MASK_GENERATORS.stream().
1270 flatMap(fm -> $TYPE$_SHUFFLE_GENERATORS.stream().
1271 flatMap(fs -> $TYPE$_GENERATORS.stream().map(fa -> {
1272 return new Object[] {fa, fs, fm};
1273 }))).
1274 toArray(Object[][]::new);
1275 }
1276
1277 #end[!Int]
1278
1279 static final List<IntFunction<$type$[]>> $TYPE$_COMPARE_GENERATORS = List.of(
1280 withToString("$type$[i]", (int s) -> {
1281 return fill(s * BUFFER_REPS,
1282 i -> ($type$)i);
1283 }),
1284 withToString("$type$[i - length / 2]", (int s) -> {
1285 return fill(s * BUFFER_REPS,
1286 i -> ($type$)(i - (s * BUFFER_REPS / 2)));
1287 }),
1288 withToString("$type$[i + 1]", (int s) -> {
1289 return fill(s * BUFFER_REPS,
1290 i -> ($type$)(i + 1));
1291 }),
1292 withToString("$type$[i - 2]", (int s) -> {
1293 return fill(s * BUFFER_REPS,
1294 i -> ($type$)(i - 2));
1295 }),
1296 withToString("$type$[zigZag(i)]", (int s) -> {
1388 return $Wideboxtype$.MAX_VALUE;
1389 default:
1390 return ($type$)0;
1391 }
1392 #end[FP]
1393 }
1394
1395 static $type$ get($type$[] a, int i) {
1396 return ($type$) a[i];
1397 }
1398
1399 static final IntFunction<$type$[]> fr = (vl) -> {
1400 int length = BUFFER_REPS * vl;
1401 return new $type$[length];
1402 };
1403
1404 static final IntFunction<boolean[]> fmr = (vl) -> {
1405 int length = BUFFER_REPS * vl;
1406 return new boolean[length];
1407 };
1408
1409 #if[!Long]
1410 static final IntFunction<long[]> lfr = (vl) -> {
1411 int length = BUFFER_REPS * vl;
1412 return new long[length];
1413 };
1414 #end[!Long]
1415
1416 #if[BITWISE]
1417 static void replaceZero($type$[] a, $type$ v) {
1418 for (int i = 0; i < a.length; i++) {
1419 if (a[i] == 0) {
1420 a[i] = v;
1421 }
1422 }
1423 }
1424
1425 static void replaceZero($type$[] a, boolean[] mask, $type$ v) {
1426 for (int i = 0; i < a.length; i++) {
1427 if (mask[i % mask.length] && a[i] == 0) {
1428 a[i] = v;
1429 }
1430 }
1431 }
1432
1433 static $type$ ROL_scalar($type$ a, $type$ b) {
1434 #if[intOrLong]
1435 return $Wideboxtype$.rotateLeft(a, ((int)b));
1436 #else[intOrLong]
1437 #if[short]
1438 return (short)(((((short)a) & 0xFFFF) << (b & 15)) | ((((short)a) & 0xFFFF) >>> (16 - (b & 15))));
1439 #else[short]
1440 return (byte)(((((byte)a) & 0xFF) << (b & 7)) | ((((byte)a) & 0xFF) >>> (8 - (b & 7))));
1441 #end[short]
1442 #end[intOrLong]
1443 }
1444
1445 static $type$ ROR_scalar($type$ a, $type$ b) {
1446 #if[intOrLong]
1447 return $Wideboxtype$.rotateRight(a, ((int)b));
1448 #else[intOrLong]
1449 #if[short]
1450 return (short)(((((short)a) & 0xFFFF) >>> (b & 15)) | ((((short)a) & 0xFFFF) << (16 - (b & 15))));
1451 #else[short]
1452 return (byte)(((((byte)a) & 0xFF) >>> (b & 7)) | ((((byte)a) & 0xFF) << (8 - (b & 7))));
1453 #end[short]
1454 #end[intOrLong]
1455 }
1456 #end[BITWISE]
1457
1458 static boolean eq($type$ a, $type$ b) {
1459 return a == b;
1460 }
1461
1462 static boolean neq($type$ a, $type$ b) {
1463 return a != b;
1464 }
1465
1466 static boolean lt($type$ a, $type$ b) {
1467 return a < b;
1468 }
1469
1470 static boolean le($type$ a, $type$ b) {
1471 return a <= b;
1472 }
1473
1474 static boolean gt($type$ a, $type$ b) {
1475 return a > b;
1476 }
1477
1478 static boolean ge($type$ a, $type$ b) {
1479 return a >= b;
1480 }
1481
1482 #if[!FP]
1483 static boolean ult($type$ a, $type$ b) {
1484 return $Boxtype$.compareUnsigned(a, b) < 0;
1485 }
1486
1487 static boolean ule($type$ a, $type$ b) {
1488 return $Boxtype$.compareUnsigned(a, b) <= 0;
1489 }
1490
1491 static boolean ugt($type$ a, $type$ b) {
1492 return $Boxtype$.compareUnsigned(a, b) > 0;
1493 }
1494
1495 static boolean uge($type$ a, $type$ b) {
1496 return $Boxtype$.compareUnsigned(a, b) >= 0;
1497 }
1498 #end[!FP]
1499
1500 static $type$ firstNonZero($type$ a, $type$ b) {
1501 return $Boxtype$.compare(a, ($type$) 0) != 0 ? a : b;
1502 }
1576 // To test backend instructions, make sure that C2 is used.
1577 for (int loop = 0; loop < INVOC_COUNT * INVOC_COUNT; loop++) {
1578 iotaShuffle();
1579 }
1580 }
1581
1582 @Test
1583 void viewAsIntegeralLanesTest() {
1584 #if[FP]
1585 Vector<?> asIntegral = SPECIES.zero().viewAsIntegralLanes();
1586 VectorSpecies<?> asIntegralSpecies = asIntegral.species();
1587 Assert.assertNotEquals(asIntegralSpecies.elementType(), SPECIES.elementType());
1588 Assert.assertEquals(asIntegralSpecies.vectorShape(), SPECIES.vectorShape());
1589 Assert.assertEquals(asIntegralSpecies.length(), SPECIES.length());
1590 Assert.assertEquals(asIntegral.viewAsFloatingLanes().species(), SPECIES);
1591 #else[FP]
1592 Vector<?> asIntegral = SPECIES.zero().viewAsIntegralLanes();
1593 Assert.assertEquals(asIntegral.species(), SPECIES);
1594 #end[FP]
1595 }
1596
1597 #if[FP]
1598 @Test
1599 void viewAsFloatingLanesTest() {
1600 Vector<?> asFloating = SPECIES.zero().viewAsFloatingLanes();
1601 Assert.assertEquals(asFloating.species(), SPECIES);
1602 }
1603 #else[FP]
1604 #if[byteOrShort]
1605 @Test(expectedExceptions = UnsupportedOperationException.class)
1606 void viewAsFloatingLanesTest() {
1607 SPECIES.zero().viewAsFloatingLanes();
1608 }
1609 #else[byteOrShort]
1610 @Test
1611 void viewAsFloatingLanesTest() {
1612 Vector<?> asFloating = SPECIES.zero().viewAsFloatingLanes();
1613 VectorSpecies<?> asFloatingSpecies = asFloating.species();
1614 Assert.assertNotEquals(asFloatingSpecies.elementType(), SPECIES.elementType());
1615 Assert.assertEquals(asFloatingSpecies.vectorShape(), SPECIES.vectorShape());
1616 Assert.assertEquals(asFloatingSpecies.length(), SPECIES.length());
1617 Assert.assertEquals(asFloating.viewAsIntegralLanes().species(), SPECIES);
1618 }
1619 #end[byteOrShort]
1620 #end[FP]
1621
1622 #if[BITWISE]
1623 @Test
1624 // Test div by 0.
1625 static void bitwiseDivByZeroSmokeTest() {
1626 try {
1627 $abstractvectortype$ a = ($abstractvectortype$) SPECIES.broadcast(0).addIndex(1);
1628 $abstractvectortype$ b = ($abstractvectortype$) SPECIES.broadcast(0);
1629 a.div(b);
1630 Assert.fail();
1631 } catch (ArithmeticException e) {
1632 }
1633
1634 try {
1635 $abstractvectortype$ a = ($abstractvectortype$) SPECIES.broadcast(0).addIndex(1);
1636 $abstractvectortype$ b = ($abstractvectortype$) SPECIES.broadcast(0);
1637 VectorMask<$Boxtype$> m = a.lt(($type$) 1);
1638 a.div(b, m);
1639 Assert.fail();
1640 } catch (ArithmeticException e) {
1641 }
1642 }
|
72 public class $vectorteststype$ extends AbstractVectorTest {
73
74 #if[MaxBit]
75 static final VectorSpecies<$Wideboxtype$> SPECIES =
76 $Type$Vector.SPECIES_MAX;
77 #else[MaxBit]
78 static final VectorSpecies<$Wideboxtype$> SPECIES =
79 $Type$Vector.SPECIES_$bits$;
80 #end[MaxBit]
81
82 static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100);
83
84 #if[MaxBit]
85 static VectorShape getMaxBit() {
86 return VectorShape.S_Max_BIT;
87 }
88
89 private static final int Max = 256; // juts so we can do N/$bits$
90 #end[MaxBit]
91
92 #if[BITWISE]
93 private static final $type$ CONST_SHIFT = $Boxtype$.SIZE / 2;
94 #end[BITWISE]
95
96 static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / $bits$);
97
98 interface FUnOp {
99 $type$ apply($type$ a);
100 }
101
102 static void assertArraysEquals($type$[] r, $type$[] a, FUnOp f) {
103 int i = 0;
104 try {
105 for (; i < a.length; i++) {
106 Assert.assertEquals(r[i], f.apply(a[i]));
107 }
108 } catch (AssertionError e) {
109 Assert.assertEquals(r[i], f.apply(a[i]), "at index #" + i + ", input = " + a[i]);
110 }
111 }
112
113 interface FUnArrayOp {
114 $type$[] apply($type$ a);
277 } else {
278 Assert.assertEquals(r[i], a[i], "at index #" + i);
279 }
280 }
281 }
282
283 static void assertRearrangeArraysEquals($type$[] r, $type$[] a, int[] order, int vector_len) {
284 int i = 0, j = 0;
285 try {
286 for (; i < a.length; i += vector_len) {
287 for (j = 0; j < vector_len; j++) {
288 Assert.assertEquals(r[i+j], a[i+order[i+j]]);
289 }
290 }
291 } catch (AssertionError e) {
292 int idx = i + j;
293 Assert.assertEquals(r[i+j], a[i+order[i+j]], "at index #" + idx + ", input = " + a[i+order[i+j]]);
294 }
295 }
296
297 static void assertcompressArraysEquals($type$[] r, $type$[] a, boolean[] m, int vector_len) {
298 int i = 0, j = 0, k = 0;
299 try {
300 for (; i < a.length; i += vector_len) {
301 k = 0;
302 for (j = 0; j < vector_len; j++) {
303 if (m[(i + j) % SPECIES.length()]) {
304 Assert.assertEquals(r[i + k], a[i + j]);
305 k++;
306 }
307 }
308 for (; k < vector_len; k++) {
309 Assert.assertEquals(r[i + k], ($type$)0);
310 }
311 }
312 } catch (AssertionError e) {
313 int idx = i + k;
314 if (m[(i + j) % SPECIES.length()]) {
315 Assert.assertEquals(r[idx], a[i + j], "at index #" + idx);
316 } else {
317 Assert.assertEquals(r[idx], ($type$)0, "at index #" + idx);
318 }
319 }
320 }
321
322 static void assertexpandArraysEquals($type$[] r, $type$[] a, boolean[] m, int vector_len) {
323 int i = 0, j = 0, k = 0;
324 try {
325 for (; i < a.length; i += vector_len) {
326 k = 0;
327 for (j = 0; j < vector_len; j++) {
328 if (m[(i + j) % SPECIES.length()]) {
329 Assert.assertEquals(r[i + j], a[i + k]);
330 k++;
331 } else {
332 Assert.assertEquals(r[i + j], ($type$)0);
333 }
334 }
335 }
336 } catch (AssertionError e) {
337 int idx = i + j;
338 if (m[idx % SPECIES.length()]) {
339 Assert.assertEquals(r[idx], a[i + k], "at index #" + idx);
340 } else {
341 Assert.assertEquals(r[idx], ($type$)0, "at index #" + idx);
342 }
343 }
344 }
345
346 static void assertSelectFromArraysEquals($type$[] r, $type$[] a, $type$[] order, int vector_len) {
347 int i = 0, j = 0;
348 try {
349 for (; i < a.length; i += vector_len) {
350 for (j = 0; j < vector_len; j++) {
351 Assert.assertEquals(r[i+j], a[i+(int)order[i+j]]);
352 }
353 }
354 } catch (AssertionError e) {
355 int idx = i + j;
356 Assert.assertEquals(r[i+j], a[i+(int)order[i+j]], "at index #" + idx + ", input = " + a[i+(int)order[i+j]]);
357 }
358 }
359
360 static void assertRearrangeArraysEquals($type$[] r, $type$[] a, int[] order, boolean[] mask, int vector_len) {
361 int i = 0, j = 0;
362 try {
363 for (; i < a.length; i += vector_len) {
364 for (j = 0; j < vector_len; j++) {
365 if (mask[j % SPECIES.length()])
1099 try {
1100 for (; i < r.length; i++) {
1101 Assert.assertEquals(r[i], (long)(a[i+offs]));
1102 }
1103 } catch (AssertionError e) {
1104 Assert.assertEquals(r[i], (long)(a[i+offs]), "at index #" + i + ", input = " + a[i+offs]);
1105 }
1106 }
1107 #end[byte]
1108
1109 static void assertArraysEquals(long[] r, $type$[] a, int offs) {
1110 int i = 0;
1111 try {
1112 for (; i < r.length; i++) {
1113 Assert.assertEquals(r[i], (long)(a[i+offs]));
1114 }
1115 } catch (AssertionError e) {
1116 Assert.assertEquals(r[i], (long)(a[i+offs]), "at index #" + i + ", input = " + a[i+offs]);
1117 }
1118 }
1119 #if[!Double]
1120
1121 static void assertArraysEquals(double[] r, $type$[] a, int offs) {
1122 int i = 0;
1123 try {
1124 for (; i < r.length; i++) {
1125 Assert.assertEquals(r[i], (double)(a[i+offs]));
1126 }
1127 } catch (AssertionError e) {
1128 Assert.assertEquals(r[i], (double)(a[i+offs]), "at index #" + i + ", input = " + a[i+offs]);
1129 }
1130 }
1131 #end[!Double]
1132
1133 static $bitstype$ bits($type$ e) {
1134 return {#if[FP]? $Type$.$type$To$Bitstype$Bits(e): e};
1135 }
1136
1137 static final List<IntFunction<$type$[]>> $TYPE$_GENERATORS = List.of(
1138 withToString("$type$[-i * 5]", (int s) -> {
1139 return fill(s * BUFFER_REPS,
1140 i -> ($type$)(-i * 5));
1141 }),
1142 withToString("$type$[i * 5]", (int s) -> {
1143 return fill(s * BUFFER_REPS,
1144 i -> ($type$)(i * 5));
1145 }),
1146 withToString("$type$[i + 1]", (int s) -> {
1147 return fill(s * BUFFER_REPS,
1148 i -> ((($type$)(i + 1) == 0) ? 1 : ($type$)(i + 1)));
1149 }),
1150 withToString("$type$[cornerCaseValue(i)]", (int s) -> {
1151 return fill(s * BUFFER_REPS,
1152 i -> cornerCaseValue(i));
1206 return Stream.concat(lfa.stream(), Stream.of(fm)).toArray();
1207 })).
1208 toArray(Object[][]::new);
1209 }
1210
1211 @DataProvider
1212 public Object[][] $type$UnaryOpProvider() {
1213 return $TYPE$_GENERATORS.stream().
1214 map(f -> new Object[]{f}).
1215 toArray(Object[][]::new);
1216 }
1217
1218 @DataProvider
1219 public Object[][] $type$UnaryOpMaskProvider() {
1220 return BOOLEAN_MASK_GENERATORS.stream().
1221 flatMap(fm -> $TYPE$_GENERATORS.stream().map(fa -> {
1222 return new Object[] {fa, fm};
1223 })).
1224 toArray(Object[][]::new);
1225 }
1226 #if[!Int]
1227 #if[!byteOrShort]
1228
1229 @DataProvider
1230 public Object[][] $type$toIntUnaryOpProvider() {
1231 return INT_$TYPE$_GENERATORS.stream().
1232 map(f -> new Object[]{f}).
1233 toArray(Object[][]::new);
1234 }
1235 #end[!byteOrShort]
1236 #end[!Int]
1237 #if[FP]
1238
1239 @DataProvider
1240 public Object[][] $type$toLongUnaryOpProvider() {
1241 return LONG_$TYPE$_GENERATORS.stream().
1242 map(f -> new Object[]{f}).
1243 toArray(Object[][]::new);
1244 }
1245 #end[FP]
1246
1247 @DataProvider
1248 public Object[][] maskProvider() {
1249 return BOOLEAN_MASK_GENERATORS.stream().
1250 map(f -> new Object[]{f}).
1251 toArray(Object[][]::new);
1252 }
1253
1254 @DataProvider
1255 public Object[][] maskCompareOpProvider() {
1256 return BOOLEAN_MASK_COMPARE_GENERATOR_PAIRS.stream().map(List::toArray).
1257 toArray(Object[][]::new);
1258 }
1271 }
1272
1273 @DataProvider
1274 public Object[][] $type$UnaryOpShuffleProvider() {
1275 return INT_SHUFFLE_GENERATORS.stream().
1276 flatMap(fs -> $TYPE$_GENERATORS.stream().map(fa -> {
1277 return new Object[] {fa, fs};
1278 })).
1279 toArray(Object[][]::new);
1280 }
1281
1282 @DataProvider
1283 public Object[][] $type$UnaryOpShuffleMaskProvider() {
1284 return BOOLEAN_MASK_GENERATORS.stream().
1285 flatMap(fm -> INT_SHUFFLE_GENERATORS.stream().
1286 flatMap(fs -> $TYPE$_GENERATORS.stream().map(fa -> {
1287 return new Object[] {fa, fs, fm};
1288 }))).
1289 toArray(Object[][]::new);
1290 }
1291 #if[!Int]
1292
1293 static final List<BiFunction<Integer,Integer,$type$[]>> $TYPE$_SHUFFLE_GENERATORS = List.of(
1294 withToStringBi("shuffle[random]", (Integer l, Integer m) -> {
1295 $type$[] a = new $type$[l];
1296 #if[ByteMax]
1297 int upper = Math.min(Byte.MAX_VALUE + 1, m);
1298 #else[ByteMax]
1299 int upper = m;
1300 #end[ByteMax]
1301 for (int i = 0; i < 1; i++) {
1302 a[i] = ($type$)RAND.nextInt(upper);
1303 }
1304 return a;
1305 })
1306 );
1307
1308 @DataProvider
1309 public Object[][] $type$UnaryOpSelectFromProvider() {
1310 return $TYPE$_SHUFFLE_GENERATORS.stream().
1311 flatMap(fs -> $TYPE$_GENERATORS.stream().map(fa -> {
1312 return new Object[] {fa, fs};
1313 })).
1314 toArray(Object[][]::new);
1315 }
1316
1317 @DataProvider
1318 public Object[][] $type$UnaryOpSelectFromMaskProvider() {
1319 return BOOLEAN_MASK_GENERATORS.stream().
1320 flatMap(fm -> $TYPE$_SHUFFLE_GENERATORS.stream().
1321 flatMap(fs -> $TYPE$_GENERATORS.stream().map(fa -> {
1322 return new Object[] {fa, fs, fm};
1323 }))).
1324 toArray(Object[][]::new);
1325 }
1326 #end[!Int]
1327
1328 static final List<IntFunction<$type$[]>> $TYPE$_COMPARE_GENERATORS = List.of(
1329 withToString("$type$[i]", (int s) -> {
1330 return fill(s * BUFFER_REPS,
1331 i -> ($type$)i);
1332 }),
1333 withToString("$type$[i - length / 2]", (int s) -> {
1334 return fill(s * BUFFER_REPS,
1335 i -> ($type$)(i - (s * BUFFER_REPS / 2)));
1336 }),
1337 withToString("$type$[i + 1]", (int s) -> {
1338 return fill(s * BUFFER_REPS,
1339 i -> ($type$)(i + 1));
1340 }),
1341 withToString("$type$[i - 2]", (int s) -> {
1342 return fill(s * BUFFER_REPS,
1343 i -> ($type$)(i - 2));
1344 }),
1345 withToString("$type$[zigZag(i)]", (int s) -> {
1437 return $Wideboxtype$.MAX_VALUE;
1438 default:
1439 return ($type$)0;
1440 }
1441 #end[FP]
1442 }
1443
1444 static $type$ get($type$[] a, int i) {
1445 return ($type$) a[i];
1446 }
1447
1448 static final IntFunction<$type$[]> fr = (vl) -> {
1449 int length = BUFFER_REPS * vl;
1450 return new $type$[length];
1451 };
1452
1453 static final IntFunction<boolean[]> fmr = (vl) -> {
1454 int length = BUFFER_REPS * vl;
1455 return new boolean[length];
1456 };
1457 #if[!Long]
1458
1459 static final IntFunction<long[]> lfr = (vl) -> {
1460 int length = BUFFER_REPS * vl;
1461 return new long[length];
1462 };
1463 #end[!Long]
1464 #if[BITWISE]
1465
1466 static void replaceZero($type$[] a, $type$ v) {
1467 for (int i = 0; i < a.length; i++) {
1468 if (a[i] == 0) {
1469 a[i] = v;
1470 }
1471 }
1472 }
1473
1474 static void replaceZero($type$[] a, boolean[] mask, $type$ v) {
1475 for (int i = 0; i < a.length; i++) {
1476 if (mask[i % mask.length] && a[i] == 0) {
1477 a[i] = v;
1478 }
1479 }
1480 }
1481
1482 static $type$ ROL_scalar($type$ a, $type$ b) {
1483 #if[intOrLong]
1484 return $Wideboxtype$.rotateLeft(a, ((int)b));
1485 #else[intOrLong]
1486 #if[short]
1487 return (short)(((((short)a) & 0xFFFF) << (b & 15)) | ((((short)a) & 0xFFFF) >>> (16 - (b & 15))));
1488 #else[short]
1489 return (byte)(((((byte)a) & 0xFF) << (b & 7)) | ((((byte)a) & 0xFF) >>> (8 - (b & 7))));
1490 #end[short]
1491 #end[intOrLong]
1492 }
1493
1494 static $type$ ROR_scalar($type$ a, $type$ b) {
1495 #if[intOrLong]
1496 return $Wideboxtype$.rotateRight(a, ((int)b));
1497 #else[intOrLong]
1498 #if[short]
1499 return (short)(((((short)a) & 0xFFFF) >>> (b & 15)) | ((((short)a) & 0xFFFF) << (16 - (b & 15))));
1500 #else[short]
1501 return (byte)(((((byte)a) & 0xFF) >>> (b & 7)) | ((((byte)a) & 0xFF) << (8 - (b & 7))));
1502 #end[short]
1503 #end[intOrLong]
1504 }
1505
1506 static $type$ TRAILING_ZEROS_COUNT_scalar($type$ a) {
1507 #if[intOrLong]
1508 return $Wideboxtype$.numberOfTrailingZeros(a);
1509 #else[intOrLong]
1510 #if[short]
1511 return (short) (a != 0 ? Integer.numberOfTrailingZeros(a) : 16);
1512 #else[short]
1513 return (byte) (a != 0 ? Integer.numberOfTrailingZeros(a) : 8);
1514 #end[short]
1515 #end[intOrLong]
1516 }
1517
1518 static $type$ LEADING_ZEROS_COUNT_scalar($type$ a) {
1519 #if[intOrLong]
1520 return $Wideboxtype$.numberOfLeadingZeros(a);
1521 #else[intOrLong]
1522 #if[short]
1523 return (short) (a >= 0 ? Integer.numberOfLeadingZeros(a) - 16 : 0);
1524 #else[short]
1525 return (byte) (a >= 0 ? Integer.numberOfLeadingZeros(a) - 24 : 0);
1526 #end[short]
1527 #end[intOrLong]
1528 }
1529
1530 static $type$ REVERSE_scalar($type$ a) {
1531 #if[intOrLong]
1532 return $Wideboxtype$.reverse(a);
1533 #else[intOrLong]
1534 #if[short]
1535 $type$ b = ROL_scalar(a, ($type$) 8);
1536 b = (short) (((b & 0x5555) << 1) | ((b & 0xAAAA) >>> 1));
1537 b = (short) (((b & 0x3333) << 2) | ((b & 0xCCCC) >>> 2));
1538 b = (short) (((b & 0x0F0F) << 4) | ((b & 0xF0F0) >>> 4));
1539 return b;
1540 #else[short]
1541 $type$ b = ($type$) ROL_scalar(a, ($type$) 4);
1542 b = (byte) (((b & 0x55) << 1) | ((b & 0xAA) >>> 1));
1543 b = (byte) (((b & 0x33) << 2) | ((b & 0xCC) >>> 2));
1544 return b;
1545 #end[short]
1546 #end[intOrLong]
1547 }
1548 #end[BITWISE]
1549
1550 static boolean eq($type$ a, $type$ b) {
1551 return a == b;
1552 }
1553
1554 static boolean neq($type$ a, $type$ b) {
1555 return a != b;
1556 }
1557
1558 static boolean lt($type$ a, $type$ b) {
1559 return a < b;
1560 }
1561
1562 static boolean le($type$ a, $type$ b) {
1563 return a <= b;
1564 }
1565
1566 static boolean gt($type$ a, $type$ b) {
1567 return a > b;
1568 }
1569
1570 static boolean ge($type$ a, $type$ b) {
1571 return a >= b;
1572 }
1573 #if[!FP]
1574
1575 static boolean ult($type$ a, $type$ b) {
1576 return $Boxtype$.compareUnsigned(a, b) < 0;
1577 }
1578
1579 static boolean ule($type$ a, $type$ b) {
1580 return $Boxtype$.compareUnsigned(a, b) <= 0;
1581 }
1582
1583 static boolean ugt($type$ a, $type$ b) {
1584 return $Boxtype$.compareUnsigned(a, b) > 0;
1585 }
1586
1587 static boolean uge($type$ a, $type$ b) {
1588 return $Boxtype$.compareUnsigned(a, b) >= 0;
1589 }
1590 #end[!FP]
1591
1592 static $type$ firstNonZero($type$ a, $type$ b) {
1593 return $Boxtype$.compare(a, ($type$) 0) != 0 ? a : b;
1594 }
1668 // To test backend instructions, make sure that C2 is used.
1669 for (int loop = 0; loop < INVOC_COUNT * INVOC_COUNT; loop++) {
1670 iotaShuffle();
1671 }
1672 }
1673
1674 @Test
1675 void viewAsIntegeralLanesTest() {
1676 #if[FP]
1677 Vector<?> asIntegral = SPECIES.zero().viewAsIntegralLanes();
1678 VectorSpecies<?> asIntegralSpecies = asIntegral.species();
1679 Assert.assertNotEquals(asIntegralSpecies.elementType(), SPECIES.elementType());
1680 Assert.assertEquals(asIntegralSpecies.vectorShape(), SPECIES.vectorShape());
1681 Assert.assertEquals(asIntegralSpecies.length(), SPECIES.length());
1682 Assert.assertEquals(asIntegral.viewAsFloatingLanes().species(), SPECIES);
1683 #else[FP]
1684 Vector<?> asIntegral = SPECIES.zero().viewAsIntegralLanes();
1685 Assert.assertEquals(asIntegral.species(), SPECIES);
1686 #end[FP]
1687 }
1688 #if[FP]
1689
1690 @Test
1691 void viewAsFloatingLanesTest() {
1692 Vector<?> asFloating = SPECIES.zero().viewAsFloatingLanes();
1693 Assert.assertEquals(asFloating.species(), SPECIES);
1694 }
1695 #else[FP]
1696 #if[byteOrShort]
1697
1698 @Test(expectedExceptions = UnsupportedOperationException.class)
1699 void viewAsFloatingLanesTest() {
1700 SPECIES.zero().viewAsFloatingLanes();
1701 }
1702 #else[byteOrShort]
1703
1704 @Test
1705 void viewAsFloatingLanesTest() {
1706 Vector<?> asFloating = SPECIES.zero().viewAsFloatingLanes();
1707 VectorSpecies<?> asFloatingSpecies = asFloating.species();
1708 Assert.assertNotEquals(asFloatingSpecies.elementType(), SPECIES.elementType());
1709 Assert.assertEquals(asFloatingSpecies.vectorShape(), SPECIES.vectorShape());
1710 Assert.assertEquals(asFloatingSpecies.length(), SPECIES.length());
1711 Assert.assertEquals(asFloating.viewAsIntegralLanes().species(), SPECIES);
1712 }
1713 #end[byteOrShort]
1714 #end[FP]
1715 #if[BITWISE]
1716
1717 @Test
1718 // Test div by 0.
1719 static void bitwiseDivByZeroSmokeTest() {
1720 try {
1721 $abstractvectortype$ a = ($abstractvectortype$) SPECIES.broadcast(0).addIndex(1);
1722 $abstractvectortype$ b = ($abstractvectortype$) SPECIES.broadcast(0);
1723 a.div(b);
1724 Assert.fail();
1725 } catch (ArithmeticException e) {
1726 }
1727
1728 try {
1729 $abstractvectortype$ a = ($abstractvectortype$) SPECIES.broadcast(0).addIndex(1);
1730 $abstractvectortype$ b = ($abstractvectortype$) SPECIES.broadcast(0);
1731 VectorMask<$Boxtype$> m = a.lt(($type$) 1);
1732 a.div(b, m);
1733 Assert.fail();
1734 } catch (ArithmeticException e) {
1735 }
1736 }
|