10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have
21 * questions.
22 */
23
24 /*
25 * @test
26 * @modules jdk.incubator.vector
27 * @run testng/othervm -ea -esa Byte64VectorTests
28 */
29
30 import jdk.incubator.vector.Vector.Shape;
31 import jdk.incubator.vector.Vector.Species;
32 import jdk.incubator.vector.Vector;
33
34 import jdk.incubator.vector.ByteVector;
35
36 import org.testng.Assert;
37 import org.testng.annotations.DataProvider;
38 import org.testng.annotations.Test;
39
40 import java.lang.Integer;
41 import java.util.List;
42 import java.util.function.BiFunction;
43 import java.util.function.IntFunction;
44 import java.util.stream.Collectors;
45 import java.util.stream.Stream;
46
47 @Test
48 public class Byte64VectorTests extends AbstractVectorTest {
49
50 static final Species<Byte> SPECIES =
51 ByteVector.SPECIES_64;
52
53 static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100);
54
55 interface FUnOp {
56 byte apply(byte a);
57 }
58
59 static void assertArraysEquals(byte[] a, byte[] r, FUnOp f) {
60 int i = 0;
61 try {
62 for (; i < a.length; i++) {
63 Assert.assertEquals(r[i], f.apply(a[i]));
64 }
65 } catch (AssertionError e) {
66 Assert.assertEquals(r[i], f.apply(a[i]), "at index #" + i + ", input = " + a[i]);
67 }
68 }
69
70 static void assertArraysEquals(byte[] a, byte[] r, boolean[] mask, FUnOp f) {
412 byte[] r = fr.apply(SPECIES.length());
413
414 for (int ic = 0; ic < INVOC_COUNT; ic++) {
415 for (int i = 0; i < a.length; i += SPECIES.length()) {
416 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
417 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
418 av.add(bv).intoArray(r, i);
419 }
420 }
421
422 assertArraysEquals(a, b, r, Byte64VectorTests::add);
423 }
424
425 @Test(dataProvider = "byteBinaryOpMaskProvider")
426 static void addByte64VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
427 IntFunction<boolean[]> fm) {
428 byte[] a = fa.apply(SPECIES.length());
429 byte[] b = fb.apply(SPECIES.length());
430 byte[] r = fr.apply(SPECIES.length());
431 boolean[] mask = fm.apply(SPECIES.length());
432 Vector.Mask<Byte> vmask = ByteVector.maskFromValues(SPECIES, mask);
433
434 for (int ic = 0; ic < INVOC_COUNT; ic++) {
435 for (int i = 0; i < a.length; i += SPECIES.length()) {
436 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
437 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
438 av.add(bv, vmask).intoArray(r, i);
439 }
440 }
441
442 assertArraysEquals(a, b, r, mask, Byte64VectorTests::add);
443 }
444 static byte sub(byte a, byte b) {
445 return (byte)(a - b);
446 }
447
448 @Test(dataProvider = "byteBinaryOpProvider")
449 static void subByte64VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
450 byte[] a = fa.apply(SPECIES.length());
451 byte[] b = fb.apply(SPECIES.length());
452 byte[] r = fr.apply(SPECIES.length());
453
454 for (int ic = 0; ic < INVOC_COUNT; ic++) {
455 for (int i = 0; i < a.length; i += SPECIES.length()) {
456 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
457 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
458 av.sub(bv).intoArray(r, i);
459 }
460 }
461
462 assertArraysEquals(a, b, r, Byte64VectorTests::sub);
463 }
464
465 @Test(dataProvider = "byteBinaryOpMaskProvider")
466 static void subByte64VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
467 IntFunction<boolean[]> fm) {
468 byte[] a = fa.apply(SPECIES.length());
469 byte[] b = fb.apply(SPECIES.length());
470 byte[] r = fr.apply(SPECIES.length());
471 boolean[] mask = fm.apply(SPECIES.length());
472 Vector.Mask<Byte> vmask = ByteVector.maskFromValues(SPECIES, mask);
473
474 for (int ic = 0; ic < INVOC_COUNT; ic++) {
475 for (int i = 0; i < a.length; i += SPECIES.length()) {
476 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
477 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
478 av.sub(bv, vmask).intoArray(r, i);
479 }
480 }
481
482 assertArraysEquals(a, b, r, mask, Byte64VectorTests::sub);
483 }
484
485
486 static byte mul(byte a, byte b) {
487 return (byte)(a * b);
488 }
489
490 @Test(dataProvider = "byteBinaryOpProvider")
491 static void mulByte64VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
492 byte[] a = fa.apply(SPECIES.length());
494 byte[] r = fr.apply(SPECIES.length());
495
496 for (int ic = 0; ic < INVOC_COUNT; ic++) {
497 for (int i = 0; i < a.length; i += SPECIES.length()) {
498 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
499 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
500 av.mul(bv).intoArray(r, i);
501 }
502 }
503
504 assertArraysEquals(a, b, r, Byte64VectorTests::mul);
505 }
506
507 @Test(dataProvider = "byteBinaryOpMaskProvider")
508 static void mulByte64VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
509 IntFunction<boolean[]> fm) {
510 byte[] a = fa.apply(SPECIES.length());
511 byte[] b = fb.apply(SPECIES.length());
512 byte[] r = fr.apply(SPECIES.length());
513 boolean[] mask = fm.apply(SPECIES.length());
514 Vector.Mask<Byte> vmask = ByteVector.maskFromValues(SPECIES, mask);
515
516 for (int ic = 0; ic < INVOC_COUNT; ic++) {
517 for (int i = 0; i < a.length; i += SPECIES.length()) {
518 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
519 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
520 av.mul(bv, vmask).intoArray(r, i);
521 }
522 }
523
524 assertArraysEquals(a, b, r, mask, Byte64VectorTests::mul);
525 }
526
527 static byte and(byte a, byte b) {
528 return (byte)(a & b);
529 }
530
531 @Test(dataProvider = "byteBinaryOpProvider")
532 static void andByte64VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
533 byte[] a = fa.apply(SPECIES.length());
534 byte[] b = fb.apply(SPECIES.length());
537 for (int ic = 0; ic < INVOC_COUNT; ic++) {
538 for (int i = 0; i < a.length; i += SPECIES.length()) {
539 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
540 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
541 av.and(bv).intoArray(r, i);
542 }
543 }
544
545 assertArraysEquals(a, b, r, Byte64VectorTests::and);
546 }
547
548
549
550 @Test(dataProvider = "byteBinaryOpMaskProvider")
551 static void andByte64VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
552 IntFunction<boolean[]> fm) {
553 byte[] a = fa.apply(SPECIES.length());
554 byte[] b = fb.apply(SPECIES.length());
555 byte[] r = fr.apply(SPECIES.length());
556 boolean[] mask = fm.apply(SPECIES.length());
557 Vector.Mask<Byte> vmask = ByteVector.maskFromValues(SPECIES, mask);
558
559 for (int ic = 0; ic < INVOC_COUNT; ic++) {
560 for (int i = 0; i < a.length; i += SPECIES.length()) {
561 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
562 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
563 av.and(bv, vmask).intoArray(r, i);
564 }
565 }
566
567 assertArraysEquals(a, b, r, mask, Byte64VectorTests::and);
568 }
569
570
571 static byte or(byte a, byte b) {
572 return (byte)(a | b);
573 }
574
575 @Test(dataProvider = "byteBinaryOpProvider")
576 static void orByte64VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
577 byte[] a = fa.apply(SPECIES.length());
581 for (int ic = 0; ic < INVOC_COUNT; ic++) {
582 for (int i = 0; i < a.length; i += SPECIES.length()) {
583 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
584 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
585 av.or(bv).intoArray(r, i);
586 }
587 }
588
589 assertArraysEquals(a, b, r, Byte64VectorTests::or);
590 }
591
592
593
594 @Test(dataProvider = "byteBinaryOpMaskProvider")
595 static void orByte64VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
596 IntFunction<boolean[]> fm) {
597 byte[] a = fa.apply(SPECIES.length());
598 byte[] b = fb.apply(SPECIES.length());
599 byte[] r = fr.apply(SPECIES.length());
600 boolean[] mask = fm.apply(SPECIES.length());
601 Vector.Mask<Byte> vmask = ByteVector.maskFromValues(SPECIES, mask);
602
603 for (int ic = 0; ic < INVOC_COUNT; ic++) {
604 for (int i = 0; i < a.length; i += SPECIES.length()) {
605 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
606 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
607 av.or(bv, vmask).intoArray(r, i);
608 }
609 }
610
611 assertArraysEquals(a, b, r, mask, Byte64VectorTests::or);
612 }
613
614
615 static byte xor(byte a, byte b) {
616 return (byte)(a ^ b);
617 }
618
619 @Test(dataProvider = "byteBinaryOpProvider")
620 static void xorByte64VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
621 byte[] a = fa.apply(SPECIES.length());
625 for (int ic = 0; ic < INVOC_COUNT; ic++) {
626 for (int i = 0; i < a.length; i += SPECIES.length()) {
627 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
628 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
629 av.xor(bv).intoArray(r, i);
630 }
631 }
632
633 assertArraysEquals(a, b, r, Byte64VectorTests::xor);
634 }
635
636
637
638 @Test(dataProvider = "byteBinaryOpMaskProvider")
639 static void xorByte64VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
640 IntFunction<boolean[]> fm) {
641 byte[] a = fa.apply(SPECIES.length());
642 byte[] b = fb.apply(SPECIES.length());
643 byte[] r = fr.apply(SPECIES.length());
644 boolean[] mask = fm.apply(SPECIES.length());
645 Vector.Mask<Byte> vmask = ByteVector.maskFromValues(SPECIES, mask);
646
647 for (int ic = 0; ic < INVOC_COUNT; ic++) {
648 for (int i = 0; i < a.length; i += SPECIES.length()) {
649 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
650 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
651 av.xor(bv, vmask).intoArray(r, i);
652 }
653 }
654
655 assertArraysEquals(a, b, r, mask, Byte64VectorTests::xor);
656 }
657
658
659
660
661
662
663
664
665
680
681 for (int ic = 0; ic < INVOC_COUNT; ic++) {
682 for (int i = 0; i < a.length; i += SPECIES.length()) {
683 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
684 av.aShiftR((int)b[i]).intoArray(r, i);
685 }
686 }
687
688 assertShiftArraysEquals(a, b, r, Byte64VectorTests::aShiftR_unary);
689 }
690
691
692
693 @Test(dataProvider = "byteBinaryOpMaskProvider")
694 static void aShiftRByte64VectorTestsShift(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
695 IntFunction<boolean[]> fm) {
696 byte[] a = fa.apply(SPECIES.length());
697 byte[] b = fb.apply(SPECIES.length());
698 byte[] r = fr.apply(SPECIES.length());
699 boolean[] mask = fm.apply(SPECIES.length());
700 Vector.Mask<Byte> vmask = ByteVector.maskFromValues(SPECIES, mask);
701
702 for (int ic = 0; ic < INVOC_COUNT; ic++) {
703 for (int i = 0; i < a.length; i += SPECIES.length()) {
704 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
705 av.aShiftR((int)b[i], vmask).intoArray(r, i);
706 }
707 }
708
709 assertShiftArraysEquals(a, b, r, mask, Byte64VectorTests::aShiftR_unary);
710 }
711
712
713 static byte shiftL_unary(byte a, byte b) {
714 return (byte)((a << (b & 7)));
715 }
716
717 @Test(dataProvider = "byteBinaryOpProvider")
718 static void shiftLByte64VectorTestsShift(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
719 byte[] a = fa.apply(SPECIES.length());
720 byte[] b = fb.apply(SPECIES.length());
722
723 for (int ic = 0; ic < INVOC_COUNT; ic++) {
724 for (int i = 0; i < a.length; i += SPECIES.length()) {
725 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
726 av.shiftL((int)b[i]).intoArray(r, i);
727 }
728 }
729
730 assertShiftArraysEquals(a, b, r, Byte64VectorTests::shiftL_unary);
731 }
732
733
734
735 @Test(dataProvider = "byteBinaryOpMaskProvider")
736 static void shiftLByte64VectorTestsShift(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
737 IntFunction<boolean[]> fm) {
738 byte[] a = fa.apply(SPECIES.length());
739 byte[] b = fb.apply(SPECIES.length());
740 byte[] r = fr.apply(SPECIES.length());
741 boolean[] mask = fm.apply(SPECIES.length());
742 Vector.Mask<Byte> vmask = ByteVector.maskFromValues(SPECIES, mask);
743
744 for (int ic = 0; ic < INVOC_COUNT; ic++) {
745 for (int i = 0; i < a.length; i += SPECIES.length()) {
746 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
747 av.shiftL((int)b[i], vmask).intoArray(r, i);
748 }
749 }
750
751 assertShiftArraysEquals(a, b, r, mask, Byte64VectorTests::shiftL_unary);
752 }
753
754
755 static byte shiftR_unary(byte a, byte b) {
756 return (byte)(((a & 0xFF) >>> (b & 7)));
757 }
758
759 @Test(dataProvider = "byteBinaryOpProvider")
760 static void shiftRByte64VectorTestsShift(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
761 byte[] a = fa.apply(SPECIES.length());
762 byte[] b = fb.apply(SPECIES.length());
764
765 for (int ic = 0; ic < INVOC_COUNT; ic++) {
766 for (int i = 0; i < a.length; i += SPECIES.length()) {
767 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
768 av.shiftR((int)b[i]).intoArray(r, i);
769 }
770 }
771
772 assertShiftArraysEquals(a, b, r, Byte64VectorTests::shiftR_unary);
773 }
774
775
776
777 @Test(dataProvider = "byteBinaryOpMaskProvider")
778 static void shiftRByte64VectorTestsShift(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
779 IntFunction<boolean[]> fm) {
780 byte[] a = fa.apply(SPECIES.length());
781 byte[] b = fb.apply(SPECIES.length());
782 byte[] r = fr.apply(SPECIES.length());
783 boolean[] mask = fm.apply(SPECIES.length());
784 Vector.Mask<Byte> vmask = ByteVector.maskFromValues(SPECIES, mask);
785
786 for (int ic = 0; ic < INVOC_COUNT; ic++) {
787 for (int i = 0; i < a.length; i += SPECIES.length()) {
788 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
789 av.shiftR((int)b[i], vmask).intoArray(r, i);
790 }
791 }
792
793 assertShiftArraysEquals(a, b, r, mask, Byte64VectorTests::shiftR_unary);
794 }
795
796
797
798
799
800
801
802 static byte max(byte a, byte b) {
803 return (byte)(Math.max(a, b));
804 }
1152 assertReductionArraysEquals(a, r, ra, Byte64VectorTests::maxAll, Byte64VectorTests::maxAll);
1153 }
1154
1155 static boolean anyTrue(boolean[] a, int idx) {
1156 boolean res = false;
1157 for (int i = idx; i < (idx + SPECIES.length()); i++) {
1158 res |= a[i];
1159 }
1160
1161 return res;
1162 }
1163
1164
1165 @Test(dataProvider = "boolUnaryOpProvider")
1166 static void anyTrueByte64VectorTests(IntFunction<boolean[]> fm) {
1167 boolean[] mask = fm.apply(SPECIES.length());
1168 boolean[] r = fmr.apply(SPECIES.length());
1169
1170 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1171 for (int i = 0; i < mask.length; i += SPECIES.length()) {
1172 Vector.Mask<Byte> vmask = ByteVector.maskFromArray(SPECIES, mask, i);
1173 r[i] = vmask.anyTrue();
1174 }
1175 }
1176
1177 assertReductionBoolArraysEquals(mask, r, Byte64VectorTests::anyTrue);
1178 }
1179
1180
1181 static boolean allTrue(boolean[] a, int idx) {
1182 boolean res = true;
1183 for (int i = idx; i < (idx + SPECIES.length()); i++) {
1184 res &= a[i];
1185 }
1186
1187 return res;
1188 }
1189
1190
1191 @Test(dataProvider = "boolUnaryOpProvider")
1192 static void allTrueByte64VectorTests(IntFunction<boolean[]> fm) {
1193 boolean[] mask = fm.apply(SPECIES.length());
1194 boolean[] r = fmr.apply(SPECIES.length());
1195
1196 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1197 for (int i = 0; i < mask.length; i += SPECIES.length()) {
1198 Vector.Mask<Byte> vmask = ByteVector.maskFromArray(SPECIES, mask, i);
1199 r[i] = vmask.allTrue();
1200 }
1201 }
1202
1203 assertReductionBoolArraysEquals(mask, r, Byte64VectorTests::allTrue);
1204 }
1205
1206
1207 @Test(dataProvider = "byteUnaryOpProvider")
1208 static void withByte64VectorTests(IntFunction<byte []> fa) {
1209 byte[] a = fa.apply(SPECIES.length());
1210 byte[] r = fr.apply(SPECIES.length());
1211
1212 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1213 for (int i = 0; i < a.length; i += SPECIES.length()) {
1214 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1215 av.with(0, (byte)4).intoArray(r, i);
1216 }
1217 }
1218
1219 assertInsertArraysEquals(a, r, (byte)4, 0);
1220 }
1221
1222 @Test(dataProvider = "byteCompareOpProvider")
1223 static void lessThanByte64VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
1224 byte[] a = fa.apply(SPECIES.length());
1225 byte[] b = fb.apply(SPECIES.length());
1226
1227 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1228 for (int i = 0; i < a.length; i += SPECIES.length()) {
1229 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1230 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1231 Vector.Mask<Byte> mv = av.lessThan(bv);
1232
1233 // Check results as part of computation.
1234 for (int j = 0; j < SPECIES.length(); j++) {
1235 Assert.assertEquals(mv.getElement(j), a[i + j] < b[i + j]);
1236 }
1237 }
1238 }
1239 }
1240
1241
1242 @Test(dataProvider = "byteCompareOpProvider")
1243 static void greaterThanByte64VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
1244 byte[] a = fa.apply(SPECIES.length());
1245 byte[] b = fb.apply(SPECIES.length());
1246
1247 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1248 for (int i = 0; i < a.length; i += SPECIES.length()) {
1249 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1250 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1251 Vector.Mask<Byte> mv = av.greaterThan(bv);
1252
1253 // Check results as part of computation.
1254 for (int j = 0; j < SPECIES.length(); j++) {
1255 Assert.assertEquals(mv.getElement(j), a[i + j] > b[i + j]);
1256 }
1257 }
1258 }
1259 }
1260
1261
1262 @Test(dataProvider = "byteCompareOpProvider")
1263 static void equalByte64VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
1264 byte[] a = fa.apply(SPECIES.length());
1265 byte[] b = fb.apply(SPECIES.length());
1266
1267 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1268 for (int i = 0; i < a.length; i += SPECIES.length()) {
1269 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1270 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1271 Vector.Mask<Byte> mv = av.equal(bv);
1272
1273 // Check results as part of computation.
1274 for (int j = 0; j < SPECIES.length(); j++) {
1275 Assert.assertEquals(mv.getElement(j), a[i + j] == b[i + j]);
1276 }
1277 }
1278 }
1279 }
1280
1281
1282 @Test(dataProvider = "byteCompareOpProvider")
1283 static void notEqualByte64VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
1284 byte[] a = fa.apply(SPECIES.length());
1285 byte[] b = fb.apply(SPECIES.length());
1286
1287 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1288 for (int i = 0; i < a.length; i += SPECIES.length()) {
1289 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1290 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1291 Vector.Mask<Byte> mv = av.notEqual(bv);
1292
1293 // Check results as part of computation.
1294 for (int j = 0; j < SPECIES.length(); j++) {
1295 Assert.assertEquals(mv.getElement(j), a[i + j] != b[i + j]);
1296 }
1297 }
1298 }
1299 }
1300
1301
1302 @Test(dataProvider = "byteCompareOpProvider")
1303 static void lessThanEqByte64VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
1304 byte[] a = fa.apply(SPECIES.length());
1305 byte[] b = fb.apply(SPECIES.length());
1306
1307 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1308 for (int i = 0; i < a.length; i += SPECIES.length()) {
1309 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1310 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1311 Vector.Mask<Byte> mv = av.lessThanEq(bv);
1312
1313 // Check results as part of computation.
1314 for (int j = 0; j < SPECIES.length(); j++) {
1315 Assert.assertEquals(mv.getElement(j), a[i + j] <= b[i + j]);
1316 }
1317 }
1318 }
1319 }
1320
1321
1322 @Test(dataProvider = "byteCompareOpProvider")
1323 static void greaterThanEqByte64VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
1324 byte[] a = fa.apply(SPECIES.length());
1325 byte[] b = fb.apply(SPECIES.length());
1326
1327 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1328 for (int i = 0; i < a.length; i += SPECIES.length()) {
1329 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1330 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1331 Vector.Mask<Byte> mv = av.greaterThanEq(bv);
1332
1333 // Check results as part of computation.
1334 for (int j = 0; j < SPECIES.length(); j++) {
1335 Assert.assertEquals(mv.getElement(j), a[i + j] >= b[i + j]);
1336 }
1337 }
1338 }
1339 }
1340
1341
1342 static byte blend(byte a, byte b, boolean mask) {
1343 return mask ? b : a;
1344 }
1345
1346 @Test(dataProvider = "byteBinaryOpMaskProvider")
1347 static void blendByte64VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
1348 IntFunction<boolean[]> fm) {
1349 byte[] a = fa.apply(SPECIES.length());
1350 byte[] b = fb.apply(SPECIES.length());
1351 byte[] r = fr.apply(SPECIES.length());
1352 boolean[] mask = fm.apply(SPECIES.length());
1353 Vector.Mask<Byte> vmask = ByteVector.maskFromValues(SPECIES, mask);
1354
1355 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1356 for (int i = 0; i < a.length; i += SPECIES.length()) {
1357 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1358 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1359 av.blend(bv, vmask).intoArray(r, i);
1360 }
1361 }
1362
1363 assertArraysEquals(a, b, r, mask, Byte64VectorTests::blend);
1364 }
1365
1366 @Test(dataProvider = "byteUnaryOpShuffleProvider")
1367 static void RearrangeByte64VectorTests(IntFunction<byte[]> fa,
1368 BiFunction<Integer,Integer,int[]> fs) {
1369 byte[] a = fa.apply(SPECIES.length());
1370 int[] order = fs.apply(a.length, SPECIES.length());
1371 byte[] r = fr.apply(SPECIES.length());
1372
1373 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1374 for (int i = 0; i < a.length; i += SPECIES.length()) {
1375 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1376 av.rearrange(ByteVector.shuffleFromArray(SPECIES, order, i)).intoArray(r, i);
1377 }
1378 }
1379
1380 assertRearrangeArraysEquals(a, r, order, SPECIES.length());
1381 }
1382
1383
1384
1385
1386 @Test(dataProvider = "byteUnaryOpProvider")
1387 static void getByte64VectorTests(IntFunction<byte[]> fa) {
1388 byte[] a = fa.apply(SPECIES.length());
1389 byte[] r = fr.apply(SPECIES.length());
1390
1391 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1392 for (int i = 0; i < a.length; i += SPECIES.length()) {
1393 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1394 int num_lanes = SPECIES.length();
1395 // Manually unroll because full unroll happens after intrinsification.
1396 // Unroll is needed because get intrinsic requires for index to be a known constant.
1568 static void negByte64VectorTests(IntFunction<byte[]> fa) {
1569 byte[] a = fa.apply(SPECIES.length());
1570 byte[] r = fr.apply(SPECIES.length());
1571
1572 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1573 for (int i = 0; i < a.length; i += SPECIES.length()) {
1574 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1575 av.neg().intoArray(r, i);
1576 }
1577 }
1578
1579 assertArraysEquals(a, r, Byte64VectorTests::neg);
1580 }
1581
1582 @Test(dataProvider = "byteUnaryOpMaskProvider")
1583 static void negMaskedByte64VectorTests(IntFunction<byte[]> fa,
1584 IntFunction<boolean[]> fm) {
1585 byte[] a = fa.apply(SPECIES.length());
1586 byte[] r = fr.apply(SPECIES.length());
1587 boolean[] mask = fm.apply(SPECIES.length());
1588 Vector.Mask<Byte> vmask = ByteVector.maskFromValues(SPECIES, mask);
1589
1590 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1591 for (int i = 0; i < a.length; i += SPECIES.length()) {
1592 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1593 av.neg(vmask).intoArray(r, i);
1594 }
1595 }
1596
1597 assertArraysEquals(a, r, mask, Byte64VectorTests::neg);
1598 }
1599
1600 static byte abs(byte a) {
1601 return (byte)(Math.abs((byte)a));
1602 }
1603
1604 @Test(dataProvider = "byteUnaryOpProvider")
1605 static void absByte64VectorTests(IntFunction<byte[]> fa) {
1606 byte[] a = fa.apply(SPECIES.length());
1607 byte[] r = fr.apply(SPECIES.length());
1608
1609 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1610 for (int i = 0; i < a.length; i += SPECIES.length()) {
1611 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1612 av.abs().intoArray(r, i);
1613 }
1614 }
1615
1616 assertArraysEquals(a, r, Byte64VectorTests::abs);
1617 }
1618
1619 @Test(dataProvider = "byteUnaryOpMaskProvider")
1620 static void absMaskedByte64VectorTests(IntFunction<byte[]> fa,
1621 IntFunction<boolean[]> fm) {
1622 byte[] a = fa.apply(SPECIES.length());
1623 byte[] r = fr.apply(SPECIES.length());
1624 boolean[] mask = fm.apply(SPECIES.length());
1625 Vector.Mask<Byte> vmask = ByteVector.maskFromValues(SPECIES, mask);
1626
1627 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1628 for (int i = 0; i < a.length; i += SPECIES.length()) {
1629 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1630 av.abs(vmask).intoArray(r, i);
1631 }
1632 }
1633
1634 assertArraysEquals(a, r, mask, Byte64VectorTests::abs);
1635 }
1636
1637
1638 static byte not(byte a) {
1639 return (byte)(~((byte)a));
1640 }
1641
1642
1643
1644 @Test(dataProvider = "byteUnaryOpProvider")
1645 static void notByte64VectorTests(IntFunction<byte[]> fa) {
1647 byte[] r = fr.apply(SPECIES.length());
1648
1649 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1650 for (int i = 0; i < a.length; i += SPECIES.length()) {
1651 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1652 av.not().intoArray(r, i);
1653 }
1654 }
1655
1656 assertArraysEquals(a, r, Byte64VectorTests::not);
1657 }
1658
1659
1660
1661 @Test(dataProvider = "byteUnaryOpMaskProvider")
1662 static void notMaskedByte64VectorTests(IntFunction<byte[]> fa,
1663 IntFunction<boolean[]> fm) {
1664 byte[] a = fa.apply(SPECIES.length());
1665 byte[] r = fr.apply(SPECIES.length());
1666 boolean[] mask = fm.apply(SPECIES.length());
1667 Vector.Mask<Byte> vmask = ByteVector.maskFromValues(SPECIES, mask);
1668
1669 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1670 for (int i = 0; i < a.length; i += SPECIES.length()) {
1671 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1672 av.not(vmask).intoArray(r, i);
1673 }
1674 }
1675
1676 assertArraysEquals(a, r, mask, Byte64VectorTests::not);
1677 }
1678
1679
1680
1681
1682
1683
1684 }
1685
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have
21 * questions.
22 */
23
24 /*
25 * @test
26 * @modules jdk.incubator.vector
27 * @run testng/othervm -ea -esa Byte64VectorTests
28 */
29
30 import jdk.incubator.vector.VectorShape;
31 import jdk.incubator.vector.VectorSpecies;
32 import jdk.incubator.vector.VectorShuffle;
33 import jdk.incubator.vector.VectorMask;
34 import jdk.incubator.vector.Vector;
35
36 import jdk.incubator.vector.ByteVector;
37
38 import org.testng.Assert;
39 import org.testng.annotations.DataProvider;
40 import org.testng.annotations.Test;
41
42 import java.lang.Integer;
43 import java.util.List;
44 import java.util.function.BiFunction;
45 import java.util.function.IntFunction;
46 import java.util.stream.Collectors;
47 import java.util.stream.Stream;
48
49 @Test
50 public class Byte64VectorTests extends AbstractVectorTest {
51
52 static final VectorSpecies<Byte> SPECIES =
53 ByteVector.SPECIES_64;
54
55 static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100);
56
57 interface FUnOp {
58 byte apply(byte a);
59 }
60
61 static void assertArraysEquals(byte[] a, byte[] r, FUnOp f) {
62 int i = 0;
63 try {
64 for (; i < a.length; i++) {
65 Assert.assertEquals(r[i], f.apply(a[i]));
66 }
67 } catch (AssertionError e) {
68 Assert.assertEquals(r[i], f.apply(a[i]), "at index #" + i + ", input = " + a[i]);
69 }
70 }
71
72 static void assertArraysEquals(byte[] a, byte[] r, boolean[] mask, FUnOp f) {
414 byte[] r = fr.apply(SPECIES.length());
415
416 for (int ic = 0; ic < INVOC_COUNT; ic++) {
417 for (int i = 0; i < a.length; i += SPECIES.length()) {
418 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
419 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
420 av.add(bv).intoArray(r, i);
421 }
422 }
423
424 assertArraysEquals(a, b, r, Byte64VectorTests::add);
425 }
426
427 @Test(dataProvider = "byteBinaryOpMaskProvider")
428 static void addByte64VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
429 IntFunction<boolean[]> fm) {
430 byte[] a = fa.apply(SPECIES.length());
431 byte[] b = fb.apply(SPECIES.length());
432 byte[] r = fr.apply(SPECIES.length());
433 boolean[] mask = fm.apply(SPECIES.length());
434 VectorMask<Byte> vmask = VectorMask.fromValues(SPECIES, mask);
435
436 for (int ic = 0; ic < INVOC_COUNT; ic++) {
437 for (int i = 0; i < a.length; i += SPECIES.length()) {
438 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
439 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
440 av.add(bv, vmask).intoArray(r, i);
441 }
442 }
443
444 assertArraysEquals(a, b, r, mask, Byte64VectorTests::add);
445 }
446 static byte sub(byte a, byte b) {
447 return (byte)(a - b);
448 }
449
450 @Test(dataProvider = "byteBinaryOpProvider")
451 static void subByte64VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
452 byte[] a = fa.apply(SPECIES.length());
453 byte[] b = fb.apply(SPECIES.length());
454 byte[] r = fr.apply(SPECIES.length());
455
456 for (int ic = 0; ic < INVOC_COUNT; ic++) {
457 for (int i = 0; i < a.length; i += SPECIES.length()) {
458 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
459 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
460 av.sub(bv).intoArray(r, i);
461 }
462 }
463
464 assertArraysEquals(a, b, r, Byte64VectorTests::sub);
465 }
466
467 @Test(dataProvider = "byteBinaryOpMaskProvider")
468 static void subByte64VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
469 IntFunction<boolean[]> fm) {
470 byte[] a = fa.apply(SPECIES.length());
471 byte[] b = fb.apply(SPECIES.length());
472 byte[] r = fr.apply(SPECIES.length());
473 boolean[] mask = fm.apply(SPECIES.length());
474 VectorMask<Byte> vmask = VectorMask.fromValues(SPECIES, mask);
475
476 for (int ic = 0; ic < INVOC_COUNT; ic++) {
477 for (int i = 0; i < a.length; i += SPECIES.length()) {
478 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
479 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
480 av.sub(bv, vmask).intoArray(r, i);
481 }
482 }
483
484 assertArraysEquals(a, b, r, mask, Byte64VectorTests::sub);
485 }
486
487
488 static byte mul(byte a, byte b) {
489 return (byte)(a * b);
490 }
491
492 @Test(dataProvider = "byteBinaryOpProvider")
493 static void mulByte64VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
494 byte[] a = fa.apply(SPECIES.length());
496 byte[] r = fr.apply(SPECIES.length());
497
498 for (int ic = 0; ic < INVOC_COUNT; ic++) {
499 for (int i = 0; i < a.length; i += SPECIES.length()) {
500 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
501 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
502 av.mul(bv).intoArray(r, i);
503 }
504 }
505
506 assertArraysEquals(a, b, r, Byte64VectorTests::mul);
507 }
508
509 @Test(dataProvider = "byteBinaryOpMaskProvider")
510 static void mulByte64VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
511 IntFunction<boolean[]> fm) {
512 byte[] a = fa.apply(SPECIES.length());
513 byte[] b = fb.apply(SPECIES.length());
514 byte[] r = fr.apply(SPECIES.length());
515 boolean[] mask = fm.apply(SPECIES.length());
516 VectorMask<Byte> vmask = VectorMask.fromValues(SPECIES, mask);
517
518 for (int ic = 0; ic < INVOC_COUNT; ic++) {
519 for (int i = 0; i < a.length; i += SPECIES.length()) {
520 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
521 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
522 av.mul(bv, vmask).intoArray(r, i);
523 }
524 }
525
526 assertArraysEquals(a, b, r, mask, Byte64VectorTests::mul);
527 }
528
529 static byte and(byte a, byte b) {
530 return (byte)(a & b);
531 }
532
533 @Test(dataProvider = "byteBinaryOpProvider")
534 static void andByte64VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
535 byte[] a = fa.apply(SPECIES.length());
536 byte[] b = fb.apply(SPECIES.length());
539 for (int ic = 0; ic < INVOC_COUNT; ic++) {
540 for (int i = 0; i < a.length; i += SPECIES.length()) {
541 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
542 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
543 av.and(bv).intoArray(r, i);
544 }
545 }
546
547 assertArraysEquals(a, b, r, Byte64VectorTests::and);
548 }
549
550
551
552 @Test(dataProvider = "byteBinaryOpMaskProvider")
553 static void andByte64VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
554 IntFunction<boolean[]> fm) {
555 byte[] a = fa.apply(SPECIES.length());
556 byte[] b = fb.apply(SPECIES.length());
557 byte[] r = fr.apply(SPECIES.length());
558 boolean[] mask = fm.apply(SPECIES.length());
559 VectorMask<Byte> vmask = VectorMask.fromValues(SPECIES, mask);
560
561 for (int ic = 0; ic < INVOC_COUNT; ic++) {
562 for (int i = 0; i < a.length; i += SPECIES.length()) {
563 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
564 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
565 av.and(bv, vmask).intoArray(r, i);
566 }
567 }
568
569 assertArraysEquals(a, b, r, mask, Byte64VectorTests::and);
570 }
571
572
573 static byte or(byte a, byte b) {
574 return (byte)(a | b);
575 }
576
577 @Test(dataProvider = "byteBinaryOpProvider")
578 static void orByte64VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
579 byte[] a = fa.apply(SPECIES.length());
583 for (int ic = 0; ic < INVOC_COUNT; ic++) {
584 for (int i = 0; i < a.length; i += SPECIES.length()) {
585 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
586 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
587 av.or(bv).intoArray(r, i);
588 }
589 }
590
591 assertArraysEquals(a, b, r, Byte64VectorTests::or);
592 }
593
594
595
596 @Test(dataProvider = "byteBinaryOpMaskProvider")
597 static void orByte64VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
598 IntFunction<boolean[]> fm) {
599 byte[] a = fa.apply(SPECIES.length());
600 byte[] b = fb.apply(SPECIES.length());
601 byte[] r = fr.apply(SPECIES.length());
602 boolean[] mask = fm.apply(SPECIES.length());
603 VectorMask<Byte> vmask = VectorMask.fromValues(SPECIES, mask);
604
605 for (int ic = 0; ic < INVOC_COUNT; ic++) {
606 for (int i = 0; i < a.length; i += SPECIES.length()) {
607 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
608 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
609 av.or(bv, vmask).intoArray(r, i);
610 }
611 }
612
613 assertArraysEquals(a, b, r, mask, Byte64VectorTests::or);
614 }
615
616
617 static byte xor(byte a, byte b) {
618 return (byte)(a ^ b);
619 }
620
621 @Test(dataProvider = "byteBinaryOpProvider")
622 static void xorByte64VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
623 byte[] a = fa.apply(SPECIES.length());
627 for (int ic = 0; ic < INVOC_COUNT; ic++) {
628 for (int i = 0; i < a.length; i += SPECIES.length()) {
629 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
630 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
631 av.xor(bv).intoArray(r, i);
632 }
633 }
634
635 assertArraysEquals(a, b, r, Byte64VectorTests::xor);
636 }
637
638
639
640 @Test(dataProvider = "byteBinaryOpMaskProvider")
641 static void xorByte64VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
642 IntFunction<boolean[]> fm) {
643 byte[] a = fa.apply(SPECIES.length());
644 byte[] b = fb.apply(SPECIES.length());
645 byte[] r = fr.apply(SPECIES.length());
646 boolean[] mask = fm.apply(SPECIES.length());
647 VectorMask<Byte> vmask = VectorMask.fromValues(SPECIES, mask);
648
649 for (int ic = 0; ic < INVOC_COUNT; ic++) {
650 for (int i = 0; i < a.length; i += SPECIES.length()) {
651 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
652 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
653 av.xor(bv, vmask).intoArray(r, i);
654 }
655 }
656
657 assertArraysEquals(a, b, r, mask, Byte64VectorTests::xor);
658 }
659
660
661
662
663
664
665
666
667
682
683 for (int ic = 0; ic < INVOC_COUNT; ic++) {
684 for (int i = 0; i < a.length; i += SPECIES.length()) {
685 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
686 av.aShiftR((int)b[i]).intoArray(r, i);
687 }
688 }
689
690 assertShiftArraysEquals(a, b, r, Byte64VectorTests::aShiftR_unary);
691 }
692
693
694
695 @Test(dataProvider = "byteBinaryOpMaskProvider")
696 static void aShiftRByte64VectorTestsShift(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
697 IntFunction<boolean[]> fm) {
698 byte[] a = fa.apply(SPECIES.length());
699 byte[] b = fb.apply(SPECIES.length());
700 byte[] r = fr.apply(SPECIES.length());
701 boolean[] mask = fm.apply(SPECIES.length());
702 VectorMask<Byte> vmask = VectorMask.fromValues(SPECIES, mask);
703
704 for (int ic = 0; ic < INVOC_COUNT; ic++) {
705 for (int i = 0; i < a.length; i += SPECIES.length()) {
706 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
707 av.aShiftR((int)b[i], vmask).intoArray(r, i);
708 }
709 }
710
711 assertShiftArraysEquals(a, b, r, mask, Byte64VectorTests::aShiftR_unary);
712 }
713
714
715 static byte shiftL_unary(byte a, byte b) {
716 return (byte)((a << (b & 7)));
717 }
718
719 @Test(dataProvider = "byteBinaryOpProvider")
720 static void shiftLByte64VectorTestsShift(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
721 byte[] a = fa.apply(SPECIES.length());
722 byte[] b = fb.apply(SPECIES.length());
724
725 for (int ic = 0; ic < INVOC_COUNT; ic++) {
726 for (int i = 0; i < a.length; i += SPECIES.length()) {
727 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
728 av.shiftL((int)b[i]).intoArray(r, i);
729 }
730 }
731
732 assertShiftArraysEquals(a, b, r, Byte64VectorTests::shiftL_unary);
733 }
734
735
736
737 @Test(dataProvider = "byteBinaryOpMaskProvider")
738 static void shiftLByte64VectorTestsShift(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
739 IntFunction<boolean[]> fm) {
740 byte[] a = fa.apply(SPECIES.length());
741 byte[] b = fb.apply(SPECIES.length());
742 byte[] r = fr.apply(SPECIES.length());
743 boolean[] mask = fm.apply(SPECIES.length());
744 VectorMask<Byte> vmask = VectorMask.fromValues(SPECIES, mask);
745
746 for (int ic = 0; ic < INVOC_COUNT; ic++) {
747 for (int i = 0; i < a.length; i += SPECIES.length()) {
748 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
749 av.shiftL((int)b[i], vmask).intoArray(r, i);
750 }
751 }
752
753 assertShiftArraysEquals(a, b, r, mask, Byte64VectorTests::shiftL_unary);
754 }
755
756
757 static byte shiftR_unary(byte a, byte b) {
758 return (byte)(((a & 0xFF) >>> (b & 7)));
759 }
760
761 @Test(dataProvider = "byteBinaryOpProvider")
762 static void shiftRByte64VectorTestsShift(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
763 byte[] a = fa.apply(SPECIES.length());
764 byte[] b = fb.apply(SPECIES.length());
766
767 for (int ic = 0; ic < INVOC_COUNT; ic++) {
768 for (int i = 0; i < a.length; i += SPECIES.length()) {
769 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
770 av.shiftR((int)b[i]).intoArray(r, i);
771 }
772 }
773
774 assertShiftArraysEquals(a, b, r, Byte64VectorTests::shiftR_unary);
775 }
776
777
778
779 @Test(dataProvider = "byteBinaryOpMaskProvider")
780 static void shiftRByte64VectorTestsShift(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
781 IntFunction<boolean[]> fm) {
782 byte[] a = fa.apply(SPECIES.length());
783 byte[] b = fb.apply(SPECIES.length());
784 byte[] r = fr.apply(SPECIES.length());
785 boolean[] mask = fm.apply(SPECIES.length());
786 VectorMask<Byte> vmask = VectorMask.fromValues(SPECIES, mask);
787
788 for (int ic = 0; ic < INVOC_COUNT; ic++) {
789 for (int i = 0; i < a.length; i += SPECIES.length()) {
790 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
791 av.shiftR((int)b[i], vmask).intoArray(r, i);
792 }
793 }
794
795 assertShiftArraysEquals(a, b, r, mask, Byte64VectorTests::shiftR_unary);
796 }
797
798
799
800
801
802
803
804 static byte max(byte a, byte b) {
805 return (byte)(Math.max(a, b));
806 }
1154 assertReductionArraysEquals(a, r, ra, Byte64VectorTests::maxAll, Byte64VectorTests::maxAll);
1155 }
1156
1157 static boolean anyTrue(boolean[] a, int idx) {
1158 boolean res = false;
1159 for (int i = idx; i < (idx + SPECIES.length()); i++) {
1160 res |= a[i];
1161 }
1162
1163 return res;
1164 }
1165
1166
1167 @Test(dataProvider = "boolUnaryOpProvider")
1168 static void anyTrueByte64VectorTests(IntFunction<boolean[]> fm) {
1169 boolean[] mask = fm.apply(SPECIES.length());
1170 boolean[] r = fmr.apply(SPECIES.length());
1171
1172 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1173 for (int i = 0; i < mask.length; i += SPECIES.length()) {
1174 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, i);
1175 r[i] = vmask.anyTrue();
1176 }
1177 }
1178
1179 assertReductionBoolArraysEquals(mask, r, Byte64VectorTests::anyTrue);
1180 }
1181
1182
1183 static boolean allTrue(boolean[] a, int idx) {
1184 boolean res = true;
1185 for (int i = idx; i < (idx + SPECIES.length()); i++) {
1186 res &= a[i];
1187 }
1188
1189 return res;
1190 }
1191
1192
1193 @Test(dataProvider = "boolUnaryOpProvider")
1194 static void allTrueByte64VectorTests(IntFunction<boolean[]> fm) {
1195 boolean[] mask = fm.apply(SPECIES.length());
1196 boolean[] r = fmr.apply(SPECIES.length());
1197
1198 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1199 for (int i = 0; i < mask.length; i += SPECIES.length()) {
1200 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, i);
1201 r[i] = vmask.allTrue();
1202 }
1203 }
1204
1205 assertReductionBoolArraysEquals(mask, r, Byte64VectorTests::allTrue);
1206 }
1207
1208
1209 @Test(dataProvider = "byteUnaryOpProvider")
1210 static void withByte64VectorTests(IntFunction<byte []> fa) {
1211 byte[] a = fa.apply(SPECIES.length());
1212 byte[] r = fr.apply(SPECIES.length());
1213
1214 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1215 for (int i = 0; i < a.length; i += SPECIES.length()) {
1216 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1217 av.with(0, (byte)4).intoArray(r, i);
1218 }
1219 }
1220
1221 assertInsertArraysEquals(a, r, (byte)4, 0);
1222 }
1223
1224 @Test(dataProvider = "byteCompareOpProvider")
1225 static void lessThanByte64VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
1226 byte[] a = fa.apply(SPECIES.length());
1227 byte[] b = fb.apply(SPECIES.length());
1228
1229 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1230 for (int i = 0; i < a.length; i += SPECIES.length()) {
1231 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1232 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1233 VectorMask<Byte> mv = av.lessThan(bv);
1234
1235 // Check results as part of computation.
1236 for (int j = 0; j < SPECIES.length(); j++) {
1237 Assert.assertEquals(mv.getElement(j), a[i + j] < b[i + j]);
1238 }
1239 }
1240 }
1241 }
1242
1243
1244 @Test(dataProvider = "byteCompareOpProvider")
1245 static void greaterThanByte64VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
1246 byte[] a = fa.apply(SPECIES.length());
1247 byte[] b = fb.apply(SPECIES.length());
1248
1249 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1250 for (int i = 0; i < a.length; i += SPECIES.length()) {
1251 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1252 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1253 VectorMask<Byte> mv = av.greaterThan(bv);
1254
1255 // Check results as part of computation.
1256 for (int j = 0; j < SPECIES.length(); j++) {
1257 Assert.assertEquals(mv.getElement(j), a[i + j] > b[i + j]);
1258 }
1259 }
1260 }
1261 }
1262
1263
1264 @Test(dataProvider = "byteCompareOpProvider")
1265 static void equalByte64VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
1266 byte[] a = fa.apply(SPECIES.length());
1267 byte[] b = fb.apply(SPECIES.length());
1268
1269 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1270 for (int i = 0; i < a.length; i += SPECIES.length()) {
1271 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1272 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1273 VectorMask<Byte> mv = av.equal(bv);
1274
1275 // Check results as part of computation.
1276 for (int j = 0; j < SPECIES.length(); j++) {
1277 Assert.assertEquals(mv.getElement(j), a[i + j] == b[i + j]);
1278 }
1279 }
1280 }
1281 }
1282
1283
1284 @Test(dataProvider = "byteCompareOpProvider")
1285 static void notEqualByte64VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
1286 byte[] a = fa.apply(SPECIES.length());
1287 byte[] b = fb.apply(SPECIES.length());
1288
1289 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1290 for (int i = 0; i < a.length; i += SPECIES.length()) {
1291 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1292 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1293 VectorMask<Byte> mv = av.notEqual(bv);
1294
1295 // Check results as part of computation.
1296 for (int j = 0; j < SPECIES.length(); j++) {
1297 Assert.assertEquals(mv.getElement(j), a[i + j] != b[i + j]);
1298 }
1299 }
1300 }
1301 }
1302
1303
1304 @Test(dataProvider = "byteCompareOpProvider")
1305 static void lessThanEqByte64VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
1306 byte[] a = fa.apply(SPECIES.length());
1307 byte[] b = fb.apply(SPECIES.length());
1308
1309 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1310 for (int i = 0; i < a.length; i += SPECIES.length()) {
1311 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1312 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1313 VectorMask<Byte> mv = av.lessThanEq(bv);
1314
1315 // Check results as part of computation.
1316 for (int j = 0; j < SPECIES.length(); j++) {
1317 Assert.assertEquals(mv.getElement(j), a[i + j] <= b[i + j]);
1318 }
1319 }
1320 }
1321 }
1322
1323
1324 @Test(dataProvider = "byteCompareOpProvider")
1325 static void greaterThanEqByte64VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
1326 byte[] a = fa.apply(SPECIES.length());
1327 byte[] b = fb.apply(SPECIES.length());
1328
1329 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1330 for (int i = 0; i < a.length; i += SPECIES.length()) {
1331 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1332 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1333 VectorMask<Byte> mv = av.greaterThanEq(bv);
1334
1335 // Check results as part of computation.
1336 for (int j = 0; j < SPECIES.length(); j++) {
1337 Assert.assertEquals(mv.getElement(j), a[i + j] >= b[i + j]);
1338 }
1339 }
1340 }
1341 }
1342
1343
1344 static byte blend(byte a, byte b, boolean mask) {
1345 return mask ? b : a;
1346 }
1347
1348 @Test(dataProvider = "byteBinaryOpMaskProvider")
1349 static void blendByte64VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
1350 IntFunction<boolean[]> fm) {
1351 byte[] a = fa.apply(SPECIES.length());
1352 byte[] b = fb.apply(SPECIES.length());
1353 byte[] r = fr.apply(SPECIES.length());
1354 boolean[] mask = fm.apply(SPECIES.length());
1355 VectorMask<Byte> vmask = VectorMask.fromValues(SPECIES, mask);
1356
1357 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1358 for (int i = 0; i < a.length; i += SPECIES.length()) {
1359 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1360 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1361 av.blend(bv, vmask).intoArray(r, i);
1362 }
1363 }
1364
1365 assertArraysEquals(a, b, r, mask, Byte64VectorTests::blend);
1366 }
1367
1368 @Test(dataProvider = "byteUnaryOpShuffleProvider")
1369 static void RearrangeByte64VectorTests(IntFunction<byte[]> fa,
1370 BiFunction<Integer,Integer,int[]> fs) {
1371 byte[] a = fa.apply(SPECIES.length());
1372 int[] order = fs.apply(a.length, SPECIES.length());
1373 byte[] r = fr.apply(SPECIES.length());
1374
1375 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1376 for (int i = 0; i < a.length; i += SPECIES.length()) {
1377 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1378 av.rearrange(VectorShuffle.fromArray(SPECIES, order, i)).intoArray(r, i);
1379 }
1380 }
1381
1382 assertRearrangeArraysEquals(a, r, order, SPECIES.length());
1383 }
1384
1385
1386
1387
1388 @Test(dataProvider = "byteUnaryOpProvider")
1389 static void getByte64VectorTests(IntFunction<byte[]> fa) {
1390 byte[] a = fa.apply(SPECIES.length());
1391 byte[] r = fr.apply(SPECIES.length());
1392
1393 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1394 for (int i = 0; i < a.length; i += SPECIES.length()) {
1395 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1396 int num_lanes = SPECIES.length();
1397 // Manually unroll because full unroll happens after intrinsification.
1398 // Unroll is needed because get intrinsic requires for index to be a known constant.
1570 static void negByte64VectorTests(IntFunction<byte[]> fa) {
1571 byte[] a = fa.apply(SPECIES.length());
1572 byte[] r = fr.apply(SPECIES.length());
1573
1574 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1575 for (int i = 0; i < a.length; i += SPECIES.length()) {
1576 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1577 av.neg().intoArray(r, i);
1578 }
1579 }
1580
1581 assertArraysEquals(a, r, Byte64VectorTests::neg);
1582 }
1583
1584 @Test(dataProvider = "byteUnaryOpMaskProvider")
1585 static void negMaskedByte64VectorTests(IntFunction<byte[]> fa,
1586 IntFunction<boolean[]> fm) {
1587 byte[] a = fa.apply(SPECIES.length());
1588 byte[] r = fr.apply(SPECIES.length());
1589 boolean[] mask = fm.apply(SPECIES.length());
1590 VectorMask<Byte> vmask = VectorMask.fromValues(SPECIES, mask);
1591
1592 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1593 for (int i = 0; i < a.length; i += SPECIES.length()) {
1594 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1595 av.neg(vmask).intoArray(r, i);
1596 }
1597 }
1598
1599 assertArraysEquals(a, r, mask, Byte64VectorTests::neg);
1600 }
1601
1602 static byte abs(byte a) {
1603 return (byte)(Math.abs((byte)a));
1604 }
1605
1606 @Test(dataProvider = "byteUnaryOpProvider")
1607 static void absByte64VectorTests(IntFunction<byte[]> fa) {
1608 byte[] a = fa.apply(SPECIES.length());
1609 byte[] r = fr.apply(SPECIES.length());
1610
1611 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1612 for (int i = 0; i < a.length; i += SPECIES.length()) {
1613 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1614 av.abs().intoArray(r, i);
1615 }
1616 }
1617
1618 assertArraysEquals(a, r, Byte64VectorTests::abs);
1619 }
1620
1621 @Test(dataProvider = "byteUnaryOpMaskProvider")
1622 static void absMaskedByte64VectorTests(IntFunction<byte[]> fa,
1623 IntFunction<boolean[]> fm) {
1624 byte[] a = fa.apply(SPECIES.length());
1625 byte[] r = fr.apply(SPECIES.length());
1626 boolean[] mask = fm.apply(SPECIES.length());
1627 VectorMask<Byte> vmask = VectorMask.fromValues(SPECIES, mask);
1628
1629 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1630 for (int i = 0; i < a.length; i += SPECIES.length()) {
1631 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1632 av.abs(vmask).intoArray(r, i);
1633 }
1634 }
1635
1636 assertArraysEquals(a, r, mask, Byte64VectorTests::abs);
1637 }
1638
1639
1640 static byte not(byte a) {
1641 return (byte)(~((byte)a));
1642 }
1643
1644
1645
1646 @Test(dataProvider = "byteUnaryOpProvider")
1647 static void notByte64VectorTests(IntFunction<byte[]> fa) {
1649 byte[] r = fr.apply(SPECIES.length());
1650
1651 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1652 for (int i = 0; i < a.length; i += SPECIES.length()) {
1653 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1654 av.not().intoArray(r, i);
1655 }
1656 }
1657
1658 assertArraysEquals(a, r, Byte64VectorTests::not);
1659 }
1660
1661
1662
1663 @Test(dataProvider = "byteUnaryOpMaskProvider")
1664 static void notMaskedByte64VectorTests(IntFunction<byte[]> fa,
1665 IntFunction<boolean[]> fm) {
1666 byte[] a = fa.apply(SPECIES.length());
1667 byte[] r = fr.apply(SPECIES.length());
1668 boolean[] mask = fm.apply(SPECIES.length());
1669 VectorMask<Byte> vmask = VectorMask.fromValues(SPECIES, mask);
1670
1671 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1672 for (int i = 0; i < a.length; i += SPECIES.length()) {
1673 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1674 av.not(vmask).intoArray(r, i);
1675 }
1676 }
1677
1678 assertArraysEquals(a, r, mask, Byte64VectorTests::not);
1679 }
1680
1681
1682
1683
1684
1685
1686 }
1687
|