< prev index next >

test/jdk/jdk/incubator/vector/ByteMaxVectorTests.java

Print this page
rev 54658 : refactored mask and shuffle creation methods, moved classes to top-level


  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 ByteMaxVectorTests
  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 ByteMaxVectorTests extends AbstractVectorTest {
  49 
  50     static final Species<Byte> SPECIES =
  51                 ByteVector.SPECIES_MAX;
  52 
  53     static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100);
  54 
  55     static Shape getMaxBit() {
  56         return Shape.S_Max_BIT;
  57     }
  58 
  59     interface FUnOp {
  60         byte apply(byte a);
  61     }
  62 
  63     static void assertArraysEquals(byte[] a, byte[] r, FUnOp f) {
  64         int i = 0;
  65         try {
  66             for (; i < a.length; i++) {
  67                 Assert.assertEquals(r[i], f.apply(a[i]));
  68             }
  69         } catch (AssertionError e) {
  70             Assert.assertEquals(r[i], f.apply(a[i]), "at index #" + i + ", input = " + a[i]);
  71         }
  72     }
  73 
  74     static void assertArraysEquals(byte[] a, byte[] r, boolean[] mask, FUnOp f) {
  75         int i = 0;
  76         try {


 416         byte[] r = fr.apply(SPECIES.length());
 417 
 418         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 419             for (int i = 0; i < a.length; i += SPECIES.length()) {
 420                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 421                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
 422                 av.add(bv).intoArray(r, i);
 423             }
 424         }
 425 
 426         assertArraysEquals(a, b, r, ByteMaxVectorTests::add);
 427     }
 428 
 429     @Test(dataProvider = "byteBinaryOpMaskProvider")
 430     static void addByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
 431                                           IntFunction<boolean[]> fm) {
 432         byte[] a = fa.apply(SPECIES.length());
 433         byte[] b = fb.apply(SPECIES.length());
 434         byte[] r = fr.apply(SPECIES.length());
 435         boolean[] mask = fm.apply(SPECIES.length());
 436         Vector.Mask<Byte> vmask = ByteVector.maskFromValues(SPECIES, mask);
 437 
 438         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 439             for (int i = 0; i < a.length; i += SPECIES.length()) {
 440                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 441                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
 442                 av.add(bv, vmask).intoArray(r, i);
 443             }
 444         }
 445 
 446         assertArraysEquals(a, b, r, mask, ByteMaxVectorTests::add);
 447     }
 448     static byte sub(byte a, byte b) {
 449         return (byte)(a - b);
 450     }
 451 
 452     @Test(dataProvider = "byteBinaryOpProvider")
 453     static void subByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
 454         byte[] a = fa.apply(SPECIES.length());
 455         byte[] b = fb.apply(SPECIES.length());
 456         byte[] r = fr.apply(SPECIES.length());
 457 
 458         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 459             for (int i = 0; i < a.length; i += SPECIES.length()) {
 460                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 461                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
 462                 av.sub(bv).intoArray(r, i);
 463             }
 464         }
 465 
 466         assertArraysEquals(a, b, r, ByteMaxVectorTests::sub);
 467     }
 468 
 469     @Test(dataProvider = "byteBinaryOpMaskProvider")
 470     static void subByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
 471                                           IntFunction<boolean[]> fm) {
 472         byte[] a = fa.apply(SPECIES.length());
 473         byte[] b = fb.apply(SPECIES.length());
 474         byte[] r = fr.apply(SPECIES.length());
 475         boolean[] mask = fm.apply(SPECIES.length());
 476         Vector.Mask<Byte> vmask = ByteVector.maskFromValues(SPECIES, mask);
 477 
 478         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 479             for (int i = 0; i < a.length; i += SPECIES.length()) {
 480                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 481                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
 482                 av.sub(bv, vmask).intoArray(r, i);
 483             }
 484         }
 485 
 486         assertArraysEquals(a, b, r, mask, ByteMaxVectorTests::sub);
 487     }
 488 
 489 
 490     static byte mul(byte a, byte b) {
 491         return (byte)(a * b);
 492     }
 493 
 494     @Test(dataProvider = "byteBinaryOpProvider")
 495     static void mulByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
 496         byte[] a = fa.apply(SPECIES.length());


 498         byte[] r = fr.apply(SPECIES.length());
 499 
 500         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 501             for (int i = 0; i < a.length; i += SPECIES.length()) {
 502                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 503                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
 504                 av.mul(bv).intoArray(r, i);
 505             }
 506         }
 507 
 508         assertArraysEquals(a, b, r, ByteMaxVectorTests::mul);
 509     }
 510 
 511     @Test(dataProvider = "byteBinaryOpMaskProvider")
 512     static void mulByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
 513                                           IntFunction<boolean[]> fm) {
 514         byte[] a = fa.apply(SPECIES.length());
 515         byte[] b = fb.apply(SPECIES.length());
 516         byte[] r = fr.apply(SPECIES.length());
 517         boolean[] mask = fm.apply(SPECIES.length());
 518         Vector.Mask<Byte> vmask = ByteVector.maskFromValues(SPECIES, mask);
 519 
 520         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 521             for (int i = 0; i < a.length; i += SPECIES.length()) {
 522                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 523                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
 524                 av.mul(bv, vmask).intoArray(r, i);
 525             }
 526         }
 527 
 528         assertArraysEquals(a, b, r, mask, ByteMaxVectorTests::mul);
 529     }
 530 
 531     static byte and(byte a, byte b) {
 532         return (byte)(a & b);
 533     }
 534 
 535     @Test(dataProvider = "byteBinaryOpProvider")
 536     static void andByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
 537         byte[] a = fa.apply(SPECIES.length());
 538         byte[] b = fb.apply(SPECIES.length());


 541         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 542             for (int i = 0; i < a.length; i += SPECIES.length()) {
 543                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 544                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
 545                 av.and(bv).intoArray(r, i);
 546             }
 547         }
 548 
 549         assertArraysEquals(a, b, r, ByteMaxVectorTests::and);
 550     }
 551 
 552 
 553 
 554     @Test(dataProvider = "byteBinaryOpMaskProvider")
 555     static void andByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
 556                                           IntFunction<boolean[]> fm) {
 557         byte[] a = fa.apply(SPECIES.length());
 558         byte[] b = fb.apply(SPECIES.length());
 559         byte[] r = fr.apply(SPECIES.length());
 560         boolean[] mask = fm.apply(SPECIES.length());
 561         Vector.Mask<Byte> vmask = ByteVector.maskFromValues(SPECIES, mask);
 562 
 563         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 564             for (int i = 0; i < a.length; i += SPECIES.length()) {
 565                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 566                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
 567                 av.and(bv, vmask).intoArray(r, i);
 568             }
 569         }
 570 
 571         assertArraysEquals(a, b, r, mask, ByteMaxVectorTests::and);
 572     }
 573 
 574 
 575     static byte or(byte a, byte b) {
 576         return (byte)(a | b);
 577     }
 578 
 579     @Test(dataProvider = "byteBinaryOpProvider")
 580     static void orByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
 581         byte[] a = fa.apply(SPECIES.length());


 585         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 586             for (int i = 0; i < a.length; i += SPECIES.length()) {
 587                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 588                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
 589                 av.or(bv).intoArray(r, i);
 590             }
 591         }
 592 
 593         assertArraysEquals(a, b, r, ByteMaxVectorTests::or);
 594     }
 595 
 596 
 597 
 598     @Test(dataProvider = "byteBinaryOpMaskProvider")
 599     static void orByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
 600                                           IntFunction<boolean[]> fm) {
 601         byte[] a = fa.apply(SPECIES.length());
 602         byte[] b = fb.apply(SPECIES.length());
 603         byte[] r = fr.apply(SPECIES.length());
 604         boolean[] mask = fm.apply(SPECIES.length());
 605         Vector.Mask<Byte> vmask = ByteVector.maskFromValues(SPECIES, mask);
 606 
 607         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 608             for (int i = 0; i < a.length; i += SPECIES.length()) {
 609                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 610                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
 611                 av.or(bv, vmask).intoArray(r, i);
 612             }
 613         }
 614 
 615         assertArraysEquals(a, b, r, mask, ByteMaxVectorTests::or);
 616     }
 617 
 618 
 619     static byte xor(byte a, byte b) {
 620         return (byte)(a ^ b);
 621     }
 622 
 623     @Test(dataProvider = "byteBinaryOpProvider")
 624     static void xorByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
 625         byte[] a = fa.apply(SPECIES.length());


 629         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 630             for (int i = 0; i < a.length; i += SPECIES.length()) {
 631                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 632                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
 633                 av.xor(bv).intoArray(r, i);
 634             }
 635         }
 636 
 637         assertArraysEquals(a, b, r, ByteMaxVectorTests::xor);
 638     }
 639 
 640 
 641 
 642     @Test(dataProvider = "byteBinaryOpMaskProvider")
 643     static void xorByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
 644                                           IntFunction<boolean[]> fm) {
 645         byte[] a = fa.apply(SPECIES.length());
 646         byte[] b = fb.apply(SPECIES.length());
 647         byte[] r = fr.apply(SPECIES.length());
 648         boolean[] mask = fm.apply(SPECIES.length());
 649         Vector.Mask<Byte> vmask = ByteVector.maskFromValues(SPECIES, mask);
 650 
 651         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 652             for (int i = 0; i < a.length; i += SPECIES.length()) {
 653                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 654                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
 655                 av.xor(bv, vmask).intoArray(r, i);
 656             }
 657         }
 658 
 659         assertArraysEquals(a, b, r, mask, ByteMaxVectorTests::xor);
 660     }
 661 
 662 
 663 
 664 
 665 
 666 
 667 
 668 
 669 


 684 
 685         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 686             for (int i = 0; i < a.length; i += SPECIES.length()) {
 687                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 688                 av.aShiftR((int)b[i]).intoArray(r, i);
 689             }
 690         }
 691 
 692         assertShiftArraysEquals(a, b, r, ByteMaxVectorTests::aShiftR_unary);
 693     }
 694 
 695 
 696 
 697     @Test(dataProvider = "byteBinaryOpMaskProvider")
 698     static void aShiftRByteMaxVectorTestsShift(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
 699                                           IntFunction<boolean[]> fm) {
 700         byte[] a = fa.apply(SPECIES.length());
 701         byte[] b = fb.apply(SPECIES.length());
 702         byte[] r = fr.apply(SPECIES.length());
 703         boolean[] mask = fm.apply(SPECIES.length());
 704         Vector.Mask<Byte> vmask = ByteVector.maskFromValues(SPECIES, mask);
 705 
 706         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 707             for (int i = 0; i < a.length; i += SPECIES.length()) {
 708                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 709                 av.aShiftR((int)b[i], vmask).intoArray(r, i);
 710             }
 711         }
 712 
 713         assertShiftArraysEquals(a, b, r, mask, ByteMaxVectorTests::aShiftR_unary);
 714     }
 715 
 716 
 717     static byte shiftL_unary(byte a, byte b) {
 718         return (byte)((a << (b & 7)));
 719     }
 720 
 721     @Test(dataProvider = "byteBinaryOpProvider")
 722     static void shiftLByteMaxVectorTestsShift(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
 723         byte[] a = fa.apply(SPECIES.length());
 724         byte[] b = fb.apply(SPECIES.length());


 726 
 727         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 728             for (int i = 0; i < a.length; i += SPECIES.length()) {
 729                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 730                 av.shiftL((int)b[i]).intoArray(r, i);
 731             }
 732         }
 733 
 734         assertShiftArraysEquals(a, b, r, ByteMaxVectorTests::shiftL_unary);
 735     }
 736 
 737 
 738 
 739     @Test(dataProvider = "byteBinaryOpMaskProvider")
 740     static void shiftLByteMaxVectorTestsShift(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
 741                                           IntFunction<boolean[]> fm) {
 742         byte[] a = fa.apply(SPECIES.length());
 743         byte[] b = fb.apply(SPECIES.length());
 744         byte[] r = fr.apply(SPECIES.length());
 745         boolean[] mask = fm.apply(SPECIES.length());
 746         Vector.Mask<Byte> vmask = ByteVector.maskFromValues(SPECIES, mask);
 747 
 748         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 749             for (int i = 0; i < a.length; i += SPECIES.length()) {
 750                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 751                 av.shiftL((int)b[i], vmask).intoArray(r, i);
 752             }
 753         }
 754 
 755         assertShiftArraysEquals(a, b, r, mask, ByteMaxVectorTests::shiftL_unary);
 756     }
 757 
 758 
 759     static byte shiftR_unary(byte a, byte b) {
 760         return (byte)(((a & 0xFF) >>> (b & 7)));
 761     }
 762 
 763     @Test(dataProvider = "byteBinaryOpProvider")
 764     static void shiftRByteMaxVectorTestsShift(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
 765         byte[] a = fa.apply(SPECIES.length());
 766         byte[] b = fb.apply(SPECIES.length());


 768 
 769         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 770             for (int i = 0; i < a.length; i += SPECIES.length()) {
 771                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 772                 av.shiftR((int)b[i]).intoArray(r, i);
 773             }
 774         }
 775 
 776         assertShiftArraysEquals(a, b, r, ByteMaxVectorTests::shiftR_unary);
 777     }
 778 
 779 
 780 
 781     @Test(dataProvider = "byteBinaryOpMaskProvider")
 782     static void shiftRByteMaxVectorTestsShift(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
 783                                           IntFunction<boolean[]> fm) {
 784         byte[] a = fa.apply(SPECIES.length());
 785         byte[] b = fb.apply(SPECIES.length());
 786         byte[] r = fr.apply(SPECIES.length());
 787         boolean[] mask = fm.apply(SPECIES.length());
 788         Vector.Mask<Byte> vmask = ByteVector.maskFromValues(SPECIES, mask);
 789 
 790         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 791             for (int i = 0; i < a.length; i += SPECIES.length()) {
 792                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 793                 av.shiftR((int)b[i], vmask).intoArray(r, i);
 794             }
 795         }
 796 
 797         assertShiftArraysEquals(a, b, r, mask, ByteMaxVectorTests::shiftR_unary);
 798     }
 799 
 800 
 801 
 802 
 803 
 804 
 805 
 806     static byte max(byte a, byte b) {
 807         return (byte)(Math.max(a, b));
 808     }


