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