1 /* 2 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 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 Byte128VectorTests 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 Byte128VectorTests extends AbstractVectorTest { 49 50 static final Species<Byte> SPECIES = 51 ByteVector.SPECIES_128; 52 53 static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100); 54 55 interface FUnOp { 56 byte apply(byte a); 57 } 58 59 static void assertArraysEquals(byte[] a, byte[] r, FUnOp f) { 60 int i = 0; 61 try { 62 for (; i < a.length; i++) { 63 Assert.assertEquals(r[i], f.apply(a[i])); 64 } 65 } catch (AssertionError e) { 66 Assert.assertEquals(r[i], f.apply(a[i]), "at index #" + i + ", input = " + a[i]); 67 } 68 } 69 70 static void assertArraysEquals(byte[] a, byte[] r, boolean[] mask, FUnOp f) { 71 int i = 0; 72 try { 73 for (; i < a.length; i++) { 74 Assert.assertEquals(r[i], mask[i % SPECIES.length()] ? f.apply(a[i]) : a[i]); 75 } 76 } catch (AssertionError e) { 77 Assert.assertEquals(r[i], mask[i % SPECIES.length()] ? f.apply(a[i]) : a[i], "at index #" + i + ", input = " + a[i] + ", mask = " + mask[i % SPECIES.length()]); 78 } 79 } 80 81 interface FReductionOp { 82 byte apply(byte[] a, int idx); 83 } 84 85 interface FReductionAllOp { 86 byte apply(byte[] a); 87 } 88 89 static void assertReductionArraysEquals(byte[] a, byte[] b, byte c, 90 FReductionOp f, FReductionAllOp fa) { 91 int i = 0; 92 try { 93 Assert.assertEquals(c, fa.apply(a)); 94 for (; i < a.length; i += SPECIES.length()) { 95 Assert.assertEquals(b[i], f.apply(a, i)); 96 } 97 } catch (AssertionError e) { 98 Assert.assertEquals(c, fa.apply(a), "Final result is incorrect!"); 99 Assert.assertEquals(b[i], f.apply(a, i), "at index #" + i); 100 } 101 } 102 103 interface FBoolReductionOp { 104 boolean apply(boolean[] a, int idx); 105 } 106 107 static void assertReductionBoolArraysEquals(boolean[] a, boolean[] b, FBoolReductionOp f) { 108 int i = 0; 109 try { 110 for (; i < a.length; i += SPECIES.length()) { 111 Assert.assertEquals(f.apply(a, i), b[i]); 112 } 113 } catch (AssertionError e) { 114 Assert.assertEquals(f.apply(a, i), b[i], "at index #" + i); 115 } 116 } 117 118 static void assertInsertArraysEquals(byte[] a, byte[] b, byte element, int index) { 119 int i = 0; 120 try { 121 for (; i < a.length; i += 1) { 122 if(i%SPECIES.length() == index) { 123 Assert.assertEquals(b[i], element); 124 } else { 125 Assert.assertEquals(b[i], a[i]); 126 } 127 } 128 } catch (AssertionError e) { 129 if (i%SPECIES.length() == index) { 130 Assert.assertEquals(b[i], element, "at index #" + i); 131 } else { 132 Assert.assertEquals(b[i], a[i], "at index #" + i); 133 } 134 } 135 } 136 137 static void assertRearrangeArraysEquals(byte[] a, byte[] r, int[] order, int vector_len) { 138 int i = 0, j = 0; 139 try { 140 for (; i < a.length; i += vector_len) { 141 for (j = 0; j < vector_len; j++) { 142 Assert.assertEquals(r[i+j], a[i+order[i+j]]); 143 } 144 } 145 } catch (AssertionError e) { 146 int idx = i + j; 147 Assert.assertEquals(r[i+j], a[i+order[i+j]], "at index #" + idx + ", input = " + a[i+order[i+j]]); 148 } 149 } 150 151 interface FBinOp { 152 byte apply(byte a, byte b); 153 } 154 155 interface FBinMaskOp { 156 byte apply(byte a, byte b, boolean m); 157 158 static FBinMaskOp lift(FBinOp f) { 159 return (a, b, m) -> m ? f.apply(a, b) : a; 160 } 161 } 162 163 static void assertArraysEquals(byte[] a, byte[] b, byte[] r, FBinOp f) { 164 int i = 0; 165 try { 166 for (; i < a.length; i++) { 167 Assert.assertEquals(r[i], f.apply(a[i], b[i])); 168 } 169 } catch (AssertionError e) { 170 Assert.assertEquals(f.apply(a[i], b[i]), r[i], "(" + a[i] + ", " + b[i] + ") at index #" + i); 171 } 172 } 173 174 static void assertArraysEquals(byte[] a, byte[] b, byte[] r, boolean[] mask, FBinOp f) { 175 assertArraysEquals(a, b, r, mask, FBinMaskOp.lift(f)); 176 } 177 178 static void assertArraysEquals(byte[] a, byte[] b, byte[] r, boolean[] mask, FBinMaskOp f) { 179 int i = 0; 180 try { 181 for (; i < a.length; i++) { 182 Assert.assertEquals(r[i], f.apply(a[i], b[i], mask[i % SPECIES.length()])); 183 } 184 } catch (AssertionError err) { 185 Assert.assertEquals(r[i], f.apply(a[i], b[i], mask[i % SPECIES.length()]), "at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", mask = " + mask[i % SPECIES.length()]); 186 } 187 } 188 189 static void assertShiftArraysEquals(byte[] a, byte[] b, byte[] r, FBinOp f) { 190 int i = 0; 191 int j = 0; 192 try { 193 for (; j < a.length; j += SPECIES.length()) { 194 for (i = 0; i < SPECIES.length(); i++) { 195 Assert.assertEquals(f.apply(a[i+j], b[j]), r[i+j]); 196 } 197 } 198 } catch (AssertionError e) { 199 Assert.assertEquals(f.apply(a[i+j], b[j]), r[i+j], "at index #" + i + ", " + j); 200 } 201 } 202 203 static void assertShiftArraysEquals(byte[] a, byte[] b, byte[] r, boolean[] mask, FBinOp f) { 204 assertShiftArraysEquals(a, b, r, mask, FBinMaskOp.lift(f)); 205 } 206 207 static void assertShiftArraysEquals(byte[] a, byte[] b, byte[] r, boolean[] mask, FBinMaskOp f) { 208 int i = 0; 209 int j = 0; 210 try { 211 for (; j < a.length; j += SPECIES.length()) { 212 for (i = 0; i < SPECIES.length(); i++) { 213 Assert.assertEquals(r[i+j], f.apply(a[i+j], b[j], mask[i])); 214 } 215 } 216 } catch (AssertionError err) { 217 Assert.assertEquals(r[i+j], f.apply(a[i+j], b[j], mask[i]), "at index #" + i + ", input1 = " + a[i+j] + ", input2 = " + b[j] + ", mask = " + mask[i]); 218 } 219 } 220 221 222 interface FBinArrayOp { 223 byte apply(byte[] a, int b); 224 } 225 226 static void assertArraysEquals(byte[] a, byte[] r, FBinArrayOp f) { 227 int i = 0; 228 try { 229 for (; i < a.length; i++) { 230 Assert.assertEquals(f.apply(a, i), r[i]); 231 } 232 } catch (AssertionError e) { 233 Assert.assertEquals(f.apply(a,i), r[i], "at index #" + i); 234 } 235 } 236 237 static final List<IntFunction<byte[]>> BYTE_GENERATORS = List.of( 238 withToString("byte[-i * 5]", (int s) -> { 239 return fill(s * 1000, 240 i -> (byte)(-i * 5)); 241 }), 242 withToString("byte[i * 5]", (int s) -> { 243 return fill(s * 1000, 244 i -> (byte)(i * 5)); 245 }), 246 withToString("byte[i + 1]", (int s) -> { 247 return fill(s * 1000, 248 i -> (((byte)(i + 1) == 0) ? 1 : (byte)(i + 1))); 249 }), 250 withToString("byte[cornerCaseValue(i)]", (int s) -> { 251 return fill(s * 1000, 252 i -> cornerCaseValue(i)); 253 }) 254 ); 255 256 // Create combinations of pairs 257 // @@@ Might be sensitive to order e.g. div by 0 258 static final List<List<IntFunction<byte[]>>> BYTE_GENERATOR_PAIRS = 259 Stream.of(BYTE_GENERATORS.get(0)). 260 flatMap(fa -> BYTE_GENERATORS.stream().skip(1).map(fb -> List.of(fa, fb))). 261 collect(Collectors.toList()); 262 263 @DataProvider 264 public Object[][] boolUnaryOpProvider() { 265 return BOOL_ARRAY_GENERATORS.stream(). 266 map(f -> new Object[]{f}). 267 toArray(Object[][]::new); 268 } 269 270 271 @DataProvider 272 public Object[][] byteBinaryOpProvider() { 273 return BYTE_GENERATOR_PAIRS.stream().map(List::toArray). 274 toArray(Object[][]::new); 275 } 276 277 @DataProvider 278 public Object[][] byteIndexedOpProvider() { 279 return BYTE_GENERATOR_PAIRS.stream().map(List::toArray). 280 toArray(Object[][]::new); 281 } 282 283 @DataProvider 284 public Object[][] byteBinaryOpMaskProvider() { 285 return BOOLEAN_MASK_GENERATORS.stream(). 286 flatMap(fm -> BYTE_GENERATOR_PAIRS.stream().map(lfa -> { 287 return Stream.concat(lfa.stream(), Stream.of(fm)).toArray(); 288 })). 289 toArray(Object[][]::new); 290 } 291 292 293 @DataProvider 294 public Object[][] byteUnaryOpProvider() { 295 return BYTE_GENERATORS.stream(). 296 map(f -> new Object[]{f}). 297 toArray(Object[][]::new); 298 } 299 300 @DataProvider 301 public Object[][] byteUnaryOpMaskProvider() { 302 return BOOLEAN_MASK_GENERATORS.stream(). 303 flatMap(fm -> BYTE_GENERATORS.stream().map(fa -> { 304 return new Object[] {fa, fm}; 305 })). 306 toArray(Object[][]::new); 307 } 308 309 @DataProvider 310 public Object[][] byteUnaryOpShuffleProvider() { 311 return INT_SHUFFLE_GENERATORS.stream(). 312 flatMap(fs -> BYTE_GENERATORS.stream().map(fa -> { 313 return new Object[] {fa, fs}; 314 })). 315 toArray(Object[][]::new); 316 } 317 318 @DataProvider 319 public Object[][] byteUnaryOpIndexProvider() { 320 return INT_INDEX_GENERATORS.stream(). 321 flatMap(fs -> BYTE_GENERATORS.stream().map(fa -> { 322 return new Object[] {fa, fs}; 323 })). 324 toArray(Object[][]::new); 325 } 326 327 328 static final List<IntFunction<byte[]>> BYTE_COMPARE_GENERATORS = List.of( 329 withToString("byte[i]", (int s) -> { 330 return fill(s * 1000, 331 i -> (byte)i); 332 }), 333 withToString("byte[i + 1]", (int s) -> { 334 return fill(s * 1000, 335 i -> (byte)(i + 1)); 336 }), 337 withToString("byte[i - 2]", (int s) -> { 338 return fill(s * 1000, 339 i -> (byte)(i - 2)); 340 }), 341 withToString("byte[zigZag(i)]", (int s) -> { 342 return fill(s * 1000, 343 i -> i%3 == 0 ? (byte)i : (i%3 == 1 ? (byte)(i + 1) : (byte)(i - 2))); 344 }), 345 withToString("byte[cornerCaseValue(i)]", (int s) -> { 346 return fill(s * 1000, 347 i -> cornerCaseValue(i)); 348 }) 349 ); 350 351 static final List<List<IntFunction<byte[]>>> BYTE_COMPARE_GENERATOR_PAIRS = 352 BYTE_COMPARE_GENERATORS.stream(). 353 flatMap(fa -> BYTE_COMPARE_GENERATORS.stream().map(fb -> List.of(fa, fb))). 354 collect(Collectors.toList()); 355 356 @DataProvider 357 public Object[][] byteCompareOpProvider() { 358 return BYTE_COMPARE_GENERATOR_PAIRS.stream().map(List::toArray). 359 toArray(Object[][]::new); 360 } 361 362 interface ToByteF { 363 byte apply(int i); 364 } 365 366 static byte[] fill(int s , ToByteF f) { 367 return fill(new byte[s], f); 368 } 369 370 static byte[] fill(byte[] a, ToByteF f) { 371 for (int i = 0; i < a.length; i++) { 372 a[i] = f.apply(i); 373 } 374 return a; 375 } 376 377 static byte cornerCaseValue(int i) { 378 switch(i % 5) { 379 case 0: 380 return Byte.MAX_VALUE; 381 case 1: 382 return Byte.MIN_VALUE; 383 case 2: 384 return Byte.MIN_VALUE; 385 case 3: 386 return Byte.MAX_VALUE; 387 default: 388 return (byte)0; 389 } 390 } 391 static byte get(byte[] a, int i) { 392 return (byte) a[i]; 393 } 394 395 static final IntFunction<byte[]> fr = (vl) -> { 396 int length = 1000 * vl; 397 return new byte[length]; 398 }; 399 400 static final IntFunction<boolean[]> fmr = (vl) -> { 401 int length = 1000 * vl; 402 return new boolean[length]; 403 }; 404 static byte add(byte a, byte b) { 405 return (byte)(a + b); 406 } 407 408 @Test(dataProvider = "byteBinaryOpProvider") 409 static void addByte128VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 410 byte[] a = fa.apply(SPECIES.length()); 411 byte[] b = fb.apply(SPECIES.length()); 412 byte[] r = fr.apply(SPECIES.length()); 413 414 for (int ic = 0; ic < INVOC_COUNT; ic++) { 415 for (int i = 0; i < a.length; i += SPECIES.length()) { 416 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 417 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 418 av.add(bv).intoArray(r, i); 419 } 420 } 421 422 assertArraysEquals(a, b, r, Byte128VectorTests::add); 423 } 424 425 @Test(dataProvider = "byteBinaryOpMaskProvider") 426 static void addByte128VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 427 IntFunction<boolean[]> fm) { 428 byte[] a = fa.apply(SPECIES.length()); 429 byte[] b = fb.apply(SPECIES.length()); 430 byte[] r = fr.apply(SPECIES.length()); 431 boolean[] mask = fm.apply(SPECIES.length()); 432 Vector.Mask<Byte> vmask = ByteVector.maskFromValues(SPECIES, mask); 433 434 for (int ic = 0; ic < INVOC_COUNT; ic++) { 435 for (int i = 0; i < a.length; i += SPECIES.length()) { 436 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 437 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 438 av.add(bv, vmask).intoArray(r, i); 439 } 440 } 441 442 assertArraysEquals(a, b, r, mask, Byte128VectorTests::add); 443 } 444 static byte sub(byte a, byte b) { 445 return (byte)(a - b); 446 } 447 448 @Test(dataProvider = "byteBinaryOpProvider") 449 static void subByte128VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 450 byte[] a = fa.apply(SPECIES.length()); 451 byte[] b = fb.apply(SPECIES.length()); 452 byte[] r = fr.apply(SPECIES.length()); 453 454 for (int ic = 0; ic < INVOC_COUNT; ic++) { 455 for (int i = 0; i < a.length; i += SPECIES.length()) { 456 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 457 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 458 av.sub(bv).intoArray(r, i); 459 } 460 } 461 462 assertArraysEquals(a, b, r, Byte128VectorTests::sub); 463 } 464 465 @Test(dataProvider = "byteBinaryOpMaskProvider") 466 static void subByte128VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 467 IntFunction<boolean[]> fm) { 468 byte[] a = fa.apply(SPECIES.length()); 469 byte[] b = fb.apply(SPECIES.length()); 470 byte[] r = fr.apply(SPECIES.length()); 471 boolean[] mask = fm.apply(SPECIES.length()); 472 Vector.Mask<Byte> vmask = ByteVector.maskFromValues(SPECIES, mask); 473 474 for (int ic = 0; ic < INVOC_COUNT; ic++) { 475 for (int i = 0; i < a.length; i += SPECIES.length()) { 476 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 477 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 478 av.sub(bv, vmask).intoArray(r, i); 479 } 480 } 481 482 assertArraysEquals(a, b, r, mask, Byte128VectorTests::sub); 483 } 484 485 486 static byte mul(byte a, byte b) { 487 return (byte)(a * b); 488 } 489 490 @Test(dataProvider = "byteBinaryOpProvider") 491 static void mulByte128VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 492 byte[] a = fa.apply(SPECIES.length()); 493 byte[] b = fb.apply(SPECIES.length()); 494 byte[] r = fr.apply(SPECIES.length()); 495 496 for (int ic = 0; ic < INVOC_COUNT; ic++) { 497 for (int i = 0; i < a.length; i += SPECIES.length()) { 498 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 499 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 500 av.mul(bv).intoArray(r, i); 501 } 502 } 503 504 assertArraysEquals(a, b, r, Byte128VectorTests::mul); 505 } 506 507 @Test(dataProvider = "byteBinaryOpMaskProvider") 508 static void mulByte128VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 509 IntFunction<boolean[]> fm) { 510 byte[] a = fa.apply(SPECIES.length()); 511 byte[] b = fb.apply(SPECIES.length()); 512 byte[] r = fr.apply(SPECIES.length()); 513 boolean[] mask = fm.apply(SPECIES.length()); 514 Vector.Mask<Byte> vmask = ByteVector.maskFromValues(SPECIES, mask); 515 516 for (int ic = 0; ic < INVOC_COUNT; ic++) { 517 for (int i = 0; i < a.length; i += SPECIES.length()) { 518 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 519 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 520 av.mul(bv, vmask).intoArray(r, i); 521 } 522 } 523 524 assertArraysEquals(a, b, r, mask, Byte128VectorTests::mul); 525 } 526 527 static byte and(byte a, byte b) { 528 return (byte)(a & b); 529 } 530 531 @Test(dataProvider = "byteBinaryOpProvider") 532 static void andByte128VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 533 byte[] a = fa.apply(SPECIES.length()); 534 byte[] b = fb.apply(SPECIES.length()); 535 byte[] r = fr.apply(SPECIES.length()); 536 537 for (int ic = 0; ic < INVOC_COUNT; ic++) { 538 for (int i = 0; i < a.length; i += SPECIES.length()) { 539 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 540 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 541 av.and(bv).intoArray(r, i); 542 } 543 } 544 545 assertArraysEquals(a, b, r, Byte128VectorTests::and); 546 } 547 548 549 550 @Test(dataProvider = "byteBinaryOpMaskProvider") 551 static void andByte128VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 552 IntFunction<boolean[]> fm) { 553 byte[] a = fa.apply(SPECIES.length()); 554 byte[] b = fb.apply(SPECIES.length()); 555 byte[] r = fr.apply(SPECIES.length()); 556 boolean[] mask = fm.apply(SPECIES.length()); 557 Vector.Mask<Byte> vmask = ByteVector.maskFromValues(SPECIES, mask); 558 559 for (int ic = 0; ic < INVOC_COUNT; ic++) { 560 for (int i = 0; i < a.length; i += SPECIES.length()) { 561 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 562 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 563 av.and(bv, vmask).intoArray(r, i); 564 } 565 } 566 567 assertArraysEquals(a, b, r, mask, Byte128VectorTests::and); 568 } 569 570 571 static byte or(byte a, byte b) { 572 return (byte)(a | b); 573 } 574 575 @Test(dataProvider = "byteBinaryOpProvider") 576 static void orByte128VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 577 byte[] a = fa.apply(SPECIES.length()); 578 byte[] b = fb.apply(SPECIES.length()); 579 byte[] r = fr.apply(SPECIES.length()); 580 581 for (int ic = 0; ic < INVOC_COUNT; ic++) { 582 for (int i = 0; i < a.length; i += SPECIES.length()) { 583 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 584 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 585 av.or(bv).intoArray(r, i); 586 } 587 } 588 589 assertArraysEquals(a, b, r, Byte128VectorTests::or); 590 } 591 592 593 594 @Test(dataProvider = "byteBinaryOpMaskProvider") 595 static void orByte128VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 596 IntFunction<boolean[]> fm) { 597 byte[] a = fa.apply(SPECIES.length()); 598 byte[] b = fb.apply(SPECIES.length()); 599 byte[] r = fr.apply(SPECIES.length()); 600 boolean[] mask = fm.apply(SPECIES.length()); 601 Vector.Mask<Byte> vmask = ByteVector.maskFromValues(SPECIES, mask); 602 603 for (int ic = 0; ic < INVOC_COUNT; ic++) { 604 for (int i = 0; i < a.length; i += SPECIES.length()) { 605 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 606 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 607 av.or(bv, vmask).intoArray(r, i); 608 } 609 } 610 611 assertArraysEquals(a, b, r, mask, Byte128VectorTests::or); 612 } 613 614 615 static byte xor(byte a, byte b) { 616 return (byte)(a ^ b); 617 } 618 619 @Test(dataProvider = "byteBinaryOpProvider") 620 static void xorByte128VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 621 byte[] a = fa.apply(SPECIES.length()); 622 byte[] b = fb.apply(SPECIES.length()); 623 byte[] r = fr.apply(SPECIES.length()); 624 625 for (int ic = 0; ic < INVOC_COUNT; ic++) { 626 for (int i = 0; i < a.length; i += SPECIES.length()) { 627 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 628 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 629 av.xor(bv).intoArray(r, i); 630 } 631 } 632 633 assertArraysEquals(a, b, r, Byte128VectorTests::xor); 634 } 635 636 637 638 @Test(dataProvider = "byteBinaryOpMaskProvider") 639 static void xorByte128VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 640 IntFunction<boolean[]> fm) { 641 byte[] a = fa.apply(SPECIES.length()); 642 byte[] b = fb.apply(SPECIES.length()); 643 byte[] r = fr.apply(SPECIES.length()); 644 boolean[] mask = fm.apply(SPECIES.length()); 645 Vector.Mask<Byte> vmask = ByteVector.maskFromValues(SPECIES, mask); 646 647 for (int ic = 0; ic < INVOC_COUNT; ic++) { 648 for (int i = 0; i < a.length; i += SPECIES.length()) { 649 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 650 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 651 av.xor(bv, vmask).intoArray(r, i); 652 } 653 } 654 655 assertArraysEquals(a, b, r, mask, Byte128VectorTests::xor); 656 } 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 static byte aShiftR_unary(byte a, byte b) { 672 return (byte)((a >> (b & 7))); 673 } 674 675 @Test(dataProvider = "byteBinaryOpProvider") 676 static void aShiftRByte128VectorTestsShift(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 677 byte[] a = fa.apply(SPECIES.length()); 678 byte[] b = fb.apply(SPECIES.length()); 679 byte[] r = fr.apply(SPECIES.length()); 680 681 for (int ic = 0; ic < INVOC_COUNT; ic++) { 682 for (int i = 0; i < a.length; i += SPECIES.length()) { 683 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 684 av.aShiftR((int)b[i]).intoArray(r, i); 685 } 686 } 687 688 assertShiftArraysEquals(a, b, r, Byte128VectorTests::aShiftR_unary); 689 } 690 691 692 693 @Test(dataProvider = "byteBinaryOpMaskProvider") 694 static void aShiftRByte128VectorTestsShift(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 695 IntFunction<boolean[]> fm) { 696 byte[] a = fa.apply(SPECIES.length()); 697 byte[] b = fb.apply(SPECIES.length()); 698 byte[] r = fr.apply(SPECIES.length()); 699 boolean[] mask = fm.apply(SPECIES.length()); 700 Vector.Mask<Byte> vmask = ByteVector.maskFromValues(SPECIES, mask); 701 702 for (int ic = 0; ic < INVOC_COUNT; ic++) { 703 for (int i = 0; i < a.length; i += SPECIES.length()) { 704 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 705 av.aShiftR((int)b[i], vmask).intoArray(r, i); 706 } 707 } 708 709 assertShiftArraysEquals(a, b, r, mask, Byte128VectorTests::aShiftR_unary); 710 } 711 712 713 static byte shiftL_unary(byte a, byte b) { 714 return (byte)((a << (b & 7))); 715 } 716 717 @Test(dataProvider = "byteBinaryOpProvider") 718 static void shiftLByte128VectorTestsShift(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 719 byte[] a = fa.apply(SPECIES.length()); 720 byte[] b = fb.apply(SPECIES.length()); 721 byte[] r = fr.apply(SPECIES.length()); 722 723 for (int ic = 0; ic < INVOC_COUNT; ic++) { 724 for (int i = 0; i < a.length; i += SPECIES.length()) { 725 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 726 av.shiftL((int)b[i]).intoArray(r, i); 727 } 728 } 729 730 assertShiftArraysEquals(a, b, r, Byte128VectorTests::shiftL_unary); 731 } 732 733 734 735 @Test(dataProvider = "byteBinaryOpMaskProvider") 736 static void shiftLByte128VectorTestsShift(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 737 IntFunction<boolean[]> fm) { 738 byte[] a = fa.apply(SPECIES.length()); 739 byte[] b = fb.apply(SPECIES.length()); 740 byte[] r = fr.apply(SPECIES.length()); 741 boolean[] mask = fm.apply(SPECIES.length()); 742 Vector.Mask<Byte> vmask = ByteVector.maskFromValues(SPECIES, mask); 743 744 for (int ic = 0; ic < INVOC_COUNT; ic++) { 745 for (int i = 0; i < a.length; i += SPECIES.length()) { 746 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 747 av.shiftL((int)b[i], vmask).intoArray(r, i); 748 } 749 } 750 751 assertShiftArraysEquals(a, b, r, mask, Byte128VectorTests::shiftL_unary); 752 } 753 754 755 static byte shiftR_unary(byte a, byte b) { 756 return (byte)(((a & 0xFF) >>> (b & 7))); 757 } 758 759 @Test(dataProvider = "byteBinaryOpProvider") 760 static void shiftRByte128VectorTestsShift(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 761 byte[] a = fa.apply(SPECIES.length()); 762 byte[] b = fb.apply(SPECIES.length()); 763 byte[] r = fr.apply(SPECIES.length()); 764 765 for (int ic = 0; ic < INVOC_COUNT; ic++) { 766 for (int i = 0; i < a.length; i += SPECIES.length()) { 767 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 768 av.shiftR((int)b[i]).intoArray(r, i); 769 } 770 } 771 772 assertShiftArraysEquals(a, b, r, Byte128VectorTests::shiftR_unary); 773 } 774 775 776 777 @Test(dataProvider = "byteBinaryOpMaskProvider") 778 static void shiftRByte128VectorTestsShift(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 779 IntFunction<boolean[]> fm) { 780 byte[] a = fa.apply(SPECIES.length()); 781 byte[] b = fb.apply(SPECIES.length()); 782 byte[] r = fr.apply(SPECIES.length()); 783 boolean[] mask = fm.apply(SPECIES.length()); 784 Vector.Mask<Byte> vmask = ByteVector.maskFromValues(SPECIES, mask); 785 786 for (int ic = 0; ic < INVOC_COUNT; ic++) { 787 for (int i = 0; i < a.length; i += SPECIES.length()) { 788 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 789 av.shiftR((int)b[i], vmask).intoArray(r, i); 790 } 791 } 792 793 assertShiftArraysEquals(a, b, r, mask, Byte128VectorTests::shiftR_unary); 794 } 795 796 797 798 799 800 801 802 static byte max(byte a, byte b) { 803 return (byte)(Math.max(a, b)); 804 } 805 806 @Test(dataProvider = "byteBinaryOpProvider") 807 static void maxByte128VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 808 byte[] a = fa.apply(SPECIES.length()); 809 byte[] b = fb.apply(SPECIES.length()); 810 byte[] r = fr.apply(SPECIES.length()); 811 812 for (int ic = 0; ic < INVOC_COUNT; ic++) { 813 for (int i = 0; i < a.length; i += SPECIES.length()) { 814 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 815 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 816 av.max(bv).intoArray(r, i); 817 } 818 } 819 820 assertArraysEquals(a, b, r, Byte128VectorTests::max); 821 } 822 static byte min(byte a, byte b) { 823 return (byte)(Math.min(a, b)); 824 } 825 826 @Test(dataProvider = "byteBinaryOpProvider") 827 static void minByte128VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 828 byte[] a = fa.apply(SPECIES.length()); 829 byte[] b = fb.apply(SPECIES.length()); 830 byte[] r = fr.apply(SPECIES.length()); 831 832 for (int ic = 0; ic < INVOC_COUNT; ic++) { 833 for (int i = 0; i < a.length; i += SPECIES.length()) { 834 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 835 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 836 av.min(bv).intoArray(r, i); 837 } 838 } 839 840 assertArraysEquals(a, b, r, Byte128VectorTests::min); 841 } 842 843 static byte andAll(byte[] a, int idx) { 844 byte res = -1; 845 for (int i = idx; i < (idx + SPECIES.length()); i++) { 846 res &= a[i]; 847 } 848 849 return res; 850 } 851 852 static byte andAll(byte[] a) { 853 byte res = -1; 854 for (int i = 0; i < a.length; i += SPECIES.length()) { 855 byte tmp = -1; 856 for (int j = 0; j < SPECIES.length(); j++) { 857 tmp &= a[i + j]; 858 } 859 res &= tmp; 860 } 861 862 return res; 863 } 864 865 866 @Test(dataProvider = "byteUnaryOpProvider") 867 static void andAllByte128VectorTests(IntFunction<byte[]> fa) { 868 byte[] a = fa.apply(SPECIES.length()); 869 byte[] r = fr.apply(SPECIES.length()); 870 byte ra = -1; 871 872 for (int ic = 0; ic < INVOC_COUNT; ic++) { 873 for (int i = 0; i < a.length; i += SPECIES.length()) { 874 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 875 r[i] = av.andAll(); 876 } 877 } 878 879 for (int ic = 0; ic < INVOC_COUNT; ic++) { 880 ra = -1; 881 for (int i = 0; i < a.length; i += SPECIES.length()) { 882 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 883 ra &= av.andAll(); 884 } 885 } 886 887 assertReductionArraysEquals(a, r, ra, Byte128VectorTests::andAll, Byte128VectorTests::andAll); 888 } 889 890 891 static byte orAll(byte[] a, int idx) { 892 byte res = 0; 893 for (int i = idx; i < (idx + SPECIES.length()); i++) { 894 res |= a[i]; 895 } 896 897 return res; 898 } 899 900 static byte orAll(byte[] a) { 901 byte res = 0; 902 for (int i = 0; i < a.length; i += SPECIES.length()) { 903 byte tmp = 0; 904 for (int j = 0; j < SPECIES.length(); j++) { 905 tmp |= a[i + j]; 906 } 907 res |= tmp; 908 } 909 910 return res; 911 } 912 913 914 @Test(dataProvider = "byteUnaryOpProvider") 915 static void orAllByte128VectorTests(IntFunction<byte[]> fa) { 916 byte[] a = fa.apply(SPECIES.length()); 917 byte[] r = fr.apply(SPECIES.length()); 918 byte ra = 0; 919 920 for (int ic = 0; ic < INVOC_COUNT; ic++) { 921 for (int i = 0; i < a.length; i += SPECIES.length()) { 922 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 923 r[i] = av.orAll(); 924 } 925 } 926 927 for (int ic = 0; ic < INVOC_COUNT; ic++) { 928 ra = 0; 929 for (int i = 0; i < a.length; i += SPECIES.length()) { 930 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 931 ra |= av.orAll(); 932 } 933 } 934 935 assertReductionArraysEquals(a, r, ra, Byte128VectorTests::orAll, Byte128VectorTests::orAll); 936 } 937 938 939 static byte xorAll(byte[] a, int idx) { 940 byte res = 0; 941 for (int i = idx; i < (idx + SPECIES.length()); i++) { 942 res ^= a[i]; 943 } 944 945 return res; 946 } 947 948 static byte xorAll(byte[] a) { 949 byte res = 0; 950 for (int i = 0; i < a.length; i += SPECIES.length()) { 951 byte tmp = 0; 952 for (int j = 0; j < SPECIES.length(); j++) { 953 tmp ^= a[i + j]; 954 } 955 res ^= tmp; 956 } 957 958 return res; 959 } 960 961 962 @Test(dataProvider = "byteUnaryOpProvider") 963 static void xorAllByte128VectorTests(IntFunction<byte[]> fa) { 964 byte[] a = fa.apply(SPECIES.length()); 965 byte[] r = fr.apply(SPECIES.length()); 966 byte ra = 0; 967 968 for (int ic = 0; ic < INVOC_COUNT; ic++) { 969 for (int i = 0; i < a.length; i += SPECIES.length()) { 970 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 971 r[i] = av.xorAll(); 972 } 973 } 974 975 for (int ic = 0; ic < INVOC_COUNT; ic++) { 976 ra = 0; 977 for (int i = 0; i < a.length; i += SPECIES.length()) { 978 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 979 ra ^= av.xorAll(); 980 } 981 } 982 983 assertReductionArraysEquals(a, r, ra, Byte128VectorTests::xorAll, Byte128VectorTests::xorAll); 984 } 985 986 static byte addAll(byte[] a, int idx) { 987 byte res = 0; 988 for (int i = idx; i < (idx + SPECIES.length()); i++) { 989 res += a[i]; 990 } 991 992 return res; 993 } 994 995 static byte addAll(byte[] a) { 996 byte res = 0; 997 for (int i = 0; i < a.length; i += SPECIES.length()) { 998 byte tmp = 0; 999 for (int j = 0; j < SPECIES.length(); j++) { 1000 tmp += a[i + j]; 1001 } 1002 res += tmp; 1003 } 1004 1005 return res; 1006 } 1007 @Test(dataProvider = "byteUnaryOpProvider") 1008 static void addAllByte128VectorTests(IntFunction<byte[]> fa) { 1009 byte[] a = fa.apply(SPECIES.length()); 1010 byte[] r = fr.apply(SPECIES.length()); 1011 byte ra = 0; 1012 1013 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1014 for (int i = 0; i < a.length; i += SPECIES.length()) { 1015 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1016 r[i] = av.addAll(); 1017 } 1018 } 1019 1020 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1021 ra = 0; 1022 for (int i = 0; i < a.length; i += SPECIES.length()) { 1023 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1024 ra += av.addAll(); 1025 } 1026 } 1027 1028 assertReductionArraysEquals(a, r, ra, Byte128VectorTests::addAll, Byte128VectorTests::addAll); 1029 } 1030 static byte mulAll(byte[] a, int idx) { 1031 byte res = 1; 1032 for (int i = idx; i < (idx + SPECIES.length()); i++) { 1033 res *= a[i]; 1034 } 1035 1036 return res; 1037 } 1038 1039 static byte mulAll(byte[] a) { 1040 byte res = 1; 1041 for (int i = 0; i < a.length; i += SPECIES.length()) { 1042 byte tmp = 1; 1043 for (int j = 0; j < SPECIES.length(); j++) { 1044 tmp *= a[i + j]; 1045 } 1046 res *= tmp; 1047 } 1048 1049 return res; 1050 } 1051 @Test(dataProvider = "byteUnaryOpProvider") 1052 static void mulAllByte128VectorTests(IntFunction<byte[]> fa) { 1053 byte[] a = fa.apply(SPECIES.length()); 1054 byte[] r = fr.apply(SPECIES.length()); 1055 byte ra = 1; 1056 1057 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1058 for (int i = 0; i < a.length; i += SPECIES.length()) { 1059 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1060 r[i] = av.mulAll(); 1061 } 1062 } 1063 1064 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1065 ra = 1; 1066 for (int i = 0; i < a.length; i += SPECIES.length()) { 1067 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1068 ra *= av.mulAll(); 1069 } 1070 } 1071 1072 assertReductionArraysEquals(a, r, ra, Byte128VectorTests::mulAll, Byte128VectorTests::mulAll); 1073 } 1074 static byte minAll(byte[] a, int idx) { 1075 byte res = Byte.MAX_VALUE; 1076 for (int i = idx; i < (idx + SPECIES.length()); i++) { 1077 res = (byte)Math.min(res, a[i]); 1078 } 1079 1080 return res; 1081 } 1082 1083 static byte minAll(byte[] a) { 1084 byte res = Byte.MAX_VALUE; 1085 for (int i = 0; i < a.length; i++) { 1086 res = (byte)Math.min(res, a[i]); 1087 } 1088 1089 return res; 1090 } 1091 @Test(dataProvider = "byteUnaryOpProvider") 1092 static void minAllByte128VectorTests(IntFunction<byte[]> fa) { 1093 byte[] a = fa.apply(SPECIES.length()); 1094 byte[] r = fr.apply(SPECIES.length()); 1095 byte ra = Byte.MAX_VALUE; 1096 1097 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1098 for (int i = 0; i < a.length; i += SPECIES.length()) { 1099 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1100 r[i] = av.minAll(); 1101 } 1102 } 1103 1104 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1105 ra = Byte.MAX_VALUE; 1106 for (int i = 0; i < a.length; i += SPECIES.length()) { 1107 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1108 ra = (byte)Math.min(ra, av.minAll()); 1109 } 1110 } 1111 1112 assertReductionArraysEquals(a, r, ra, Byte128VectorTests::minAll, Byte128VectorTests::minAll); 1113 } 1114 static byte maxAll(byte[] a, int idx) { 1115 byte res = Byte.MIN_VALUE; 1116 for (int i = idx; i < (idx + SPECIES.length()); i++) { 1117 res = (byte)Math.max(res, a[i]); 1118 } 1119 1120 return res; 1121 } 1122 1123 static byte maxAll(byte[] a) { 1124 byte res = Byte.MIN_VALUE; 1125 for (int i = 0; i < a.length; i++) { 1126 res = (byte)Math.max(res, a[i]); 1127 } 1128 1129 return res; 1130 } 1131 @Test(dataProvider = "byteUnaryOpProvider") 1132 static void maxAllByte128VectorTests(IntFunction<byte[]> fa) { 1133 byte[] a = fa.apply(SPECIES.length()); 1134 byte[] r = fr.apply(SPECIES.length()); 1135 byte ra = Byte.MIN_VALUE; 1136 1137 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1138 for (int i = 0; i < a.length; i += SPECIES.length()) { 1139 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1140 r[i] = av.maxAll(); 1141 } 1142 } 1143 1144 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1145 ra = Byte.MIN_VALUE; 1146 for (int i = 0; i < a.length; i += SPECIES.length()) { 1147 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1148 ra = (byte)Math.max(ra, av.maxAll()); 1149 } 1150 } 1151 1152 assertReductionArraysEquals(a, r, ra, Byte128VectorTests::maxAll, Byte128VectorTests::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 anyTrueByte128VectorTests(IntFunction<boolean[]> fm) { 1167 boolean[] mask = fm.apply(SPECIES.length()); 1168 boolean[] r = fmr.apply(SPECIES.length()); 1169 1170 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1171 for (int i = 0; i < mask.length; i += SPECIES.length()) { 1172 Vector.Mask<Byte> vmask = ByteVector.maskFromArray(SPECIES, mask, i); 1173 r[i] = vmask.anyTrue(); 1174 } 1175 } 1176 1177 assertReductionBoolArraysEquals(mask, r, Byte128VectorTests::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 allTrueByte128VectorTests(IntFunction<boolean[]> fm) { 1193 boolean[] mask = fm.apply(SPECIES.length()); 1194 boolean[] r = fmr.apply(SPECIES.length()); 1195 1196 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1197 for (int i = 0; i < mask.length; i += SPECIES.length()) { 1198 Vector.Mask<Byte> vmask = ByteVector.maskFromArray(SPECIES, mask, i); 1199 r[i] = vmask.allTrue(); 1200 } 1201 } 1202 1203 assertReductionBoolArraysEquals(mask, r, Byte128VectorTests::allTrue); 1204 } 1205 1206 1207 @Test(dataProvider = "byteUnaryOpProvider") 1208 static void withByte128VectorTests(IntFunction<byte []> fa) { 1209 byte[] a = fa.apply(SPECIES.length()); 1210 byte[] r = fr.apply(SPECIES.length()); 1211 1212 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1213 for (int i = 0; i < a.length; i += SPECIES.length()) { 1214 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1215 av.with(0, (byte)4).intoArray(r, i); 1216 } 1217 } 1218 1219 assertInsertArraysEquals(a, r, (byte)4, 0); 1220 } 1221 1222 @Test(dataProvider = "byteCompareOpProvider") 1223 static void lessThanByte128VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 1224 byte[] a = fa.apply(SPECIES.length()); 1225 byte[] b = fb.apply(SPECIES.length()); 1226 1227 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1228 for (int i = 0; i < a.length; i += SPECIES.length()) { 1229 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1230 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 1231 Vector.Mask<Byte> mv = av.lessThan(bv); 1232 1233 // Check results as part of computation. 1234 for (int j = 0; j < SPECIES.length(); j++) { 1235 Assert.assertEquals(mv.getElement(j), a[i + j] < b[i + j]); 1236 } 1237 } 1238 } 1239 } 1240 1241 1242 @Test(dataProvider = "byteCompareOpProvider") 1243 static void greaterThanByte128VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 1244 byte[] a = fa.apply(SPECIES.length()); 1245 byte[] b = fb.apply(SPECIES.length()); 1246 1247 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1248 for (int i = 0; i < a.length; i += SPECIES.length()) { 1249 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1250 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 1251 Vector.Mask<Byte> mv = av.greaterThan(bv); 1252 1253 // Check results as part of computation. 1254 for (int j = 0; j < SPECIES.length(); j++) { 1255 Assert.assertEquals(mv.getElement(j), a[i + j] > b[i + j]); 1256 } 1257 } 1258 } 1259 } 1260 1261 1262 @Test(dataProvider = "byteCompareOpProvider") 1263 static void equalByte128VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 1264 byte[] a = fa.apply(SPECIES.length()); 1265 byte[] b = fb.apply(SPECIES.length()); 1266 1267 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1268 for (int i = 0; i < a.length; i += SPECIES.length()) { 1269 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1270 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 1271 Vector.Mask<Byte> mv = av.equal(bv); 1272 1273 // Check results as part of computation. 1274 for (int j = 0; j < SPECIES.length(); j++) { 1275 Assert.assertEquals(mv.getElement(j), a[i + j] == b[i + j]); 1276 } 1277 } 1278 } 1279 } 1280 1281 1282 @Test(dataProvider = "byteCompareOpProvider") 1283 static void notEqualByte128VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 1284 byte[] a = fa.apply(SPECIES.length()); 1285 byte[] b = fb.apply(SPECIES.length()); 1286 1287 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1288 for (int i = 0; i < a.length; i += SPECIES.length()) { 1289 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1290 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 1291 Vector.Mask<Byte> mv = av.notEqual(bv); 1292 1293 // Check results as part of computation. 1294 for (int j = 0; j < SPECIES.length(); j++) { 1295 Assert.assertEquals(mv.getElement(j), a[i + j] != b[i + j]); 1296 } 1297 } 1298 } 1299 } 1300 1301 1302 @Test(dataProvider = "byteCompareOpProvider") 1303 static void lessThanEqByte128VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 1304 byte[] a = fa.apply(SPECIES.length()); 1305 byte[] b = fb.apply(SPECIES.length()); 1306 1307 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1308 for (int i = 0; i < a.length; i += SPECIES.length()) { 1309 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1310 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 1311 Vector.Mask<Byte> mv = av.lessThanEq(bv); 1312 1313 // Check results as part of computation. 1314 for (int j = 0; j < SPECIES.length(); j++) { 1315 Assert.assertEquals(mv.getElement(j), a[i + j] <= b[i + j]); 1316 } 1317 } 1318 } 1319 } 1320 1321 1322 @Test(dataProvider = "byteCompareOpProvider") 1323 static void greaterThanEqByte128VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 1324 byte[] a = fa.apply(SPECIES.length()); 1325 byte[] b = fb.apply(SPECIES.length()); 1326 1327 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1328 for (int i = 0; i < a.length; i += SPECIES.length()) { 1329 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1330 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 1331 Vector.Mask<Byte> mv = av.greaterThanEq(bv); 1332 1333 // Check results as part of computation. 1334 for (int j = 0; j < SPECIES.length(); j++) { 1335 Assert.assertEquals(mv.getElement(j), a[i + j] >= b[i + j]); 1336 } 1337 } 1338 } 1339 } 1340 1341 1342 static byte blend(byte a, byte b, boolean mask) { 1343 return mask ? b : a; 1344 } 1345 1346 @Test(dataProvider = "byteBinaryOpMaskProvider") 1347 static void blendByte128VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 1348 IntFunction<boolean[]> fm) { 1349 byte[] a = fa.apply(SPECIES.length()); 1350 byte[] b = fb.apply(SPECIES.length()); 1351 byte[] r = fr.apply(SPECIES.length()); 1352 boolean[] mask = fm.apply(SPECIES.length()); 1353 Vector.Mask<Byte> vmask = ByteVector.maskFromValues(SPECIES, mask); 1354 1355 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1356 for (int i = 0; i < a.length; i += SPECIES.length()) { 1357 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1358 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 1359 av.blend(bv, vmask).intoArray(r, i); 1360 } 1361 } 1362 1363 assertArraysEquals(a, b, r, mask, Byte128VectorTests::blend); 1364 } 1365 1366 @Test(dataProvider = "byteUnaryOpShuffleProvider") 1367 static void RearrangeByte128VectorTests(IntFunction<byte[]> fa, 1368 BiFunction<Integer,Integer,int[]> fs) { 1369 byte[] a = fa.apply(SPECIES.length()); 1370 int[] order = fs.apply(a.length, SPECIES.length()); 1371 byte[] r = fr.apply(SPECIES.length()); 1372 1373 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1374 for (int i = 0; i < a.length; i += SPECIES.length()) { 1375 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1376 av.rearrange(ByteVector.shuffleFromArray(SPECIES, order, i)).intoArray(r, i); 1377 } 1378 } 1379 1380 assertRearrangeArraysEquals(a, r, order, SPECIES.length()); 1381 } 1382 1383 1384 1385 1386 @Test(dataProvider = "byteUnaryOpProvider") 1387 static void getByte128VectorTests(IntFunction<byte[]> fa) { 1388 byte[] a = fa.apply(SPECIES.length()); 1389 byte[] r = fr.apply(SPECIES.length()); 1390 1391 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1392 for (int i = 0; i < a.length; i += SPECIES.length()) { 1393 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1394 int num_lanes = SPECIES.length(); 1395 // Manually unroll because full unroll happens after intrinsification. 1396 // Unroll is needed because get intrinsic requires for index to be a known constant. 1397 if (num_lanes == 1) { 1398 r[i]=av.get(0); 1399 } else if (num_lanes == 2) { 1400 r[i]=av.get(0); 1401 r[i+1]=av.get(1); 1402 } else if (num_lanes == 4) { 1403 r[i]=av.get(0); 1404 r[i+1]=av.get(1); 1405 r[i+2]=av.get(2); 1406 r[i+3]=av.get(3); 1407 } else if (num_lanes == 8) { 1408 r[i]=av.get(0); 1409 r[i+1]=av.get(1); 1410 r[i+2]=av.get(2); 1411 r[i+3]=av.get(3); 1412 r[i+4]=av.get(4); 1413 r[i+5]=av.get(5); 1414 r[i+6]=av.get(6); 1415 r[i+7]=av.get(7); 1416 } else if (num_lanes == 16) { 1417 r[i]=av.get(0); 1418 r[i+1]=av.get(1); 1419 r[i+2]=av.get(2); 1420 r[i+3]=av.get(3); 1421 r[i+4]=av.get(4); 1422 r[i+5]=av.get(5); 1423 r[i+6]=av.get(6); 1424 r[i+7]=av.get(7); 1425 r[i+8]=av.get(8); 1426 r[i+9]=av.get(9); 1427 r[i+10]=av.get(10); 1428 r[i+11]=av.get(11); 1429 r[i+12]=av.get(12); 1430 r[i+13]=av.get(13); 1431 r[i+14]=av.get(14); 1432 r[i+15]=av.get(15); 1433 } else if (num_lanes == 32) { 1434 r[i]=av.get(0); 1435 r[i+1]=av.get(1); 1436 r[i+2]=av.get(2); 1437 r[i+3]=av.get(3); 1438 r[i+4]=av.get(4); 1439 r[i+5]=av.get(5); 1440 r[i+6]=av.get(6); 1441 r[i+7]=av.get(7); 1442 r[i+8]=av.get(8); 1443 r[i+9]=av.get(9); 1444 r[i+10]=av.get(10); 1445 r[i+11]=av.get(11); 1446 r[i+12]=av.get(12); 1447 r[i+13]=av.get(13); 1448 r[i+14]=av.get(14); 1449 r[i+15]=av.get(15); 1450 r[i+16]=av.get(16); 1451 r[i+17]=av.get(17); 1452 r[i+18]=av.get(18); 1453 r[i+19]=av.get(19); 1454 r[i+20]=av.get(20); 1455 r[i+21]=av.get(21); 1456 r[i+22]=av.get(22); 1457 r[i+23]=av.get(23); 1458 r[i+24]=av.get(24); 1459 r[i+25]=av.get(25); 1460 r[i+26]=av.get(26); 1461 r[i+27]=av.get(27); 1462 r[i+28]=av.get(28); 1463 r[i+29]=av.get(29); 1464 r[i+30]=av.get(30); 1465 r[i+31]=av.get(31); 1466 } else if (num_lanes == 64) { 1467 r[i]=av.get(0); 1468 r[i+1]=av.get(1); 1469 r[i+2]=av.get(2); 1470 r[i+3]=av.get(3); 1471 r[i+4]=av.get(4); 1472 r[i+5]=av.get(5); 1473 r[i+6]=av.get(6); 1474 r[i+7]=av.get(7); 1475 r[i+8]=av.get(8); 1476 r[i+9]=av.get(9); 1477 r[i+10]=av.get(10); 1478 r[i+11]=av.get(11); 1479 r[i+12]=av.get(12); 1480 r[i+13]=av.get(13); 1481 r[i+14]=av.get(14); 1482 r[i+15]=av.get(15); 1483 r[i+16]=av.get(16); 1484 r[i+17]=av.get(17); 1485 r[i+18]=av.get(18); 1486 r[i+19]=av.get(19); 1487 r[i+20]=av.get(20); 1488 r[i+21]=av.get(21); 1489 r[i+22]=av.get(22); 1490 r[i+23]=av.get(23); 1491 r[i+24]=av.get(24); 1492 r[i+25]=av.get(25); 1493 r[i+26]=av.get(26); 1494 r[i+27]=av.get(27); 1495 r[i+28]=av.get(28); 1496 r[i+29]=av.get(29); 1497 r[i+30]=av.get(30); 1498 r[i+31]=av.get(31); 1499 r[i+32]=av.get(32); 1500 r[i+33]=av.get(33); 1501 r[i+34]=av.get(34); 1502 r[i+35]=av.get(35); 1503 r[i+36]=av.get(36); 1504 r[i+37]=av.get(37); 1505 r[i+38]=av.get(38); 1506 r[i+39]=av.get(39); 1507 r[i+40]=av.get(40); 1508 r[i+41]=av.get(41); 1509 r[i+42]=av.get(42); 1510 r[i+43]=av.get(43); 1511 r[i+44]=av.get(44); 1512 r[i+45]=av.get(45); 1513 r[i+46]=av.get(46); 1514 r[i+47]=av.get(47); 1515 r[i+48]=av.get(48); 1516 r[i+49]=av.get(49); 1517 r[i+50]=av.get(50); 1518 r[i+51]=av.get(51); 1519 r[i+52]=av.get(52); 1520 r[i+53]=av.get(53); 1521 r[i+54]=av.get(54); 1522 r[i+55]=av.get(55); 1523 r[i+56]=av.get(56); 1524 r[i+57]=av.get(57); 1525 r[i+58]=av.get(58); 1526 r[i+59]=av.get(59); 1527 r[i+60]=av.get(60); 1528 r[i+61]=av.get(61); 1529 r[i+62]=av.get(62); 1530 r[i+63]=av.get(63); 1531 } else { 1532 for (int j = 0; j < SPECIES.length(); j++) { 1533 r[i+j]=av.get(j); 1534 } 1535 } 1536 } 1537 } 1538 1539 assertArraysEquals(a, r, Byte128VectorTests::get); 1540 } 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 static byte neg(byte a) { 1564 return (byte)(-((byte)a)); 1565 } 1566 1567 @Test(dataProvider = "byteUnaryOpProvider") 1568 static void negByte128VectorTests(IntFunction<byte[]> fa) { 1569 byte[] a = fa.apply(SPECIES.length()); 1570 byte[] r = fr.apply(SPECIES.length()); 1571 1572 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1573 for (int i = 0; i < a.length; i += SPECIES.length()) { 1574 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1575 av.neg().intoArray(r, i); 1576 } 1577 } 1578 1579 assertArraysEquals(a, r, Byte128VectorTests::neg); 1580 } 1581 1582 @Test(dataProvider = "byteUnaryOpMaskProvider") 1583 static void negMaskedByte128VectorTests(IntFunction<byte[]> fa, 1584 IntFunction<boolean[]> fm) { 1585 byte[] a = fa.apply(SPECIES.length()); 1586 byte[] r = fr.apply(SPECIES.length()); 1587 boolean[] mask = fm.apply(SPECIES.length()); 1588 Vector.Mask<Byte> vmask = ByteVector.maskFromValues(SPECIES, mask); 1589 1590 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1591 for (int i = 0; i < a.length; i += SPECIES.length()) { 1592 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1593 av.neg(vmask).intoArray(r, i); 1594 } 1595 } 1596 1597 assertArraysEquals(a, r, mask, Byte128VectorTests::neg); 1598 } 1599 1600 static byte abs(byte a) { 1601 return (byte)(Math.abs((byte)a)); 1602 } 1603 1604 @Test(dataProvider = "byteUnaryOpProvider") 1605 static void absByte128VectorTests(IntFunction<byte[]> fa) { 1606 byte[] a = fa.apply(SPECIES.length()); 1607 byte[] r = fr.apply(SPECIES.length()); 1608 1609 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1610 for (int i = 0; i < a.length; i += SPECIES.length()) { 1611 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1612 av.abs().intoArray(r, i); 1613 } 1614 } 1615 1616 assertArraysEquals(a, r, Byte128VectorTests::abs); 1617 } 1618 1619 @Test(dataProvider = "byteUnaryOpMaskProvider") 1620 static void absMaskedByte128VectorTests(IntFunction<byte[]> fa, 1621 IntFunction<boolean[]> fm) { 1622 byte[] a = fa.apply(SPECIES.length()); 1623 byte[] r = fr.apply(SPECIES.length()); 1624 boolean[] mask = fm.apply(SPECIES.length()); 1625 Vector.Mask<Byte> vmask = ByteVector.maskFromValues(SPECIES, mask); 1626 1627 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1628 for (int i = 0; i < a.length; i += SPECIES.length()) { 1629 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1630 av.abs(vmask).intoArray(r, i); 1631 } 1632 } 1633 1634 assertArraysEquals(a, r, mask, Byte128VectorTests::abs); 1635 } 1636 1637 1638 static byte not(byte a) { 1639 return (byte)(~((byte)a)); 1640 } 1641 1642 1643 1644 @Test(dataProvider = "byteUnaryOpProvider") 1645 static void notByte128VectorTests(IntFunction<byte[]> fa) { 1646 byte[] a = fa.apply(SPECIES.length()); 1647 byte[] r = fr.apply(SPECIES.length()); 1648 1649 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1650 for (int i = 0; i < a.length; i += SPECIES.length()) { 1651 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1652 av.not().intoArray(r, i); 1653 } 1654 } 1655 1656 assertArraysEquals(a, r, Byte128VectorTests::not); 1657 } 1658 1659 1660 1661 @Test(dataProvider = "byteUnaryOpMaskProvider") 1662 static void notMaskedByte128VectorTests(IntFunction<byte[]> fa, 1663 IntFunction<boolean[]> fm) { 1664 byte[] a = fa.apply(SPECIES.length()); 1665 byte[] r = fr.apply(SPECIES.length()); 1666 boolean[] mask = fm.apply(SPECIES.length()); 1667 Vector.Mask<Byte> vmask = ByteVector.maskFromValues(SPECIES, mask); 1668 1669 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1670 for (int i = 0; i < a.length; i += SPECIES.length()) { 1671 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1672 av.not(vmask).intoArray(r, i); 1673 } 1674 } 1675 1676 assertArraysEquals(a, r, mask, Byte128VectorTests::not); 1677 } 1678 1679 1680 1681 1682 1683 1684 } 1685