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