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