1156         assertReductionArraysEquals(a, r, ra, ByteMaxVectorTests::maxAll, ByteMaxVectorTests::maxAll);
1157     }
1158 
1159     static boolean anyTrue(boolean[] a, int idx) {
1160         boolean res = false;
1161         for (int i = idx; i < (idx + SPECIES.length()); i++) {
1162             res |= a[i];
1163         }
1164 
1165         return res;
1166     }
1167 
1168 
1169     @Test(dataProvider = "boolUnaryOpProvider")
1170     static void anyTrueByteMaxVectorTests(IntFunction<boolean[]> fm) {
1171         boolean[] mask = fm.apply(SPECIES.length());
1172         boolean[] r = fmr.apply(SPECIES.length());
1173 
1174         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1175             for (int i = 0; i < mask.length; i += SPECIES.length()) {
1176                 Vector.Mask<Byte> vmask = ByteVector.maskFromArray(SPECIES, mask, i);
1177                 r[i] = vmask.anyTrue();
1178             }
1179         }
1180 
1181         assertReductionBoolArraysEquals(mask, r, ByteMaxVectorTests::anyTrue);
1182     }
1183 
1184 
1185     static boolean allTrue(boolean[] a, int idx) {
1186         boolean res = true;
1187         for (int i = idx; i < (idx + SPECIES.length()); i++) {
1188             res &= a[i];
1189         }
1190 
1191         return res;
1192     }
1193 
1194 
1195     @Test(dataProvider = "boolUnaryOpProvider")
1196     static void allTrueByteMaxVectorTests(IntFunction<boolean[]> fm) {
1197         boolean[] mask = fm.apply(SPECIES.length());
1198         boolean[] r = fmr.apply(SPECIES.length());
1199 
1200         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1201             for (int i = 0; i < mask.length; i += SPECIES.length()) {
1202                 Vector.Mask<Byte> vmask = ByteVector.maskFromArray(SPECIES, mask, i);
1203                 r[i] = vmask.allTrue();
1204             }
1205         }
1206 
1207         assertReductionBoolArraysEquals(mask, r, ByteMaxVectorTests::allTrue);
1208     }
1209 
1210 
1211     @Test(dataProvider = "byteUnaryOpProvider")
1212     static void withByteMaxVectorTests(IntFunction<byte []> fa) {
1213         byte[] a = fa.apply(SPECIES.length());
1214         byte[] r = fr.apply(SPECIES.length());
1215 
1216         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1217             for (int i = 0; i < a.length; i += SPECIES.length()) {
1218                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1219                 av.with(0, (byte)4).intoArray(r, i);
1220             }
1221         }
1222 
1223         assertInsertArraysEquals(a, r, (byte)4, 0);
1224     }
1225 
1226     @Test(dataProvider = "byteCompareOpProvider")
1227     static void lessThanByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
1228         byte[] a = fa.apply(SPECIES.length());
1229         byte[] b = fb.apply(SPECIES.length());
1230 
1231         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1232             for (int i = 0; i < a.length; i += SPECIES.length()) {
1233                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1234                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1235                 Vector.Mask<Byte> mv = av.lessThan(bv);
1236 
1237                 // Check results as part of computation.
1238                 for (int j = 0; j < SPECIES.length(); j++) {
1239                     Assert.assertEquals(mv.getElement(j), a[i + j] < b[i + j]);
1240                 }
1241             }
1242         }
1243     }
1244 
1245 
1246     @Test(dataProvider = "byteCompareOpProvider")
1247     static void greaterThanByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
1248         byte[] a = fa.apply(SPECIES.length());
1249         byte[] b = fb.apply(SPECIES.length());
1250 
1251         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1252             for (int i = 0; i < a.length; i += SPECIES.length()) {
1253                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1254                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1255                 Vector.Mask<Byte> mv = av.greaterThan(bv);
1256 
1257                 // Check results as part of computation.
1258                 for (int j = 0; j < SPECIES.length(); j++) {
1259                     Assert.assertEquals(mv.getElement(j), a[i + j] > b[i + j]);
1260                 }
1261             }
1262         }
1263     }
1264 
1265 
1266     @Test(dataProvider = "byteCompareOpProvider")
1267     static void equalByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
1268         byte[] a = fa.apply(SPECIES.length());
1269         byte[] b = fb.apply(SPECIES.length());
1270 
1271         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1272             for (int i = 0; i < a.length; i += SPECIES.length()) {
1273                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1274                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1275                 Vector.Mask<Byte> mv = av.equal(bv);
1276 
1277                 // Check results as part of computation.
1278                 for (int j = 0; j < SPECIES.length(); j++) {
1279                     Assert.assertEquals(mv.getElement(j), a[i + j] == b[i + j]);
1280                 }
1281             }
1282         }
1283     }
1284 
1285 
1286     @Test(dataProvider = "byteCompareOpProvider")
1287     static void notEqualByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
1288         byte[] a = fa.apply(SPECIES.length());
1289         byte[] b = fb.apply(SPECIES.length());
1290 
1291         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1292             for (int i = 0; i < a.length; i += SPECIES.length()) {
1293                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1294                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1295                 Vector.Mask<Byte> mv = av.notEqual(bv);
1296 
1297                 // Check results as part of computation.
1298                 for (int j = 0; j < SPECIES.length(); j++) {
1299                     Assert.assertEquals(mv.getElement(j), a[i + j] != b[i + j]);
1300                 }
1301             }
1302         }
1303     }
1304 
1305 
1306     @Test(dataProvider = "byteCompareOpProvider")
1307     static void lessThanEqByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
1308         byte[] a = fa.apply(SPECIES.length());
1309         byte[] b = fb.apply(SPECIES.length());
1310 
1311         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1312             for (int i = 0; i < a.length; i += SPECIES.length()) {
1313                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1314                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1315                 Vector.Mask<Byte> mv = av.lessThanEq(bv);
1316 
1317                 // Check results as part of computation.
1318                 for (int j = 0; j < SPECIES.length(); j++) {
1319                     Assert.assertEquals(mv.getElement(j), a[i + j] <= b[i + j]);
1320                 }
1321             }
1322         }
1323     }
1324 
1325 
1326     @Test(dataProvider = "byteCompareOpProvider")
1327     static void greaterThanEqByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
1328         byte[] a = fa.apply(SPECIES.length());
1329         byte[] b = fb.apply(SPECIES.length());
1330 
1331         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1332             for (int i = 0; i < a.length; i += SPECIES.length()) {
1333                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1334                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1335                 Vector.Mask<Byte> mv = av.greaterThanEq(bv);
1336 
1337                 // Check results as part of computation.
1338                 for (int j = 0; j < SPECIES.length(); j++) {
1339                     Assert.assertEquals(mv.getElement(j), a[i + j] >= b[i + j]);
1340                 }
1341             }
1342         }
1343     }
1344 
1345 
1346     static byte blend(byte a, byte b, boolean mask) {
1347         return mask ? b : a;
1348     }
1349 
1350     @Test(dataProvider = "byteBinaryOpMaskProvider")
1351     static void blendByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
1352                                           IntFunction<boolean[]> fm) {
1353         byte[] a = fa.apply(SPECIES.length());
1354         byte[] b = fb.apply(SPECIES.length());
1355         byte[] r = fr.apply(SPECIES.length());
1356         boolean[] mask = fm.apply(SPECIES.length());
1357         Vector.Mask<Byte> vmask = ByteVector.maskFromValues(SPECIES, mask);
1358 
1359         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1360             for (int i = 0; i < a.length; i += SPECIES.length()) {
1361                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1362                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1363                 av.blend(bv, vmask).intoArray(r, i);
1364             }
1365         }
1366 
1367         assertArraysEquals(a, b, r, mask, ByteMaxVectorTests::blend);
1368     }
1369 
1370     @Test(dataProvider = "byteUnaryOpShuffleProvider")
1371     static void RearrangeByteMaxVectorTests(IntFunction<byte[]> fa,
1372                                            BiFunction<Integer,Integer,int[]> fs) {
1373         byte[] a = fa.apply(SPECIES.length());
1374         int[] order = fs.apply(a.length, SPECIES.length());
1375         byte[] r = fr.apply(SPECIES.length());
1376 
1377         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1378             for (int i = 0; i < a.length; i += SPECIES.length()) {
1379                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1380                 av.rearrange(ByteVector.shuffleFromArray(SPECIES, order, i)).intoArray(r, i);
1381             }
1382         }
1383 
1384         assertRearrangeArraysEquals(a, r, order, SPECIES.length());
1385     }
1386 
1387 
1388 
1389 
1390     @Test(dataProvider = "byteUnaryOpProvider")
1391     static void getByteMaxVectorTests(IntFunction<byte[]> fa) {
1392         byte[] a = fa.apply(SPECIES.length());
1393         byte[] r = fr.apply(SPECIES.length());
1394 
1395         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1396             for (int i = 0; i < a.length; i += SPECIES.length()) {
1397                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1398                 int num_lanes = SPECIES.length();
1399                 // Manually unroll because full unroll happens after intrinsification.
1400                 // Unroll is needed because get intrinsic requires for index to be a known constant.


1572     static void negByteMaxVectorTests(IntFunction<byte[]> fa) {
1573         byte[] a = fa.apply(SPECIES.length());
1574         byte[] r = fr.apply(SPECIES.length());
1575 
1576         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1577             for (int i = 0; i < a.length; i += SPECIES.length()) {
1578                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1579                 av.neg().intoArray(r, i);
1580             }
1581         }
1582 
1583         assertArraysEquals(a, r, ByteMaxVectorTests::neg);
1584     }
1585 
1586     @Test(dataProvider = "byteUnaryOpMaskProvider")
1587     static void negMaskedByteMaxVectorTests(IntFunction<byte[]> fa,
1588                                                 IntFunction<boolean[]> fm) {
1589         byte[] a = fa.apply(SPECIES.length());
1590         byte[] r = fr.apply(SPECIES.length());
1591         boolean[] mask = fm.apply(SPECIES.length());
1592         Vector.Mask<Byte> vmask = ByteVector.maskFromValues(SPECIES, mask);
1593 
1594         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1595             for (int i = 0; i < a.length; i += SPECIES.length()) {
1596                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1597                 av.neg(vmask).intoArray(r, i);
1598             }
1599         }
1600 
1601         assertArraysEquals(a, r, mask, ByteMaxVectorTests::neg);
1602     }
1603 
1604     static byte abs(byte a) {
1605         return (byte)(Math.abs((byte)a));
1606     }
1607 
1608     @Test(dataProvider = "byteUnaryOpProvider")
1609     static void absByteMaxVectorTests(IntFunction<byte[]> fa) {
1610         byte[] a = fa.apply(SPECIES.length());
1611         byte[] r = fr.apply(SPECIES.length());
1612 
1613         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1614             for (int i = 0; i < a.length; i += SPECIES.length()) {
1615                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1616                 av.abs().intoArray(r, i);
1617             }
1618         }
1619 
1620         assertArraysEquals(a, r, ByteMaxVectorTests::abs);
1621     }
1622 
1623     @Test(dataProvider = "byteUnaryOpMaskProvider")
1624     static void absMaskedByteMaxVectorTests(IntFunction<byte[]> fa,
1625                                                 IntFunction<boolean[]> fm) {
1626         byte[] a = fa.apply(SPECIES.length());
1627         byte[] r = fr.apply(SPECIES.length());
1628         boolean[] mask = fm.apply(SPECIES.length());
1629         Vector.Mask<Byte> vmask = ByteVector.maskFromValues(SPECIES, mask);
1630 
1631         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1632             for (int i = 0; i < a.length; i += SPECIES.length()) {
1633                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1634                 av.abs(vmask).intoArray(r, i);
1635             }
1636         }
1637 
1638         assertArraysEquals(a, r, mask, ByteMaxVectorTests::abs);
1639     }
1640 
1641 
1642     static byte not(byte a) {
1643         return (byte)(~((byte)a));
1644     }
1645 
1646 
1647 
1648     @Test(dataProvider = "byteUnaryOpProvider")
1649     static void notByteMaxVectorTests(IntFunction<byte[]> fa) {


1651         byte[] r = fr.apply(SPECIES.length());
1652 
1653         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1654             for (int i = 0; i < a.length; i += SPECIES.length()) {
1655                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1656                 av.not().intoArray(r, i);
1657             }
1658         }
1659 
1660         assertArraysEquals(a, r, ByteMaxVectorTests::not);
1661     }
1662 
1663 
1664 
1665     @Test(dataProvider = "byteUnaryOpMaskProvider")
1666     static void notMaskedByteMaxVectorTests(IntFunction<byte[]> fa,
1667                                                 IntFunction<boolean[]> fm) {
1668         byte[] a = fa.apply(SPECIES.length());
1669         byte[] r = fr.apply(SPECIES.length());
1670         boolean[] mask = fm.apply(SPECIES.length());
1671         Vector.Mask<Byte> vmask = ByteVector.maskFromValues(SPECIES, mask);
1672 
1673         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1674             for (int i = 0; i < a.length; i += SPECIES.length()) {
1675                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1676                 av.not(vmask).intoArray(r, i);
1677             }
1678         }
1679 
1680         assertArraysEquals(a, r, mask, ByteMaxVectorTests::not);
1681     }
1682 
1683 
1684 
1685 
1686 
1687 
1688 }
1689 


  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 ByteMaxVectorTests
  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 ByteMaxVectorTests extends AbstractVectorTest {
  51 
  52     static final VectorSpecies<Byte> SPECIES =
  53                 ByteVector.SPECIES_MAX;
  54 
  55     static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100);
  56 
  57     static VectorShape getMaxBit() {
  58         return VectorShape.S_Max_BIT;
  59     }
  60 
  61     interface FUnOp {
  62         byte apply(byte a);
  63     }
  64 
  65     static void assertArraysEquals(byte[] a, byte[] r, FUnOp f) {
  66         int i = 0;
  67         try {
  68             for (; i < a.length; i++) {
  69                 Assert.assertEquals(r[i], f.apply(a[i]));
  70             }
  71         } catch (AssertionError e) {
  72             Assert.assertEquals(r[i], f.apply(a[i]), "at index #" + i + ", input = " + a[i]);
  73         }
  74     }
  75 
  76     static void assertArraysEquals(byte[] a, byte[] r, boolean[] mask, FUnOp f) {
  77         int i = 0;
  78         try {


 418         byte[] r = fr.apply(SPECIES.length());
 419 
 420         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 421             for (int i = 0; i < a.length; i += SPECIES.length()) {
 422                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 423                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
 424                 av.add(bv).intoArray(r, i);
 425             }
 426         }
 427 
 428         assertArraysEquals(a, b, r, ByteMaxVectorTests::add);
 429     }
 430 
 431     @Test(dataProvider = "byteBinaryOpMaskProvider")
 432     static void addByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
 433                                           IntFunction<boolean[]> fm) {
 434         byte[] a = fa.apply(SPECIES.length());
 435         byte[] b = fb.apply(SPECIES.length());
 436         byte[] r = fr.apply(SPECIES.length());
 437         boolean[] mask = fm.apply(SPECIES.length());
 438         VectorMask<Byte> vmask = VectorMask.fromValues(SPECIES, mask);
 439 
 440         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 441             for (int i = 0; i < a.length; i += SPECIES.length()) {
 442                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 443                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
 444                 av.add(bv, vmask).intoArray(r, i);
 445             }
 446         }
 447 
 448         assertArraysEquals(a, b, r, mask, ByteMaxVectorTests::add);
 449     }
 450     static byte sub(byte a, byte b) {
 451         return (byte)(a - b);
 452     }
 453 
 454     @Test(dataProvider = "byteBinaryOpProvider")
 455     static void subByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
 456         byte[] a = fa.apply(SPECIES.length());
 457         byte[] b = fb.apply(SPECIES.length());
 458         byte[] r = fr.apply(SPECIES.length());
 459 
 460         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 461             for (int i = 0; i < a.length; i += SPECIES.length()) {
 462                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 463                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
 464                 av.sub(bv).intoArray(r, i);
 465             }
 466         }
 467 
 468         assertArraysEquals(a, b, r, ByteMaxVectorTests::sub);
 469     }
 470 
 471     @Test(dataProvider = "byteBinaryOpMaskProvider")
 472     static void subByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
 473                                           IntFunction<boolean[]> fm) {
 474         byte[] a = fa.apply(SPECIES.length());
 475         byte[] b = fb.apply(SPECIES.length());
 476         byte[] r = fr.apply(SPECIES.length());
 477         boolean[] mask = fm.apply(SPECIES.length());
 478         VectorMask<Byte> vmask = VectorMask.fromValues(SPECIES, mask);
 479 
 480         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 481             for (int i = 0; i < a.length; i += SPECIES.length()) {
 482                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 483                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
 484                 av.sub(bv, vmask).intoArray(r, i);
 485             }
 486         }
 487 
 488         assertArraysEquals(a, b, r, mask, ByteMaxVectorTests::sub);
 489     }
 490 
 491 
 492     static byte mul(byte a, byte b) {
 493         return (byte)(a * b);
 494     }
 495 
 496     @Test(dataProvider = "byteBinaryOpProvider")
 497     static void mulByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
 498         byte[] a = fa.apply(SPECIES.length());


 500         byte[] r = fr.apply(SPECIES.length());
 501 
 502         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 503             for (int i = 0; i < a.length; i += SPECIES.length()) {
 504                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 505                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
 506                 av.mul(bv).intoArray(r, i);
 507             }
 508         }
 509 
 510         assertArraysEquals(a, b, r, ByteMaxVectorTests::mul);
 511     }
 512 
 513     @Test(dataProvider = "byteBinaryOpMaskProvider")
 514     static void mulByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
 515                                           IntFunction<boolean[]> fm) {
 516         byte[] a = fa.apply(SPECIES.length());
 517         byte[] b = fb.apply(SPECIES.length());
 518         byte[] r = fr.apply(SPECIES.length());
 519         boolean[] mask = fm.apply(SPECIES.length());
 520         VectorMask<Byte> vmask = VectorMask.fromValues(SPECIES, mask);
 521 
 522         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 523             for (int i = 0; i < a.length; i += SPECIES.length()) {
 524                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 525                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
 526                 av.mul(bv, vmask).intoArray(r, i);
 527             }
 528         }
 529 
 530         assertArraysEquals(a, b, r, mask, ByteMaxVectorTests::mul);
 531     }
 532 
 533     static byte and(byte a, byte b) {
 534         return (byte)(a & b);
 535     }
 536 
 537     @Test(dataProvider = "byteBinaryOpProvider")
 538     static void andByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
 539         byte[] a = fa.apply(SPECIES.length());
 540         byte[] b = fb.apply(SPECIES.length());


 543         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 544             for (int i = 0; i < a.length; i += SPECIES.length()) {
 545                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 546                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
 547                 av.and(bv).intoArray(r, i);
 548             }
 549         }
 550 
 551         assertArraysEquals(a, b, r, ByteMaxVectorTests::and);
 552     }
 553 
 554 
 555 
 556     @Test(dataProvider = "byteBinaryOpMaskProvider")
 557     static void andByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
 558                                           IntFunction<boolean[]> fm) {
 559         byte[] a = fa.apply(SPECIES.length());
 560         byte[] b = fb.apply(SPECIES.length());
 561         byte[] r = fr.apply(SPECIES.length());
 562         boolean[] mask = fm.apply(SPECIES.length());
 563         VectorMask<Byte> vmask = VectorMask.fromValues(SPECIES, mask);
 564 
 565         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 566             for (int i = 0; i < a.length; i += SPECIES.length()) {
 567                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 568                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
 569                 av.and(bv, vmask).intoArray(r, i);
 570             }
 571         }
 572 
 573         assertArraysEquals(a, b, r, mask, ByteMaxVectorTests::and);
 574     }
 575 
 576 
 577     static byte or(byte a, byte b) {
 578         return (byte)(a | b);
 579     }
 580 
 581     @Test(dataProvider = "byteBinaryOpProvider")
 582     static void orByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
 583         byte[] a = fa.apply(SPECIES.length());


 587         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 588             for (int i = 0; i < a.length; i += SPECIES.length()) {
 589                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 590                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
 591                 av.or(bv).intoArray(r, i);
 592             }
 593         }
 594 
 595         assertArraysEquals(a, b, r, ByteMaxVectorTests::or);
 596     }
 597 
 598 
 599 
 600     @Test(dataProvider = "byteBinaryOpMaskProvider")
 601     static void orByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
 602                                           IntFunction<boolean[]> fm) {
 603         byte[] a = fa.apply(SPECIES.length());
 604         byte[] b = fb.apply(SPECIES.length());
 605         byte[] r = fr.apply(SPECIES.length());
 606         boolean[] mask = fm.apply(SPECIES.length());
 607         VectorMask<Byte> vmask = VectorMask.fromValues(SPECIES, mask);
 608 
 609         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 610             for (int i = 0; i < a.length; i += SPECIES.length()) {
 611                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 612                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
 613                 av.or(bv, vmask).intoArray(r, i);
 614             }
 615         }
 616 
 617         assertArraysEquals(a, b, r, mask, ByteMaxVectorTests::or);
 618     }
 619 
 620 
 621     static byte xor(byte a, byte b) {
 622         return (byte)(a ^ b);
 623     }
 624 
 625     @Test(dataProvider = "byteBinaryOpProvider")
 626     static void xorByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
 627         byte[] a = fa.apply(SPECIES.length());


 631         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 632             for (int i = 0; i < a.length; i += SPECIES.length()) {
 633                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 634                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
 635                 av.xor(bv).intoArray(r, i);
 636             }
 637         }
 638 
 639         assertArraysEquals(a, b, r, ByteMaxVectorTests::xor);
 640     }
 641 
 642 
 643 
 644     @Test(dataProvider = "byteBinaryOpMaskProvider")
 645     static void xorByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
 646                                           IntFunction<boolean[]> fm) {
 647         byte[] a = fa.apply(SPECIES.length());
 648         byte[] b = fb.apply(SPECIES.length());
 649         byte[] r = fr.apply(SPECIES.length());
 650         boolean[] mask = fm.apply(SPECIES.length());
 651         VectorMask<Byte> vmask = VectorMask.fromValues(SPECIES, mask);
 652 
 653         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 654             for (int i = 0; i < a.length; i += SPECIES.length()) {
 655                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 656                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
 657                 av.xor(bv, vmask).intoArray(r, i);
 658             }
 659         }
 660 
 661         assertArraysEquals(a, b, r, mask, ByteMaxVectorTests::xor);
 662     }
 663 
 664 
 665 
 666 
 667 
 668 
 669 
 670 
 671 


 686 
 687         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 688             for (int i = 0; i < a.length; i += SPECIES.length()) {
 689                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 690                 av.aShiftR((int)b[i]).intoArray(r, i);
 691             }
 692         }
 693 
 694         assertShiftArraysEquals(a, b, r, ByteMaxVectorTests::aShiftR_unary);
 695     }
 696 
 697 
 698 
 699     @Test(dataProvider = "byteBinaryOpMaskProvider")
 700     static void aShiftRByteMaxVectorTestsShift(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
 701                                           IntFunction<boolean[]> fm) {
 702         byte[] a = fa.apply(SPECIES.length());
 703         byte[] b = fb.apply(SPECIES.length());
 704         byte[] r = fr.apply(SPECIES.length());
 705         boolean[] mask = fm.apply(SPECIES.length());
 706         VectorMask<Byte> vmask = VectorMask.fromValues(SPECIES, mask);
 707 
 708         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 709             for (int i = 0; i < a.length; i += SPECIES.length()) {
 710                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 711                 av.aShiftR((int)b[i], vmask).intoArray(r, i);
 712             }
 713         }
 714 
 715         assertShiftArraysEquals(a, b, r, mask, ByteMaxVectorTests::aShiftR_unary);
 716     }
 717 
 718 
 719     static byte shiftL_unary(byte a, byte b) {
 720         return (byte)((a << (b & 7)));
 721     }
 722 
 723     @Test(dataProvider = "byteBinaryOpProvider")
 724     static void shiftLByteMaxVectorTestsShift(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
 725         byte[] a = fa.apply(SPECIES.length());
 726         byte[] b = fb.apply(SPECIES.length());


 728 
 729         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 730             for (int i = 0; i < a.length; i += SPECIES.length()) {
 731                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 732                 av.shiftL((int)b[i]).intoArray(r, i);
 733             }
 734         }
 735 
 736         assertShiftArraysEquals(a, b, r, ByteMaxVectorTests::shiftL_unary);
 737     }
 738 
 739 
 740 
 741     @Test(dataProvider = "byteBinaryOpMaskProvider")
 742     static void shiftLByteMaxVectorTestsShift(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
 743                                           IntFunction<boolean[]> fm) {
 744         byte[] a = fa.apply(SPECIES.length());
 745         byte[] b = fb.apply(SPECIES.length());
 746         byte[] r = fr.apply(SPECIES.length());
 747         boolean[] mask = fm.apply(SPECIES.length());
 748         VectorMask<Byte> vmask = VectorMask.fromValues(SPECIES, mask);
 749 
 750         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 751             for (int i = 0; i < a.length; i += SPECIES.length()) {
 752                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 753                 av.shiftL((int)b[i], vmask).intoArray(r, i);
 754             }
 755         }
 756 
 757         assertShiftArraysEquals(a, b, r, mask, ByteMaxVectorTests::shiftL_unary);
 758     }
 759 
 760 
 761     static byte shiftR_unary(byte a, byte b) {
 762         return (byte)(((a & 0xFF) >>> (b & 7)));
 763     }
 764 
 765     @Test(dataProvider = "byteBinaryOpProvider")
 766     static void shiftRByteMaxVectorTestsShift(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
 767         byte[] a = fa.apply(SPECIES.length());
 768         byte[] b = fb.apply(SPECIES.length());


 770 
 771         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 772             for (int i = 0; i < a.length; i += SPECIES.length()) {
 773                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 774                 av.shiftR((int)b[i]).intoArray(r, i);
 775             }
 776         }
 777 
 778         assertShiftArraysEquals(a, b, r, ByteMaxVectorTests::shiftR_unary);
 779     }
 780 
 781 
 782 
 783     @Test(dataProvider = "byteBinaryOpMaskProvider")
 784     static void shiftRByteMaxVectorTestsShift(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
 785                                           IntFunction<boolean[]> fm) {
 786         byte[] a = fa.apply(SPECIES.length());
 787         byte[] b = fb.apply(SPECIES.length());
 788         byte[] r = fr.apply(SPECIES.length());
 789         boolean[] mask = fm.apply(SPECIES.length());
 790         VectorMask<Byte> vmask = VectorMask.fromValues(SPECIES, mask);
 791 
 792         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 793             for (int i = 0; i < a.length; i += SPECIES.length()) {
 794                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 795                 av.shiftR((int)b[i], vmask).intoArray(r, i);
 796             }
 797         }
 798 
 799         assertShiftArraysEquals(a, b, r, mask, ByteMaxVectorTests::shiftR_unary);
 800     }
 801 
 802 
 803 
 804 
 805 
 806 
 807 
 808     static byte max(byte a, byte b) {
 809         return (byte)(Math.max(a, b));
 810     }


