1 /* 2 * Copyright (c) 2018, 2022, 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 -XX:-TieredCompilation ByteMaxVectorTests 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.Objects; 51 import java.util.stream.Collectors; 52 import java.util.stream.Stream; 53 54 @Test 55 public class ByteMaxVectorTests extends AbstractVectorTest { 56 57 static final VectorSpecies<Byte> SPECIES = 58 ByteVector.SPECIES_MAX; 59 60 static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100); 61 62 static VectorShape getMaxBit() { 63 return VectorShape.S_Max_BIT; 64 } 65 66 private static final int Max = 256; // juts so we can do N/Max 67 68 private static final byte CONST_SHIFT = Byte.SIZE / 2; 69 70 static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / Max); 71 72 interface FUnOp { 73 byte apply(byte a); 74 } 75 76 static void assertArraysEquals(byte[] r, byte[] a, FUnOp f) { 77 int i = 0; 78 try { 79 for (; i < a.length; i++) { 80 Assert.assertEquals(r[i], f.apply(a[i])); 81 } 82 } catch (AssertionError e) { 83 Assert.assertEquals(r[i], f.apply(a[i]), "at index #" + i + ", input = " + a[i]); 84 } 85 } 86 87 interface FUnArrayOp { 88 byte[] apply(byte a); 89 } 90 91 static void assertArraysEquals(byte[] r, byte[] a, FUnArrayOp f) { 92 int i = 0; 93 try { 94 for (; i < a.length; i += SPECIES.length()) { 95 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()), 96 f.apply(a[i])); 97 } 98 } catch (AssertionError e) { 99 byte[] ref = f.apply(a[i]); 100 byte[] res = Arrays.copyOfRange(r, i, i+SPECIES.length()); 101 Assert.assertEquals(res, ref, "(ref: " + Arrays.toString(ref) 102 + ", res: " + Arrays.toString(res) 103 + "), at index #" + i); 104 } 105 } 106 107 static void assertArraysEquals(byte[] r, byte[] a, boolean[] mask, FUnOp f) { 108 int i = 0; 109 try { 110 for (; i < a.length; i++) { 111 Assert.assertEquals(r[i], mask[i % SPECIES.length()] ? f.apply(a[i]) : a[i]); 112 } 113 } catch (AssertionError e) { 114 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()]); 115 } 116 } 117 118 interface FReductionOp { 119 byte apply(byte[] a, int idx); 120 } 121 122 interface FReductionAllOp { 123 byte apply(byte[] a); 124 } 125 126 static void assertReductionArraysEquals(byte[] r, byte rc, byte[] a, 127 FReductionOp f, FReductionAllOp fa) { 128 int i = 0; 129 try { 130 Assert.assertEquals(rc, fa.apply(a)); 131 for (; i < a.length; i += SPECIES.length()) { 132 Assert.assertEquals(r[i], f.apply(a, i)); 133 } 134 } catch (AssertionError e) { 135 Assert.assertEquals(rc, fa.apply(a), "Final result is incorrect!"); 136 Assert.assertEquals(r[i], f.apply(a, i), "at index #" + i); 137 } 138 } 139 140 interface FReductionMaskedOp { 141 byte apply(byte[] a, int idx, boolean[] mask); 142 } 143 144 interface FReductionAllMaskedOp { 145 byte apply(byte[] a, boolean[] mask); 146 } 147 148 static void assertReductionArraysEqualsMasked(byte[] r, byte rc, byte[] a, boolean[] mask, 149 FReductionMaskedOp f, FReductionAllMaskedOp fa) { 150 int i = 0; 151 try { 152 Assert.assertEquals(rc, fa.apply(a, mask)); 153 for (; i < a.length; i += SPECIES.length()) { 154 Assert.assertEquals(r[i], f.apply(a, i, mask)); 155 } 156 } catch (AssertionError e) { 157 Assert.assertEquals(rc, fa.apply(a, mask), "Final result is incorrect!"); 158 Assert.assertEquals(r[i], f.apply(a, i, mask), "at index #" + i); 159 } 160 } 161 162 interface FReductionOpLong { 163 long apply(byte[] a, int idx); 164 } 165 166 interface FReductionAllOpLong { 167 long apply(byte[] a); 168 } 169 170 static void assertReductionLongArraysEquals(long[] r, long rc, byte[] a, 171 FReductionOpLong f, FReductionAllOpLong fa) { 172 int i = 0; 173 try { 174 Assert.assertEquals(rc, fa.apply(a)); 175 for (; i < a.length; i += SPECIES.length()) { 176 Assert.assertEquals(r[i], f.apply(a, i)); 177 } 178 } catch (AssertionError e) { 179 Assert.assertEquals(rc, fa.apply(a), "Final result is incorrect!"); 180 Assert.assertEquals(r[i], f.apply(a, i), "at index #" + i); 181 } 182 } 183 184 interface FReductionMaskedOpLong { 185 long apply(byte[] a, int idx, boolean[] mask); 186 } 187 188 interface FReductionAllMaskedOpLong { 189 long apply(byte[] a, boolean[] mask); 190 } 191 192 static void assertReductionLongArraysEqualsMasked(long[] r, long rc, byte[] a, boolean[] mask, 193 FReductionMaskedOpLong f, FReductionAllMaskedOpLong fa) { 194 int i = 0; 195 try { 196 Assert.assertEquals(rc, fa.apply(a, mask)); 197 for (; i < a.length; i += SPECIES.length()) { 198 Assert.assertEquals(r[i], f.apply(a, i, mask)); 199 } 200 } catch (AssertionError e) { 201 Assert.assertEquals(rc, fa.apply(a, mask), "Final result is incorrect!"); 202 Assert.assertEquals(r[i], f.apply(a, i, mask), "at index #" + i); 203 } 204 } 205 206 interface FBoolReductionOp { 207 boolean apply(boolean[] a, int idx); 208 } 209 210 static void assertReductionBoolArraysEquals(boolean[] r, boolean[] a, FBoolReductionOp f) { 211 int i = 0; 212 try { 213 for (; i < a.length; i += SPECIES.length()) { 214 Assert.assertEquals(r[i], f.apply(a, i)); 215 } 216 } catch (AssertionError e) { 217 Assert.assertEquals(r[i], f.apply(a, i), "at index #" + i); 218 } 219 } 220 221 interface FMaskReductionOp { 222 int apply(boolean[] a, int idx); 223 } 224 225 static void assertMaskReductionArraysEquals(int[] r, boolean[] a, FMaskReductionOp f) { 226 int i = 0; 227 try { 228 for (; i < a.length; i += SPECIES.length()) { 229 Assert.assertEquals(r[i], f.apply(a, i)); 230 } 231 } catch (AssertionError e) { 232 Assert.assertEquals(r[i], f.apply(a, i), "at index #" + i); 233 } 234 } 235 236 static void assertInsertArraysEquals(byte[] r, byte[] a, byte element, int index, int start, int end) { 237 int i = start; 238 try { 239 for (; i < end; i += 1) { 240 if(i%SPECIES.length() == index) { 241 Assert.assertEquals(r[i], element); 242 } else { 243 Assert.assertEquals(r[i], a[i]); 244 } 245 } 246 } catch (AssertionError e) { 247 if (i%SPECIES.length() == index) { 248 Assert.assertEquals(r[i], element, "at index #" + i); 249 } else { 250 Assert.assertEquals(r[i], a[i], "at index #" + i); 251 } 252 } 253 } 254 255 static void assertRearrangeArraysEquals(byte[] r, byte[] a, int[] order, int vector_len) { 256 int i = 0, j = 0; 257 try { 258 for (; i < a.length; i += vector_len) { 259 for (j = 0; j < vector_len; j++) { 260 Assert.assertEquals(r[i+j], a[i+order[i+j]]); 261 } 262 } 263 } catch (AssertionError e) { 264 int idx = i + j; 265 Assert.assertEquals(r[i+j], a[i+order[i+j]], "at index #" + idx + ", input = " + a[i+order[i+j]]); 266 } 267 } 268 269 static void assertcompressArraysEquals(byte[] r, byte[] a, boolean[] m, int vector_len) { 270 int i = 0, j = 0, k = 0; 271 try { 272 for (; i < a.length; i += vector_len) { 273 k = 0; 274 for (j = 0; j < vector_len; j++) { 275 if (m[(i + j) % SPECIES.length()]) { 276 Assert.assertEquals(r[i + k], a[i + j]); 277 k++; 278 } 279 } 280 for (; k < vector_len; k++) { 281 Assert.assertEquals(r[i + k], (byte)0); 282 } 283 } 284 } catch (AssertionError e) { 285 int idx = i + k; 286 if (m[(i + j) % SPECIES.length()]) { 287 Assert.assertEquals(r[idx], a[i + j], "at index #" + idx); 288 } else { 289 Assert.assertEquals(r[idx], (byte)0, "at index #" + idx); 290 } 291 } 292 } 293 294 static void assertexpandArraysEquals(byte[] r, byte[] a, boolean[] m, int vector_len) { 295 int i = 0, j = 0, k = 0; 296 try { 297 for (; i < a.length; i += vector_len) { 298 k = 0; 299 for (j = 0; j < vector_len; j++) { 300 if (m[(i + j) % SPECIES.length()]) { 301 Assert.assertEquals(r[i + j], a[i + k]); 302 k++; 303 } else { 304 Assert.assertEquals(r[i + j], (byte)0); 305 } 306 } 307 } 308 } catch (AssertionError e) { 309 int idx = i + j; 310 if (m[idx % SPECIES.length()]) { 311 Assert.assertEquals(r[idx], a[i + k], "at index #" + idx); 312 } else { 313 Assert.assertEquals(r[idx], (byte)0, "at index #" + idx); 314 } 315 } 316 } 317 318 static void assertSelectFromArraysEquals(byte[] r, byte[] a, byte[] order, int vector_len) { 319 int i = 0, j = 0; 320 try { 321 for (; i < a.length; i += vector_len) { 322 for (j = 0; j < vector_len; j++) { 323 Assert.assertEquals(r[i+j], a[i+(int)order[i+j]]); 324 } 325 } 326 } catch (AssertionError e) { 327 int idx = i + j; 328 Assert.assertEquals(r[i+j], a[i+(int)order[i+j]], "at index #" + idx + ", input = " + a[i+(int)order[i+j]]); 329 } 330 } 331 332 static void assertRearrangeArraysEquals(byte[] r, byte[] a, int[] order, boolean[] mask, int vector_len) { 333 int i = 0, j = 0; 334 try { 335 for (; i < a.length; i += vector_len) { 336 for (j = 0; j < vector_len; j++) { 337 if (mask[j % SPECIES.length()]) 338 Assert.assertEquals(r[i+j], a[i+order[i+j]]); 339 else 340 Assert.assertEquals(r[i+j], (byte)0); 341 } 342 } 343 } catch (AssertionError e) { 344 int idx = i + j; 345 if (mask[j % SPECIES.length()]) 346 Assert.assertEquals(r[i+j], a[i+order[i+j]], "at index #" + idx + ", input = " + a[i+order[i+j]] + ", mask = " + mask[j % SPECIES.length()]); 347 else 348 Assert.assertEquals(r[i+j], (byte)0, "at index #" + idx + ", input = " + a[i+order[i+j]] + ", mask = " + mask[j % SPECIES.length()]); 349 } 350 } 351 352 static void assertSelectFromArraysEquals(byte[] r, byte[] a, byte[] order, boolean[] mask, int vector_len) { 353 int i = 0, j = 0; 354 try { 355 for (; i < a.length; i += vector_len) { 356 for (j = 0; j < vector_len; j++) { 357 if (mask[j % SPECIES.length()]) 358 Assert.assertEquals(r[i+j], a[i+(int)order[i+j]]); 359 else 360 Assert.assertEquals(r[i+j], (byte)0); 361 } 362 } 363 } catch (AssertionError e) { 364 int idx = i + j; 365 if (mask[j % SPECIES.length()]) 366 Assert.assertEquals(r[i+j], a[i+(int)order[i+j]], "at index #" + idx + ", input = " + a[i+(int)order[i+j]] + ", mask = " + mask[j % SPECIES.length()]); 367 else 368 Assert.assertEquals(r[i+j], (byte)0, "at index #" + idx + ", input = " + a[i+(int)order[i+j]] + ", mask = " + mask[j % SPECIES.length()]); 369 } 370 } 371 372 static void assertBroadcastArraysEquals(byte[] r, byte[] a) { 373 int i = 0; 374 for (; i < a.length; i += SPECIES.length()) { 375 int idx = i; 376 for (int j = idx; j < (idx + SPECIES.length()); j++) 377 a[j]=a[idx]; 378 } 379 380 try { 381 for (i = 0; i < a.length; i++) { 382 Assert.assertEquals(r[i], a[i]); 383 } 384 } catch (AssertionError e) { 385 Assert.assertEquals(r[i], a[i], "at index #" + i + ", input = " + a[i]); 386 } 387 } 388 389 interface FBinOp { 390 byte apply(byte a, byte b); 391 } 392 393 interface FBinMaskOp { 394 byte apply(byte a, byte b, boolean m); 395 396 static FBinMaskOp lift(FBinOp f) { 397 return (a, b, m) -> m ? f.apply(a, b) : a; 398 } 399 } 400 401 static void assertArraysEquals(byte[] r, byte[] a, byte[] b, FBinOp f) { 402 int i = 0; 403 try { 404 for (; i < a.length; i++) { 405 Assert.assertEquals(r[i], f.apply(a[i], b[i])); 406 } 407 } catch (AssertionError e) { 408 Assert.assertEquals(r[i], f.apply(a[i], b[i]), "(" + a[i] + ", " + b[i] + ") at index #" + i); 409 } 410 } 411 412 static void assertBroadcastArraysEquals(byte[] r, byte[] a, byte[] b, FBinOp f) { 413 int i = 0; 414 try { 415 for (; i < a.length; i++) { 416 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()])); 417 } 418 } catch (AssertionError e) { 419 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()]), 420 "(" + a[i] + ", " + b[(i / SPECIES.length()) * SPECIES.length()] + ") at index #" + i); 421 } 422 } 423 424 static void assertBroadcastLongArraysEquals(byte[] r, byte[] a, byte[] b, FBinOp f) { 425 int i = 0; 426 try { 427 for (; i < a.length; i++) { 428 Assert.assertEquals(r[i], f.apply(a[i], (byte)((long)b[(i / SPECIES.length()) * SPECIES.length()]))); 429 } 430 } catch (AssertionError e) { 431 Assert.assertEquals(r[i], f.apply(a[i], (byte)((long)b[(i / SPECIES.length()) * SPECIES.length()])), 432 "(" + a[i] + ", " + b[(i / SPECIES.length()) * SPECIES.length()] + ") at index #" + i); 433 } 434 } 435 436 static void assertArraysEquals(byte[] r, byte[] a, byte[] b, boolean[] mask, FBinOp f) { 437 assertArraysEquals(r, a, b, mask, FBinMaskOp.lift(f)); 438 } 439 440 static void assertArraysEquals(byte[] r, byte[] a, byte[] b, boolean[] mask, FBinMaskOp f) { 441 int i = 0; 442 try { 443 for (; i < a.length; i++) { 444 Assert.assertEquals(r[i], f.apply(a[i], b[i], mask[i % SPECIES.length()])); 445 } 446 } catch (AssertionError err) { 447 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()]); 448 } 449 } 450 451 static void assertBroadcastArraysEquals(byte[] r, byte[] a, byte[] b, boolean[] mask, FBinOp f) { 452 assertBroadcastArraysEquals(r, a, b, mask, FBinMaskOp.lift(f)); 453 } 454 455 static void assertBroadcastArraysEquals(byte[] r, byte[] a, byte[] b, boolean[] mask, FBinMaskOp f) { 456 int i = 0; 457 try { 458 for (; i < a.length; i++) { 459 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], mask[i % SPECIES.length()])); 460 } 461 } catch (AssertionError err) { 462 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], 463 mask[i % SPECIES.length()]), "at index #" + i + ", input1 = " + a[i] + 464 ", input2 = " + b[(i / SPECIES.length()) * SPECIES.length()] + ", mask = " + 465 mask[i % SPECIES.length()]); 466 } 467 } 468 469 static void assertBroadcastLongArraysEquals(byte[] r, byte[] a, byte[] b, boolean[] mask, FBinOp f) { 470 assertBroadcastLongArraysEquals(r, a, b, mask, FBinMaskOp.lift(f)); 471 } 472 473 static void assertBroadcastLongArraysEquals(byte[] r, byte[] a, byte[] b, boolean[] mask, FBinMaskOp f) { 474 int i = 0; 475 try { 476 for (; i < a.length; i++) { 477 Assert.assertEquals(r[i], f.apply(a[i], (byte)((long)b[(i / SPECIES.length()) * SPECIES.length()]), mask[i % SPECIES.length()])); 478 } 479 } catch (AssertionError err) { 480 Assert.assertEquals(r[i], f.apply(a[i], (byte)((long)b[(i / SPECIES.length()) * SPECIES.length()]), 481 mask[i % SPECIES.length()]), "at index #" + i + ", input1 = " + a[i] + 482 ", input2 = " + b[(i / SPECIES.length()) * SPECIES.length()] + ", mask = " + 483 mask[i % SPECIES.length()]); 484 } 485 } 486 487 static void assertShiftArraysEquals(byte[] r, byte[] a, byte[] b, FBinOp f) { 488 int i = 0; 489 int j = 0; 490 try { 491 for (; j < a.length; j += SPECIES.length()) { 492 for (i = 0; i < SPECIES.length(); i++) { 493 Assert.assertEquals(r[i+j], f.apply(a[i+j], b[j])); 494 } 495 } 496 } catch (AssertionError e) { 497 Assert.assertEquals(r[i+j], f.apply(a[i+j], b[j]), "at index #" + i + ", " + j); 498 } 499 } 500 501 static void assertShiftArraysEquals(byte[] r, byte[] a, byte[] b, boolean[] mask, FBinOp f) { 502 assertShiftArraysEquals(r, a, b, mask, FBinMaskOp.lift(f)); 503 } 504 505 static void assertShiftArraysEquals(byte[] r, byte[] a, byte[] b, boolean[] mask, FBinMaskOp f) { 506 int i = 0; 507 int j = 0; 508 try { 509 for (; j < a.length; j += SPECIES.length()) { 510 for (i = 0; i < SPECIES.length(); i++) { 511 Assert.assertEquals(r[i+j], f.apply(a[i+j], b[j], mask[i])); 512 } 513 } 514 } catch (AssertionError err) { 515 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]); 516 } 517 } 518 519 interface FBinConstOp { 520 byte apply(byte a); 521 } 522 523 interface FBinConstMaskOp { 524 byte apply(byte a, boolean m); 525 526 static FBinConstMaskOp lift(FBinConstOp f) { 527 return (a, m) -> m ? f.apply(a) : a; 528 } 529 } 530 531 static void assertShiftConstEquals(byte[] r, byte[] a, FBinConstOp f) { 532 int i = 0; 533 int j = 0; 534 try { 535 for (; j < a.length; j += SPECIES.length()) { 536 for (i = 0; i < SPECIES.length(); i++) { 537 Assert.assertEquals(r[i+j], f.apply(a[i+j])); 538 } 539 } 540 } catch (AssertionError e) { 541 Assert.assertEquals(r[i+j], f.apply(a[i+j]), "at index #" + i + ", " + j); 542 } 543 } 544 545 static void assertShiftConstEquals(byte[] r, byte[] a, boolean[] mask, FBinConstOp f) { 546 assertShiftConstEquals(r, a, mask, FBinConstMaskOp.lift(f)); 547 } 548 549 static void assertShiftConstEquals(byte[] r, byte[] a, boolean[] mask, FBinConstMaskOp f) { 550 int i = 0; 551 int j = 0; 552 try { 553 for (; j < a.length; j += SPECIES.length()) { 554 for (i = 0; i < SPECIES.length(); i++) { 555 Assert.assertEquals(r[i+j], f.apply(a[i+j], mask[i])); 556 } 557 } 558 } catch (AssertionError err) { 559 Assert.assertEquals(r[i+j], f.apply(a[i+j], mask[i]), "at index #" + i + ", input1 = " + a[i+j] + ", mask = " + mask[i]); 560 } 561 } 562 563 interface FTernOp { 564 byte apply(byte a, byte b, byte c); 565 } 566 567 interface FTernMaskOp { 568 byte apply(byte a, byte b, byte c, boolean m); 569 570 static FTernMaskOp lift(FTernOp f) { 571 return (a, b, c, m) -> m ? f.apply(a, b, c) : a; 572 } 573 } 574 575 static void assertArraysEquals(byte[] r, byte[] a, byte[] b, byte[] c, FTernOp f) { 576 int i = 0; 577 try { 578 for (; i < a.length; i++) { 579 Assert.assertEquals(r[i], f.apply(a[i], b[i], c[i])); 580 } 581 } catch (AssertionError e) { 582 Assert.assertEquals(r[i], f.apply(a[i], b[i], c[i]), "at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]); 583 } 584 } 585 586 static void assertArraysEquals(byte[] r, byte[] a, byte[] b, byte[] c, boolean[] mask, FTernOp f) { 587 assertArraysEquals(r, a, b, c, mask, FTernMaskOp.lift(f)); 588 } 589 590 static void assertArraysEquals(byte[] r, byte[] a, byte[] b, byte[] c, boolean[] mask, FTernMaskOp f) { 591 int i = 0; 592 try { 593 for (; i < a.length; i++) { 594 Assert.assertEquals(r[i], f.apply(a[i], b[i], c[i], mask[i % SPECIES.length()])); 595 } 596 } catch (AssertionError err) { 597 Assert.assertEquals(r[i], f.apply(a[i], b[i], c[i], mask[i % SPECIES.length()]), "at index #" + i + ", input1 = " + a[i] + ", input2 = " 598 + b[i] + ", input3 = " + c[i] + ", mask = " + mask[i % SPECIES.length()]); 599 } 600 } 601 602 static void assertBroadcastArraysEquals(byte[] r, byte[] a, byte[] b, byte[] c, FTernOp f) { 603 int i = 0; 604 try { 605 for (; i < a.length; i++) { 606 Assert.assertEquals(r[i], f.apply(a[i], b[i], c[(i / SPECIES.length()) * SPECIES.length()])); 607 } 608 } catch (AssertionError e) { 609 Assert.assertEquals(r[i], f.apply(a[i], b[i], c[(i / SPECIES.length()) * SPECIES.length()]), "at index #" + 610 i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + 611 c[(i / SPECIES.length()) * SPECIES.length()]); 612 } 613 } 614 615 static void assertAltBroadcastArraysEquals(byte[] r, byte[] a, byte[] b, byte[] c, FTernOp f) { 616 int i = 0; 617 try { 618 for (; i < a.length; i++) { 619 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], c[i])); 620 } 621 } catch (AssertionError e) { 622 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], c[i]), "at index #" + 623 i + ", input1 = " + a[i] + ", input2 = " + 624 b[(i / SPECIES.length()) * SPECIES.length()] + ", input3 = " + c[i]); 625 } 626 } 627 628 static void assertBroadcastArraysEquals(byte[] r, byte[] a, byte[] b, byte[] c, boolean[] mask, 629 FTernOp f) { 630 assertBroadcastArraysEquals(r, a, b, c, mask, FTernMaskOp.lift(f)); 631 } 632 633 static void assertBroadcastArraysEquals(byte[] r, byte[] a, byte[] b, byte[] c, boolean[] mask, 634 FTernMaskOp f) { 635 int i = 0; 636 try { 637 for (; i < a.length; i++) { 638 Assert.assertEquals(r[i], f.apply(a[i], b[i], c[(i / SPECIES.length()) * SPECIES.length()], 639 mask[i % SPECIES.length()])); 640 } 641 } catch (AssertionError err) { 642 Assert.assertEquals(r[i], f.apply(a[i], b[i], c[(i / SPECIES.length()) * SPECIES.length()], 643 mask[i % SPECIES.length()]), "at index #" + i + ", input1 = " + a[i] + ", input2 = " + 644 b[i] + ", input3 = " + c[(i / SPECIES.length()) * SPECIES.length()] + ", mask = " + 645 mask[i % SPECIES.length()]); 646 } 647 } 648 649 static void assertAltBroadcastArraysEquals(byte[] r, byte[] a, byte[] b, byte[] c, boolean[] mask, 650 FTernOp f) { 651 assertAltBroadcastArraysEquals(r, a, b, c, mask, FTernMaskOp.lift(f)); 652 } 653 654 static void assertAltBroadcastArraysEquals(byte[] r, byte[] a, byte[] b, byte[] c, boolean[] mask, 655 FTernMaskOp f) { 656 int i = 0; 657 try { 658 for (; i < a.length; i++) { 659 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], c[i], 660 mask[i % SPECIES.length()])); 661 } 662 } catch (AssertionError err) { 663 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], c[i], 664 mask[i % SPECIES.length()]), "at index #" + i + ", input1 = " + a[i] + 665 ", input2 = " + b[(i / SPECIES.length()) * SPECIES.length()] + 666 ", input3 = " + c[i] + ", mask = " + mask[i % SPECIES.length()]); 667 } 668 } 669 670 static void assertDoubleBroadcastArraysEquals(byte[] r, byte[] a, byte[] b, byte[] c, FTernOp f) { 671 int i = 0; 672 try { 673 for (; i < a.length; i++) { 674 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], 675 c[(i / SPECIES.length()) * SPECIES.length()])); 676 } 677 } catch (AssertionError e) { 678 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], 679 c[(i / SPECIES.length()) * SPECIES.length()]), "at index #" + i + ", input1 = " + a[i] 680 + ", input2 = " + b[(i / SPECIES.length()) * SPECIES.length()] + ", input3 = " + 681 c[(i / SPECIES.length()) * SPECIES.length()]); 682 } 683 } 684 685 static void assertDoubleBroadcastArraysEquals(byte[] r, byte[] a, byte[] b, byte[] c, boolean[] mask, 686 FTernOp f) { 687 assertDoubleBroadcastArraysEquals(r, a, b, c, mask, FTernMaskOp.lift(f)); 688 } 689 690 static void assertDoubleBroadcastArraysEquals(byte[] r, byte[] a, byte[] b, byte[] c, boolean[] mask, 691 FTernMaskOp f) { 692 int i = 0; 693 try { 694 for (; i < a.length; i++) { 695 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], 696 c[(i / SPECIES.length()) * SPECIES.length()], mask[i % SPECIES.length()])); 697 } 698 } catch (AssertionError err) { 699 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], 700 c[(i / SPECIES.length()) * SPECIES.length()], mask[i % SPECIES.length()]), "at index #" 701 + i + ", input1 = " + a[i] + ", input2 = " + b[(i / SPECIES.length()) * SPECIES.length()] + 702 ", input3 = " + c[(i / SPECIES.length()) * SPECIES.length()] + ", mask = " + 703 mask[i % SPECIES.length()]); 704 } 705 } 706 707 708 709 interface FBinArrayOp { 710 byte apply(byte[] a, int b); 711 } 712 713 static void assertArraysEquals(byte[] r, byte[] a, FBinArrayOp f) { 714 int i = 0; 715 try { 716 for (; i < a.length; i++) { 717 Assert.assertEquals(r[i], f.apply(a, i)); 718 } 719 } catch (AssertionError e) { 720 Assert.assertEquals(r[i], f.apply(a,i), "at index #" + i); 721 } 722 } 723 724 interface FGatherScatterOp { 725 byte[] apply(byte[] a, int ix, int[] b, int iy); 726 } 727 728 static void assertArraysEquals(byte[] r, byte[] a, int[] b, FGatherScatterOp f) { 729 int i = 0; 730 try { 731 for (; i < a.length; i += SPECIES.length()) { 732 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()), 733 f.apply(a, i, b, i)); 734 } 735 } catch (AssertionError e) { 736 byte[] ref = f.apply(a, i, b, i); 737 byte[] res = Arrays.copyOfRange(r, i, i+SPECIES.length()); 738 Assert.assertEquals(res, ref, 739 "(ref: " + Arrays.toString(ref) + ", res: " + Arrays.toString(res) + ", a: " 740 + Arrays.toString(Arrays.copyOfRange(a, i, i+SPECIES.length())) 741 + ", b: " 742 + Arrays.toString(Arrays.copyOfRange(b, i, i+SPECIES.length())) 743 + " at index #" + i); 744 } 745 } 746 747 interface FGatherMaskedOp { 748 byte[] apply(byte[] a, int ix, boolean[] mask, int[] b, int iy); 749 } 750 751 interface FScatterMaskedOp { 752 byte[] apply(byte[] r, byte[] a, int ix, boolean[] mask, int[] b, int iy); 753 } 754 755 static void assertArraysEquals(byte[] r, byte[] a, int[] b, boolean[] mask, FGatherMaskedOp f) { 756 int i = 0; 757 try { 758 for (; i < a.length; i += SPECIES.length()) { 759 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()), 760 f.apply(a, i, mask, b, i)); 761 } 762 } catch (AssertionError e) { 763 byte[] ref = f.apply(a, i, mask, b, i); 764 byte[] res = Arrays.copyOfRange(r, i, i+SPECIES.length()); 765 Assert.assertEquals(res, ref, 766 "(ref: " + Arrays.toString(ref) + ", res: " + Arrays.toString(res) + ", a: " 767 + Arrays.toString(Arrays.copyOfRange(a, i, i+SPECIES.length())) 768 + ", b: " 769 + Arrays.toString(Arrays.copyOfRange(b, i, i+SPECIES.length())) 770 + ", mask: " 771 + Arrays.toString(mask) 772 + " at index #" + i); 773 } 774 } 775 776 static void assertArraysEquals(byte[] r, byte[] a, int[] b, boolean[] mask, FScatterMaskedOp f) { 777 int i = 0; 778 try { 779 for (; i < a.length; i += SPECIES.length()) { 780 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()), 781 f.apply(r, a, i, mask, b, i)); 782 } 783 } catch (AssertionError e) { 784 byte[] ref = f.apply(r, a, i, mask, b, i); 785 byte[] res = Arrays.copyOfRange(r, i, i+SPECIES.length()); 786 Assert.assertEquals(res, ref, 787 "(ref: " + Arrays.toString(ref) + ", res: " + Arrays.toString(res) + ", a: " 788 + Arrays.toString(Arrays.copyOfRange(a, i, i+SPECIES.length())) 789 + ", b: " 790 + Arrays.toString(Arrays.copyOfRange(b, i, i+SPECIES.length())) 791 + ", r: " 792 + Arrays.toString(Arrays.copyOfRange(r, i, i+SPECIES.length())) 793 + ", mask: " 794 + Arrays.toString(mask) 795 + " at index #" + i); 796 } 797 } 798 799 interface FLaneOp { 800 byte[] apply(byte[] a, int origin, int idx); 801 } 802 803 static void assertArraysEquals(byte[] r, byte[] a, int origin, FLaneOp f) { 804 int i = 0; 805 try { 806 for (; i < a.length; i += SPECIES.length()) { 807 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()), 808 f.apply(a, origin, i)); 809 } 810 } catch (AssertionError e) { 811 byte[] ref = f.apply(a, origin, i); 812 byte[] res = Arrays.copyOfRange(r, i, i+SPECIES.length()); 813 Assert.assertEquals(res, ref, "(ref: " + Arrays.toString(ref) 814 + ", res: " + Arrays.toString(res) 815 + "), at index #" + i); 816 } 817 } 818 819 interface FLaneBop { 820 byte[] apply(byte[] a, byte[] b, int origin, int idx); 821 } 822 823 static void assertArraysEquals(byte[] r, byte[] a, byte[] b, int origin, FLaneBop f) { 824 int i = 0; 825 try { 826 for (; i < a.length; i += SPECIES.length()) { 827 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()), 828 f.apply(a, b, origin, i)); 829 } 830 } catch (AssertionError e) { 831 byte[] ref = f.apply(a, b, origin, i); 832 byte[] res = Arrays.copyOfRange(r, i, i+SPECIES.length()); 833 Assert.assertEquals(res, ref, "(ref: " + Arrays.toString(ref) 834 + ", res: " + Arrays.toString(res) 835 + "), at index #" + i 836 + ", at origin #" + origin); 837 } 838 } 839 840 interface FLaneMaskedBop { 841 byte[] apply(byte[] a, byte[] b, int origin, boolean[] mask, int idx); 842 } 843 844 static void assertArraysEquals(byte[] r, byte[] a, byte[] b, int origin, boolean[] mask, FLaneMaskedBop f) { 845 int i = 0; 846 try { 847 for (; i < a.length; i += SPECIES.length()) { 848 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()), 849 f.apply(a, b, origin, mask, i)); 850 } 851 } catch (AssertionError e) { 852 byte[] ref = f.apply(a, b, origin, mask, i); 853 byte[] res = Arrays.copyOfRange(r, i, i+SPECIES.length()); 854 Assert.assertEquals(res, ref, "(ref: " + Arrays.toString(ref) 855 + ", res: " + Arrays.toString(res) 856 + "), at index #" + i 857 + ", at origin #" + origin); 858 } 859 } 860 861 interface FLanePartBop { 862 byte[] apply(byte[] a, byte[] b, int origin, int part, int idx); 863 } 864 865 static void assertArraysEquals(byte[] r, byte[] a, byte[] b, int origin, int part, FLanePartBop f) { 866 int i = 0; 867 try { 868 for (; i < a.length; i += SPECIES.length()) { 869 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()), 870 f.apply(a, b, origin, part, i)); 871 } 872 } catch (AssertionError e) { 873 byte[] ref = f.apply(a, b, origin, part, i); 874 byte[] res = Arrays.copyOfRange(r, i, i+SPECIES.length()); 875 Assert.assertEquals(res, ref, "(ref: " + Arrays.toString(ref) 876 + ", res: " + Arrays.toString(res) 877 + "), at index #" + i 878 + ", at origin #" + origin 879 + ", with part #" + part); 880 } 881 } 882 883 interface FLanePartMaskedBop { 884 byte[] apply(byte[] a, byte[] b, int origin, int part, boolean[] mask, int idx); 885 } 886 887 static void assertArraysEquals(byte[] r, byte[] a, byte[] b, int origin, int part, boolean[] mask, FLanePartMaskedBop f) { 888 int i = 0; 889 try { 890 for (; i < a.length; i += SPECIES.length()) { 891 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()), 892 f.apply(a, b, origin, part, mask, i)); 893 } 894 } catch (AssertionError e) { 895 byte[] ref = f.apply(a, b, origin, part, mask, i); 896 byte[] res = Arrays.copyOfRange(r, i, i+SPECIES.length()); 897 Assert.assertEquals(res, ref, "(ref: " + Arrays.toString(ref) 898 + ", res: " + Arrays.toString(res) 899 + "), at index #" + i 900 + ", at origin #" + origin 901 + ", with part #" + part); 902 } 903 } 904 905 906 static void assertArraysEquals(int[] r, byte[] a, int offs) { 907 int i = 0; 908 try { 909 for (; i < r.length; i++) { 910 Assert.assertEquals(r[i], (int)(a[i+offs])); 911 } 912 } catch (AssertionError e) { 913 Assert.assertEquals(r[i], (int)(a[i+offs]), "at index #" + i + ", input = " + a[i+offs]); 914 } 915 } 916 917 918 static void assertArraysEquals(byte[] r, byte[] a, int offs) { 919 int i = 0; 920 try { 921 for (; i < r.length; i++) { 922 Assert.assertEquals(r[i], (long)(a[i+offs])); 923 } 924 } catch (AssertionError e) { 925 Assert.assertEquals(r[i], (long)(a[i+offs]), "at index #" + i + ", input = " + a[i+offs]); 926 } 927 } 928 929 static void assertArraysEquals(long[] r, byte[] a, int offs) { 930 int i = 0; 931 try { 932 for (; i < r.length; i++) { 933 Assert.assertEquals(r[i], (long)(a[i+offs])); 934 } 935 } catch (AssertionError e) { 936 Assert.assertEquals(r[i], (long)(a[i+offs]), "at index #" + i + ", input = " + a[i+offs]); 937 } 938 } 939 940 static void assertArraysEquals(double[] r, byte[] a, int offs) { 941 int i = 0; 942 try { 943 for (; i < r.length; i++) { 944 Assert.assertEquals(r[i], (double)(a[i+offs])); 945 } 946 } catch (AssertionError e) { 947 Assert.assertEquals(r[i], (double)(a[i+offs]), "at index #" + i + ", input = " + a[i+offs]); 948 } 949 } 950 951 static byte bits(byte e) { 952 return e; 953 } 954 955 static final List<IntFunction<byte[]>> BYTE_GENERATORS = List.of( 956 withToString("byte[-i * 5]", (int s) -> { 957 return fill(s * BUFFER_REPS, 958 i -> (byte)(-i * 5)); 959 }), 960 withToString("byte[i * 5]", (int s) -> { 961 return fill(s * BUFFER_REPS, 962 i -> (byte)(i * 5)); 963 }), 964 withToString("byte[i + 1]", (int s) -> { 965 return fill(s * BUFFER_REPS, 966 i -> (((byte)(i + 1) == 0) ? 1 : (byte)(i + 1))); 967 }), 968 withToString("byte[cornerCaseValue(i)]", (int s) -> { 969 return fill(s * BUFFER_REPS, 970 i -> cornerCaseValue(i)); 971 }) 972 ); 973 974 // Create combinations of pairs 975 // @@@ Might be sensitive to order e.g. div by 0 976 static final List<List<IntFunction<byte[]>>> BYTE_GENERATOR_PAIRS = 977 Stream.of(BYTE_GENERATORS.get(0)). 978 flatMap(fa -> BYTE_GENERATORS.stream().skip(1).map(fb -> List.of(fa, fb))). 979 collect(Collectors.toList()); 980 981 @DataProvider 982 public Object[][] boolUnaryOpProvider() { 983 return BOOL_ARRAY_GENERATORS.stream(). 984 map(f -> new Object[]{f}). 985 toArray(Object[][]::new); 986 } 987 988 static final List<List<IntFunction<byte[]>>> BYTE_GENERATOR_TRIPLES = 989 BYTE_GENERATOR_PAIRS.stream(). 990 flatMap(pair -> BYTE_GENERATORS.stream().map(f -> List.of(pair.get(0), pair.get(1), f))). 991 collect(Collectors.toList()); 992 993 @DataProvider 994 public Object[][] byteBinaryOpProvider() { 995 return BYTE_GENERATOR_PAIRS.stream().map(List::toArray). 996 toArray(Object[][]::new); 997 } 998 999 @DataProvider 1000 public Object[][] byteIndexedOpProvider() { 1001 return BYTE_GENERATOR_PAIRS.stream().map(List::toArray). 1002 toArray(Object[][]::new); 1003 } 1004 1005 @DataProvider 1006 public Object[][] byteBinaryOpMaskProvider() { 1007 return BOOLEAN_MASK_GENERATORS.stream(). 1008 flatMap(fm -> BYTE_GENERATOR_PAIRS.stream().map(lfa -> { 1009 return Stream.concat(lfa.stream(), Stream.of(fm)).toArray(); 1010 })). 1011 toArray(Object[][]::new); 1012 } 1013 1014 @DataProvider 1015 public Object[][] byteTernaryOpProvider() { 1016 return BYTE_GENERATOR_TRIPLES.stream().map(List::toArray). 1017 toArray(Object[][]::new); 1018 } 1019 1020 @DataProvider 1021 public Object[][] byteTernaryOpMaskProvider() { 1022 return BOOLEAN_MASK_GENERATORS.stream(). 1023 flatMap(fm -> BYTE_GENERATOR_TRIPLES.stream().map(lfa -> { 1024 return Stream.concat(lfa.stream(), Stream.of(fm)).toArray(); 1025 })). 1026 toArray(Object[][]::new); 1027 } 1028 1029 @DataProvider 1030 public Object[][] byteUnaryOpProvider() { 1031 return BYTE_GENERATORS.stream(). 1032 map(f -> new Object[]{f}). 1033 toArray(Object[][]::new); 1034 } 1035 1036 @DataProvider 1037 public Object[][] byteUnaryOpMaskProvider() { 1038 return BOOLEAN_MASK_GENERATORS.stream(). 1039 flatMap(fm -> BYTE_GENERATORS.stream().map(fa -> { 1040 return new Object[] {fa, fm}; 1041 })). 1042 toArray(Object[][]::new); 1043 } 1044 1045 @DataProvider 1046 public Object[][] maskProvider() { 1047 return BOOLEAN_MASK_GENERATORS.stream(). 1048 map(f -> new Object[]{f}). 1049 toArray(Object[][]::new); 1050 } 1051 1052 @DataProvider 1053 public Object[][] maskCompareOpProvider() { 1054 return BOOLEAN_MASK_COMPARE_GENERATOR_PAIRS.stream().map(List::toArray). 1055 toArray(Object[][]::new); 1056 } 1057 1058 @DataProvider 1059 public Object[][] shuffleProvider() { 1060 return INT_SHUFFLE_GENERATORS.stream(). 1061 map(f -> new Object[]{f}). 1062 toArray(Object[][]::new); 1063 } 1064 1065 @DataProvider 1066 public Object[][] shuffleCompareOpProvider() { 1067 return INT_SHUFFLE_COMPARE_GENERATOR_PAIRS.stream().map(List::toArray). 1068 toArray(Object[][]::new); 1069 } 1070 1071 @DataProvider 1072 public Object[][] byteUnaryOpShuffleProvider() { 1073 return INT_SHUFFLE_GENERATORS.stream(). 1074 flatMap(fs -> BYTE_GENERATORS.stream().map(fa -> { 1075 return new Object[] {fa, fs}; 1076 })). 1077 toArray(Object[][]::new); 1078 } 1079 1080 @DataProvider 1081 public Object[][] byteUnaryOpShuffleMaskProvider() { 1082 return BOOLEAN_MASK_GENERATORS.stream(). 1083 flatMap(fm -> INT_SHUFFLE_GENERATORS.stream(). 1084 flatMap(fs -> BYTE_GENERATORS.stream().map(fa -> { 1085 return new Object[] {fa, fs, fm}; 1086 }))). 1087 toArray(Object[][]::new); 1088 } 1089 1090 static final List<BiFunction<Integer,Integer,byte[]>> BYTE_SHUFFLE_GENERATORS = List.of( 1091 withToStringBi("shuffle[random]", (Integer l, Integer m) -> { 1092 byte[] a = new byte[l]; 1093 int upper = Math.min(Byte.MAX_VALUE + 1, m); 1094 for (int i = 0; i < 1; i++) { 1095 a[i] = (byte)RAND.nextInt(upper); 1096 } 1097 return a; 1098 }) 1099 ); 1100 1101 @DataProvider 1102 public Object[][] byteUnaryOpSelectFromProvider() { 1103 return BYTE_SHUFFLE_GENERATORS.stream(). 1104 flatMap(fs -> BYTE_GENERATORS.stream().map(fa -> { 1105 return new Object[] {fa, fs}; 1106 })). 1107 toArray(Object[][]::new); 1108 } 1109 1110 @DataProvider 1111 public Object[][] byteUnaryOpSelectFromMaskProvider() { 1112 return BOOLEAN_MASK_GENERATORS.stream(). 1113 flatMap(fm -> BYTE_SHUFFLE_GENERATORS.stream(). 1114 flatMap(fs -> BYTE_GENERATORS.stream().map(fa -> { 1115 return new Object[] {fa, fs, fm}; 1116 }))). 1117 toArray(Object[][]::new); 1118 } 1119 1120 static final List<IntFunction<byte[]>> BYTE_COMPARE_GENERATORS = List.of( 1121 withToString("byte[i]", (int s) -> { 1122 return fill(s * BUFFER_REPS, 1123 i -> (byte)i); 1124 }), 1125 withToString("byte[i - length / 2]", (int s) -> { 1126 return fill(s * BUFFER_REPS, 1127 i -> (byte)(i - (s * BUFFER_REPS / 2))); 1128 }), 1129 withToString("byte[i + 1]", (int s) -> { 1130 return fill(s * BUFFER_REPS, 1131 i -> (byte)(i + 1)); 1132 }), 1133 withToString("byte[i - 2]", (int s) -> { 1134 return fill(s * BUFFER_REPS, 1135 i -> (byte)(i - 2)); 1136 }), 1137 withToString("byte[zigZag(i)]", (int s) -> { 1138 return fill(s * BUFFER_REPS, 1139 i -> i%3 == 0 ? (byte)i : (i%3 == 1 ? (byte)(i + 1) : (byte)(i - 2))); 1140 }), 1141 withToString("byte[cornerCaseValue(i)]", (int s) -> { 1142 return fill(s * BUFFER_REPS, 1143 i -> cornerCaseValue(i)); 1144 }) 1145 ); 1146 1147 static final List<List<IntFunction<byte[]>>> BYTE_TEST_GENERATOR_ARGS = 1148 BYTE_COMPARE_GENERATORS.stream(). 1149 map(fa -> List.of(fa)). 1150 collect(Collectors.toList()); 1151 1152 @DataProvider 1153 public Object[][] byteTestOpProvider() { 1154 return BYTE_TEST_GENERATOR_ARGS.stream().map(List::toArray). 1155 toArray(Object[][]::new); 1156 } 1157 1158 @DataProvider 1159 public Object[][] byteTestOpMaskProvider() { 1160 return BOOLEAN_MASK_GENERATORS.stream(). 1161 flatMap(fm -> BYTE_TEST_GENERATOR_ARGS.stream().map(lfa -> { 1162 return Stream.concat(lfa.stream(), Stream.of(fm)).toArray(); 1163 })). 1164 toArray(Object[][]::new); 1165 } 1166 1167 static final List<List<IntFunction<byte[]>>> BYTE_COMPARE_GENERATOR_PAIRS = 1168 BYTE_COMPARE_GENERATORS.stream(). 1169 flatMap(fa -> BYTE_COMPARE_GENERATORS.stream().map(fb -> List.of(fa, fb))). 1170 collect(Collectors.toList()); 1171 1172 @DataProvider 1173 public Object[][] byteCompareOpProvider() { 1174 return BYTE_COMPARE_GENERATOR_PAIRS.stream().map(List::toArray). 1175 toArray(Object[][]::new); 1176 } 1177 1178 @DataProvider 1179 public Object[][] byteCompareOpMaskProvider() { 1180 return BOOLEAN_MASK_GENERATORS.stream(). 1181 flatMap(fm -> BYTE_COMPARE_GENERATOR_PAIRS.stream().map(lfa -> { 1182 return Stream.concat(lfa.stream(), Stream.of(fm)).toArray(); 1183 })). 1184 toArray(Object[][]::new); 1185 } 1186 1187 interface ToByteF { 1188 byte apply(int i); 1189 } 1190 1191 static byte[] fill(int s , ToByteF f) { 1192 return fill(new byte[s], f); 1193 } 1194 1195 static byte[] fill(byte[] a, ToByteF f) { 1196 for (int i = 0; i < a.length; i++) { 1197 a[i] = f.apply(i); 1198 } 1199 return a; 1200 } 1201 1202 static byte cornerCaseValue(int i) { 1203 switch(i % 5) { 1204 case 0: 1205 return Byte.MAX_VALUE; 1206 case 1: 1207 return Byte.MIN_VALUE; 1208 case 2: 1209 return Byte.MIN_VALUE; 1210 case 3: 1211 return Byte.MAX_VALUE; 1212 default: 1213 return (byte)0; 1214 } 1215 } 1216 1217 static byte get(byte[] a, int i) { 1218 return (byte) a[i]; 1219 } 1220 1221 static final IntFunction<byte[]> fr = (vl) -> { 1222 int length = BUFFER_REPS * vl; 1223 return new byte[length]; 1224 }; 1225 1226 static final IntFunction<boolean[]> fmr = (vl) -> { 1227 int length = BUFFER_REPS * vl; 1228 return new boolean[length]; 1229 }; 1230 1231 static final IntFunction<long[]> lfr = (vl) -> { 1232 int length = BUFFER_REPS * vl; 1233 return new long[length]; 1234 }; 1235 1236 static void replaceZero(byte[] a, byte v) { 1237 for (int i = 0; i < a.length; i++) { 1238 if (a[i] == 0) { 1239 a[i] = v; 1240 } 1241 } 1242 } 1243 1244 static void replaceZero(byte[] a, boolean[] mask, byte v) { 1245 for (int i = 0; i < a.length; i++) { 1246 if (mask[i % mask.length] && a[i] == 0) { 1247 a[i] = v; 1248 } 1249 } 1250 } 1251 1252 static byte ROL_scalar(byte a, byte b) { 1253 return (byte)(((((byte)a) & 0xFF) << (b & 7)) | ((((byte)a) & 0xFF) >>> (8 - (b & 7)))); 1254 } 1255 1256 static byte ROR_scalar(byte a, byte b) { 1257 return (byte)(((((byte)a) & 0xFF) >>> (b & 7)) | ((((byte)a) & 0xFF) << (8 - (b & 7)))); 1258 } 1259 1260 static byte TRAILING_ZEROS_COUNT_scalar(byte a) { 1261 return (byte) (a != 0 ? Integer.numberOfTrailingZeros(a) : 8); 1262 } 1263 1264 static byte LEADING_ZEROS_COUNT_scalar(byte a) { 1265 return (byte) (a >= 0 ? Integer.numberOfLeadingZeros(a) - 24 : 0); 1266 } 1267 1268 static byte REVERSE_scalar(byte a) { 1269 byte b = (byte) ROL_scalar(a, (byte) 4); 1270 b = (byte) (((b & 0x55) << 1) | ((b & 0xAA) >>> 1)); 1271 b = (byte) (((b & 0x33) << 2) | ((b & 0xCC) >>> 2)); 1272 return b; 1273 } 1274 1275 static boolean eq(byte a, byte b) { 1276 return a == b; 1277 } 1278 1279 static boolean neq(byte a, byte b) { 1280 return a != b; 1281 } 1282 1283 static boolean lt(byte a, byte b) { 1284 return a < b; 1285 } 1286 1287 static boolean le(byte a, byte b) { 1288 return a <= b; 1289 } 1290 1291 static boolean gt(byte a, byte b) { 1292 return a > b; 1293 } 1294 1295 static boolean ge(byte a, byte b) { 1296 return a >= b; 1297 } 1298 1299 static boolean ult(byte a, byte b) { 1300 return Byte.compareUnsigned(a, b) < 0; 1301 } 1302 1303 static boolean ule(byte a, byte b) { 1304 return Byte.compareUnsigned(a, b) <= 0; 1305 } 1306 1307 static boolean ugt(byte a, byte b) { 1308 return Byte.compareUnsigned(a, b) > 0; 1309 } 1310 1311 static boolean uge(byte a, byte b) { 1312 return Byte.compareUnsigned(a, b) >= 0; 1313 } 1314 1315 static byte firstNonZero(byte a, byte b) { 1316 return Byte.compare(a, (byte) 0) != 0 ? a : b; 1317 } 1318 1319 @Test 1320 static void smokeTest1() { 1321 ByteVector three = ByteVector.broadcast(SPECIES, (byte)-3); 1322 ByteVector three2 = (ByteVector) SPECIES.broadcast(-3); 1323 assert(three.eq(three2).allTrue()); 1324 ByteVector three3 = three2.broadcast(1).broadcast(-3); 1325 assert(three.eq(three3).allTrue()); 1326 int scale = 2; 1327 Class<?> ETYPE = byte.class; 1328 if (ETYPE == double.class || ETYPE == long.class) 1329 scale = 1000000; 1330 else if (ETYPE == byte.class && SPECIES.length() >= 64) 1331 scale = 1; 1332 ByteVector higher = three.addIndex(scale); 1333 VectorMask<Byte> m = three.compare(VectorOperators.LE, higher); 1334 assert(m.allTrue()); 1335 m = higher.min((byte)-1).test(VectorOperators.IS_NEGATIVE); 1336 assert(m.allTrue()); 1337 byte max = higher.reduceLanes(VectorOperators.MAX); 1338 assert(max == -3 + scale * (SPECIES.length()-1)); 1339 } 1340 1341 private static byte[] 1342 bothToArray(ByteVector a, ByteVector b) { 1343 byte[] r = new byte[a.length() + b.length()]; 1344 a.intoArray(r, 0); 1345 b.intoArray(r, a.length()); 1346 return r; 1347 } 1348 1349 @Test 1350 static void smokeTest2() { 1351 // Do some zipping and shuffling. 1352 ByteVector io = (ByteVector) SPECIES.broadcast(0).addIndex(1); 1353 ByteVector io2 = (ByteVector) VectorShuffle.iota(SPECIES,0,1,false).toVector(); 1354 Assert.assertEquals(io, io2); 1355 ByteVector a = io.add((byte)1); //[1,2] 1356 ByteVector b = a.neg(); //[-1,-2] 1357 byte[] abValues = bothToArray(a,b); //[1,2,-1,-2] 1358 VectorShuffle<Byte> zip0 = VectorShuffle.makeZip(SPECIES, 0); 1359 VectorShuffle<Byte> zip1 = VectorShuffle.makeZip(SPECIES, 1); 1360 ByteVector zab0 = a.rearrange(zip0,b); //[1,-1] 1361 ByteVector zab1 = a.rearrange(zip1,b); //[2,-2] 1362 byte[] zabValues = bothToArray(zab0, zab1); //[1,-1,2,-2] 1363 // manually zip 1364 byte[] manual = new byte[zabValues.length]; 1365 for (int i = 0; i < manual.length; i += 2) { 1366 manual[i+0] = abValues[i/2]; 1367 manual[i+1] = abValues[a.length() + i/2]; 1368 } 1369 Assert.assertEquals(Arrays.toString(zabValues), Arrays.toString(manual)); 1370 VectorShuffle<Byte> unz0 = VectorShuffle.makeUnzip(SPECIES, 0); 1371 VectorShuffle<Byte> unz1 = VectorShuffle.makeUnzip(SPECIES, 1); 1372 ByteVector uab0 = zab0.rearrange(unz0,zab1); 1373 ByteVector uab1 = zab0.rearrange(unz1,zab1); 1374 byte[] abValues1 = bothToArray(uab0, uab1); 1375 Assert.assertEquals(Arrays.toString(abValues), Arrays.toString(abValues1)); 1376 } 1377 1378 static void iotaShuffle() { 1379 ByteVector io = (ByteVector) SPECIES.broadcast(0).addIndex(1); 1380 ByteVector io2 = (ByteVector) VectorShuffle.iota(SPECIES, 0 , 1, false).toVector(); 1381 Assert.assertEquals(io, io2); 1382 } 1383 1384 @Test 1385 // Test all shuffle related operations. 1386 static void shuffleTest() { 1387 // To test backend instructions, make sure that C2 is used. 1388 for (int loop = 0; loop < INVOC_COUNT * INVOC_COUNT; loop++) { 1389 iotaShuffle(); 1390 } 1391 } 1392 1393 @Test 1394 void viewAsIntegeralLanesTest() { 1395 Vector<?> asIntegral = SPECIES.zero().viewAsIntegralLanes(); 1396 Assert.assertEquals(asIntegral.species(), SPECIES); 1397 } 1398 1399 @Test(expectedExceptions = UnsupportedOperationException.class) 1400 void viewAsFloatingLanesTest() { 1401 SPECIES.zero().viewAsFloatingLanes(); 1402 } 1403 1404 @Test 1405 // Test div by 0. 1406 static void bitwiseDivByZeroSmokeTest() { 1407 try { 1408 ByteVector a = (ByteVector) SPECIES.broadcast(0).addIndex(1); 1409 ByteVector b = (ByteVector) SPECIES.broadcast(0); 1410 a.div(b); 1411 Assert.fail(); 1412 } catch (ArithmeticException e) { 1413 } 1414 1415 try { 1416 ByteVector a = (ByteVector) SPECIES.broadcast(0).addIndex(1); 1417 ByteVector b = (ByteVector) SPECIES.broadcast(0); 1418 VectorMask<Byte> m = a.lt((byte) 1); 1419 a.div(b, m); 1420 Assert.fail(); 1421 } catch (ArithmeticException e) { 1422 } 1423 } 1424 1425 static byte ADD(byte a, byte b) { 1426 return (byte)(a + b); 1427 } 1428 1429 @Test(dataProvider = "byteBinaryOpProvider") 1430 static void ADDByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 1431 byte[] a = fa.apply(SPECIES.length()); 1432 byte[] b = fb.apply(SPECIES.length()); 1433 byte[] r = fr.apply(SPECIES.length()); 1434 1435 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1436 for (int i = 0; i < a.length; i += SPECIES.length()) { 1437 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1438 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 1439 av.lanewise(VectorOperators.ADD, bv).intoArray(r, i); 1440 } 1441 } 1442 1443 assertArraysEquals(r, a, b, ByteMaxVectorTests::ADD); 1444 } 1445 1446 static byte add(byte a, byte b) { 1447 return (byte)(a + b); 1448 } 1449 1450 @Test(dataProvider = "byteBinaryOpProvider") 1451 static void addByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 1452 byte[] a = fa.apply(SPECIES.length()); 1453 byte[] b = fb.apply(SPECIES.length()); 1454 byte[] r = fr.apply(SPECIES.length()); 1455 1456 for (int i = 0; i < a.length; i += SPECIES.length()) { 1457 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1458 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 1459 av.add(bv).intoArray(r, i); 1460 } 1461 1462 assertArraysEquals(r, a, b, ByteMaxVectorTests::add); 1463 } 1464 1465 @Test(dataProvider = "byteBinaryOpMaskProvider") 1466 static void ADDByteMaxVectorTestsMasked(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.ADD, bv, vmask).intoArray(r, i); 1479 } 1480 } 1481 1482 assertArraysEquals(r, a, b, mask, ByteMaxVectorTests::ADD); 1483 } 1484 1485 @Test(dataProvider = "byteBinaryOpMaskProvider") 1486 static void addByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 1487 IntFunction<boolean[]> fm) { 1488 byte[] a = fa.apply(SPECIES.length()); 1489 byte[] b = fb.apply(SPECIES.length()); 1490 byte[] r = fr.apply(SPECIES.length()); 1491 boolean[] mask = fm.apply(SPECIES.length()); 1492 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1493 1494 for (int i = 0; i < a.length; i += SPECIES.length()) { 1495 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1496 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 1497 av.add(bv, vmask).intoArray(r, i); 1498 } 1499 1500 assertArraysEquals(r, a, b, mask, ByteMaxVectorTests::add); 1501 } 1502 1503 static byte SUB(byte a, byte b) { 1504 return (byte)(a - b); 1505 } 1506 1507 @Test(dataProvider = "byteBinaryOpProvider") 1508 static void SUBByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 1509 byte[] a = fa.apply(SPECIES.length()); 1510 byte[] b = fb.apply(SPECIES.length()); 1511 byte[] r = fr.apply(SPECIES.length()); 1512 1513 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1514 for (int i = 0; i < a.length; i += SPECIES.length()) { 1515 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1516 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 1517 av.lanewise(VectorOperators.SUB, bv).intoArray(r, i); 1518 } 1519 } 1520 1521 assertArraysEquals(r, a, b, ByteMaxVectorTests::SUB); 1522 } 1523 1524 static byte sub(byte a, byte b) { 1525 return (byte)(a - b); 1526 } 1527 1528 @Test(dataProvider = "byteBinaryOpProvider") 1529 static void subByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 1530 byte[] a = fa.apply(SPECIES.length()); 1531 byte[] b = fb.apply(SPECIES.length()); 1532 byte[] r = fr.apply(SPECIES.length()); 1533 1534 for (int i = 0; i < a.length; i += SPECIES.length()) { 1535 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1536 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 1537 av.sub(bv).intoArray(r, i); 1538 } 1539 1540 assertArraysEquals(r, a, b, ByteMaxVectorTests::sub); 1541 } 1542 1543 @Test(dataProvider = "byteBinaryOpMaskProvider") 1544 static void SUBByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 1545 IntFunction<boolean[]> fm) { 1546 byte[] a = fa.apply(SPECIES.length()); 1547 byte[] b = fb.apply(SPECIES.length()); 1548 byte[] r = fr.apply(SPECIES.length()); 1549 boolean[] mask = fm.apply(SPECIES.length()); 1550 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1551 1552 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1553 for (int i = 0; i < a.length; i += SPECIES.length()) { 1554 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1555 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 1556 av.lanewise(VectorOperators.SUB, bv, vmask).intoArray(r, i); 1557 } 1558 } 1559 1560 assertArraysEquals(r, a, b, mask, ByteMaxVectorTests::SUB); 1561 } 1562 1563 @Test(dataProvider = "byteBinaryOpMaskProvider") 1564 static void subByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 1565 IntFunction<boolean[]> fm) { 1566 byte[] a = fa.apply(SPECIES.length()); 1567 byte[] b = fb.apply(SPECIES.length()); 1568 byte[] r = fr.apply(SPECIES.length()); 1569 boolean[] mask = fm.apply(SPECIES.length()); 1570 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1571 1572 for (int i = 0; i < a.length; i += SPECIES.length()) { 1573 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1574 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 1575 av.sub(bv, vmask).intoArray(r, i); 1576 } 1577 1578 assertArraysEquals(r, a, b, mask, ByteMaxVectorTests::sub); 1579 } 1580 1581 static byte MUL(byte a, byte b) { 1582 return (byte)(a * b); 1583 } 1584 1585 @Test(dataProvider = "byteBinaryOpProvider") 1586 static void MULByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 1587 byte[] a = fa.apply(SPECIES.length()); 1588 byte[] b = fb.apply(SPECIES.length()); 1589 byte[] r = fr.apply(SPECIES.length()); 1590 1591 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1592 for (int i = 0; i < a.length; i += SPECIES.length()) { 1593 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1594 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 1595 av.lanewise(VectorOperators.MUL, bv).intoArray(r, i); 1596 } 1597 } 1598 1599 assertArraysEquals(r, a, b, ByteMaxVectorTests::MUL); 1600 } 1601 1602 static byte mul(byte a, byte b) { 1603 return (byte)(a * b); 1604 } 1605 1606 @Test(dataProvider = "byteBinaryOpProvider") 1607 static void mulByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 1608 byte[] a = fa.apply(SPECIES.length()); 1609 byte[] b = fb.apply(SPECIES.length()); 1610 byte[] r = fr.apply(SPECIES.length()); 1611 1612 for (int i = 0; i < a.length; i += SPECIES.length()) { 1613 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1614 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 1615 av.mul(bv).intoArray(r, i); 1616 } 1617 1618 assertArraysEquals(r, a, b, ByteMaxVectorTests::mul); 1619 } 1620 1621 @Test(dataProvider = "byteBinaryOpMaskProvider") 1622 static void MULByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 1623 IntFunction<boolean[]> fm) { 1624 byte[] a = fa.apply(SPECIES.length()); 1625 byte[] b = fb.apply(SPECIES.length()); 1626 byte[] r = fr.apply(SPECIES.length()); 1627 boolean[] mask = fm.apply(SPECIES.length()); 1628 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1629 1630 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1631 for (int i = 0; i < a.length; i += SPECIES.length()) { 1632 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1633 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 1634 av.lanewise(VectorOperators.MUL, bv, vmask).intoArray(r, i); 1635 } 1636 } 1637 1638 assertArraysEquals(r, a, b, mask, ByteMaxVectorTests::MUL); 1639 } 1640 1641 @Test(dataProvider = "byteBinaryOpMaskProvider") 1642 static void mulByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 1643 IntFunction<boolean[]> fm) { 1644 byte[] a = fa.apply(SPECIES.length()); 1645 byte[] b = fb.apply(SPECIES.length()); 1646 byte[] r = fr.apply(SPECIES.length()); 1647 boolean[] mask = fm.apply(SPECIES.length()); 1648 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1649 1650 for (int i = 0; i < a.length; i += SPECIES.length()) { 1651 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1652 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 1653 av.mul(bv, vmask).intoArray(r, i); 1654 } 1655 1656 assertArraysEquals(r, a, b, mask, ByteMaxVectorTests::mul); 1657 } 1658 1659 static byte DIV(byte a, byte b) { 1660 return (byte)(a / b); 1661 } 1662 1663 @Test(dataProvider = "byteBinaryOpProvider") 1664 static void DIVByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 1665 byte[] a = fa.apply(SPECIES.length()); 1666 byte[] b = fb.apply(SPECIES.length()); 1667 byte[] r = fr.apply(SPECIES.length()); 1668 1669 replaceZero(b, (byte) 1); 1670 1671 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1672 for (int i = 0; i < a.length; i += SPECIES.length()) { 1673 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1674 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 1675 av.lanewise(VectorOperators.DIV, bv).intoArray(r, i); 1676 } 1677 } 1678 1679 assertArraysEquals(r, a, b, ByteMaxVectorTests::DIV); 1680 } 1681 1682 static byte div(byte a, byte b) { 1683 return (byte)(a / b); 1684 } 1685 1686 @Test(dataProvider = "byteBinaryOpProvider") 1687 static void divByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 1688 byte[] a = fa.apply(SPECIES.length()); 1689 byte[] b = fb.apply(SPECIES.length()); 1690 byte[] r = fr.apply(SPECIES.length()); 1691 1692 replaceZero(b, (byte) 1); 1693 1694 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1695 for (int i = 0; i < a.length; i += SPECIES.length()) { 1696 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1697 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 1698 av.div(bv).intoArray(r, i); 1699 } 1700 } 1701 1702 assertArraysEquals(r, a, b, ByteMaxVectorTests::div); 1703 } 1704 1705 @Test(dataProvider = "byteBinaryOpMaskProvider") 1706 static void DIVByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 1707 IntFunction<boolean[]> fm) { 1708 byte[] a = fa.apply(SPECIES.length()); 1709 byte[] b = fb.apply(SPECIES.length()); 1710 byte[] r = fr.apply(SPECIES.length()); 1711 boolean[] mask = fm.apply(SPECIES.length()); 1712 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1713 1714 replaceZero(b, mask, (byte) 1); 1715 1716 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1717 for (int i = 0; i < a.length; i += SPECIES.length()) { 1718 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1719 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 1720 av.lanewise(VectorOperators.DIV, bv, vmask).intoArray(r, i); 1721 } 1722 } 1723 1724 assertArraysEquals(r, a, b, mask, ByteMaxVectorTests::DIV); 1725 } 1726 1727 @Test(dataProvider = "byteBinaryOpMaskProvider") 1728 static void divByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 1729 IntFunction<boolean[]> fm) { 1730 byte[] a = fa.apply(SPECIES.length()); 1731 byte[] b = fb.apply(SPECIES.length()); 1732 byte[] r = fr.apply(SPECIES.length()); 1733 boolean[] mask = fm.apply(SPECIES.length()); 1734 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1735 1736 replaceZero(b, mask, (byte) 1); 1737 1738 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1739 for (int i = 0; i < a.length; i += SPECIES.length()) { 1740 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1741 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 1742 av.div(bv, vmask).intoArray(r, i); 1743 } 1744 } 1745 1746 assertArraysEquals(r, a, b, mask, ByteMaxVectorTests::div); 1747 } 1748 1749 static byte FIRST_NONZERO(byte a, byte b) { 1750 return (byte)((a)!=0?a:b); 1751 } 1752 1753 @Test(dataProvider = "byteBinaryOpProvider") 1754 static void FIRST_NONZEROByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 1755 byte[] a = fa.apply(SPECIES.length()); 1756 byte[] b = fb.apply(SPECIES.length()); 1757 byte[] r = fr.apply(SPECIES.length()); 1758 1759 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1760 for (int i = 0; i < a.length; i += SPECIES.length()) { 1761 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1762 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 1763 av.lanewise(VectorOperators.FIRST_NONZERO, bv).intoArray(r, i); 1764 } 1765 } 1766 1767 assertArraysEquals(r, a, b, ByteMaxVectorTests::FIRST_NONZERO); 1768 } 1769 1770 @Test(dataProvider = "byteBinaryOpMaskProvider") 1771 static void FIRST_NONZEROByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 1772 IntFunction<boolean[]> fm) { 1773 byte[] a = fa.apply(SPECIES.length()); 1774 byte[] b = fb.apply(SPECIES.length()); 1775 byte[] r = fr.apply(SPECIES.length()); 1776 boolean[] mask = fm.apply(SPECIES.length()); 1777 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1778 1779 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1780 for (int i = 0; i < a.length; i += SPECIES.length()) { 1781 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1782 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 1783 av.lanewise(VectorOperators.FIRST_NONZERO, bv, vmask).intoArray(r, i); 1784 } 1785 } 1786 1787 assertArraysEquals(r, a, b, mask, ByteMaxVectorTests::FIRST_NONZERO); 1788 } 1789 1790 static byte AND(byte a, byte b) { 1791 return (byte)(a & b); 1792 } 1793 1794 @Test(dataProvider = "byteBinaryOpProvider") 1795 static void ANDByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 1796 byte[] a = fa.apply(SPECIES.length()); 1797 byte[] b = fb.apply(SPECIES.length()); 1798 byte[] r = fr.apply(SPECIES.length()); 1799 1800 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1801 for (int i = 0; i < a.length; i += SPECIES.length()) { 1802 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1803 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 1804 av.lanewise(VectorOperators.AND, bv).intoArray(r, i); 1805 } 1806 } 1807 1808 assertArraysEquals(r, a, b, ByteMaxVectorTests::AND); 1809 } 1810 1811 static byte and(byte a, byte b) { 1812 return (byte)(a & b); 1813 } 1814 1815 @Test(dataProvider = "byteBinaryOpProvider") 1816 static void andByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 1817 byte[] a = fa.apply(SPECIES.length()); 1818 byte[] b = fb.apply(SPECIES.length()); 1819 byte[] r = fr.apply(SPECIES.length()); 1820 1821 for (int i = 0; i < a.length; i += SPECIES.length()) { 1822 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1823 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 1824 av.and(bv).intoArray(r, i); 1825 } 1826 1827 assertArraysEquals(r, a, b, ByteMaxVectorTests::and); 1828 } 1829 1830 @Test(dataProvider = "byteBinaryOpMaskProvider") 1831 static void ANDByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 1832 IntFunction<boolean[]> fm) { 1833 byte[] a = fa.apply(SPECIES.length()); 1834 byte[] b = fb.apply(SPECIES.length()); 1835 byte[] r = fr.apply(SPECIES.length()); 1836 boolean[] mask = fm.apply(SPECIES.length()); 1837 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1838 1839 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1840 for (int i = 0; i < a.length; i += SPECIES.length()) { 1841 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1842 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 1843 av.lanewise(VectorOperators.AND, bv, vmask).intoArray(r, i); 1844 } 1845 } 1846 1847 assertArraysEquals(r, a, b, mask, ByteMaxVectorTests::AND); 1848 } 1849 1850 static byte AND_NOT(byte a, byte b) { 1851 return (byte)(a & ~b); 1852 } 1853 1854 @Test(dataProvider = "byteBinaryOpProvider") 1855 static void AND_NOTByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 1856 byte[] a = fa.apply(SPECIES.length()); 1857 byte[] b = fb.apply(SPECIES.length()); 1858 byte[] r = fr.apply(SPECIES.length()); 1859 1860 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1861 for (int i = 0; i < a.length; i += SPECIES.length()) { 1862 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1863 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 1864 av.lanewise(VectorOperators.AND_NOT, bv).intoArray(r, i); 1865 } 1866 } 1867 1868 assertArraysEquals(r, a, b, ByteMaxVectorTests::AND_NOT); 1869 } 1870 1871 @Test(dataProvider = "byteBinaryOpMaskProvider") 1872 static void AND_NOTByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 1873 IntFunction<boolean[]> fm) { 1874 byte[] a = fa.apply(SPECIES.length()); 1875 byte[] b = fb.apply(SPECIES.length()); 1876 byte[] r = fr.apply(SPECIES.length()); 1877 boolean[] mask = fm.apply(SPECIES.length()); 1878 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1879 1880 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1881 for (int i = 0; i < a.length; i += SPECIES.length()) { 1882 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1883 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 1884 av.lanewise(VectorOperators.AND_NOT, bv, vmask).intoArray(r, i); 1885 } 1886 } 1887 1888 assertArraysEquals(r, a, b, mask, ByteMaxVectorTests::AND_NOT); 1889 } 1890 1891 static byte OR(byte a, byte b) { 1892 return (byte)(a | b); 1893 } 1894 1895 @Test(dataProvider = "byteBinaryOpProvider") 1896 static void ORByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 1897 byte[] a = fa.apply(SPECIES.length()); 1898 byte[] b = fb.apply(SPECIES.length()); 1899 byte[] r = fr.apply(SPECIES.length()); 1900 1901 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1902 for (int i = 0; i < a.length; i += SPECIES.length()) { 1903 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1904 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 1905 av.lanewise(VectorOperators.OR, bv).intoArray(r, i); 1906 } 1907 } 1908 1909 assertArraysEquals(r, a, b, ByteMaxVectorTests::OR); 1910 } 1911 1912 static byte or(byte a, byte b) { 1913 return (byte)(a | b); 1914 } 1915 1916 @Test(dataProvider = "byteBinaryOpProvider") 1917 static void orByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 1918 byte[] a = fa.apply(SPECIES.length()); 1919 byte[] b = fb.apply(SPECIES.length()); 1920 byte[] r = fr.apply(SPECIES.length()); 1921 1922 for (int i = 0; i < a.length; i += SPECIES.length()) { 1923 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1924 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 1925 av.or(bv).intoArray(r, i); 1926 } 1927 1928 assertArraysEquals(r, a, b, ByteMaxVectorTests::or); 1929 } 1930 1931 @Test(dataProvider = "byteBinaryOpMaskProvider") 1932 static void ORByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 1933 IntFunction<boolean[]> fm) { 1934 byte[] a = fa.apply(SPECIES.length()); 1935 byte[] b = fb.apply(SPECIES.length()); 1936 byte[] r = fr.apply(SPECIES.length()); 1937 boolean[] mask = fm.apply(SPECIES.length()); 1938 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1939 1940 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1941 for (int i = 0; i < a.length; i += SPECIES.length()) { 1942 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1943 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 1944 av.lanewise(VectorOperators.OR, bv, vmask).intoArray(r, i); 1945 } 1946 } 1947 1948 assertArraysEquals(r, a, b, mask, ByteMaxVectorTests::OR); 1949 } 1950 1951 static byte XOR(byte a, byte b) { 1952 return (byte)(a ^ b); 1953 } 1954 1955 @Test(dataProvider = "byteBinaryOpProvider") 1956 static void XORByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 1957 byte[] a = fa.apply(SPECIES.length()); 1958 byte[] b = fb.apply(SPECIES.length()); 1959 byte[] r = fr.apply(SPECIES.length()); 1960 1961 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1962 for (int i = 0; i < a.length; i += SPECIES.length()) { 1963 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1964 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 1965 av.lanewise(VectorOperators.XOR, bv).intoArray(r, i); 1966 } 1967 } 1968 1969 assertArraysEquals(r, a, b, ByteMaxVectorTests::XOR); 1970 } 1971 1972 @Test(dataProvider = "byteBinaryOpMaskProvider") 1973 static void XORByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 1974 IntFunction<boolean[]> fm) { 1975 byte[] a = fa.apply(SPECIES.length()); 1976 byte[] b = fb.apply(SPECIES.length()); 1977 byte[] r = fr.apply(SPECIES.length()); 1978 boolean[] mask = fm.apply(SPECIES.length()); 1979 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1980 1981 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1982 for (int i = 0; i < a.length; i += SPECIES.length()) { 1983 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 1984 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 1985 av.lanewise(VectorOperators.XOR, bv, vmask).intoArray(r, i); 1986 } 1987 } 1988 1989 assertArraysEquals(r, a, b, mask, ByteMaxVectorTests::XOR); 1990 } 1991 1992 @Test(dataProvider = "byteBinaryOpProvider") 1993 static void addByteMaxVectorTestsBroadcastSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 1994 byte[] a = fa.apply(SPECIES.length()); 1995 byte[] b = fb.apply(SPECIES.length()); 1996 byte[] r = fr.apply(SPECIES.length()); 1997 1998 for (int i = 0; i < a.length; i += SPECIES.length()) { 1999 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2000 av.add(b[i]).intoArray(r, i); 2001 } 2002 2003 assertBroadcastArraysEquals(r, a, b, ByteMaxVectorTests::add); 2004 } 2005 2006 @Test(dataProvider = "byteBinaryOpMaskProvider") 2007 static void addByteMaxVectorTestsBroadcastMaskedSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 2008 IntFunction<boolean[]> fm) { 2009 byte[] a = fa.apply(SPECIES.length()); 2010 byte[] b = fb.apply(SPECIES.length()); 2011 byte[] r = fr.apply(SPECIES.length()); 2012 boolean[] mask = fm.apply(SPECIES.length()); 2013 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2014 2015 for (int i = 0; i < a.length; i += SPECIES.length()) { 2016 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2017 av.add(b[i], vmask).intoArray(r, i); 2018 } 2019 2020 assertBroadcastArraysEquals(r, a, b, mask, ByteMaxVectorTests::add); 2021 } 2022 2023 @Test(dataProvider = "byteBinaryOpProvider") 2024 static void subByteMaxVectorTestsBroadcastSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 2025 byte[] a = fa.apply(SPECIES.length()); 2026 byte[] b = fb.apply(SPECIES.length()); 2027 byte[] r = fr.apply(SPECIES.length()); 2028 2029 for (int i = 0; i < a.length; i += SPECIES.length()) { 2030 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2031 av.sub(b[i]).intoArray(r, i); 2032 } 2033 2034 assertBroadcastArraysEquals(r, a, b, ByteMaxVectorTests::sub); 2035 } 2036 2037 @Test(dataProvider = "byteBinaryOpMaskProvider") 2038 static void subByteMaxVectorTestsBroadcastMaskedSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 2039 IntFunction<boolean[]> fm) { 2040 byte[] a = fa.apply(SPECIES.length()); 2041 byte[] b = fb.apply(SPECIES.length()); 2042 byte[] r = fr.apply(SPECIES.length()); 2043 boolean[] mask = fm.apply(SPECIES.length()); 2044 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2045 2046 for (int i = 0; i < a.length; i += SPECIES.length()) { 2047 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2048 av.sub(b[i], vmask).intoArray(r, i); 2049 } 2050 2051 assertBroadcastArraysEquals(r, a, b, mask, ByteMaxVectorTests::sub); 2052 } 2053 2054 @Test(dataProvider = "byteBinaryOpProvider") 2055 static void mulByteMaxVectorTestsBroadcastSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 2056 byte[] a = fa.apply(SPECIES.length()); 2057 byte[] b = fb.apply(SPECIES.length()); 2058 byte[] r = fr.apply(SPECIES.length()); 2059 2060 for (int i = 0; i < a.length; i += SPECIES.length()) { 2061 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2062 av.mul(b[i]).intoArray(r, i); 2063 } 2064 2065 assertBroadcastArraysEquals(r, a, b, ByteMaxVectorTests::mul); 2066 } 2067 2068 @Test(dataProvider = "byteBinaryOpMaskProvider") 2069 static void mulByteMaxVectorTestsBroadcastMaskedSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 2070 IntFunction<boolean[]> fm) { 2071 byte[] a = fa.apply(SPECIES.length()); 2072 byte[] b = fb.apply(SPECIES.length()); 2073 byte[] r = fr.apply(SPECIES.length()); 2074 boolean[] mask = fm.apply(SPECIES.length()); 2075 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2076 2077 for (int i = 0; i < a.length; i += SPECIES.length()) { 2078 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2079 av.mul(b[i], vmask).intoArray(r, i); 2080 } 2081 2082 assertBroadcastArraysEquals(r, a, b, mask, ByteMaxVectorTests::mul); 2083 } 2084 2085 @Test(dataProvider = "byteBinaryOpProvider") 2086 static void divByteMaxVectorTestsBroadcastSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 2087 byte[] a = fa.apply(SPECIES.length()); 2088 byte[] b = fb.apply(SPECIES.length()); 2089 byte[] r = fr.apply(SPECIES.length()); 2090 2091 replaceZero(b, (byte) 1); 2092 2093 for (int i = 0; i < a.length; i += SPECIES.length()) { 2094 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2095 av.div(b[i]).intoArray(r, i); 2096 } 2097 2098 assertBroadcastArraysEquals(r, a, b, ByteMaxVectorTests::div); 2099 } 2100 2101 @Test(dataProvider = "byteBinaryOpMaskProvider") 2102 static void divByteMaxVectorTestsBroadcastMaskedSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 2103 IntFunction<boolean[]> fm) { 2104 byte[] a = fa.apply(SPECIES.length()); 2105 byte[] b = fb.apply(SPECIES.length()); 2106 byte[] r = fr.apply(SPECIES.length()); 2107 boolean[] mask = fm.apply(SPECIES.length()); 2108 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2109 2110 replaceZero(b, (byte) 1); 2111 2112 for (int i = 0; i < a.length; i += SPECIES.length()) { 2113 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2114 av.div(b[i], vmask).intoArray(r, i); 2115 } 2116 2117 assertBroadcastArraysEquals(r, a, b, mask, ByteMaxVectorTests::div); 2118 } 2119 2120 @Test(dataProvider = "byteBinaryOpProvider") 2121 static void ORByteMaxVectorTestsBroadcastSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 2122 byte[] a = fa.apply(SPECIES.length()); 2123 byte[] b = fb.apply(SPECIES.length()); 2124 byte[] r = fr.apply(SPECIES.length()); 2125 2126 for (int i = 0; i < a.length; i += SPECIES.length()) { 2127 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2128 av.lanewise(VectorOperators.OR, b[i]).intoArray(r, i); 2129 } 2130 2131 assertBroadcastArraysEquals(r, a, b, ByteMaxVectorTests::OR); 2132 } 2133 2134 @Test(dataProvider = "byteBinaryOpProvider") 2135 static void orByteMaxVectorTestsBroadcastSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 2136 byte[] a = fa.apply(SPECIES.length()); 2137 byte[] b = fb.apply(SPECIES.length()); 2138 byte[] r = fr.apply(SPECIES.length()); 2139 2140 for (int i = 0; i < a.length; i += SPECIES.length()) { 2141 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2142 av.or(b[i]).intoArray(r, i); 2143 } 2144 2145 assertBroadcastArraysEquals(r, a, b, ByteMaxVectorTests::or); 2146 } 2147 2148 @Test(dataProvider = "byteBinaryOpMaskProvider") 2149 static void ORByteMaxVectorTestsBroadcastMaskedSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 2150 IntFunction<boolean[]> fm) { 2151 byte[] a = fa.apply(SPECIES.length()); 2152 byte[] b = fb.apply(SPECIES.length()); 2153 byte[] r = fr.apply(SPECIES.length()); 2154 boolean[] mask = fm.apply(SPECIES.length()); 2155 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2156 2157 for (int i = 0; i < a.length; i += SPECIES.length()) { 2158 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2159 av.lanewise(VectorOperators.OR, b[i], vmask).intoArray(r, i); 2160 } 2161 2162 assertBroadcastArraysEquals(r, a, b, mask, ByteMaxVectorTests::OR); 2163 } 2164 2165 @Test(dataProvider = "byteBinaryOpProvider") 2166 static void ANDByteMaxVectorTestsBroadcastSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 2167 byte[] a = fa.apply(SPECIES.length()); 2168 byte[] b = fb.apply(SPECIES.length()); 2169 byte[] r = fr.apply(SPECIES.length()); 2170 2171 for (int i = 0; i < a.length; i += SPECIES.length()) { 2172 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2173 av.lanewise(VectorOperators.AND, b[i]).intoArray(r, i); 2174 } 2175 2176 assertBroadcastArraysEquals(r, a, b, ByteMaxVectorTests::AND); 2177 } 2178 2179 @Test(dataProvider = "byteBinaryOpProvider") 2180 static void andByteMaxVectorTestsBroadcastSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 2181 byte[] a = fa.apply(SPECIES.length()); 2182 byte[] b = fb.apply(SPECIES.length()); 2183 byte[] r = fr.apply(SPECIES.length()); 2184 2185 for (int i = 0; i < a.length; i += SPECIES.length()) { 2186 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2187 av.and(b[i]).intoArray(r, i); 2188 } 2189 2190 assertBroadcastArraysEquals(r, a, b, ByteMaxVectorTests::and); 2191 } 2192 2193 @Test(dataProvider = "byteBinaryOpMaskProvider") 2194 static void ANDByteMaxVectorTestsBroadcastMaskedSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 2195 IntFunction<boolean[]> fm) { 2196 byte[] a = fa.apply(SPECIES.length()); 2197 byte[] b = fb.apply(SPECIES.length()); 2198 byte[] r = fr.apply(SPECIES.length()); 2199 boolean[] mask = fm.apply(SPECIES.length()); 2200 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2201 2202 for (int i = 0; i < a.length; i += SPECIES.length()) { 2203 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2204 av.lanewise(VectorOperators.AND, b[i], vmask).intoArray(r, i); 2205 } 2206 2207 assertBroadcastArraysEquals(r, a, b, mask, ByteMaxVectorTests::AND); 2208 } 2209 2210 @Test(dataProvider = "byteBinaryOpProvider") 2211 static void ORByteMaxVectorTestsBroadcastLongSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 2212 byte[] a = fa.apply(SPECIES.length()); 2213 byte[] b = fb.apply(SPECIES.length()); 2214 byte[] r = fr.apply(SPECIES.length()); 2215 2216 for (int i = 0; i < a.length; i += SPECIES.length()) { 2217 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2218 av.lanewise(VectorOperators.OR, (long)b[i]).intoArray(r, i); 2219 } 2220 2221 assertBroadcastLongArraysEquals(r, a, b, ByteMaxVectorTests::OR); 2222 } 2223 2224 @Test(dataProvider = "byteBinaryOpMaskProvider") 2225 static void ORByteMaxVectorTestsBroadcastMaskedLongSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 2226 IntFunction<boolean[]> fm) { 2227 byte[] a = fa.apply(SPECIES.length()); 2228 byte[] b = fb.apply(SPECIES.length()); 2229 byte[] r = fr.apply(SPECIES.length()); 2230 boolean[] mask = fm.apply(SPECIES.length()); 2231 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2232 2233 for (int i = 0; i < a.length; i += SPECIES.length()) { 2234 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2235 av.lanewise(VectorOperators.OR, (long)b[i], vmask).intoArray(r, i); 2236 } 2237 2238 assertBroadcastLongArraysEquals(r, a, b, mask, ByteMaxVectorTests::OR); 2239 } 2240 2241 @Test(dataProvider = "byteBinaryOpProvider") 2242 static void ADDByteMaxVectorTestsBroadcastLongSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 2243 byte[] a = fa.apply(SPECIES.length()); 2244 byte[] b = fb.apply(SPECIES.length()); 2245 byte[] r = fr.apply(SPECIES.length()); 2246 2247 for (int i = 0; i < a.length; i += SPECIES.length()) { 2248 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2249 av.lanewise(VectorOperators.ADD, (long)b[i]).intoArray(r, i); 2250 } 2251 2252 assertBroadcastLongArraysEquals(r, a, b, ByteMaxVectorTests::ADD); 2253 } 2254 2255 @Test(dataProvider = "byteBinaryOpMaskProvider") 2256 static void ADDByteMaxVectorTestsBroadcastMaskedLongSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 2257 IntFunction<boolean[]> fm) { 2258 byte[] a = fa.apply(SPECIES.length()); 2259 byte[] b = fb.apply(SPECIES.length()); 2260 byte[] r = fr.apply(SPECIES.length()); 2261 boolean[] mask = fm.apply(SPECIES.length()); 2262 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2263 2264 for (int i = 0; i < a.length; i += SPECIES.length()) { 2265 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2266 av.lanewise(VectorOperators.ADD, (long)b[i], vmask).intoArray(r, i); 2267 } 2268 2269 assertBroadcastLongArraysEquals(r, a, b, mask, ByteMaxVectorTests::ADD); 2270 } 2271 2272 static byte LSHL(byte a, byte b) { 2273 return (byte)((a << (b & 0x7))); 2274 } 2275 2276 @Test(dataProvider = "byteBinaryOpProvider") 2277 static void LSHLByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 2278 byte[] a = fa.apply(SPECIES.length()); 2279 byte[] b = fb.apply(SPECIES.length()); 2280 byte[] r = fr.apply(SPECIES.length()); 2281 2282 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2283 for (int i = 0; i < a.length; i += SPECIES.length()) { 2284 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2285 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 2286 av.lanewise(VectorOperators.LSHL, bv).intoArray(r, i); 2287 } 2288 } 2289 2290 assertArraysEquals(r, a, b, ByteMaxVectorTests::LSHL); 2291 } 2292 2293 @Test(dataProvider = "byteBinaryOpMaskProvider") 2294 static void LSHLByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 2295 IntFunction<boolean[]> fm) { 2296 byte[] a = fa.apply(SPECIES.length()); 2297 byte[] b = fb.apply(SPECIES.length()); 2298 byte[] r = fr.apply(SPECIES.length()); 2299 boolean[] mask = fm.apply(SPECIES.length()); 2300 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2301 2302 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2303 for (int i = 0; i < a.length; i += SPECIES.length()) { 2304 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2305 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 2306 av.lanewise(VectorOperators.LSHL, bv, vmask).intoArray(r, i); 2307 } 2308 } 2309 2310 assertArraysEquals(r, a, b, mask, ByteMaxVectorTests::LSHL); 2311 } 2312 2313 static byte ASHR(byte a, byte b) { 2314 return (byte)((a >> (b & 0x7))); 2315 } 2316 2317 @Test(dataProvider = "byteBinaryOpProvider") 2318 static void ASHRByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 2319 byte[] a = fa.apply(SPECIES.length()); 2320 byte[] b = fb.apply(SPECIES.length()); 2321 byte[] r = fr.apply(SPECIES.length()); 2322 2323 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2324 for (int i = 0; i < a.length; i += SPECIES.length()) { 2325 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2326 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 2327 av.lanewise(VectorOperators.ASHR, bv).intoArray(r, i); 2328 } 2329 } 2330 2331 assertArraysEquals(r, a, b, ByteMaxVectorTests::ASHR); 2332 } 2333 2334 @Test(dataProvider = "byteBinaryOpMaskProvider") 2335 static void ASHRByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 2336 IntFunction<boolean[]> fm) { 2337 byte[] a = fa.apply(SPECIES.length()); 2338 byte[] b = fb.apply(SPECIES.length()); 2339 byte[] r = fr.apply(SPECIES.length()); 2340 boolean[] mask = fm.apply(SPECIES.length()); 2341 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2342 2343 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2344 for (int i = 0; i < a.length; i += SPECIES.length()) { 2345 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2346 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 2347 av.lanewise(VectorOperators.ASHR, bv, vmask).intoArray(r, i); 2348 } 2349 } 2350 2351 assertArraysEquals(r, a, b, mask, ByteMaxVectorTests::ASHR); 2352 } 2353 2354 static byte LSHR(byte a, byte b) { 2355 return (byte)(((a & 0xFF) >>> (b & 0x7))); 2356 } 2357 2358 @Test(dataProvider = "byteBinaryOpProvider") 2359 static void LSHRByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 2360 byte[] a = fa.apply(SPECIES.length()); 2361 byte[] b = fb.apply(SPECIES.length()); 2362 byte[] r = fr.apply(SPECIES.length()); 2363 2364 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2365 for (int i = 0; i < a.length; i += SPECIES.length()) { 2366 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2367 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 2368 av.lanewise(VectorOperators.LSHR, bv).intoArray(r, i); 2369 } 2370 } 2371 2372 assertArraysEquals(r, a, b, ByteMaxVectorTests::LSHR); 2373 } 2374 2375 @Test(dataProvider = "byteBinaryOpMaskProvider") 2376 static void LSHRByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 2377 IntFunction<boolean[]> fm) { 2378 byte[] a = fa.apply(SPECIES.length()); 2379 byte[] b = fb.apply(SPECIES.length()); 2380 byte[] r = fr.apply(SPECIES.length()); 2381 boolean[] mask = fm.apply(SPECIES.length()); 2382 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2383 2384 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2385 for (int i = 0; i < a.length; i += SPECIES.length()) { 2386 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2387 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 2388 av.lanewise(VectorOperators.LSHR, bv, vmask).intoArray(r, i); 2389 } 2390 } 2391 2392 assertArraysEquals(r, a, b, mask, ByteMaxVectorTests::LSHR); 2393 } 2394 2395 static byte LSHL_unary(byte a, byte b) { 2396 return (byte)((a << (b & 7))); 2397 } 2398 2399 @Test(dataProvider = "byteBinaryOpProvider") 2400 static void LSHLByteMaxVectorTestsScalarShift(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 2401 byte[] a = fa.apply(SPECIES.length()); 2402 byte[] b = fb.apply(SPECIES.length()); 2403 byte[] r = fr.apply(SPECIES.length()); 2404 2405 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2406 for (int i = 0; i < a.length; i += SPECIES.length()) { 2407 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2408 av.lanewise(VectorOperators.LSHL, (int)b[i]).intoArray(r, i); 2409 } 2410 } 2411 2412 assertShiftArraysEquals(r, a, b, ByteMaxVectorTests::LSHL_unary); 2413 } 2414 2415 @Test(dataProvider = "byteBinaryOpMaskProvider") 2416 static void LSHLByteMaxVectorTestsScalarShiftMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 2417 IntFunction<boolean[]> fm) { 2418 byte[] a = fa.apply(SPECIES.length()); 2419 byte[] b = fb.apply(SPECIES.length()); 2420 byte[] r = fr.apply(SPECIES.length()); 2421 boolean[] mask = fm.apply(SPECIES.length()); 2422 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2423 2424 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2425 for (int i = 0; i < a.length; i += SPECIES.length()) { 2426 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2427 av.lanewise(VectorOperators.LSHL, (int)b[i], vmask).intoArray(r, i); 2428 } 2429 } 2430 2431 assertShiftArraysEquals(r, a, b, mask, ByteMaxVectorTests::LSHL_unary); 2432 } 2433 2434 static byte LSHR_unary(byte a, byte b) { 2435 return (byte)(((a & 0xFF) >>> (b & 7))); 2436 } 2437 2438 @Test(dataProvider = "byteBinaryOpProvider") 2439 static void LSHRByteMaxVectorTestsScalarShift(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 2440 byte[] a = fa.apply(SPECIES.length()); 2441 byte[] b = fb.apply(SPECIES.length()); 2442 byte[] r = fr.apply(SPECIES.length()); 2443 2444 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2445 for (int i = 0; i < a.length; i += SPECIES.length()) { 2446 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2447 av.lanewise(VectorOperators.LSHR, (int)b[i]).intoArray(r, i); 2448 } 2449 } 2450 2451 assertShiftArraysEquals(r, a, b, ByteMaxVectorTests::LSHR_unary); 2452 } 2453 2454 @Test(dataProvider = "byteBinaryOpMaskProvider") 2455 static void LSHRByteMaxVectorTestsScalarShiftMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 2456 IntFunction<boolean[]> fm) { 2457 byte[] a = fa.apply(SPECIES.length()); 2458 byte[] b = fb.apply(SPECIES.length()); 2459 byte[] r = fr.apply(SPECIES.length()); 2460 boolean[] mask = fm.apply(SPECIES.length()); 2461 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2462 2463 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2464 for (int i = 0; i < a.length; i += SPECIES.length()) { 2465 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2466 av.lanewise(VectorOperators.LSHR, (int)b[i], vmask).intoArray(r, i); 2467 } 2468 } 2469 2470 assertShiftArraysEquals(r, a, b, mask, ByteMaxVectorTests::LSHR_unary); 2471 } 2472 2473 static byte ASHR_unary(byte a, byte b) { 2474 return (byte)((a >> (b & 7))); 2475 } 2476 2477 @Test(dataProvider = "byteBinaryOpProvider") 2478 static void ASHRByteMaxVectorTestsScalarShift(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 2479 byte[] a = fa.apply(SPECIES.length()); 2480 byte[] b = fb.apply(SPECIES.length()); 2481 byte[] r = fr.apply(SPECIES.length()); 2482 2483 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2484 for (int i = 0; i < a.length; i += SPECIES.length()) { 2485 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2486 av.lanewise(VectorOperators.ASHR, (int)b[i]).intoArray(r, i); 2487 } 2488 } 2489 2490 assertShiftArraysEquals(r, a, b, ByteMaxVectorTests::ASHR_unary); 2491 } 2492 2493 @Test(dataProvider = "byteBinaryOpMaskProvider") 2494 static void ASHRByteMaxVectorTestsScalarShiftMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 2495 IntFunction<boolean[]> fm) { 2496 byte[] a = fa.apply(SPECIES.length()); 2497 byte[] b = fb.apply(SPECIES.length()); 2498 byte[] r = fr.apply(SPECIES.length()); 2499 boolean[] mask = fm.apply(SPECIES.length()); 2500 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2501 2502 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2503 for (int i = 0; i < a.length; i += SPECIES.length()) { 2504 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2505 av.lanewise(VectorOperators.ASHR, (int)b[i], vmask).intoArray(r, i); 2506 } 2507 } 2508 2509 assertShiftArraysEquals(r, a, b, mask, ByteMaxVectorTests::ASHR_unary); 2510 } 2511 2512 static byte ROR(byte a, byte b) { 2513 return (byte)(ROR_scalar(a,b)); 2514 } 2515 2516 @Test(dataProvider = "byteBinaryOpProvider") 2517 static void RORByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 2518 byte[] a = fa.apply(SPECIES.length()); 2519 byte[] b = fb.apply(SPECIES.length()); 2520 byte[] r = fr.apply(SPECIES.length()); 2521 2522 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2523 for (int i = 0; i < a.length; i += SPECIES.length()) { 2524 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2525 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 2526 av.lanewise(VectorOperators.ROR, bv).intoArray(r, i); 2527 } 2528 } 2529 2530 assertArraysEquals(r, a, b, ByteMaxVectorTests::ROR); 2531 } 2532 2533 @Test(dataProvider = "byteBinaryOpMaskProvider") 2534 static void RORByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 2535 IntFunction<boolean[]> fm) { 2536 byte[] a = fa.apply(SPECIES.length()); 2537 byte[] b = fb.apply(SPECIES.length()); 2538 byte[] r = fr.apply(SPECIES.length()); 2539 boolean[] mask = fm.apply(SPECIES.length()); 2540 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2541 2542 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2543 for (int i = 0; i < a.length; i += SPECIES.length()) { 2544 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2545 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 2546 av.lanewise(VectorOperators.ROR, bv, vmask).intoArray(r, i); 2547 } 2548 } 2549 2550 assertArraysEquals(r, a, b, mask, ByteMaxVectorTests::ROR); 2551 } 2552 2553 static byte ROL(byte a, byte b) { 2554 return (byte)(ROL_scalar(a,b)); 2555 } 2556 2557 @Test(dataProvider = "byteBinaryOpProvider") 2558 static void ROLByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 2559 byte[] a = fa.apply(SPECIES.length()); 2560 byte[] b = fb.apply(SPECIES.length()); 2561 byte[] r = fr.apply(SPECIES.length()); 2562 2563 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2564 for (int i = 0; i < a.length; i += SPECIES.length()) { 2565 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2566 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 2567 av.lanewise(VectorOperators.ROL, bv).intoArray(r, i); 2568 } 2569 } 2570 2571 assertArraysEquals(r, a, b, ByteMaxVectorTests::ROL); 2572 } 2573 2574 @Test(dataProvider = "byteBinaryOpMaskProvider") 2575 static void ROLByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 2576 IntFunction<boolean[]> fm) { 2577 byte[] a = fa.apply(SPECIES.length()); 2578 byte[] b = fb.apply(SPECIES.length()); 2579 byte[] r = fr.apply(SPECIES.length()); 2580 boolean[] mask = fm.apply(SPECIES.length()); 2581 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2582 2583 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2584 for (int i = 0; i < a.length; i += SPECIES.length()) { 2585 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2586 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 2587 av.lanewise(VectorOperators.ROL, bv, vmask).intoArray(r, i); 2588 } 2589 } 2590 2591 assertArraysEquals(r, a, b, mask, ByteMaxVectorTests::ROL); 2592 } 2593 2594 static byte ROR_unary(byte a, byte b) { 2595 return (byte)(ROR_scalar(a, b)); 2596 } 2597 2598 @Test(dataProvider = "byteBinaryOpProvider") 2599 static void RORByteMaxVectorTestsScalarShift(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 2600 byte[] a = fa.apply(SPECIES.length()); 2601 byte[] b = fb.apply(SPECIES.length()); 2602 byte[] r = fr.apply(SPECIES.length()); 2603 2604 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2605 for (int i = 0; i < a.length; i += SPECIES.length()) { 2606 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2607 av.lanewise(VectorOperators.ROR, (int)b[i]).intoArray(r, i); 2608 } 2609 } 2610 2611 assertShiftArraysEquals(r, a, b, ByteMaxVectorTests::ROR_unary); 2612 } 2613 2614 @Test(dataProvider = "byteBinaryOpMaskProvider") 2615 static void RORByteMaxVectorTestsScalarShiftMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 2616 IntFunction<boolean[]> fm) { 2617 byte[] a = fa.apply(SPECIES.length()); 2618 byte[] b = fb.apply(SPECIES.length()); 2619 byte[] r = fr.apply(SPECIES.length()); 2620 boolean[] mask = fm.apply(SPECIES.length()); 2621 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2622 2623 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2624 for (int i = 0; i < a.length; i += SPECIES.length()) { 2625 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2626 av.lanewise(VectorOperators.ROR, (int)b[i], vmask).intoArray(r, i); 2627 } 2628 } 2629 2630 assertShiftArraysEquals(r, a, b, mask, ByteMaxVectorTests::ROR_unary); 2631 } 2632 2633 static byte ROL_unary(byte a, byte b) { 2634 return (byte)(ROL_scalar(a, b)); 2635 } 2636 2637 @Test(dataProvider = "byteBinaryOpProvider") 2638 static void ROLByteMaxVectorTestsScalarShift(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 2639 byte[] a = fa.apply(SPECIES.length()); 2640 byte[] b = fb.apply(SPECIES.length()); 2641 byte[] r = fr.apply(SPECIES.length()); 2642 2643 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2644 for (int i = 0; i < a.length; i += SPECIES.length()) { 2645 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2646 av.lanewise(VectorOperators.ROL, (int)b[i]).intoArray(r, i); 2647 } 2648 } 2649 2650 assertShiftArraysEquals(r, a, b, ByteMaxVectorTests::ROL_unary); 2651 } 2652 2653 @Test(dataProvider = "byteBinaryOpMaskProvider") 2654 static void ROLByteMaxVectorTestsScalarShiftMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 2655 IntFunction<boolean[]> fm) { 2656 byte[] a = fa.apply(SPECIES.length()); 2657 byte[] b = fb.apply(SPECIES.length()); 2658 byte[] r = fr.apply(SPECIES.length()); 2659 boolean[] mask = fm.apply(SPECIES.length()); 2660 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2661 2662 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2663 for (int i = 0; i < a.length; i += SPECIES.length()) { 2664 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2665 av.lanewise(VectorOperators.ROL, (int)b[i], vmask).intoArray(r, i); 2666 } 2667 } 2668 2669 assertShiftArraysEquals(r, a, b, mask, ByteMaxVectorTests::ROL_unary); 2670 } 2671 static byte LSHR_binary_const(byte a) { 2672 return (byte)(((a & 0xFF) >>> CONST_SHIFT)); 2673 } 2674 2675 @Test(dataProvider = "byteUnaryOpProvider") 2676 static void LSHRByteMaxVectorTestsScalarShiftConst(IntFunction<byte[]> fa) { 2677 byte[] a = fa.apply(SPECIES.length()); 2678 byte[] r = fr.apply(SPECIES.length()); 2679 2680 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2681 for (int i = 0; i < a.length; i += SPECIES.length()) { 2682 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2683 av.lanewise(VectorOperators.LSHR, CONST_SHIFT).intoArray(r, i); 2684 } 2685 } 2686 2687 assertShiftConstEquals(r, a, ByteMaxVectorTests::LSHR_binary_const); 2688 } 2689 2690 @Test(dataProvider = "byteUnaryOpMaskProvider") 2691 static void LSHRByteMaxVectorTestsScalarShiftMaskedConst(IntFunction<byte[]> fa, 2692 IntFunction<boolean[]> fm) { 2693 byte[] a = fa.apply(SPECIES.length()); 2694 byte[] r = fr.apply(SPECIES.length()); 2695 boolean[] mask = fm.apply(SPECIES.length()); 2696 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2697 2698 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2699 for (int i = 0; i < a.length; i += SPECIES.length()) { 2700 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2701 av.lanewise(VectorOperators.LSHR, CONST_SHIFT, vmask).intoArray(r, i); 2702 } 2703 } 2704 2705 assertShiftConstEquals(r, a, mask, ByteMaxVectorTests::LSHR_binary_const); 2706 } 2707 2708 static byte LSHL_binary_const(byte a) { 2709 return (byte)((a << CONST_SHIFT)); 2710 } 2711 2712 @Test(dataProvider = "byteUnaryOpProvider") 2713 static void LSHLByteMaxVectorTestsScalarShiftConst(IntFunction<byte[]> fa) { 2714 byte[] a = fa.apply(SPECIES.length()); 2715 byte[] r = fr.apply(SPECIES.length()); 2716 2717 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2718 for (int i = 0; i < a.length; i += SPECIES.length()) { 2719 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2720 av.lanewise(VectorOperators.LSHL, CONST_SHIFT).intoArray(r, i); 2721 } 2722 } 2723 2724 assertShiftConstEquals(r, a, ByteMaxVectorTests::LSHL_binary_const); 2725 } 2726 2727 @Test(dataProvider = "byteUnaryOpMaskProvider") 2728 static void LSHLByteMaxVectorTestsScalarShiftMaskedConst(IntFunction<byte[]> fa, 2729 IntFunction<boolean[]> fm) { 2730 byte[] a = fa.apply(SPECIES.length()); 2731 byte[] r = fr.apply(SPECIES.length()); 2732 boolean[] mask = fm.apply(SPECIES.length()); 2733 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2734 2735 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2736 for (int i = 0; i < a.length; i += SPECIES.length()) { 2737 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2738 av.lanewise(VectorOperators.LSHL, CONST_SHIFT, vmask).intoArray(r, i); 2739 } 2740 } 2741 2742 assertShiftConstEquals(r, a, mask, ByteMaxVectorTests::LSHL_binary_const); 2743 } 2744 2745 static byte ASHR_binary_const(byte a) { 2746 return (byte)((a >> CONST_SHIFT)); 2747 } 2748 2749 @Test(dataProvider = "byteUnaryOpProvider") 2750 static void ASHRByteMaxVectorTestsScalarShiftConst(IntFunction<byte[]> fa) { 2751 byte[] a = fa.apply(SPECIES.length()); 2752 byte[] r = fr.apply(SPECIES.length()); 2753 2754 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2755 for (int i = 0; i < a.length; i += SPECIES.length()) { 2756 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2757 av.lanewise(VectorOperators.ASHR, CONST_SHIFT).intoArray(r, i); 2758 } 2759 } 2760 2761 assertShiftConstEquals(r, a, ByteMaxVectorTests::ASHR_binary_const); 2762 } 2763 2764 @Test(dataProvider = "byteUnaryOpMaskProvider") 2765 static void ASHRByteMaxVectorTestsScalarShiftMaskedConst(IntFunction<byte[]> fa, 2766 IntFunction<boolean[]> fm) { 2767 byte[] a = fa.apply(SPECIES.length()); 2768 byte[] r = fr.apply(SPECIES.length()); 2769 boolean[] mask = fm.apply(SPECIES.length()); 2770 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2771 2772 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2773 for (int i = 0; i < a.length; i += SPECIES.length()) { 2774 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2775 av.lanewise(VectorOperators.ASHR, CONST_SHIFT, vmask).intoArray(r, i); 2776 } 2777 } 2778 2779 assertShiftConstEquals(r, a, mask, ByteMaxVectorTests::ASHR_binary_const); 2780 } 2781 2782 static byte ROR_binary_const(byte a) { 2783 return (byte)(ROR_scalar(a, CONST_SHIFT)); 2784 } 2785 2786 @Test(dataProvider = "byteUnaryOpProvider") 2787 static void RORByteMaxVectorTestsScalarShiftConst(IntFunction<byte[]> fa) { 2788 byte[] a = fa.apply(SPECIES.length()); 2789 byte[] r = fr.apply(SPECIES.length()); 2790 2791 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2792 for (int i = 0; i < a.length; i += SPECIES.length()) { 2793 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2794 av.lanewise(VectorOperators.ROR, CONST_SHIFT).intoArray(r, i); 2795 } 2796 } 2797 2798 assertShiftConstEquals(r, a, ByteMaxVectorTests::ROR_binary_const); 2799 } 2800 2801 @Test(dataProvider = "byteUnaryOpMaskProvider") 2802 static void RORByteMaxVectorTestsScalarShiftMaskedConst(IntFunction<byte[]> fa, 2803 IntFunction<boolean[]> fm) { 2804 byte[] a = fa.apply(SPECIES.length()); 2805 byte[] r = fr.apply(SPECIES.length()); 2806 boolean[] mask = fm.apply(SPECIES.length()); 2807 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2808 2809 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2810 for (int i = 0; i < a.length; i += SPECIES.length()) { 2811 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2812 av.lanewise(VectorOperators.ROR, CONST_SHIFT, vmask).intoArray(r, i); 2813 } 2814 } 2815 2816 assertShiftConstEquals(r, a, mask, ByteMaxVectorTests::ROR_binary_const); 2817 } 2818 2819 static byte ROL_binary_const(byte a) { 2820 return (byte)(ROL_scalar(a, CONST_SHIFT)); 2821 } 2822 2823 @Test(dataProvider = "byteUnaryOpProvider") 2824 static void ROLByteMaxVectorTestsScalarShiftConst(IntFunction<byte[]> fa) { 2825 byte[] a = fa.apply(SPECIES.length()); 2826 byte[] r = fr.apply(SPECIES.length()); 2827 2828 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2829 for (int i = 0; i < a.length; i += SPECIES.length()) { 2830 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2831 av.lanewise(VectorOperators.ROL, CONST_SHIFT).intoArray(r, i); 2832 } 2833 } 2834 2835 assertShiftConstEquals(r, a, ByteMaxVectorTests::ROL_binary_const); 2836 } 2837 2838 @Test(dataProvider = "byteUnaryOpMaskProvider") 2839 static void ROLByteMaxVectorTestsScalarShiftMaskedConst(IntFunction<byte[]> fa, 2840 IntFunction<boolean[]> fm) { 2841 byte[] a = fa.apply(SPECIES.length()); 2842 byte[] r = fr.apply(SPECIES.length()); 2843 boolean[] mask = fm.apply(SPECIES.length()); 2844 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2845 2846 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2847 for (int i = 0; i < a.length; i += SPECIES.length()) { 2848 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2849 av.lanewise(VectorOperators.ROL, CONST_SHIFT, vmask).intoArray(r, i); 2850 } 2851 } 2852 2853 assertShiftConstEquals(r, a, mask, ByteMaxVectorTests::ROL_binary_const); 2854 } 2855 2856 2857 static byte MIN(byte a, byte b) { 2858 return (byte)(Math.min(a, b)); 2859 } 2860 2861 @Test(dataProvider = "byteBinaryOpProvider") 2862 static void MINByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 2863 byte[] a = fa.apply(SPECIES.length()); 2864 byte[] b = fb.apply(SPECIES.length()); 2865 byte[] r = fr.apply(SPECIES.length()); 2866 2867 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2868 for (int i = 0; i < a.length; i += SPECIES.length()) { 2869 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2870 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 2871 av.lanewise(VectorOperators.MIN, bv).intoArray(r, i); 2872 } 2873 } 2874 2875 assertArraysEquals(r, a, b, ByteMaxVectorTests::MIN); 2876 } 2877 2878 static byte min(byte a, byte b) { 2879 return (byte)(Math.min(a, b)); 2880 } 2881 2882 @Test(dataProvider = "byteBinaryOpProvider") 2883 static void minByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 2884 byte[] a = fa.apply(SPECIES.length()); 2885 byte[] b = fb.apply(SPECIES.length()); 2886 byte[] r = fr.apply(SPECIES.length()); 2887 2888 for (int i = 0; i < a.length; i += SPECIES.length()) { 2889 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2890 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 2891 av.min(bv).intoArray(r, i); 2892 } 2893 2894 assertArraysEquals(r, a, b, ByteMaxVectorTests::min); 2895 } 2896 2897 static byte MAX(byte a, byte b) { 2898 return (byte)(Math.max(a, b)); 2899 } 2900 2901 @Test(dataProvider = "byteBinaryOpProvider") 2902 static void MAXByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 2903 byte[] a = fa.apply(SPECIES.length()); 2904 byte[] b = fb.apply(SPECIES.length()); 2905 byte[] r = fr.apply(SPECIES.length()); 2906 2907 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2908 for (int i = 0; i < a.length; i += SPECIES.length()) { 2909 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2910 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 2911 av.lanewise(VectorOperators.MAX, bv).intoArray(r, i); 2912 } 2913 } 2914 2915 assertArraysEquals(r, a, b, ByteMaxVectorTests::MAX); 2916 } 2917 2918 static byte max(byte a, byte b) { 2919 return (byte)(Math.max(a, b)); 2920 } 2921 2922 @Test(dataProvider = "byteBinaryOpProvider") 2923 static void maxByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 2924 byte[] a = fa.apply(SPECIES.length()); 2925 byte[] b = fb.apply(SPECIES.length()); 2926 byte[] r = fr.apply(SPECIES.length()); 2927 2928 for (int i = 0; i < a.length; i += SPECIES.length()) { 2929 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2930 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 2931 av.max(bv).intoArray(r, i); 2932 } 2933 2934 assertArraysEquals(r, a, b, ByteMaxVectorTests::max); 2935 } 2936 2937 @Test(dataProvider = "byteBinaryOpProvider") 2938 static void MINByteMaxVectorTestsBroadcastSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 2939 byte[] a = fa.apply(SPECIES.length()); 2940 byte[] b = fb.apply(SPECIES.length()); 2941 byte[] r = fr.apply(SPECIES.length()); 2942 2943 for (int i = 0; i < a.length; i += SPECIES.length()) { 2944 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2945 av.lanewise(VectorOperators.MIN, b[i]).intoArray(r, i); 2946 } 2947 2948 assertBroadcastArraysEquals(r, a, b, ByteMaxVectorTests::MIN); 2949 } 2950 2951 @Test(dataProvider = "byteBinaryOpProvider") 2952 static void minByteMaxVectorTestsBroadcastSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 2953 byte[] a = fa.apply(SPECIES.length()); 2954 byte[] b = fb.apply(SPECIES.length()); 2955 byte[] r = fr.apply(SPECIES.length()); 2956 2957 for (int i = 0; i < a.length; i += SPECIES.length()) { 2958 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2959 av.min(b[i]).intoArray(r, i); 2960 } 2961 2962 assertBroadcastArraysEquals(r, a, b, ByteMaxVectorTests::min); 2963 } 2964 2965 @Test(dataProvider = "byteBinaryOpProvider") 2966 static void MAXByteMaxVectorTestsBroadcastSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 2967 byte[] a = fa.apply(SPECIES.length()); 2968 byte[] b = fb.apply(SPECIES.length()); 2969 byte[] r = fr.apply(SPECIES.length()); 2970 2971 for (int i = 0; i < a.length; i += SPECIES.length()) { 2972 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2973 av.lanewise(VectorOperators.MAX, b[i]).intoArray(r, i); 2974 } 2975 2976 assertBroadcastArraysEquals(r, a, b, ByteMaxVectorTests::MAX); 2977 } 2978 2979 @Test(dataProvider = "byteBinaryOpProvider") 2980 static void maxByteMaxVectorTestsBroadcastSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 2981 byte[] a = fa.apply(SPECIES.length()); 2982 byte[] b = fb.apply(SPECIES.length()); 2983 byte[] r = fr.apply(SPECIES.length()); 2984 2985 for (int i = 0; i < a.length; i += SPECIES.length()) { 2986 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 2987 av.max(b[i]).intoArray(r, i); 2988 } 2989 2990 assertBroadcastArraysEquals(r, a, b, ByteMaxVectorTests::max); 2991 } 2992 2993 static byte ANDReduce(byte[] a, int idx) { 2994 byte res = -1; 2995 for (int i = idx; i < (idx + SPECIES.length()); i++) { 2996 res &= a[i]; 2997 } 2998 2999 return res; 3000 } 3001 3002 static byte ANDReduceAll(byte[] a) { 3003 byte res = -1; 3004 for (int i = 0; i < a.length; i += SPECIES.length()) { 3005 res &= ANDReduce(a, i); 3006 } 3007 3008 return res; 3009 } 3010 3011 @Test(dataProvider = "byteUnaryOpProvider") 3012 static void ANDReduceByteMaxVectorTests(IntFunction<byte[]> fa) { 3013 byte[] a = fa.apply(SPECIES.length()); 3014 byte[] r = fr.apply(SPECIES.length()); 3015 byte ra = -1; 3016 3017 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3018 for (int i = 0; i < a.length; i += SPECIES.length()) { 3019 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 3020 r[i] = av.reduceLanes(VectorOperators.AND); 3021 } 3022 } 3023 3024 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3025 ra = -1; 3026 for (int i = 0; i < a.length; i += SPECIES.length()) { 3027 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 3028 ra &= av.reduceLanes(VectorOperators.AND); 3029 } 3030 } 3031 3032 assertReductionArraysEquals(r, ra, a, 3033 ByteMaxVectorTests::ANDReduce, ByteMaxVectorTests::ANDReduceAll); 3034 } 3035 3036 static byte ANDReduceMasked(byte[] a, int idx, boolean[] mask) { 3037 byte res = -1; 3038 for (int i = idx; i < (idx + SPECIES.length()); i++) { 3039 if (mask[i % SPECIES.length()]) 3040 res &= a[i]; 3041 } 3042 3043 return res; 3044 } 3045 3046 static byte ANDReduceAllMasked(byte[] a, boolean[] mask) { 3047 byte res = -1; 3048 for (int i = 0; i < a.length; i += SPECIES.length()) { 3049 res &= ANDReduceMasked(a, i, mask); 3050 } 3051 3052 return res; 3053 } 3054 3055 @Test(dataProvider = "byteUnaryOpMaskProvider") 3056 static void ANDReduceByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<boolean[]> fm) { 3057 byte[] a = fa.apply(SPECIES.length()); 3058 byte[] r = fr.apply(SPECIES.length()); 3059 boolean[] mask = fm.apply(SPECIES.length()); 3060 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3061 byte ra = -1; 3062 3063 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3064 for (int i = 0; i < a.length; i += SPECIES.length()) { 3065 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 3066 r[i] = av.reduceLanes(VectorOperators.AND, vmask); 3067 } 3068 } 3069 3070 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3071 ra = -1; 3072 for (int i = 0; i < a.length; i += SPECIES.length()) { 3073 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 3074 ra &= av.reduceLanes(VectorOperators.AND, vmask); 3075 } 3076 } 3077 3078 assertReductionArraysEqualsMasked(r, ra, a, mask, 3079 ByteMaxVectorTests::ANDReduceMasked, ByteMaxVectorTests::ANDReduceAllMasked); 3080 } 3081 3082 static byte ORReduce(byte[] a, int idx) { 3083 byte res = 0; 3084 for (int i = idx; i < (idx + SPECIES.length()); i++) { 3085 res |= a[i]; 3086 } 3087 3088 return res; 3089 } 3090 3091 static byte ORReduceAll(byte[] a) { 3092 byte res = 0; 3093 for (int i = 0; i < a.length; i += SPECIES.length()) { 3094 res |= ORReduce(a, i); 3095 } 3096 3097 return res; 3098 } 3099 3100 @Test(dataProvider = "byteUnaryOpProvider") 3101 static void ORReduceByteMaxVectorTests(IntFunction<byte[]> fa) { 3102 byte[] a = fa.apply(SPECIES.length()); 3103 byte[] r = fr.apply(SPECIES.length()); 3104 byte ra = 0; 3105 3106 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3107 for (int i = 0; i < a.length; i += SPECIES.length()) { 3108 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 3109 r[i] = av.reduceLanes(VectorOperators.OR); 3110 } 3111 } 3112 3113 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3114 ra = 0; 3115 for (int i = 0; i < a.length; i += SPECIES.length()) { 3116 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 3117 ra |= av.reduceLanes(VectorOperators.OR); 3118 } 3119 } 3120 3121 assertReductionArraysEquals(r, ra, a, 3122 ByteMaxVectorTests::ORReduce, ByteMaxVectorTests::ORReduceAll); 3123 } 3124 3125 static byte ORReduceMasked(byte[] a, int idx, boolean[] mask) { 3126 byte res = 0; 3127 for (int i = idx; i < (idx + SPECIES.length()); i++) { 3128 if (mask[i % SPECIES.length()]) 3129 res |= a[i]; 3130 } 3131 3132 return res; 3133 } 3134 3135 static byte ORReduceAllMasked(byte[] a, boolean[] mask) { 3136 byte res = 0; 3137 for (int i = 0; i < a.length; i += SPECIES.length()) { 3138 res |= ORReduceMasked(a, i, mask); 3139 } 3140 3141 return res; 3142 } 3143 3144 @Test(dataProvider = "byteUnaryOpMaskProvider") 3145 static void ORReduceByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<boolean[]> fm) { 3146 byte[] a = fa.apply(SPECIES.length()); 3147 byte[] r = fr.apply(SPECIES.length()); 3148 boolean[] mask = fm.apply(SPECIES.length()); 3149 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3150 byte ra = 0; 3151 3152 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3153 for (int i = 0; i < a.length; i += SPECIES.length()) { 3154 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 3155 r[i] = av.reduceLanes(VectorOperators.OR, vmask); 3156 } 3157 } 3158 3159 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3160 ra = 0; 3161 for (int i = 0; i < a.length; i += SPECIES.length()) { 3162 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 3163 ra |= av.reduceLanes(VectorOperators.OR, vmask); 3164 } 3165 } 3166 3167 assertReductionArraysEqualsMasked(r, ra, a, mask, 3168 ByteMaxVectorTests::ORReduceMasked, ByteMaxVectorTests::ORReduceAllMasked); 3169 } 3170 3171 static byte XORReduce(byte[] a, int idx) { 3172 byte res = 0; 3173 for (int i = idx; i < (idx + SPECIES.length()); i++) { 3174 res ^= a[i]; 3175 } 3176 3177 return res; 3178 } 3179 3180 static byte XORReduceAll(byte[] a) { 3181 byte res = 0; 3182 for (int i = 0; i < a.length; i += SPECIES.length()) { 3183 res ^= XORReduce(a, i); 3184 } 3185 3186 return res; 3187 } 3188 3189 @Test(dataProvider = "byteUnaryOpProvider") 3190 static void XORReduceByteMaxVectorTests(IntFunction<byte[]> fa) { 3191 byte[] a = fa.apply(SPECIES.length()); 3192 byte[] r = fr.apply(SPECIES.length()); 3193 byte ra = 0; 3194 3195 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3196 for (int i = 0; i < a.length; i += SPECIES.length()) { 3197 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 3198 r[i] = av.reduceLanes(VectorOperators.XOR); 3199 } 3200 } 3201 3202 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3203 ra = 0; 3204 for (int i = 0; i < a.length; i += SPECIES.length()) { 3205 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 3206 ra ^= av.reduceLanes(VectorOperators.XOR); 3207 } 3208 } 3209 3210 assertReductionArraysEquals(r, ra, a, 3211 ByteMaxVectorTests::XORReduce, ByteMaxVectorTests::XORReduceAll); 3212 } 3213 3214 static byte XORReduceMasked(byte[] a, int idx, boolean[] mask) { 3215 byte res = 0; 3216 for (int i = idx; i < (idx + SPECIES.length()); i++) { 3217 if (mask[i % SPECIES.length()]) 3218 res ^= a[i]; 3219 } 3220 3221 return res; 3222 } 3223 3224 static byte XORReduceAllMasked(byte[] a, boolean[] mask) { 3225 byte res = 0; 3226 for (int i = 0; i < a.length; i += SPECIES.length()) { 3227 res ^= XORReduceMasked(a, i, mask); 3228 } 3229 3230 return res; 3231 } 3232 3233 @Test(dataProvider = "byteUnaryOpMaskProvider") 3234 static void XORReduceByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<boolean[]> fm) { 3235 byte[] a = fa.apply(SPECIES.length()); 3236 byte[] r = fr.apply(SPECIES.length()); 3237 boolean[] mask = fm.apply(SPECIES.length()); 3238 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3239 byte ra = 0; 3240 3241 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3242 for (int i = 0; i < a.length; i += SPECIES.length()) { 3243 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 3244 r[i] = av.reduceLanes(VectorOperators.XOR, vmask); 3245 } 3246 } 3247 3248 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3249 ra = 0; 3250 for (int i = 0; i < a.length; i += SPECIES.length()) { 3251 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 3252 ra ^= av.reduceLanes(VectorOperators.XOR, vmask); 3253 } 3254 } 3255 3256 assertReductionArraysEqualsMasked(r, ra, a, mask, 3257 ByteMaxVectorTests::XORReduceMasked, ByteMaxVectorTests::XORReduceAllMasked); 3258 } 3259 3260 static byte ADDReduce(byte[] a, int idx) { 3261 byte res = 0; 3262 for (int i = idx; i < (idx + SPECIES.length()); i++) { 3263 res += a[i]; 3264 } 3265 3266 return res; 3267 } 3268 3269 static byte ADDReduceAll(byte[] a) { 3270 byte res = 0; 3271 for (int i = 0; i < a.length; i += SPECIES.length()) { 3272 res += ADDReduce(a, i); 3273 } 3274 3275 return res; 3276 } 3277 3278 @Test(dataProvider = "byteUnaryOpProvider") 3279 static void ADDReduceByteMaxVectorTests(IntFunction<byte[]> fa) { 3280 byte[] a = fa.apply(SPECIES.length()); 3281 byte[] r = fr.apply(SPECIES.length()); 3282 byte ra = 0; 3283 3284 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3285 for (int i = 0; i < a.length; i += SPECIES.length()) { 3286 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 3287 r[i] = av.reduceLanes(VectorOperators.ADD); 3288 } 3289 } 3290 3291 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3292 ra = 0; 3293 for (int i = 0; i < a.length; i += SPECIES.length()) { 3294 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 3295 ra += av.reduceLanes(VectorOperators.ADD); 3296 } 3297 } 3298 3299 assertReductionArraysEquals(r, ra, a, 3300 ByteMaxVectorTests::ADDReduce, ByteMaxVectorTests::ADDReduceAll); 3301 } 3302 3303 static byte ADDReduceMasked(byte[] a, int idx, boolean[] mask) { 3304 byte res = 0; 3305 for (int i = idx; i < (idx + SPECIES.length()); i++) { 3306 if (mask[i % SPECIES.length()]) 3307 res += a[i]; 3308 } 3309 3310 return res; 3311 } 3312 3313 static byte ADDReduceAllMasked(byte[] a, boolean[] mask) { 3314 byte res = 0; 3315 for (int i = 0; i < a.length; i += SPECIES.length()) { 3316 res += ADDReduceMasked(a, i, mask); 3317 } 3318 3319 return res; 3320 } 3321 3322 @Test(dataProvider = "byteUnaryOpMaskProvider") 3323 static void ADDReduceByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<boolean[]> fm) { 3324 byte[] a = fa.apply(SPECIES.length()); 3325 byte[] r = fr.apply(SPECIES.length()); 3326 boolean[] mask = fm.apply(SPECIES.length()); 3327 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3328 byte ra = 0; 3329 3330 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3331 for (int i = 0; i < a.length; i += SPECIES.length()) { 3332 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 3333 r[i] = av.reduceLanes(VectorOperators.ADD, vmask); 3334 } 3335 } 3336 3337 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3338 ra = 0; 3339 for (int i = 0; i < a.length; i += SPECIES.length()) { 3340 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 3341 ra += av.reduceLanes(VectorOperators.ADD, vmask); 3342 } 3343 } 3344 3345 assertReductionArraysEqualsMasked(r, ra, a, mask, 3346 ByteMaxVectorTests::ADDReduceMasked, ByteMaxVectorTests::ADDReduceAllMasked); 3347 } 3348 3349 static byte MULReduce(byte[] a, int idx) { 3350 byte res = 1; 3351 for (int i = idx; i < (idx + SPECIES.length()); i++) { 3352 res *= a[i]; 3353 } 3354 3355 return res; 3356 } 3357 3358 static byte MULReduceAll(byte[] a) { 3359 byte res = 1; 3360 for (int i = 0; i < a.length; i += SPECIES.length()) { 3361 res *= MULReduce(a, i); 3362 } 3363 3364 return res; 3365 } 3366 3367 @Test(dataProvider = "byteUnaryOpProvider") 3368 static void MULReduceByteMaxVectorTests(IntFunction<byte[]> fa) { 3369 byte[] a = fa.apply(SPECIES.length()); 3370 byte[] r = fr.apply(SPECIES.length()); 3371 byte ra = 1; 3372 3373 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3374 for (int i = 0; i < a.length; i += SPECIES.length()) { 3375 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 3376 r[i] = av.reduceLanes(VectorOperators.MUL); 3377 } 3378 } 3379 3380 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3381 ra = 1; 3382 for (int i = 0; i < a.length; i += SPECIES.length()) { 3383 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 3384 ra *= av.reduceLanes(VectorOperators.MUL); 3385 } 3386 } 3387 3388 assertReductionArraysEquals(r, ra, a, 3389 ByteMaxVectorTests::MULReduce, ByteMaxVectorTests::MULReduceAll); 3390 } 3391 3392 static byte MULReduceMasked(byte[] a, int idx, boolean[] mask) { 3393 byte res = 1; 3394 for (int i = idx; i < (idx + SPECIES.length()); i++) { 3395 if (mask[i % SPECIES.length()]) 3396 res *= a[i]; 3397 } 3398 3399 return res; 3400 } 3401 3402 static byte MULReduceAllMasked(byte[] a, boolean[] mask) { 3403 byte res = 1; 3404 for (int i = 0; i < a.length; i += SPECIES.length()) { 3405 res *= MULReduceMasked(a, i, mask); 3406 } 3407 3408 return res; 3409 } 3410 3411 @Test(dataProvider = "byteUnaryOpMaskProvider") 3412 static void MULReduceByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<boolean[]> fm) { 3413 byte[] a = fa.apply(SPECIES.length()); 3414 byte[] r = fr.apply(SPECIES.length()); 3415 boolean[] mask = fm.apply(SPECIES.length()); 3416 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3417 byte ra = 1; 3418 3419 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3420 for (int i = 0; i < a.length; i += SPECIES.length()) { 3421 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 3422 r[i] = av.reduceLanes(VectorOperators.MUL, vmask); 3423 } 3424 } 3425 3426 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3427 ra = 1; 3428 for (int i = 0; i < a.length; i += SPECIES.length()) { 3429 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 3430 ra *= av.reduceLanes(VectorOperators.MUL, vmask); 3431 } 3432 } 3433 3434 assertReductionArraysEqualsMasked(r, ra, a, mask, 3435 ByteMaxVectorTests::MULReduceMasked, ByteMaxVectorTests::MULReduceAllMasked); 3436 } 3437 3438 static byte MINReduce(byte[] a, int idx) { 3439 byte res = Byte.MAX_VALUE; 3440 for (int i = idx; i < (idx + SPECIES.length()); i++) { 3441 res = (byte) Math.min(res, a[i]); 3442 } 3443 3444 return res; 3445 } 3446 3447 static byte MINReduceAll(byte[] a) { 3448 byte res = Byte.MAX_VALUE; 3449 for (int i = 0; i < a.length; i += SPECIES.length()) { 3450 res = (byte) Math.min(res, MINReduce(a, i)); 3451 } 3452 3453 return res; 3454 } 3455 3456 @Test(dataProvider = "byteUnaryOpProvider") 3457 static void MINReduceByteMaxVectorTests(IntFunction<byte[]> fa) { 3458 byte[] a = fa.apply(SPECIES.length()); 3459 byte[] r = fr.apply(SPECIES.length()); 3460 byte ra = Byte.MAX_VALUE; 3461 3462 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3463 for (int i = 0; i < a.length; i += SPECIES.length()) { 3464 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 3465 r[i] = av.reduceLanes(VectorOperators.MIN); 3466 } 3467 } 3468 3469 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3470 ra = Byte.MAX_VALUE; 3471 for (int i = 0; i < a.length; i += SPECIES.length()) { 3472 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 3473 ra = (byte) Math.min(ra, av.reduceLanes(VectorOperators.MIN)); 3474 } 3475 } 3476 3477 assertReductionArraysEquals(r, ra, a, 3478 ByteMaxVectorTests::MINReduce, ByteMaxVectorTests::MINReduceAll); 3479 } 3480 3481 static byte MINReduceMasked(byte[] a, int idx, boolean[] mask) { 3482 byte res = Byte.MAX_VALUE; 3483 for (int i = idx; i < (idx + SPECIES.length()); i++) { 3484 if (mask[i % SPECIES.length()]) 3485 res = (byte) Math.min(res, a[i]); 3486 } 3487 3488 return res; 3489 } 3490 3491 static byte MINReduceAllMasked(byte[] a, boolean[] mask) { 3492 byte res = Byte.MAX_VALUE; 3493 for (int i = 0; i < a.length; i += SPECIES.length()) { 3494 res = (byte) Math.min(res, MINReduceMasked(a, i, mask)); 3495 } 3496 3497 return res; 3498 } 3499 3500 @Test(dataProvider = "byteUnaryOpMaskProvider") 3501 static void MINReduceByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<boolean[]> fm) { 3502 byte[] a = fa.apply(SPECIES.length()); 3503 byte[] r = fr.apply(SPECIES.length()); 3504 boolean[] mask = fm.apply(SPECIES.length()); 3505 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3506 byte ra = Byte.MAX_VALUE; 3507 3508 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3509 for (int i = 0; i < a.length; i += SPECIES.length()) { 3510 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 3511 r[i] = av.reduceLanes(VectorOperators.MIN, vmask); 3512 } 3513 } 3514 3515 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3516 ra = Byte.MAX_VALUE; 3517 for (int i = 0; i < a.length; i += SPECIES.length()) { 3518 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 3519 ra = (byte) Math.min(ra, av.reduceLanes(VectorOperators.MIN, vmask)); 3520 } 3521 } 3522 3523 assertReductionArraysEqualsMasked(r, ra, a, mask, 3524 ByteMaxVectorTests::MINReduceMasked, ByteMaxVectorTests::MINReduceAllMasked); 3525 } 3526 3527 static byte MAXReduce(byte[] a, int idx) { 3528 byte res = Byte.MIN_VALUE; 3529 for (int i = idx; i < (idx + SPECIES.length()); i++) { 3530 res = (byte) Math.max(res, a[i]); 3531 } 3532 3533 return res; 3534 } 3535 3536 static byte MAXReduceAll(byte[] a) { 3537 byte res = Byte.MIN_VALUE; 3538 for (int i = 0; i < a.length; i += SPECIES.length()) { 3539 res = (byte) Math.max(res, MAXReduce(a, i)); 3540 } 3541 3542 return res; 3543 } 3544 3545 @Test(dataProvider = "byteUnaryOpProvider") 3546 static void MAXReduceByteMaxVectorTests(IntFunction<byte[]> fa) { 3547 byte[] a = fa.apply(SPECIES.length()); 3548 byte[] r = fr.apply(SPECIES.length()); 3549 byte ra = Byte.MIN_VALUE; 3550 3551 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3552 for (int i = 0; i < a.length; i += SPECIES.length()) { 3553 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 3554 r[i] = av.reduceLanes(VectorOperators.MAX); 3555 } 3556 } 3557 3558 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3559 ra = Byte.MIN_VALUE; 3560 for (int i = 0; i < a.length; i += SPECIES.length()) { 3561 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 3562 ra = (byte) Math.max(ra, av.reduceLanes(VectorOperators.MAX)); 3563 } 3564 } 3565 3566 assertReductionArraysEquals(r, ra, a, 3567 ByteMaxVectorTests::MAXReduce, ByteMaxVectorTests::MAXReduceAll); 3568 } 3569 3570 static byte MAXReduceMasked(byte[] a, int idx, boolean[] mask) { 3571 byte res = Byte.MIN_VALUE; 3572 for (int i = idx; i < (idx + SPECIES.length()); i++) { 3573 if (mask[i % SPECIES.length()]) 3574 res = (byte) Math.max(res, a[i]); 3575 } 3576 3577 return res; 3578 } 3579 3580 static byte MAXReduceAllMasked(byte[] a, boolean[] mask) { 3581 byte res = Byte.MIN_VALUE; 3582 for (int i = 0; i < a.length; i += SPECIES.length()) { 3583 res = (byte) Math.max(res, MAXReduceMasked(a, i, mask)); 3584 } 3585 3586 return res; 3587 } 3588 3589 @Test(dataProvider = "byteUnaryOpMaskProvider") 3590 static void MAXReduceByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<boolean[]> fm) { 3591 byte[] a = fa.apply(SPECIES.length()); 3592 byte[] r = fr.apply(SPECIES.length()); 3593 boolean[] mask = fm.apply(SPECIES.length()); 3594 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3595 byte ra = Byte.MIN_VALUE; 3596 3597 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3598 for (int i = 0; i < a.length; i += SPECIES.length()) { 3599 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 3600 r[i] = av.reduceLanes(VectorOperators.MAX, vmask); 3601 } 3602 } 3603 3604 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3605 ra = Byte.MIN_VALUE; 3606 for (int i = 0; i < a.length; i += SPECIES.length()) { 3607 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 3608 ra = (byte) Math.max(ra, av.reduceLanes(VectorOperators.MAX, vmask)); 3609 } 3610 } 3611 3612 assertReductionArraysEqualsMasked(r, ra, a, mask, 3613 ByteMaxVectorTests::MAXReduceMasked, ByteMaxVectorTests::MAXReduceAllMasked); 3614 } 3615 3616 static byte FIRST_NONZEROReduce(byte[] a, int idx) { 3617 byte res = (byte) 0; 3618 for (int i = idx; i < (idx + SPECIES.length()); i++) { 3619 res = firstNonZero(res, a[i]); 3620 } 3621 3622 return res; 3623 } 3624 3625 static byte FIRST_NONZEROReduceAll(byte[] a) { 3626 byte res = (byte) 0; 3627 for (int i = 0; i < a.length; i += SPECIES.length()) { 3628 res = firstNonZero(res, FIRST_NONZEROReduce(a, i)); 3629 } 3630 3631 return res; 3632 } 3633 3634 @Test(dataProvider = "byteUnaryOpProvider") 3635 static void FIRST_NONZEROReduceByteMaxVectorTests(IntFunction<byte[]> fa) { 3636 byte[] a = fa.apply(SPECIES.length()); 3637 byte[] r = fr.apply(SPECIES.length()); 3638 byte ra = (byte) 0; 3639 3640 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3641 for (int i = 0; i < a.length; i += SPECIES.length()) { 3642 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 3643 r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO); 3644 } 3645 } 3646 3647 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3648 ra = (byte) 0; 3649 for (int i = 0; i < a.length; i += SPECIES.length()) { 3650 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 3651 ra = firstNonZero(ra, av.reduceLanes(VectorOperators.FIRST_NONZERO)); 3652 } 3653 } 3654 3655 assertReductionArraysEquals(r, ra, a, 3656 ByteMaxVectorTests::FIRST_NONZEROReduce, ByteMaxVectorTests::FIRST_NONZEROReduceAll); 3657 } 3658 3659 static byte FIRST_NONZEROReduceMasked(byte[] a, int idx, boolean[] mask) { 3660 byte res = (byte) 0; 3661 for (int i = idx; i < (idx + SPECIES.length()); i++) { 3662 if (mask[i % SPECIES.length()]) 3663 res = firstNonZero(res, a[i]); 3664 } 3665 3666 return res; 3667 } 3668 3669 static byte FIRST_NONZEROReduceAllMasked(byte[] a, boolean[] mask) { 3670 byte res = (byte) 0; 3671 for (int i = 0; i < a.length; i += SPECIES.length()) { 3672 res = firstNonZero(res, FIRST_NONZEROReduceMasked(a, i, mask)); 3673 } 3674 3675 return res; 3676 } 3677 3678 @Test(dataProvider = "byteUnaryOpMaskProvider") 3679 static void FIRST_NONZEROReduceByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<boolean[]> fm) { 3680 byte[] a = fa.apply(SPECIES.length()); 3681 byte[] r = fr.apply(SPECIES.length()); 3682 boolean[] mask = fm.apply(SPECIES.length()); 3683 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3684 byte ra = (byte) 0; 3685 3686 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3687 for (int i = 0; i < a.length; i += SPECIES.length()) { 3688 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 3689 r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); 3690 } 3691 } 3692 3693 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3694 ra = (byte) 0; 3695 for (int i = 0; i < a.length; i += SPECIES.length()) { 3696 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 3697 ra = firstNonZero(ra, av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask)); 3698 } 3699 } 3700 3701 assertReductionArraysEqualsMasked(r, ra, a, mask, 3702 ByteMaxVectorTests::FIRST_NONZEROReduceMasked, ByteMaxVectorTests::FIRST_NONZEROReduceAllMasked); 3703 } 3704 3705 static boolean anyTrue(boolean[] a, int idx) { 3706 boolean res = false; 3707 for (int i = idx; i < (idx + SPECIES.length()); i++) { 3708 res |= a[i]; 3709 } 3710 3711 return res; 3712 } 3713 3714 @Test(dataProvider = "boolUnaryOpProvider") 3715 static void anyTrueByteMaxVectorTests(IntFunction<boolean[]> fm) { 3716 boolean[] mask = fm.apply(SPECIES.length()); 3717 boolean[] r = fmr.apply(SPECIES.length()); 3718 3719 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3720 for (int i = 0; i < mask.length; i += SPECIES.length()) { 3721 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, i); 3722 r[i] = vmask.anyTrue(); 3723 } 3724 } 3725 3726 assertReductionBoolArraysEquals(r, mask, ByteMaxVectorTests::anyTrue); 3727 } 3728 3729 static boolean allTrue(boolean[] a, int idx) { 3730 boolean res = true; 3731 for (int i = idx; i < (idx + SPECIES.length()); i++) { 3732 res &= a[i]; 3733 } 3734 3735 return res; 3736 } 3737 3738 @Test(dataProvider = "boolUnaryOpProvider") 3739 static void allTrueByteMaxVectorTests(IntFunction<boolean[]> fm) { 3740 boolean[] mask = fm.apply(SPECIES.length()); 3741 boolean[] r = fmr.apply(SPECIES.length()); 3742 3743 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3744 for (int i = 0; i < mask.length; i += SPECIES.length()) { 3745 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, i); 3746 r[i] = vmask.allTrue(); 3747 } 3748 } 3749 3750 assertReductionBoolArraysEquals(r, mask, ByteMaxVectorTests::allTrue); 3751 } 3752 3753 @Test(dataProvider = "byteUnaryOpProvider") 3754 static void withByteMaxVectorTests(IntFunction<byte []> fa) { 3755 byte[] a = fa.apply(SPECIES.length()); 3756 byte[] r = fr.apply(SPECIES.length()); 3757 3758 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3759 for (int i = 0, j = 0; i < a.length; i += SPECIES.length()) { 3760 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 3761 av.withLane((j++ & (SPECIES.length()-1)), (byte)(65535+i)).intoArray(r, i); 3762 } 3763 } 3764 3765 3766 for (int i = 0, j = 0; i < a.length; i += SPECIES.length()) { 3767 assertInsertArraysEquals(r, a, (byte)(65535+i), (j++ & (SPECIES.length()-1)), i , i + SPECIES.length()); 3768 } 3769 } 3770 3771 static boolean testIS_DEFAULT(byte a) { 3772 return bits(a)==0; 3773 } 3774 3775 @Test(dataProvider = "byteTestOpProvider") 3776 static void IS_DEFAULTByteMaxVectorTests(IntFunction<byte[]> fa) { 3777 byte[] a = fa.apply(SPECIES.length()); 3778 3779 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3780 for (int i = 0; i < a.length; i += SPECIES.length()) { 3781 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 3782 VectorMask<Byte> mv = av.test(VectorOperators.IS_DEFAULT); 3783 3784 // Check results as part of computation. 3785 for (int j = 0; j < SPECIES.length(); j++) { 3786 Assert.assertEquals(mv.laneIsSet(j), testIS_DEFAULT(a[i + j])); 3787 } 3788 } 3789 } 3790 } 3791 3792 @Test(dataProvider = "byteTestOpMaskProvider") 3793 static void IS_DEFAULTMaskedByteMaxVectorTests(IntFunction<byte[]> fa, 3794 IntFunction<boolean[]> fm) { 3795 byte[] a = fa.apply(SPECIES.length()); 3796 boolean[] mask = fm.apply(SPECIES.length()); 3797 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3798 3799 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3800 for (int i = 0; i < a.length; i += SPECIES.length()) { 3801 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 3802 VectorMask<Byte> mv = av.test(VectorOperators.IS_DEFAULT, vmask); 3803 3804 // Check results as part of computation. 3805 for (int j = 0; j < SPECIES.length(); j++) { 3806 Assert.assertEquals(mv.laneIsSet(j), vmask.laneIsSet(j) && testIS_DEFAULT(a[i + j])); 3807 } 3808 } 3809 } 3810 } 3811 3812 static boolean testIS_NEGATIVE(byte a) { 3813 return bits(a)<0; 3814 } 3815 3816 @Test(dataProvider = "byteTestOpProvider") 3817 static void IS_NEGATIVEByteMaxVectorTests(IntFunction<byte[]> fa) { 3818 byte[] a = fa.apply(SPECIES.length()); 3819 3820 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3821 for (int i = 0; i < a.length; i += SPECIES.length()) { 3822 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 3823 VectorMask<Byte> mv = av.test(VectorOperators.IS_NEGATIVE); 3824 3825 // Check results as part of computation. 3826 for (int j = 0; j < SPECIES.length(); j++) { 3827 Assert.assertEquals(mv.laneIsSet(j), testIS_NEGATIVE(a[i + j])); 3828 } 3829 } 3830 } 3831 } 3832 3833 @Test(dataProvider = "byteTestOpMaskProvider") 3834 static void IS_NEGATIVEMaskedByteMaxVectorTests(IntFunction<byte[]> fa, 3835 IntFunction<boolean[]> fm) { 3836 byte[] a = fa.apply(SPECIES.length()); 3837 boolean[] mask = fm.apply(SPECIES.length()); 3838 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3839 3840 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3841 for (int i = 0; i < a.length; i += SPECIES.length()) { 3842 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 3843 VectorMask<Byte> mv = av.test(VectorOperators.IS_NEGATIVE, vmask); 3844 3845 // Check results as part of computation. 3846 for (int j = 0; j < SPECIES.length(); j++) { 3847 Assert.assertEquals(mv.laneIsSet(j), vmask.laneIsSet(j) && testIS_NEGATIVE(a[i + j])); 3848 } 3849 } 3850 } 3851 } 3852 3853 @Test(dataProvider = "byteCompareOpProvider") 3854 static void LTByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 3855 byte[] a = fa.apply(SPECIES.length()); 3856 byte[] b = fb.apply(SPECIES.length()); 3857 3858 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3859 for (int i = 0; i < a.length; i += SPECIES.length()) { 3860 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 3861 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 3862 VectorMask<Byte> mv = av.compare(VectorOperators.LT, bv); 3863 3864 // Check results as part of computation. 3865 for (int j = 0; j < SPECIES.length(); j++) { 3866 Assert.assertEquals(mv.laneIsSet(j), lt(a[i + j], b[i + j])); 3867 } 3868 } 3869 } 3870 } 3871 3872 @Test(dataProvider = "byteCompareOpProvider") 3873 static void ltByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 3874 byte[] a = fa.apply(SPECIES.length()); 3875 byte[] b = fb.apply(SPECIES.length()); 3876 3877 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3878 for (int i = 0; i < a.length; i += SPECIES.length()) { 3879 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 3880 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 3881 VectorMask<Byte> mv = av.lt(bv); 3882 3883 // Check results as part of computation. 3884 for (int j = 0; j < SPECIES.length(); j++) { 3885 Assert.assertEquals(mv.laneIsSet(j), lt(a[i + j], b[i + j])); 3886 } 3887 } 3888 } 3889 } 3890 3891 @Test(dataProvider = "byteCompareOpMaskProvider") 3892 static void LTByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 3893 IntFunction<boolean[]> fm) { 3894 byte[] a = fa.apply(SPECIES.length()); 3895 byte[] b = fb.apply(SPECIES.length()); 3896 boolean[] mask = fm.apply(SPECIES.length()); 3897 3898 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3899 3900 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3901 for (int i = 0; i < a.length; i += SPECIES.length()) { 3902 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 3903 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 3904 VectorMask<Byte> mv = av.compare(VectorOperators.LT, bv, vmask); 3905 3906 // Check results as part of computation. 3907 for (int j = 0; j < SPECIES.length(); j++) { 3908 Assert.assertEquals(mv.laneIsSet(j), mask[j] && lt(a[i + j], b[i + j])); 3909 } 3910 } 3911 } 3912 } 3913 3914 @Test(dataProvider = "byteCompareOpProvider") 3915 static void GTByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 3916 byte[] a = fa.apply(SPECIES.length()); 3917 byte[] b = fb.apply(SPECIES.length()); 3918 3919 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3920 for (int i = 0; i < a.length; i += SPECIES.length()) { 3921 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 3922 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 3923 VectorMask<Byte> mv = av.compare(VectorOperators.GT, bv); 3924 3925 // Check results as part of computation. 3926 for (int j = 0; j < SPECIES.length(); j++) { 3927 Assert.assertEquals(mv.laneIsSet(j), gt(a[i + j], b[i + j])); 3928 } 3929 } 3930 } 3931 } 3932 3933 @Test(dataProvider = "byteCompareOpMaskProvider") 3934 static void GTByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 3935 IntFunction<boolean[]> fm) { 3936 byte[] a = fa.apply(SPECIES.length()); 3937 byte[] b = fb.apply(SPECIES.length()); 3938 boolean[] mask = fm.apply(SPECIES.length()); 3939 3940 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3941 3942 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3943 for (int i = 0; i < a.length; i += SPECIES.length()) { 3944 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 3945 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 3946 VectorMask<Byte> mv = av.compare(VectorOperators.GT, bv, vmask); 3947 3948 // Check results as part of computation. 3949 for (int j = 0; j < SPECIES.length(); j++) { 3950 Assert.assertEquals(mv.laneIsSet(j), mask[j] && gt(a[i + j], b[i + j])); 3951 } 3952 } 3953 } 3954 } 3955 3956 @Test(dataProvider = "byteCompareOpProvider") 3957 static void EQByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 3958 byte[] a = fa.apply(SPECIES.length()); 3959 byte[] b = fb.apply(SPECIES.length()); 3960 3961 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3962 for (int i = 0; i < a.length; i += SPECIES.length()) { 3963 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 3964 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 3965 VectorMask<Byte> mv = av.compare(VectorOperators.EQ, bv); 3966 3967 // Check results as part of computation. 3968 for (int j = 0; j < SPECIES.length(); j++) { 3969 Assert.assertEquals(mv.laneIsSet(j), eq(a[i + j], b[i + j])); 3970 } 3971 } 3972 } 3973 } 3974 3975 @Test(dataProvider = "byteCompareOpProvider") 3976 static void eqByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 3977 byte[] a = fa.apply(SPECIES.length()); 3978 byte[] b = fb.apply(SPECIES.length()); 3979 3980 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3981 for (int i = 0; i < a.length; i += SPECIES.length()) { 3982 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 3983 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 3984 VectorMask<Byte> mv = av.eq(bv); 3985 3986 // Check results as part of computation. 3987 for (int j = 0; j < SPECIES.length(); j++) { 3988 Assert.assertEquals(mv.laneIsSet(j), eq(a[i + j], b[i + j])); 3989 } 3990 } 3991 } 3992 } 3993 3994 @Test(dataProvider = "byteCompareOpMaskProvider") 3995 static void EQByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 3996 IntFunction<boolean[]> fm) { 3997 byte[] a = fa.apply(SPECIES.length()); 3998 byte[] b = fb.apply(SPECIES.length()); 3999 boolean[] mask = fm.apply(SPECIES.length()); 4000 4001 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 4002 4003 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4004 for (int i = 0; i < a.length; i += SPECIES.length()) { 4005 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 4006 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 4007 VectorMask<Byte> mv = av.compare(VectorOperators.EQ, bv, vmask); 4008 4009 // Check results as part of computation. 4010 for (int j = 0; j < SPECIES.length(); j++) { 4011 Assert.assertEquals(mv.laneIsSet(j), mask[j] && eq(a[i + j], b[i + j])); 4012 } 4013 } 4014 } 4015 } 4016 4017 @Test(dataProvider = "byteCompareOpProvider") 4018 static void NEByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 4019 byte[] a = fa.apply(SPECIES.length()); 4020 byte[] b = fb.apply(SPECIES.length()); 4021 4022 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4023 for (int i = 0; i < a.length; i += SPECIES.length()) { 4024 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 4025 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 4026 VectorMask<Byte> mv = av.compare(VectorOperators.NE, bv); 4027 4028 // Check results as part of computation. 4029 for (int j = 0; j < SPECIES.length(); j++) { 4030 Assert.assertEquals(mv.laneIsSet(j), neq(a[i + j], b[i + j])); 4031 } 4032 } 4033 } 4034 } 4035 4036 @Test(dataProvider = "byteCompareOpMaskProvider") 4037 static void NEByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 4038 IntFunction<boolean[]> fm) { 4039 byte[] a = fa.apply(SPECIES.length()); 4040 byte[] b = fb.apply(SPECIES.length()); 4041 boolean[] mask = fm.apply(SPECIES.length()); 4042 4043 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 4044 4045 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4046 for (int i = 0; i < a.length; i += SPECIES.length()) { 4047 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 4048 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 4049 VectorMask<Byte> mv = av.compare(VectorOperators.NE, bv, vmask); 4050 4051 // Check results as part of computation. 4052 for (int j = 0; j < SPECIES.length(); j++) { 4053 Assert.assertEquals(mv.laneIsSet(j), mask[j] && neq(a[i + j], b[i + j])); 4054 } 4055 } 4056 } 4057 } 4058 4059 @Test(dataProvider = "byteCompareOpProvider") 4060 static void LEByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 4061 byte[] a = fa.apply(SPECIES.length()); 4062 byte[] b = fb.apply(SPECIES.length()); 4063 4064 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4065 for (int i = 0; i < a.length; i += SPECIES.length()) { 4066 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 4067 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 4068 VectorMask<Byte> mv = av.compare(VectorOperators.LE, bv); 4069 4070 // Check results as part of computation. 4071 for (int j = 0; j < SPECIES.length(); j++) { 4072 Assert.assertEquals(mv.laneIsSet(j), le(a[i + j], b[i + j])); 4073 } 4074 } 4075 } 4076 } 4077 4078 @Test(dataProvider = "byteCompareOpMaskProvider") 4079 static void LEByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 4080 IntFunction<boolean[]> fm) { 4081 byte[] a = fa.apply(SPECIES.length()); 4082 byte[] b = fb.apply(SPECIES.length()); 4083 boolean[] mask = fm.apply(SPECIES.length()); 4084 4085 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 4086 4087 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4088 for (int i = 0; i < a.length; i += SPECIES.length()) { 4089 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 4090 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 4091 VectorMask<Byte> mv = av.compare(VectorOperators.LE, bv, vmask); 4092 4093 // Check results as part of computation. 4094 for (int j = 0; j < SPECIES.length(); j++) { 4095 Assert.assertEquals(mv.laneIsSet(j), mask[j] && le(a[i + j], b[i + j])); 4096 } 4097 } 4098 } 4099 } 4100 4101 @Test(dataProvider = "byteCompareOpProvider") 4102 static void GEByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 4103 byte[] a = fa.apply(SPECIES.length()); 4104 byte[] b = fb.apply(SPECIES.length()); 4105 4106 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4107 for (int i = 0; i < a.length; i += SPECIES.length()) { 4108 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 4109 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 4110 VectorMask<Byte> mv = av.compare(VectorOperators.GE, bv); 4111 4112 // Check results as part of computation. 4113 for (int j = 0; j < SPECIES.length(); j++) { 4114 Assert.assertEquals(mv.laneIsSet(j), ge(a[i + j], b[i + j])); 4115 } 4116 } 4117 } 4118 } 4119 4120 @Test(dataProvider = "byteCompareOpMaskProvider") 4121 static void GEByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 4122 IntFunction<boolean[]> fm) { 4123 byte[] a = fa.apply(SPECIES.length()); 4124 byte[] b = fb.apply(SPECIES.length()); 4125 boolean[] mask = fm.apply(SPECIES.length()); 4126 4127 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 4128 4129 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4130 for (int i = 0; i < a.length; i += SPECIES.length()) { 4131 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 4132 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 4133 VectorMask<Byte> mv = av.compare(VectorOperators.GE, bv, vmask); 4134 4135 // Check results as part of computation. 4136 for (int j = 0; j < SPECIES.length(); j++) { 4137 Assert.assertEquals(mv.laneIsSet(j), mask[j] && ge(a[i + j], b[i + j])); 4138 } 4139 } 4140 } 4141 } 4142 4143 @Test(dataProvider = "byteCompareOpProvider") 4144 static void UNSIGNED_LTByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 4145 byte[] a = fa.apply(SPECIES.length()); 4146 byte[] b = fb.apply(SPECIES.length()); 4147 4148 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4149 for (int i = 0; i < a.length; i += SPECIES.length()) { 4150 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 4151 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 4152 VectorMask<Byte> mv = av.compare(VectorOperators.UNSIGNED_LT, bv); 4153 4154 // Check results as part of computation. 4155 for (int j = 0; j < SPECIES.length(); j++) { 4156 Assert.assertEquals(mv.laneIsSet(j), ult(a[i + j], b[i + j])); 4157 } 4158 } 4159 } 4160 } 4161 4162 @Test(dataProvider = "byteCompareOpMaskProvider") 4163 static void UNSIGNED_LTByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 4164 IntFunction<boolean[]> fm) { 4165 byte[] a = fa.apply(SPECIES.length()); 4166 byte[] b = fb.apply(SPECIES.length()); 4167 boolean[] mask = fm.apply(SPECIES.length()); 4168 4169 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 4170 4171 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4172 for (int i = 0; i < a.length; i += SPECIES.length()) { 4173 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 4174 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 4175 VectorMask<Byte> mv = av.compare(VectorOperators.UNSIGNED_LT, bv, vmask); 4176 4177 // Check results as part of computation. 4178 for (int j = 0; j < SPECIES.length(); j++) { 4179 Assert.assertEquals(mv.laneIsSet(j), mask[j] && ult(a[i + j], b[i + j])); 4180 } 4181 } 4182 } 4183 } 4184 4185 @Test(dataProvider = "byteCompareOpProvider") 4186 static void UNSIGNED_GTByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 4187 byte[] a = fa.apply(SPECIES.length()); 4188 byte[] b = fb.apply(SPECIES.length()); 4189 4190 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4191 for (int i = 0; i < a.length; i += SPECIES.length()) { 4192 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 4193 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 4194 VectorMask<Byte> mv = av.compare(VectorOperators.UNSIGNED_GT, bv); 4195 4196 // Check results as part of computation. 4197 for (int j = 0; j < SPECIES.length(); j++) { 4198 Assert.assertEquals(mv.laneIsSet(j), ugt(a[i + j], b[i + j])); 4199 } 4200 } 4201 } 4202 } 4203 4204 @Test(dataProvider = "byteCompareOpMaskProvider") 4205 static void UNSIGNED_GTByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 4206 IntFunction<boolean[]> fm) { 4207 byte[] a = fa.apply(SPECIES.length()); 4208 byte[] b = fb.apply(SPECIES.length()); 4209 boolean[] mask = fm.apply(SPECIES.length()); 4210 4211 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 4212 4213 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4214 for (int i = 0; i < a.length; i += SPECIES.length()) { 4215 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 4216 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 4217 VectorMask<Byte> mv = av.compare(VectorOperators.UNSIGNED_GT, bv, vmask); 4218 4219 // Check results as part of computation. 4220 for (int j = 0; j < SPECIES.length(); j++) { 4221 Assert.assertEquals(mv.laneIsSet(j), mask[j] && ugt(a[i + j], b[i + j])); 4222 } 4223 } 4224 } 4225 } 4226 4227 @Test(dataProvider = "byteCompareOpProvider") 4228 static void UNSIGNED_LEByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 4229 byte[] a = fa.apply(SPECIES.length()); 4230 byte[] b = fb.apply(SPECIES.length()); 4231 4232 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4233 for (int i = 0; i < a.length; i += SPECIES.length()) { 4234 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 4235 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 4236 VectorMask<Byte> mv = av.compare(VectorOperators.UNSIGNED_LE, bv); 4237 4238 // Check results as part of computation. 4239 for (int j = 0; j < SPECIES.length(); j++) { 4240 Assert.assertEquals(mv.laneIsSet(j), ule(a[i + j], b[i + j])); 4241 } 4242 } 4243 } 4244 } 4245 4246 @Test(dataProvider = "byteCompareOpMaskProvider") 4247 static void UNSIGNED_LEByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 4248 IntFunction<boolean[]> fm) { 4249 byte[] a = fa.apply(SPECIES.length()); 4250 byte[] b = fb.apply(SPECIES.length()); 4251 boolean[] mask = fm.apply(SPECIES.length()); 4252 4253 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 4254 4255 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4256 for (int i = 0; i < a.length; i += SPECIES.length()) { 4257 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 4258 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 4259 VectorMask<Byte> mv = av.compare(VectorOperators.UNSIGNED_LE, bv, vmask); 4260 4261 // Check results as part of computation. 4262 for (int j = 0; j < SPECIES.length(); j++) { 4263 Assert.assertEquals(mv.laneIsSet(j), mask[j] && ule(a[i + j], b[i + j])); 4264 } 4265 } 4266 } 4267 } 4268 4269 @Test(dataProvider = "byteCompareOpProvider") 4270 static void UNSIGNED_GEByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 4271 byte[] a = fa.apply(SPECIES.length()); 4272 byte[] b = fb.apply(SPECIES.length()); 4273 4274 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4275 for (int i = 0; i < a.length; i += SPECIES.length()) { 4276 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 4277 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 4278 VectorMask<Byte> mv = av.compare(VectorOperators.UNSIGNED_GE, bv); 4279 4280 // Check results as part of computation. 4281 for (int j = 0; j < SPECIES.length(); j++) { 4282 Assert.assertEquals(mv.laneIsSet(j), uge(a[i + j], b[i + j])); 4283 } 4284 } 4285 } 4286 } 4287 4288 @Test(dataProvider = "byteCompareOpMaskProvider") 4289 static void UNSIGNED_GEByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 4290 IntFunction<boolean[]> fm) { 4291 byte[] a = fa.apply(SPECIES.length()); 4292 byte[] b = fb.apply(SPECIES.length()); 4293 boolean[] mask = fm.apply(SPECIES.length()); 4294 4295 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 4296 4297 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4298 for (int i = 0; i < a.length; i += SPECIES.length()) { 4299 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 4300 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 4301 VectorMask<Byte> mv = av.compare(VectorOperators.UNSIGNED_GE, bv, vmask); 4302 4303 // Check results as part of computation. 4304 for (int j = 0; j < SPECIES.length(); j++) { 4305 Assert.assertEquals(mv.laneIsSet(j), mask[j] && uge(a[i + j], b[i + j])); 4306 } 4307 } 4308 } 4309 } 4310 4311 @Test(dataProvider = "byteCompareOpProvider") 4312 static void LTByteMaxVectorTestsBroadcastSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 4313 byte[] a = fa.apply(SPECIES.length()); 4314 byte[] b = fb.apply(SPECIES.length()); 4315 4316 for (int i = 0; i < a.length; i += SPECIES.length()) { 4317 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 4318 VectorMask<Byte> mv = av.compare(VectorOperators.LT, b[i]); 4319 4320 // Check results as part of computation. 4321 for (int j = 0; j < SPECIES.length(); j++) { 4322 Assert.assertEquals(mv.laneIsSet(j), a[i + j] < b[i]); 4323 } 4324 } 4325 } 4326 4327 @Test(dataProvider = "byteCompareOpMaskProvider") 4328 static void LTByteMaxVectorTestsBroadcastMaskedSmokeTest(IntFunction<byte[]> fa, 4329 IntFunction<byte[]> fb, IntFunction<boolean[]> fm) { 4330 byte[] a = fa.apply(SPECIES.length()); 4331 byte[] b = fb.apply(SPECIES.length()); 4332 boolean[] mask = fm.apply(SPECIES.length()); 4333 4334 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 4335 4336 for (int i = 0; i < a.length; i += SPECIES.length()) { 4337 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 4338 VectorMask<Byte> mv = av.compare(VectorOperators.LT, b[i], vmask); 4339 4340 // Check results as part of computation. 4341 for (int j = 0; j < SPECIES.length(); j++) { 4342 Assert.assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] < b[i])); 4343 } 4344 } 4345 } 4346 4347 @Test(dataProvider = "byteCompareOpProvider") 4348 static void LTByteMaxVectorTestsBroadcastLongSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 4349 byte[] a = fa.apply(SPECIES.length()); 4350 byte[] b = fb.apply(SPECIES.length()); 4351 4352 for (int i = 0; i < a.length; i += SPECIES.length()) { 4353 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 4354 VectorMask<Byte> mv = av.compare(VectorOperators.LT, (long)b[i]); 4355 4356 // Check results as part of computation. 4357 for (int j = 0; j < SPECIES.length(); j++) { 4358 Assert.assertEquals(mv.laneIsSet(j), a[i + j] < (byte)((long)b[i])); 4359 } 4360 } 4361 } 4362 4363 @Test(dataProvider = "byteCompareOpMaskProvider") 4364 static void LTByteMaxVectorTestsBroadcastLongMaskedSmokeTest(IntFunction<byte[]> fa, 4365 IntFunction<byte[]> fb, IntFunction<boolean[]> fm) { 4366 byte[] a = fa.apply(SPECIES.length()); 4367 byte[] b = fb.apply(SPECIES.length()); 4368 boolean[] mask = fm.apply(SPECIES.length()); 4369 4370 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 4371 4372 for (int i = 0; i < a.length; i += SPECIES.length()) { 4373 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 4374 VectorMask<Byte> mv = av.compare(VectorOperators.LT, (long)b[i], vmask); 4375 4376 // Check results as part of computation. 4377 for (int j = 0; j < SPECIES.length(); j++) { 4378 Assert.assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] < (byte)((long)b[i]))); 4379 } 4380 } 4381 } 4382 4383 @Test(dataProvider = "byteCompareOpProvider") 4384 static void EQByteMaxVectorTestsBroadcastSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 4385 byte[] a = fa.apply(SPECIES.length()); 4386 byte[] b = fb.apply(SPECIES.length()); 4387 4388 for (int i = 0; i < a.length; i += SPECIES.length()) { 4389 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 4390 VectorMask<Byte> mv = av.compare(VectorOperators.EQ, b[i]); 4391 4392 // Check results as part of computation. 4393 for (int j = 0; j < SPECIES.length(); j++) { 4394 Assert.assertEquals(mv.laneIsSet(j), a[i + j] == b[i]); 4395 } 4396 } 4397 } 4398 4399 @Test(dataProvider = "byteCompareOpMaskProvider") 4400 static void EQByteMaxVectorTestsBroadcastMaskedSmokeTest(IntFunction<byte[]> fa, 4401 IntFunction<byte[]> fb, IntFunction<boolean[]> fm) { 4402 byte[] a = fa.apply(SPECIES.length()); 4403 byte[] b = fb.apply(SPECIES.length()); 4404 boolean[] mask = fm.apply(SPECIES.length()); 4405 4406 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 4407 4408 for (int i = 0; i < a.length; i += SPECIES.length()) { 4409 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 4410 VectorMask<Byte> mv = av.compare(VectorOperators.EQ, b[i], vmask); 4411 4412 // Check results as part of computation. 4413 for (int j = 0; j < SPECIES.length(); j++) { 4414 Assert.assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] == b[i])); 4415 } 4416 } 4417 } 4418 4419 @Test(dataProvider = "byteCompareOpProvider") 4420 static void EQByteMaxVectorTestsBroadcastLongSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 4421 byte[] a = fa.apply(SPECIES.length()); 4422 byte[] b = fb.apply(SPECIES.length()); 4423 4424 for (int i = 0; i < a.length; i += SPECIES.length()) { 4425 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 4426 VectorMask<Byte> mv = av.compare(VectorOperators.EQ, (long)b[i]); 4427 4428 // Check results as part of computation. 4429 for (int j = 0; j < SPECIES.length(); j++) { 4430 Assert.assertEquals(mv.laneIsSet(j), a[i + j] == (byte)((long)b[i])); 4431 } 4432 } 4433 } 4434 4435 @Test(dataProvider = "byteCompareOpMaskProvider") 4436 static void EQByteMaxVectorTestsBroadcastLongMaskedSmokeTest(IntFunction<byte[]> fa, 4437 IntFunction<byte[]> fb, IntFunction<boolean[]> fm) { 4438 byte[] a = fa.apply(SPECIES.length()); 4439 byte[] b = fb.apply(SPECIES.length()); 4440 boolean[] mask = fm.apply(SPECIES.length()); 4441 4442 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 4443 4444 for (int i = 0; i < a.length; i += SPECIES.length()) { 4445 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 4446 VectorMask<Byte> mv = av.compare(VectorOperators.EQ, (long)b[i], vmask); 4447 4448 // Check results as part of computation. 4449 for (int j = 0; j < SPECIES.length(); j++) { 4450 Assert.assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] == (byte)((long)b[i]))); 4451 } 4452 } 4453 } 4454 4455 static byte blend(byte a, byte b, boolean mask) { 4456 return mask ? b : a; 4457 } 4458 4459 @Test(dataProvider = "byteBinaryOpMaskProvider") 4460 static void blendByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 4461 IntFunction<boolean[]> fm) { 4462 byte[] a = fa.apply(SPECIES.length()); 4463 byte[] b = fb.apply(SPECIES.length()); 4464 byte[] r = fr.apply(SPECIES.length()); 4465 boolean[] mask = fm.apply(SPECIES.length()); 4466 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 4467 4468 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4469 for (int i = 0; i < a.length; i += SPECIES.length()) { 4470 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 4471 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 4472 av.blend(bv, vmask).intoArray(r, i); 4473 } 4474 } 4475 4476 assertArraysEquals(r, a, b, mask, ByteMaxVectorTests::blend); 4477 } 4478 4479 @Test(dataProvider = "byteUnaryOpShuffleProvider") 4480 static void RearrangeByteMaxVectorTests(IntFunction<byte[]> fa, 4481 BiFunction<Integer,Integer,int[]> fs) { 4482 byte[] a = fa.apply(SPECIES.length()); 4483 int[] order = fs.apply(a.length, SPECIES.length()); 4484 byte[] r = fr.apply(SPECIES.length()); 4485 4486 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4487 for (int i = 0; i < a.length; i += SPECIES.length()) { 4488 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 4489 av.rearrange(VectorShuffle.fromArray(SPECIES, order, i)).intoArray(r, i); 4490 } 4491 } 4492 4493 assertRearrangeArraysEquals(r, a, order, SPECIES.length()); 4494 } 4495 4496 @Test(dataProvider = "byteUnaryOpShuffleMaskProvider") 4497 static void RearrangeByteMaxVectorTestsMaskedSmokeTest(IntFunction<byte[]> fa, 4498 BiFunction<Integer,Integer,int[]> fs, 4499 IntFunction<boolean[]> fm) { 4500 byte[] a = fa.apply(SPECIES.length()); 4501 int[] order = fs.apply(a.length, SPECIES.length()); 4502 byte[] r = fr.apply(SPECIES.length()); 4503 boolean[] mask = fm.apply(SPECIES.length()); 4504 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 4505 4506 for (int i = 0; i < a.length; i += SPECIES.length()) { 4507 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 4508 av.rearrange(VectorShuffle.fromArray(SPECIES, order, i), vmask).intoArray(r, i); 4509 } 4510 4511 assertRearrangeArraysEquals(r, a, order, mask, SPECIES.length()); 4512 } 4513 4514 @Test(dataProvider = "byteUnaryOpMaskProvider") 4515 static void compressByteMaxVectorTests(IntFunction<byte[]> fa, 4516 IntFunction<boolean[]> fm) { 4517 byte[] a = fa.apply(SPECIES.length()); 4518 byte[] r = fr.apply(SPECIES.length()); 4519 boolean[] mask = fm.apply(SPECIES.length()); 4520 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 4521 4522 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4523 for (int i = 0; i < a.length; i += SPECIES.length()) { 4524 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 4525 av.compress(vmask).intoArray(r, i); 4526 } 4527 } 4528 4529 assertcompressArraysEquals(r, a, mask, SPECIES.length()); 4530 } 4531 4532 @Test(dataProvider = "byteUnaryOpMaskProvider") 4533 static void expandByteMaxVectorTests(IntFunction<byte[]> fa, 4534 IntFunction<boolean[]> fm) { 4535 byte[] a = fa.apply(SPECIES.length()); 4536 byte[] r = fr.apply(SPECIES.length()); 4537 boolean[] mask = fm.apply(SPECIES.length()); 4538 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 4539 4540 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4541 for (int i = 0; i < a.length; i += SPECIES.length()) { 4542 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 4543 av.expand(vmask).intoArray(r, i); 4544 } 4545 } 4546 4547 assertexpandArraysEquals(r, a, mask, SPECIES.length()); 4548 } 4549 4550 @Test(dataProvider = "byteUnaryOpProvider") 4551 static void getByteMaxVectorTests(IntFunction<byte[]> fa) { 4552 byte[] a = fa.apply(SPECIES.length()); 4553 byte[] r = fr.apply(SPECIES.length()); 4554 4555 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4556 for (int i = 0; i < a.length; i += SPECIES.length()) { 4557 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 4558 int num_lanes = SPECIES.length(); 4559 // Manually unroll because full unroll happens after intrinsification. 4560 // Unroll is needed because get intrinsic requires for index to be a known constant. 4561 if (num_lanes == 1) { 4562 r[i]=av.lane(0); 4563 } else if (num_lanes == 2) { 4564 r[i]=av.lane(0); 4565 r[i+1]=av.lane(1); 4566 } else if (num_lanes == 4) { 4567 r[i]=av.lane(0); 4568 r[i+1]=av.lane(1); 4569 r[i+2]=av.lane(2); 4570 r[i+3]=av.lane(3); 4571 } else if (num_lanes == 8) { 4572 r[i]=av.lane(0); 4573 r[i+1]=av.lane(1); 4574 r[i+2]=av.lane(2); 4575 r[i+3]=av.lane(3); 4576 r[i+4]=av.lane(4); 4577 r[i+5]=av.lane(5); 4578 r[i+6]=av.lane(6); 4579 r[i+7]=av.lane(7); 4580 } else if (num_lanes == 16) { 4581 r[i]=av.lane(0); 4582 r[i+1]=av.lane(1); 4583 r[i+2]=av.lane(2); 4584 r[i+3]=av.lane(3); 4585 r[i+4]=av.lane(4); 4586 r[i+5]=av.lane(5); 4587 r[i+6]=av.lane(6); 4588 r[i+7]=av.lane(7); 4589 r[i+8]=av.lane(8); 4590 r[i+9]=av.lane(9); 4591 r[i+10]=av.lane(10); 4592 r[i+11]=av.lane(11); 4593 r[i+12]=av.lane(12); 4594 r[i+13]=av.lane(13); 4595 r[i+14]=av.lane(14); 4596 r[i+15]=av.lane(15); 4597 } else if (num_lanes == 32) { 4598 r[i]=av.lane(0); 4599 r[i+1]=av.lane(1); 4600 r[i+2]=av.lane(2); 4601 r[i+3]=av.lane(3); 4602 r[i+4]=av.lane(4); 4603 r[i+5]=av.lane(5); 4604 r[i+6]=av.lane(6); 4605 r[i+7]=av.lane(7); 4606 r[i+8]=av.lane(8); 4607 r[i+9]=av.lane(9); 4608 r[i+10]=av.lane(10); 4609 r[i+11]=av.lane(11); 4610 r[i+12]=av.lane(12); 4611 r[i+13]=av.lane(13); 4612 r[i+14]=av.lane(14); 4613 r[i+15]=av.lane(15); 4614 r[i+16]=av.lane(16); 4615 r[i+17]=av.lane(17); 4616 r[i+18]=av.lane(18); 4617 r[i+19]=av.lane(19); 4618 r[i+20]=av.lane(20); 4619 r[i+21]=av.lane(21); 4620 r[i+22]=av.lane(22); 4621 r[i+23]=av.lane(23); 4622 r[i+24]=av.lane(24); 4623 r[i+25]=av.lane(25); 4624 r[i+26]=av.lane(26); 4625 r[i+27]=av.lane(27); 4626 r[i+28]=av.lane(28); 4627 r[i+29]=av.lane(29); 4628 r[i+30]=av.lane(30); 4629 r[i+31]=av.lane(31); 4630 } else if (num_lanes == 64) { 4631 r[i]=av.lane(0); 4632 r[i+1]=av.lane(1); 4633 r[i+2]=av.lane(2); 4634 r[i+3]=av.lane(3); 4635 r[i+4]=av.lane(4); 4636 r[i+5]=av.lane(5); 4637 r[i+6]=av.lane(6); 4638 r[i+7]=av.lane(7); 4639 r[i+8]=av.lane(8); 4640 r[i+9]=av.lane(9); 4641 r[i+10]=av.lane(10); 4642 r[i+11]=av.lane(11); 4643 r[i+12]=av.lane(12); 4644 r[i+13]=av.lane(13); 4645 r[i+14]=av.lane(14); 4646 r[i+15]=av.lane(15); 4647 r[i+16]=av.lane(16); 4648 r[i+17]=av.lane(17); 4649 r[i+18]=av.lane(18); 4650 r[i+19]=av.lane(19); 4651 r[i+20]=av.lane(20); 4652 r[i+21]=av.lane(21); 4653 r[i+22]=av.lane(22); 4654 r[i+23]=av.lane(23); 4655 r[i+24]=av.lane(24); 4656 r[i+25]=av.lane(25); 4657 r[i+26]=av.lane(26); 4658 r[i+27]=av.lane(27); 4659 r[i+28]=av.lane(28); 4660 r[i+29]=av.lane(29); 4661 r[i+30]=av.lane(30); 4662 r[i+31]=av.lane(31); 4663 r[i+32]=av.lane(32); 4664 r[i+33]=av.lane(33); 4665 r[i+34]=av.lane(34); 4666 r[i+35]=av.lane(35); 4667 r[i+36]=av.lane(36); 4668 r[i+37]=av.lane(37); 4669 r[i+38]=av.lane(38); 4670 r[i+39]=av.lane(39); 4671 r[i+40]=av.lane(40); 4672 r[i+41]=av.lane(41); 4673 r[i+42]=av.lane(42); 4674 r[i+43]=av.lane(43); 4675 r[i+44]=av.lane(44); 4676 r[i+45]=av.lane(45); 4677 r[i+46]=av.lane(46); 4678 r[i+47]=av.lane(47); 4679 r[i+48]=av.lane(48); 4680 r[i+49]=av.lane(49); 4681 r[i+50]=av.lane(50); 4682 r[i+51]=av.lane(51); 4683 r[i+52]=av.lane(52); 4684 r[i+53]=av.lane(53); 4685 r[i+54]=av.lane(54); 4686 r[i+55]=av.lane(55); 4687 r[i+56]=av.lane(56); 4688 r[i+57]=av.lane(57); 4689 r[i+58]=av.lane(58); 4690 r[i+59]=av.lane(59); 4691 r[i+60]=av.lane(60); 4692 r[i+61]=av.lane(61); 4693 r[i+62]=av.lane(62); 4694 r[i+63]=av.lane(63); 4695 } else { 4696 for (int j = 0; j < SPECIES.length(); j++) { 4697 r[i+j]=av.lane(j); 4698 } 4699 } 4700 } 4701 } 4702 4703 assertArraysEquals(r, a, ByteMaxVectorTests::get); 4704 } 4705 4706 @Test(dataProvider = "byteUnaryOpProvider") 4707 static void BroadcastByteMaxVectorTests(IntFunction<byte[]> fa) { 4708 byte[] a = fa.apply(SPECIES.length()); 4709 byte[] r = new byte[a.length]; 4710 4711 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4712 for (int i = 0; i < a.length; i += SPECIES.length()) { 4713 ByteVector.broadcast(SPECIES, a[i]).intoArray(r, i); 4714 } 4715 } 4716 4717 assertBroadcastArraysEquals(r, a); 4718 } 4719 4720 @Test(dataProvider = "byteUnaryOpProvider") 4721 static void ZeroByteMaxVectorTests(IntFunction<byte[]> fa) { 4722 byte[] a = fa.apply(SPECIES.length()); 4723 byte[] r = new byte[a.length]; 4724 4725 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4726 for (int i = 0; i < a.length; i += SPECIES.length()) { 4727 ByteVector.zero(SPECIES).intoArray(a, i); 4728 } 4729 } 4730 4731 Assert.assertEquals(a, r); 4732 } 4733 4734 static byte[] sliceUnary(byte[] a, int origin, int idx) { 4735 byte[] res = new byte[SPECIES.length()]; 4736 for (int i = 0; i < SPECIES.length(); i++){ 4737 if(i+origin < SPECIES.length()) 4738 res[i] = a[idx+i+origin]; 4739 else 4740 res[i] = (byte)0; 4741 } 4742 return res; 4743 } 4744 4745 @Test(dataProvider = "byteUnaryOpProvider") 4746 static void sliceUnaryByteMaxVectorTests(IntFunction<byte[]> fa) { 4747 byte[] a = fa.apply(SPECIES.length()); 4748 byte[] r = new byte[a.length]; 4749 int origin = (new java.util.Random()).nextInt(SPECIES.length()); 4750 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4751 for (int i = 0; i < a.length; i += SPECIES.length()) { 4752 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 4753 av.slice(origin).intoArray(r, i); 4754 } 4755 } 4756 4757 assertArraysEquals(r, a, origin, ByteMaxVectorTests::sliceUnary); 4758 } 4759 4760 static byte[] sliceBinary(byte[] a, byte[] b, int origin, int idx) { 4761 byte[] res = new byte[SPECIES.length()]; 4762 for (int i = 0, j = 0; i < SPECIES.length(); i++){ 4763 if(i+origin < SPECIES.length()) 4764 res[i] = a[idx+i+origin]; 4765 else { 4766 res[i] = b[idx+j]; 4767 j++; 4768 } 4769 } 4770 return res; 4771 } 4772 4773 @Test(dataProvider = "byteBinaryOpProvider") 4774 static void sliceBinaryByteMaxVectorTestsBinary(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 4775 byte[] a = fa.apply(SPECIES.length()); 4776 byte[] b = fb.apply(SPECIES.length()); 4777 byte[] r = new byte[a.length]; 4778 int origin = (new java.util.Random()).nextInt(SPECIES.length()); 4779 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4780 for (int i = 0; i < a.length; i += SPECIES.length()) { 4781 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 4782 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 4783 av.slice(origin, bv).intoArray(r, i); 4784 } 4785 } 4786 4787 assertArraysEquals(r, a, b, origin, ByteMaxVectorTests::sliceBinary); 4788 } 4789 4790 static byte[] slice(byte[] a, byte[] b, int origin, boolean[] mask, int idx) { 4791 byte[] res = new byte[SPECIES.length()]; 4792 for (int i = 0, j = 0; i < SPECIES.length(); i++){ 4793 if(i+origin < SPECIES.length()) 4794 res[i] = mask[i] ? a[idx+i+origin] : (byte)0; 4795 else { 4796 res[i] = mask[i] ? b[idx+j] : (byte)0; 4797 j++; 4798 } 4799 } 4800 return res; 4801 } 4802 4803 @Test(dataProvider = "byteBinaryOpMaskProvider") 4804 static void sliceByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 4805 IntFunction<boolean[]> fm) { 4806 byte[] a = fa.apply(SPECIES.length()); 4807 byte[] b = fb.apply(SPECIES.length()); 4808 boolean[] mask = fm.apply(SPECIES.length()); 4809 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 4810 4811 byte[] r = new byte[a.length]; 4812 int origin = (new java.util.Random()).nextInt(SPECIES.length()); 4813 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4814 for (int i = 0; i < a.length; i += SPECIES.length()) { 4815 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 4816 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 4817 av.slice(origin, bv, vmask).intoArray(r, i); 4818 } 4819 } 4820 4821 assertArraysEquals(r, a, b, origin, mask, ByteMaxVectorTests::slice); 4822 } 4823 4824 static byte[] unsliceUnary(byte[] a, int origin, int idx) { 4825 byte[] res = new byte[SPECIES.length()]; 4826 for (int i = 0, j = 0; i < SPECIES.length(); i++){ 4827 if(i < origin) 4828 res[i] = (byte)0; 4829 else { 4830 res[i] = a[idx+j]; 4831 j++; 4832 } 4833 } 4834 return res; 4835 } 4836 4837 @Test(dataProvider = "byteUnaryOpProvider") 4838 static void unsliceUnaryByteMaxVectorTests(IntFunction<byte[]> fa) { 4839 byte[] a = fa.apply(SPECIES.length()); 4840 byte[] r = new byte[a.length]; 4841 int origin = (new java.util.Random()).nextInt(SPECIES.length()); 4842 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4843 for (int i = 0; i < a.length; i += SPECIES.length()) { 4844 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 4845 av.unslice(origin).intoArray(r, i); 4846 } 4847 } 4848 4849 assertArraysEquals(r, a, origin, ByteMaxVectorTests::unsliceUnary); 4850 } 4851 4852 static byte[] unsliceBinary(byte[] a, byte[] b, int origin, int part, int idx) { 4853 byte[] res = new byte[SPECIES.length()]; 4854 for (int i = 0, j = 0; i < SPECIES.length(); i++){ 4855 if (part == 0) { 4856 if (i < origin) 4857 res[i] = b[idx+i]; 4858 else { 4859 res[i] = a[idx+j]; 4860 j++; 4861 } 4862 } else if (part == 1) { 4863 if (i < origin) 4864 res[i] = a[idx+SPECIES.length()-origin+i]; 4865 else { 4866 res[i] = b[idx+origin+j]; 4867 j++; 4868 } 4869 } 4870 } 4871 return res; 4872 } 4873 4874 @Test(dataProvider = "byteBinaryOpProvider") 4875 static void unsliceBinaryByteMaxVectorTestsBinary(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 4876 byte[] a = fa.apply(SPECIES.length()); 4877 byte[] b = fb.apply(SPECIES.length()); 4878 byte[] r = new byte[a.length]; 4879 int origin = (new java.util.Random()).nextInt(SPECIES.length()); 4880 int part = (new java.util.Random()).nextInt(2); 4881 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4882 for (int i = 0; i < a.length; i += SPECIES.length()) { 4883 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 4884 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 4885 av.unslice(origin, bv, part).intoArray(r, i); 4886 } 4887 } 4888 4889 assertArraysEquals(r, a, b, origin, part, ByteMaxVectorTests::unsliceBinary); 4890 } 4891 4892 static byte[] unslice(byte[] a, byte[] b, int origin, int part, boolean[] mask, int idx) { 4893 byte[] res = new byte[SPECIES.length()]; 4894 for (int i = 0, j = 0; i < SPECIES.length(); i++){ 4895 if(i+origin < SPECIES.length()) 4896 res[i] = b[idx+i+origin]; 4897 else { 4898 res[i] = b[idx+j]; 4899 j++; 4900 } 4901 } 4902 for (int i = 0; i < SPECIES.length(); i++){ 4903 res[i] = mask[i] ? a[idx+i] : res[i]; 4904 } 4905 byte[] res1 = new byte[SPECIES.length()]; 4906 if (part == 0) { 4907 for (int i = 0, j = 0; i < SPECIES.length(); i++){ 4908 if (i < origin) 4909 res1[i] = b[idx+i]; 4910 else { 4911 res1[i] = res[j]; 4912 j++; 4913 } 4914 } 4915 } else if (part == 1) { 4916 for (int i = 0, j = 0; i < SPECIES.length(); i++){ 4917 if (i < origin) 4918 res1[i] = res[SPECIES.length()-origin+i]; 4919 else { 4920 res1[i] = b[idx+origin+j]; 4921 j++; 4922 } 4923 } 4924 } 4925 return res1; 4926 } 4927 4928 @Test(dataProvider = "byteBinaryOpMaskProvider") 4929 static void unsliceByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 4930 IntFunction<boolean[]> fm) { 4931 byte[] a = fa.apply(SPECIES.length()); 4932 byte[] b = fb.apply(SPECIES.length()); 4933 boolean[] mask = fm.apply(SPECIES.length()); 4934 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 4935 byte[] r = new byte[a.length]; 4936 int origin = (new java.util.Random()).nextInt(SPECIES.length()); 4937 int part = (new java.util.Random()).nextInt(2); 4938 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4939 for (int i = 0; i < a.length; i += SPECIES.length()) { 4940 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 4941 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 4942 av.unslice(origin, bv, part, vmask).intoArray(r, i); 4943 } 4944 } 4945 4946 assertArraysEquals(r, a, b, origin, part, mask, ByteMaxVectorTests::unslice); 4947 } 4948 4949 static byte BITWISE_BLEND(byte a, byte b, byte c) { 4950 return (byte)((a&~(c))|(b&c)); 4951 } 4952 4953 static byte bitwiseBlend(byte a, byte b, byte c) { 4954 return (byte)((a&~(c))|(b&c)); 4955 } 4956 4957 @Test(dataProvider = "byteTernaryOpProvider") 4958 static void BITWISE_BLENDByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb, IntFunction<byte[]> fc) { 4959 byte[] a = fa.apply(SPECIES.length()); 4960 byte[] b = fb.apply(SPECIES.length()); 4961 byte[] c = fc.apply(SPECIES.length()); 4962 byte[] r = fr.apply(SPECIES.length()); 4963 4964 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4965 for (int i = 0; i < a.length; i += SPECIES.length()) { 4966 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 4967 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 4968 ByteVector cv = ByteVector.fromArray(SPECIES, c, i); 4969 av.lanewise(VectorOperators.BITWISE_BLEND, bv, cv).intoArray(r, i); 4970 } 4971 } 4972 4973 assertArraysEquals(r, a, b, c, ByteMaxVectorTests::BITWISE_BLEND); 4974 } 4975 4976 @Test(dataProvider = "byteTernaryOpProvider") 4977 static void bitwiseBlendByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb, IntFunction<byte[]> fc) { 4978 byte[] a = fa.apply(SPECIES.length()); 4979 byte[] b = fb.apply(SPECIES.length()); 4980 byte[] c = fc.apply(SPECIES.length()); 4981 byte[] r = fr.apply(SPECIES.length()); 4982 4983 for (int i = 0; i < a.length; i += SPECIES.length()) { 4984 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 4985 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 4986 ByteVector cv = ByteVector.fromArray(SPECIES, c, i); 4987 av.bitwiseBlend(bv, cv).intoArray(r, i); 4988 } 4989 4990 assertArraysEquals(r, a, b, c, ByteMaxVectorTests::bitwiseBlend); 4991 } 4992 4993 @Test(dataProvider = "byteTernaryOpMaskProvider") 4994 static void BITWISE_BLENDByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 4995 IntFunction<byte[]> fc, IntFunction<boolean[]> fm) { 4996 byte[] a = fa.apply(SPECIES.length()); 4997 byte[] b = fb.apply(SPECIES.length()); 4998 byte[] c = fc.apply(SPECIES.length()); 4999 byte[] r = fr.apply(SPECIES.length()); 5000 boolean[] mask = fm.apply(SPECIES.length()); 5001 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 5002 5003 for (int ic = 0; ic < INVOC_COUNT; ic++) { 5004 for (int i = 0; i < a.length; i += SPECIES.length()) { 5005 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 5006 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 5007 ByteVector cv = ByteVector.fromArray(SPECIES, c, i); 5008 av.lanewise(VectorOperators.BITWISE_BLEND, bv, cv, vmask).intoArray(r, i); 5009 } 5010 } 5011 5012 assertArraysEquals(r, a, b, c, mask, ByteMaxVectorTests::BITWISE_BLEND); 5013 } 5014 5015 @Test(dataProvider = "byteTernaryOpProvider") 5016 static void BITWISE_BLENDByteMaxVectorTestsBroadcastSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb, IntFunction<byte[]> fc) { 5017 byte[] a = fa.apply(SPECIES.length()); 5018 byte[] b = fb.apply(SPECIES.length()); 5019 byte[] c = fc.apply(SPECIES.length()); 5020 byte[] r = fr.apply(SPECIES.length()); 5021 5022 for (int i = 0; i < a.length; i += SPECIES.length()) { 5023 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 5024 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 5025 av.lanewise(VectorOperators.BITWISE_BLEND, bv, c[i]).intoArray(r, i); 5026 } 5027 assertBroadcastArraysEquals(r, a, b, c, ByteMaxVectorTests::BITWISE_BLEND); 5028 } 5029 5030 @Test(dataProvider = "byteTernaryOpProvider") 5031 static void BITWISE_BLENDByteMaxVectorTestsAltBroadcastSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb, IntFunction<byte[]> fc) { 5032 byte[] a = fa.apply(SPECIES.length()); 5033 byte[] b = fb.apply(SPECIES.length()); 5034 byte[] c = fc.apply(SPECIES.length()); 5035 byte[] r = fr.apply(SPECIES.length()); 5036 5037 for (int i = 0; i < a.length; i += SPECIES.length()) { 5038 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 5039 ByteVector cv = ByteVector.fromArray(SPECIES, c, i); 5040 av.lanewise(VectorOperators.BITWISE_BLEND, b[i], cv).intoArray(r, i); 5041 } 5042 assertAltBroadcastArraysEquals(r, a, b, c, ByteMaxVectorTests::BITWISE_BLEND); 5043 } 5044 5045 @Test(dataProvider = "byteTernaryOpProvider") 5046 static void bitwiseBlendByteMaxVectorTestsBroadcastSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb, IntFunction<byte[]> fc) { 5047 byte[] a = fa.apply(SPECIES.length()); 5048 byte[] b = fb.apply(SPECIES.length()); 5049 byte[] c = fc.apply(SPECIES.length()); 5050 byte[] r = fr.apply(SPECIES.length()); 5051 5052 for (int i = 0; i < a.length; i += SPECIES.length()) { 5053 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 5054 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 5055 av.bitwiseBlend(bv, c[i]).intoArray(r, i); 5056 } 5057 assertBroadcastArraysEquals(r, a, b, c, ByteMaxVectorTests::bitwiseBlend); 5058 } 5059 5060 @Test(dataProvider = "byteTernaryOpProvider") 5061 static void bitwiseBlendByteMaxVectorTestsAltBroadcastSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb, IntFunction<byte[]> fc) { 5062 byte[] a = fa.apply(SPECIES.length()); 5063 byte[] b = fb.apply(SPECIES.length()); 5064 byte[] c = fc.apply(SPECIES.length()); 5065 byte[] r = fr.apply(SPECIES.length()); 5066 5067 for (int i = 0; i < a.length; i += SPECIES.length()) { 5068 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 5069 ByteVector cv = ByteVector.fromArray(SPECIES, c, i); 5070 av.bitwiseBlend(b[i], cv).intoArray(r, i); 5071 } 5072 assertAltBroadcastArraysEquals(r, a, b, c, ByteMaxVectorTests::bitwiseBlend); 5073 } 5074 5075 @Test(dataProvider = "byteTernaryOpMaskProvider") 5076 static void BITWISE_BLENDByteMaxVectorTestsBroadcastMaskedSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 5077 IntFunction<byte[]> fc, IntFunction<boolean[]> fm) { 5078 byte[] a = fa.apply(SPECIES.length()); 5079 byte[] b = fb.apply(SPECIES.length()); 5080 byte[] c = fc.apply(SPECIES.length()); 5081 byte[] r = fr.apply(SPECIES.length()); 5082 boolean[] mask = fm.apply(SPECIES.length()); 5083 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 5084 5085 for (int i = 0; i < a.length; i += SPECIES.length()) { 5086 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 5087 ByteVector bv = ByteVector.fromArray(SPECIES, b, i); 5088 av.lanewise(VectorOperators.BITWISE_BLEND, bv, c[i], vmask).intoArray(r, i); 5089 } 5090 5091 assertBroadcastArraysEquals(r, a, b, c, mask, ByteMaxVectorTests::BITWISE_BLEND); 5092 } 5093 5094 @Test(dataProvider = "byteTernaryOpMaskProvider") 5095 static void BITWISE_BLENDByteMaxVectorTestsAltBroadcastMaskedSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 5096 IntFunction<byte[]> fc, IntFunction<boolean[]> fm) { 5097 byte[] a = fa.apply(SPECIES.length()); 5098 byte[] b = fb.apply(SPECIES.length()); 5099 byte[] c = fc.apply(SPECIES.length()); 5100 byte[] r = fr.apply(SPECIES.length()); 5101 boolean[] mask = fm.apply(SPECIES.length()); 5102 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 5103 5104 for (int i = 0; i < a.length; i += SPECIES.length()) { 5105 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 5106 ByteVector cv = ByteVector.fromArray(SPECIES, c, i); 5107 av.lanewise(VectorOperators.BITWISE_BLEND, b[i], cv, vmask).intoArray(r, i); 5108 } 5109 5110 assertAltBroadcastArraysEquals(r, a, b, c, mask, ByteMaxVectorTests::BITWISE_BLEND); 5111 } 5112 5113 @Test(dataProvider = "byteTernaryOpProvider") 5114 static void BITWISE_BLENDByteMaxVectorTestsDoubleBroadcastSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb, IntFunction<byte[]> fc) { 5115 byte[] a = fa.apply(SPECIES.length()); 5116 byte[] b = fb.apply(SPECIES.length()); 5117 byte[] c = fc.apply(SPECIES.length()); 5118 byte[] r = fr.apply(SPECIES.length()); 5119 5120 for (int i = 0; i < a.length; i += SPECIES.length()) { 5121 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 5122 av.lanewise(VectorOperators.BITWISE_BLEND, b[i], c[i]).intoArray(r, i); 5123 } 5124 5125 assertDoubleBroadcastArraysEquals(r, a, b, c, ByteMaxVectorTests::BITWISE_BLEND); 5126 } 5127 5128 @Test(dataProvider = "byteTernaryOpProvider") 5129 static void bitwiseBlendByteMaxVectorTestsDoubleBroadcastSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb, IntFunction<byte[]> fc) { 5130 byte[] a = fa.apply(SPECIES.length()); 5131 byte[] b = fb.apply(SPECIES.length()); 5132 byte[] c = fc.apply(SPECIES.length()); 5133 byte[] r = fr.apply(SPECIES.length()); 5134 5135 for (int i = 0; i < a.length; i += SPECIES.length()) { 5136 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 5137 av.bitwiseBlend(b[i], c[i]).intoArray(r, i); 5138 } 5139 5140 assertDoubleBroadcastArraysEquals(r, a, b, c, ByteMaxVectorTests::bitwiseBlend); 5141 } 5142 5143 @Test(dataProvider = "byteTernaryOpMaskProvider") 5144 static void BITWISE_BLENDByteMaxVectorTestsDoubleBroadcastMaskedSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 5145 IntFunction<byte[]> fc, IntFunction<boolean[]> fm) { 5146 byte[] a = fa.apply(SPECIES.length()); 5147 byte[] b = fb.apply(SPECIES.length()); 5148 byte[] c = fc.apply(SPECIES.length()); 5149 byte[] r = fr.apply(SPECIES.length()); 5150 boolean[] mask = fm.apply(SPECIES.length()); 5151 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 5152 5153 for (int i = 0; i < a.length; i += SPECIES.length()) { 5154 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 5155 av.lanewise(VectorOperators.BITWISE_BLEND, b[i], c[i], vmask).intoArray(r, i); 5156 } 5157 5158 assertDoubleBroadcastArraysEquals(r, a, b, c, mask, ByteMaxVectorTests::BITWISE_BLEND); 5159 } 5160 5161 static byte NEG(byte a) { 5162 return (byte)(-((byte)a)); 5163 } 5164 5165 static byte neg(byte a) { 5166 return (byte)(-((byte)a)); 5167 } 5168 5169 @Test(dataProvider = "byteUnaryOpProvider") 5170 static void NEGByteMaxVectorTests(IntFunction<byte[]> fa) { 5171 byte[] a = fa.apply(SPECIES.length()); 5172 byte[] r = fr.apply(SPECIES.length()); 5173 5174 for (int ic = 0; ic < INVOC_COUNT; ic++) { 5175 for (int i = 0; i < a.length; i += SPECIES.length()) { 5176 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 5177 av.lanewise(VectorOperators.NEG).intoArray(r, i); 5178 } 5179 } 5180 5181 assertArraysEquals(r, a, ByteMaxVectorTests::NEG); 5182 } 5183 5184 @Test(dataProvider = "byteUnaryOpProvider") 5185 static void negByteMaxVectorTests(IntFunction<byte[]> fa) { 5186 byte[] a = fa.apply(SPECIES.length()); 5187 byte[] r = fr.apply(SPECIES.length()); 5188 5189 for (int ic = 0; ic < INVOC_COUNT; ic++) { 5190 for (int i = 0; i < a.length; i += SPECIES.length()) { 5191 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 5192 av.neg().intoArray(r, i); 5193 } 5194 } 5195 5196 assertArraysEquals(r, a, ByteMaxVectorTests::neg); 5197 } 5198 5199 @Test(dataProvider = "byteUnaryOpMaskProvider") 5200 static void NEGMaskedByteMaxVectorTests(IntFunction<byte[]> fa, 5201 IntFunction<boolean[]> fm) { 5202 byte[] a = fa.apply(SPECIES.length()); 5203 byte[] r = fr.apply(SPECIES.length()); 5204 boolean[] mask = fm.apply(SPECIES.length()); 5205 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 5206 5207 for (int ic = 0; ic < INVOC_COUNT; ic++) { 5208 for (int i = 0; i < a.length; i += SPECIES.length()) { 5209 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 5210 av.lanewise(VectorOperators.NEG, vmask).intoArray(r, i); 5211 } 5212 } 5213 5214 assertArraysEquals(r, a, mask, ByteMaxVectorTests::NEG); 5215 } 5216 5217 static byte ABS(byte a) { 5218 return (byte)(Math.abs((byte)a)); 5219 } 5220 5221 static byte abs(byte a) { 5222 return (byte)(Math.abs((byte)a)); 5223 } 5224 5225 @Test(dataProvider = "byteUnaryOpProvider") 5226 static void ABSByteMaxVectorTests(IntFunction<byte[]> fa) { 5227 byte[] a = fa.apply(SPECIES.length()); 5228 byte[] r = fr.apply(SPECIES.length()); 5229 5230 for (int ic = 0; ic < INVOC_COUNT; ic++) { 5231 for (int i = 0; i < a.length; i += SPECIES.length()) { 5232 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 5233 av.lanewise(VectorOperators.ABS).intoArray(r, i); 5234 } 5235 } 5236 5237 assertArraysEquals(r, a, ByteMaxVectorTests::ABS); 5238 } 5239 5240 @Test(dataProvider = "byteUnaryOpProvider") 5241 static void absByteMaxVectorTests(IntFunction<byte[]> fa) { 5242 byte[] a = fa.apply(SPECIES.length()); 5243 byte[] r = fr.apply(SPECIES.length()); 5244 5245 for (int ic = 0; ic < INVOC_COUNT; ic++) { 5246 for (int i = 0; i < a.length; i += SPECIES.length()) { 5247 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 5248 av.abs().intoArray(r, i); 5249 } 5250 } 5251 5252 assertArraysEquals(r, a, ByteMaxVectorTests::abs); 5253 } 5254 5255 @Test(dataProvider = "byteUnaryOpMaskProvider") 5256 static void ABSMaskedByteMaxVectorTests(IntFunction<byte[]> fa, 5257 IntFunction<boolean[]> fm) { 5258 byte[] a = fa.apply(SPECIES.length()); 5259 byte[] r = fr.apply(SPECIES.length()); 5260 boolean[] mask = fm.apply(SPECIES.length()); 5261 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 5262 5263 for (int ic = 0; ic < INVOC_COUNT; ic++) { 5264 for (int i = 0; i < a.length; i += SPECIES.length()) { 5265 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 5266 av.lanewise(VectorOperators.ABS, vmask).intoArray(r, i); 5267 } 5268 } 5269 5270 assertArraysEquals(r, a, mask, ByteMaxVectorTests::ABS); 5271 } 5272 5273 static byte NOT(byte a) { 5274 return (byte)(~((byte)a)); 5275 } 5276 5277 static byte not(byte a) { 5278 return (byte)(~((byte)a)); 5279 } 5280 5281 @Test(dataProvider = "byteUnaryOpProvider") 5282 static void NOTByteMaxVectorTests(IntFunction<byte[]> fa) { 5283 byte[] a = fa.apply(SPECIES.length()); 5284 byte[] r = fr.apply(SPECIES.length()); 5285 5286 for (int ic = 0; ic < INVOC_COUNT; ic++) { 5287 for (int i = 0; i < a.length; i += SPECIES.length()) { 5288 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 5289 av.lanewise(VectorOperators.NOT).intoArray(r, i); 5290 } 5291 } 5292 5293 assertArraysEquals(r, a, ByteMaxVectorTests::NOT); 5294 } 5295 5296 @Test(dataProvider = "byteUnaryOpProvider") 5297 static void notByteMaxVectorTests(IntFunction<byte[]> fa) { 5298 byte[] a = fa.apply(SPECIES.length()); 5299 byte[] r = fr.apply(SPECIES.length()); 5300 5301 for (int ic = 0; ic < INVOC_COUNT; ic++) { 5302 for (int i = 0; i < a.length; i += SPECIES.length()) { 5303 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 5304 av.not().intoArray(r, i); 5305 } 5306 } 5307 5308 assertArraysEquals(r, a, ByteMaxVectorTests::not); 5309 } 5310 5311 @Test(dataProvider = "byteUnaryOpMaskProvider") 5312 static void NOTMaskedByteMaxVectorTests(IntFunction<byte[]> fa, 5313 IntFunction<boolean[]> fm) { 5314 byte[] a = fa.apply(SPECIES.length()); 5315 byte[] r = fr.apply(SPECIES.length()); 5316 boolean[] mask = fm.apply(SPECIES.length()); 5317 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 5318 5319 for (int ic = 0; ic < INVOC_COUNT; ic++) { 5320 for (int i = 0; i < a.length; i += SPECIES.length()) { 5321 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 5322 av.lanewise(VectorOperators.NOT, vmask).intoArray(r, i); 5323 } 5324 } 5325 5326 assertArraysEquals(r, a, mask, ByteMaxVectorTests::NOT); 5327 } 5328 5329 static byte ZOMO(byte a) { 5330 return (byte)((a==0?0:-1)); 5331 } 5332 5333 @Test(dataProvider = "byteUnaryOpProvider") 5334 static void ZOMOByteMaxVectorTests(IntFunction<byte[]> fa) { 5335 byte[] a = fa.apply(SPECIES.length()); 5336 byte[] r = fr.apply(SPECIES.length()); 5337 5338 for (int ic = 0; ic < INVOC_COUNT; ic++) { 5339 for (int i = 0; i < a.length; i += SPECIES.length()) { 5340 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 5341 av.lanewise(VectorOperators.ZOMO).intoArray(r, i); 5342 } 5343 } 5344 5345 assertArraysEquals(r, a, ByteMaxVectorTests::ZOMO); 5346 } 5347 5348 @Test(dataProvider = "byteUnaryOpMaskProvider") 5349 static void ZOMOMaskedByteMaxVectorTests(IntFunction<byte[]> fa, 5350 IntFunction<boolean[]> fm) { 5351 byte[] a = fa.apply(SPECIES.length()); 5352 byte[] r = fr.apply(SPECIES.length()); 5353 boolean[] mask = fm.apply(SPECIES.length()); 5354 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 5355 5356 for (int ic = 0; ic < INVOC_COUNT; ic++) { 5357 for (int i = 0; i < a.length; i += SPECIES.length()) { 5358 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 5359 av.lanewise(VectorOperators.ZOMO, vmask).intoArray(r, i); 5360 } 5361 } 5362 5363 assertArraysEquals(r, a, mask, ByteMaxVectorTests::ZOMO); 5364 } 5365 5366 static byte BIT_COUNT(byte a) { 5367 return (byte)(Integer.bitCount((int)a & 0xFF)); 5368 } 5369 5370 @Test(dataProvider = "byteUnaryOpProvider") 5371 static void BIT_COUNTByteMaxVectorTests(IntFunction<byte[]> fa) { 5372 byte[] a = fa.apply(SPECIES.length()); 5373 byte[] r = fr.apply(SPECIES.length()); 5374 5375 for (int ic = 0; ic < INVOC_COUNT; ic++) { 5376 for (int i = 0; i < a.length; i += SPECIES.length()) { 5377 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 5378 av.lanewise(VectorOperators.BIT_COUNT).intoArray(r, i); 5379 } 5380 } 5381 5382 assertArraysEquals(r, a, ByteMaxVectorTests::BIT_COUNT); 5383 } 5384 5385 @Test(dataProvider = "byteUnaryOpMaskProvider") 5386 static void BIT_COUNTMaskedByteMaxVectorTests(IntFunction<byte[]> fa, 5387 IntFunction<boolean[]> fm) { 5388 byte[] a = fa.apply(SPECIES.length()); 5389 byte[] r = fr.apply(SPECIES.length()); 5390 boolean[] mask = fm.apply(SPECIES.length()); 5391 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 5392 5393 for (int ic = 0; ic < INVOC_COUNT; ic++) { 5394 for (int i = 0; i < a.length; i += SPECIES.length()) { 5395 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 5396 av.lanewise(VectorOperators.BIT_COUNT, vmask).intoArray(r, i); 5397 } 5398 } 5399 5400 assertArraysEquals(r, a, mask, ByteMaxVectorTests::BIT_COUNT); 5401 } 5402 5403 static byte TRAILING_ZEROS_COUNT(byte a) { 5404 return (byte)(TRAILING_ZEROS_COUNT_scalar(a)); 5405 } 5406 5407 @Test(dataProvider = "byteUnaryOpProvider") 5408 static void TRAILING_ZEROS_COUNTByteMaxVectorTests(IntFunction<byte[]> fa) { 5409 byte[] a = fa.apply(SPECIES.length()); 5410 byte[] r = fr.apply(SPECIES.length()); 5411 5412 for (int ic = 0; ic < INVOC_COUNT; ic++) { 5413 for (int i = 0; i < a.length; i += SPECIES.length()) { 5414 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 5415 av.lanewise(VectorOperators.TRAILING_ZEROS_COUNT).intoArray(r, i); 5416 } 5417 } 5418 5419 assertArraysEquals(r, a, ByteMaxVectorTests::TRAILING_ZEROS_COUNT); 5420 } 5421 5422 @Test(dataProvider = "byteUnaryOpMaskProvider") 5423 static void TRAILING_ZEROS_COUNTMaskedByteMaxVectorTests(IntFunction<byte[]> fa, 5424 IntFunction<boolean[]> fm) { 5425 byte[] a = fa.apply(SPECIES.length()); 5426 byte[] r = fr.apply(SPECIES.length()); 5427 boolean[] mask = fm.apply(SPECIES.length()); 5428 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 5429 5430 for (int ic = 0; ic < INVOC_COUNT; ic++) { 5431 for (int i = 0; i < a.length; i += SPECIES.length()) { 5432 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 5433 av.lanewise(VectorOperators.TRAILING_ZEROS_COUNT, vmask).intoArray(r, i); 5434 } 5435 } 5436 5437 assertArraysEquals(r, a, mask, ByteMaxVectorTests::TRAILING_ZEROS_COUNT); 5438 } 5439 5440 static byte LEADING_ZEROS_COUNT(byte a) { 5441 return (byte)(LEADING_ZEROS_COUNT_scalar(a)); 5442 } 5443 5444 @Test(dataProvider = "byteUnaryOpProvider") 5445 static void LEADING_ZEROS_COUNTByteMaxVectorTests(IntFunction<byte[]> fa) { 5446 byte[] a = fa.apply(SPECIES.length()); 5447 byte[] r = fr.apply(SPECIES.length()); 5448 5449 for (int ic = 0; ic < INVOC_COUNT; ic++) { 5450 for (int i = 0; i < a.length; i += SPECIES.length()) { 5451 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 5452 av.lanewise(VectorOperators.LEADING_ZEROS_COUNT).intoArray(r, i); 5453 } 5454 } 5455 5456 assertArraysEquals(r, a, ByteMaxVectorTests::LEADING_ZEROS_COUNT); 5457 } 5458 5459 @Test(dataProvider = "byteUnaryOpMaskProvider") 5460 static void LEADING_ZEROS_COUNTMaskedByteMaxVectorTests(IntFunction<byte[]> fa, 5461 IntFunction<boolean[]> fm) { 5462 byte[] a = fa.apply(SPECIES.length()); 5463 byte[] r = fr.apply(SPECIES.length()); 5464 boolean[] mask = fm.apply(SPECIES.length()); 5465 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 5466 5467 for (int ic = 0; ic < INVOC_COUNT; ic++) { 5468 for (int i = 0; i < a.length; i += SPECIES.length()) { 5469 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 5470 av.lanewise(VectorOperators.LEADING_ZEROS_COUNT, vmask).intoArray(r, i); 5471 } 5472 } 5473 5474 assertArraysEquals(r, a, mask, ByteMaxVectorTests::LEADING_ZEROS_COUNT); 5475 } 5476 5477 static byte REVERSE(byte a) { 5478 return (byte)(REVERSE_scalar(a)); 5479 } 5480 5481 @Test(dataProvider = "byteUnaryOpProvider") 5482 static void REVERSEByteMaxVectorTests(IntFunction<byte[]> fa) { 5483 byte[] a = fa.apply(SPECIES.length()); 5484 byte[] r = fr.apply(SPECIES.length()); 5485 5486 for (int ic = 0; ic < INVOC_COUNT; ic++) { 5487 for (int i = 0; i < a.length; i += SPECIES.length()) { 5488 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 5489 av.lanewise(VectorOperators.REVERSE).intoArray(r, i); 5490 } 5491 } 5492 5493 assertArraysEquals(r, a, ByteMaxVectorTests::REVERSE); 5494 } 5495 5496 @Test(dataProvider = "byteUnaryOpMaskProvider") 5497 static void REVERSEMaskedByteMaxVectorTests(IntFunction<byte[]> fa, 5498 IntFunction<boolean[]> fm) { 5499 byte[] a = fa.apply(SPECIES.length()); 5500 byte[] r = fr.apply(SPECIES.length()); 5501 boolean[] mask = fm.apply(SPECIES.length()); 5502 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 5503 5504 for (int ic = 0; ic < INVOC_COUNT; ic++) { 5505 for (int i = 0; i < a.length; i += SPECIES.length()) { 5506 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 5507 av.lanewise(VectorOperators.REVERSE, vmask).intoArray(r, i); 5508 } 5509 } 5510 5511 assertArraysEquals(r, a, mask, ByteMaxVectorTests::REVERSE); 5512 } 5513 5514 static byte REVERSE_BYTES(byte a) { 5515 return (byte)(a); 5516 } 5517 5518 @Test(dataProvider = "byteUnaryOpProvider") 5519 static void REVERSE_BYTESByteMaxVectorTests(IntFunction<byte[]> fa) { 5520 byte[] a = fa.apply(SPECIES.length()); 5521 byte[] r = fr.apply(SPECIES.length()); 5522 5523 for (int ic = 0; ic < INVOC_COUNT; ic++) { 5524 for (int i = 0; i < a.length; i += SPECIES.length()) { 5525 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 5526 av.lanewise(VectorOperators.REVERSE_BYTES).intoArray(r, i); 5527 } 5528 } 5529 5530 assertArraysEquals(r, a, ByteMaxVectorTests::REVERSE_BYTES); 5531 } 5532 5533 @Test(dataProvider = "byteUnaryOpMaskProvider") 5534 static void REVERSE_BYTESMaskedByteMaxVectorTests(IntFunction<byte[]> fa, 5535 IntFunction<boolean[]> fm) { 5536 byte[] a = fa.apply(SPECIES.length()); 5537 byte[] r = fr.apply(SPECIES.length()); 5538 boolean[] mask = fm.apply(SPECIES.length()); 5539 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 5540 5541 for (int ic = 0; ic < INVOC_COUNT; ic++) { 5542 for (int i = 0; i < a.length; i += SPECIES.length()) { 5543 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 5544 av.lanewise(VectorOperators.REVERSE_BYTES, vmask).intoArray(r, i); 5545 } 5546 } 5547 5548 assertArraysEquals(r, a, mask, ByteMaxVectorTests::REVERSE_BYTES); 5549 } 5550 5551 @Test(dataProvider = "byteCompareOpProvider") 5552 static void ltByteMaxVectorTestsBroadcastSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 5553 byte[] a = fa.apply(SPECIES.length()); 5554 byte[] b = fb.apply(SPECIES.length()); 5555 5556 for (int i = 0; i < a.length; i += SPECIES.length()) { 5557 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 5558 VectorMask<Byte> mv = av.lt(b[i]); 5559 5560 // Check results as part of computation. 5561 for (int j = 0; j < SPECIES.length(); j++) { 5562 Assert.assertEquals(mv.laneIsSet(j), a[i + j] < b[i]); 5563 } 5564 } 5565 } 5566 5567 @Test(dataProvider = "byteCompareOpProvider") 5568 static void eqByteMaxVectorTestsBroadcastMaskedSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { 5569 byte[] a = fa.apply(SPECIES.length()); 5570 byte[] b = fb.apply(SPECIES.length()); 5571 5572 for (int i = 0; i < a.length; i += SPECIES.length()) { 5573 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 5574 VectorMask<Byte> mv = av.eq(b[i]); 5575 5576 // Check results as part of computation. 5577 for (int j = 0; j < SPECIES.length(); j++) { 5578 Assert.assertEquals(mv.laneIsSet(j), a[i + j] == b[i]); 5579 } 5580 } 5581 } 5582 5583 @Test(dataProvider = "byteUnaryOpProvider") 5584 static void toIntArrayByteMaxVectorTestsSmokeTest(IntFunction<byte[]> fa) { 5585 byte[] a = fa.apply(SPECIES.length()); 5586 5587 for (int i = 0; i < a.length; i += SPECIES.length()) { 5588 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 5589 int[] r = av.toIntArray(); 5590 assertArraysEquals(r, a, i); 5591 } 5592 } 5593 5594 @Test(dataProvider = "byteUnaryOpProvider") 5595 static void toLongArrayByteMaxVectorTestsSmokeTest(IntFunction<byte[]> fa) { 5596 byte[] a = fa.apply(SPECIES.length()); 5597 5598 for (int i = 0; i < a.length; i += SPECIES.length()) { 5599 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 5600 long[] r = av.toLongArray(); 5601 assertArraysEquals(r, a, i); 5602 } 5603 } 5604 5605 @Test(dataProvider = "byteUnaryOpProvider") 5606 static void toDoubleArrayByteMaxVectorTestsSmokeTest(IntFunction<byte[]> fa) { 5607 byte[] a = fa.apply(SPECIES.length()); 5608 5609 for (int i = 0; i < a.length; i += SPECIES.length()) { 5610 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 5611 double[] r = av.toDoubleArray(); 5612 assertArraysEquals(r, a, i); 5613 } 5614 } 5615 5616 @Test(dataProvider = "byteUnaryOpProvider") 5617 static void toStringByteMaxVectorTestsSmokeTest(IntFunction<byte[]> fa) { 5618 byte[] a = fa.apply(SPECIES.length()); 5619 5620 for (int i = 0; i < a.length; i += SPECIES.length()) { 5621 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 5622 String str = av.toString(); 5623 5624 byte subarr[] = Arrays.copyOfRange(a, i, i + SPECIES.length()); 5625 Assert.assertTrue(str.equals(Arrays.toString(subarr)), "at index " + i + ", string should be = " + Arrays.toString(subarr) + ", but is = " + str); 5626 } 5627 } 5628 5629 @Test(dataProvider = "byteUnaryOpProvider") 5630 static void hashCodeByteMaxVectorTestsSmokeTest(IntFunction<byte[]> fa) { 5631 byte[] a = fa.apply(SPECIES.length()); 5632 5633 for (int i = 0; i < a.length; i += SPECIES.length()) { 5634 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 5635 int hash = av.hashCode(); 5636 5637 byte subarr[] = Arrays.copyOfRange(a, i, i + SPECIES.length()); 5638 int expectedHash = Objects.hash(SPECIES, Arrays.hashCode(subarr)); 5639 Assert.assertTrue(hash == expectedHash, "at index " + i + ", hash should be = " + expectedHash + ", but is = " + hash); 5640 } 5641 } 5642 5643 @Test(dataProvider = "byteUnaryOpProvider") 5644 static void reinterpretAsBytesByteMaxVectorTestsSmokeTest(IntFunction<byte[]> fa) { 5645 byte[] a = fa.apply(SPECIES.length()); 5646 byte[] r = new byte[a.length]; 5647 5648 for (int i = 0; i < a.length; i += SPECIES.length()) { 5649 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 5650 av.reinterpretAsBytes().intoArray(r, i); 5651 } 5652 assertArraysEquals(r, a, 0); 5653 } 5654 5655 static long ADDReduceLong(byte[] a, int idx) { 5656 byte res = 0; 5657 for (int i = idx; i < (idx + SPECIES.length()); i++) { 5658 res += a[i]; 5659 } 5660 5661 return (long)res; 5662 } 5663 5664 static long ADDReduceAllLong(byte[] a) { 5665 long res = 0; 5666 for (int i = 0; i < a.length; i += SPECIES.length()) { 5667 res += ADDReduceLong(a, i); 5668 } 5669 5670 return res; 5671 } 5672 5673 @Test(dataProvider = "byteUnaryOpProvider") 5674 static void ADDReduceLongByteMaxVectorTests(IntFunction<byte[]> fa) { 5675 byte[] a = fa.apply(SPECIES.length()); 5676 long[] r = lfr.apply(SPECIES.length()); 5677 long ra = 0; 5678 5679 for (int i = 0; i < a.length; i += SPECIES.length()) { 5680 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 5681 r[i] = av.reduceLanesToLong(VectorOperators.ADD); 5682 } 5683 5684 ra = 0; 5685 for (int i = 0; i < a.length; i ++) { 5686 ra += r[i]; 5687 } 5688 5689 assertReductionLongArraysEquals(r, ra, a, 5690 ByteMaxVectorTests::ADDReduceLong, ByteMaxVectorTests::ADDReduceAllLong); 5691 } 5692 5693 static long ADDReduceLongMasked(byte[] a, int idx, boolean[] mask) { 5694 byte res = 0; 5695 for (int i = idx; i < (idx + SPECIES.length()); i++) { 5696 if(mask[i % SPECIES.length()]) 5697 res += a[i]; 5698 } 5699 5700 return (long)res; 5701 } 5702 5703 static long ADDReduceAllLongMasked(byte[] a, boolean[] mask) { 5704 long res = 0; 5705 for (int i = 0; i < a.length; i += SPECIES.length()) { 5706 res += ADDReduceLongMasked(a, i, mask); 5707 } 5708 5709 return res; 5710 } 5711 5712 @Test(dataProvider = "byteUnaryOpMaskProvider") 5713 static void ADDReduceLongByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<boolean[]> fm) { 5714 byte[] a = fa.apply(SPECIES.length()); 5715 long[] r = lfr.apply(SPECIES.length()); 5716 boolean[] mask = fm.apply(SPECIES.length()); 5717 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 5718 long ra = 0; 5719 5720 for (int i = 0; i < a.length; i += SPECIES.length()) { 5721 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 5722 r[i] = av.reduceLanesToLong(VectorOperators.ADD, vmask); 5723 } 5724 5725 ra = 0; 5726 for (int i = 0; i < a.length; i ++) { 5727 ra += r[i]; 5728 } 5729 5730 assertReductionLongArraysEqualsMasked(r, ra, a, mask, 5731 ByteMaxVectorTests::ADDReduceLongMasked, ByteMaxVectorTests::ADDReduceAllLongMasked); 5732 } 5733 5734 @Test(dataProvider = "byteUnaryOpProvider") 5735 static void BroadcastLongByteMaxVectorTestsSmokeTest(IntFunction<byte[]> fa) { 5736 byte[] a = fa.apply(SPECIES.length()); 5737 byte[] r = new byte[a.length]; 5738 5739 for (int i = 0; i < a.length; i += SPECIES.length()) { 5740 ByteVector.broadcast(SPECIES, (long)a[i]).intoArray(r, i); 5741 } 5742 assertBroadcastArraysEquals(r, a); 5743 } 5744 5745 @Test(dataProvider = "byteBinaryOpMaskProvider") 5746 static void blendByteMaxVectorTestsBroadcastLongSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb, 5747 IntFunction<boolean[]> fm) { 5748 byte[] a = fa.apply(SPECIES.length()); 5749 byte[] b = fb.apply(SPECIES.length()); 5750 byte[] r = fr.apply(SPECIES.length()); 5751 boolean[] mask = fm.apply(SPECIES.length()); 5752 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 5753 5754 for (int ic = 0; ic < INVOC_COUNT; ic++) { 5755 for (int i = 0; i < a.length; i += SPECIES.length()) { 5756 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 5757 av.blend((long)b[i], vmask).intoArray(r, i); 5758 } 5759 } 5760 assertBroadcastLongArraysEquals(r, a, b, mask, ByteMaxVectorTests::blend); 5761 } 5762 5763 5764 @Test(dataProvider = "byteUnaryOpSelectFromProvider") 5765 static void SelectFromByteMaxVectorTests(IntFunction<byte[]> fa, 5766 BiFunction<Integer,Integer,byte[]> fs) { 5767 byte[] a = fa.apply(SPECIES.length()); 5768 byte[] order = fs.apply(a.length, SPECIES.length()); 5769 byte[] r = fr.apply(SPECIES.length()); 5770 5771 for (int i = 0; i < a.length; i += SPECIES.length()) { 5772 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 5773 ByteVector bv = ByteVector.fromArray(SPECIES, order, i); 5774 bv.selectFrom(av).intoArray(r, i); 5775 } 5776 5777 assertSelectFromArraysEquals(r, a, order, SPECIES.length()); 5778 } 5779 5780 @Test(dataProvider = "byteUnaryOpSelectFromMaskProvider") 5781 static void SelectFromByteMaxVectorTestsMaskedSmokeTest(IntFunction<byte[]> fa, 5782 BiFunction<Integer,Integer,byte[]> fs, 5783 IntFunction<boolean[]> fm) { 5784 byte[] a = fa.apply(SPECIES.length()); 5785 byte[] order = fs.apply(a.length, SPECIES.length()); 5786 byte[] r = fr.apply(SPECIES.length()); 5787 boolean[] mask = fm.apply(SPECIES.length()); 5788 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0); 5789 5790 for (int i = 0; i < a.length; i += SPECIES.length()) { 5791 ByteVector av = ByteVector.fromArray(SPECIES, a, i); 5792 ByteVector bv = ByteVector.fromArray(SPECIES, order, i); 5793 bv.selectFrom(av, vmask).intoArray(r, i); 5794 } 5795 5796 assertSelectFromArraysEquals(r, a, order, mask, SPECIES.length()); 5797 } 5798 5799 @Test(dataProvider = "shuffleProvider") 5800 static void shuffleMiscellaneousByteMaxVectorTestsSmokeTest(BiFunction<Integer,Integer,int[]> fs) { 5801 int[] a = fs.apply(SPECIES.length() * BUFFER_REPS, SPECIES.length()); 5802 5803 for (int i = 0; i < a.length; i += SPECIES.length()) { 5804 var shuffle = VectorShuffle.fromArray(SPECIES, a, i); 5805 int hash = shuffle.hashCode(); 5806 int length = shuffle.length(); 5807 5808 int subarr[] = Arrays.copyOfRange(a, i, i + SPECIES.length()); 5809 int expectedHash = Objects.hash(SPECIES, Arrays.hashCode(subarr)); 5810 Assert.assertTrue(hash == expectedHash, "at index " + i + ", hash should be = " + expectedHash + ", but is = " + hash); 5811 Assert.assertEquals(length, SPECIES.length()); 5812 } 5813 } 5814 5815 @Test(dataProvider = "shuffleProvider") 5816 static void shuffleToStringByteMaxVectorTestsSmokeTest(BiFunction<Integer,Integer,int[]> fs) { 5817 int[] a = fs.apply(SPECIES.length() * BUFFER_REPS, SPECIES.length()); 5818 5819 for (int i = 0; i < a.length; i += SPECIES.length()) { 5820 var shuffle = VectorShuffle.fromArray(SPECIES, a, i); 5821 String str = shuffle.toString(); 5822 5823 int subarr[] = Arrays.copyOfRange(a, i, i + SPECIES.length()); 5824 Assert.assertTrue(str.equals("Shuffle" + Arrays.toString(subarr)), "at index " + 5825 i + ", string should be = " + Arrays.toString(subarr) + ", but is = " + str); 5826 } 5827 } 5828 5829 @Test(dataProvider = "shuffleCompareOpProvider") 5830 static void shuffleEqualsByteMaxVectorTestsSmokeTest(BiFunction<Integer,Integer,int[]> fa, BiFunction<Integer,Integer,int[]> fb) { 5831 int[] a = fa.apply(SPECIES.length() * BUFFER_REPS, SPECIES.length()); 5832 int[] b = fb.apply(SPECIES.length() * BUFFER_REPS, SPECIES.length()); 5833 5834 for (int i = 0; i < a.length; i += SPECIES.length()) { 5835 var av = VectorShuffle.fromArray(SPECIES, a, i); 5836 var bv = VectorShuffle.fromArray(SPECIES, b, i); 5837 boolean eq = av.equals(bv); 5838 int to = i + SPECIES.length(); 5839 Assert.assertEquals(eq, Arrays.equals(a, i, to, b, i, to)); 5840 } 5841 } 5842 5843 @Test(dataProvider = "maskCompareOpProvider") 5844 static void maskEqualsByteMaxVectorTestsSmokeTest(IntFunction<boolean[]> fa, IntFunction<boolean[]> fb) { 5845 boolean[] a = fa.apply(SPECIES.length()); 5846 boolean[] b = fb.apply(SPECIES.length()); 5847 5848 for (int i = 0; i < a.length; i += SPECIES.length()) { 5849 var av = SPECIES.loadMask(a, i); 5850 var bv = SPECIES.loadMask(b, i); 5851 boolean equals = av.equals(bv); 5852 int to = i + SPECIES.length(); 5853 Assert.assertEquals(equals, Arrays.equals(a, i, to, b, i, to)); 5854 } 5855 } 5856 5857 static boolean beq(boolean a, boolean b) { 5858 return (a == b); 5859 } 5860 5861 @Test(dataProvider = "maskCompareOpProvider") 5862 static void maskEqByteMaxVectorTestsSmokeTest(IntFunction<boolean[]> fa, IntFunction<boolean[]> fb) { 5863 boolean[] a = fa.apply(SPECIES.length()); 5864 boolean[] b = fb.apply(SPECIES.length()); 5865 boolean[] r = new boolean[a.length]; 5866 5867 for (int i = 0; i < a.length; i += SPECIES.length()) { 5868 var av = SPECIES.loadMask(a, i); 5869 var bv = SPECIES.loadMask(b, i); 5870 var cv = av.eq(bv); 5871 cv.intoArray(r, i); 5872 } 5873 assertArraysEquals(r, a, b, ByteMaxVectorTests::beq); 5874 } 5875 5876 @Test(dataProvider = "maskProvider") 5877 static void maskHashCodeByteMaxVectorTestsSmokeTest(IntFunction<boolean[]> fa) { 5878 boolean[] a = fa.apply(SPECIES.length()); 5879 5880 for (int i = 0; i < a.length; i += SPECIES.length()) { 5881 var vmask = SPECIES.loadMask(a, i); 5882 int hash = vmask.hashCode(); 5883 5884 boolean subarr[] = Arrays.copyOfRange(a, i, i + SPECIES.length()); 5885 int expectedHash = Objects.hash(SPECIES, Arrays.hashCode(subarr)); 5886 Assert.assertTrue(hash == expectedHash, "at index " + i + ", hash should be = " + expectedHash + ", but is = " + hash); 5887 } 5888 } 5889 5890 static int maskTrueCount(boolean[] a, int idx) { 5891 int trueCount = 0; 5892 for (int i = idx; i < idx + SPECIES.length(); i++) { 5893 trueCount += a[i] ? 1 : 0; 5894 } 5895 return trueCount; 5896 } 5897 5898 @Test(dataProvider = "maskProvider") 5899 static void maskTrueCountByteMaxVectorTestsSmokeTest(IntFunction<boolean[]> fa) { 5900 boolean[] a = fa.apply(SPECIES.length()); 5901 int[] r = new int[a.length]; 5902 5903 for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { 5904 for (int i = 0; i < a.length; i += SPECIES.length()) { 5905 var vmask = SPECIES.loadMask(a, i); 5906 r[i] = vmask.trueCount(); 5907 } 5908 } 5909 5910 assertMaskReductionArraysEquals(r, a, ByteMaxVectorTests::maskTrueCount); 5911 } 5912 5913 static int maskLastTrue(boolean[] a, int idx) { 5914 int i = idx + SPECIES.length() - 1; 5915 for (; i >= idx; i--) { 5916 if (a[i]) { 5917 break; 5918 } 5919 } 5920 return i - idx; 5921 } 5922 5923 @Test(dataProvider = "maskProvider") 5924 static void maskLastTrueByteMaxVectorTestsSmokeTest(IntFunction<boolean[]> fa) { 5925 boolean[] a = fa.apply(SPECIES.length()); 5926 int[] r = new int[a.length]; 5927 5928 for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { 5929 for (int i = 0; i < a.length; i += SPECIES.length()) { 5930 var vmask = SPECIES.loadMask(a, i); 5931 r[i] = vmask.lastTrue(); 5932 } 5933 } 5934 5935 assertMaskReductionArraysEquals(r, a, ByteMaxVectorTests::maskLastTrue); 5936 } 5937 5938 static int maskFirstTrue(boolean[] a, int idx) { 5939 int i = idx; 5940 for (; i < idx + SPECIES.length(); i++) { 5941 if (a[i]) { 5942 break; 5943 } 5944 } 5945 return i - idx; 5946 } 5947 5948 @Test(dataProvider = "maskProvider") 5949 static void maskFirstTrueByteMaxVectorTestsSmokeTest(IntFunction<boolean[]> fa) { 5950 boolean[] a = fa.apply(SPECIES.length()); 5951 int[] r = new int[a.length]; 5952 5953 for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { 5954 for (int i = 0; i < a.length; i += SPECIES.length()) { 5955 var vmask = SPECIES.loadMask(a, i); 5956 r[i] = vmask.firstTrue(); 5957 } 5958 } 5959 5960 assertMaskReductionArraysEquals(r, a, ByteMaxVectorTests::maskFirstTrue); 5961 } 5962 5963 @Test(dataProvider = "maskProvider") 5964 static void maskCompressByteMaxVectorTestsSmokeTest(IntFunction<boolean[]> fa) { 5965 int trueCount = 0; 5966 boolean[] a = fa.apply(SPECIES.length()); 5967 5968 for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { 5969 for (int i = 0; i < a.length; i += SPECIES.length()) { 5970 var vmask = SPECIES.loadMask(a, i); 5971 trueCount = vmask.trueCount(); 5972 var rmask = vmask.compress(); 5973 for (int j = 0; j < SPECIES.length(); j++) { 5974 Assert.assertEquals(rmask.laneIsSet(j), j < trueCount); 5975 } 5976 } 5977 } 5978 } 5979 5980 5981 @DataProvider 5982 public static Object[][] offsetProvider() { 5983 return new Object[][]{ 5984 {0}, 5985 {-1}, 5986 {+1}, 5987 {+2}, 5988 {-2}, 5989 }; 5990 } 5991 5992 @Test(dataProvider = "offsetProvider") 5993 static void indexInRangeByteMaxVectorTestsSmokeTest(int offset) { 5994 int limit = SPECIES.length() * BUFFER_REPS; 5995 for (int i = 0; i < limit; i += SPECIES.length()) { 5996 var actualMask = SPECIES.indexInRange(i + offset, limit); 5997 var expectedMask = SPECIES.maskAll(true).indexInRange(i + offset, limit); 5998 assert(actualMask.equals(expectedMask)); 5999 for (int j = 0; j < SPECIES.length(); j++) { 6000 int index = i + j + offset; 6001 Assert.assertEquals(actualMask.laneIsSet(j), index >= 0 && index < limit); 6002 } 6003 } 6004 } 6005 6006 @Test(dataProvider = "offsetProvider") 6007 static void indexInRangeLongByteMaxVectorTestsSmokeTest(int offset) { 6008 long limit = SPECIES.length() * BUFFER_REPS; 6009 for (long i = 0; i < limit; i += SPECIES.length()) { 6010 var actualMask = SPECIES.indexInRange(i + offset, limit); 6011 var expectedMask = SPECIES.maskAll(true).indexInRange(i + offset, limit); 6012 assert(actualMask.equals(expectedMask)); 6013 for (int j = 0; j < SPECIES.length(); j++) { 6014 long index = i + j + offset; 6015 Assert.assertEquals(actualMask.laneIsSet(j), index >= 0 && index < limit); 6016 } 6017 } 6018 } 6019 6020 @DataProvider 6021 public static Object[][] lengthProvider() { 6022 return new Object[][]{ 6023 {0}, 6024 {1}, 6025 {32}, 6026 {37}, 6027 {1024}, 6028 {1024+1}, 6029 {1024+5}, 6030 }; 6031 } 6032 6033 @Test(dataProvider = "lengthProvider") 6034 static void loopBoundByteMaxVectorTestsSmokeTest(int length) { 6035 int actualLoopBound = SPECIES.loopBound(length); 6036 int expectedLoopBound = length - Math.floorMod(length, SPECIES.length()); 6037 Assert.assertEquals(actualLoopBound, expectedLoopBound); 6038 } 6039 6040 @Test(dataProvider = "lengthProvider") 6041 static void loopBoundLongByteMaxVectorTestsSmokeTest(int _length) { 6042 long length = _length; 6043 long actualLoopBound = SPECIES.loopBound(length); 6044 long expectedLoopBound = length - Math.floorMod(length, SPECIES.length()); 6045 Assert.assertEquals(actualLoopBound, expectedLoopBound); 6046 } 6047 6048 @Test 6049 static void ElementSizeByteMaxVectorTestsSmokeTest() { 6050 ByteVector av = ByteVector.zero(SPECIES); 6051 int elsize = av.elementSize(); 6052 Assert.assertEquals(elsize, Byte.SIZE); 6053 } 6054 6055 @Test 6056 static void VectorShapeByteMaxVectorTestsSmokeTest() { 6057 ByteVector av = ByteVector.zero(SPECIES); 6058 VectorShape vsh = av.shape(); 6059 assert(vsh.equals(VectorShape.S_Max_BIT)); 6060 } 6061 6062 @Test 6063 static void ShapeWithLanesByteMaxVectorTestsSmokeTest() { 6064 ByteVector av = ByteVector.zero(SPECIES); 6065 VectorShape vsh = av.shape(); 6066 VectorSpecies species = vsh.withLanes(byte.class); 6067 assert(species.equals(SPECIES)); 6068 } 6069 6070 @Test 6071 static void ElementTypeByteMaxVectorTestsSmokeTest() { 6072 ByteVector av = ByteVector.zero(SPECIES); 6073 assert(av.species().elementType() == byte.class); 6074 } 6075 6076 @Test 6077 static void SpeciesElementSizeByteMaxVectorTestsSmokeTest() { 6078 ByteVector av = ByteVector.zero(SPECIES); 6079 assert(av.species().elementSize() == Byte.SIZE); 6080 } 6081 6082 @Test 6083 static void VectorTypeByteMaxVectorTestsSmokeTest() { 6084 ByteVector av = ByteVector.zero(SPECIES); 6085 assert(av.species().vectorType() == av.getClass()); 6086 } 6087 6088 @Test 6089 static void WithLanesByteMaxVectorTestsSmokeTest() { 6090 ByteVector av = ByteVector.zero(SPECIES); 6091 VectorSpecies species = av.species().withLanes(byte.class); 6092 assert(species.equals(SPECIES)); 6093 } 6094 6095 @Test 6096 static void WithShapeByteMaxVectorTestsSmokeTest() { 6097 ByteVector av = ByteVector.zero(SPECIES); 6098 VectorShape vsh = av.shape(); 6099 VectorSpecies species = av.species().withShape(vsh); 6100 assert(species.equals(SPECIES)); 6101 } 6102 6103 @Test 6104 static void MaskAllTrueByteMaxVectorTestsSmokeTest() { 6105 for (int ic = 0; ic < INVOC_COUNT; ic++) { 6106 Assert.assertEquals(SPECIES.maskAll(true).toLong(), -1L >>> (64 - SPECIES.length())); 6107 } 6108 } 6109 }