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