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