1 /* 2 * Copyright (c) 2018, 2020, 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 any 21 * questions. 22 */ 23 24 /* 25 * @test 26 * @modules jdk.incubator.vector 27 * @run testng/othervm -ea -esa -Xbatch Byte256VectorTests 28 */ 29 30 // -- This file was mechanically generated: Do not edit! -- // 31 32 import jdk.incubator.vector.VectorShape; 33 import jdk.incubator.vector.VectorSpecies; 34 import jdk.incubator.vector.VectorShuffle; 35 import jdk.incubator.vector.VectorMask; 36 import jdk.incubator.vector.VectorOperators; 37 import jdk.incubator.vector.Vector; 38 39 import jdk.incubator.vector.ByteVector; 40 41 import org.testng.Assert; 42 import org.testng.annotations.DataProvider; 43 import org.testng.annotations.Test; 44 45 import java.lang.Integer; 46 import java.util.List; 47 import java.util.Arrays; 48 import java.util.function.BiFunction; 49 import java.util.function.IntFunction; 50 import java.util.stream.Collectors; 51 import java.util.stream.Stream; 52 53 @Test 54 public class Byte256VectorTests extends AbstractVectorTest { 55 56 static final VectorSpecies<Byte> SPECIES = 57 ByteVector.SPECIES_256; 58 59 static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100); 60 61 62 static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 256); 63 64 static final int BUFFER_SIZE = Integer.getInteger("jdk.incubator.vector.test.buffer-size", BUFFER_REPS * (256 / 8)); 65 66 interface FUnOp { 67 byte apply(byte a); 68 } 69 70 static void assertArraysEquals(byte[] a, byte[] r, FUnOp f) { 71 int i = 0; 72 try { 73 for (; i < a.length; i++) { 74 Assert.assertEquals(r[i], f.apply(a[i])); 75 } 76 } catch (AssertionError e) { 77 Assert.assertEquals(r[i], f.apply(a[i]), "at index #" + i + ", input = " + a[i]); 78 } 79 } 80 81 interface FUnArrayOp { 82 byte[] apply(byte a); 83 } 84 85 static void assertArraysEquals(byte[] a, byte[] r, FUnArrayOp f) { 86 int i = 0; 87 try { 88 for (; i < a.length; i += SPECIES.length()) { 89 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()), 90 f.apply(a[i])); 91 } 92 } catch (AssertionError e) { 93 byte[] ref = f.apply(a[i]); 94 byte[] res = Arrays.copyOfRange(r, i, i+SPECIES.length()); 95 Assert.assertEquals(ref, res, "(ref: " + Arrays.toString(ref) 96 + ", res: " + Arrays.toString(res) 97 + "), at index #" + i); 98 } 99 } 100 101 static void assertArraysEquals(byte[] a, byte[] r, boolean[] mask, FUnOp f) { 102 int i = 0; 103 try { 104 for (; i < a.length; i++) { 105 Assert.assertEquals(r[i], mask[i % SPECIES.length()] ? f.apply(a[i]) : a[i]); 106 } 107 } catch (AssertionError e) { 108 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()]); 109 } 110 } 111 112 interface FReductionOp { 113 byte apply(byte[] a, int idx); 114 } 115 116 interface FReductionAllOp { 117 byte apply(byte[] a); 118 } 119 120 static void assertReductionArraysEquals(byte[] a, byte[] b, byte c, 121 FReductionOp f, FReductionAllOp fa) { 122 int i = 0; 123 try { 124 Assert.assertEquals(c, fa.apply(a)); 125 for (; i < a.length; i += SPECIES.length()) { 126 Assert.assertEquals(b[i], f.apply(a, i)); 127 } 128 } catch (AssertionError e) { 129 Assert.assertEquals(c, fa.apply(a), "Final result is incorrect!"); 130 Assert.assertEquals(b[i], f.apply(a, i), "at index #" + i); 131 } 132 } 133 134 interface FReductionMaskedOp { 135 byte apply(byte[] a, int idx, boolean[] mask); 136 } 137 138 interface FReductionAllMaskedOp { 139 byte apply(byte[] a, boolean[] mask); 140 } 141 142 static void assertReductionArraysEqualsMasked(byte[] a, byte[] b, byte c, boolean[] mask, 143 FReductionMaskedOp f, FReductionAllMaskedOp fa) { 144 int i = 0; 145 try { 146 Assert.assertEquals(c, fa.apply(a, mask)); 147 for (; i < a.length; i += SPECIES.length()) { 148 Assert.assertEquals(b[i], f.apply(a, i, mask)); 149 } 150 } catch (AssertionError e) { 151 Assert.assertEquals(c, fa.apply(a, mask), "Final result is incorrect!"); 152 Assert.assertEquals(b[i], f.apply(a, i, mask), "at index #" + i); 153 } 154 } 155 156 interface FBoolReductionOp { 157 boolean apply(boolean[] a, int idx); 158 } 159 160 static void assertReductionBoolArraysEquals(boolean[] a, boolean[] b, FBoolReductionOp f) { 161 int i = 0; 162 try { 163 for (; i < a.length; i += SPECIES.length()) { 164 Assert.assertEquals(b[i], f.apply(a, i)); 165 } 166 } catch (AssertionError e) { 167 Assert.assertEquals(b[i], f.apply(a, i), "at index #" + i); 168 } 169 } 170 171 static void assertInsertArraysEquals(byte[] a, byte[] b, byte element, int index) { 172 int i = 0; 173 try { 174 for (; i < a.length; i += 1) { 175 if(i%SPECIES.length() == index) { 176 Assert.assertEquals(b[i], element); 177 } else { 178 Assert.assertEquals(b[i], a[i]); 179 } 180 } 181 } catch (AssertionError e) { 182 if (i%SPECIES.length() == index) { 183 Assert.assertEquals(b[i], element, "at index #" + i); 184 } else { 185 Assert.assertEquals(b[i], a[i], "at index #" + i); 186 } 187 } 188 } 189 190 static void assertRearrangeArraysEquals(byte[] a, byte[] r, int[] order, int vector_len) { 191 int i = 0, j = 0; 192 try { 193 for (; i < a.length; i += vector_len) { 194 for (j = 0; j < vector_len; j++) { 195 Assert.assertEquals(r[i+j], a[i+order[i+j]]); 196 } 197 } 198 } catch (AssertionError e) { 199 int idx = i + j; 200 Assert.assertEquals(r[i+j], a[i+order[i+j]], "at index #" + idx + ", input = " + a[i+order[i+j]]); 201 } 202 } 203 204 static void assertBroadcastArraysEquals(byte[]a, byte[]r) { 205 int i = 0; 206 for (; i < a.length; i += SPECIES.length()) { 207 int idx = i; 208 for (int j = idx; j < (idx + SPECIES.length()); j++) 209 a[j]=a[idx]; 210 } 211 212 try { 213 for (i = 0; i < a.length; i++) { 214 Assert.assertEquals(r[i], a[i]); 215 } 216 } catch (AssertionError e) { 217 Assert.assertEquals(r[i], a[i], "at index #" + i + ", input = " + a[i]); 218 } 219 } 220 221 interface FBinOp { 222 byte apply(byte a, byte b); 223 } 224 225 interface FBinMaskOp { 226 byte apply(byte a, byte b, boolean m); 227 228 static FBinMaskOp lift(FBinOp f) { 229 return (a, b, m) -> m ? f.apply(a, b) : a; 230 } 231 } 232 233 static void assertArraysEquals(byte[] a, byte[] b, byte[] r, FBinOp f) { 234 int i = 0; 235 try { 236 for (; i < a.length; i++) { 237 Assert.assertEquals(r[i], f.apply(a[i], b[i])); 238 } 239 } catch (AssertionError e) { 240 Assert.assertEquals(r[i], f.apply(a[i], b[i]), "(" + a[i] + ", " + b[i] + ") at index #" + i); 241 } 242 } 243 244 static void assertBroadcastArraysEquals(byte[] a, byte[] b, byte[] r, FBinOp f) { 245 int i = 0; 246 try { 247 for (; i < a.length; i++) { 248 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()])); 249 } 250 } catch (AssertionError e) { 251 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()]), "(" + a[i] + ", " + b[(i / SPECIES.length()) * SPECIES.length()] + ") at index #" + i); 252 } 253 } 254 255 static void assertArraysEquals(byte[] a, byte[] b, byte[] r, boolean[] mask, FBinOp f) { 256 assertArraysEquals(a, b, r, mask, FBinMaskOp.lift(f)); 257 } 258 259 static void assertArraysEquals(byte[] a, byte[] b, byte[] r, boolean[] mask, FBinMaskOp f) { 260 int i = 0; 261 try { 262 for (; i < a.length; i++) { 263 Assert.assertEquals(r[i], f.apply(a[i], b[i], mask[i % SPECIES.length()])); 264 } 265 } catch (AssertionError err) { 266 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()]); 267 } 268 } 269 270 static void assertBroadcastArraysEquals(byte[] a, byte[] b, byte[] r, boolean[] mask, FBinOp f) { 271 assertBroadcastArraysEquals(a, b, r, mask, FBinMaskOp.lift(f)); 272 } 273 274 static void assertBroadcastArraysEquals(byte[] a, byte[] b, byte[] r, boolean[] mask, FBinMaskOp f) { 275 int i = 0; 276 try { 277 for (; i < a.length; i++) { 278 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], mask[i % SPECIES.length()])); 279 } 280 } catch (AssertionError err) { 281 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], mask[i % SPECIES.length()]), "at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[(i / SPECIES.length()) * SPECIES.length()] + ", mask = " + mask[i % SPECIES.length()]); 282 } 283 } 284 285 static void assertShiftArraysEquals(byte[] a, byte[] b, byte[] r, FBinOp f) { 286 int i = 0; 287 int j = 0; 288 try { 289 for (; j < a.length; j += SPECIES.length()) { 290 for (i = 0; i < SPECIES.length(); i++) { 291 Assert.assertEquals(r[i+j], f.apply(a[i+j], b[j])); 292 } 293 } 294 } catch (AssertionError e) { 295 Assert.assertEquals(r[i+j], f.apply(a[i+j], b[j]), "at index #" + i + ", " + j); 296 } 297 } 298 299 static void assertShiftArraysEquals(byte[] a, byte[] b, byte[] r, boolean[] mask, FBinOp f) { 300 assertShiftArraysEquals(a, b, r, mask, FBinMaskOp.lift(f)); 301 } 302 303 static void assertShiftArraysEquals(byte[] a, byte[] b, byte[] r, boolean[] mask, FBinMaskOp f) { 304 int i = 0; 305 int j = 0; 306 try { 307 for (; j < a.length; j += SPECIES.length()) { 308 for (i = 0; i < SPECIES.length(); i++) { 309 Assert.assertEquals(r[i+j], f.apply(a[i+j], b[j], mask[i])); 310 } 311 } 312 } catch (AssertionError err) { 313 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]); 314 } 315 } 316 317 interface FTernOp { 318 byte apply(byte a, byte b, byte c); 319 } 320 321 interface FTernMaskOp { 322 byte apply(byte a, byte b, byte c, boolean m); 323 324 static FTernMaskOp lift(FTernOp f) { 325 return (a, b, c, m) -> m ? f.apply(a, b, c) : a; 326 } 327 } 328 329 static void assertArraysEquals(byte[] a, byte[] b, byte[] c, byte[] r, FTernOp f) { 330 int i = 0; 331 try { 332 for (; i < a.length; i++) { 333 Assert.assertEquals(r[i], f.apply(a[i], b[i], c[i])); 334 } 335 } catch (AssertionError e) { 336 Assert.assertEquals(r[i], f.apply(a[i], b[i], c[i]), "at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]); 337 } 338 } 339 340 static void assertArraysEquals(byte[] a, byte[] b, byte[] c, byte[] r, boolean[] mask, FTernOp f) { 341 assertArraysEquals(a, b, c, r, mask, FTernMaskOp.lift(f)); 342 } 343 344 static void assertArraysEquals(byte[] a, byte[] b, byte[] c, byte[] r, boolean[] mask, FTernMaskOp f) { 345 int i = 0; 346 try { 347 for (; i < a.length; i++) { 348 Assert.assertEquals(r[i], f.apply(a[i], b[i], c[i], mask[i % SPECIES.length()])); 349 } 350 } catch (AssertionError err) { 351 Assert.assertEquals(r[i], f.apply(a[i], b[i], c[i], mask[i % SPECIES.length()]), "at index #" + i + ", input1 = " + a[i] + ", input2 = " 352 + b[i] + ", input3 = " + c[i] + ", mask = " + mask[i % SPECIES.length()]); 353 } 354 } 355 356 357 interface FBinArrayOp { 358 byte apply(byte[] a, int b); 359 } 360 361 static void assertArraysEquals(byte[] a, byte[] r, FBinArrayOp f) { 362 int i = 0; 363 try { 364 for (; i < a.length; i++) { 365 Assert.assertEquals(r[i], f.apply(a, i)); 366 } 367 } catch (AssertionError e) { 368 Assert.assertEquals(r[i], f.apply(a,i), "at index #" + i); 369 } 370 } 371 372 interface FGatherScatterOp { 373 byte[] apply(byte[] a, int ix, int[] b, int iy); 374 } 375 376 static void assertArraysEquals(byte[] a, int[] b, byte[] r, FGatherScatterOp f) { 377 int i = 0; 378 try { 379 for (; i < a.length; i += SPECIES.length()) { 380 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()), 381 f.apply(a, i, b, i)); 382 } 383 } catch (AssertionError e) { 384 byte[] ref = f.apply(a, i, b, i); 385 byte[] res = Arrays.copyOfRange(r, i, i+SPECIES.length()); 386 Assert.assertEquals(res, ref, 387 "(ref: " + Arrays.toString(ref) + ", res: " + Arrays.toString(res) + ", a: " 388 + Arrays.toString(Arrays.copyOfRange(a, i, i+SPECIES.length())) 389 + ", b: " 390 + Arrays.toString(Arrays.copyOfRange(b, i, i+SPECIES.length())) 391 + " at index #" + i); 392 } 393 } 394 395 interface FGatherMaskedOp { 396 byte[] apply(byte[] a, int ix, boolean[] mask, int[] b, int iy); 397 } 398 399 interface FScatterMaskedOp { 400 byte[] apply(byte[] r, byte[] a, int ix, boolean[] mask, int[] b, int iy); 401 } 402 403 static void assertArraysEquals(byte[] a, int[] b, byte[] r, boolean[] mask, FGatherMaskedOp f) { 404 int i = 0; 405 try { 406 for (; i < a.length; i += SPECIES.length()) { 407 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()), 408 f.apply(a, i, mask, b, i)); 409 } 410 } catch (AssertionError e) { 411 byte[] ref = f.apply(a, i, mask, b, i); 412 byte[] res = Arrays.copyOfRange(r, i, i+SPECIES.length()); 413 Assert.assertEquals(ref, res, 414 "(ref: " + Arrays.toString(ref) + ", res: " + Arrays.toString(res) + ", a: " 415 + Arrays.toString(Arrays.copyOfRange(a, i, i+SPECIES.length())) 416 + ", b: " 417 + Arrays.toString(Arrays.copyOfRange(b, i, i+SPECIES.length())) 418 + ", mask: " 419 + Arrays.toString(mask) 420 + " at index #" + i); 421 } 422 } 423 424 static void assertArraysEquals(byte[] a, int[] b, byte[] r, boolean[] mask, FScatterMaskedOp f) { 425 int i = 0; 426 try { 427 for (; i < a.length; i += SPECIES.length()) { 428 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()), 429 f.apply(r, a, i, mask, b, i)); 430 } 431 } catch (AssertionError e) { 432 byte[] ref = f.apply(r, a, i, mask, b, i); 433 byte[] res = Arrays.copyOfRange(r, i, i+SPECIES.length()); 434 Assert.assertEquals(ref, res, 435 "(ref: " + Arrays.toString(ref) + ", res: " + Arrays.toString(res) + ", a: " 436 + Arrays.toString(Arrays.copyOfRange(a, i, i+SPECIES.length())) 437 + ", b: " 438 + Arrays.toString(Arrays.copyOfRange(b, i, i+SPECIES.length())) 439 + ", r: " 440 + Arrays.toString(Arrays.copyOfRange(r, i, i+SPECIES.length())) 441 + ", mask: " 442 + Arrays.toString(mask) 443 + " at index #" + i); 444 } 445 } 446 447 interface FLaneOp { 448 byte[] apply(byte[] a, int origin, int idx); 449 } 450 451 static void assertArraysEquals(byte[] a, byte[] r, int origin, FLaneOp f) { 452 int i = 0; 453 try { 454 for (; i < a.length; i += SPECIES.length()) { 455 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()), 456 f.apply(a, origin, i)); 457 } 458 } catch (AssertionError e) { 459 byte[] ref = f.apply(a, origin, i); 460 byte[] res = Arrays.copyOfRange(r, i, i+SPECIES.length()); 461 Assert.assertEquals(ref, res, "(ref: " + Arrays.toString(ref) 462 + ", res: " + Arrays.toString(res) 463 + "), at index #" + i); 464 } 465 } 466 467 interface FLaneBop { 468 byte[] apply(byte[] a, byte[] b, int origin, int idx); 469 } 470 471 static void assertArraysEquals(byte[] a, byte[] b, byte[] r, int origin, FLaneBop f) { 472 int i = 0; 473 try { 474 for (; i < a.length; i += SPECIES.length()) { 475 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()), 476 f.apply(a, b, origin, i)); 477 } 478 } catch (AssertionError e) { 479 byte[] ref = f.apply(a, b, origin, i); 480 byte[] res = Arrays.copyOfRange(r, i, i+SPECIES.length()); 481 Assert.assertEquals(ref, res, "(ref: " + Arrays.toString(ref) 482 + ", res: " + Arrays.toString(res) 483 + "), at index #" + i 484 + ", at origin #" + origin); 485 } 486 } 487 488 interface FLaneMaskedBop { 489 byte[] apply(byte[] a, byte[] b, int origin, boolean[] mask, int idx); 490 } 491 492 static void assertArraysEquals(byte[] a, byte[] b, byte[] r, int origin, boolean[] mask, FLaneMaskedBop f) { 493 int i = 0; 494 try { 495 for (; i < a.length; i += SPECIES.length()) { 496 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()), 497 f.apply(a, b, origin, mask, i)); 498 } 499 } catch (AssertionError e) { 500 byte[] ref = f.apply(a, b, origin, mask, i); 501 byte[] res = Arrays.copyOfRange(r, i, i+SPECIES.length()); 502 Assert.assertEquals(ref, res, "(ref: " + Arrays.toString(ref) 503 + ", res: " + Arrays.toString(res) 504 + "), at index #" + i 505 + ", at origin #" + origin); 506 } 507 } 508 509 interface FLanePartBop { 510 byte[] apply(byte[] a, byte[] b, int origin, int part, int idx); 511 } 512 513 static void assertArraysEquals(byte[] a, byte[] b, byte[] r, int origin, int part, FLanePartBop f) { 514 int i = 0; 515 try { 516 for (; i < a.length; i += SPECIES.length()) { 517 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()), 518 f.apply(a, b, origin, part, i)); 519 } 520 } catch (AssertionError e) { 521 byte[] ref = f.apply(a, b, origin, part, i); 522 byte[] res = Arrays.copyOfRange(r, i, i+SPECIES.length()); 523 Assert.assertEquals(ref, res, "(ref: " + Arrays.toString(ref) 524 + ", res: " + Arrays.toString(res) 525 + "), at index #" + i 526 + ", at origin #" + origin 527 + ", with part #" + part); 528 } 529 } 530 531 interface FLanePartMaskedBop { 532 byte[] apply(byte[] a, byte[] b, int origin, int part, boolean[] mask, int idx); 533 } 534 535 static void assertArraysEquals(byte[] a, byte[] b, byte[] r, int origin, int part, boolean[] mask, FLanePartMaskedBop f) { 536 int i = 0; 537 try { 538 for (; i < a.length; i += SPECIES.length()) { 539 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()), 540 f.apply(a, b, origin, part, mask, i)); 541 } 542 } catch (AssertionError e) { 543 byte[] ref = f.apply(a, b, origin, part, mask, i); 544 byte[] res = Arrays.copyOfRange(r, i, i+SPECIES.length()); 545 Assert.assertEquals(ref, res, "(ref: " + Arrays.toString(ref) 546 + ", res: " + Arrays.toString(res) 547 + "), at index #" + i 548 + ", at origin #" + origin 549 + ", with part #" + part); 550 } 551 } 552 553 static byte bits(byte e) { 554 return e; 555 } 556 557 static final List<IntFunction<byte[]>> BYTE_GENERATORS = List.of( 558 withToString("byte[-i * 5]", (int s) -> { 559 return fill(s * BUFFER_REPS, 560 i -> (byte)(-i * 5)); 561 }), 562 withToString("byte[i * 5]", (int s) -> { 563 return fill(s * BUFFER_REPS, 564 i -> (byte)(i * 5)); 565 }), 566 withToString("byte[i + 1]", (int s) -> { 567 return fill(s * BUFFER_REPS, 568 i -> (((byte)(i + 1) == 0) ? 1 : (byte)(i + 1))); 569 }), 570 withToString("byte[cornerCaseValue(i)]", (int s) -> { 571 return fill(s * BUFFER_REPS, 572 i -> cornerCaseValue(i)); 573 }) 574 ); 575 576 // Create combinations of pairs 577 // @@@ Might be sensitive to order e.g. div by 0 578 static final List<List<IntFunction<byte[]>>> BYTE_GENERATOR_PAIRS = 579 Stream.of(BYTE_GENERATORS.get(0)). 580 flatMap(fa -> BYTE_GENERATORS.stream().skip(1).map(fb -> List.of(fa, fb))). 581 collect(Collectors.toList()); 582 583 @DataProvider 584 public Object[][] boolUnaryOpProvider() { 585 return BOOL_ARRAY_GENERATORS.stream(). 586 map(f -> new Object[]{f}). 587 toArray(Object[][]::new); 588 } 589 590 static final List<List<IntFunction<byte[]>>> BYTE_GENERATOR_TRIPLES = 591 BYTE_GENERATOR_PAIRS.stream(). 592 flatMap(pair -> BYTE_GENERATORS.stream().map(f -> List.of(pair.get(0), pair.get(1), f))). 593 collect(Collectors.toList()); 594 595 @DataProvider 596 public Object[][] byteBinaryOpProvider() { 597 return BYTE_GENERATOR_PAIRS.stream().map(List::toArray). 598 toArray(Object[][]::new); 599 } 600 601 @DataProvider 602 public Object[][] byteIndexedOpProvider() { 603 return BYTE_GENERATOR_PAIRS.stream().map(List::toArray). 604 toArray(Object[][]::new); 605 } 606 607 @DataProvider 608 public Object[][] byteBinaryOpMaskProvider() { 609 return BOOLEAN_MASK_GENERATORS.stream(). 610 flatMap(fm -> BYTE_GENERATOR_PAIRS.stream().map(lfa -> { 611 return Stream.concat(lfa.stream(), Stream.of(fm)).toArray(); 612 })). 613 toArray(Object[][]::new); 614 } 615 616 @DataProvider 617 public Object[][] byteTernaryOpProvider() { 618 return BYTE_GENERATOR_TRIPLES.stream().map(List::toArray). 619 toArray(Object[][]::new); 620 } 621 622 @DataProvider 623 public Object[][] byteTernaryOpMaskProvider() { 624 return BOOLEAN_MASK_GENERATORS.stream(). 625 flatMap(fm -> BYTE_GENERATOR_TRIPLES.stream().map(lfa -> { 626 return Stream.concat(lfa.stream(), Stream.of(fm)).toArray(); 627 })). 628 toArray(Object[][]::new); 629 } 630 631 @DataProvider 632 public Object[][] byteUnaryOpProvider() { 633 return BYTE_GENERATORS.stream(). 634 map(f -> new Object[]{f}). 635 toArray(Object[][]::new); 636 } 637 638 @DataProvider 639 public Object[][] byteUnaryOpMaskProvider() { 640 return BOOLEAN_MASK_GENERATORS.stream(). 641 flatMap(fm -> BYTE_GENERATORS.stream().map(fa -> { 642 return new Object[] {fa, fm}; 643 })). 644 toArray(Object[][]::new); 645 } 646 647 @DataProvider 648 public Object[][] byteUnaryOpShuffleProvider() { 649 return INT_SHUFFLE_GENERATORS.stream(). 650 flatMap(fs -> BYTE_GENERATORS.stream().map(fa -> { 651 return new Object[] {fa, fs}; 652 })). 653 toArray(Object[][]::new); 654 } 655 656 @DataProvider 657 public Object[][] byteUnaryOpIndexProvider() { 658 return INT_INDEX_GENERATORS.stream(). 659 flatMap(fs -> BYTE_GENERATORS.stream().map(fa -> { 660 return new Object[] {fa, fs}; 661 })). 662 toArray(Object[][]::new); 663 } 664 665 @DataProvider 666 public Object[][] byteUnaryMaskedOpIndexProvider() { 667 return BOOLEAN_MASK_GENERATORS.stream(). 668 flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> 669 BYTE_GENERATORS.stream().map(fa -> { 670 return new Object[] {fa, fm, fs}; 671 }))). 672 toArray(Object[][]::new); 673 } 674 675 @DataProvider 676 public Object[][] scatterMaskedOpIndexProvider() { 677 return BOOLEAN_MASK_GENERATORS.stream(). 678 flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> 679 BYTE_GENERATORS.stream().flatMap(fn -> 680 BYTE_GENERATORS.stream().map(fa -> { 681 return new Object[] {fa, fn, fm, fs}; 682 })))). 683 toArray(Object[][]::new); 684 } 685 686 static final List<IntFunction<byte[]>> BYTE_COMPARE_GENERATORS = List.of( 687 withToString("byte[i]", (int s) -> { 688 return fill(s * BUFFER_REPS, 689 i -> (byte)i); 690 }), 691 withToString("byte[i + 1]", (int s) -> { 692 return fill(s * BUFFER_REPS, 693 i -> (byte)(i + 1)); 694 }), 695 withToString("byte[i - 2]", (int s) -> { 696 return fill(s * BUFFER_REPS, 697 i -> (byte)(i - 2)); 698 }), 699 withToString("byte[zigZag(i)]", (int s) -> { 700 return fill(s * BUFFER_REPS, 701 i -> i%3 == 0 ? (byte)i : (i%3 == 1 ? (byte)(i + 1) : (byte)(i - 2))); 702 }), 703 withToString("byte[cornerCaseValue(i)]", (int s) -> { 704 return fill(s * BUFFER_REPS, 705 i -> cornerCaseValue(i)); 706 }) 707 ); 708 709 static final List<List<IntFunction<byte[]>>> BYTE_TEST_GENERATOR_ARGS = 710 BYTE_COMPARE_GENERATORS.stream(). 711 map(fa -> List.of(fa)). 712 collect(Collectors.toList()); 713 714 @DataProvider 715 public Object[][] byteTestOpProvider() { 716 return BYTE_TEST_GENERATOR_ARGS.stream().map(List::toArray). 717 toArray(Object[][]::new); 718 } 719 720 static final List<List<IntFunction<byte[]>>> BYTE_COMPARE_GENERATOR_PAIRS = 721 BYTE_COMPARE_GENERATORS.stream(). 722 flatMap(fa -> BYTE_COMPARE_GENERATORS.stream().map(fb -> List.of(fa, fb))). 723 collect(Collectors.toList()); 724 725 @DataProvider 726 public Object[][] byteCompareOpProvider() { 727 return BYTE_COMPARE_GENERATOR_PAIRS.stream().map(List::toArray). 728 toArray(Object[][]::new); 729 } 730 731 interface ToByteF { 732 byte apply(int i); 733 } 734 735 static byte[] fill(int s , ToByteF f) { 736 return fill(new byte[s], f); 737 } 738 739 static byte[] fill(byte[] a, ToByteF f) { 740 for (int i = 0; i < a.length; i++) { 741 a[i] = f.apply(i); 742 } 743 return a; 744 } 745 746 static byte cornerCaseValue(int i) { 747 switch(i % 5) { 748 case 0: 749 return Byte.MAX_VALUE; 750 case 1: 751 return Byte.MIN_VALUE; 752 case 2: 753 return Byte.MIN_VALUE; 754 case 3: 755 return Byte.MAX_VALUE; 756 default: 757 return (byte)0; 758 } 759 } 760 static byte get(byte[] a, int i) { 761 return (byte) a[i]; 762 } 763 764 static final IntFunction<byte[]> fr = (vl) -> { 765 int length = BUFFER_REPS * vl; 766 return new byte[length]; 767 }; 768 769 static final IntFunction<boolean[]> fmr = (vl) -> { 770 int length = BUFFER_REPS * vl; 771 return new boolean[length]; 772 }; 773 774 static void replaceZero(byte[] a, byte v) { 775 for (int i = 0; i < a.length; i++) { 776 if (a[i] == 0) { 777 a[i] = v; 778 } 779 } 780 } 781 782 static void replaceZero(byte[] a, boolean[] mask, byte v) { 783 for (int i = 0; i < a.length; i++) { 784 if (mask[i % mask.length] && a[i] == 0) { 785 a[i] = v; 786 } 787 } 788 } 789 790 @Test 791 static void smokeTest1() { 792 ByteVector three = ByteVector.broadcast(SPECIES, (byte)-3); 793 ByteVector three2 = (ByteVector) SPECIES.broadcast(-3); 794 assert(three.eq(three2).allTrue()); 795 ByteVector three3 = three2.broadcast(1).broadcast(-3); 796 assert(three.eq(three3).allTrue()); 797 int scale = 2; 798 Class<?> ETYPE = byte.class; 799 if (ETYPE == double.class || ETYPE == long.class) 800 scale = 1000000; 801 else if (ETYPE == byte.class && SPECIES.length() >= 64) 802 scale = 1; 803 ByteVector higher = three.addIndex(scale); 804 VectorMask<Byte> m = three.compare(VectorOperators.LE, higher); 805 assert(m.allTrue()); 806 m = higher.min((byte)-1).test(VectorOperators.IS_NEGATIVE); 807 assert(m.allTrue()); 808 byte max = higher.reduceLanes(VectorOperators.MAX); 809 assert(max == -3 + scale * (SPECIES.length()-1)); 810 } 811 812 private static byte[] 813 bothToArray(ByteVector a, ByteVector b) { 814 byte[] r = new byte[a.length() + b.length()]; 815 a.intoArray(r, 0); 816 b.intoArray(r, a.length()); 817 return r; 818 } 819 820 @Test 821 static void smokeTest2() { 822 // Do some zipping and shuffling. 823 ByteVector io = (ByteVector) SPECIES.broadcast(0).addIndex(1); 824 ByteVector io2 = (ByteVector) VectorShuffle.iota(SPECIES,0,1,false).toVector(); 825 Assert.assertEquals(io, io2); 826 ByteVector a = io.add((byte)1); //[1,2] 827 ByteVector b = a.neg(); //[-1,-2] 828 byte[] abValues = bothToArray(a,b); //[1,2,-1,-2] 829 VectorShuffle<Byte> zip0 = VectorShuffle.makeZip(SPECIES, 0); 830 VectorShuffle<Byte> zip1 = VectorShuffle.makeZip(SPECIES, 1); 831 ByteVector zab0 = a.rearrange(zip0,b); //[1,-1] 832 ByteVector zab1 = a.rearrange(zip1,b); //[2,-2] 833 byte[] zabValues = bothToArray(zab0, zab1); //[1,-1,2,-2] 834 // manually zip 835 byte[] manual = new byte[zabValues.length]; 836 for (int i = 0; i < manual.length; i += 2) { 837 manual[i+0] = abValues[i/2]; 838 manual[i+1] = abValues[a.length() + i/2]; 839 } 840 Assert.assertEquals(Arrays.toString(zabValues), Arrays.toString(manual)); 841 VectorShuffle<Byte> unz0 = VectorShuffle.makeUnzip(SPECIES, 0); 842 VectorShuffle<Byte> unz1 = VectorShuffle.makeUnzip(SPECIES, 1); 843 ByteVector uab0 = zab0.rearrange(unz0,zab1); 844 ByteVector uab1 = zab0.rearrange(unz1,zab1); 845 byte[] abValues1 = bothToArray(uab0, uab1); 846 Assert.assertEquals(Arrays.toString(abValues), Arrays.toString(abValues1)); 847 } 848 849 static void iotaShuffle() { 850 ByteVector io = (ByteVector) SPECIES.broadcast(0).addIndex(1); 851 ByteVector io2 = (ByteVector) VectorShuffle.iota(SPECIES, 0 , 1, false).toVector(); 852 Assert.assertEquals(io, io2); 853 } 854 855 @Test 856 // Test all shuffle related operations. 857 static void shuffleTest() { 858 // To test backend instructions, make sure that C2 is used. 859 for (int loop = 0; loop < INVOC_COUNT * INVOC_COUNT; loop++) { 860 iotaShuffle(); 861 } 862 } 863 864 @Test 865 void viewAsIntegeralLanesTest() { 866 Vector<?> asIntegral = SPECIES.zero().viewAsIntegralLanes(); 867 Assert.assertEquals(asIntegral.species(), SPECIES); 868 } 869 870 @Test(expectedExceptions = UnsupportedOperationException.class) 871 void viewAsFloatingLanesTest() { 872 SPECIES.zero().viewAsFloatingLanes(); 873 } 874 875 @Test 876 // Test div by 0. 877 static void bitwiseDivByZeroSmokeTest() { 878 try { 879 ByteVector a = (ByteVector) SPECIES.broadcast(0).addIndex(1); 880 ByteVector b = (ByteVector) SPECIES.broadcast(0); 881 a.div(b); 882 Assert.fail(); 883 } catch (ArithmeticException e) { 884 } 885 886 try { 887 ByteVector a = (ByteVector) SPECIES.broadcast(0).addIndex(1); 888 ByteVector b = (ByteVector) SPECIES.broadcast(0); 889 VectorMask<Byte> m = a.lt((byte) 1); 890 a.div(b, m); 891 Assert.fail(); 892 } catch (ArithmeticException e) { 893 } 894 } 895 static byte ADD(byte a, byte b) { 896 return (byte)(a + b); 897 } 898 899 @Test(dataProvider = "byteBinaryOpProvider") 900 static void ADDByte256VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 901 byte[] a = fa.apply(SPECIES.length()); 902 byte[] b = fb.apply(SPECIES.length()); 903 byte[] r = fr.apply(SPECIES.length()); 904 905 for (int ic = 0; ic < INVOC_COUNT; ic++) { 906 for (int i = 0; i < a.length; i += SPECIES.length()) { 907 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 908 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 909 av.lanewise(VectorOperators.ADD, bv).intoArray(r, i); 910 } 911 } 912 913 assertArraysEquals(a, b, r, Byte256VectorTests::ADD); 914 } 915 static byte add(byte a, byte b) { 916 return (byte)(a + b); 917 } 918 919 @Test(dataProvider = "byteBinaryOpProvider") 920 static void addByte256VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 921 byte[] a = fa.apply(SPECIES.length()); 922 byte[] b = fb.apply(SPECIES.length()); 923 byte[] r = fr.apply(SPECIES.length()); 924 925 for (int ic = 0; ic < INVOC_COUNT; ic++) { 926 for (int i = 0; i < a.length; i += SPECIES.length()) { 927 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 928 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 929 av.add(bv).intoArray(r, i); 930 } 931 } 932 933 assertArraysEquals(a, b, r, Byte256VectorTests::add); 934 } 935 936 @Test(dataProvider = "byteBinaryOpMaskProvider") 937 static void ADDByte256VectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 938 IntFunction<boolean[]> fm) { 939 byte[] a = fa.apply(SPECIES.length()); 940 byte[] b = fb.apply(SPECIES.length()); 941 byte[] r = fr.apply(SPECIES.length()); 942 boolean[] mask = fm.apply(SPECIES.length()); 943 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 944 945 for (int ic = 0; ic < INVOC_COUNT; ic++) { 946 for (int i = 0; i < a.length; i += SPECIES.length()) { 947 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 948 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 949 av.lanewise(VectorOperators.ADD, bv, vmask).intoArray(r, i); 950 } 951 } 952 953 assertArraysEquals(a, b, r, mask, Byte256VectorTests::ADD); 954 } 955 956 @Test(dataProvider = "byteBinaryOpMaskProvider") 957 static void addByte256VectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 958 IntFunction<boolean[]> fm) { 959 byte[] a = fa.apply(SPECIES.length()); 960 byte[] b = fb.apply(SPECIES.length()); 961 byte[] r = fr.apply(SPECIES.length()); 962 boolean[] mask = fm.apply(SPECIES.length()); 963 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 964 965 for (int ic = 0; ic < INVOC_COUNT; ic++) { 966 for (int i = 0; i < a.length; i += SPECIES.length()) { 967 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 968 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 969 av.add(bv, vmask).intoArray(r, i); 970 } 971 } 972 973 assertArraysEquals(a, b, r, mask, Byte256VectorTests::add); 974 } 975 static byte SUB(byte a, byte b) { 976 return (byte)(a - b); 977 } 978 979 @Test(dataProvider = "byteBinaryOpProvider") 980 static void SUBByte256VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 981 byte[] a = fa.apply(SPECIES.length()); 982 byte[] b = fb.apply(SPECIES.length()); 983 byte[] r = fr.apply(SPECIES.length()); 984 985 for (int ic = 0; ic < INVOC_COUNT; ic++) { 986 for (int i = 0; i < a.length; i += SPECIES.length()) { 987 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 988 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 989 av.lanewise(VectorOperators.SUB, bv).intoArray(r, i); 990 } 991 } 992 993 assertArraysEquals(a, b, r, Byte256VectorTests::SUB); 994 } 995 static byte sub(byte a, byte b) { 996 return (byte)(a - b); 997 } 998 999 @Test(dataProvider = "byteBinaryOpProvider") 1000 static void subByte256VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 1001 byte[] a = fa.apply(SPECIES.length()); 1002 byte[] b = fb.apply(SPECIES.length()); 1003 byte[] r = fr.apply(SPECIES.length()); 1004 1005 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1006 for (int i = 0; i < a.length; i += SPECIES.length()) { 1007 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1008 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 1009 av.sub(bv).intoArray(r, i); 1010 } 1011 } 1012 1013 assertArraysEquals(a, b, r, Byte256VectorTests::sub); 1014 } 1015 1016 @Test(dataProvider = "byteBinaryOpMaskProvider") 1017 static void SUBByte256VectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 1018 IntFunction<boolean[]> fm) { 1019 byte[] a = fa.apply(SPECIES.length()); 1020 byte[] b = fb.apply(SPECIES.length()); 1021 byte[] r = fr.apply(SPECIES.length()); 1022 boolean[] mask = fm.apply(SPECIES.length()); 1023 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1024 1025 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1026 for (int i = 0; i < a.length; i += SPECIES.length()) { 1027 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1028 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 1029 av.lanewise(VectorOperators.SUB, bv, vmask).intoArray(r, i); 1030 } 1031 } 1032 1033 assertArraysEquals(a, b, r, mask, Byte256VectorTests::SUB); 1034 } 1035 1036 @Test(dataProvider = "byteBinaryOpMaskProvider") 1037 static void subByte256VectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 1038 IntFunction<boolean[]> fm) { 1039 byte[] a = fa.apply(SPECIES.length()); 1040 byte[] b = fb.apply(SPECIES.length()); 1041 byte[] r = fr.apply(SPECIES.length()); 1042 boolean[] mask = fm.apply(SPECIES.length()); 1043 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1044 1045 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1046 for (int i = 0; i < a.length; i += SPECIES.length()) { 1047 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1048 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 1049 av.sub(bv, vmask).intoArray(r, i); 1050 } 1051 } 1052 1053 assertArraysEquals(a, b, r, mask, Byte256VectorTests::sub); 1054 } 1055 static byte MUL(byte a, byte b) { 1056 return (byte)(a * b); 1057 } 1058 1059 @Test(dataProvider = "byteBinaryOpProvider") 1060 static void MULByte256VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 1061 byte[] a = fa.apply(SPECIES.length()); 1062 byte[] b = fb.apply(SPECIES.length()); 1063 byte[] r = fr.apply(SPECIES.length()); 1064 1065 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1066 for (int i = 0; i < a.length; i += SPECIES.length()) { 1067 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1068 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 1069 av.lanewise(VectorOperators.MUL, bv).intoArray(r, i); 1070 } 1071 } 1072 1073 assertArraysEquals(a, b, r, Byte256VectorTests::MUL); 1074 } 1075 static byte mul(byte a, byte b) { 1076 return (byte)(a * b); 1077 } 1078 1079 @Test(dataProvider = "byteBinaryOpProvider") 1080 static void mulByte256VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 1081 byte[] a = fa.apply(SPECIES.length()); 1082 byte[] b = fb.apply(SPECIES.length()); 1083 byte[] r = fr.apply(SPECIES.length()); 1084 1085 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1086 for (int i = 0; i < a.length; i += SPECIES.length()) { 1087 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1088 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 1089 av.mul(bv).intoArray(r, i); 1090 } 1091 } 1092 1093 assertArraysEquals(a, b, r, Byte256VectorTests::mul); 1094 } 1095 1096 @Test(dataProvider = "byteBinaryOpMaskProvider") 1097 static void MULByte256VectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 1098 IntFunction<boolean[]> fm) { 1099 byte[] a = fa.apply(SPECIES.length()); 1100 byte[] b = fb.apply(SPECIES.length()); 1101 byte[] r = fr.apply(SPECIES.length()); 1102 boolean[] mask = fm.apply(SPECIES.length()); 1103 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1104 1105 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1106 for (int i = 0; i < a.length; i += SPECIES.length()) { 1107 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1108 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 1109 av.lanewise(VectorOperators.MUL, bv, vmask).intoArray(r, i); 1110 } 1111 } 1112 1113 assertArraysEquals(a, b, r, mask, Byte256VectorTests::MUL); 1114 } 1115 1116 @Test(dataProvider = "byteBinaryOpMaskProvider") 1117 static void mulByte256VectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 1118 IntFunction<boolean[]> fm) { 1119 byte[] a = fa.apply(SPECIES.length()); 1120 byte[] b = fb.apply(SPECIES.length()); 1121 byte[] r = fr.apply(SPECIES.length()); 1122 boolean[] mask = fm.apply(SPECIES.length()); 1123 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1124 1125 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1126 for (int i = 0; i < a.length; i += SPECIES.length()) { 1127 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1128 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 1129 av.mul(bv, vmask).intoArray(r, i); 1130 } 1131 } 1132 1133 assertArraysEquals(a, b, r, mask, Byte256VectorTests::mul); 1134 } 1135 1136 1137 1138 static byte DIV(byte a, byte b) { 1139 return (byte)(a / b); 1140 } 1141 1142 @Test(dataProvider = "byteBinaryOpProvider") 1143 static void DIVByte256VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 1144 byte[] a = fa.apply(SPECIES.length()); 1145 byte[] b = fb.apply(SPECIES.length()); 1146 byte[] r = fr.apply(SPECIES.length()); 1147 1148 replaceZero(b, (byte) 1); 1149 1150 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1151 for (int i = 0; i < a.length; i += SPECIES.length()) { 1152 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1153 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 1154 av.lanewise(VectorOperators.DIV, bv).intoArray(r, i); 1155 } 1156 } 1157 1158 assertArraysEquals(a, b, r, Byte256VectorTests::DIV); 1159 } 1160 static byte div(byte a, byte b) { 1161 return (byte)(a / b); 1162 } 1163 1164 @Test(dataProvider = "byteBinaryOpProvider") 1165 static void divByte256VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 1166 byte[] a = fa.apply(SPECIES.length()); 1167 byte[] b = fb.apply(SPECIES.length()); 1168 byte[] r = fr.apply(SPECIES.length()); 1169 1170 replaceZero(b, (byte) 1); 1171 1172 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1173 for (int i = 0; i < a.length; i += SPECIES.length()) { 1174 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1175 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 1176 av.div(bv).intoArray(r, i); 1177 } 1178 } 1179 1180 assertArraysEquals(a, b, r, Byte256VectorTests::div); 1181 } 1182 1183 1184 1185 @Test(dataProvider = "byteBinaryOpMaskProvider") 1186 static void DIVByte256VectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 1187 IntFunction<boolean[]> fm) { 1188 byte[] a = fa.apply(SPECIES.length()); 1189 byte[] b = fb.apply(SPECIES.length()); 1190 byte[] r = fr.apply(SPECIES.length()); 1191 boolean[] mask = fm.apply(SPECIES.length()); 1192 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1193 1194 replaceZero(b, mask, (byte) 1); 1195 1196 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1197 for (int i = 0; i < a.length; i += SPECIES.length()) { 1198 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1199 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 1200 av.lanewise(VectorOperators.DIV, bv, vmask).intoArray(r, i); 1201 } 1202 } 1203 1204 assertArraysEquals(a, b, r, mask, Byte256VectorTests::DIV); 1205 } 1206 1207 @Test(dataProvider = "byteBinaryOpMaskProvider") 1208 static void divByte256VectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 1209 IntFunction<boolean[]> fm) { 1210 byte[] a = fa.apply(SPECIES.length()); 1211 byte[] b = fb.apply(SPECIES.length()); 1212 byte[] r = fr.apply(SPECIES.length()); 1213 boolean[] mask = fm.apply(SPECIES.length()); 1214 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1215 1216 replaceZero(b, mask, (byte) 1); 1217 1218 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1219 for (int i = 0; i < a.length; i += SPECIES.length()) { 1220 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1221 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 1222 av.div(bv, vmask).intoArray(r, i); 1223 } 1224 } 1225 1226 assertArraysEquals(a, b, r, mask, Byte256VectorTests::div); 1227 } 1228 1229 static byte FIRST_NONZERO(byte a, byte b) { 1230 return (byte)((a)!=0?a:b); 1231 } 1232 1233 @Test(dataProvider = "byteBinaryOpProvider") 1234 static void FIRST_NONZEROByte256VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 1235 byte[] a = fa.apply(SPECIES.length()); 1236 byte[] b = fb.apply(SPECIES.length()); 1237 byte[] r = fr.apply(SPECIES.length()); 1238 1239 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1240 for (int i = 0; i < a.length; i += SPECIES.length()) { 1241 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1242 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 1243 av.lanewise(VectorOperators.FIRST_NONZERO, bv).intoArray(r, i); 1244 } 1245 } 1246 1247 assertArraysEquals(a, b, r, Byte256VectorTests::FIRST_NONZERO); 1248 } 1249 1250 @Test(dataProvider = "byteBinaryOpMaskProvider") 1251 static void FIRST_NONZEROByte256VectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 1252 IntFunction<boolean[]> fm) { 1253 byte[] a = fa.apply(SPECIES.length()); 1254 byte[] b = fb.apply(SPECIES.length()); 1255 byte[] r = fr.apply(SPECIES.length()); 1256 boolean[] mask = fm.apply(SPECIES.length()); 1257 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1258 1259 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1260 for (int i = 0; i < a.length; i += SPECIES.length()) { 1261 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1262 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 1263 av.lanewise(VectorOperators.FIRST_NONZERO, bv, vmask).intoArray(r, i); 1264 } 1265 } 1266 1267 assertArraysEquals(a, b, r, mask, Byte256VectorTests::FIRST_NONZERO); 1268 } 1269 1270 static byte AND(byte a, byte b) { 1271 return (byte)(a & b); 1272 } 1273 1274 @Test(dataProvider = "byteBinaryOpProvider") 1275 static void ANDByte256VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 1276 byte[] a = fa.apply(SPECIES.length()); 1277 byte[] b = fb.apply(SPECIES.length()); 1278 byte[] r = fr.apply(SPECIES.length()); 1279 1280 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1281 for (int i = 0; i < a.length; i += SPECIES.length()) { 1282 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1283 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 1284 av.lanewise(VectorOperators.AND, bv).intoArray(r, i); 1285 } 1286 } 1287 1288 assertArraysEquals(a, b, r, Byte256VectorTests::AND); 1289 } 1290 static byte and(byte a, byte b) { 1291 return (byte)(a & b); 1292 } 1293 1294 @Test(dataProvider = "byteBinaryOpProvider") 1295 static void andByte256VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 1296 byte[] a = fa.apply(SPECIES.length()); 1297 byte[] b = fb.apply(SPECIES.length()); 1298 byte[] r = fr.apply(SPECIES.length()); 1299 1300 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1301 for (int i = 0; i < a.length; i += SPECIES.length()) { 1302 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1303 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 1304 av.and(bv).intoArray(r, i); 1305 } 1306 } 1307 1308 assertArraysEquals(a, b, r, Byte256VectorTests::and); 1309 } 1310 1311 1312 1313 @Test(dataProvider = "byteBinaryOpMaskProvider") 1314 static void ANDByte256VectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 1315 IntFunction<boolean[]> fm) { 1316 byte[] a = fa.apply(SPECIES.length()); 1317 byte[] b = fb.apply(SPECIES.length()); 1318 byte[] r = fr.apply(SPECIES.length()); 1319 boolean[] mask = fm.apply(SPECIES.length()); 1320 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1321 1322 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1323 for (int i = 0; i < a.length; i += SPECIES.length()) { 1324 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1325 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 1326 av.lanewise(VectorOperators.AND, bv, vmask).intoArray(r, i); 1327 } 1328 } 1329 1330 assertArraysEquals(a, b, r, mask, Byte256VectorTests::AND); 1331 } 1332 1333 1334 static byte AND_NOT(byte a, byte b) { 1335 return (byte)(a & ~b); 1336 } 1337 1338 @Test(dataProvider = "byteBinaryOpProvider") 1339 static void AND_NOTByte256VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 1340 byte[] a = fa.apply(SPECIES.length()); 1341 byte[] b = fb.apply(SPECIES.length()); 1342 byte[] r = fr.apply(SPECIES.length()); 1343 1344 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1345 for (int i = 0; i < a.length; i += SPECIES.length()) { 1346 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1347 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 1348 av.lanewise(VectorOperators.AND_NOT, bv).intoArray(r, i); 1349 } 1350 } 1351 1352 assertArraysEquals(a, b, r, Byte256VectorTests::AND_NOT); 1353 } 1354 1355 1356 1357 @Test(dataProvider = "byteBinaryOpMaskProvider") 1358 static void AND_NOTByte256VectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 1359 IntFunction<boolean[]> fm) { 1360 byte[] a = fa.apply(SPECIES.length()); 1361 byte[] b = fb.apply(SPECIES.length()); 1362 byte[] r = fr.apply(SPECIES.length()); 1363 boolean[] mask = fm.apply(SPECIES.length()); 1364 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1365 1366 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1367 for (int i = 0; i < a.length; i += SPECIES.length()) { 1368 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1369 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 1370 av.lanewise(VectorOperators.AND_NOT, bv, vmask).intoArray(r, i); 1371 } 1372 } 1373 1374 assertArraysEquals(a, b, r, mask, Byte256VectorTests::AND_NOT); 1375 } 1376 1377 1378 static byte OR(byte a, byte b) { 1379 return (byte)(a | b); 1380 } 1381 1382 @Test(dataProvider = "byteBinaryOpProvider") 1383 static void ORByte256VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 1384 byte[] a = fa.apply(SPECIES.length()); 1385 byte[] b = fb.apply(SPECIES.length()); 1386 byte[] r = fr.apply(SPECIES.length()); 1387 1388 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1389 for (int i = 0; i < a.length; i += SPECIES.length()) { 1390 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1391 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 1392 av.lanewise(VectorOperators.OR, bv).intoArray(r, i); 1393 } 1394 } 1395 1396 assertArraysEquals(a, b, r, Byte256VectorTests::OR); 1397 } 1398 static byte or(byte a, byte b) { 1399 return (byte)(a | b); 1400 } 1401 1402 @Test(dataProvider = "byteBinaryOpProvider") 1403 static void orByte256VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 1404 byte[] a = fa.apply(SPECIES.length()); 1405 byte[] b = fb.apply(SPECIES.length()); 1406 byte[] r = fr.apply(SPECIES.length()); 1407 1408 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1409 for (int i = 0; i < a.length; i += SPECIES.length()) { 1410 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1411 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 1412 av.or(bv).intoArray(r, i); 1413 } 1414 } 1415 1416 assertArraysEquals(a, b, r, Byte256VectorTests::or); 1417 } 1418 1419 1420 1421 @Test(dataProvider = "byteBinaryOpMaskProvider") 1422 static void ORByte256VectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 1423 IntFunction<boolean[]> fm) { 1424 byte[] a = fa.apply(SPECIES.length()); 1425 byte[] b = fb.apply(SPECIES.length()); 1426 byte[] r = fr.apply(SPECIES.length()); 1427 boolean[] mask = fm.apply(SPECIES.length()); 1428 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1429 1430 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1431 for (int i = 0; i < a.length; i += SPECIES.length()) { 1432 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1433 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 1434 av.lanewise(VectorOperators.OR, bv, vmask).intoArray(r, i); 1435 } 1436 } 1437 1438 assertArraysEquals(a, b, r, mask, Byte256VectorTests::OR); 1439 } 1440 1441 1442 static byte XOR(byte a, byte b) { 1443 return (byte)(a ^ b); 1444 } 1445 1446 @Test(dataProvider = "byteBinaryOpProvider") 1447 static void XORByte256VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 1448 byte[] a = fa.apply(SPECIES.length()); 1449 byte[] b = fb.apply(SPECIES.length()); 1450 byte[] r = fr.apply(SPECIES.length()); 1451 1452 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1453 for (int i = 0; i < a.length; i += SPECIES.length()) { 1454 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1455 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 1456 av.lanewise(VectorOperators.XOR, bv).intoArray(r, i); 1457 } 1458 } 1459 1460 assertArraysEquals(a, b, r, Byte256VectorTests::XOR); 1461 } 1462 1463 1464 1465 @Test(dataProvider = "byteBinaryOpMaskProvider") 1466 static void XORByte256VectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 1467 IntFunction<boolean[]> fm) { 1468 byte[] a = fa.apply(SPECIES.length()); 1469 byte[] b = fb.apply(SPECIES.length()); 1470 byte[] r = fr.apply(SPECIES.length()); 1471 boolean[] mask = fm.apply(SPECIES.length()); 1472 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1473 1474 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1475 for (int i = 0; i < a.length; i += SPECIES.length()) { 1476 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1477 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 1478 av.lanewise(VectorOperators.XOR, bv, vmask).intoArray(r, i); 1479 } 1480 } 1481 1482 assertArraysEquals(a, b, r, mask, Byte256VectorTests::XOR); 1483 } 1484 1485 1486 @Test(dataProvider = "byteBinaryOpProvider") 1487 static void addByte256VectorTestsBroadcastSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 1488 byte[] a = fa.apply(SPECIES.length()); 1489 byte[] b = fb.apply(SPECIES.length()); 1490 byte[] r = fr.apply(SPECIES.length()); 1491 1492 for (int i = 0; i < a.length; i += SPECIES.length()) { 1493 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1494 av.add(b[i]).intoArray(r, i); 1495 } 1496 1497 assertBroadcastArraysEquals(a, b, r, Byte256VectorTests::add); 1498 } 1499 1500 @Test(dataProvider = "byteBinaryOpMaskProvider") 1501 static void addByte256VectorTestsBroadcastMaskedSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 1502 IntFunction<boolean[]> fm) { 1503 byte[] a = fa.apply(SPECIES.length()); 1504 byte[] b = fb.apply(SPECIES.length()); 1505 byte[] r = fr.apply(SPECIES.length()); 1506 boolean[] mask = fm.apply(SPECIES.length()); 1507 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1508 1509 for (int i = 0; i < a.length; i += SPECIES.length()) { 1510 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1511 av.add(b[i], vmask).intoArray(r, i); 1512 } 1513 1514 assertBroadcastArraysEquals(a, b, r, mask, Byte256VectorTests::add); 1515 } 1516 1517 @Test(dataProvider = "byteBinaryOpProvider") 1518 static void subByte256VectorTestsBroadcastSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 1519 byte[] a = fa.apply(SPECIES.length()); 1520 byte[] b = fb.apply(SPECIES.length()); 1521 byte[] r = fr.apply(SPECIES.length()); 1522 1523 for (int i = 0; i < a.length; i += SPECIES.length()) { 1524 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1525 av.sub(b[i]).intoArray(r, i); 1526 } 1527 1528 assertBroadcastArraysEquals(a, b, r, Byte256VectorTests::sub); 1529 } 1530 1531 @Test(dataProvider = "byteBinaryOpMaskProvider") 1532 static void subByte256VectorTestsBroadcastMaskedSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 1533 IntFunction<boolean[]> fm) { 1534 byte[] a = fa.apply(SPECIES.length()); 1535 byte[] b = fb.apply(SPECIES.length()); 1536 byte[] r = fr.apply(SPECIES.length()); 1537 boolean[] mask = fm.apply(SPECIES.length()); 1538 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1539 1540 for (int i = 0; i < a.length; i += SPECIES.length()) { 1541 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1542 av.sub(b[i], vmask).intoArray(r, i); 1543 } 1544 1545 assertBroadcastArraysEquals(a, b, r, mask, Byte256VectorTests::sub); 1546 } 1547 1548 @Test(dataProvider = "byteBinaryOpProvider") 1549 static void mulByte256VectorTestsBroadcastSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 1550 byte[] a = fa.apply(SPECIES.length()); 1551 byte[] b = fb.apply(SPECIES.length()); 1552 byte[] r = fr.apply(SPECIES.length()); 1553 1554 for (int i = 0; i < a.length; i += SPECIES.length()) { 1555 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1556 av.mul(b[i]).intoArray(r, i); 1557 } 1558 1559 assertBroadcastArraysEquals(a, b, r, Byte256VectorTests::mul); 1560 } 1561 1562 @Test(dataProvider = "byteBinaryOpMaskProvider") 1563 static void mulByte256VectorTestsBroadcastMaskedSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 1564 IntFunction<boolean[]> fm) { 1565 byte[] a = fa.apply(SPECIES.length()); 1566 byte[] b = fb.apply(SPECIES.length()); 1567 byte[] r = fr.apply(SPECIES.length()); 1568 boolean[] mask = fm.apply(SPECIES.length()); 1569 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1570 1571 for (int i = 0; i < a.length; i += SPECIES.length()) { 1572 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1573 av.mul(b[i], vmask).intoArray(r, i); 1574 } 1575 1576 assertBroadcastArraysEquals(a, b, r, mask, Byte256VectorTests::mul); 1577 } 1578 1579 1580 1581 1582 @Test(dataProvider = "byteBinaryOpProvider") 1583 static void divByte256VectorTestsBroadcastSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 1584 byte[] a = fa.apply(SPECIES.length()); 1585 byte[] b = fb.apply(SPECIES.length()); 1586 byte[] r = fr.apply(SPECIES.length()); 1587 1588 replaceZero(b, (byte) 1); 1589 1590 for (int i = 0; i < a.length; i += SPECIES.length()) { 1591 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1592 av.div(b[i]).intoArray(r, i); 1593 } 1594 1595 assertBroadcastArraysEquals(a, b, r, Byte256VectorTests::div); 1596 } 1597 1598 1599 1600 @Test(dataProvider = "byteBinaryOpMaskProvider") 1601 static void divByte256VectorTestsBroadcastMaskedSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 1602 IntFunction<boolean[]> fm) { 1603 byte[] a = fa.apply(SPECIES.length()); 1604 byte[] b = fb.apply(SPECIES.length()); 1605 byte[] r = fr.apply(SPECIES.length()); 1606 boolean[] mask = fm.apply(SPECIES.length()); 1607 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1608 1609 replaceZero(b, (byte) 1); 1610 1611 for (int i = 0; i < a.length; i += SPECIES.length()) { 1612 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1613 av.div(b[i], vmask).intoArray(r, i); 1614 } 1615 1616 assertBroadcastArraysEquals(a, b, r, mask, Byte256VectorTests::div); 1617 } 1618 1619 1620 1621 @Test(dataProvider = "byteBinaryOpProvider") 1622 static void ORByte256VectorTestsBroadcastSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 1623 byte[] a = fa.apply(SPECIES.length()); 1624 byte[] b = fb.apply(SPECIES.length()); 1625 byte[] r = fr.apply(SPECIES.length()); 1626 1627 for (int i = 0; i < a.length; i += SPECIES.length()) { 1628 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1629 av.lanewise(VectorOperators.OR, b[i]).intoArray(r, i); 1630 } 1631 1632 assertBroadcastArraysEquals(a, b, r, Byte256VectorTests::OR); 1633 } 1634 1635 @Test(dataProvider = "byteBinaryOpProvider") 1636 static void orByte256VectorTestsBroadcastSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 1637 byte[] a = fa.apply(SPECIES.length()); 1638 byte[] b = fb.apply(SPECIES.length()); 1639 byte[] r = fr.apply(SPECIES.length()); 1640 1641 for (int i = 0; i < a.length; i += SPECIES.length()) { 1642 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1643 av.or(b[i]).intoArray(r, i); 1644 } 1645 1646 assertBroadcastArraysEquals(a, b, r, Byte256VectorTests::or); 1647 } 1648 1649 1650 1651 @Test(dataProvider = "byteBinaryOpMaskProvider") 1652 static void ORByte256VectorTestsBroadcastMaskedSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 1653 IntFunction<boolean[]> fm) { 1654 byte[] a = fa.apply(SPECIES.length()); 1655 byte[] b = fb.apply(SPECIES.length()); 1656 byte[] r = fr.apply(SPECIES.length()); 1657 boolean[] mask = fm.apply(SPECIES.length()); 1658 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1659 1660 for (int i = 0; i < a.length; i += SPECIES.length()) { 1661 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1662 av.lanewise(VectorOperators.OR, b[i], vmask).intoArray(r, i); 1663 } 1664 1665 assertBroadcastArraysEquals(a, b, r, mask, Byte256VectorTests::OR); 1666 } 1667 1668 1669 1670 1671 static byte LSHL(byte a, byte b) { 1672 return (byte)((a << (b & 0x7))); 1673 } 1674 1675 @Test(dataProvider = "byteBinaryOpProvider") 1676 static void LSHLByte256VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 1677 byte[] a = fa.apply(SPECIES.length()); 1678 byte[] b = fb.apply(SPECIES.length()); 1679 byte[] r = fr.apply(SPECIES.length()); 1680 1681 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1682 for (int i = 0; i < a.length; i += SPECIES.length()) { 1683 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1684 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 1685 av.lanewise(VectorOperators.LSHL, bv).intoArray(r, i); 1686 } 1687 } 1688 1689 assertArraysEquals(a, b, r, Byte256VectorTests::LSHL); 1690 } 1691 1692 1693 1694 @Test(dataProvider = "byteBinaryOpMaskProvider") 1695 static void LSHLByte256VectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 1696 IntFunction<boolean[]> fm) { 1697 byte[] a = fa.apply(SPECIES.length()); 1698 byte[] b = fb.apply(SPECIES.length()); 1699 byte[] r = fr.apply(SPECIES.length()); 1700 boolean[] mask = fm.apply(SPECIES.length()); 1701 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1702 1703 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1704 for (int i = 0; i < a.length; i += SPECIES.length()) { 1705 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1706 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 1707 av.lanewise(VectorOperators.LSHL, bv, vmask).intoArray(r, i); 1708 } 1709 } 1710 1711 assertArraysEquals(a, b, r, mask, Byte256VectorTests::LSHL); 1712 } 1713 1714 1715 1716 1717 1718 1719 static byte ASHR(byte a, byte b) { 1720 return (byte)((a >> (b & 0x7))); 1721 } 1722 1723 @Test(dataProvider = "byteBinaryOpProvider") 1724 static void ASHRByte256VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 1725 byte[] a = fa.apply(SPECIES.length()); 1726 byte[] b = fb.apply(SPECIES.length()); 1727 byte[] r = fr.apply(SPECIES.length()); 1728 1729 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1730 for (int i = 0; i < a.length; i += SPECIES.length()) { 1731 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1732 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 1733 av.lanewise(VectorOperators.ASHR, bv).intoArray(r, i); 1734 } 1735 } 1736 1737 assertArraysEquals(a, b, r, Byte256VectorTests::ASHR); 1738 } 1739 1740 1741 1742 @Test(dataProvider = "byteBinaryOpMaskProvider") 1743 static void ASHRByte256VectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 1744 IntFunction<boolean[]> fm) { 1745 byte[] a = fa.apply(SPECIES.length()); 1746 byte[] b = fb.apply(SPECIES.length()); 1747 byte[] r = fr.apply(SPECIES.length()); 1748 boolean[] mask = fm.apply(SPECIES.length()); 1749 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1750 1751 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1752 for (int i = 0; i < a.length; i += SPECIES.length()) { 1753 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1754 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 1755 av.lanewise(VectorOperators.ASHR, bv, vmask).intoArray(r, i); 1756 } 1757 } 1758 1759 assertArraysEquals(a, b, r, mask, Byte256VectorTests::ASHR); 1760 } 1761 1762 1763 1764 1765 1766 1767 static byte LSHR(byte a, byte b) { 1768 return (byte)(((a & 0xFF) >>> (b & 0x7))); 1769 } 1770 1771 @Test(dataProvider = "byteBinaryOpProvider") 1772 static void LSHRByte256VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 1773 byte[] a = fa.apply(SPECIES.length()); 1774 byte[] b = fb.apply(SPECIES.length()); 1775 byte[] r = fr.apply(SPECIES.length()); 1776 1777 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1778 for (int i = 0; i < a.length; i += SPECIES.length()) { 1779 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1780 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 1781 av.lanewise(VectorOperators.LSHR, bv).intoArray(r, i); 1782 } 1783 } 1784 1785 assertArraysEquals(a, b, r, Byte256VectorTests::LSHR); 1786 } 1787 1788 1789 1790 @Test(dataProvider = "byteBinaryOpMaskProvider") 1791 static void LSHRByte256VectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 1792 IntFunction<boolean[]> fm) { 1793 byte[] a = fa.apply(SPECIES.length()); 1794 byte[] b = fb.apply(SPECIES.length()); 1795 byte[] r = fr.apply(SPECIES.length()); 1796 boolean[] mask = fm.apply(SPECIES.length()); 1797 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1798 1799 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1800 for (int i = 0; i < a.length; i += SPECIES.length()) { 1801 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1802 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 1803 av.lanewise(VectorOperators.LSHR, bv, vmask).intoArray(r, i); 1804 } 1805 } 1806 1807 assertArraysEquals(a, b, r, mask, Byte256VectorTests::LSHR); 1808 } 1809 1810 1811 1812 1813 1814 1815 static byte LSHL_unary(byte a, byte b) { 1816 return (byte)((a << (b & 7))); 1817 } 1818 1819 @Test(dataProvider = "byteBinaryOpProvider") 1820 static void LSHLByte256VectorTestsShift(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 1821 byte[] a = fa.apply(SPECIES.length()); 1822 byte[] b = fb.apply(SPECIES.length()); 1823 byte[] r = fr.apply(SPECIES.length()); 1824 1825 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1826 for (int i = 0; i < a.length; i += SPECIES.length()) { 1827 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1828 av.lanewise(VectorOperators.LSHL, (int)b[i]).intoArray(r, i); 1829 } 1830 } 1831 1832 assertShiftArraysEquals(a, b, r, Byte256VectorTests::LSHL_unary); 1833 } 1834 1835 1836 1837 @Test(dataProvider = "byteBinaryOpMaskProvider") 1838 static void LSHLByte256VectorTestsShift(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 1839 IntFunction<boolean[]> fm) { 1840 byte[] a = fa.apply(SPECIES.length()); 1841 byte[] b = fb.apply(SPECIES.length()); 1842 byte[] r = fr.apply(SPECIES.length()); 1843 boolean[] mask = fm.apply(SPECIES.length()); 1844 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1845 1846 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1847 for (int i = 0; i < a.length; i += SPECIES.length()) { 1848 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1849 av.lanewise(VectorOperators.LSHL, (int)b[i], vmask).intoArray(r, i); 1850 } 1851 } 1852 1853 assertShiftArraysEquals(a, b, r, mask, Byte256VectorTests::LSHL_unary); 1854 } 1855 1856 1857 1858 1859 1860 1861 static byte LSHR_unary(byte a, byte b) { 1862 return (byte)(((a & 0xFF) >>> (b & 7))); 1863 } 1864 1865 @Test(dataProvider = "byteBinaryOpProvider") 1866 static void LSHRByte256VectorTestsShift(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 1867 byte[] a = fa.apply(SPECIES.length()); 1868 byte[] b = fb.apply(SPECIES.length()); 1869 byte[] r = fr.apply(SPECIES.length()); 1870 1871 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1872 for (int i = 0; i < a.length; i += SPECIES.length()) { 1873 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1874 av.lanewise(VectorOperators.LSHR, (int)b[i]).intoArray(r, i); 1875 } 1876 } 1877 1878 assertShiftArraysEquals(a, b, r, Byte256VectorTests::LSHR_unary); 1879 } 1880 1881 1882 1883 @Test(dataProvider = "byteBinaryOpMaskProvider") 1884 static void LSHRByte256VectorTestsShift(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 1885 IntFunction<boolean[]> fm) { 1886 byte[] a = fa.apply(SPECIES.length()); 1887 byte[] b = fb.apply(SPECIES.length()); 1888 byte[] r = fr.apply(SPECIES.length()); 1889 boolean[] mask = fm.apply(SPECIES.length()); 1890 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1891 1892 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1893 for (int i = 0; i < a.length; i += SPECIES.length()) { 1894 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1895 av.lanewise(VectorOperators.LSHR, (int)b[i], vmask).intoArray(r, i); 1896 } 1897 } 1898 1899 assertShiftArraysEquals(a, b, r, mask, Byte256VectorTests::LSHR_unary); 1900 } 1901 1902 1903 1904 1905 1906 1907 static byte ASHR_unary(byte a, byte b) { 1908 return (byte)((a >> (b & 7))); 1909 } 1910 1911 @Test(dataProvider = "byteBinaryOpProvider") 1912 static void ASHRByte256VectorTestsShift(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 1913 byte[] a = fa.apply(SPECIES.length()); 1914 byte[] b = fb.apply(SPECIES.length()); 1915 byte[] r = fr.apply(SPECIES.length()); 1916 1917 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1918 for (int i = 0; i < a.length; i += SPECIES.length()) { 1919 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1920 av.lanewise(VectorOperators.ASHR, (int)b[i]).intoArray(r, i); 1921 } 1922 } 1923 1924 assertShiftArraysEquals(a, b, r, Byte256VectorTests::ASHR_unary); 1925 } 1926 1927 1928 1929 @Test(dataProvider = "byteBinaryOpMaskProvider") 1930 static void ASHRByte256VectorTestsShift(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 1931 IntFunction<boolean[]> fm) { 1932 byte[] a = fa.apply(SPECIES.length()); 1933 byte[] b = fb.apply(SPECIES.length()); 1934 byte[] r = fr.apply(SPECIES.length()); 1935 boolean[] mask = fm.apply(SPECIES.length()); 1936 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1937 1938 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1939 for (int i = 0; i < a.length; i += SPECIES.length()) { 1940 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1941 av.lanewise(VectorOperators.ASHR, (int)b[i], vmask).intoArray(r, i); 1942 } 1943 } 1944 1945 assertShiftArraysEquals(a, b, r, mask, Byte256VectorTests::ASHR_unary); 1946 } 1947 1948 1949 1950 static byte MIN(byte a, byte b) { 1951 return (byte)(Math.min(a, b)); 1952 } 1953 1954 @Test(dataProvider = "byteBinaryOpProvider") 1955 static void MINByte256VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 1956 byte[] a = fa.apply(SPECIES.length()); 1957 byte[] b = fb.apply(SPECIES.length()); 1958 byte[] r = fr.apply(SPECIES.length()); 1959 1960 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1961 for (int i = 0; i < a.length; i += SPECIES.length()) { 1962 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1963 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 1964 av.lanewise(VectorOperators.MIN, bv).intoArray(r, i); 1965 } 1966 } 1967 1968 assertArraysEquals(a, b, r, Byte256VectorTests::MIN); 1969 } 1970 static byte min(byte a, byte b) { 1971 return (byte)(Math.min(a, b)); 1972 } 1973 1974 @Test(dataProvider = "byteBinaryOpProvider") 1975 static void minByte256VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 1976 byte[] a = fa.apply(SPECIES.length()); 1977 byte[] b = fb.apply(SPECIES.length()); 1978 byte[] r = fr.apply(SPECIES.length()); 1979 1980 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1981 for (int i = 0; i < a.length; i += SPECIES.length()) { 1982 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1983 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 1984 av.min(bv).intoArray(r, i); 1985 } 1986 } 1987 1988 assertArraysEquals(a, b, r, Byte256VectorTests::min); 1989 } 1990 static byte MAX(byte a, byte b) { 1991 return (byte)(Math.max(a, b)); 1992 } 1993 1994 @Test(dataProvider = "byteBinaryOpProvider") 1995 static void MAXByte256VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 1996 byte[] a = fa.apply(SPECIES.length()); 1997 byte[] b = fb.apply(SPECIES.length()); 1998 byte[] r = fr.apply(SPECIES.length()); 1999 2000 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2001 for (int i = 0; i < a.length; i += SPECIES.length()) { 2002 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2003 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 2004 av.lanewise(VectorOperators.MAX, bv).intoArray(r, i); 2005 } 2006 } 2007 2008 assertArraysEquals(a, b, r, Byte256VectorTests::MAX); 2009 } 2010 static byte max(byte a, byte b) { 2011 return (byte)(Math.max(a, b)); 2012 } 2013 2014 @Test(dataProvider = "byteBinaryOpProvider") 2015 static void maxByte256VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 2016 byte[] a = fa.apply(SPECIES.length()); 2017 byte[] b = fb.apply(SPECIES.length()); 2018 byte[] r = fr.apply(SPECIES.length()); 2019 2020 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2021 for (int i = 0; i < a.length; i += SPECIES.length()) { 2022 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2023 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 2024 av.max(bv).intoArray(r, i); 2025 } 2026 } 2027 2028 assertArraysEquals(a, b, r, Byte256VectorTests::max); 2029 } 2030 2031 @Test(dataProvider = "byteBinaryOpProvider") 2032 static void MINByte256VectorTestsBroadcastSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 2033 byte[] a = fa.apply(SPECIES.length()); 2034 byte[] b = fb.apply(SPECIES.length()); 2035 byte[] r = fr.apply(SPECIES.length()); 2036 2037 for (int i = 0; i < a.length; i += SPECIES.length()) { 2038 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2039 av.lanewise(VectorOperators.MIN, b[i]).intoArray(r, i); 2040 } 2041 2042 assertBroadcastArraysEquals(a, b, r, Byte256VectorTests::MIN); 2043 } 2044 2045 @Test(dataProvider = "byteBinaryOpProvider") 2046 static void minByte256VectorTestsBroadcastSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 2047 byte[] a = fa.apply(SPECIES.length()); 2048 byte[] b = fb.apply(SPECIES.length()); 2049 byte[] r = fr.apply(SPECIES.length()); 2050 2051 for (int i = 0; i < a.length; i += SPECIES.length()) { 2052 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2053 av.min(b[i]).intoArray(r, i); 2054 } 2055 2056 assertBroadcastArraysEquals(a, b, r, Byte256VectorTests::min); 2057 } 2058 2059 @Test(dataProvider = "byteBinaryOpProvider") 2060 static void MAXByte256VectorTestsBroadcastSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 2061 byte[] a = fa.apply(SPECIES.length()); 2062 byte[] b = fb.apply(SPECIES.length()); 2063 byte[] r = fr.apply(SPECIES.length()); 2064 2065 for (int i = 0; i < a.length; i += SPECIES.length()) { 2066 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2067 av.lanewise(VectorOperators.MAX, b[i]).intoArray(r, i); 2068 } 2069 2070 assertBroadcastArraysEquals(a, b, r, Byte256VectorTests::MAX); 2071 } 2072 2073 @Test(dataProvider = "byteBinaryOpProvider") 2074 static void maxByte256VectorTestsBroadcastSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 2075 byte[] a = fa.apply(SPECIES.length()); 2076 byte[] b = fb.apply(SPECIES.length()); 2077 byte[] r = fr.apply(SPECIES.length()); 2078 2079 for (int i = 0; i < a.length; i += SPECIES.length()) { 2080 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2081 av.max(b[i]).intoArray(r, i); 2082 } 2083 2084 assertBroadcastArraysEquals(a, b, r, Byte256VectorTests::max); 2085 } 2086 2087 static byte AND(byte[] a, int idx) { 2088 byte res = -1; 2089 for (int i = idx; i < (idx + SPECIES.length()); i++) { 2090 res &= a[i]; 2091 } 2092 2093 return res; 2094 } 2095 2096 static byte AND(byte[] a) { 2097 byte res = -1; 2098 for (int i = 0; i < a.length; i += SPECIES.length()) { 2099 byte tmp = -1; 2100 for (int j = 0; j < SPECIES.length(); j++) { 2101 tmp &= a[i + j]; 2102 } 2103 res &= tmp; 2104 } 2105 2106 return res; 2107 } 2108 2109 2110 @Test(dataProvider = "byteUnaryOpProvider") 2111 static void ANDByte256VectorTests(IntFunction<byte[]> fa) { 2112 byte[] a = fa.apply(SPECIES.length()); 2113 byte[] r = fr.apply(SPECIES.length()); 2114 byte ra = -1; 2115 2116 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2117 for (int i = 0; i < a.length; i += SPECIES.length()) { 2118 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2119 r[i] = av.reduceLanes(VectorOperators.AND); 2120 } 2121 } 2122 2123 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2124 ra = -1; 2125 for (int i = 0; i < a.length; i += SPECIES.length()) { 2126 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2127 ra &= av.reduceLanes(VectorOperators.AND); 2128 } 2129 } 2130 2131 assertReductionArraysEquals(a, r, ra, Byte256VectorTests::AND, Byte256VectorTests::AND); 2132 } 2133 2134 2135 static byte ANDMasked(byte[] a, int idx, boolean[] mask) { 2136 byte res = -1; 2137 for (int i = idx; i < (idx + SPECIES.length()); i++) { 2138 if(mask[i % SPECIES.length()]) 2139 res &= a[i]; 2140 } 2141 2142 return res; 2143 } 2144 2145 static byte ANDMasked(byte[] a, boolean[] mask) { 2146 byte res = -1; 2147 for (int i = 0; i < a.length; i += SPECIES.length()) { 2148 byte tmp = -1; 2149 for (int j = 0; j < SPECIES.length(); j++) { 2150 if(mask[(i + j) % SPECIES.length()]) 2151 tmp &= a[i + j]; 2152 } 2153 res &= tmp; 2154 } 2155 2156 return res; 2157 } 2158 2159 2160 @Test(dataProvider = "byteUnaryOpMaskProvider") 2161 static void ANDByte256VectorTestsMasked(IntFunction<byte[]> fa, IntFunction<boolean[]> fm) { 2162 byte[] a = fa.apply(SPECIES.length()); 2163 byte[] r = fr.apply(SPECIES.length()); 2164 boolean[] mask = fm.apply(SPECIES.length()); 2165 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2166 byte ra = -1; 2167 2168 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2169 for (int i = 0; i < a.length; i += SPECIES.length()) { 2170 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2171 r[i] = av.reduceLanes(VectorOperators.AND, vmask); 2172 } 2173 } 2174 2175 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2176 ra = -1; 2177 for (int i = 0; i < a.length; i += SPECIES.length()) { 2178 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2179 ra &= av.reduceLanes(VectorOperators.AND, vmask); 2180 } 2181 } 2182 2183 assertReductionArraysEqualsMasked(a, r, ra, mask, Byte256VectorTests::ANDMasked, Byte256VectorTests::ANDMasked); 2184 } 2185 2186 2187 static byte OR(byte[] a, int idx) { 2188 byte res = 0; 2189 for (int i = idx; i < (idx + SPECIES.length()); i++) { 2190 res |= a[i]; 2191 } 2192 2193 return res; 2194 } 2195 2196 static byte OR(byte[] a) { 2197 byte res = 0; 2198 for (int i = 0; i < a.length; i += SPECIES.length()) { 2199 byte tmp = 0; 2200 for (int j = 0; j < SPECIES.length(); j++) { 2201 tmp |= a[i + j]; 2202 } 2203 res |= tmp; 2204 } 2205 2206 return res; 2207 } 2208 2209 2210 @Test(dataProvider = "byteUnaryOpProvider") 2211 static void ORByte256VectorTests(IntFunction<byte[]> fa) { 2212 byte[] a = fa.apply(SPECIES.length()); 2213 byte[] r = fr.apply(SPECIES.length()); 2214 byte ra = 0; 2215 2216 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2217 for (int i = 0; i < a.length; i += SPECIES.length()) { 2218 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2219 r[i] = av.reduceLanes(VectorOperators.OR); 2220 } 2221 } 2222 2223 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2224 ra = 0; 2225 for (int i = 0; i < a.length; i += SPECIES.length()) { 2226 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2227 ra |= av.reduceLanes(VectorOperators.OR); 2228 } 2229 } 2230 2231 assertReductionArraysEquals(a, r, ra, Byte256VectorTests::OR, Byte256VectorTests::OR); 2232 } 2233 2234 2235 static byte ORMasked(byte[] a, int idx, boolean[] mask) { 2236 byte res = 0; 2237 for (int i = idx; i < (idx + SPECIES.length()); i++) { 2238 if(mask[i % SPECIES.length()]) 2239 res |= a[i]; 2240 } 2241 2242 return res; 2243 } 2244 2245 static byte ORMasked(byte[] a, boolean[] mask) { 2246 byte res = 0; 2247 for (int i = 0; i < a.length; i += SPECIES.length()) { 2248 byte tmp = 0; 2249 for (int j = 0; j < SPECIES.length(); j++) { 2250 if(mask[(i + j) % SPECIES.length()]) 2251 tmp |= a[i + j]; 2252 } 2253 res |= tmp; 2254 } 2255 2256 return res; 2257 } 2258 2259 2260 @Test(dataProvider = "byteUnaryOpMaskProvider") 2261 static void ORByte256VectorTestsMasked(IntFunction<byte[]> fa, IntFunction<boolean[]> fm) { 2262 byte[] a = fa.apply(SPECIES.length()); 2263 byte[] r = fr.apply(SPECIES.length()); 2264 boolean[] mask = fm.apply(SPECIES.length()); 2265 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2266 byte ra = 0; 2267 2268 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2269 for (int i = 0; i < a.length; i += SPECIES.length()) { 2270 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2271 r[i] = av.reduceLanes(VectorOperators.OR, vmask); 2272 } 2273 } 2274 2275 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2276 ra = 0; 2277 for (int i = 0; i < a.length; i += SPECIES.length()) { 2278 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2279 ra |= av.reduceLanes(VectorOperators.OR, vmask); 2280 } 2281 } 2282 2283 assertReductionArraysEqualsMasked(a, r, ra, mask, Byte256VectorTests::ORMasked, Byte256VectorTests::ORMasked); 2284 } 2285 2286 2287 static byte XOR(byte[] a, int idx) { 2288 byte res = 0; 2289 for (int i = idx; i < (idx + SPECIES.length()); i++) { 2290 res ^= a[i]; 2291 } 2292 2293 return res; 2294 } 2295 2296 static byte XOR(byte[] a) { 2297 byte res = 0; 2298 for (int i = 0; i < a.length; i += SPECIES.length()) { 2299 byte tmp = 0; 2300 for (int j = 0; j < SPECIES.length(); j++) { 2301 tmp ^= a[i + j]; 2302 } 2303 res ^= tmp; 2304 } 2305 2306 return res; 2307 } 2308 2309 2310 @Test(dataProvider = "byteUnaryOpProvider") 2311 static void XORByte256VectorTests(IntFunction<byte[]> fa) { 2312 byte[] a = fa.apply(SPECIES.length()); 2313 byte[] r = fr.apply(SPECIES.length()); 2314 byte ra = 0; 2315 2316 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2317 for (int i = 0; i < a.length; i += SPECIES.length()) { 2318 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2319 r[i] = av.reduceLanes(VectorOperators.XOR); 2320 } 2321 } 2322 2323 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2324 ra = 0; 2325 for (int i = 0; i < a.length; i += SPECIES.length()) { 2326 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2327 ra ^= av.reduceLanes(VectorOperators.XOR); 2328 } 2329 } 2330 2331 assertReductionArraysEquals(a, r, ra, Byte256VectorTests::XOR, Byte256VectorTests::XOR); 2332 } 2333 2334 2335 static byte XORMasked(byte[] a, int idx, boolean[] mask) { 2336 byte res = 0; 2337 for (int i = idx; i < (idx + SPECIES.length()); i++) { 2338 if(mask[i % SPECIES.length()]) 2339 res ^= a[i]; 2340 } 2341 2342 return res; 2343 } 2344 2345 static byte XORMasked(byte[] a, boolean[] mask) { 2346 byte res = 0; 2347 for (int i = 0; i < a.length; i += SPECIES.length()) { 2348 byte tmp = 0; 2349 for (int j = 0; j < SPECIES.length(); j++) { 2350 if(mask[(i + j) % SPECIES.length()]) 2351 tmp ^= a[i + j]; 2352 } 2353 res ^= tmp; 2354 } 2355 2356 return res; 2357 } 2358 2359 2360 @Test(dataProvider = "byteUnaryOpMaskProvider") 2361 static void XORByte256VectorTestsMasked(IntFunction<byte[]> fa, IntFunction<boolean[]> fm) { 2362 byte[] a = fa.apply(SPECIES.length()); 2363 byte[] r = fr.apply(SPECIES.length()); 2364 boolean[] mask = fm.apply(SPECIES.length()); 2365 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2366 byte ra = 0; 2367 2368 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2369 for (int i = 0; i < a.length; i += SPECIES.length()) { 2370 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2371 r[i] = av.reduceLanes(VectorOperators.XOR, vmask); 2372 } 2373 } 2374 2375 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2376 ra = 0; 2377 for (int i = 0; i < a.length; i += SPECIES.length()) { 2378 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2379 ra ^= av.reduceLanes(VectorOperators.XOR, vmask); 2380 } 2381 } 2382 2383 assertReductionArraysEqualsMasked(a, r, ra, mask, Byte256VectorTests::XORMasked, Byte256VectorTests::XORMasked); 2384 } 2385 2386 static byte ADD(byte[] a, int idx) { 2387 byte res = 0; 2388 for (int i = idx; i < (idx + SPECIES.length()); i++) { 2389 res += a[i]; 2390 } 2391 2392 return res; 2393 } 2394 2395 static byte ADD(byte[] a) { 2396 byte res = 0; 2397 for (int i = 0; i < a.length; i += SPECIES.length()) { 2398 byte tmp = 0; 2399 for (int j = 0; j < SPECIES.length(); j++) { 2400 tmp += a[i + j]; 2401 } 2402 res += tmp; 2403 } 2404 2405 return res; 2406 } 2407 @Test(dataProvider = "byteUnaryOpProvider") 2408 static void ADDByte256VectorTests(IntFunction<byte[]> fa) { 2409 byte[] a = fa.apply(SPECIES.length()); 2410 byte[] r = fr.apply(SPECIES.length()); 2411 byte ra = 0; 2412 2413 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2414 for (int i = 0; i < a.length; i += SPECIES.length()) { 2415 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2416 r[i] = av.reduceLanes(VectorOperators.ADD); 2417 } 2418 } 2419 2420 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2421 ra = 0; 2422 for (int i = 0; i < a.length; i += SPECIES.length()) { 2423 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2424 ra += av.reduceLanes(VectorOperators.ADD); 2425 } 2426 } 2427 2428 assertReductionArraysEquals(a, r, ra, Byte256VectorTests::ADD, Byte256VectorTests::ADD); 2429 } 2430 static byte ADDMasked(byte[] a, int idx, boolean[] mask) { 2431 byte res = 0; 2432 for (int i = idx; i < (idx + SPECIES.length()); i++) { 2433 if(mask[i % SPECIES.length()]) 2434 res += a[i]; 2435 } 2436 2437 return res; 2438 } 2439 2440 static byte ADDMasked(byte[] a, boolean[] mask) { 2441 byte res = 0; 2442 for (int i = 0; i < a.length; i += SPECIES.length()) { 2443 byte tmp = 0; 2444 for (int j = 0; j < SPECIES.length(); j++) { 2445 if(mask[(i + j) % SPECIES.length()]) 2446 tmp += a[i + j]; 2447 } 2448 res += tmp; 2449 } 2450 2451 return res; 2452 } 2453 @Test(dataProvider = "byteUnaryOpMaskProvider") 2454 static void ADDByte256VectorTestsMasked(IntFunction<byte[]> fa, IntFunction<boolean[]> fm) { 2455 byte[] a = fa.apply(SPECIES.length()); 2456 byte[] r = fr.apply(SPECIES.length()); 2457 boolean[] mask = fm.apply(SPECIES.length()); 2458 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2459 byte ra = 0; 2460 2461 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2462 for (int i = 0; i < a.length; i += SPECIES.length()) { 2463 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2464 r[i] = av.reduceLanes(VectorOperators.ADD, vmask); 2465 } 2466 } 2467 2468 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2469 ra = 0; 2470 for (int i = 0; i < a.length; i += SPECIES.length()) { 2471 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2472 ra += av.reduceLanes(VectorOperators.ADD, vmask); 2473 } 2474 } 2475 2476 assertReductionArraysEqualsMasked(a, r, ra, mask, Byte256VectorTests::ADDMasked, Byte256VectorTests::ADDMasked); 2477 } 2478 static byte MUL(byte[] a, int idx) { 2479 byte res = 1; 2480 for (int i = idx; i < (idx + SPECIES.length()); i++) { 2481 res *= a[i]; 2482 } 2483 2484 return res; 2485 } 2486 2487 static byte MUL(byte[] a) { 2488 byte res = 1; 2489 for (int i = 0; i < a.length; i += SPECIES.length()) { 2490 byte tmp = 1; 2491 for (int j = 0; j < SPECIES.length(); j++) { 2492 tmp *= a[i + j]; 2493 } 2494 res *= tmp; 2495 } 2496 2497 return res; 2498 } 2499 @Test(dataProvider = "byteUnaryOpProvider") 2500 static void MULByte256VectorTests(IntFunction<byte[]> fa) { 2501 byte[] a = fa.apply(SPECIES.length()); 2502 byte[] r = fr.apply(SPECIES.length()); 2503 byte ra = 1; 2504 2505 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2506 for (int i = 0; i < a.length; i += SPECIES.length()) { 2507 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2508 r[i] = av.reduceLanes(VectorOperators.MUL); 2509 } 2510 } 2511 2512 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2513 ra = 1; 2514 for (int i = 0; i < a.length; i += SPECIES.length()) { 2515 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2516 ra *= av.reduceLanes(VectorOperators.MUL); 2517 } 2518 } 2519 2520 assertReductionArraysEquals(a, r, ra, Byte256VectorTests::MUL, Byte256VectorTests::MUL); 2521 } 2522 static byte MULMasked(byte[] a, int idx, boolean[] mask) { 2523 byte res = 1; 2524 for (int i = idx; i < (idx + SPECIES.length()); i++) { 2525 if(mask[i % SPECIES.length()]) 2526 res *= a[i]; 2527 } 2528 2529 return res; 2530 } 2531 2532 static byte MULMasked(byte[] a, boolean[] mask) { 2533 byte res = 1; 2534 for (int i = 0; i < a.length; i += SPECIES.length()) { 2535 byte tmp = 1; 2536 for (int j = 0; j < SPECIES.length(); j++) { 2537 if(mask[(i + j) % SPECIES.length()]) 2538 tmp *= a[i + j]; 2539 } 2540 res *= tmp; 2541 } 2542 2543 return res; 2544 } 2545 @Test(dataProvider = "byteUnaryOpMaskProvider") 2546 static void MULByte256VectorTestsMasked(IntFunction<byte[]> fa, IntFunction<boolean[]> fm) { 2547 byte[] a = fa.apply(SPECIES.length()); 2548 byte[] r = fr.apply(SPECIES.length()); 2549 boolean[] mask = fm.apply(SPECIES.length()); 2550 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2551 byte ra = 1; 2552 2553 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2554 for (int i = 0; i < a.length; i += SPECIES.length()) { 2555 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2556 r[i] = av.reduceLanes(VectorOperators.MUL, vmask); 2557 } 2558 } 2559 2560 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2561 ra = 1; 2562 for (int i = 0; i < a.length; i += SPECIES.length()) { 2563 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2564 ra *= av.reduceLanes(VectorOperators.MUL, vmask); 2565 } 2566 } 2567 2568 assertReductionArraysEqualsMasked(a, r, ra, mask, Byte256VectorTests::MULMasked, Byte256VectorTests::MULMasked); 2569 } 2570 static byte MIN(byte[] a, int idx) { 2571 byte res = Byte.MAX_VALUE; 2572 for (int i = idx; i < (idx + SPECIES.length()); i++) { 2573 res = (byte)Math.min(res, a[i]); 2574 } 2575 2576 return res; 2577 } 2578 2579 static byte MIN(byte[] a) { 2580 byte res = Byte.MAX_VALUE; 2581 for (int i = 0; i < a.length; i++) { 2582 res = (byte)Math.min(res, a[i]); 2583 } 2584 2585 return res; 2586 } 2587 @Test(dataProvider = "byteUnaryOpProvider") 2588 static void MINByte256VectorTests(IntFunction<byte[]> fa) { 2589 byte[] a = fa.apply(SPECIES.length()); 2590 byte[] r = fr.apply(SPECIES.length()); 2591 byte ra = Byte.MAX_VALUE; 2592 2593 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2594 for (int i = 0; i < a.length; i += SPECIES.length()) { 2595 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2596 r[i] = av.reduceLanes(VectorOperators.MIN); 2597 } 2598 } 2599 2600 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2601 ra = Byte.MAX_VALUE; 2602 for (int i = 0; i < a.length; i += SPECIES.length()) { 2603 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2604 ra = (byte)Math.min(ra, av.reduceLanes(VectorOperators.MIN)); 2605 } 2606 } 2607 2608 assertReductionArraysEquals(a, r, ra, Byte256VectorTests::MIN, Byte256VectorTests::MIN); 2609 } 2610 static byte MINMasked(byte[] a, int idx, boolean[] mask) { 2611 byte res = Byte.MAX_VALUE; 2612 for (int i = idx; i < (idx + SPECIES.length()); i++) { 2613 if(mask[i % SPECIES.length()]) 2614 res = (byte)Math.min(res, a[i]); 2615 } 2616 2617 return res; 2618 } 2619 2620 static byte MINMasked(byte[] a, boolean[] mask) { 2621 byte res = Byte.MAX_VALUE; 2622 for (int i = 0; i < a.length; i++) { 2623 if(mask[i % SPECIES.length()]) 2624 res = (byte)Math.min(res, a[i]); 2625 } 2626 2627 return res; 2628 } 2629 @Test(dataProvider = "byteUnaryOpMaskProvider") 2630 static void MINByte256VectorTestsMasked(IntFunction<byte[]> fa, IntFunction<boolean[]> fm) { 2631 byte[] a = fa.apply(SPECIES.length()); 2632 byte[] r = fr.apply(SPECIES.length()); 2633 boolean[] mask = fm.apply(SPECIES.length()); 2634 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2635 byte ra = Byte.MAX_VALUE; 2636 2637 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2638 for (int i = 0; i < a.length; i += SPECIES.length()) { 2639 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2640 r[i] = av.reduceLanes(VectorOperators.MIN, vmask); 2641 } 2642 } 2643 2644 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2645 ra = Byte.MAX_VALUE; 2646 for (int i = 0; i < a.length; i += SPECIES.length()) { 2647 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2648 ra = (byte)Math.min(ra, av.reduceLanes(VectorOperators.MIN, vmask)); 2649 } 2650 } 2651 2652 assertReductionArraysEqualsMasked(a, r, ra, mask, Byte256VectorTests::MINMasked, Byte256VectorTests::MINMasked); 2653 } 2654 static byte MAX(byte[] a, int idx) { 2655 byte res = Byte.MIN_VALUE; 2656 for (int i = idx; i < (idx + SPECIES.length()); i++) { 2657 res = (byte)Math.max(res, a[i]); 2658 } 2659 2660 return res; 2661 } 2662 2663 static byte MAX(byte[] a) { 2664 byte res = Byte.MIN_VALUE; 2665 for (int i = 0; i < a.length; i++) { 2666 res = (byte)Math.max(res, a[i]); 2667 } 2668 2669 return res; 2670 } 2671 @Test(dataProvider = "byteUnaryOpProvider") 2672 static void MAXByte256VectorTests(IntFunction<byte[]> fa) { 2673 byte[] a = fa.apply(SPECIES.length()); 2674 byte[] r = fr.apply(SPECIES.length()); 2675 byte ra = Byte.MIN_VALUE; 2676 2677 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2678 for (int i = 0; i < a.length; i += SPECIES.length()) { 2679 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2680 r[i] = av.reduceLanes(VectorOperators.MAX); 2681 } 2682 } 2683 2684 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2685 ra = Byte.MIN_VALUE; 2686 for (int i = 0; i < a.length; i += SPECIES.length()) { 2687 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2688 ra = (byte)Math.max(ra, av.reduceLanes(VectorOperators.MAX)); 2689 } 2690 } 2691 2692 assertReductionArraysEquals(a, r, ra, Byte256VectorTests::MAX, Byte256VectorTests::MAX); 2693 } 2694 static byte MAXMasked(byte[] a, int idx, boolean[] mask) { 2695 byte res = Byte.MIN_VALUE; 2696 for (int i = idx; i < (idx + SPECIES.length()); i++) { 2697 if(mask[i % SPECIES.length()]) 2698 res = (byte)Math.max(res, a[i]); 2699 } 2700 2701 return res; 2702 } 2703 2704 static byte MAXMasked(byte[] a, boolean[] mask) { 2705 byte res = Byte.MIN_VALUE; 2706 for (int i = 0; i < a.length; i++) { 2707 if(mask[i % SPECIES.length()]) 2708 res = (byte)Math.max(res, a[i]); 2709 } 2710 2711 return res; 2712 } 2713 @Test(dataProvider = "byteUnaryOpMaskProvider") 2714 static void MAXByte256VectorTestsMasked(IntFunction<byte[]> fa, IntFunction<boolean[]> fm) { 2715 byte[] a = fa.apply(SPECIES.length()); 2716 byte[] r = fr.apply(SPECIES.length()); 2717 boolean[] mask = fm.apply(SPECIES.length()); 2718 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2719 byte ra = Byte.MIN_VALUE; 2720 2721 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2722 for (int i = 0; i < a.length; i += SPECIES.length()) { 2723 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2724 r[i] = av.reduceLanes(VectorOperators.MAX, vmask); 2725 } 2726 } 2727 2728 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2729 ra = Byte.MIN_VALUE; 2730 for (int i = 0; i < a.length; i += SPECIES.length()) { 2731 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2732 ra = (byte)Math.max(ra, av.reduceLanes(VectorOperators.MAX, vmask)); 2733 } 2734 } 2735 2736 assertReductionArraysEqualsMasked(a, r, ra, mask, Byte256VectorTests::MAXMasked, Byte256VectorTests::MAXMasked); 2737 } 2738 2739 static boolean anyTrue(boolean[] a, int idx) { 2740 boolean res = false; 2741 for (int i = idx; i < (idx + SPECIES.length()); i++) { 2742 res |= a[i]; 2743 } 2744 2745 return res; 2746 } 2747 2748 2749 @Test(dataProvider = "boolUnaryOpProvider") 2750 static void anyTrueByte256VectorTests(IntFunction<boolean[]> fm) { 2751 boolean[] mask = fm.apply(SPECIES.length()); 2752 boolean[] r = fmr.apply(SPECIES.length()); 2753 2754 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2755 for (int i = 0; i < mask.length; i += SPECIES.length()) { 2756 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, i); 2757 r[i] = vmask.anyTrue(); 2758 } 2759 } 2760 2761 assertReductionBoolArraysEquals(mask, r, Byte256VectorTests::anyTrue); 2762 } 2763 2764 2765 static boolean allTrue(boolean[] a, int idx) { 2766 boolean res = true; 2767 for (int i = idx; i < (idx + SPECIES.length()); i++) { 2768 res &= a[i]; 2769 } 2770 2771 return res; 2772 } 2773 2774 2775 @Test(dataProvider = "boolUnaryOpProvider") 2776 static void allTrueByte256VectorTests(IntFunction<boolean[]> fm) { 2777 boolean[] mask = fm.apply(SPECIES.length()); 2778 boolean[] r = fmr.apply(SPECIES.length()); 2779 2780 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2781 for (int i = 0; i < mask.length; i += SPECIES.length()) { 2782 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, i); 2783 r[i] = vmask.allTrue(); 2784 } 2785 } 2786 2787 assertReductionBoolArraysEquals(mask, r, Byte256VectorTests::allTrue); 2788 } 2789 2790 2791 @Test(dataProvider = "byteUnaryOpProvider") 2792 static void withByte256VectorTests(IntFunction<byte []> fa) { 2793 byte[] a = fa.apply(SPECIES.length()); 2794 byte[] r = fr.apply(SPECIES.length()); 2795 2796 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2797 for (int i = 0; i < a.length; i += SPECIES.length()) { 2798 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2799 av.withLane(0, (byte)4).intoArray(r, i); 2800 } 2801 } 2802 2803 assertInsertArraysEquals(a, r, (byte)4, 0); 2804 } 2805 static boolean testIS_DEFAULT(byte a) { 2806 return bits(a)==0; 2807 } 2808 2809 @Test(dataProvider = "byteTestOpProvider") 2810 static void IS_DEFAULTByte256VectorTests(IntFunction<byte[]> fa) { 2811 byte[] a = fa.apply(SPECIES.length()); 2812 2813 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2814 for (int i = 0; i < a.length; i += SPECIES.length()) { 2815 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2816 VectorMask<Byte> mv = av.test(VectorOperators.IS_DEFAULT); 2817 2818 // Check results as part of computation. 2819 for (int j = 0; j < SPECIES.length(); j++) { 2820 2821 Assert.assertEquals(mv.laneIsSet(j), testIS_DEFAULT(a[i + j])); 2822 } 2823 } 2824 } 2825 } 2826 2827 static boolean testIS_NEGATIVE(byte a) { 2828 return bits(a)<0; 2829 } 2830 2831 @Test(dataProvider = "byteTestOpProvider") 2832 static void IS_NEGATIVEByte256VectorTests(IntFunction<byte[]> fa) { 2833 byte[] a = fa.apply(SPECIES.length()); 2834 2835 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2836 for (int i = 0; i < a.length; i += SPECIES.length()) { 2837 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2838 VectorMask<Byte> mv = av.test(VectorOperators.IS_NEGATIVE); 2839 2840 // Check results as part of computation. 2841 for (int j = 0; j < SPECIES.length(); j++) { 2842 2843 Assert.assertEquals(mv.laneIsSet(j), testIS_NEGATIVE(a[i + j])); 2844 } 2845 } 2846 } 2847 } 2848 2849 2850 2851 2852 2853 @Test(dataProvider = "byteCompareOpProvider") 2854 static void LTByte256VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 2855 byte[] a = fa.apply(SPECIES.length()); 2856 byte[] b = fb.apply(SPECIES.length()); 2857 2858 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2859 for (int i = 0; i < a.length; i += SPECIES.length()) { 2860 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2861 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 2862 VectorMask<Byte> mv = av.compare(VectorOperators.LT, bv); 2863 2864 // Check results as part of computation. 2865 for (int j = 0; j < SPECIES.length(); j++) { 2866 Assert.assertEquals(mv.laneIsSet(j), a[i + j] < b[i + j]); 2867 } 2868 } 2869 } 2870 } 2871 2872 2873 @Test(dataProvider = "byteCompareOpProvider") 2874 static void ltByte256VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 2875 byte[] a = fa.apply(SPECIES.length()); 2876 byte[] b = fb.apply(SPECIES.length()); 2877 2878 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2879 for (int i = 0; i < a.length; i += SPECIES.length()) { 2880 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2881 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 2882 VectorMask<Byte> mv = av.lt(bv); 2883 2884 // Check results as part of computation. 2885 for (int j = 0; j < SPECIES.length(); j++) { 2886 Assert.assertEquals(mv.laneIsSet(j), a[i + j] < b[i + j]); 2887 } 2888 } 2889 } 2890 } 2891 2892 2893 @Test(dataProvider = "byteCompareOpProvider") 2894 static void GTByte256VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 2895 byte[] a = fa.apply(SPECIES.length()); 2896 byte[] b = fb.apply(SPECIES.length()); 2897 2898 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2899 for (int i = 0; i < a.length; i += SPECIES.length()) { 2900 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2901 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 2902 VectorMask<Byte> mv = av.compare(VectorOperators.GT, bv); 2903 2904 // Check results as part of computation. 2905 for (int j = 0; j < SPECIES.length(); j++) { 2906 Assert.assertEquals(mv.laneIsSet(j), a[i + j] > b[i + j]); 2907 } 2908 } 2909 } 2910 } 2911 2912 2913 @Test(dataProvider = "byteCompareOpProvider") 2914 static void EQByte256VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 2915 byte[] a = fa.apply(SPECIES.length()); 2916 byte[] b = fb.apply(SPECIES.length()); 2917 2918 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2919 for (int i = 0; i < a.length; i += SPECIES.length()) { 2920 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2921 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 2922 VectorMask<Byte> mv = av.compare(VectorOperators.EQ, bv); 2923 2924 // Check results as part of computation. 2925 for (int j = 0; j < SPECIES.length(); j++) { 2926 Assert.assertEquals(mv.laneIsSet(j), a[i + j] == b[i + j]); 2927 } 2928 } 2929 } 2930 } 2931 2932 2933 @Test(dataProvider = "byteCompareOpProvider") 2934 static void eqByte256VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 2935 byte[] a = fa.apply(SPECIES.length()); 2936 byte[] b = fb.apply(SPECIES.length()); 2937 2938 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2939 for (int i = 0; i < a.length; i += SPECIES.length()) { 2940 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2941 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 2942 VectorMask<Byte> mv = av.eq(bv); 2943 2944 // Check results as part of computation. 2945 for (int j = 0; j < SPECIES.length(); j++) { 2946 Assert.assertEquals(mv.laneIsSet(j), a[i + j] == b[i + j]); 2947 } 2948 } 2949 } 2950 } 2951 2952 2953 @Test(dataProvider = "byteCompareOpProvider") 2954 static void NEByte256VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 2955 byte[] a = fa.apply(SPECIES.length()); 2956 byte[] b = fb.apply(SPECIES.length()); 2957 2958 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2959 for (int i = 0; i < a.length; i += SPECIES.length()) { 2960 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2961 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 2962 VectorMask<Byte> mv = av.compare(VectorOperators.NE, bv); 2963 2964 // Check results as part of computation. 2965 for (int j = 0; j < SPECIES.length(); j++) { 2966 Assert.assertEquals(mv.laneIsSet(j), a[i + j] != b[i + j]); 2967 } 2968 } 2969 } 2970 } 2971 2972 2973 @Test(dataProvider = "byteCompareOpProvider") 2974 static void LEByte256VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 2975 byte[] a = fa.apply(SPECIES.length()); 2976 byte[] b = fb.apply(SPECIES.length()); 2977 2978 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2979 for (int i = 0; i < a.length; i += SPECIES.length()) { 2980 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2981 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 2982 VectorMask<Byte> mv = av.compare(VectorOperators.LE, bv); 2983 2984 // Check results as part of computation. 2985 for (int j = 0; j < SPECIES.length(); j++) { 2986 Assert.assertEquals(mv.laneIsSet(j), a[i + j] <= b[i + j]); 2987 } 2988 } 2989 } 2990 } 2991 2992 2993 @Test(dataProvider = "byteCompareOpProvider") 2994 static void GEByte256VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 2995 byte[] a = fa.apply(SPECIES.length()); 2996 byte[] b = fb.apply(SPECIES.length()); 2997 2998 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2999 for (int i = 0; i < a.length; i += SPECIES.length()) { 3000 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 3001 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 3002 VectorMask<Byte> mv = av.compare(VectorOperators.GE, bv); 3003 3004 // Check results as part of computation. 3005 for (int j = 0; j < SPECIES.length(); j++) { 3006 Assert.assertEquals(mv.laneIsSet(j), a[i + j] >= b[i + j]); 3007 } 3008 } 3009 } 3010 } 3011 3012 3013 static byte blend(byte a, byte b, boolean mask) { 3014 return mask ? b : a; 3015 } 3016 3017 @Test(dataProvider = "byteBinaryOpMaskProvider") 3018 static void blendByte256VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 3019 IntFunction<boolean[]> fm) { 3020 byte[] a = fa.apply(SPECIES.length()); 3021 byte[] b = fb.apply(SPECIES.length()); 3022 byte[] r = fr.apply(SPECIES.length()); 3023 boolean[] mask = fm.apply(SPECIES.length()); 3024 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3025 3026 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3027 for (int i = 0; i < a.length; i += SPECIES.length()) { 3028 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 3029 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 3030 av.blend(bv, vmask).intoArray(r, i); 3031 } 3032 } 3033 3034 assertArraysEquals(a, b, r, mask, Byte256VectorTests::blend); 3035 } 3036 3037 @Test(dataProvider = "byteUnaryOpShuffleProvider") 3038 static void RearrangeByte256VectorTests(IntFunction<byte[]> fa, 3039 BiFunction<Integer,Integer,int[]> fs) { 3040 byte[] a = fa.apply(SPECIES.length()); 3041 int[] order = fs.apply(a.length, SPECIES.length()); 3042 byte[] r = fr.apply(SPECIES.length()); 3043 3044 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3045 for (int i = 0; i < a.length; i += SPECIES.length()) { 3046 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 3047 av.rearrange(VectorShuffle.fromArray(SPECIES, order, i)).intoArray(r, i); 3048 } 3049 } 3050 3051 assertRearrangeArraysEquals(a, r, order, SPECIES.length()); 3052 } 3053 3054 3055 3056 3057 @Test(dataProvider = "byteUnaryOpProvider") 3058 static void getByte256VectorTests(IntFunction<byte[]> fa) { 3059 byte[] a = fa.apply(SPECIES.length()); 3060 byte[] r = fr.apply(SPECIES.length()); 3061 3062 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3063 for (int i = 0; i < a.length; i += SPECIES.length()) { 3064 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 3065 int num_lanes = SPECIES.length(); 3066 // Manually unroll because full unroll happens after intrinsification. 3067 // Unroll is needed because get intrinsic requires for index to be a known constant. 3068 if (num_lanes == 1) { 3069 r[i]=av.lane(0); 3070 } else if (num_lanes == 2) { 3071 r[i]=av.lane(0); 3072 r[i+1]=av.lane(1); 3073 } else if (num_lanes == 4) { 3074 r[i]=av.lane(0); 3075 r[i+1]=av.lane(1); 3076 r[i+2]=av.lane(2); 3077 r[i+3]=av.lane(3); 3078 } else if (num_lanes == 8) { 3079 r[i]=av.lane(0); 3080 r[i+1]=av.lane(1); 3081 r[i+2]=av.lane(2); 3082 r[i+3]=av.lane(3); 3083 r[i+4]=av.lane(4); 3084 r[i+5]=av.lane(5); 3085 r[i+6]=av.lane(6); 3086 r[i+7]=av.lane(7); 3087 } else if (num_lanes == 16) { 3088 r[i]=av.lane(0); 3089 r[i+1]=av.lane(1); 3090 r[i+2]=av.lane(2); 3091 r[i+3]=av.lane(3); 3092 r[i+4]=av.lane(4); 3093 r[i+5]=av.lane(5); 3094 r[i+6]=av.lane(6); 3095 r[i+7]=av.lane(7); 3096 r[i+8]=av.lane(8); 3097 r[i+9]=av.lane(9); 3098 r[i+10]=av.lane(10); 3099 r[i+11]=av.lane(11); 3100 r[i+12]=av.lane(12); 3101 r[i+13]=av.lane(13); 3102 r[i+14]=av.lane(14); 3103 r[i+15]=av.lane(15); 3104 } else if (num_lanes == 32) { 3105 r[i]=av.lane(0); 3106 r[i+1]=av.lane(1); 3107 r[i+2]=av.lane(2); 3108 r[i+3]=av.lane(3); 3109 r[i+4]=av.lane(4); 3110 r[i+5]=av.lane(5); 3111 r[i+6]=av.lane(6); 3112 r[i+7]=av.lane(7); 3113 r[i+8]=av.lane(8); 3114 r[i+9]=av.lane(9); 3115 r[i+10]=av.lane(10); 3116 r[i+11]=av.lane(11); 3117 r[i+12]=av.lane(12); 3118 r[i+13]=av.lane(13); 3119 r[i+14]=av.lane(14); 3120 r[i+15]=av.lane(15); 3121 r[i+16]=av.lane(16); 3122 r[i+17]=av.lane(17); 3123 r[i+18]=av.lane(18); 3124 r[i+19]=av.lane(19); 3125 r[i+20]=av.lane(20); 3126 r[i+21]=av.lane(21); 3127 r[i+22]=av.lane(22); 3128 r[i+23]=av.lane(23); 3129 r[i+24]=av.lane(24); 3130 r[i+25]=av.lane(25); 3131 r[i+26]=av.lane(26); 3132 r[i+27]=av.lane(27); 3133 r[i+28]=av.lane(28); 3134 r[i+29]=av.lane(29); 3135 r[i+30]=av.lane(30); 3136 r[i+31]=av.lane(31); 3137 } else if (num_lanes == 64) { 3138 r[i]=av.lane(0); 3139 r[i+1]=av.lane(1); 3140 r[i+2]=av.lane(2); 3141 r[i+3]=av.lane(3); 3142 r[i+4]=av.lane(4); 3143 r[i+5]=av.lane(5); 3144 r[i+6]=av.lane(6); 3145 r[i+7]=av.lane(7); 3146 r[i+8]=av.lane(8); 3147 r[i+9]=av.lane(9); 3148 r[i+10]=av.lane(10); 3149 r[i+11]=av.lane(11); 3150 r[i+12]=av.lane(12); 3151 r[i+13]=av.lane(13); 3152 r[i+14]=av.lane(14); 3153 r[i+15]=av.lane(15); 3154 r[i+16]=av.lane(16); 3155 r[i+17]=av.lane(17); 3156 r[i+18]=av.lane(18); 3157 r[i+19]=av.lane(19); 3158 r[i+20]=av.lane(20); 3159 r[i+21]=av.lane(21); 3160 r[i+22]=av.lane(22); 3161 r[i+23]=av.lane(23); 3162 r[i+24]=av.lane(24); 3163 r[i+25]=av.lane(25); 3164 r[i+26]=av.lane(26); 3165 r[i+27]=av.lane(27); 3166 r[i+28]=av.lane(28); 3167 r[i+29]=av.lane(29); 3168 r[i+30]=av.lane(30); 3169 r[i+31]=av.lane(31); 3170 r[i+32]=av.lane(32); 3171 r[i+33]=av.lane(33); 3172 r[i+34]=av.lane(34); 3173 r[i+35]=av.lane(35); 3174 r[i+36]=av.lane(36); 3175 r[i+37]=av.lane(37); 3176 r[i+38]=av.lane(38); 3177 r[i+39]=av.lane(39); 3178 r[i+40]=av.lane(40); 3179 r[i+41]=av.lane(41); 3180 r[i+42]=av.lane(42); 3181 r[i+43]=av.lane(43); 3182 r[i+44]=av.lane(44); 3183 r[i+45]=av.lane(45); 3184 r[i+46]=av.lane(46); 3185 r[i+47]=av.lane(47); 3186 r[i+48]=av.lane(48); 3187 r[i+49]=av.lane(49); 3188 r[i+50]=av.lane(50); 3189 r[i+51]=av.lane(51); 3190 r[i+52]=av.lane(52); 3191 r[i+53]=av.lane(53); 3192 r[i+54]=av.lane(54); 3193 r[i+55]=av.lane(55); 3194 r[i+56]=av.lane(56); 3195 r[i+57]=av.lane(57); 3196 r[i+58]=av.lane(58); 3197 r[i+59]=av.lane(59); 3198 r[i+60]=av.lane(60); 3199 r[i+61]=av.lane(61); 3200 r[i+62]=av.lane(62); 3201 r[i+63]=av.lane(63); 3202 } else { 3203 for (int j = 0; j < SPECIES.length(); j++) { 3204 r[i+j]=av.lane(j); 3205 } 3206 } 3207 } 3208 } 3209 3210 assertArraysEquals(a, r, Byte256VectorTests::get); 3211 } 3212 3213 @Test(dataProvider = "byteUnaryOpProvider") 3214 static void BroadcastByte256VectorTests(IntFunction<byte[]> fa) { 3215 byte[] a = fa.apply(SPECIES.length()); 3216 byte[] r = new byte[a.length]; 3217 3218 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3219 for (int i = 0; i < a.length; i += SPECIES.length()) { 3220 ByteVector.broadcast(SPECIES, a[i]).intoArray(r, i); 3221 } 3222 } 3223 3224 assertBroadcastArraysEquals(a, r); 3225 } 3226 3227 3228 3229 3230 3231 @Test(dataProvider = "byteUnaryOpProvider") 3232 static void ZeroByte256VectorTests(IntFunction<byte[]> fa) { 3233 byte[] a = fa.apply(SPECIES.length()); 3234 byte[] r = new byte[a.length]; 3235 3236 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3237 for (int i = 0; i < a.length; i += SPECIES.length()) { 3238 ByteVector.zero(SPECIES).intoArray(a, i); 3239 } 3240 } 3241 3242 Assert.assertEquals(a, r); 3243 } 3244 3245 3246 3247 3248 static byte[] sliceUnary(byte[] a, int origin, int idx) { 3249 byte[] res = new byte[SPECIES.length()]; 3250 for (int i = 0; i < SPECIES.length(); i++){ 3251 if(i+origin < SPECIES.length()) 3252 res[i] = a[idx+i+origin]; 3253 else 3254 res[i] = (byte)0; 3255 } 3256 return res; 3257 } 3258 3259 @Test(dataProvider = "byteUnaryOpProvider") 3260 static void sliceUnaryByte256VectorTests(IntFunction<byte[]> fa) { 3261 byte[] a = fa.apply(SPECIES.length()); 3262 byte[] r = new byte[a.length]; 3263 int origin = (new java.util.Random()).nextInt(SPECIES.length()); 3264 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3265 for (int i = 0; i < a.length; i += SPECIES.length()) { 3266 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 3267 av.slice(origin).intoArray(r, i); 3268 } 3269 } 3270 3271 assertArraysEquals(a, r, origin, Byte256VectorTests::sliceUnary); 3272 } 3273 static byte[] sliceBinary(byte[] a, byte[] b, int origin, int idx) { 3274 byte[] res = new byte[SPECIES.length()]; 3275 for (int i = 0, j = 0; i < SPECIES.length(); i++){ 3276 if(i+origin < SPECIES.length()) 3277 res[i] = a[idx+i+origin]; 3278 else { 3279 res[i] = b[idx+j]; 3280 j++; 3281 } 3282 } 3283 return res; 3284 } 3285 3286 @Test(dataProvider = "byteBinaryOpProvider") 3287 static void sliceBinaryByte256VectorTestsBinary(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 3288 byte[] a = fa.apply(SPECIES.length()); 3289 byte[] b = fb.apply(SPECIES.length()); 3290 byte[] r = new byte[a.length]; 3291 int origin = (new java.util.Random()).nextInt(SPECIES.length()); 3292 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3293 for (int i = 0; i < a.length; i += SPECIES.length()) { 3294 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 3295 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 3296 av.slice(origin, bv).intoArray(r, i); 3297 } 3298 } 3299 3300 assertArraysEquals(a, b, r, origin, Byte256VectorTests::sliceBinary); 3301 } 3302 static byte[] slice(byte[] a, byte[] b, int origin, boolean[] mask, int idx) { 3303 byte[] res = new byte[SPECIES.length()]; 3304 for (int i = 0, j = 0; i < SPECIES.length(); i++){ 3305 if(i+origin < SPECIES.length()) 3306 res[i] = mask[i] ? a[idx+i+origin] : (byte)0; 3307 else { 3308 res[i] = mask[i] ? b[idx+j] : (byte)0; 3309 j++; 3310 } 3311 } 3312 return res; 3313 } 3314 3315 @Test(dataProvider = "byteBinaryOpMaskProvider") 3316 static void sliceByte256VectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 3317 IntFunction<boolean[]> fm) { 3318 byte[] a = fa.apply(SPECIES.length()); 3319 byte[] b = fb.apply(SPECIES.length()); 3320 boolean[] mask = fm.apply(SPECIES.length()); 3321 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3322 3323 byte[] r = new byte[a.length]; 3324 int origin = (new java.util.Random()).nextInt(SPECIES.length()); 3325 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3326 for (int i = 0; i < a.length; i += SPECIES.length()) { 3327 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 3328 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 3329 av.slice(origin, bv, vmask).intoArray(r, i); 3330 } 3331 } 3332 3333 assertArraysEquals(a, b, r, origin, mask, Byte256VectorTests::slice); 3334 } 3335 static byte[] unsliceUnary(byte[] a, int origin, int idx) { 3336 byte[] res = new byte[SPECIES.length()]; 3337 for (int i = 0, j = 0; i < SPECIES.length(); i++){ 3338 if(i < origin) 3339 res[i] = (byte)0; 3340 else { 3341 res[i] = a[idx+j]; 3342 j++; 3343 } 3344 } 3345 return res; 3346 } 3347 3348 @Test(dataProvider = "byteUnaryOpProvider") 3349 static void unsliceUnaryByte256VectorTests(IntFunction<byte[]> fa) { 3350 byte[] a = fa.apply(SPECIES.length()); 3351 byte[] r = new byte[a.length]; 3352 int origin = (new java.util.Random()).nextInt(SPECIES.length()); 3353 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3354 for (int i = 0; i < a.length; i += SPECIES.length()) { 3355 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 3356 av.unslice(origin).intoArray(r, i); 3357 } 3358 } 3359 3360 assertArraysEquals(a, r, origin, Byte256VectorTests::unsliceUnary); 3361 } 3362 static byte[] unsliceBinary(byte[] a, byte[] b, int origin, int part, int idx) { 3363 byte[] res = new byte[SPECIES.length()]; 3364 for (int i = 0, j = 0; i < SPECIES.length(); i++){ 3365 if (part == 0) { 3366 if (i < origin) 3367 res[i] = b[idx+i]; 3368 else { 3369 res[i] = a[idx+j]; 3370 j++; 3371 } 3372 } else if (part == 1) { 3373 if (i < origin) 3374 res[i] = a[idx+SPECIES.length()-origin+i]; 3375 else { 3376 res[i] = b[idx+origin+j]; 3377 j++; 3378 } 3379 } 3380 } 3381 return res; 3382 } 3383 3384 @Test(dataProvider = "byteBinaryOpProvider") 3385 static void unsliceBinaryByte256VectorTestsBinary(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 3386 byte[] a = fa.apply(SPECIES.length()); 3387 byte[] b = fb.apply(SPECIES.length()); 3388 byte[] r = new byte[a.length]; 3389 int origin = (new java.util.Random()).nextInt(SPECIES.length()); 3390 int part = (new java.util.Random()).nextInt(2); 3391 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3392 for (int i = 0; i < a.length; i += SPECIES.length()) { 3393 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 3394 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 3395 av.unslice(origin, bv, part).intoArray(r, i); 3396 } 3397 } 3398 3399 assertArraysEquals(a, b, r, origin, part, Byte256VectorTests::unsliceBinary); 3400 } 3401 static byte[] unslice(byte[] a, byte[] b, int origin, int part, boolean[] mask, int idx) { 3402 byte[] res = new byte[SPECIES.length()]; 3403 for (int i = 0, j = 0; i < SPECIES.length(); i++){ 3404 if(i+origin < SPECIES.length()) 3405 res[i] = b[idx+i+origin]; 3406 else { 3407 res[i] = b[idx+j]; 3408 j++; 3409 } 3410 } 3411 for (int i = 0; i < SPECIES.length(); i++){ 3412 res[i] = mask[i] ? a[idx+i] : res[i]; 3413 } 3414 byte[] res1 = new byte[SPECIES.length()]; 3415 if (part == 0) { 3416 for (int i = 0, j = 0; i < SPECIES.length(); i++){ 3417 if (i < origin) 3418 res1[i] = b[idx+i]; 3419 else { 3420 res1[i] = res[j]; 3421 j++; 3422 } 3423 } 3424 } else if (part == 1) { 3425 for (int i = 0, j = 0; i < SPECIES.length(); i++){ 3426 if (i < origin) 3427 res1[i] = res[SPECIES.length()-origin+i]; 3428 else { 3429 res1[i] = b[idx+origin+j]; 3430 j++; 3431 } 3432 } 3433 } 3434 return res1; 3435 } 3436 3437 @Test(dataProvider = "byteBinaryOpMaskProvider") 3438 static void unsliceByte256VectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 3439 IntFunction<boolean[]> fm) { 3440 byte[] a = fa.apply(SPECIES.length()); 3441 byte[] b = fb.apply(SPECIES.length()); 3442 boolean[] mask = fm.apply(SPECIES.length()); 3443 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3444 byte[] r = new byte[a.length]; 3445 int origin = (new java.util.Random()).nextInt(SPECIES.length()); 3446 int part = (new java.util.Random()).nextInt(2); 3447 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3448 for (int i = 0; i < a.length; i += SPECIES.length()) { 3449 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 3450 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 3451 av.unslice(origin, bv, part, vmask).intoArray(r, i); 3452 } 3453 } 3454 3455 assertArraysEquals(a, b, r, origin, part, mask, Byte256VectorTests::unslice); 3456 } 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 static byte BITWISE_BLEND(byte a, byte b, byte c) { 3480 return (byte)((a&~(c))|(b&c)); 3481 } 3482 3483 3484 @Test(dataProvider = "byteTernaryOpProvider") 3485 static void BITWISE_BLENDByte256VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb, IntFunction<byte[]> fc) { 3486 byte[] a = fa.apply(SPECIES.length()); 3487 byte[] b = fb.apply(SPECIES.length()); 3488 byte[] c = fc.apply(SPECIES.length()); 3489 byte[] r = fr.apply(SPECIES.length()); 3490 3491 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3492 for (int i = 0; i < a.length; i += SPECIES.length()) { 3493 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 3494 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 3495 ByteVector cv = ByteVector.fromArray(SPECIES, c, i); 3496 av.lanewise(VectorOperators.BITWISE_BLEND, bv, cv).intoArray(r, i); 3497 } 3498 } 3499 3500 assertArraysEquals(a, b, c, r, Byte256VectorTests::BITWISE_BLEND); 3501 } 3502 3503 3504 @Test(dataProvider = "byteTernaryOpMaskProvider") 3505 static void BITWISE_BLENDByte256VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 3506 IntFunction<byte[]> fc, IntFunction<boolean[]> fm) { 3507 byte[] a = fa.apply(SPECIES.length()); 3508 byte[] b = fb.apply(SPECIES.length()); 3509 byte[] c = fc.apply(SPECIES.length()); 3510 byte[] r = fr.apply(SPECIES.length()); 3511 boolean[] mask = fm.apply(SPECIES.length()); 3512 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3513 3514 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3515 for (int i = 0; i < a.length; i += SPECIES.length()) { 3516 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 3517 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 3518 ByteVector cv = ByteVector.fromArray(SPECIES, c, i); 3519 av.lanewise(VectorOperators.BITWISE_BLEND, bv, cv, vmask).intoArray(r, i); 3520 } 3521 } 3522 3523 assertArraysEquals(a, b, c, r, mask, Byte256VectorTests::BITWISE_BLEND); 3524 } 3525 3526 3527 static byte NEG(byte a) { 3528 return (byte)(-((byte)a)); 3529 } 3530 3531 static byte neg(byte a) { 3532 return (byte)(-((byte)a)); 3533 } 3534 3535 @Test(dataProvider = "byteUnaryOpProvider") 3536 static void NEGByte256VectorTests(IntFunction<byte[]> fa) { 3537 byte[] a = fa.apply(SPECIES.length()); 3538 byte[] r = fr.apply(SPECIES.length()); 3539 3540 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3541 for (int i = 0; i < a.length; i += SPECIES.length()) { 3542 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 3543 av.lanewise(VectorOperators.NEG).intoArray(r, i); 3544 } 3545 } 3546 3547 assertArraysEquals(a, r, Byte256VectorTests::NEG); 3548 } 3549 3550 @Test(dataProvider = "byteUnaryOpProvider") 3551 static void negByte256VectorTests(IntFunction<byte[]> fa) { 3552 byte[] a = fa.apply(SPECIES.length()); 3553 byte[] r = fr.apply(SPECIES.length()); 3554 3555 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3556 for (int i = 0; i < a.length; i += SPECIES.length()) { 3557 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 3558 av.neg().intoArray(r, i); 3559 } 3560 } 3561 3562 assertArraysEquals(a, r, Byte256VectorTests::neg); 3563 } 3564 3565 @Test(dataProvider = "byteUnaryOpMaskProvider") 3566 static void NEGMaskedByte256VectorTests(IntFunction<byte[]> fa, 3567 IntFunction<boolean[]> fm) { 3568 byte[] a = fa.apply(SPECIES.length()); 3569 byte[] r = fr.apply(SPECIES.length()); 3570 boolean[] mask = fm.apply(SPECIES.length()); 3571 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3572 3573 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3574 for (int i = 0; i < a.length; i += SPECIES.length()) { 3575 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 3576 av.lanewise(VectorOperators.NEG, vmask).intoArray(r, i); 3577 } 3578 } 3579 3580 assertArraysEquals(a, r, mask, Byte256VectorTests::NEG); 3581 } 3582 3583 static byte ABS(byte a) { 3584 return (byte)(Math.abs((byte)a)); 3585 } 3586 3587 static byte abs(byte a) { 3588 return (byte)(Math.abs((byte)a)); 3589 } 3590 3591 @Test(dataProvider = "byteUnaryOpProvider") 3592 static void ABSByte256VectorTests(IntFunction<byte[]> fa) { 3593 byte[] a = fa.apply(SPECIES.length()); 3594 byte[] r = fr.apply(SPECIES.length()); 3595 3596 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3597 for (int i = 0; i < a.length; i += SPECIES.length()) { 3598 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 3599 av.lanewise(VectorOperators.ABS).intoArray(r, i); 3600 } 3601 } 3602 3603 assertArraysEquals(a, r, Byte256VectorTests::ABS); 3604 } 3605 3606 @Test(dataProvider = "byteUnaryOpProvider") 3607 static void absByte256VectorTests(IntFunction<byte[]> fa) { 3608 byte[] a = fa.apply(SPECIES.length()); 3609 byte[] r = fr.apply(SPECIES.length()); 3610 3611 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3612 for (int i = 0; i < a.length; i += SPECIES.length()) { 3613 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 3614 av.abs().intoArray(r, i); 3615 } 3616 } 3617 3618 assertArraysEquals(a, r, Byte256VectorTests::abs); 3619 } 3620 3621 @Test(dataProvider = "byteUnaryOpMaskProvider") 3622 static void ABSMaskedByte256VectorTests(IntFunction<byte[]> fa, 3623 IntFunction<boolean[]> fm) { 3624 byte[] a = fa.apply(SPECIES.length()); 3625 byte[] r = fr.apply(SPECIES.length()); 3626 boolean[] mask = fm.apply(SPECIES.length()); 3627 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3628 3629 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3630 for (int i = 0; i < a.length; i += SPECIES.length()) { 3631 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 3632 av.lanewise(VectorOperators.ABS, vmask).intoArray(r, i); 3633 } 3634 } 3635 3636 assertArraysEquals(a, r, mask, Byte256VectorTests::ABS); 3637 } 3638 3639 3640 static byte NOT(byte a) { 3641 return (byte)(~((byte)a)); 3642 } 3643 3644 static byte not(byte a) { 3645 return (byte)(~((byte)a)); 3646 } 3647 3648 3649 3650 @Test(dataProvider = "byteUnaryOpProvider") 3651 static void NOTByte256VectorTests(IntFunction<byte[]> fa) { 3652 byte[] a = fa.apply(SPECIES.length()); 3653 byte[] r = fr.apply(SPECIES.length()); 3654 3655 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3656 for (int i = 0; i < a.length; i += SPECIES.length()) { 3657 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 3658 av.lanewise(VectorOperators.NOT).intoArray(r, i); 3659 } 3660 } 3661 3662 assertArraysEquals(a, r, Byte256VectorTests::NOT); 3663 } 3664 3665 @Test(dataProvider = "byteUnaryOpProvider") 3666 static void notByte256VectorTests(IntFunction<byte[]> fa) { 3667 byte[] a = fa.apply(SPECIES.length()); 3668 byte[] r = fr.apply(SPECIES.length()); 3669 3670 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3671 for (int i = 0; i < a.length; i += SPECIES.length()) { 3672 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 3673 av.not().intoArray(r, i); 3674 } 3675 } 3676 3677 assertArraysEquals(a, r, Byte256VectorTests::not); 3678 } 3679 3680 3681 3682 @Test(dataProvider = "byteUnaryOpMaskProvider") 3683 static void NOTMaskedByte256VectorTests(IntFunction<byte[]> fa, 3684 IntFunction<boolean[]> fm) { 3685 byte[] a = fa.apply(SPECIES.length()); 3686 byte[] r = fr.apply(SPECIES.length()); 3687 boolean[] mask = fm.apply(SPECIES.length()); 3688 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3689 3690 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3691 for (int i = 0; i < a.length; i += SPECIES.length()) { 3692 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 3693 av.lanewise(VectorOperators.NOT, vmask).intoArray(r, i); 3694 } 3695 } 3696 3697 assertArraysEquals(a, r, mask, Byte256VectorTests::NOT); 3698 } 3699 3700 3701 3702 static byte ZOMO(byte a) { 3703 return (byte)((a==0?0:-1)); 3704 } 3705 3706 3707 3708 @Test(dataProvider = "byteUnaryOpProvider") 3709 static void ZOMOByte256VectorTests(IntFunction<byte[]> fa) { 3710 byte[] a = fa.apply(SPECIES.length()); 3711 byte[] r = fr.apply(SPECIES.length()); 3712 3713 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3714 for (int i = 0; i < a.length; i += SPECIES.length()) { 3715 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 3716 av.lanewise(VectorOperators.ZOMO).intoArray(r, i); 3717 } 3718 } 3719 3720 assertArraysEquals(a, r, Byte256VectorTests::ZOMO); 3721 } 3722 3723 3724 3725 @Test(dataProvider = "byteUnaryOpMaskProvider") 3726 static void ZOMOMaskedByte256VectorTests(IntFunction<byte[]> fa, 3727 IntFunction<boolean[]> fm) { 3728 byte[] a = fa.apply(SPECIES.length()); 3729 byte[] r = fr.apply(SPECIES.length()); 3730 boolean[] mask = fm.apply(SPECIES.length()); 3731 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3732 3733 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3734 for (int i = 0; i < a.length; i += SPECIES.length()) { 3735 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 3736 av.lanewise(VectorOperators.ZOMO, vmask).intoArray(r, i); 3737 } 3738 } 3739 3740 assertArraysEquals(a, r, mask, Byte256VectorTests::ZOMO); 3741 } 3742 3743 3744 3745 3746 static byte[] gather(byte a[], int ix, int[] b, int iy) { 3747 byte[] res = new byte[SPECIES.length()]; 3748 for (int i = 0; i < SPECIES.length(); i++) { 3749 int bi = iy + i; 3750 res[i] = a[b[bi] + ix]; 3751 } 3752 return res; 3753 } 3754 3755 @Test(dataProvider = "byteUnaryOpIndexProvider") 3756 static void gatherByte256VectorTests(IntFunction<byte[]> fa, BiFunction<Integer,Integer,int[]> fs) { 3757 byte[] a = fa.apply(SPECIES.length()); 3758 int[] b = fs.apply(a.length, SPECIES.length()); 3759 byte[] r = new byte[a.length]; 3760 3761 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3762 for (int i = 0; i < a.length; i += SPECIES.length()) { 3763 ByteVector av = ByteVector.fromArray(SPECIES, a, i, b, i); 3764 av.intoArray(r, i); 3765 } 3766 } 3767 3768 assertArraysEquals(a, b, r, Byte256VectorTests::gather); 3769 } 3770 static byte[] gatherMasked(byte a[], int ix, boolean[] mask, int[] b, int iy) { 3771 byte[] res = new byte[SPECIES.length()]; 3772 for (int i = 0; i < SPECIES.length(); i++) { 3773 int bi = iy + i; 3774 if (mask[i]) { 3775 res[i] = a[b[bi] + ix]; 3776 } 3777 } 3778 return res; 3779 } 3780 3781 @Test(dataProvider = "byteUnaryMaskedOpIndexProvider") 3782 static void gatherMaskedByte256VectorTests(IntFunction<byte[]> fa, BiFunction<Integer,Integer,int[]> fs, IntFunction<boolean[]> fm) { 3783 byte[] a = fa.apply(SPECIES.length()); 3784 int[] b = fs.apply(a.length, SPECIES.length()); 3785 byte[] r = new byte[a.length]; 3786 boolean[] mask = fm.apply(SPECIES.length()); 3787 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3788 3789 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3790 for (int i = 0; i < a.length; i += SPECIES.length()) { 3791 ByteVector av = ByteVector.fromArray(SPECIES, a, i, b, i, vmask); 3792 av.intoArray(r, i); 3793 } 3794 } 3795 3796 assertArraysEquals(a, b, r, mask, Byte256VectorTests::gatherMasked); 3797 } 3798 3799 static byte[] scatter(byte a[], int ix, int[] b, int iy) { 3800 byte[] res = new byte[SPECIES.length()]; 3801 for (int i = 0; i < SPECIES.length(); i++) { 3802 int bi = iy + i; 3803 res[b[bi]] = a[i + ix]; 3804 } 3805 return res; 3806 } 3807 3808 @Test(dataProvider = "byteUnaryOpIndexProvider") 3809 static void scatterByte256VectorTests(IntFunction<byte[]> fa, BiFunction<Integer,Integer,int[]> fs) { 3810 byte[] a = fa.apply(SPECIES.length()); 3811 int[] b = fs.apply(a.length, SPECIES.length()); 3812 byte[] r = new byte[a.length]; 3813 3814 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3815 for (int i = 0; i < a.length; i += SPECIES.length()) { 3816 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 3817 av.intoArray(r, i, b, i); 3818 } 3819 } 3820 3821 assertArraysEquals(a, b, r, Byte256VectorTests::scatter); 3822 } 3823 3824 static byte[] scatterMasked(byte r[], byte a[], int ix, boolean[] mask, int[] b, int iy) { 3825 // First, gather r. 3826 byte[] oldVal = gather(r, ix, b, iy); 3827 byte[] newVal = new byte[SPECIES.length()]; 3828 3829 // Second, blending it with a. 3830 for (int i = 0; i < SPECIES.length(); i++) { 3831 newVal[i] = blend(oldVal[i], a[i+ix], mask[i]); 3832 } 3833 3834 // Third, scatter: copy old value of r, and scatter it manually. 3835 byte[] res = Arrays.copyOfRange(r, ix, ix+SPECIES.length()); 3836 for (int i = 0; i < SPECIES.length(); i++) { 3837 int bi = iy + i; 3838 res[b[bi]] = newVal[i]; 3839 } 3840 3841 return res; 3842 } 3843 3844 @Test(dataProvider = "scatterMaskedOpIndexProvider") 3845 static void scatterMaskedByte256VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb, BiFunction<Integer,Integer,int[]> fs, IntFunction<boolean[]> fm) { 3846 byte[] a = fa.apply(SPECIES.length()); 3847 int[] b = fs.apply(a.length, SPECIES.length()); 3848 byte[] r = fb.apply(SPECIES.length()); 3849 boolean[] mask = fm.apply(SPECIES.length()); 3850 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3851 3852 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3853 for (int i = 0; i < a.length; i += SPECIES.length()) { 3854 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 3855 av.intoArray(r, i, b, i, vmask); 3856 } 3857 } 3858 3859 assertArraysEquals(a, b, r, mask, Byte256VectorTests::scatterMasked); 3860 } 3861 3862 } 3863