< prev index next >

test/jdk/jdk/incubator/vector/Short64VectorTests.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 Short64VectorTests
  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.ShortVector;
  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 Short64VectorTests extends AbstractVectorTest {
  49 
  50     static final Species<Short> SPECIES =
  51                 ShortVector.SPECIES_64;
  52 
  53     static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100);
  54 
  55     interface FUnOp {
  56         short apply(short a);
  57     }
  58 
  59     static void assertArraysEquals(short[] a, short[] 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(short[] a, short[] r, boolean[] mask, FUnOp f) {


 412         short[] 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 417                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 418                 av.add(bv).intoArray(r, i);
 419             }
 420         }
 421 
 422         assertArraysEquals(a, b, r, Short64VectorTests::add);
 423     }
 424 
 425     @Test(dataProvider = "shortBinaryOpMaskProvider")
 426     static void addShort64VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb,
 427                                           IntFunction<boolean[]> fm) {
 428         short[] a = fa.apply(SPECIES.length());
 429         short[] b = fb.apply(SPECIES.length());
 430         short[] r = fr.apply(SPECIES.length());
 431         boolean[] mask = fm.apply(SPECIES.length());
 432         Vector.Mask<Short> vmask = ShortVector.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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 437                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 438                 av.add(bv, vmask).intoArray(r, i);
 439             }
 440         }
 441 
 442         assertArraysEquals(a, b, r, mask, Short64VectorTests::add);
 443     }
 444     static short sub(short a, short b) {
 445         return (short)(a - b);
 446     }
 447 
 448     @Test(dataProvider = "shortBinaryOpProvider")
 449     static void subShort64VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) {
 450         short[] a = fa.apply(SPECIES.length());
 451         short[] b = fb.apply(SPECIES.length());
 452         short[] 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 457                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 458                 av.sub(bv).intoArray(r, i);
 459             }
 460         }
 461 
 462         assertArraysEquals(a, b, r, Short64VectorTests::sub);
 463     }
 464 
 465     @Test(dataProvider = "shortBinaryOpMaskProvider")
 466     static void subShort64VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb,
 467                                           IntFunction<boolean[]> fm) {
 468         short[] a = fa.apply(SPECIES.length());
 469         short[] b = fb.apply(SPECIES.length());
 470         short[] r = fr.apply(SPECIES.length());
 471         boolean[] mask = fm.apply(SPECIES.length());
 472         Vector.Mask<Short> vmask = ShortVector.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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 477                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 478                 av.sub(bv, vmask).intoArray(r, i);
 479             }
 480         }
 481 
 482         assertArraysEquals(a, b, r, mask, Short64VectorTests::sub);
 483     }
 484 
 485 
 486     static short mul(short a, short b) {
 487         return (short)(a * b);
 488     }
 489 
 490     @Test(dataProvider = "shortBinaryOpProvider")
 491     static void mulShort64VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) {
 492         short[] a = fa.apply(SPECIES.length());


 494         short[] 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 499                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 500                 av.mul(bv).intoArray(r, i);
 501             }
 502         }
 503 
 504         assertArraysEquals(a, b, r, Short64VectorTests::mul);
 505     }
 506 
 507     @Test(dataProvider = "shortBinaryOpMaskProvider")
 508     static void mulShort64VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb,
 509                                           IntFunction<boolean[]> fm) {
 510         short[] a = fa.apply(SPECIES.length());
 511         short[] b = fb.apply(SPECIES.length());
 512         short[] r = fr.apply(SPECIES.length());
 513         boolean[] mask = fm.apply(SPECIES.length());
 514         Vector.Mask<Short> vmask = ShortVector.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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 519                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 520                 av.mul(bv, vmask).intoArray(r, i);
 521             }
 522         }
 523 
 524         assertArraysEquals(a, b, r, mask, Short64VectorTests::mul);
 525     }
 526 
 527     static short and(short a, short b) {
 528         return (short)(a & b);
 529     }
 530 
 531     @Test(dataProvider = "shortBinaryOpProvider")
 532     static void andShort64VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) {
 533         short[] a = fa.apply(SPECIES.length());
 534         short[] 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 540                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 541                 av.and(bv).intoArray(r, i);
 542             }
 543         }
 544 
 545         assertArraysEquals(a, b, r, Short64VectorTests::and);
 546     }
 547 
 548 
 549 
 550     @Test(dataProvider = "shortBinaryOpMaskProvider")
 551     static void andShort64VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb,
 552                                           IntFunction<boolean[]> fm) {
 553         short[] a = fa.apply(SPECIES.length());
 554         short[] b = fb.apply(SPECIES.length());
 555         short[] r = fr.apply(SPECIES.length());
 556         boolean[] mask = fm.apply(SPECIES.length());
 557         Vector.Mask<Short> vmask = ShortVector.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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 562                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 563                 av.and(bv, vmask).intoArray(r, i);
 564             }
 565         }
 566 
 567         assertArraysEquals(a, b, r, mask, Short64VectorTests::and);
 568     }
 569 
 570 
 571     static short or(short a, short b) {
 572         return (short)(a | b);
 573     }
 574 
 575     @Test(dataProvider = "shortBinaryOpProvider")
 576     static void orShort64VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) {
 577         short[] 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 584                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 585                 av.or(bv).intoArray(r, i);
 586             }
 587         }
 588 
 589         assertArraysEquals(a, b, r, Short64VectorTests::or);
 590     }
 591 
 592 
 593 
 594     @Test(dataProvider = "shortBinaryOpMaskProvider")
 595     static void orShort64VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb,
 596                                           IntFunction<boolean[]> fm) {
 597         short[] a = fa.apply(SPECIES.length());
 598         short[] b = fb.apply(SPECIES.length());
 599         short[] r = fr.apply(SPECIES.length());
 600         boolean[] mask = fm.apply(SPECIES.length());
 601         Vector.Mask<Short> vmask = ShortVector.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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 606                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 607                 av.or(bv, vmask).intoArray(r, i);
 608             }
 609         }
 610 
 611         assertArraysEquals(a, b, r, mask, Short64VectorTests::or);
 612     }
 613 
 614 
 615     static short xor(short a, short b) {
 616         return (short)(a ^ b);
 617     }
 618 
 619     @Test(dataProvider = "shortBinaryOpProvider")
 620     static void xorShort64VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) {
 621         short[] 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 628                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 629                 av.xor(bv).intoArray(r, i);
 630             }
 631         }
 632 
 633         assertArraysEquals(a, b, r, Short64VectorTests::xor);
 634     }
 635 
 636 
 637 
 638     @Test(dataProvider = "shortBinaryOpMaskProvider")
 639     static void xorShort64VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb,
 640                                           IntFunction<boolean[]> fm) {
 641         short[] a = fa.apply(SPECIES.length());
 642         short[] b = fb.apply(SPECIES.length());
 643         short[] r = fr.apply(SPECIES.length());
 644         boolean[] mask = fm.apply(SPECIES.length());
 645         Vector.Mask<Short> vmask = ShortVector.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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 650                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 651                 av.xor(bv, vmask).intoArray(r, i);
 652             }
 653         }
 654 
 655         assertArraysEquals(a, b, r, mask, Short64VectorTests::xor);
 656     }
 657 
 658 
 659 
 660 
 661 
 662 
 663 
 664 
 665 


 686 
 687         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 688             for (int i = 0; i < a.length; i += SPECIES.length()) {
 689                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 690                 av.aShiftR((int)b[i]).intoArray(r, i);
 691             }
 692         }
 693 
 694         assertShiftArraysEquals(a, b, r, Short64VectorTests::aShiftR_unary);
 695     }
 696 
 697 
 698 
 699     @Test(dataProvider = "shortBinaryOpMaskProvider")
 700     static void aShiftRShort64VectorTestsShift(IntFunction<short[]> fa, IntFunction<short[]> fb,
 701                                           IntFunction<boolean[]> fm) {
 702         short[] a = fa.apply(SPECIES.length());
 703         short[] b = fb.apply(SPECIES.length());
 704         short[] r = fr.apply(SPECIES.length());
 705         boolean[] mask = fm.apply(SPECIES.length());
 706         Vector.Mask<Short> vmask = ShortVector.maskFromValues(SPECIES, mask);
 707 
 708         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 709             for (int i = 0; i < a.length; i += SPECIES.length()) {
 710                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 711                 av.aShiftR((int)b[i], vmask).intoArray(r, i);
 712             }
 713         }
 714 
 715         assertShiftArraysEquals(a, b, r, mask, Short64VectorTests::aShiftR_unary);
 716     }
 717 
 718 
 719     static short shiftL_unary(short a, short b) {
 720         return (short)((a << (b & 15)));
 721     }
 722 
 723     @Test(dataProvider = "shortBinaryOpProvider")
 724     static void shiftLShort64VectorTestsShift(IntFunction<short[]> fa, IntFunction<short[]> fb) {
 725         short[] a = fa.apply(SPECIES.length());
 726         short[] 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 732                 av.shiftL((int)b[i]).intoArray(r, i);
 733             }
 734         }
 735 
 736         assertShiftArraysEquals(a, b, r, Short64VectorTests::shiftL_unary);
 737     }
 738 
 739 
 740 
 741     @Test(dataProvider = "shortBinaryOpMaskProvider")
 742     static void shiftLShort64VectorTestsShift(IntFunction<short[]> fa, IntFunction<short[]> fb,
 743                                           IntFunction<boolean[]> fm) {
 744         short[] a = fa.apply(SPECIES.length());
 745         short[] b = fb.apply(SPECIES.length());
 746         short[] r = fr.apply(SPECIES.length());
 747         boolean[] mask = fm.apply(SPECIES.length());
 748         Vector.Mask<Short> vmask = ShortVector.maskFromValues(SPECIES, mask);
 749 
 750         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 751             for (int i = 0; i < a.length; i += SPECIES.length()) {
 752                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 753                 av.shiftL((int)b[i], vmask).intoArray(r, i);
 754             }
 755         }
 756 
 757         assertShiftArraysEquals(a, b, r, mask, Short64VectorTests::shiftL_unary);
 758     }
 759 
 760 
 761     static short shiftR_unary(short a, short b) {
 762         return (short)(((a & 0xFFFF) >>> (b & 15)));
 763     }
 764 
 765     @Test(dataProvider = "shortBinaryOpProvider")
 766     static void shiftRShort64VectorTestsShift(IntFunction<short[]> fa, IntFunction<short[]> fb) {
 767         short[] a = fa.apply(SPECIES.length());
 768         short[] 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 774                 av.shiftR((int)b[i]).intoArray(r, i);
 775             }
 776         }
 777 
 778         assertShiftArraysEquals(a, b, r, Short64VectorTests::shiftR_unary);
 779     }
 780 
 781 
 782 
 783     @Test(dataProvider = "shortBinaryOpMaskProvider")
 784     static void shiftRShort64VectorTestsShift(IntFunction<short[]> fa, IntFunction<short[]> fb,
 785                                           IntFunction<boolean[]> fm) {
 786         short[] a = fa.apply(SPECIES.length());
 787         short[] b = fb.apply(SPECIES.length());
 788         short[] r = fr.apply(SPECIES.length());
 789         boolean[] mask = fm.apply(SPECIES.length());
 790         Vector.Mask<Short> vmask = ShortVector.maskFromValues(SPECIES, mask);
 791 
 792         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 793             for (int i = 0; i < a.length; i += SPECIES.length()) {
 794                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 795                 av.shiftR((int)b[i], vmask).intoArray(r, i);
 796             }
 797         }
 798 
 799         assertShiftArraysEquals(a, b, r, mask, Short64VectorTests::shiftR_unary);
 800     }
 801 
 802     static short max(short a, short b) {
 803         return (short)(Math.max(a, b));
 804     }
 805 
 806     @Test(dataProvider = "shortBinaryOpProvider")
 807     static void maxShort64VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) {
 808         short[] a = fa.apply(SPECIES.length());
 809         short[] b = fb.apply(SPECIES.length());
 810         short[] r = fr.apply(SPECIES.length());


1152         assertReductionArraysEquals(a, r, ra, Short64VectorTests::maxAll, Short64VectorTests::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 anyTrueShort64VectorTests(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<Short> vmask = ShortVector.maskFromArray(SPECIES, mask, i);
1173                 r[i] = vmask.anyTrue();
1174             }
1175         }
1176 
1177         assertReductionBoolArraysEquals(mask, r, Short64VectorTests::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 allTrueShort64VectorTests(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<Short> vmask = ShortVector.maskFromArray(SPECIES, mask, i);
1199                 r[i] = vmask.allTrue();
1200             }
1201         }
1202 
1203         assertReductionBoolArraysEquals(mask, r, Short64VectorTests::allTrue);
1204     }
1205 
1206 
1207     @Test(dataProvider = "shortUnaryOpProvider")
1208     static void withShort64VectorTests(IntFunction<short []> fa) {
1209         short[] a = fa.apply(SPECIES.length());
1210         short[] 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1215                 av.with(0, (short)4).intoArray(r, i);
1216             }
1217         }
1218 
1219         assertInsertArraysEquals(a, r, (short)4, 0);
1220     }
1221 
1222     @Test(dataProvider = "shortCompareOpProvider")
1223     static void lessThanShort64VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) {
1224         short[] a = fa.apply(SPECIES.length());
1225         short[] 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1230                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
1231                 Vector.Mask<Short> 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 = "shortCompareOpProvider")
1243     static void greaterThanShort64VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) {
1244         short[] a = fa.apply(SPECIES.length());
1245         short[] 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1250                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
1251                 Vector.Mask<Short> 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 = "shortCompareOpProvider")
1263     static void equalShort64VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) {
1264         short[] a = fa.apply(SPECIES.length());
1265         short[] 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1270                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
1271                 Vector.Mask<Short> 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 = "shortCompareOpProvider")
1283     static void notEqualShort64VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) {
1284         short[] a = fa.apply(SPECIES.length());
1285         short[] 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1290                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
1291                 Vector.Mask<Short> 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 = "shortCompareOpProvider")
1303     static void lessThanEqShort64VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) {
1304         short[] a = fa.apply(SPECIES.length());
1305         short[] 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1310                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
1311                 Vector.Mask<Short> 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 = "shortCompareOpProvider")
1323     static void greaterThanEqShort64VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) {
1324         short[] a = fa.apply(SPECIES.length());
1325         short[] 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1330                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
1331                 Vector.Mask<Short> 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 short blend(short a, short b, boolean mask) {
1343         return mask ? b : a;
1344     }
1345 
1346     @Test(dataProvider = "shortBinaryOpMaskProvider")
1347     static void blendShort64VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb,
1348                                           IntFunction<boolean[]> fm) {
1349         short[] a = fa.apply(SPECIES.length());
1350         short[] b = fb.apply(SPECIES.length());
1351         short[] r = fr.apply(SPECIES.length());
1352         boolean[] mask = fm.apply(SPECIES.length());
1353         Vector.Mask<Short> vmask = ShortVector.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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1358                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
1359                 av.blend(bv, vmask).intoArray(r, i);
1360             }
1361         }
1362 
1363         assertArraysEquals(a, b, r, mask, Short64VectorTests::blend);
1364     }
1365 
1366     @Test(dataProvider = "shortUnaryOpShuffleProvider")
1367     static void RearrangeShort64VectorTests(IntFunction<short[]> fa,
1368                                            BiFunction<Integer,Integer,int[]> fs) {
1369         short[] a = fa.apply(SPECIES.length());
1370         int[] order = fs.apply(a.length, SPECIES.length());
1371         short[] 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1376                 av.rearrange(ShortVector.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 = "shortUnaryOpProvider")
1387     static void getShort64VectorTests(IntFunction<short[]> fa) {
1388         short[] a = fa.apply(SPECIES.length());
1389         short[] 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                 ShortVector av = ShortVector.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 negShort64VectorTests(IntFunction<short[]> fa) {
1569         short[] a = fa.apply(SPECIES.length());
1570         short[] 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1575                 av.neg().intoArray(r, i);
1576             }
1577         }
1578 
1579         assertArraysEquals(a, r, Short64VectorTests::neg);
1580     }
1581 
1582     @Test(dataProvider = "shortUnaryOpMaskProvider")
1583     static void negMaskedShort64VectorTests(IntFunction<short[]> fa,
1584                                                 IntFunction<boolean[]> fm) {
1585         short[] a = fa.apply(SPECIES.length());
1586         short[] r = fr.apply(SPECIES.length());
1587         boolean[] mask = fm.apply(SPECIES.length());
1588         Vector.Mask<Short> vmask = ShortVector.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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1593                 av.neg(vmask).intoArray(r, i);
1594             }
1595         }
1596 
1597         assertArraysEquals(a, r, mask, Short64VectorTests::neg);
1598     }
1599 
1600     static short abs(short a) {
1601         return (short)(Math.abs((short)a));
1602     }
1603 
1604     @Test(dataProvider = "shortUnaryOpProvider")
1605     static void absShort64VectorTests(IntFunction<short[]> fa) {
1606         short[] a = fa.apply(SPECIES.length());
1607         short[] 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1612                 av.abs().intoArray(r, i);
1613             }
1614         }
1615 
1616         assertArraysEquals(a, r, Short64VectorTests::abs);
1617     }
1618 
1619     @Test(dataProvider = "shortUnaryOpMaskProvider")
1620     static void absMaskedShort64VectorTests(IntFunction<short[]> fa,
1621                                                 IntFunction<boolean[]> fm) {
1622         short[] a = fa.apply(SPECIES.length());
1623         short[] r = fr.apply(SPECIES.length());
1624         boolean[] mask = fm.apply(SPECIES.length());
1625         Vector.Mask<Short> vmask = ShortVector.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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1630                 av.abs(vmask).intoArray(r, i);
1631             }
1632         }
1633 
1634         assertArraysEquals(a, r, mask, Short64VectorTests::abs);
1635     }
1636 
1637 
1638     static short not(short a) {
1639         return (short)(~((short)a));
1640     }
1641 
1642 
1643 
1644     @Test(dataProvider = "shortUnaryOpProvider")
1645     static void notShort64VectorTests(IntFunction<short[]> fa) {


1647         short[] 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1652                 av.not().intoArray(r, i);
1653             }
1654         }
1655 
1656         assertArraysEquals(a, r, Short64VectorTests::not);
1657     }
1658 
1659 
1660 
1661     @Test(dataProvider = "shortUnaryOpMaskProvider")
1662     static void notMaskedShort64VectorTests(IntFunction<short[]> fa,
1663                                                 IntFunction<boolean[]> fm) {
1664         short[] a = fa.apply(SPECIES.length());
1665         short[] r = fr.apply(SPECIES.length());
1666         boolean[] mask = fm.apply(SPECIES.length());
1667         Vector.Mask<Short> vmask = ShortVector.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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1672                 av.not(vmask).intoArray(r, i);
1673             }
1674         }
1675 
1676         assertArraysEquals(a, r, mask, Short64VectorTests::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 Short64VectorTests
  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.ShortVector;
  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 Short64VectorTests extends AbstractVectorTest {
  51 
  52     static final VectorSpecies<Short> SPECIES =
  53                 ShortVector.SPECIES_64;
  54 
  55     static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100);
  56 
  57     interface FUnOp {
  58         short apply(short a);
  59     }
  60 
  61     static void assertArraysEquals(short[] a, short[] 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(short[] a, short[] r, boolean[] mask, FUnOp f) {


 414         short[] 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 419                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 420                 av.add(bv).intoArray(r, i);
 421             }
 422         }
 423 
 424         assertArraysEquals(a, b, r, Short64VectorTests::add);
 425     }
 426 
 427     @Test(dataProvider = "shortBinaryOpMaskProvider")
 428     static void addShort64VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb,
 429                                           IntFunction<boolean[]> fm) {
 430         short[] a = fa.apply(SPECIES.length());
 431         short[] b = fb.apply(SPECIES.length());
 432         short[] r = fr.apply(SPECIES.length());
 433         boolean[] mask = fm.apply(SPECIES.length());
 434         VectorMask<Short> 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 439                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 440                 av.add(bv, vmask).intoArray(r, i);
 441             }
 442         }
 443 
 444         assertArraysEquals(a, b, r, mask, Short64VectorTests::add);
 445     }
 446     static short sub(short a, short b) {
 447         return (short)(a - b);
 448     }
 449 
 450     @Test(dataProvider = "shortBinaryOpProvider")
 451     static void subShort64VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) {
 452         short[] a = fa.apply(SPECIES.length());
 453         short[] b = fb.apply(SPECIES.length());
 454         short[] 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 459                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 460                 av.sub(bv).intoArray(r, i);
 461             }
 462         }
 463 
 464         assertArraysEquals(a, b, r, Short64VectorTests::sub);
 465     }
 466 
 467     @Test(dataProvider = "shortBinaryOpMaskProvider")
 468     static void subShort64VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb,
 469                                           IntFunction<boolean[]> fm) {
 470         short[] a = fa.apply(SPECIES.length());
 471         short[] b = fb.apply(SPECIES.length());
 472         short[] r = fr.apply(SPECIES.length());
 473         boolean[] mask = fm.apply(SPECIES.length());
 474         VectorMask<Short> 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 479                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 480                 av.sub(bv, vmask).intoArray(r, i);
 481             }
 482         }
 483 
 484         assertArraysEquals(a, b, r, mask, Short64VectorTests::sub);
 485     }
 486 
 487 
 488     static short mul(short a, short b) {
 489         return (short)(a * b);
 490     }
 491 
 492     @Test(dataProvider = "shortBinaryOpProvider")
 493     static void mulShort64VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) {
 494         short[] a = fa.apply(SPECIES.length());


 496         short[] 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 501                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 502                 av.mul(bv).intoArray(r, i);
 503             }
 504         }
 505 
 506         assertArraysEquals(a, b, r, Short64VectorTests::mul);
 507     }
 508 
 509     @Test(dataProvider = "shortBinaryOpMaskProvider")
 510     static void mulShort64VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb,
 511                                           IntFunction<boolean[]> fm) {
 512         short[] a = fa.apply(SPECIES.length());
 513         short[] b = fb.apply(SPECIES.length());
 514         short[] r = fr.apply(SPECIES.length());
 515         boolean[] mask = fm.apply(SPECIES.length());
 516         VectorMask<Short> 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 521                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 522                 av.mul(bv, vmask).intoArray(r, i);
 523             }
 524         }
 525 
 526         assertArraysEquals(a, b, r, mask, Short64VectorTests::mul);
 527     }
 528 
 529     static short and(short a, short b) {
 530         return (short)(a & b);
 531     }
 532 
 533     @Test(dataProvider = "shortBinaryOpProvider")
 534     static void andShort64VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) {
 535         short[] a = fa.apply(SPECIES.length());
 536         short[] 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 542                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 543                 av.and(bv).intoArray(r, i);
 544             }
 545         }
 546 
 547         assertArraysEquals(a, b, r, Short64VectorTests::and);
 548     }
 549 
 550 
 551 
 552     @Test(dataProvider = "shortBinaryOpMaskProvider")
 553     static void andShort64VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb,
 554                                           IntFunction<boolean[]> fm) {
 555         short[] a = fa.apply(SPECIES.length());
 556         short[] b = fb.apply(SPECIES.length());
 557         short[] r = fr.apply(SPECIES.length());
 558         boolean[] mask = fm.apply(SPECIES.length());
 559         VectorMask<Short> 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 564                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 565                 av.and(bv, vmask).intoArray(r, i);
 566             }
 567         }
 568 
 569         assertArraysEquals(a, b, r, mask, Short64VectorTests::and);
 570     }
 571 
 572 
 573     static short or(short a, short b) {
 574         return (short)(a | b);
 575     }
 576 
 577     @Test(dataProvider = "shortBinaryOpProvider")
 578     static void orShort64VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) {
 579         short[] 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 586                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 587                 av.or(bv).intoArray(r, i);
 588             }
 589         }
 590 
 591         assertArraysEquals(a, b, r, Short64VectorTests::or);
 592     }
 593 
 594 
 595 
 596     @Test(dataProvider = "shortBinaryOpMaskProvider")
 597     static void orShort64VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb,
 598                                           IntFunction<boolean[]> fm) {
 599         short[] a = fa.apply(SPECIES.length());
 600         short[] b = fb.apply(SPECIES.length());
 601         short[] r = fr.apply(SPECIES.length());
 602         boolean[] mask = fm.apply(SPECIES.length());
 603         VectorMask<Short> 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 608                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 609                 av.or(bv, vmask).intoArray(r, i);
 610             }
 611         }
 612 
 613         assertArraysEquals(a, b, r, mask, Short64VectorTests::or);
 614     }
 615 
 616 
 617     static short xor(short a, short b) {
 618         return (short)(a ^ b);
 619     }
 620 
 621     @Test(dataProvider = "shortBinaryOpProvider")
 622     static void xorShort64VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) {
 623         short[] 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 630                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 631                 av.xor(bv).intoArray(r, i);
 632             }
 633         }
 634 
 635         assertArraysEquals(a, b, r, Short64VectorTests::xor);
 636     }
 637 
 638 
 639 
 640     @Test(dataProvider = "shortBinaryOpMaskProvider")
 641     static void xorShort64VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb,
 642                                           IntFunction<boolean[]> fm) {
 643         short[] a = fa.apply(SPECIES.length());
 644         short[] b = fb.apply(SPECIES.length());
 645         short[] r = fr.apply(SPECIES.length());
 646         boolean[] mask = fm.apply(SPECIES.length());
 647         VectorMask<Short> 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 652                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
 653                 av.xor(bv, vmask).intoArray(r, i);
 654             }
 655         }
 656 
 657         assertArraysEquals(a, b, r, mask, Short64VectorTests::xor);
 658     }
 659 
 660 
 661 
 662 
 663 
 664 
 665 
 666 
 667 


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


 730 
 731         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 732             for (int i = 0; i < a.length; i += SPECIES.length()) {
 733                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 734                 av.shiftL((int)b[i]).intoArray(r, i);
 735             }
 736         }
 737 
 738         assertShiftArraysEquals(a, b, r, Short64VectorTests::shiftL_unary);
 739     }
 740 
 741 
 742 
 743     @Test(dataProvider = "shortBinaryOpMaskProvider")
 744     static void shiftLShort64VectorTestsShift(IntFunction<short[]> fa, IntFunction<short[]> fb,
 745                                           IntFunction<boolean[]> fm) {
 746         short[] a = fa.apply(SPECIES.length());
 747         short[] b = fb.apply(SPECIES.length());
 748         short[] r = fr.apply(SPECIES.length());
 749         boolean[] mask = fm.apply(SPECIES.length());
 750         VectorMask<Short> vmask = VectorMask.fromValues(SPECIES, mask);
 751 
 752         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 753             for (int i = 0; i < a.length; i += SPECIES.length()) {
 754                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
 755                 av.shiftL((int)b[i], vmask).intoArray(r, i);
 756             }
 757         }
 758 
 759         assertShiftArraysEquals(a, b, r, mask, Short64VectorTests::shiftL_unary);
 760     }
 761 
 762 
 763     static short shiftR_unary(short a, short b) {
 764         return (short)(((a & 0xFFFF) >>> (b & 15)));
 765     }
 766 
 767     @Test(dataProvider = "shortBinaryOpProvider")
 768     static void shiftRShort64VectorTestsShift(IntFunction<short[]> fa, IntFunction<short[]> fb) {
 769         short[] a = fa.apply(SPECIES.length());
 770         short[] b = fb.apply(SPECIES.length());


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


1154         assertReductionArraysEquals(a, r, ra, Short64VectorTests::maxAll, Short64VectorTests::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 anyTrueShort64VectorTests(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<Short> vmask = VectorMask.fromArray(SPECIES, mask, i);
1175                 r[i] = vmask.anyTrue();
1176             }
1177         }
1178 
1179         assertReductionBoolArraysEquals(mask, r, Short64VectorTests::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 allTrueShort64VectorTests(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<Short> vmask = VectorMask.fromArray(SPECIES, mask, i);
1201                 r[i] = vmask.allTrue();
1202             }
1203         }
1204 
1205         assertReductionBoolArraysEquals(mask, r, Short64VectorTests::allTrue);
1206     }
1207 
1208 
1209     @Test(dataProvider = "shortUnaryOpProvider")
1210     static void withShort64VectorTests(IntFunction<short []> fa) {
1211         short[] a = fa.apply(SPECIES.length());
1212         short[] 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1217                 av.with(0, (short)4).intoArray(r, i);
1218             }
1219         }
1220 
1221         assertInsertArraysEquals(a, r, (short)4, 0);
1222     }
1223 
1224     @Test(dataProvider = "shortCompareOpProvider")
1225     static void lessThanShort64VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) {
1226         short[] a = fa.apply(SPECIES.length());
1227         short[] 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1232                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
1233                 VectorMask<Short> 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 = "shortCompareOpProvider")
1245     static void greaterThanShort64VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) {
1246         short[] a = fa.apply(SPECIES.length());
1247         short[] 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1252                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
1253                 VectorMask<Short> 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 = "shortCompareOpProvider")
1265     static void equalShort64VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) {
1266         short[] a = fa.apply(SPECIES.length());
1267         short[] 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1272                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
1273                 VectorMask<Short> 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 = "shortCompareOpProvider")
1285     static void notEqualShort64VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) {
1286         short[] a = fa.apply(SPECIES.length());
1287         short[] 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1292                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
1293                 VectorMask<Short> 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 = "shortCompareOpProvider")
1305     static void lessThanEqShort64VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) {
1306         short[] a = fa.apply(SPECIES.length());
1307         short[] 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1312                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
1313                 VectorMask<Short> 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 = "shortCompareOpProvider")
1325     static void greaterThanEqShort64VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) {
1326         short[] a = fa.apply(SPECIES.length());
1327         short[] 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1332                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
1333                 VectorMask<Short> 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 short blend(short a, short b, boolean mask) {
1345         return mask ? b : a;
1346     }
1347 
1348     @Test(dataProvider = "shortBinaryOpMaskProvider")
1349     static void blendShort64VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb,
1350                                           IntFunction<boolean[]> fm) {
1351         short[] a = fa.apply(SPECIES.length());
1352         short[] b = fb.apply(SPECIES.length());
1353         short[] r = fr.apply(SPECIES.length());
1354         boolean[] mask = fm.apply(SPECIES.length());
1355         VectorMask<Short> 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1360                 ShortVector bv = ShortVector.fromArray(SPECIES, b, i);
1361                 av.blend(bv, vmask).intoArray(r, i);
1362             }
1363         }
1364 
1365         assertArraysEquals(a, b, r, mask, Short64VectorTests::blend);
1366     }
1367 
1368     @Test(dataProvider = "shortUnaryOpShuffleProvider")
1369     static void RearrangeShort64VectorTests(IntFunction<short[]> fa,
1370                                            BiFunction<Integer,Integer,int[]> fs) {
1371         short[] a = fa.apply(SPECIES.length());
1372         int[] order = fs.apply(a.length, SPECIES.length());
1373         short[] 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                 ShortVector av = ShortVector.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 = "shortUnaryOpProvider")
1389     static void getShort64VectorTests(IntFunction<short[]> fa) {
1390         short[] a = fa.apply(SPECIES.length());
1391         short[] 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                 ShortVector av = ShortVector.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 negShort64VectorTests(IntFunction<short[]> fa) {
1571         short[] a = fa.apply(SPECIES.length());
1572         short[] 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1577                 av.neg().intoArray(r, i);
1578             }
1579         }
1580 
1581         assertArraysEquals(a, r, Short64VectorTests::neg);
1582     }
1583 
1584     @Test(dataProvider = "shortUnaryOpMaskProvider")
1585     static void negMaskedShort64VectorTests(IntFunction<short[]> fa,
1586                                                 IntFunction<boolean[]> fm) {
1587         short[] a = fa.apply(SPECIES.length());
1588         short[] r = fr.apply(SPECIES.length());
1589         boolean[] mask = fm.apply(SPECIES.length());
1590         VectorMask<Short> 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1595                 av.neg(vmask).intoArray(r, i);
1596             }
1597         }
1598 
1599         assertArraysEquals(a, r, mask, Short64VectorTests::neg);
1600     }
1601 
1602     static short abs(short a) {
1603         return (short)(Math.abs((short)a));
1604     }
1605 
1606     @Test(dataProvider = "shortUnaryOpProvider")
1607     static void absShort64VectorTests(IntFunction<short[]> fa) {
1608         short[] a = fa.apply(SPECIES.length());
1609         short[] 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1614                 av.abs().intoArray(r, i);
1615             }
1616         }
1617 
1618         assertArraysEquals(a, r, Short64VectorTests::abs);
1619     }
1620 
1621     @Test(dataProvider = "shortUnaryOpMaskProvider")
1622     static void absMaskedShort64VectorTests(IntFunction<short[]> fa,
1623                                                 IntFunction<boolean[]> fm) {
1624         short[] a = fa.apply(SPECIES.length());
1625         short[] r = fr.apply(SPECIES.length());
1626         boolean[] mask = fm.apply(SPECIES.length());
1627         VectorMask<Short> 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1632                 av.abs(vmask).intoArray(r, i);
1633             }
1634         }
1635 
1636         assertArraysEquals(a, r, mask, Short64VectorTests::abs);
1637     }
1638 
1639 
1640     static short not(short a) {
1641         return (short)(~((short)a));
1642     }
1643 
1644 
1645 
1646     @Test(dataProvider = "shortUnaryOpProvider")
1647     static void notShort64VectorTests(IntFunction<short[]> fa) {


1649         short[] 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1654                 av.not().intoArray(r, i);
1655             }
1656         }
1657 
1658         assertArraysEquals(a, r, Short64VectorTests::not);
1659     }
1660 
1661 
1662 
1663     @Test(dataProvider = "shortUnaryOpMaskProvider")
1664     static void notMaskedShort64VectorTests(IntFunction<short[]> fa,
1665                                                 IntFunction<boolean[]> fm) {
1666         short[] a = fa.apply(SPECIES.length());
1667         short[] r = fr.apply(SPECIES.length());
1668         boolean[] mask = fm.apply(SPECIES.length());
1669         VectorMask<Short> 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                 ShortVector av = ShortVector.fromArray(SPECIES, a, i);
1674                 av.not(vmask).intoArray(r, i);
1675             }
1676         }
1677 
1678         assertArraysEquals(a, r, mask, Short64VectorTests::not);
1679     }
1680 
1681 
1682 
1683 
1684 
1685 
1686 }
1687 
< prev index next >