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