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