1158         assertReductionArraysEquals(a, r, ra, ByteMaxVectorTests::maxAll, ByteMaxVectorTests::maxAll);
1159     }
1160 
1161     static boolean anyTrue(boolean[] a, int idx) {
1162         boolean res = false;
1163         for (int i = idx; i < (idx + SPECIES.length()); i++) {
1164             res |= a[i];
1165         }
1166 
1167         return res;
1168     }
1169 
1170 
1171     @Test(dataProvider = "boolUnaryOpProvider")
1172     static void anyTrueByteMaxVectorTests(IntFunction<boolean[]> fm) {
1173         boolean[] mask = fm.apply(SPECIES.length());
1174         boolean[] r = fmr.apply(SPECIES.length());
1175 
1176         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1177             for (int i = 0; i < mask.length; i += SPECIES.length()) {
1178                 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, i);
1179                 r[i] = vmask.anyTrue();
1180             }
1181         }
1182 
1183         assertReductionBoolArraysEquals(mask, r, ByteMaxVectorTests::anyTrue);
1184     }
1185 
1186 
1187     static boolean allTrue(boolean[] a, int idx) {
1188         boolean res = true;
1189         for (int i = idx; i < (idx + SPECIES.length()); i++) {
1190             res &= a[i];
1191         }
1192 
1193         return res;
1194     }
1195 
1196 
1197     @Test(dataProvider = "boolUnaryOpProvider")
1198     static void allTrueByteMaxVectorTests(IntFunction<boolean[]> fm) {
1199         boolean[] mask = fm.apply(SPECIES.length());
1200         boolean[] r = fmr.apply(SPECIES.length());
1201 
1202         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1203             for (int i = 0; i < mask.length; i += SPECIES.length()) {
1204                 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, i);
1205                 r[i] = vmask.allTrue();
1206             }
1207         }
1208 
1209         assertReductionBoolArraysEquals(mask, r, ByteMaxVectorTests::allTrue);
1210     }
1211 
1212 
1213     @Test(dataProvider = "byteUnaryOpProvider")
1214     static void withByteMaxVectorTests(IntFunction<byte []> fa) {
1215         byte[] a = fa.apply(SPECIES.length());
1216         byte[] r = fr.apply(SPECIES.length());
1217 
1218         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1219             for (int i = 0; i < a.length; i += SPECIES.length()) {
1220                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1221                 av.with(0, (byte)4).intoArray(r, i);
1222             }
1223         }
1224 
1225         assertInsertArraysEquals(a, r, (byte)4, 0);
1226     }
1227 
1228     @Test(dataProvider = "byteCompareOpProvider")
1229     static void lessThanByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
1230         byte[] a = fa.apply(SPECIES.length());
1231         byte[] b = fb.apply(SPECIES.length());
1232 
1233         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1234             for (int i = 0; i < a.length; i += SPECIES.length()) {
1235                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1236                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1237                 VectorMask<Byte> mv = av.lessThan(bv);
1238 
1239                 // Check results as part of computation.
1240                 for (int j = 0; j < SPECIES.length(); j++) {
1241                     Assert.assertEquals(mv.getElement(j), a[i + j] < b[i + j]);
1242                 }
1243             }
1244         }
1245     }
1246 
1247 
1248     @Test(dataProvider = "byteCompareOpProvider")
1249     static void greaterThanByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
1250         byte[] a = fa.apply(SPECIES.length());
1251         byte[] b = fb.apply(SPECIES.length());
1252 
1253         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1254             for (int i = 0; i < a.length; i += SPECIES.length()) {
1255                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1256                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1257                 VectorMask<Byte> mv = av.greaterThan(bv);
1258 
1259                 // Check results as part of computation.
1260                 for (int j = 0; j < SPECIES.length(); j++) {
1261                     Assert.assertEquals(mv.getElement(j), a[i + j] > b[i + j]);
1262                 }
1263             }
1264         }
1265     }
1266 
1267 
1268     @Test(dataProvider = "byteCompareOpProvider")
1269     static void equalByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
1270         byte[] a = fa.apply(SPECIES.length());
1271         byte[] b = fb.apply(SPECIES.length());
1272 
1273         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1274             for (int i = 0; i < a.length; i += SPECIES.length()) {
1275                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1276                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1277                 VectorMask<Byte> mv = av.equal(bv);
1278 
1279                 // Check results as part of computation.
1280                 for (int j = 0; j < SPECIES.length(); j++) {
1281                     Assert.assertEquals(mv.getElement(j), a[i + j] == b[i + j]);
1282                 }
1283             }
1284         }
1285     }
1286 
1287 
1288     @Test(dataProvider = "byteCompareOpProvider")
1289     static void notEqualByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
1290         byte[] a = fa.apply(SPECIES.length());
1291         byte[] b = fb.apply(SPECIES.length());
1292 
1293         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1294             for (int i = 0; i < a.length; i += SPECIES.length()) {
1295                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1296                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1297                 VectorMask<Byte> mv = av.notEqual(bv);
1298 
1299                 // Check results as part of computation.
1300                 for (int j = 0; j < SPECIES.length(); j++) {
1301                     Assert.assertEquals(mv.getElement(j), a[i + j] != b[i + j]);
1302                 }
1303             }
1304         }
1305     }
1306 
1307 
1308     @Test(dataProvider = "byteCompareOpProvider")
1309     static void lessThanEqByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
1310         byte[] a = fa.apply(SPECIES.length());
1311         byte[] b = fb.apply(SPECIES.length());
1312 
1313         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1314             for (int i = 0; i < a.length; i += SPECIES.length()) {
1315                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1316                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1317                 VectorMask<Byte> mv = av.lessThanEq(bv);
1318 
1319                 // Check results as part of computation.
1320                 for (int j = 0; j < SPECIES.length(); j++) {
1321                     Assert.assertEquals(mv.getElement(j), a[i + j] <= b[i + j]);
1322                 }
1323             }
1324         }
1325     }
1326 
1327 
1328     @Test(dataProvider = "byteCompareOpProvider")
1329     static void greaterThanEqByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
1330         byte[] a = fa.apply(SPECIES.length());
1331         byte[] b = fb.apply(SPECIES.length());
1332 
1333         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1334             for (int i = 0; i < a.length; i += SPECIES.length()) {
1335                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1336                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1337                 VectorMask<Byte> mv = av.greaterThanEq(bv);
1338 
1339                 // Check results as part of computation.
1340                 for (int j = 0; j < SPECIES.length(); j++) {
1341                     Assert.assertEquals(mv.getElement(j), a[i + j] >= b[i + j]);
1342                 }
1343             }
1344         }
1345     }
1346 
1347 
1348     static byte blend(byte a, byte b, boolean mask) {
1349         return mask ? b : a;
1350     }
1351 
1352     @Test(dataProvider = "byteBinaryOpMaskProvider")
1353     static void blendByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
1354                                           IntFunction<boolean[]> fm) {
1355         byte[] a = fa.apply(SPECIES.length());
1356         byte[] b = fb.apply(SPECIES.length());
1357         byte[] r = fr.apply(SPECIES.length());
1358         boolean[] mask = fm.apply(SPECIES.length());
1359         VectorMask<Byte> vmask = VectorMask.fromValues(SPECIES, mask);
1360 
1361         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1362             for (int i = 0; i < a.length; i += SPECIES.length()) {
1363                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1364                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1365                 av.blend(bv, vmask).intoArray(r, i);
1366             }
1367         }
1368 
1369         assertArraysEquals(a, b, r, mask, ByteMaxVectorTests::blend);
1370     }
1371 
1372     @Test(dataProvider = "byteUnaryOpShuffleProvider")
1373     static void RearrangeByteMaxVectorTests(IntFunction<byte[]> fa,
1374                                            BiFunction<Integer,Integer,int[]> fs) {
1375         byte[] a = fa.apply(SPECIES.length());
1376         int[] order = fs.apply(a.length, SPECIES.length());
1377         byte[] r = fr.apply(SPECIES.length());
1378 
1379         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1380             for (int i = 0; i < a.length; i += SPECIES.length()) {
1381                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1382                 av.rearrange(VectorShuffle.fromArray(SPECIES, order, i)).intoArray(r, i);
1383             }
1384         }
1385 
1386         assertRearrangeArraysEquals(a, r, order, SPECIES.length());
1387     }
1388 
1389 
1390 
1391 
1392     @Test(dataProvider = "byteUnaryOpProvider")
1393     static void getByteMaxVectorTests(IntFunction<byte[]> fa) {
1394         byte[] a = fa.apply(SPECIES.length());
1395         byte[] r = fr.apply(SPECIES.length());
1396 
1397         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1398             for (int i = 0; i < a.length; i += SPECIES.length()) {
1399                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1400                 int num_lanes = SPECIES.length();
1401                 // Manually unroll because full unroll happens after intrinsification.
1402                 // Unroll is needed because get intrinsic requires for index to be a known constant.


1574     static void negByteMaxVectorTests(IntFunction<byte[]> fa) {
1575         byte[] a = fa.apply(SPECIES.length());
1576         byte[] r = fr.apply(SPECIES.length());
1577 
1578         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1579             for (int i = 0; i < a.length; i += SPECIES.length()) {
1580                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1581                 av.neg().intoArray(r, i);
1582             }
1583         }
1584 
1585         assertArraysEquals(a, r, ByteMaxVectorTests::neg);
1586     }
1587 
1588     @Test(dataProvider = "byteUnaryOpMaskProvider")
1589     static void negMaskedByteMaxVectorTests(IntFunction<byte[]> fa,
1590                                                 IntFunction<boolean[]> fm) {
1591         byte[] a = fa.apply(SPECIES.length());
1592         byte[] r = fr.apply(SPECIES.length());
1593         boolean[] mask = fm.apply(SPECIES.length());
1594         VectorMask<Byte> vmask = VectorMask.fromValues(SPECIES, mask);
1595 
1596         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1597             for (int i = 0; i < a.length; i += SPECIES.length()) {
1598                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1599                 av.neg(vmask).intoArray(r, i);
1600             }
1601         }
1602 
1603         assertArraysEquals(a, r, mask, ByteMaxVectorTests::neg);
1604     }
1605 
1606     static byte abs(byte a) {
1607         return (byte)(Math.abs((byte)a));
1608     }
1609 
1610     @Test(dataProvider = "byteUnaryOpProvider")
1611     static void absByteMaxVectorTests(IntFunction<byte[]> fa) {
1612         byte[] a = fa.apply(SPECIES.length());
1613         byte[] r = fr.apply(SPECIES.length());
1614 
1615         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1616             for (int i = 0; i < a.length; i += SPECIES.length()) {
1617                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1618                 av.abs().intoArray(r, i);
1619             }
1620         }
1621 
1622         assertArraysEquals(a, r, ByteMaxVectorTests::abs);
1623     }
1624 
1625     @Test(dataProvider = "byteUnaryOpMaskProvider")
1626     static void absMaskedByteMaxVectorTests(IntFunction<byte[]> fa,
1627                                                 IntFunction<boolean[]> fm) {
1628         byte[] a = fa.apply(SPECIES.length());
1629         byte[] r = fr.apply(SPECIES.length());
1630         boolean[] mask = fm.apply(SPECIES.length());
1631         VectorMask<Byte> vmask = VectorMask.fromValues(SPECIES, mask);
1632 
1633         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1634             for (int i = 0; i < a.length; i += SPECIES.length()) {
1635                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1636                 av.abs(vmask).intoArray(r, i);
1637             }
1638         }
1639 
1640         assertArraysEquals(a, r, mask, ByteMaxVectorTests::abs);
1641     }
1642 
1643 
1644     static byte not(byte a) {
1645         return (byte)(~((byte)a));
1646     }
1647 
1648 
1649 
1650     @Test(dataProvider = "byteUnaryOpProvider")
1651     static void notByteMaxVectorTests(IntFunction<byte[]> fa) {


1653         byte[] r = fr.apply(SPECIES.length());
1654 
1655         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1656             for (int i = 0; i < a.length; i += SPECIES.length()) {
1657                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1658                 av.not().intoArray(r, i);
1659             }
1660         }
1661 
1662         assertArraysEquals(a, r, ByteMaxVectorTests::not);
1663     }
1664 
1665 
1666 
1667     @Test(dataProvider = "byteUnaryOpMaskProvider")
1668     static void notMaskedByteMaxVectorTests(IntFunction<byte[]> fa,
1669                                                 IntFunction<boolean[]> fm) {
1670         byte[] a = fa.apply(SPECIES.length());
1671         byte[] r = fr.apply(SPECIES.length());
1672         boolean[] mask = fm.apply(SPECIES.length());
1673         VectorMask<Byte> vmask = VectorMask.fromValues(SPECIES, mask);
1674 
1675         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1676             for (int i = 0; i < a.length; i += SPECIES.length()) {
1677                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1678                 av.not(vmask).intoArray(r, i);
1679             }
1680         }
1681 
1682         assertArraysEquals(a, r, mask, ByteMaxVectorTests::not);
1683     }
1684 
1685 
1686 
1687 
1688 
1689 
1690 }
1691 
< prev index next >