1 /* 2 * Copyright (c) 2018, 2025, 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 * @key randomness 27 * 28 * @library /test/lib 29 * @modules jdk.incubator.vector 30 * @run testng/othervm/timeout=300 -ea -esa -Xbatch -XX:-TieredCompilation Short512VectorTests 31 */ 32 33 // -- This file was mechanically generated: Do not edit! -- // 34 35 import jdk.incubator.vector.VectorShape; 36 import jdk.incubator.vector.VectorSpecies; 37 import jdk.incubator.vector.VectorShuffle; 38 import jdk.incubator.vector.VectorMask; 39 import jdk.incubator.vector.VectorOperators; 40 import jdk.incubator.vector.Vector; 41 import jdk.incubator.vector.VectorMath; 42 43 import jdk.incubator.vector.ShortVector; 44 45 import org.testng.Assert; 46 import org.testng.annotations.DataProvider; 47 import org.testng.annotations.Test; 48 49 import java.lang.Integer; 50 import java.util.List; 51 import java.util.Arrays; 52 import java.util.function.BiFunction; 53 import java.util.function.IntFunction; 54 import java.util.Objects; 55 import java.util.stream.Collectors; 56 import java.util.stream.Stream; 57 58 @Test 59 public class Short512VectorTests extends AbstractVectorTest { 60 61 static final VectorSpecies<Short> SPECIES = 62 ShortVector.SPECIES_512; 63 64 static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100); 65 66 static ShortVector bcast_vec = ShortVector.broadcast(SPECIES, (short)10); 67 68 69 private static final short CONST_SHIFT = Short.SIZE / 2; 70 71 static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 512); 72 73 static void assertArraysStrictlyEquals(short[] r, short[] a) { 74 for (int i = 0; i < a.length; i++) { 75 if (r[i] != a[i]) { 76 Assert.fail("at index #" + i + ", expected = " + a[i] + ", actual = " + r[i]); 77 } 78 } 79 } 80 81 interface FUnOp { 82 short apply(short a); 83 } 84 85 static void assertArraysEquals(short[] r, short[] a, FUnOp f) { 86 int i = 0; 87 try { 88 for (; i < a.length; i++) { 89 Assert.assertEquals(r[i], f.apply(a[i])); 90 } 91 } catch (AssertionError e) { 92 Assert.assertEquals(r[i], f.apply(a[i]), "at index #" + i + ", input = " + a[i]); 93 } 94 } 95 96 interface FUnArrayOp { 97 short[] apply(short a); 98 } 99 100 static void assertArraysEquals(short[] r, short[] a, FUnArrayOp f) { 101 int i = 0; 102 try { 103 for (; i < a.length; i += SPECIES.length()) { 104 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()), 105 f.apply(a[i])); 106 } 107 } catch (AssertionError e) { 108 short[] ref = f.apply(a[i]); 109 short[] res = Arrays.copyOfRange(r, i, i+SPECIES.length()); 110 Assert.assertEquals(res, ref, "(ref: " + Arrays.toString(ref) 111 + ", res: " + Arrays.toString(res) 112 + "), at index #" + i); 113 } 114 } 115 116 static void assertArraysEquals(short[] r, short[] a, boolean[] mask, FUnOp f) { 117 int i = 0; 118 try { 119 for (; i < a.length; i++) { 120 Assert.assertEquals(r[i], mask[i % SPECIES.length()] ? f.apply(a[i]) : a[i]); 121 } 122 } catch (AssertionError e) { 123 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()]); 124 } 125 } 126 127 interface FReductionOp { 128 short apply(short[] a, int idx); 129 } 130 131 interface FReductionAllOp { 132 short apply(short[] a); 133 } 134 135 static void assertReductionArraysEquals(short[] r, short rc, short[] a, 136 FReductionOp f, FReductionAllOp fa) { 137 int i = 0; 138 try { 139 Assert.assertEquals(rc, fa.apply(a)); 140 for (; i < a.length; i += SPECIES.length()) { 141 Assert.assertEquals(r[i], f.apply(a, i)); 142 } 143 } catch (AssertionError e) { 144 Assert.assertEquals(rc, fa.apply(a), "Final result is incorrect!"); 145 Assert.assertEquals(r[i], f.apply(a, i), "at index #" + i); 146 } 147 } 148 149 interface FReductionMaskedOp { 150 short apply(short[] a, int idx, boolean[] mask); 151 } 152 153 interface FReductionAllMaskedOp { 154 short apply(short[] a, boolean[] mask); 155 } 156 157 static void assertReductionArraysEqualsMasked(short[] r, short rc, short[] a, boolean[] mask, 158 FReductionMaskedOp f, FReductionAllMaskedOp fa) { 159 int i = 0; 160 try { 161 Assert.assertEquals(rc, fa.apply(a, mask)); 162 for (; i < a.length; i += SPECIES.length()) { 163 Assert.assertEquals(r[i], f.apply(a, i, mask)); 164 } 165 } catch (AssertionError e) { 166 Assert.assertEquals(rc, fa.apply(a, mask), "Final result is incorrect!"); 167 Assert.assertEquals(r[i], f.apply(a, i, mask), "at index #" + i); 168 } 169 } 170 171 interface FReductionOpLong { 172 long apply(short[] a, int idx); 173 } 174 175 interface FReductionAllOpLong { 176 long apply(short[] a); 177 } 178 179 static void assertReductionLongArraysEquals(long[] r, long rc, short[] a, 180 FReductionOpLong f, FReductionAllOpLong fa) { 181 int i = 0; 182 try { 183 Assert.assertEquals(rc, fa.apply(a)); 184 for (; i < a.length; i += SPECIES.length()) { 185 Assert.assertEquals(r[i], f.apply(a, i)); 186 } 187 } catch (AssertionError e) { 188 Assert.assertEquals(rc, fa.apply(a), "Final result is incorrect!"); 189 Assert.assertEquals(r[i], f.apply(a, i), "at index #" + i); 190 } 191 } 192 193 interface FReductionMaskedOpLong { 194 long apply(short[] a, int idx, boolean[] mask); 195 } 196 197 interface FReductionAllMaskedOpLong { 198 long apply(short[] a, boolean[] mask); 199 } 200 201 static void assertReductionLongArraysEqualsMasked(long[] r, long rc, short[] a, boolean[] mask, 202 FReductionMaskedOpLong f, FReductionAllMaskedOpLong fa) { 203 int i = 0; 204 try { 205 Assert.assertEquals(rc, fa.apply(a, mask)); 206 for (; i < a.length; i += SPECIES.length()) { 207 Assert.assertEquals(r[i], f.apply(a, i, mask)); 208 } 209 } catch (AssertionError e) { 210 Assert.assertEquals(rc, fa.apply(a, mask), "Final result is incorrect!"); 211 Assert.assertEquals(r[i], f.apply(a, i, mask), "at index #" + i); 212 } 213 } 214 215 interface FBoolReductionOp { 216 boolean apply(boolean[] a, int idx); 217 } 218 219 static void assertReductionBoolArraysEquals(boolean[] r, boolean[] a, FBoolReductionOp f) { 220 int i = 0; 221 try { 222 for (; i < a.length; i += SPECIES.length()) { 223 Assert.assertEquals(r[i], f.apply(a, i)); 224 } 225 } catch (AssertionError e) { 226 Assert.assertEquals(r[i], f.apply(a, i), "at index #" + i); 227 } 228 } 229 230 interface FMaskReductionOp { 231 int apply(boolean[] a, int idx); 232 } 233 234 static void assertMaskReductionArraysEquals(int[] r, boolean[] a, FMaskReductionOp f) { 235 int i = 0; 236 try { 237 for (; i < a.length; i += SPECIES.length()) { 238 Assert.assertEquals(r[i], f.apply(a, i)); 239 } 240 } catch (AssertionError e) { 241 Assert.assertEquals(r[i], f.apply(a, i), "at index #" + i); 242 } 243 } 244 245 static void assertRearrangeArraysEquals(short[] r, short[] a, int[] order, int vector_len) { 246 int i = 0, j = 0; 247 try { 248 for (; i < a.length; i += vector_len) { 249 for (j = 0; j < vector_len; j++) { 250 Assert.assertEquals(r[i+j], a[i+order[i+j]]); 251 } 252 } 253 } catch (AssertionError e) { 254 int idx = i + j; 255 Assert.assertEquals(r[i+j], a[i+order[i+j]], "at index #" + idx + ", input = " + a[i+order[i+j]]); 256 } 257 } 258 259 static void assertcompressArraysEquals(short[] r, short[] a, boolean[] m, int vector_len) { 260 int i = 0, j = 0, k = 0; 261 try { 262 for (; i < a.length; i += vector_len) { 263 k = 0; 264 for (j = 0; j < vector_len; j++) { 265 if (m[(i + j) % SPECIES.length()]) { 266 Assert.assertEquals(r[i + k], a[i + j]); 267 k++; 268 } 269 } 270 for (; k < vector_len; k++) { 271 Assert.assertEquals(r[i + k], (short)0); 272 } 273 } 274 } catch (AssertionError e) { 275 int idx = i + k; 276 if (m[(i + j) % SPECIES.length()]) { 277 Assert.assertEquals(r[idx], a[i + j], "at index #" + idx); 278 } else { 279 Assert.assertEquals(r[idx], (short)0, "at index #" + idx); 280 } 281 } 282 } 283 284 static void assertexpandArraysEquals(short[] r, short[] a, boolean[] m, int vector_len) { 285 int i = 0, j = 0, k = 0; 286 try { 287 for (; i < a.length; i += vector_len) { 288 k = 0; 289 for (j = 0; j < vector_len; j++) { 290 if (m[(i + j) % SPECIES.length()]) { 291 Assert.assertEquals(r[i + j], a[i + k]); 292 k++; 293 } else { 294 Assert.assertEquals(r[i + j], (short)0); 295 } 296 } 297 } 298 } catch (AssertionError e) { 299 int idx = i + j; 300 if (m[idx % SPECIES.length()]) { 301 Assert.assertEquals(r[idx], a[i + k], "at index #" + idx); 302 } else { 303 Assert.assertEquals(r[idx], (short)0, "at index #" + idx); 304 } 305 } 306 } 307 308 static void assertSelectFromTwoVectorEquals(short[] r, short[] order, short[] a, short[] b, int vector_len) { 309 int i = 0, j = 0; 310 boolean is_exceptional_idx = false; 311 int idx = 0, wrapped_index = 0, oidx = 0; 312 try { 313 for (; i < a.length; i += vector_len) { 314 for (j = 0; j < vector_len; j++) { 315 idx = i + j; 316 wrapped_index = Math.floorMod((int)order[idx], 2 * vector_len); 317 is_exceptional_idx = wrapped_index >= vector_len; 318 oidx = is_exceptional_idx ? (wrapped_index - vector_len) : wrapped_index; 319 Assert.assertEquals(r[idx], (is_exceptional_idx ? b[i + oidx] : a[i + oidx])); 320 } 321 } 322 } catch (AssertionError e) { 323 Assert.assertEquals(r[idx], (is_exceptional_idx ? b[i + oidx] : a[i + oidx]), "at index #" + idx + ", order = " + order[idx] + ", a = " + a[i + oidx] + ", b = " + b[i + oidx]); 324 } 325 } 326 327 static void assertSelectFromArraysEquals(short[] r, short[] a, short[] order, int vector_len) { 328 int i = 0, j = 0; 329 try { 330 for (; i < a.length; i += vector_len) { 331 for (j = 0; j < vector_len; j++) { 332 Assert.assertEquals(r[i+j], a[i+(int)order[i+j]]); 333 } 334 } 335 } catch (AssertionError e) { 336 int idx = i + j; 337 Assert.assertEquals(r[i+j], a[i+(int)order[i+j]], "at index #" + idx + ", input = " + a[i+(int)order[i+j]]); 338 } 339 } 340 341 static void assertRearrangeArraysEquals(short[] r, short[] a, int[] order, boolean[] mask, int vector_len) { 342 int i = 0, j = 0; 343 try { 344 for (; i < a.length; i += vector_len) { 345 for (j = 0; j < vector_len; j++) { 346 if (mask[j % SPECIES.length()]) 347 Assert.assertEquals(r[i+j], a[i+order[i+j]]); 348 else 349 Assert.assertEquals(r[i+j], (short)0); 350 } 351 } 352 } catch (AssertionError e) { 353 int idx = i + j; 354 if (mask[j % SPECIES.length()]) 355 Assert.assertEquals(r[i+j], a[i+order[i+j]], "at index #" + idx + ", input = " + a[i+order[i+j]] + ", mask = " + mask[j % SPECIES.length()]); 356 else 357 Assert.assertEquals(r[i+j], (short)0, "at index #" + idx + ", input = " + a[i+order[i+j]] + ", mask = " + mask[j % SPECIES.length()]); 358 } 359 } 360 361 static void assertSelectFromArraysEquals(short[] r, short[] a, short[] order, boolean[] mask, int vector_len) { 362 int i = 0, j = 0; 363 try { 364 for (; i < a.length; i += vector_len) { 365 for (j = 0; j < vector_len; j++) { 366 if (mask[j % SPECIES.length()]) 367 Assert.assertEquals(r[i+j], a[i+(int)order[i+j]]); 368 else 369 Assert.assertEquals(r[i+j], (short)0); 370 } 371 } 372 } catch (AssertionError e) { 373 int idx = i + j; 374 if (mask[j % SPECIES.length()]) 375 Assert.assertEquals(r[i+j], a[i+(int)order[i+j]], "at index #" + idx + ", input = " + a[i+(int)order[i+j]] + ", mask = " + mask[j % SPECIES.length()]); 376 else 377 Assert.assertEquals(r[i+j], (short)0, "at index #" + idx + ", input = " + a[i+(int)order[i+j]] + ", mask = " + mask[j % SPECIES.length()]); 378 } 379 } 380 381 static void assertBroadcastArraysEquals(short[] r, short[] a) { 382 int i = 0; 383 for (; i < a.length; i += SPECIES.length()) { 384 int idx = i; 385 for (int j = idx; j < (idx + SPECIES.length()); j++) 386 a[j]=a[idx]; 387 } 388 389 try { 390 for (i = 0; i < a.length; i++) { 391 Assert.assertEquals(r[i], a[i]); 392 } 393 } catch (AssertionError e) { 394 Assert.assertEquals(r[i], a[i], "at index #" + i + ", input = " + a[i]); 395 } 396 } 397 398 interface FBinOp { 399 short apply(short a, short b); 400 } 401 402 interface FBinMaskOp { 403 short apply(short a, short b, boolean m); 404 405 static FBinMaskOp lift(FBinOp f) { 406 return (a, b, m) -> m ? f.apply(a, b) : a; 407 } 408 } 409 410 static void assertArraysEqualsAssociative(short[] rl, short[] rr, short[] a, short[] b, short[] c, FBinOp f) { 411 int i = 0; 412 try { 413 for (; i < a.length; i++) { 414 //Left associative 415 Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i]), c[i])); 416 417 //Right associative 418 Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i]))); 419 420 //Results equal sanity check 421 Assert.assertEquals(rl[i], rr[i]); 422 } 423 } catch (AssertionError e) { 424 Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i]), c[i]), "left associative test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]); 425 Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i])), "right associative test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]); 426 Assert.assertEquals(rl[i], rr[i], "Result checks not equal at index #" + i + "leftRes = " + rl[i] + ", rightRes = " + rr[i]); 427 } 428 } 429 430 static void assertArraysEqualsAssociative(short[] rl, short[] rr, short[] a, short[] b, short[] c, boolean[] mask, FBinOp f) { 431 assertArraysEqualsAssociative(rl, rr, a, b, c, mask, FBinMaskOp.lift(f)); 432 } 433 434 static void assertArraysEqualsAssociative(short[] rl, short[] rr, short[] a, short[] b, short[] c, boolean[] mask, FBinMaskOp f) { 435 int i = 0; 436 boolean mask_bit = false; 437 try { 438 for (; i < a.length; i++) { 439 mask_bit = mask[i % SPECIES.length()]; 440 //Left associative 441 Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i], mask_bit), c[i], mask_bit)); 442 443 //Right associative 444 Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i], mask_bit), mask_bit)); 445 446 //Results equal sanity check 447 Assert.assertEquals(rl[i], rr[i]); 448 } 449 } catch (AssertionError e) { 450 Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i], mask_bit), c[i], mask_bit), "left associative masked test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i] + ", mask = " + mask_bit); 451 Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i], mask_bit), mask_bit), "right associative masked test at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i] + ", mask = " + mask_bit); 452 Assert.assertEquals(rl[i], rr[i], "Result checks not equal at index #" + i + "leftRes = " + rl[i] + ", rightRes = " + rr[i]); 453 } 454 } 455 456 static void assertArraysEquals(short[] r, short[] a, short[] b, FBinOp f) { 457 int i = 0; 458 try { 459 for (; i < a.length; i++) { 460 Assert.assertEquals(r[i], f.apply(a[i], b[i])); 461 } 462 } catch (AssertionError e) { 463 Assert.assertEquals(r[i], f.apply(a[i], b[i]), "(" + a[i] + ", " + b[i] + ") at index #" + i); 464 } 465 } 466 467 static void assertArraysEquals(short[] r, short[] a, short b, FBinOp f) { 468 int i = 0; 469 try { 470 for (; i < a.length; i++) { 471 Assert.assertEquals(r[i], f.apply(a[i], b)); 472 } 473 } catch (AssertionError e) { 474 Assert.assertEquals(r[i], f.apply(a[i], b), "(" + a[i] + ", " + b + ") at index #" + i); 475 } 476 } 477 478 static void assertBroadcastArraysEquals(short[] r, short[] a, short[] b, FBinOp f) { 479 int i = 0; 480 try { 481 for (; i < a.length; i++) { 482 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()])); 483 } 484 } catch (AssertionError e) { 485 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()]), 486 "(" + a[i] + ", " + b[(i / SPECIES.length()) * SPECIES.length()] + ") at index #" + i); 487 } 488 } 489 490 static void assertBroadcastLongArraysEquals(short[] r, short[] a, short[] b, FBinOp f) { 491 int i = 0; 492 try { 493 for (; i < a.length; i++) { 494 Assert.assertEquals(r[i], f.apply(a[i], (short)((long)b[(i / SPECIES.length()) * SPECIES.length()]))); 495 } 496 } catch (AssertionError e) { 497 Assert.assertEquals(r[i], f.apply(a[i], (short)((long)b[(i / SPECIES.length()) * SPECIES.length()])), 498 "(" + a[i] + ", " + b[(i / SPECIES.length()) * SPECIES.length()] + ") at index #" + i); 499 } 500 } 501 502 static void assertArraysEquals(short[] r, short[] a, short[] b, boolean[] mask, FBinOp f) { 503 assertArraysEquals(r, a, b, mask, FBinMaskOp.lift(f)); 504 } 505 506 static void assertArraysEquals(short[] r, short[] a, short[] b, boolean[] mask, FBinMaskOp f) { 507 int i = 0; 508 try { 509 for (; i < a.length; i++) { 510 Assert.assertEquals(r[i], f.apply(a[i], b[i], mask[i % SPECIES.length()])); 511 } 512 } catch (AssertionError err) { 513 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()]); 514 } 515 } 516 517 static void assertArraysEquals(short[] r, short[] a, short b, boolean[] mask, FBinOp f) { 518 assertArraysEquals(r, a, b, mask, FBinMaskOp.lift(f)); 519 } 520 521 static void assertArraysEquals(short[] r, short[] a, short b, boolean[] mask, FBinMaskOp f) { 522 int i = 0; 523 try { 524 for (; i < a.length; i++) { 525 Assert.assertEquals(r[i], f.apply(a[i], b, mask[i % SPECIES.length()])); 526 } 527 } catch (AssertionError err) { 528 Assert.assertEquals(r[i], f.apply(a[i], b, mask[i % SPECIES.length()]), "at index #" + i + ", input1 = " + a[i] + ", input2 = " + b + ", mask = " + mask[i % SPECIES.length()]); 529 } 530 } 531 532 static void assertBroadcastArraysEquals(short[] r, short[] a, short[] b, boolean[] mask, FBinOp f) { 533 assertBroadcastArraysEquals(r, a, b, mask, FBinMaskOp.lift(f)); 534 } 535 536 static void assertBroadcastArraysEquals(short[] r, short[] a, short[] b, boolean[] mask, FBinMaskOp f) { 537 int i = 0; 538 try { 539 for (; i < a.length; i++) { 540 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], mask[i % SPECIES.length()])); 541 } 542 } catch (AssertionError err) { 543 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], 544 mask[i % SPECIES.length()]), "at index #" + i + ", input1 = " + a[i] + 545 ", input2 = " + b[(i / SPECIES.length()) * SPECIES.length()] + ", mask = " + 546 mask[i % SPECIES.length()]); 547 } 548 } 549 550 static void assertBroadcastLongArraysEquals(short[] r, short[] a, short[] b, boolean[] mask, FBinOp f) { 551 assertBroadcastLongArraysEquals(r, a, b, mask, FBinMaskOp.lift(f)); 552 } 553 554 static void assertBroadcastLongArraysEquals(short[] r, short[] a, short[] b, boolean[] mask, FBinMaskOp f) { 555 int i = 0; 556 try { 557 for (; i < a.length; i++) { 558 Assert.assertEquals(r[i], f.apply(a[i], (short)((long)b[(i / SPECIES.length()) * SPECIES.length()]), mask[i % SPECIES.length()])); 559 } 560 } catch (AssertionError err) { 561 Assert.assertEquals(r[i], f.apply(a[i], (short)((long)b[(i / SPECIES.length()) * SPECIES.length()]), 562 mask[i % SPECIES.length()]), "at index #" + i + ", input1 = " + a[i] + 563 ", input2 = " + b[(i / SPECIES.length()) * SPECIES.length()] + ", mask = " + 564 mask[i % SPECIES.length()]); 565 } 566 } 567 568 static void assertShiftArraysEquals(short[] r, short[] a, short[] b, FBinOp f) { 569 int i = 0; 570 int j = 0; 571 try { 572 for (; j < a.length; j += SPECIES.length()) { 573 for (i = 0; i < SPECIES.length(); i++) { 574 Assert.assertEquals(r[i+j], f.apply(a[i+j], b[j])); 575 } 576 } 577 } catch (AssertionError e) { 578 Assert.assertEquals(r[i+j], f.apply(a[i+j], b[j]), "at index #" + i + ", " + j); 579 } 580 } 581 582 static void assertShiftArraysEquals(short[] r, short[] a, short[] b, boolean[] mask, FBinOp f) { 583 assertShiftArraysEquals(r, a, b, mask, FBinMaskOp.lift(f)); 584 } 585 586 static void assertShiftArraysEquals(short[] r, short[] a, short[] b, boolean[] mask, FBinMaskOp f) { 587 int i = 0; 588 int j = 0; 589 try { 590 for (; j < a.length; j += SPECIES.length()) { 591 for (i = 0; i < SPECIES.length(); i++) { 592 Assert.assertEquals(r[i+j], f.apply(a[i+j], b[j], mask[i])); 593 } 594 } 595 } catch (AssertionError err) { 596 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]); 597 } 598 } 599 600 interface FBinConstOp { 601 short apply(short a); 602 } 603 604 interface FBinConstMaskOp { 605 short apply(short a, boolean m); 606 607 static FBinConstMaskOp lift(FBinConstOp f) { 608 return (a, m) -> m ? f.apply(a) : a; 609 } 610 } 611 612 static void assertShiftConstEquals(short[] r, short[] a, FBinConstOp f) { 613 int i = 0; 614 int j = 0; 615 try { 616 for (; j < a.length; j += SPECIES.length()) { 617 for (i = 0; i < SPECIES.length(); i++) { 618 Assert.assertEquals(r[i+j], f.apply(a[i+j])); 619 } 620 } 621 } catch (AssertionError e) { 622 Assert.assertEquals(r[i+j], f.apply(a[i+j]), "at index #" + i + ", " + j); 623 } 624 } 625 626 static void assertShiftConstEquals(short[] r, short[] a, boolean[] mask, FBinConstOp f) { 627 assertShiftConstEquals(r, a, mask, FBinConstMaskOp.lift(f)); 628 } 629 630 static void assertShiftConstEquals(short[] r, short[] a, boolean[] mask, FBinConstMaskOp f) { 631 int i = 0; 632 int j = 0; 633 try { 634 for (; j < a.length; j += SPECIES.length()) { 635 for (i = 0; i < SPECIES.length(); i++) { 636 Assert.assertEquals(r[i+j], f.apply(a[i+j], mask[i])); 637 } 638 } 639 } catch (AssertionError err) { 640 Assert.assertEquals(r[i+j], f.apply(a[i+j], mask[i]), "at index #" + i + ", input1 = " + a[i+j] + ", mask = " + mask[i]); 641 } 642 } 643 644 interface FTernOp { 645 short apply(short a, short b, short c); 646 } 647 648 interface FTernMaskOp { 649 short apply(short a, short b, short c, boolean m); 650 651 static FTernMaskOp lift(FTernOp f) { 652 return (a, b, c, m) -> m ? f.apply(a, b, c) : a; 653 } 654 } 655 656 static void assertArraysEquals(short[] r, short[] a, short[] b, short[] c, FTernOp f) { 657 int i = 0; 658 try { 659 for (; i < a.length; i++) { 660 Assert.assertEquals(r[i], f.apply(a[i], b[i], c[i])); 661 } 662 } catch (AssertionError e) { 663 Assert.assertEquals(r[i], f.apply(a[i], b[i], c[i]), "at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]); 664 } 665 } 666 667 static void assertArraysEquals(short[] r, short[] a, short[] b, short[] c, boolean[] mask, FTernOp f) { 668 assertArraysEquals(r, a, b, c, mask, FTernMaskOp.lift(f)); 669 } 670 671 static void assertArraysEquals(short[] r, short[] a, short[] b, short[] c, boolean[] mask, FTernMaskOp f) { 672 int i = 0; 673 try { 674 for (; i < a.length; i++) { 675 Assert.assertEquals(r[i], f.apply(a[i], b[i], c[i], mask[i % SPECIES.length()])); 676 } 677 } catch (AssertionError err) { 678 Assert.assertEquals(r[i], f.apply(a[i], b[i], c[i], mask[i % SPECIES.length()]), "at index #" + i + ", input1 = " + a[i] + ", input2 = " 679 + b[i] + ", input3 = " + c[i] + ", mask = " + mask[i % SPECIES.length()]); 680 } 681 } 682 683 static void assertBroadcastArraysEquals(short[] r, short[] a, short[] b, short[] c, FTernOp f) { 684 int i = 0; 685 try { 686 for (; i < a.length; i++) { 687 Assert.assertEquals(r[i], f.apply(a[i], b[i], c[(i / SPECIES.length()) * SPECIES.length()])); 688 } 689 } catch (AssertionError e) { 690 Assert.assertEquals(r[i], f.apply(a[i], b[i], c[(i / SPECIES.length()) * SPECIES.length()]), "at index #" + 691 i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + 692 c[(i / SPECIES.length()) * SPECIES.length()]); 693 } 694 } 695 696 static void assertAltBroadcastArraysEquals(short[] r, short[] a, short[] b, short[] c, FTernOp f) { 697 int i = 0; 698 try { 699 for (; i < a.length; i++) { 700 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], c[i])); 701 } 702 } catch (AssertionError e) { 703 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], c[i]), "at index #" + 704 i + ", input1 = " + a[i] + ", input2 = " + 705 b[(i / SPECIES.length()) * SPECIES.length()] + ", input3 = " + c[i]); 706 } 707 } 708 709 static void assertBroadcastArraysEquals(short[] r, short[] a, short[] b, short[] c, boolean[] mask, 710 FTernOp f) { 711 assertBroadcastArraysEquals(r, a, b, c, mask, FTernMaskOp.lift(f)); 712 } 713 714 static void assertBroadcastArraysEquals(short[] r, short[] a, short[] b, short[] c, boolean[] mask, 715 FTernMaskOp f) { 716 int i = 0; 717 try { 718 for (; i < a.length; i++) { 719 Assert.assertEquals(r[i], f.apply(a[i], b[i], c[(i / SPECIES.length()) * SPECIES.length()], 720 mask[i % SPECIES.length()])); 721 } 722 } catch (AssertionError err) { 723 Assert.assertEquals(r[i], f.apply(a[i], b[i], c[(i / SPECIES.length()) * SPECIES.length()], 724 mask[i % SPECIES.length()]), "at index #" + i + ", input1 = " + a[i] + ", input2 = " + 725 b[i] + ", input3 = " + c[(i / SPECIES.length()) * SPECIES.length()] + ", mask = " + 726 mask[i % SPECIES.length()]); 727 } 728 } 729 730 static void assertAltBroadcastArraysEquals(short[] r, short[] a, short[] b, short[] c, boolean[] mask, 731 FTernOp f) { 732 assertAltBroadcastArraysEquals(r, a, b, c, mask, FTernMaskOp.lift(f)); 733 } 734 735 static void assertAltBroadcastArraysEquals(short[] r, short[] a, short[] b, short[] c, boolean[] mask, 736 FTernMaskOp f) { 737 int i = 0; 738 try { 739 for (; i < a.length; i++) { 740 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], c[i], 741 mask[i % SPECIES.length()])); 742 } 743 } catch (AssertionError err) { 744 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], c[i], 745 mask[i % SPECIES.length()]), "at index #" + i + ", input1 = " + a[i] + 746 ", input2 = " + b[(i / SPECIES.length()) * SPECIES.length()] + 747 ", input3 = " + c[i] + ", mask = " + mask[i % SPECIES.length()]); 748 } 749 } 750 751 static void assertDoubleBroadcastArraysEquals(short[] r, short[] a, short[] b, short[] c, FTernOp f) { 752 int i = 0; 753 try { 754 for (; i < a.length; i++) { 755 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], 756 c[(i / SPECIES.length()) * SPECIES.length()])); 757 } 758 } catch (AssertionError e) { 759 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], 760 c[(i / SPECIES.length()) * SPECIES.length()]), "at index #" + i + ", input1 = " + a[i] 761 + ", input2 = " + b[(i / SPECIES.length()) * SPECIES.length()] + ", input3 = " + 762 c[(i / SPECIES.length()) * SPECIES.length()]); 763 } 764 } 765 766 static void assertDoubleBroadcastArraysEquals(short[] r, short[] a, short[] b, short[] c, boolean[] mask, 767 FTernOp f) { 768 assertDoubleBroadcastArraysEquals(r, a, b, c, mask, FTernMaskOp.lift(f)); 769 } 770 771 static void assertDoubleBroadcastArraysEquals(short[] r, short[] a, short[] b, short[] c, boolean[] mask, 772 FTernMaskOp f) { 773 int i = 0; 774 try { 775 for (; i < a.length; i++) { 776 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], 777 c[(i / SPECIES.length()) * SPECIES.length()], mask[i % SPECIES.length()])); 778 } 779 } catch (AssertionError err) { 780 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], 781 c[(i / SPECIES.length()) * SPECIES.length()], mask[i % SPECIES.length()]), "at index #" 782 + i + ", input1 = " + a[i] + ", input2 = " + b[(i / SPECIES.length()) * SPECIES.length()] + 783 ", input3 = " + c[(i / SPECIES.length()) * SPECIES.length()] + ", mask = " + 784 mask[i % SPECIES.length()]); 785 } 786 } 787 788 789 790 interface FGatherScatterOp { 791 short[] apply(short[] a, int ix, int[] b, int iy); 792 } 793 794 static void assertArraysEquals(short[] r, short[] a, int[] b, FGatherScatterOp f) { 795 int i = 0; 796 try { 797 for (; i < a.length; i += SPECIES.length()) { 798 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()), 799 f.apply(a, i, b, i)); 800 } 801 } catch (AssertionError e) { 802 short[] ref = f.apply(a, i, b, i); 803 short[] res = Arrays.copyOfRange(r, i, i+SPECIES.length()); 804 Assert.assertEquals(res, ref, 805 "(ref: " + Arrays.toString(ref) + ", res: " + Arrays.toString(res) + ", a: " 806 + Arrays.toString(Arrays.copyOfRange(a, i, i+SPECIES.length())) 807 + ", b: " 808 + Arrays.toString(Arrays.copyOfRange(b, i, i+SPECIES.length())) 809 + " at index #" + i); 810 } 811 } 812 813 interface FGatherMaskedOp { 814 short[] apply(short[] a, int ix, boolean[] mask, int[] b, int iy); 815 } 816 817 interface FScatterMaskedOp { 818 short[] apply(short[] r, short[] a, int ix, boolean[] mask, int[] b, int iy); 819 } 820 821 static void assertArraysEquals(short[] r, short[] a, int[] b, boolean[] mask, FGatherMaskedOp f) { 822 int i = 0; 823 try { 824 for (; i < a.length; i += SPECIES.length()) { 825 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()), 826 f.apply(a, i, mask, b, i)); 827 } 828 } catch (AssertionError e) { 829 short[] ref = f.apply(a, i, mask, b, i); 830 short[] res = Arrays.copyOfRange(r, i, i+SPECIES.length()); 831 Assert.assertEquals(res, ref, 832 "(ref: " + Arrays.toString(ref) + ", res: " + Arrays.toString(res) + ", a: " 833 + Arrays.toString(Arrays.copyOfRange(a, i, i+SPECIES.length())) 834 + ", b: " 835 + Arrays.toString(Arrays.copyOfRange(b, i, i+SPECIES.length())) 836 + ", mask: " 837 + Arrays.toString(mask) 838 + " at index #" + i); 839 } 840 } 841 842 static void assertArraysEquals(short[] r, short[] a, int[] b, boolean[] mask, FScatterMaskedOp f) { 843 int i = 0; 844 try { 845 for (; i < a.length; i += SPECIES.length()) { 846 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()), 847 f.apply(r, a, i, mask, b, i)); 848 } 849 } catch (AssertionError e) { 850 short[] ref = f.apply(r, a, i, mask, b, i); 851 short[] res = Arrays.copyOfRange(r, i, i+SPECIES.length()); 852 Assert.assertEquals(res, ref, 853 "(ref: " + Arrays.toString(ref) + ", res: " + Arrays.toString(res) + ", a: " 854 + Arrays.toString(Arrays.copyOfRange(a, i, i+SPECIES.length())) 855 + ", b: " 856 + Arrays.toString(Arrays.copyOfRange(b, i, i+SPECIES.length())) 857 + ", r: " 858 + Arrays.toString(Arrays.copyOfRange(r, i, i+SPECIES.length())) 859 + ", mask: " 860 + Arrays.toString(mask) 861 + " at index #" + i); 862 } 863 } 864 865 interface FLaneOp { 866 short[] apply(short[] a, int origin, int idx); 867 } 868 869 static void assertArraysEquals(short[] r, short[] a, int origin, FLaneOp f) { 870 int i = 0; 871 try { 872 for (; i < a.length; i += SPECIES.length()) { 873 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()), 874 f.apply(a, origin, i)); 875 } 876 } catch (AssertionError e) { 877 short[] ref = f.apply(a, origin, i); 878 short[] res = Arrays.copyOfRange(r, i, i+SPECIES.length()); 879 Assert.assertEquals(res, ref, "(ref: " + Arrays.toString(ref) 880 + ", res: " + Arrays.toString(res) 881 + "), at index #" + i); 882 } 883 } 884 885 interface FLaneBop { 886 short[] apply(short[] a, short[] b, int origin, int idx); 887 } 888 889 static void assertArraysEquals(short[] r, short[] a, short[] b, int origin, FLaneBop f) { 890 int i = 0; 891 try { 892 for (; i < a.length; i += SPECIES.length()) { 893 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()), 894 f.apply(a, b, origin, i)); 895 } 896 } catch (AssertionError e) { 897 short[] ref = f.apply(a, b, origin, i); 898 short[] res = Arrays.copyOfRange(r, i, i+SPECIES.length()); 899 Assert.assertEquals(res, ref, "(ref: " + Arrays.toString(ref) 900 + ", res: " + Arrays.toString(res) 901 + "), at index #" + i 902 + ", at origin #" + origin); 903 } 904 } 905 906 interface FLaneMaskedBop { 907 short[] apply(short[] a, short[] b, int origin, boolean[] mask, int idx); 908 } 909 910 static void assertArraysEquals(short[] r, short[] a, short[] b, int origin, boolean[] mask, FLaneMaskedBop f) { 911 int i = 0; 912 try { 913 for (; i < a.length; i += SPECIES.length()) { 914 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()), 915 f.apply(a, b, origin, mask, i)); 916 } 917 } catch (AssertionError e) { 918 short[] ref = f.apply(a, b, origin, mask, i); 919 short[] res = Arrays.copyOfRange(r, i, i+SPECIES.length()); 920 Assert.assertEquals(res, ref, "(ref: " + Arrays.toString(ref) 921 + ", res: " + Arrays.toString(res) 922 + "), at index #" + i 923 + ", at origin #" + origin); 924 } 925 } 926 927 interface FLanePartBop { 928 short[] apply(short[] a, short[] b, int origin, int part, int idx); 929 } 930 931 static void assertArraysEquals(short[] r, short[] a, short[] b, int origin, int part, FLanePartBop f) { 932 int i = 0; 933 try { 934 for (; i < a.length; i += SPECIES.length()) { 935 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()), 936 f.apply(a, b, origin, part, i)); 937 } 938 } catch (AssertionError e) { 939 short[] ref = f.apply(a, b, origin, part, i); 940 short[] res = Arrays.copyOfRange(r, i, i+SPECIES.length()); 941 Assert.assertEquals(res, ref, "(ref: " + Arrays.toString(ref) 942 + ", res: " + Arrays.toString(res) 943 + "), at index #" + i 944 + ", at origin #" + origin 945 + ", with part #" + part); 946 } 947 } 948 949 interface FLanePartMaskedBop { 950 short[] apply(short[] a, short[] b, int origin, int part, boolean[] mask, int idx); 951 } 952 953 static void assertArraysEquals(short[] r, short[] a, short[] b, int origin, int part, boolean[] mask, FLanePartMaskedBop f) { 954 int i = 0; 955 try { 956 for (; i < a.length; i += SPECIES.length()) { 957 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()), 958 f.apply(a, b, origin, part, mask, i)); 959 } 960 } catch (AssertionError e) { 961 short[] ref = f.apply(a, b, origin, part, mask, i); 962 short[] res = Arrays.copyOfRange(r, i, i+SPECIES.length()); 963 Assert.assertEquals(res, ref, "(ref: " + Arrays.toString(ref) 964 + ", res: " + Arrays.toString(res) 965 + "), at index #" + i 966 + ", at origin #" + origin 967 + ", with part #" + part); 968 } 969 } 970 971 972 static void assertArraysEquals(int[] r, short[] a, int offs) { 973 int i = 0; 974 try { 975 for (; i < r.length; i++) { 976 Assert.assertEquals(r[i], (int)(a[i+offs])); 977 } 978 } catch (AssertionError e) { 979 Assert.assertEquals(r[i], (int)(a[i+offs]), "at index #" + i + ", input = " + a[i+offs]); 980 } 981 } 982 983 984 985 static void assertArraysEquals(long[] r, short[] a, int offs) { 986 int i = 0; 987 try { 988 for (; i < r.length; i++) { 989 Assert.assertEquals(r[i], (long)(a[i+offs])); 990 } 991 } catch (AssertionError e) { 992 Assert.assertEquals(r[i], (long)(a[i+offs]), "at index #" + i + ", input = " + a[i+offs]); 993 } 994 } 995 996 static void assertArraysEquals(double[] r, short[] a, int offs) { 997 int i = 0; 998 try { 999 for (; i < r.length; i++) { 1000 Assert.assertEquals(r[i], (double)(a[i+offs])); 1001 } 1002 } catch (AssertionError e) { 1003 Assert.assertEquals(r[i], (double)(a[i+offs]), "at index #" + i + ", input = " + a[i+offs]); 1004 } 1005 } 1006 1007 static short bits(short e) { 1008 return e; 1009 } 1010 1011 static final List<IntFunction<short[]>> SHORT_GENERATORS = List.of( 1012 withToString("short[-i * 5]", (int s) -> { 1013 return fill(s * BUFFER_REPS, 1014 i -> (short)(-i * 5)); 1015 }), 1016 withToString("short[i * 5]", (int s) -> { 1017 return fill(s * BUFFER_REPS, 1018 i -> (short)(i * 5)); 1019 }), 1020 withToString("short[i + 1]", (int s) -> { 1021 return fill(s * BUFFER_REPS, 1022 i -> (((short)(i + 1) == 0) ? 1 : (short)(i + 1))); 1023 }), 1024 withToString("short[cornerCaseValue(i)]", (int s) -> { 1025 return fill(s * BUFFER_REPS, 1026 i -> cornerCaseValue(i)); 1027 }) 1028 ); 1029 1030 static final List<IntFunction<short[]>> SHORT_SATURATING_GENERATORS = List.of( 1031 withToString("short[Short.MIN_VALUE]", (int s) -> { 1032 return fill(s * BUFFER_REPS, 1033 i -> (short)(Short.MIN_VALUE)); 1034 }), 1035 withToString("short[Short.MAX_VALUE]", (int s) -> { 1036 return fill(s * BUFFER_REPS, 1037 i -> (short)(Short.MAX_VALUE)); 1038 }), 1039 withToString("short[Short.MAX_VALUE - 100]", (int s) -> { 1040 return fill(s * BUFFER_REPS, 1041 i -> (short)(Short.MAX_VALUE - 100)); 1042 }), 1043 withToString("short[Short.MIN_VALUE + 100]", (int s) -> { 1044 return fill(s * BUFFER_REPS, 1045 i -> (short)(Short.MIN_VALUE + 100)); 1046 }), 1047 withToString("short[-i * 5]", (int s) -> { 1048 return fill(s * BUFFER_REPS, 1049 i -> (short)(-i * 5)); 1050 }), 1051 withToString("short[i * 5]", (int s) -> { 1052 return fill(s * BUFFER_REPS, 1053 i -> (short)(i * 5)); 1054 }) 1055 ); 1056 1057 static final List<IntFunction<short[]>> SHORT_SATURATING_GENERATORS_ASSOC = List.of( 1058 withToString("short[Short.MAX_VALUE]", (int s) -> { 1059 return fill(s * BUFFER_REPS, 1060 i -> (short)(Short.MAX_VALUE)); 1061 }), 1062 withToString("short[Short.MAX_VALUE - 100]", (int s) -> { 1063 return fill(s * BUFFER_REPS, 1064 i -> (short)(Short.MAX_VALUE - 100)); 1065 }), 1066 withToString("short[-1]", (int s) -> { 1067 return fill(s * BUFFER_REPS, 1068 i -> (short)(-1)); 1069 }) 1070 ); 1071 1072 // Create combinations of pairs 1073 // @@@ Might be sensitive to order e.g. div by 0 1074 static final List<List<IntFunction<short[]>>> SHORT_GENERATOR_PAIRS = 1075 Stream.of(SHORT_GENERATORS.get(0)). 1076 flatMap(fa -> SHORT_GENERATORS.stream().skip(1).map(fb -> List.of(fa, fb))). 1077 collect(Collectors.toList()); 1078 1079 static final List<List<IntFunction<short[]>>> SHORT_SATURATING_GENERATOR_PAIRS = 1080 Stream.of(SHORT_GENERATORS.get(0)). 1081 flatMap(fa -> SHORT_SATURATING_GENERATORS.stream().skip(1).map(fb -> List.of(fa, fb))). 1082 collect(Collectors.toList()); 1083 1084 static final List<List<IntFunction<short[]>>> SHORT_SATURATING_GENERATOR_TRIPLETS = 1085 Stream.of(SHORT_GENERATORS.get(1)) 1086 .flatMap(fa -> SHORT_SATURATING_GENERATORS_ASSOC.stream().map(fb -> List.of(fa, fb))) 1087 .flatMap(pair -> SHORT_SATURATING_GENERATORS_ASSOC.stream().map(f -> List.of(pair.get(0), pair.get(1), f))) 1088 .collect(Collectors.toList()); 1089 1090 @DataProvider 1091 public Object[][] boolUnaryOpProvider() { 1092 return BOOL_ARRAY_GENERATORS.stream(). 1093 map(f -> new Object[]{f}). 1094 toArray(Object[][]::new); 1095 } 1096 1097 static final List<List<IntFunction<short[]>>> SHORT_GENERATOR_TRIPLES = 1098 SHORT_GENERATOR_PAIRS.stream(). 1099 flatMap(pair -> SHORT_GENERATORS.stream().map(f -> List.of(pair.get(0), pair.get(1), f))). 1100 collect(Collectors.toList()); 1101 1102 static final List<IntFunction<short[]>> SELECT_FROM_INDEX_GENERATORS = List.of( 1103 withToString("short[0..VECLEN*2)", (int s) -> { 1104 return fill(s * BUFFER_REPS, 1105 i -> (short)(RAND.nextInt())); 1106 }) 1107 ); 1108 1109 static final List<List<IntFunction<short[]>>> SHORT_GENERATOR_SELECT_FROM_TRIPLES = 1110 SHORT_GENERATOR_PAIRS.stream(). 1111 flatMap(pair -> SELECT_FROM_INDEX_GENERATORS.stream().map(f -> List.of(pair.get(0), pair.get(1), f))). 1112 collect(Collectors.toList()); 1113 1114 @DataProvider 1115 public Object[][] shortBinaryOpProvider() { 1116 return SHORT_GENERATOR_PAIRS.stream().map(List::toArray). 1117 toArray(Object[][]::new); 1118 } 1119 1120 @DataProvider 1121 public Object[][] shortSaturatingBinaryOpProvider() { 1122 return SHORT_SATURATING_GENERATOR_PAIRS.stream().map(List::toArray). 1123 toArray(Object[][]::new); 1124 } 1125 1126 @DataProvider 1127 public Object[][] shortSaturatingBinaryOpAssocProvider() { 1128 return SHORT_SATURATING_GENERATOR_TRIPLETS.stream().map(List::toArray). 1129 toArray(Object[][]::new); 1130 } 1131 1132 @DataProvider 1133 public Object[][] shortSaturatingBinaryOpAssocMaskProvider() { 1134 return BOOLEAN_MASK_GENERATORS.stream(). 1135 flatMap(fm -> SHORT_SATURATING_GENERATOR_TRIPLETS.stream().map(lfa -> { 1136 return Stream.concat(lfa.stream(), Stream.of(fm)).toArray(); 1137 })). 1138 toArray(Object[][]::new); 1139 } 1140 1141 1142 @DataProvider 1143 public Object[][] shortIndexedOpProvider() { 1144 return SHORT_GENERATOR_PAIRS.stream().map(List::toArray). 1145 toArray(Object[][]::new); 1146 } 1147 1148 @DataProvider 1149 public Object[][] shortSaturatingBinaryOpMaskProvider() { 1150 return BOOLEAN_MASK_GENERATORS.stream(). 1151 flatMap(fm -> SHORT_SATURATING_GENERATOR_PAIRS.stream().map(lfa -> { 1152 return Stream.concat(lfa.stream(), Stream.of(fm)).toArray(); 1153 })). 1154 toArray(Object[][]::new); 1155 } 1156 1157 @DataProvider 1158 public Object[][] shortSaturatingUnaryOpProvider() { 1159 return SHORT_SATURATING_GENERATORS.stream(). 1160 map(f -> new Object[]{f}). 1161 toArray(Object[][]::new); 1162 } 1163 1164 @DataProvider 1165 public Object[][] shortSaturatingUnaryOpMaskProvider() { 1166 return BOOLEAN_MASK_GENERATORS.stream(). 1167 flatMap(fm -> SHORT_SATURATING_GENERATORS.stream().map(fa -> { 1168 return new Object[] {fa, fm}; 1169 })). 1170 toArray(Object[][]::new); 1171 } 1172 1173 @DataProvider 1174 public Object[][] shortBinaryOpMaskProvider() { 1175 return BOOLEAN_MASK_GENERATORS.stream(). 1176 flatMap(fm -> SHORT_GENERATOR_PAIRS.stream().map(lfa -> { 1177 return Stream.concat(lfa.stream(), Stream.of(fm)).toArray(); 1178 })). 1179 toArray(Object[][]::new); 1180 } 1181 1182 @DataProvider 1183 public Object[][] shortTernaryOpProvider() { 1184 return SHORT_GENERATOR_TRIPLES.stream().map(List::toArray). 1185 toArray(Object[][]::new); 1186 } 1187 1188 @DataProvider 1189 public Object[][] shortSelectFromTwoVectorOpProvider() { 1190 return SHORT_GENERATOR_SELECT_FROM_TRIPLES.stream().map(List::toArray). 1191 toArray(Object[][]::new); 1192 } 1193 1194 @DataProvider 1195 public Object[][] shortTernaryOpMaskProvider() { 1196 return BOOLEAN_MASK_GENERATORS.stream(). 1197 flatMap(fm -> SHORT_GENERATOR_TRIPLES.stream().map(lfa -> { 1198 return Stream.concat(lfa.stream(), Stream.of(fm)).toArray(); 1199 })). 1200 toArray(Object[][]::new); 1201 } 1202 1203 @DataProvider 1204 public Object[][] shortUnaryOpProvider() { 1205 return SHORT_GENERATORS.stream(). 1206 map(f -> new Object[]{f}). 1207 toArray(Object[][]::new); 1208 } 1209 1210 @DataProvider 1211 public Object[][] shortUnaryOpMaskProvider() { 1212 return BOOLEAN_MASK_GENERATORS.stream(). 1213 flatMap(fm -> SHORT_GENERATORS.stream().map(fa -> { 1214 return new Object[] {fa, fm}; 1215 })). 1216 toArray(Object[][]::new); 1217 } 1218 1219 @DataProvider 1220 public Object[][] maskProvider() { 1221 return BOOLEAN_MASK_GENERATORS.stream(). 1222 map(f -> new Object[]{f}). 1223 toArray(Object[][]::new); 1224 } 1225 1226 @DataProvider 1227 public Object[][] maskCompareOpProvider() { 1228 return BOOLEAN_MASK_COMPARE_GENERATOR_PAIRS.stream().map(List::toArray). 1229 toArray(Object[][]::new); 1230 } 1231 1232 @DataProvider 1233 public Object[][] shuffleProvider() { 1234 return INT_SHUFFLE_GENERATORS.stream(). 1235 map(f -> new Object[]{f}). 1236 toArray(Object[][]::new); 1237 } 1238 1239 @DataProvider 1240 public Object[][] shuffleCompareOpProvider() { 1241 return INT_SHUFFLE_COMPARE_GENERATOR_PAIRS.stream().map(List::toArray). 1242 toArray(Object[][]::new); 1243 } 1244 1245 @DataProvider 1246 public Object[][] shortUnaryOpShuffleProvider() { 1247 return INT_SHUFFLE_GENERATORS.stream(). 1248 flatMap(fs -> SHORT_GENERATORS.stream().map(fa -> { 1249 return new Object[] {fa, fs}; 1250 })). 1251 toArray(Object[][]::new); 1252 } 1253 1254 @DataProvider 1255 public Object[][] shortUnaryOpShuffleMaskProvider() { 1256 return BOOLEAN_MASK_GENERATORS.stream(). 1257 flatMap(fm -> INT_SHUFFLE_GENERATORS.stream(). 1258 flatMap(fs -> SHORT_GENERATORS.stream().map(fa -> { 1259 return new Object[] {fa, fs, fm}; 1260 }))). 1261 toArray(Object[][]::new); 1262 } 1263 1264 static final List<BiFunction<Integer,Integer,short[]>> SHORT_SHUFFLE_GENERATORS = List.of( 1265 withToStringBi("shuffle[random]", (Integer l, Integer m) -> { 1266 short[] a = new short[l]; 1267 int upper = m; 1268 for (int i = 0; i < 1; i++) { 1269 a[i] = (short)RAND.nextInt(upper); 1270 } 1271 return a; 1272 }) 1273 ); 1274 1275 @DataProvider 1276 public Object[][] shortUnaryOpSelectFromProvider() { 1277 return SHORT_SHUFFLE_GENERATORS.stream(). 1278 flatMap(fs -> SHORT_GENERATORS.stream().map(fa -> { 1279 return new Object[] {fa, fs}; 1280 })). 1281 toArray(Object[][]::new); 1282 } 1283 1284 @DataProvider 1285 public Object[][] shortUnaryOpSelectFromMaskProvider() { 1286 return BOOLEAN_MASK_GENERATORS.stream(). 1287 flatMap(fm -> SHORT_SHUFFLE_GENERATORS.stream(). 1288 flatMap(fs -> SHORT_GENERATORS.stream().map(fa -> { 1289 return new Object[] {fa, fs, fm}; 1290 }))). 1291 toArray(Object[][]::new); 1292 } 1293 1294 static final List<IntFunction<short[]>> SHORT_COMPARE_GENERATORS = List.of( 1295 withToString("short[i]", (int s) -> { 1296 return fill(s * BUFFER_REPS, 1297 i -> (short)i); 1298 }), 1299 withToString("short[i - length / 2]", (int s) -> { 1300 return fill(s * BUFFER_REPS, 1301 i -> (short)(i - (s * BUFFER_REPS / 2))); 1302 }), 1303 withToString("short[i + 1]", (int s) -> { 1304 return fill(s * BUFFER_REPS, 1305 i -> (short)(i + 1)); 1306 }), 1307 withToString("short[i - 2]", (int s) -> { 1308 return fill(s * BUFFER_REPS, 1309 i -> (short)(i - 2)); 1310 }), 1311 withToString("short[zigZag(i)]", (int s) -> { 1312 return fill(s * BUFFER_REPS, 1313 i -> i%3 == 0 ? (short)i : (i%3 == 1 ? (short)(i + 1) : (short)(i - 2))); 1314 }), 1315 withToString("short[cornerCaseValue(i)]", (int s) -> { 1316 return fill(s * BUFFER_REPS, 1317 i -> cornerCaseValue(i)); 1318 }) 1319 ); 1320 1321 static final List<List<IntFunction<short[]>>> SHORT_TEST_GENERATOR_ARGS = 1322 SHORT_COMPARE_GENERATORS.stream(). 1323 map(fa -> List.of(fa)). 1324 collect(Collectors.toList()); 1325 1326 @DataProvider 1327 public Object[][] shortTestOpProvider() { 1328 return SHORT_TEST_GENERATOR_ARGS.stream().map(List::toArray). 1329 toArray(Object[][]::new); 1330 } 1331 1332 @DataProvider 1333 public Object[][] shortTestOpMaskProvider() { 1334 return BOOLEAN_MASK_GENERATORS.stream(). 1335 flatMap(fm -> SHORT_TEST_GENERATOR_ARGS.stream().map(lfa -> { 1336 return Stream.concat(lfa.stream(), Stream.of(fm)).toArray(); 1337 })). 1338 toArray(Object[][]::new); 1339 } 1340 1341 static final List<List<IntFunction<short[]>>> SHORT_COMPARE_GENERATOR_PAIRS = 1342 SHORT_COMPARE_GENERATORS.stream(). 1343 flatMap(fa -> SHORT_COMPARE_GENERATORS.stream().map(fb -> List.of(fa, fb))). 1344 collect(Collectors.toList()); 1345 1346 @DataProvider 1347 public Object[][] shortCompareOpProvider() { 1348 return SHORT_COMPARE_GENERATOR_PAIRS.stream().map(List::toArray). 1349 toArray(Object[][]::new); 1350 } 1351 1352 @DataProvider 1353 public Object[][] shortCompareOpMaskProvider() { 1354 return BOOLEAN_MASK_GENERATORS.stream(). 1355 flatMap(fm -> SHORT_COMPARE_GENERATOR_PAIRS.stream().map(lfa -> { 1356 return Stream.concat(lfa.stream(), Stream.of(fm)).toArray(); 1357 })). 1358 toArray(Object[][]::new); 1359 } 1360 1361 interface ToShortF { 1362 short apply(int i); 1363 } 1364 1365 static short[] fill(int s , ToShortF f) { 1366 return fill(new short[s], f); 1367 } 1368 1369 static short[] fill(short[] a, ToShortF f) { 1370 for (int i = 0; i < a.length; i++) { 1371 a[i] = f.apply(i); 1372 } 1373 return a; 1374 } 1375 1376 static short cornerCaseValue(int i) { 1377 switch(i % 5) { 1378 case 0: 1379 return Short.MAX_VALUE; 1380 case 1: 1381 return Short.MIN_VALUE; 1382 case 2: 1383 return Short.MIN_VALUE; 1384 case 3: 1385 return Short.MAX_VALUE; 1386 default: 1387 return (short)0; 1388 } 1389 } 1390 1391 static final IntFunction<short[]> fr = (vl) -> { 1392 int length = BUFFER_REPS * vl; 1393 return new short[length]; 1394 }; 1395 1396 static final IntFunction<boolean[]> fmr = (vl) -> { 1397 int length = BUFFER_REPS * vl; 1398 return new boolean[length]; 1399 }; 1400 1401 static final IntFunction<long[]> lfr = (vl) -> { 1402 int length = BUFFER_REPS * vl; 1403 return new long[length]; 1404 }; 1405 1406 static void replaceZero(short[] a, short v) { 1407 for (int i = 0; i < a.length; i++) { 1408 if (a[i] == 0) { 1409 a[i] = v; 1410 } 1411 } 1412 } 1413 1414 static void replaceZero(short[] a, boolean[] mask, short v) { 1415 for (int i = 0; i < a.length; i++) { 1416 if (mask[i % mask.length] && a[i] == 0) { 1417 a[i] = v; 1418 } 1419 } 1420 } 1421 1422 static short ROL_scalar(short a, short b) { 1423 return (short)(((((short)a) & 0xFFFF) << (b & 15)) | ((((short)a) & 0xFFFF) >>> (16 - (b & 15)))); 1424 } 1425 1426 static short ROR_scalar(short a, short b) { 1427 return (short)(((((short)a) & 0xFFFF) >>> (b & 15)) | ((((short)a) & 0xFFFF) << (16 - (b & 15)))); 1428 } 1429 1430 static short TRAILING_ZEROS_COUNT_scalar(short a) { 1431 return (short) (a != 0 ? Integer.numberOfTrailingZeros(a) : 16); 1432 } 1433 1434 static short LEADING_ZEROS_COUNT_scalar(short a) { 1435 return (short) (a >= 0 ? Integer.numberOfLeadingZeros(a) - 16 : 0); 1436 } 1437 1438 static short REVERSE_scalar(short a) { 1439 short b = ROL_scalar(a, (short) 8); 1440 b = (short) (((b & 0x5555) << 1) | ((b & 0xAAAA) >>> 1)); 1441 b = (short) (((b & 0x3333) << 2) | ((b & 0xCCCC) >>> 2)); 1442 b = (short) (((b & 0x0F0F) << 4) | ((b & 0xF0F0) >>> 4)); 1443 return b; 1444 } 1445 1446 static boolean eq(short a, short b) { 1447 return a == b; 1448 } 1449 1450 static boolean neq(short a, short b) { 1451 return a != b; 1452 } 1453 1454 static boolean lt(short a, short b) { 1455 return a < b; 1456 } 1457 1458 static boolean le(short a, short b) { 1459 return a <= b; 1460 } 1461 1462 static boolean gt(short a, short b) { 1463 return a > b; 1464 } 1465 1466 static boolean ge(short a, short b) { 1467 return a >= b; 1468 } 1469 1470 static boolean ult(short a, short b) { 1471 return Short.compareUnsigned(a, b) < 0; 1472 } 1473 1474 static boolean ule(short a, short b) { 1475 return Short.compareUnsigned(a, b) <= 0; 1476 } 1477 1478 static boolean ugt(short a, short b) { 1479 return Short.compareUnsigned(a, b) > 0; 1480 } 1481 1482 static boolean uge(short a, short b) { 1483 return Short.compareUnsigned(a, b) >= 0; 1484 } 1485 1486 static short firstNonZero(short a, short b) { 1487 return Short.compare(a, (short) 0) != 0 ? a : b; 1488 } 1489 1490 @Test 1491 static void smokeTest1() { 1492 ShortVector three = ShortVector.broadcast(SPECIES, (byte)-3); 1493 ShortVector three2 = (ShortVector) SPECIES.broadcast(-3); 1494 assert(three.eq(three2).allTrue()); 1495 ShortVector three3 = three2.broadcast(1).broadcast(-3); 1496 assert(three.eq(three3).allTrue()); 1497 int scale = 2; 1498 Class<?> ETYPE = short.class; 1499 if (ETYPE == double.class || ETYPE == long.class) 1500 scale = 1000000; 1501 else if (ETYPE == byte.class && SPECIES.length() >= 64) 1502 scale = 1; 1503 ShortVector higher = three.addIndex(scale); 1504 VectorMask<Short> m = three.compare(VectorOperators.LE, higher); 1505 assert(m.allTrue()); 1506 m = higher.min((short)-1).test(VectorOperators.IS_NEGATIVE); 1507 assert(m.allTrue()); 1508 short max = higher.reduceLanes(VectorOperators.MAX); 1509 assert(max == -3 + scale * (SPECIES.length()-1)); 1510 } 1511 1512 private static short[] 1513 bothToArray(ShortVector a, ShortVector b) { 1514 short[] r = new short[a.length() + b.length()]; 1515 a.intoArray(r, 0); 1516 b.intoArray(r, a.length()); 1517 return r; 1518 } 1519 1520 @Test 1521 static void smokeTest2() { 1522 // Do some zipping and shuffling. 1523 ShortVector io = (ShortVector) SPECIES.broadcast(0).addIndex(1); 1524 ShortVector io2 = (ShortVector) VectorShuffle.iota(SPECIES,0,1,false).toVector(); 1525 Assert.assertEquals(io, io2); 1526 ShortVector a = io.add((short)1); //[1,2] 1527 ShortVector b = a.neg(); //[-1,-2] 1528 short[] abValues = bothToArray(a,b); //[1,2,-1,-2] 1529 VectorShuffle<Short> zip0 = VectorShuffle.makeZip(SPECIES, 0); 1530 VectorShuffle<Short> zip1 = VectorShuffle.makeZip(SPECIES, 1); 1531 ShortVector zab0 = a.rearrange(zip0,b); //[1,-1] 1532 ShortVector zab1 = a.rearrange(zip1,b); //[2,-2] 1533 short[] zabValues = bothToArray(zab0, zab1); //[1,-1,2,-2] 1534 // manually zip 1535 short[] manual = new short[zabValues.length]; 1536 for (int i = 0; i < manual.length; i += 2) { 1537 manual[i+0] = abValues[i/2]; 1538 manual[i+1] = abValues[a.length() + i/2]; 1539 } 1540 Assert.assertEquals(Arrays.toString(zabValues), Arrays.toString(manual)); 1541 VectorShuffle<Short> unz0 = VectorShuffle.makeUnzip(SPECIES, 0); 1542 VectorShuffle<Short> unz1 = VectorShuffle.makeUnzip(SPECIES, 1); 1543 ShortVector uab0 = zab0.rearrange(unz0,zab1); 1544 ShortVector uab1 = zab0.rearrange(unz1,zab1); 1545 short[] abValues1 = bothToArray(uab0, uab1); 1546 Assert.assertEquals(Arrays.toString(abValues), Arrays.toString(abValues1)); 1547 } 1548 1549 static void iotaShuffle() { 1550 ShortVector io = (ShortVector) SPECIES.broadcast(0).addIndex(1); 1551 ShortVector io2 = (ShortVector) VectorShuffle.iota(SPECIES, 0 , 1, false).toVector(); 1552 Assert.assertEquals(io, io2); 1553 } 1554 1555 @Test 1556 // Test all shuffle related operations. 1557 static void shuffleTest() { 1558 // To test backend instructions, make sure that C2 is used. 1559 for (int loop = 0; loop < INVOC_COUNT * INVOC_COUNT; loop++) { 1560 iotaShuffle(); 1561 } 1562 } 1563 1564 @Test 1565 void viewAsIntegeralLanesTest() { 1566 Vector<?> asIntegral = SPECIES.zero().viewAsIntegralLanes(); 1567 Assert.assertEquals(asIntegral.species(), SPECIES); 1568 } 1569 1570 @Test(expectedExceptions = UnsupportedOperationException.class) 1571 void viewAsFloatingLanesTest() { 1572 SPECIES.zero().viewAsFloatingLanes(); 1573 } 1574 1575 @Test 1576 // Test div by 0. 1577 static void bitwiseDivByZeroSmokeTest() { 1578 try { 1579 ShortVector a = (ShortVector) SPECIES.broadcast(0).addIndex(1); 1580 ShortVector b = (ShortVector) SPECIES.broadcast(0); 1581 a.div(b); 1582 Assert.fail(); 1583 } catch (ArithmeticException e) { 1584 } 1585 1586 try { 1587 ShortVector a = (ShortVector) SPECIES.broadcast(0).addIndex(1); 1588 ShortVector b = (ShortVector) SPECIES.broadcast(0); 1589 VectorMask<Short> m = a.lt((short) 1); 1590 a.div(b, m); 1591 Assert.fail(); 1592 } catch (ArithmeticException e) { 1593 } 1594 } 1595 1596 static short ADD(short a, short b) { 1597 return (short)(a + b); 1598 } 1599 1600 @Test(dataProvider = "shortBinaryOpProvider") 1601 static void ADDShort512VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { 1602 short[] a = fa.apply(SPECIES.length()); 1603 short[] b = fb.apply(SPECIES.length()); 1604 short[] r = fr.apply(SPECIES.length()); 1605 1606 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1607 for (int i = 0; i < a.length; i += SPECIES.length()) { 1608 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1609 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 1610 av.lanewise(VectorOperators.ADD, bv).intoArray(r, i); 1611 } 1612 } 1613 1614 assertArraysEquals(r, a, b, Short512VectorTests::ADD); 1615 } 1616 1617 static short add(short a, short b) { 1618 return (short)(a + b); 1619 } 1620 1621 @Test(dataProvider = "shortBinaryOpProvider") 1622 static void addShort512VectorTests(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 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 1630 av.add(bv).intoArray(r, i); 1631 } 1632 1633 assertArraysEquals(r, a, b, Short512VectorTests::add); 1634 } 1635 1636 @Test(dataProvider = "shortBinaryOpMaskProvider") 1637 static void ADDShort512VectorTestsMasked(IntFunction<short[]> fa, IntFunction<short[]> fb, 1638 IntFunction<boolean[]> fm) { 1639 short[] a = fa.apply(SPECIES.length()); 1640 short[] b = fb.apply(SPECIES.length()); 1641 short[] r = fr.apply(SPECIES.length()); 1642 boolean[] mask = fm.apply(SPECIES.length()); 1643 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1644 1645 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1646 for (int i = 0; i < a.length; i += SPECIES.length()) { 1647 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1648 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 1649 av.lanewise(VectorOperators.ADD, bv, vmask).intoArray(r, i); 1650 } 1651 } 1652 1653 assertArraysEquals(r, a, b, mask, Short512VectorTests::ADD); 1654 } 1655 1656 @Test(dataProvider = "shortBinaryOpMaskProvider") 1657 static void addShort512VectorTestsMasked(IntFunction<short[]> fa, IntFunction<short[]> fb, 1658 IntFunction<boolean[]> fm) { 1659 short[] a = fa.apply(SPECIES.length()); 1660 short[] b = fb.apply(SPECIES.length()); 1661 short[] r = fr.apply(SPECIES.length()); 1662 boolean[] mask = fm.apply(SPECIES.length()); 1663 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1664 1665 for (int i = 0; i < a.length; i += SPECIES.length()) { 1666 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1667 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 1668 av.add(bv, vmask).intoArray(r, i); 1669 } 1670 1671 assertArraysEquals(r, a, b, mask, Short512VectorTests::add); 1672 } 1673 1674 static short SUB(short a, short b) { 1675 return (short)(a - b); 1676 } 1677 1678 @Test(dataProvider = "shortBinaryOpProvider") 1679 static void SUBShort512VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { 1680 short[] a = fa.apply(SPECIES.length()); 1681 short[] b = fb.apply(SPECIES.length()); 1682 short[] r = fr.apply(SPECIES.length()); 1683 1684 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1685 for (int i = 0; i < a.length; i += SPECIES.length()) { 1686 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1687 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 1688 av.lanewise(VectorOperators.SUB, bv).intoArray(r, i); 1689 } 1690 } 1691 1692 assertArraysEquals(r, a, b, Short512VectorTests::SUB); 1693 } 1694 1695 static short sub(short a, short b) { 1696 return (short)(a - b); 1697 } 1698 1699 @Test(dataProvider = "shortBinaryOpProvider") 1700 static void subShort512VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { 1701 short[] a = fa.apply(SPECIES.length()); 1702 short[] b = fb.apply(SPECIES.length()); 1703 short[] r = fr.apply(SPECIES.length()); 1704 1705 for (int i = 0; i < a.length; i += SPECIES.length()) { 1706 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1707 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 1708 av.sub(bv).intoArray(r, i); 1709 } 1710 1711 assertArraysEquals(r, a, b, Short512VectorTests::sub); 1712 } 1713 1714 @Test(dataProvider = "shortBinaryOpMaskProvider") 1715 static void SUBShort512VectorTestsMasked(IntFunction<short[]> fa, IntFunction<short[]> fb, 1716 IntFunction<boolean[]> fm) { 1717 short[] a = fa.apply(SPECIES.length()); 1718 short[] b = fb.apply(SPECIES.length()); 1719 short[] r = fr.apply(SPECIES.length()); 1720 boolean[] mask = fm.apply(SPECIES.length()); 1721 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1722 1723 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1724 for (int i = 0; i < a.length; i += SPECIES.length()) { 1725 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1726 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 1727 av.lanewise(VectorOperators.SUB, bv, vmask).intoArray(r, i); 1728 } 1729 } 1730 1731 assertArraysEquals(r, a, b, mask, Short512VectorTests::SUB); 1732 } 1733 1734 @Test(dataProvider = "shortBinaryOpMaskProvider") 1735 static void subShort512VectorTestsMasked(IntFunction<short[]> fa, IntFunction<short[]> fb, 1736 IntFunction<boolean[]> fm) { 1737 short[] a = fa.apply(SPECIES.length()); 1738 short[] b = fb.apply(SPECIES.length()); 1739 short[] r = fr.apply(SPECIES.length()); 1740 boolean[] mask = fm.apply(SPECIES.length()); 1741 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1742 1743 for (int i = 0; i < a.length; i += SPECIES.length()) { 1744 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1745 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 1746 av.sub(bv, vmask).intoArray(r, i); 1747 } 1748 1749 assertArraysEquals(r, a, b, mask, Short512VectorTests::sub); 1750 } 1751 1752 static short MUL(short a, short b) { 1753 return (short)(a * b); 1754 } 1755 1756 @Test(dataProvider = "shortBinaryOpProvider") 1757 static void MULShort512VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { 1758 short[] a = fa.apply(SPECIES.length()); 1759 short[] b = fb.apply(SPECIES.length()); 1760 short[] r = fr.apply(SPECIES.length()); 1761 1762 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1763 for (int i = 0; i < a.length; i += SPECIES.length()) { 1764 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1765 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 1766 av.lanewise(VectorOperators.MUL, bv).intoArray(r, i); 1767 } 1768 } 1769 1770 assertArraysEquals(r, a, b, Short512VectorTests::MUL); 1771 } 1772 1773 static short mul(short a, short b) { 1774 return (short)(a * b); 1775 } 1776 1777 @Test(dataProvider = "shortBinaryOpProvider") 1778 static void mulShort512VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { 1779 short[] a = fa.apply(SPECIES.length()); 1780 short[] b = fb.apply(SPECIES.length()); 1781 short[] r = fr.apply(SPECIES.length()); 1782 1783 for (int i = 0; i < a.length; i += SPECIES.length()) { 1784 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1785 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 1786 av.mul(bv).intoArray(r, i); 1787 } 1788 1789 assertArraysEquals(r, a, b, Short512VectorTests::mul); 1790 } 1791 1792 @Test(dataProvider = "shortBinaryOpMaskProvider") 1793 static void MULShort512VectorTestsMasked(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.MUL, bv, vmask).intoArray(r, i); 1806 } 1807 } 1808 1809 assertArraysEquals(r, a, b, mask, Short512VectorTests::MUL); 1810 } 1811 1812 @Test(dataProvider = "shortBinaryOpMaskProvider") 1813 static void mulShort512VectorTestsMasked(IntFunction<short[]> fa, IntFunction<short[]> fb, 1814 IntFunction<boolean[]> fm) { 1815 short[] a = fa.apply(SPECIES.length()); 1816 short[] b = fb.apply(SPECIES.length()); 1817 short[] r = fr.apply(SPECIES.length()); 1818 boolean[] mask = fm.apply(SPECIES.length()); 1819 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1820 1821 for (int i = 0; i < a.length; i += SPECIES.length()) { 1822 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1823 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 1824 av.mul(bv, vmask).intoArray(r, i); 1825 } 1826 1827 assertArraysEquals(r, a, b, mask, Short512VectorTests::mul); 1828 } 1829 1830 static short DIV(short a, short b) { 1831 return (short)(a / b); 1832 } 1833 1834 @Test(dataProvider = "shortBinaryOpProvider") 1835 static void DIVShort512VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { 1836 short[] a = fa.apply(SPECIES.length()); 1837 short[] b = fb.apply(SPECIES.length()); 1838 short[] r = fr.apply(SPECIES.length()); 1839 1840 replaceZero(b, (short) 1); 1841 1842 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1843 for (int i = 0; i < a.length; i += SPECIES.length()) { 1844 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1845 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 1846 av.lanewise(VectorOperators.DIV, bv).intoArray(r, i); 1847 } 1848 } 1849 1850 assertArraysEquals(r, a, b, Short512VectorTests::DIV); 1851 } 1852 1853 static short div(short a, short b) { 1854 return (short)(a / b); 1855 } 1856 1857 @Test(dataProvider = "shortBinaryOpProvider") 1858 static void divShort512VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { 1859 short[] a = fa.apply(SPECIES.length()); 1860 short[] b = fb.apply(SPECIES.length()); 1861 short[] r = fr.apply(SPECIES.length()); 1862 1863 replaceZero(b, (short) 1); 1864 1865 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1866 for (int i = 0; i < a.length; i += SPECIES.length()) { 1867 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1868 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 1869 av.div(bv).intoArray(r, i); 1870 } 1871 } 1872 1873 assertArraysEquals(r, a, b, Short512VectorTests::div); 1874 } 1875 1876 @Test(dataProvider = "shortBinaryOpMaskProvider") 1877 static void DIVShort512VectorTestsMasked(IntFunction<short[]> fa, IntFunction<short[]> fb, 1878 IntFunction<boolean[]> fm) { 1879 short[] a = fa.apply(SPECIES.length()); 1880 short[] b = fb.apply(SPECIES.length()); 1881 short[] r = fr.apply(SPECIES.length()); 1882 boolean[] mask = fm.apply(SPECIES.length()); 1883 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1884 1885 replaceZero(b, mask, (short) 1); 1886 1887 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1888 for (int i = 0; i < a.length; i += SPECIES.length()) { 1889 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1890 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 1891 av.lanewise(VectorOperators.DIV, bv, vmask).intoArray(r, i); 1892 } 1893 } 1894 1895 assertArraysEquals(r, a, b, mask, Short512VectorTests::DIV); 1896 } 1897 1898 @Test(dataProvider = "shortBinaryOpMaskProvider") 1899 static void divShort512VectorTestsMasked(IntFunction<short[]> fa, IntFunction<short[]> fb, 1900 IntFunction<boolean[]> fm) { 1901 short[] a = fa.apply(SPECIES.length()); 1902 short[] b = fb.apply(SPECIES.length()); 1903 short[] r = fr.apply(SPECIES.length()); 1904 boolean[] mask = fm.apply(SPECIES.length()); 1905 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1906 1907 replaceZero(b, mask, (short) 1); 1908 1909 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1910 for (int i = 0; i < a.length; i += SPECIES.length()) { 1911 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1912 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 1913 av.div(bv, vmask).intoArray(r, i); 1914 } 1915 } 1916 1917 assertArraysEquals(r, a, b, mask, Short512VectorTests::div); 1918 } 1919 1920 static short FIRST_NONZERO(short a, short b) { 1921 return (short)((a)!=0?a:b); 1922 } 1923 1924 @Test(dataProvider = "shortBinaryOpProvider") 1925 static void FIRST_NONZEROShort512VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { 1926 short[] a = fa.apply(SPECIES.length()); 1927 short[] b = fb.apply(SPECIES.length()); 1928 short[] r = fr.apply(SPECIES.length()); 1929 1930 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1931 for (int i = 0; i < a.length; i += SPECIES.length()) { 1932 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1933 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 1934 av.lanewise(VectorOperators.FIRST_NONZERO, bv).intoArray(r, i); 1935 } 1936 } 1937 1938 assertArraysEquals(r, a, b, Short512VectorTests::FIRST_NONZERO); 1939 } 1940 1941 @Test(dataProvider = "shortBinaryOpMaskProvider") 1942 static void FIRST_NONZEROShort512VectorTestsMasked(IntFunction<short[]> fa, IntFunction<short[]> fb, 1943 IntFunction<boolean[]> fm) { 1944 short[] a = fa.apply(SPECIES.length()); 1945 short[] b = fb.apply(SPECIES.length()); 1946 short[] r = fr.apply(SPECIES.length()); 1947 boolean[] mask = fm.apply(SPECIES.length()); 1948 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1949 1950 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1951 for (int i = 0; i < a.length; i += SPECIES.length()) { 1952 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1953 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 1954 av.lanewise(VectorOperators.FIRST_NONZERO, bv, vmask).intoArray(r, i); 1955 } 1956 } 1957 1958 assertArraysEquals(r, a, b, mask, Short512VectorTests::FIRST_NONZERO); 1959 } 1960 1961 static short AND(short a, short b) { 1962 return (short)(a & b); 1963 } 1964 1965 @Test(dataProvider = "shortBinaryOpProvider") 1966 static void ANDShort512VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { 1967 short[] a = fa.apply(SPECIES.length()); 1968 short[] b = fb.apply(SPECIES.length()); 1969 short[] r = fr.apply(SPECIES.length()); 1970 1971 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1972 for (int i = 0; i < a.length; i += SPECIES.length()) { 1973 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1974 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 1975 av.lanewise(VectorOperators.AND, bv).intoArray(r, i); 1976 } 1977 } 1978 1979 assertArraysEquals(r, a, b, Short512VectorTests::AND); 1980 } 1981 1982 static short and(short a, short b) { 1983 return (short)(a & b); 1984 } 1985 1986 @Test(dataProvider = "shortBinaryOpProvider") 1987 static void andShort512VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { 1988 short[] a = fa.apply(SPECIES.length()); 1989 short[] b = fb.apply(SPECIES.length()); 1990 short[] r = fr.apply(SPECIES.length()); 1991 1992 for (int i = 0; i < a.length; i += SPECIES.length()) { 1993 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 1994 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 1995 av.and(bv).intoArray(r, i); 1996 } 1997 1998 assertArraysEquals(r, a, b, Short512VectorTests::and); 1999 } 2000 2001 @Test(dataProvider = "shortBinaryOpMaskProvider") 2002 static void ANDShort512VectorTestsMasked(IntFunction<short[]> fa, IntFunction<short[]> fb, 2003 IntFunction<boolean[]> fm) { 2004 short[] a = fa.apply(SPECIES.length()); 2005 short[] b = fb.apply(SPECIES.length()); 2006 short[] r = fr.apply(SPECIES.length()); 2007 boolean[] mask = fm.apply(SPECIES.length()); 2008 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2009 2010 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2011 for (int i = 0; i < a.length; i += SPECIES.length()) { 2012 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 2013 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 2014 av.lanewise(VectorOperators.AND, bv, vmask).intoArray(r, i); 2015 } 2016 } 2017 2018 assertArraysEquals(r, a, b, mask, Short512VectorTests::AND); 2019 } 2020 2021 static short AND_NOT(short a, short b) { 2022 return (short)(a & ~b); 2023 } 2024 2025 @Test(dataProvider = "shortBinaryOpProvider") 2026 static void AND_NOTShort512VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { 2027 short[] a = fa.apply(SPECIES.length()); 2028 short[] b = fb.apply(SPECIES.length()); 2029 short[] r = fr.apply(SPECIES.length()); 2030 2031 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2032 for (int i = 0; i < a.length; i += SPECIES.length()) { 2033 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 2034 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 2035 av.lanewise(VectorOperators.AND_NOT, bv).intoArray(r, i); 2036 } 2037 } 2038 2039 assertArraysEquals(r, a, b, Short512VectorTests::AND_NOT); 2040 } 2041 2042 @Test(dataProvider = "shortBinaryOpMaskProvider") 2043 static void AND_NOTShort512VectorTestsMasked(IntFunction<short[]> fa, IntFunction<short[]> fb, 2044 IntFunction<boolean[]> fm) { 2045 short[] a = fa.apply(SPECIES.length()); 2046 short[] b = fb.apply(SPECIES.length()); 2047 short[] r = fr.apply(SPECIES.length()); 2048 boolean[] mask = fm.apply(SPECIES.length()); 2049 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2050 2051 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2052 for (int i = 0; i < a.length; i += SPECIES.length()) { 2053 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 2054 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 2055 av.lanewise(VectorOperators.AND_NOT, bv, vmask).intoArray(r, i); 2056 } 2057 } 2058 2059 assertArraysEquals(r, a, b, mask, Short512VectorTests::AND_NOT); 2060 } 2061 2062 static short OR(short a, short b) { 2063 return (short)(a | b); 2064 } 2065 2066 @Test(dataProvider = "shortBinaryOpProvider") 2067 static void ORShort512VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { 2068 short[] a = fa.apply(SPECIES.length()); 2069 short[] b = fb.apply(SPECIES.length()); 2070 short[] r = fr.apply(SPECIES.length()); 2071 2072 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2073 for (int i = 0; i < a.length; i += SPECIES.length()) { 2074 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 2075 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 2076 av.lanewise(VectorOperators.OR, bv).intoArray(r, i); 2077 } 2078 } 2079 2080 assertArraysEquals(r, a, b, Short512VectorTests::OR); 2081 } 2082 2083 static short or(short a, short b) { 2084 return (short)(a | b); 2085 } 2086 2087 @Test(dataProvider = "shortBinaryOpProvider") 2088 static void orShort512VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { 2089 short[] a = fa.apply(SPECIES.length()); 2090 short[] b = fb.apply(SPECIES.length()); 2091 short[] r = fr.apply(SPECIES.length()); 2092 2093 for (int i = 0; i < a.length; i += SPECIES.length()) { 2094 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 2095 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 2096 av.or(bv).intoArray(r, i); 2097 } 2098 2099 assertArraysEquals(r, a, b, Short512VectorTests::or); 2100 } 2101 2102 @Test(dataProvider = "shortBinaryOpMaskProvider") 2103 static void ORShort512VectorTestsMasked(IntFunction<short[]> fa, IntFunction<short[]> fb, 2104 IntFunction<boolean[]> fm) { 2105 short[] a = fa.apply(SPECIES.length()); 2106 short[] b = fb.apply(SPECIES.length()); 2107 short[] r = fr.apply(SPECIES.length()); 2108 boolean[] mask = fm.apply(SPECIES.length()); 2109 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2110 2111 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2112 for (int i = 0; i < a.length; i += SPECIES.length()) { 2113 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 2114 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 2115 av.lanewise(VectorOperators.OR, bv, vmask).intoArray(r, i); 2116 } 2117 } 2118 2119 assertArraysEquals(r, a, b, mask, Short512VectorTests::OR); 2120 } 2121 2122 static short XOR(short a, short b) { 2123 return (short)(a ^ b); 2124 } 2125 2126 @Test(dataProvider = "shortBinaryOpProvider") 2127 static void XORShort512VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { 2128 short[] a = fa.apply(SPECIES.length()); 2129 short[] b = fb.apply(SPECIES.length()); 2130 short[] r = fr.apply(SPECIES.length()); 2131 2132 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2133 for (int i = 0; i < a.length; i += SPECIES.length()) { 2134 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 2135 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 2136 av.lanewise(VectorOperators.XOR, bv).intoArray(r, i); 2137 } 2138 } 2139 2140 assertArraysEquals(r, a, b, Short512VectorTests::XOR); 2141 } 2142 2143 @Test(dataProvider = "shortBinaryOpMaskProvider") 2144 static void XORShort512VectorTestsMasked(IntFunction<short[]> fa, IntFunction<short[]> fb, 2145 IntFunction<boolean[]> fm) { 2146 short[] a = fa.apply(SPECIES.length()); 2147 short[] b = fb.apply(SPECIES.length()); 2148 short[] r = fr.apply(SPECIES.length()); 2149 boolean[] mask = fm.apply(SPECIES.length()); 2150 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2151 2152 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2153 for (int i = 0; i < a.length; i += SPECIES.length()) { 2154 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 2155 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 2156 av.lanewise(VectorOperators.XOR, bv, vmask).intoArray(r, i); 2157 } 2158 } 2159 2160 assertArraysEquals(r, a, b, mask, Short512VectorTests::XOR); 2161 } 2162 2163 @Test(dataProvider = "shortBinaryOpProvider") 2164 static void addShort512VectorTestsBroadcastSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb) { 2165 short[] a = fa.apply(SPECIES.length()); 2166 short[] b = fb.apply(SPECIES.length()); 2167 short[] r = fr.apply(SPECIES.length()); 2168 2169 for (int i = 0; i < a.length; i += SPECIES.length()) { 2170 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 2171 av.add(b[i]).intoArray(r, i); 2172 } 2173 2174 assertBroadcastArraysEquals(r, a, b, Short512VectorTests::add); 2175 } 2176 2177 @Test(dataProvider = "shortBinaryOpMaskProvider") 2178 static void addShort512VectorTestsBroadcastMaskedSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb, 2179 IntFunction<boolean[]> fm) { 2180 short[] a = fa.apply(SPECIES.length()); 2181 short[] b = fb.apply(SPECIES.length()); 2182 short[] r = fr.apply(SPECIES.length()); 2183 boolean[] mask = fm.apply(SPECIES.length()); 2184 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2185 2186 for (int i = 0; i < a.length; i += SPECIES.length()) { 2187 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 2188 av.add(b[i], vmask).intoArray(r, i); 2189 } 2190 2191 assertBroadcastArraysEquals(r, a, b, mask, Short512VectorTests::add); 2192 } 2193 2194 @Test(dataProvider = "shortBinaryOpProvider") 2195 static void subShort512VectorTestsBroadcastSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb) { 2196 short[] a = fa.apply(SPECIES.length()); 2197 short[] b = fb.apply(SPECIES.length()); 2198 short[] r = fr.apply(SPECIES.length()); 2199 2200 for (int i = 0; i < a.length; i += SPECIES.length()) { 2201 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 2202 av.sub(b[i]).intoArray(r, i); 2203 } 2204 2205 assertBroadcastArraysEquals(r, a, b, Short512VectorTests::sub); 2206 } 2207 2208 @Test(dataProvider = "shortBinaryOpMaskProvider") 2209 static void subShort512VectorTestsBroadcastMaskedSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb, 2210 IntFunction<boolean[]> fm) { 2211 short[] a = fa.apply(SPECIES.length()); 2212 short[] b = fb.apply(SPECIES.length()); 2213 short[] r = fr.apply(SPECIES.length()); 2214 boolean[] mask = fm.apply(SPECIES.length()); 2215 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2216 2217 for (int i = 0; i < a.length; i += SPECIES.length()) { 2218 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 2219 av.sub(b[i], vmask).intoArray(r, i); 2220 } 2221 2222 assertBroadcastArraysEquals(r, a, b, mask, Short512VectorTests::sub); 2223 } 2224 2225 @Test(dataProvider = "shortBinaryOpProvider") 2226 static void mulShort512VectorTestsBroadcastSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb) { 2227 short[] a = fa.apply(SPECIES.length()); 2228 short[] b = fb.apply(SPECIES.length()); 2229 short[] r = fr.apply(SPECIES.length()); 2230 2231 for (int i = 0; i < a.length; i += SPECIES.length()) { 2232 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 2233 av.mul(b[i]).intoArray(r, i); 2234 } 2235 2236 assertBroadcastArraysEquals(r, a, b, Short512VectorTests::mul); 2237 } 2238 2239 @Test(dataProvider = "shortBinaryOpMaskProvider") 2240 static void mulShort512VectorTestsBroadcastMaskedSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb, 2241 IntFunction<boolean[]> fm) { 2242 short[] a = fa.apply(SPECIES.length()); 2243 short[] b = fb.apply(SPECIES.length()); 2244 short[] r = fr.apply(SPECIES.length()); 2245 boolean[] mask = fm.apply(SPECIES.length()); 2246 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2247 2248 for (int i = 0; i < a.length; i += SPECIES.length()) { 2249 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 2250 av.mul(b[i], vmask).intoArray(r, i); 2251 } 2252 2253 assertBroadcastArraysEquals(r, a, b, mask, Short512VectorTests::mul); 2254 } 2255 2256 @Test(dataProvider = "shortBinaryOpProvider") 2257 static void divShort512VectorTestsBroadcastSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb) { 2258 short[] a = fa.apply(SPECIES.length()); 2259 short[] b = fb.apply(SPECIES.length()); 2260 short[] r = fr.apply(SPECIES.length()); 2261 2262 replaceZero(b, (short) 1); 2263 2264 for (int i = 0; i < a.length; i += SPECIES.length()) { 2265 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 2266 av.div(b[i]).intoArray(r, i); 2267 } 2268 2269 assertBroadcastArraysEquals(r, a, b, Short512VectorTests::div); 2270 } 2271 2272 @Test(dataProvider = "shortBinaryOpMaskProvider") 2273 static void divShort512VectorTestsBroadcastMaskedSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb, 2274 IntFunction<boolean[]> fm) { 2275 short[] a = fa.apply(SPECIES.length()); 2276 short[] b = fb.apply(SPECIES.length()); 2277 short[] r = fr.apply(SPECIES.length()); 2278 boolean[] mask = fm.apply(SPECIES.length()); 2279 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2280 2281 replaceZero(b, (short) 1); 2282 2283 for (int i = 0; i < a.length; i += SPECIES.length()) { 2284 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 2285 av.div(b[i], vmask).intoArray(r, i); 2286 } 2287 2288 assertBroadcastArraysEquals(r, a, b, mask, Short512VectorTests::div); 2289 } 2290 2291 @Test(dataProvider = "shortBinaryOpProvider") 2292 static void ORShort512VectorTestsBroadcastSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb) { 2293 short[] a = fa.apply(SPECIES.length()); 2294 short[] b = fb.apply(SPECIES.length()); 2295 short[] r = fr.apply(SPECIES.length()); 2296 2297 for (int i = 0; i < a.length; i += SPECIES.length()) { 2298 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 2299 av.lanewise(VectorOperators.OR, b[i]).intoArray(r, i); 2300 } 2301 2302 assertBroadcastArraysEquals(r, a, b, Short512VectorTests::OR); 2303 } 2304 2305 @Test(dataProvider = "shortBinaryOpProvider") 2306 static void orShort512VectorTestsBroadcastSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb) { 2307 short[] a = fa.apply(SPECIES.length()); 2308 short[] b = fb.apply(SPECIES.length()); 2309 short[] r = fr.apply(SPECIES.length()); 2310 2311 for (int i = 0; i < a.length; i += SPECIES.length()) { 2312 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 2313 av.or(b[i]).intoArray(r, i); 2314 } 2315 2316 assertBroadcastArraysEquals(r, a, b, Short512VectorTests::or); 2317 } 2318 2319 @Test(dataProvider = "shortBinaryOpMaskProvider") 2320 static void ORShort512VectorTestsBroadcastMaskedSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb, 2321 IntFunction<boolean[]> fm) { 2322 short[] a = fa.apply(SPECIES.length()); 2323 short[] b = fb.apply(SPECIES.length()); 2324 short[] r = fr.apply(SPECIES.length()); 2325 boolean[] mask = fm.apply(SPECIES.length()); 2326 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2327 2328 for (int i = 0; i < a.length; i += SPECIES.length()) { 2329 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 2330 av.lanewise(VectorOperators.OR, b[i], vmask).intoArray(r, i); 2331 } 2332 2333 assertBroadcastArraysEquals(r, a, b, mask, Short512VectorTests::OR); 2334 } 2335 2336 @Test(dataProvider = "shortBinaryOpProvider") 2337 static void ANDShort512VectorTestsBroadcastSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb) { 2338 short[] a = fa.apply(SPECIES.length()); 2339 short[] b = fb.apply(SPECIES.length()); 2340 short[] r = fr.apply(SPECIES.length()); 2341 2342 for (int i = 0; i < a.length; i += SPECIES.length()) { 2343 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 2344 av.lanewise(VectorOperators.AND, b[i]).intoArray(r, i); 2345 } 2346 2347 assertBroadcastArraysEquals(r, a, b, Short512VectorTests::AND); 2348 } 2349 2350 @Test(dataProvider = "shortBinaryOpProvider") 2351 static void andShort512VectorTestsBroadcastSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb) { 2352 short[] a = fa.apply(SPECIES.length()); 2353 short[] b = fb.apply(SPECIES.length()); 2354 short[] r = fr.apply(SPECIES.length()); 2355 2356 for (int i = 0; i < a.length; i += SPECIES.length()) { 2357 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 2358 av.and(b[i]).intoArray(r, i); 2359 } 2360 2361 assertBroadcastArraysEquals(r, a, b, Short512VectorTests::and); 2362 } 2363 2364 @Test(dataProvider = "shortBinaryOpMaskProvider") 2365 static void ANDShort512VectorTestsBroadcastMaskedSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb, 2366 IntFunction<boolean[]> fm) { 2367 short[] a = fa.apply(SPECIES.length()); 2368 short[] b = fb.apply(SPECIES.length()); 2369 short[] r = fr.apply(SPECIES.length()); 2370 boolean[] mask = fm.apply(SPECIES.length()); 2371 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2372 2373 for (int i = 0; i < a.length; i += SPECIES.length()) { 2374 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 2375 av.lanewise(VectorOperators.AND, b[i], vmask).intoArray(r, i); 2376 } 2377 2378 assertBroadcastArraysEquals(r, a, b, mask, Short512VectorTests::AND); 2379 } 2380 2381 @Test(dataProvider = "shortBinaryOpProvider") 2382 static void ORShort512VectorTestsBroadcastLongSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb) { 2383 short[] a = fa.apply(SPECIES.length()); 2384 short[] b = fb.apply(SPECIES.length()); 2385 short[] r = fr.apply(SPECIES.length()); 2386 2387 for (int i = 0; i < a.length; i += SPECIES.length()) { 2388 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 2389 av.lanewise(VectorOperators.OR, (long)b[i]).intoArray(r, i); 2390 } 2391 2392 assertBroadcastLongArraysEquals(r, a, b, Short512VectorTests::OR); 2393 } 2394 2395 @Test(dataProvider = "shortBinaryOpMaskProvider") 2396 static void ORShort512VectorTestsBroadcastMaskedLongSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb, 2397 IntFunction<boolean[]> fm) { 2398 short[] a = fa.apply(SPECIES.length()); 2399 short[] b = fb.apply(SPECIES.length()); 2400 short[] r = fr.apply(SPECIES.length()); 2401 boolean[] mask = fm.apply(SPECIES.length()); 2402 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2403 2404 for (int i = 0; i < a.length; i += SPECIES.length()) { 2405 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 2406 av.lanewise(VectorOperators.OR, (long)b[i], vmask).intoArray(r, i); 2407 } 2408 2409 assertBroadcastLongArraysEquals(r, a, b, mask, Short512VectorTests::OR); 2410 } 2411 2412 @Test(dataProvider = "shortBinaryOpProvider") 2413 static void ADDShort512VectorTestsBroadcastLongSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb) { 2414 short[] a = fa.apply(SPECIES.length()); 2415 short[] b = fb.apply(SPECIES.length()); 2416 short[] r = fr.apply(SPECIES.length()); 2417 2418 for (int i = 0; i < a.length; i += SPECIES.length()) { 2419 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 2420 av.lanewise(VectorOperators.ADD, (long)b[i]).intoArray(r, i); 2421 } 2422 2423 assertBroadcastLongArraysEquals(r, a, b, Short512VectorTests::ADD); 2424 } 2425 2426 @Test(dataProvider = "shortBinaryOpMaskProvider") 2427 static void ADDShort512VectorTestsBroadcastMaskedLongSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb, 2428 IntFunction<boolean[]> fm) { 2429 short[] a = fa.apply(SPECIES.length()); 2430 short[] b = fb.apply(SPECIES.length()); 2431 short[] r = fr.apply(SPECIES.length()); 2432 boolean[] mask = fm.apply(SPECIES.length()); 2433 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2434 2435 for (int i = 0; i < a.length; i += SPECIES.length()) { 2436 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 2437 av.lanewise(VectorOperators.ADD, (long)b[i], vmask).intoArray(r, i); 2438 } 2439 2440 assertBroadcastLongArraysEquals(r, a, b, mask, Short512VectorTests::ADD); 2441 } 2442 2443 static short LSHL(short a, short b) { 2444 return (short)((a << (b & 0xF))); 2445 } 2446 2447 @Test(dataProvider = "shortBinaryOpProvider") 2448 static void LSHLShort512VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { 2449 short[] a = fa.apply(SPECIES.length()); 2450 short[] b = fb.apply(SPECIES.length()); 2451 short[] r = fr.apply(SPECIES.length()); 2452 2453 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2454 for (int i = 0; i < a.length; i += SPECIES.length()) { 2455 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 2456 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 2457 av.lanewise(VectorOperators.LSHL, bv).intoArray(r, i); 2458 } 2459 } 2460 2461 assertArraysEquals(r, a, b, Short512VectorTests::LSHL); 2462 } 2463 2464 @Test(dataProvider = "shortBinaryOpMaskProvider") 2465 static void LSHLShort512VectorTestsMasked(IntFunction<short[]> fa, IntFunction<short[]> fb, 2466 IntFunction<boolean[]> fm) { 2467 short[] a = fa.apply(SPECIES.length()); 2468 short[] b = fb.apply(SPECIES.length()); 2469 short[] r = fr.apply(SPECIES.length()); 2470 boolean[] mask = fm.apply(SPECIES.length()); 2471 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2472 2473 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2474 for (int i = 0; i < a.length; i += SPECIES.length()) { 2475 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 2476 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 2477 av.lanewise(VectorOperators.LSHL, bv, vmask).intoArray(r, i); 2478 } 2479 } 2480 2481 assertArraysEquals(r, a, b, mask, Short512VectorTests::LSHL); 2482 } 2483 2484 static short ASHR(short a, short b) { 2485 return (short)((a >> (b & 0xF))); 2486 } 2487 2488 @Test(dataProvider = "shortBinaryOpProvider") 2489 static void ASHRShort512VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { 2490 short[] a = fa.apply(SPECIES.length()); 2491 short[] b = fb.apply(SPECIES.length()); 2492 short[] r = fr.apply(SPECIES.length()); 2493 2494 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2495 for (int i = 0; i < a.length; i += SPECIES.length()) { 2496 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 2497 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 2498 av.lanewise(VectorOperators.ASHR, bv).intoArray(r, i); 2499 } 2500 } 2501 2502 assertArraysEquals(r, a, b, Short512VectorTests::ASHR); 2503 } 2504 2505 @Test(dataProvider = "shortBinaryOpMaskProvider") 2506 static void ASHRShort512VectorTestsMasked(IntFunction<short[]> fa, IntFunction<short[]> fb, 2507 IntFunction<boolean[]> fm) { 2508 short[] a = fa.apply(SPECIES.length()); 2509 short[] b = fb.apply(SPECIES.length()); 2510 short[] r = fr.apply(SPECIES.length()); 2511 boolean[] mask = fm.apply(SPECIES.length()); 2512 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2513 2514 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2515 for (int i = 0; i < a.length; i += SPECIES.length()) { 2516 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 2517 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 2518 av.lanewise(VectorOperators.ASHR, bv, vmask).intoArray(r, i); 2519 } 2520 } 2521 2522 assertArraysEquals(r, a, b, mask, Short512VectorTests::ASHR); 2523 } 2524 2525 static short LSHR(short a, short b) { 2526 return (short)(((a & 0xFFFF) >>> (b & 0xF))); 2527 } 2528 2529 @Test(dataProvider = "shortBinaryOpProvider") 2530 static void LSHRShort512VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { 2531 short[] a = fa.apply(SPECIES.length()); 2532 short[] b = fb.apply(SPECIES.length()); 2533 short[] r = fr.apply(SPECIES.length()); 2534 2535 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2536 for (int i = 0; i < a.length; i += SPECIES.length()) { 2537 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 2538 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 2539 av.lanewise(VectorOperators.LSHR, bv).intoArray(r, i); 2540 } 2541 } 2542 2543 assertArraysEquals(r, a, b, Short512VectorTests::LSHR); 2544 } 2545 2546 @Test(dataProvider = "shortBinaryOpMaskProvider") 2547 static void LSHRShort512VectorTestsMasked(IntFunction<short[]> fa, IntFunction<short[]> fb, 2548 IntFunction<boolean[]> fm) { 2549 short[] a = fa.apply(SPECIES.length()); 2550 short[] b = fb.apply(SPECIES.length()); 2551 short[] r = fr.apply(SPECIES.length()); 2552 boolean[] mask = fm.apply(SPECIES.length()); 2553 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2554 2555 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2556 for (int i = 0; i < a.length; i += SPECIES.length()) { 2557 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 2558 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 2559 av.lanewise(VectorOperators.LSHR, bv, vmask).intoArray(r, i); 2560 } 2561 } 2562 2563 assertArraysEquals(r, a, b, mask, Short512VectorTests::LSHR); 2564 } 2565 2566 static short LSHL_unary(short a, short b) { 2567 return (short)((a << (b & 15))); 2568 } 2569 2570 @Test(dataProvider = "shortBinaryOpProvider") 2571 static void LSHLShort512VectorTestsScalarShift(IntFunction<short[]> fa, IntFunction<short[]> fb) { 2572 short[] a = fa.apply(SPECIES.length()); 2573 short[] b = fb.apply(SPECIES.length()); 2574 short[] r = fr.apply(SPECIES.length()); 2575 2576 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2577 for (int i = 0; i < a.length; i += SPECIES.length()) { 2578 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 2579 av.lanewise(VectorOperators.LSHL, (int)b[i]).intoArray(r, i); 2580 } 2581 } 2582 2583 assertShiftArraysEquals(r, a, b, Short512VectorTests::LSHL_unary); 2584 } 2585 2586 @Test(dataProvider = "shortBinaryOpMaskProvider") 2587 static void LSHLShort512VectorTestsScalarShiftMasked(IntFunction<short[]> fa, IntFunction<short[]> fb, 2588 IntFunction<boolean[]> fm) { 2589 short[] a = fa.apply(SPECIES.length()); 2590 short[] b = fb.apply(SPECIES.length()); 2591 short[] r = fr.apply(SPECIES.length()); 2592 boolean[] mask = fm.apply(SPECIES.length()); 2593 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2594 2595 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2596 for (int i = 0; i < a.length; i += SPECIES.length()) { 2597 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 2598 av.lanewise(VectorOperators.LSHL, (int)b[i], vmask).intoArray(r, i); 2599 } 2600 } 2601 2602 assertShiftArraysEquals(r, a, b, mask, Short512VectorTests::LSHL_unary); 2603 } 2604 2605 static short LSHR_unary(short a, short b) { 2606 return (short)(((a & 0xFFFF) >>> (b & 15))); 2607 } 2608 2609 @Test(dataProvider = "shortBinaryOpProvider") 2610 static void LSHRShort512VectorTestsScalarShift(IntFunction<short[]> fa, IntFunction<short[]> fb) { 2611 short[] a = fa.apply(SPECIES.length()); 2612 short[] b = fb.apply(SPECIES.length()); 2613 short[] r = fr.apply(SPECIES.length()); 2614 2615 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2616 for (int i = 0; i < a.length; i += SPECIES.length()) { 2617 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 2618 av.lanewise(VectorOperators.LSHR, (int)b[i]).intoArray(r, i); 2619 } 2620 } 2621 2622 assertShiftArraysEquals(r, a, b, Short512VectorTests::LSHR_unary); 2623 } 2624 2625 @Test(dataProvider = "shortBinaryOpMaskProvider") 2626 static void LSHRShort512VectorTestsScalarShiftMasked(IntFunction<short[]> fa, IntFunction<short[]> fb, 2627 IntFunction<boolean[]> fm) { 2628 short[] a = fa.apply(SPECIES.length()); 2629 short[] b = fb.apply(SPECIES.length()); 2630 short[] r = fr.apply(SPECIES.length()); 2631 boolean[] mask = fm.apply(SPECIES.length()); 2632 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2633 2634 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2635 for (int i = 0; i < a.length; i += SPECIES.length()) { 2636 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 2637 av.lanewise(VectorOperators.LSHR, (int)b[i], vmask).intoArray(r, i); 2638 } 2639 } 2640 2641 assertShiftArraysEquals(r, a, b, mask, Short512VectorTests::LSHR_unary); 2642 } 2643 2644 static short ASHR_unary(short a, short b) { 2645 return (short)((a >> (b & 15))); 2646 } 2647 2648 @Test(dataProvider = "shortBinaryOpProvider") 2649 static void ASHRShort512VectorTestsScalarShift(IntFunction<short[]> fa, IntFunction<short[]> fb) { 2650 short[] a = fa.apply(SPECIES.length()); 2651 short[] b = fb.apply(SPECIES.length()); 2652 short[] r = fr.apply(SPECIES.length()); 2653 2654 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2655 for (int i = 0; i < a.length; i += SPECIES.length()) { 2656 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 2657 av.lanewise(VectorOperators.ASHR, (int)b[i]).intoArray(r, i); 2658 } 2659 } 2660 2661 assertShiftArraysEquals(r, a, b, Short512VectorTests::ASHR_unary); 2662 } 2663 2664 @Test(dataProvider = "shortBinaryOpMaskProvider") 2665 static void ASHRShort512VectorTestsScalarShiftMasked(IntFunction<short[]> fa, IntFunction<short[]> fb, 2666 IntFunction<boolean[]> fm) { 2667 short[] a = fa.apply(SPECIES.length()); 2668 short[] b = fb.apply(SPECIES.length()); 2669 short[] r = fr.apply(SPECIES.length()); 2670 boolean[] mask = fm.apply(SPECIES.length()); 2671 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2672 2673 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2674 for (int i = 0; i < a.length; i += SPECIES.length()) { 2675 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 2676 av.lanewise(VectorOperators.ASHR, (int)b[i], vmask).intoArray(r, i); 2677 } 2678 } 2679 2680 assertShiftArraysEquals(r, a, b, mask, Short512VectorTests::ASHR_unary); 2681 } 2682 2683 static short ROR(short a, short b) { 2684 return (short)(ROR_scalar(a,b)); 2685 } 2686 2687 @Test(dataProvider = "shortBinaryOpProvider") 2688 static void RORShort512VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { 2689 short[] a = fa.apply(SPECIES.length()); 2690 short[] b = fb.apply(SPECIES.length()); 2691 short[] r = fr.apply(SPECIES.length()); 2692 2693 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2694 for (int i = 0; i < a.length; i += SPECIES.length()) { 2695 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 2696 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 2697 av.lanewise(VectorOperators.ROR, bv).intoArray(r, i); 2698 } 2699 } 2700 2701 assertArraysEquals(r, a, b, Short512VectorTests::ROR); 2702 } 2703 2704 @Test(dataProvider = "shortBinaryOpMaskProvider") 2705 static void RORShort512VectorTestsMasked(IntFunction<short[]> fa, IntFunction<short[]> fb, 2706 IntFunction<boolean[]> fm) { 2707 short[] a = fa.apply(SPECIES.length()); 2708 short[] b = fb.apply(SPECIES.length()); 2709 short[] r = fr.apply(SPECIES.length()); 2710 boolean[] mask = fm.apply(SPECIES.length()); 2711 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2712 2713 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2714 for (int i = 0; i < a.length; i += SPECIES.length()) { 2715 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 2716 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 2717 av.lanewise(VectorOperators.ROR, bv, vmask).intoArray(r, i); 2718 } 2719 } 2720 2721 assertArraysEquals(r, a, b, mask, Short512VectorTests::ROR); 2722 } 2723 2724 static short ROL(short a, short b) { 2725 return (short)(ROL_scalar(a,b)); 2726 } 2727 2728 @Test(dataProvider = "shortBinaryOpProvider") 2729 static void ROLShort512VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { 2730 short[] a = fa.apply(SPECIES.length()); 2731 short[] b = fb.apply(SPECIES.length()); 2732 short[] r = fr.apply(SPECIES.length()); 2733 2734 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2735 for (int i = 0; i < a.length; i += SPECIES.length()) { 2736 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 2737 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 2738 av.lanewise(VectorOperators.ROL, bv).intoArray(r, i); 2739 } 2740 } 2741 2742 assertArraysEquals(r, a, b, Short512VectorTests::ROL); 2743 } 2744 2745 @Test(dataProvider = "shortBinaryOpMaskProvider") 2746 static void ROLShort512VectorTestsMasked(IntFunction<short[]> fa, IntFunction<short[]> fb, 2747 IntFunction<boolean[]> fm) { 2748 short[] a = fa.apply(SPECIES.length()); 2749 short[] b = fb.apply(SPECIES.length()); 2750 short[] r = fr.apply(SPECIES.length()); 2751 boolean[] mask = fm.apply(SPECIES.length()); 2752 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2753 2754 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2755 for (int i = 0; i < a.length; i += SPECIES.length()) { 2756 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 2757 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 2758 av.lanewise(VectorOperators.ROL, bv, vmask).intoArray(r, i); 2759 } 2760 } 2761 2762 assertArraysEquals(r, a, b, mask, Short512VectorTests::ROL); 2763 } 2764 2765 static short ROR_unary(short a, short b) { 2766 return (short)(ROR_scalar(a, b)); 2767 } 2768 2769 @Test(dataProvider = "shortBinaryOpProvider") 2770 static void RORShort512VectorTestsScalarShift(IntFunction<short[]> fa, IntFunction<short[]> fb) { 2771 short[] a = fa.apply(SPECIES.length()); 2772 short[] b = fb.apply(SPECIES.length()); 2773 short[] r = fr.apply(SPECIES.length()); 2774 2775 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2776 for (int i = 0; i < a.length; i += SPECIES.length()) { 2777 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 2778 av.lanewise(VectorOperators.ROR, (int)b[i]).intoArray(r, i); 2779 } 2780 } 2781 2782 assertShiftArraysEquals(r, a, b, Short512VectorTests::ROR_unary); 2783 } 2784 2785 @Test(dataProvider = "shortBinaryOpMaskProvider") 2786 static void RORShort512VectorTestsScalarShiftMasked(IntFunction<short[]> fa, IntFunction<short[]> fb, 2787 IntFunction<boolean[]> fm) { 2788 short[] a = fa.apply(SPECIES.length()); 2789 short[] b = fb.apply(SPECIES.length()); 2790 short[] r = fr.apply(SPECIES.length()); 2791 boolean[] mask = fm.apply(SPECIES.length()); 2792 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2793 2794 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2795 for (int i = 0; i < a.length; i += SPECIES.length()) { 2796 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 2797 av.lanewise(VectorOperators.ROR, (int)b[i], vmask).intoArray(r, i); 2798 } 2799 } 2800 2801 assertShiftArraysEquals(r, a, b, mask, Short512VectorTests::ROR_unary); 2802 } 2803 2804 static short ROL_unary(short a, short b) { 2805 return (short)(ROL_scalar(a, b)); 2806 } 2807 2808 @Test(dataProvider = "shortBinaryOpProvider") 2809 static void ROLShort512VectorTestsScalarShift(IntFunction<short[]> fa, IntFunction<short[]> fb) { 2810 short[] a = fa.apply(SPECIES.length()); 2811 short[] b = fb.apply(SPECIES.length()); 2812 short[] r = fr.apply(SPECIES.length()); 2813 2814 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2815 for (int i = 0; i < a.length; i += SPECIES.length()) { 2816 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 2817 av.lanewise(VectorOperators.ROL, (int)b[i]).intoArray(r, i); 2818 } 2819 } 2820 2821 assertShiftArraysEquals(r, a, b, Short512VectorTests::ROL_unary); 2822 } 2823 2824 @Test(dataProvider = "shortBinaryOpMaskProvider") 2825 static void ROLShort512VectorTestsScalarShiftMasked(IntFunction<short[]> fa, IntFunction<short[]> fb, 2826 IntFunction<boolean[]> fm) { 2827 short[] a = fa.apply(SPECIES.length()); 2828 short[] b = fb.apply(SPECIES.length()); 2829 short[] r = fr.apply(SPECIES.length()); 2830 boolean[] mask = fm.apply(SPECIES.length()); 2831 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2832 2833 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2834 for (int i = 0; i < a.length; i += SPECIES.length()) { 2835 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 2836 av.lanewise(VectorOperators.ROL, (int)b[i], vmask).intoArray(r, i); 2837 } 2838 } 2839 2840 assertShiftArraysEquals(r, a, b, mask, Short512VectorTests::ROL_unary); 2841 } 2842 static short LSHR_binary_const(short a) { 2843 return (short)(((a & 0xFFFF) >>> CONST_SHIFT)); 2844 } 2845 2846 @Test(dataProvider = "shortUnaryOpProvider") 2847 static void LSHRShort512VectorTestsScalarShiftConst(IntFunction<short[]> fa) { 2848 short[] a = fa.apply(SPECIES.length()); 2849 short[] r = fr.apply(SPECIES.length()); 2850 2851 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2852 for (int i = 0; i < a.length; i += SPECIES.length()) { 2853 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 2854 av.lanewise(VectorOperators.LSHR, CONST_SHIFT).intoArray(r, i); 2855 } 2856 } 2857 2858 assertShiftConstEquals(r, a, Short512VectorTests::LSHR_binary_const); 2859 } 2860 2861 @Test(dataProvider = "shortUnaryOpMaskProvider") 2862 static void LSHRShort512VectorTestsScalarShiftMaskedConst(IntFunction<short[]> fa, 2863 IntFunction<boolean[]> fm) { 2864 short[] a = fa.apply(SPECIES.length()); 2865 short[] r = fr.apply(SPECIES.length()); 2866 boolean[] mask = fm.apply(SPECIES.length()); 2867 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2868 2869 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2870 for (int i = 0; i < a.length; i += SPECIES.length()) { 2871 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 2872 av.lanewise(VectorOperators.LSHR, CONST_SHIFT, vmask).intoArray(r, i); 2873 } 2874 } 2875 2876 assertShiftConstEquals(r, a, mask, Short512VectorTests::LSHR_binary_const); 2877 } 2878 2879 static short LSHL_binary_const(short a) { 2880 return (short)((a << CONST_SHIFT)); 2881 } 2882 2883 @Test(dataProvider = "shortUnaryOpProvider") 2884 static void LSHLShort512VectorTestsScalarShiftConst(IntFunction<short[]> fa) { 2885 short[] a = fa.apply(SPECIES.length()); 2886 short[] r = fr.apply(SPECIES.length()); 2887 2888 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2889 for (int i = 0; i < a.length; i += SPECIES.length()) { 2890 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 2891 av.lanewise(VectorOperators.LSHL, CONST_SHIFT).intoArray(r, i); 2892 } 2893 } 2894 2895 assertShiftConstEquals(r, a, Short512VectorTests::LSHL_binary_const); 2896 } 2897 2898 @Test(dataProvider = "shortUnaryOpMaskProvider") 2899 static void LSHLShort512VectorTestsScalarShiftMaskedConst(IntFunction<short[]> fa, 2900 IntFunction<boolean[]> fm) { 2901 short[] a = fa.apply(SPECIES.length()); 2902 short[] r = fr.apply(SPECIES.length()); 2903 boolean[] mask = fm.apply(SPECIES.length()); 2904 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2905 2906 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2907 for (int i = 0; i < a.length; i += SPECIES.length()) { 2908 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 2909 av.lanewise(VectorOperators.LSHL, CONST_SHIFT, vmask).intoArray(r, i); 2910 } 2911 } 2912 2913 assertShiftConstEquals(r, a, mask, Short512VectorTests::LSHL_binary_const); 2914 } 2915 2916 static short ASHR_binary_const(short a) { 2917 return (short)((a >> CONST_SHIFT)); 2918 } 2919 2920 @Test(dataProvider = "shortUnaryOpProvider") 2921 static void ASHRShort512VectorTestsScalarShiftConst(IntFunction<short[]> fa) { 2922 short[] a = fa.apply(SPECIES.length()); 2923 short[] r = fr.apply(SPECIES.length()); 2924 2925 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2926 for (int i = 0; i < a.length; i += SPECIES.length()) { 2927 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 2928 av.lanewise(VectorOperators.ASHR, CONST_SHIFT).intoArray(r, i); 2929 } 2930 } 2931 2932 assertShiftConstEquals(r, a, Short512VectorTests::ASHR_binary_const); 2933 } 2934 2935 @Test(dataProvider = "shortUnaryOpMaskProvider") 2936 static void ASHRShort512VectorTestsScalarShiftMaskedConst(IntFunction<short[]> fa, 2937 IntFunction<boolean[]> fm) { 2938 short[] a = fa.apply(SPECIES.length()); 2939 short[] r = fr.apply(SPECIES.length()); 2940 boolean[] mask = fm.apply(SPECIES.length()); 2941 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2942 2943 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2944 for (int i = 0; i < a.length; i += SPECIES.length()) { 2945 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 2946 av.lanewise(VectorOperators.ASHR, CONST_SHIFT, vmask).intoArray(r, i); 2947 } 2948 } 2949 2950 assertShiftConstEquals(r, a, mask, Short512VectorTests::ASHR_binary_const); 2951 } 2952 2953 static short ROR_binary_const(short a) { 2954 return (short)(ROR_scalar(a, CONST_SHIFT)); 2955 } 2956 2957 @Test(dataProvider = "shortUnaryOpProvider") 2958 static void RORShort512VectorTestsScalarShiftConst(IntFunction<short[]> fa) { 2959 short[] a = fa.apply(SPECIES.length()); 2960 short[] r = fr.apply(SPECIES.length()); 2961 2962 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2963 for (int i = 0; i < a.length; i += SPECIES.length()) { 2964 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 2965 av.lanewise(VectorOperators.ROR, CONST_SHIFT).intoArray(r, i); 2966 } 2967 } 2968 2969 assertShiftConstEquals(r, a, Short512VectorTests::ROR_binary_const); 2970 } 2971 2972 @Test(dataProvider = "shortUnaryOpMaskProvider") 2973 static void RORShort512VectorTestsScalarShiftMaskedConst(IntFunction<short[]> fa, 2974 IntFunction<boolean[]> fm) { 2975 short[] a = fa.apply(SPECIES.length()); 2976 short[] r = fr.apply(SPECIES.length()); 2977 boolean[] mask = fm.apply(SPECIES.length()); 2978 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2979 2980 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2981 for (int i = 0; i < a.length; i += SPECIES.length()) { 2982 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 2983 av.lanewise(VectorOperators.ROR, CONST_SHIFT, vmask).intoArray(r, i); 2984 } 2985 } 2986 2987 assertShiftConstEquals(r, a, mask, Short512VectorTests::ROR_binary_const); 2988 } 2989 2990 static short ROL_binary_const(short a) { 2991 return (short)(ROL_scalar(a, CONST_SHIFT)); 2992 } 2993 2994 @Test(dataProvider = "shortUnaryOpProvider") 2995 static void ROLShort512VectorTestsScalarShiftConst(IntFunction<short[]> fa) { 2996 short[] a = fa.apply(SPECIES.length()); 2997 short[] r = fr.apply(SPECIES.length()); 2998 2999 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3000 for (int i = 0; i < a.length; i += SPECIES.length()) { 3001 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 3002 av.lanewise(VectorOperators.ROL, CONST_SHIFT).intoArray(r, i); 3003 } 3004 } 3005 3006 assertShiftConstEquals(r, a, Short512VectorTests::ROL_binary_const); 3007 } 3008 3009 @Test(dataProvider = "shortUnaryOpMaskProvider") 3010 static void ROLShort512VectorTestsScalarShiftMaskedConst(IntFunction<short[]> fa, 3011 IntFunction<boolean[]> fm) { 3012 short[] a = fa.apply(SPECIES.length()); 3013 short[] r = fr.apply(SPECIES.length()); 3014 boolean[] mask = fm.apply(SPECIES.length()); 3015 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3016 3017 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3018 for (int i = 0; i < a.length; i += SPECIES.length()) { 3019 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 3020 av.lanewise(VectorOperators.ROL, CONST_SHIFT, vmask).intoArray(r, i); 3021 } 3022 } 3023 3024 assertShiftConstEquals(r, a, mask, Short512VectorTests::ROL_binary_const); 3025 } 3026 3027 3028 @Test(dataProvider = "shortUnaryOpProvider") 3029 static void MINShort512VectorTestsWithMemOp(IntFunction<short[]> fa) { 3030 short[] a = fa.apply(SPECIES.length()); 3031 short[] r = fr.apply(SPECIES.length()); 3032 3033 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3034 for (int i = 0; i < a.length; i += SPECIES.length()) { 3035 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 3036 av.lanewise(VectorOperators.MIN, bcast_vec).intoArray(r, i); 3037 } 3038 } 3039 3040 assertArraysEquals(r, a, (short)10, Short512VectorTests::MIN); 3041 } 3042 3043 @Test(dataProvider = "shortUnaryOpProvider") 3044 static void minShort512VectorTestsWithMemOp(IntFunction<short[]> fa) { 3045 short[] a = fa.apply(SPECIES.length()); 3046 short[] r = fr.apply(SPECIES.length()); 3047 3048 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3049 for (int i = 0; i < a.length; i += SPECIES.length()) { 3050 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 3051 av.min(bcast_vec).intoArray(r, i); 3052 } 3053 } 3054 3055 assertArraysEquals(r, a, (short)10, Short512VectorTests::min); 3056 } 3057 3058 @Test(dataProvider = "shortUnaryOpMaskProvider") 3059 static void MINShort512VectorTestsMaskedWithMemOp(IntFunction<short[]> fa, IntFunction<boolean[]> fm) { 3060 short[] a = fa.apply(SPECIES.length()); 3061 short[] r = fr.apply(SPECIES.length()); 3062 boolean[] mask = fm.apply(SPECIES.length()); 3063 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3064 3065 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3066 for (int i = 0; i < a.length; i += SPECIES.length()) { 3067 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 3068 av.lanewise(VectorOperators.MIN, bcast_vec, vmask).intoArray(r, i); 3069 } 3070 } 3071 3072 assertArraysEquals(r, a, (short)10, mask, Short512VectorTests::MIN); 3073 } 3074 3075 @Test(dataProvider = "shortUnaryOpProvider") 3076 static void MAXShort512VectorTestsWithMemOp(IntFunction<short[]> fa) { 3077 short[] a = fa.apply(SPECIES.length()); 3078 short[] r = fr.apply(SPECIES.length()); 3079 3080 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3081 for (int i = 0; i < a.length; i += SPECIES.length()) { 3082 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 3083 av.lanewise(VectorOperators.MAX, bcast_vec).intoArray(r, i); 3084 } 3085 } 3086 3087 assertArraysEquals(r, a, (short)10, Short512VectorTests::MAX); 3088 } 3089 3090 @Test(dataProvider = "shortUnaryOpProvider") 3091 static void maxShort512VectorTestsWithMemOp(IntFunction<short[]> fa) { 3092 short[] a = fa.apply(SPECIES.length()); 3093 short[] r = fr.apply(SPECIES.length()); 3094 3095 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3096 for (int i = 0; i < a.length; i += SPECIES.length()) { 3097 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 3098 av.max(bcast_vec).intoArray(r, i); 3099 } 3100 } 3101 3102 assertArraysEquals(r, a, (short)10, Short512VectorTests::max); 3103 } 3104 3105 @Test(dataProvider = "shortUnaryOpMaskProvider") 3106 static void MAXShort512VectorTestsMaskedWithMemOp(IntFunction<short[]> fa, IntFunction<boolean[]> fm) { 3107 short[] a = fa.apply(SPECIES.length()); 3108 short[] r = fr.apply(SPECIES.length()); 3109 boolean[] mask = fm.apply(SPECIES.length()); 3110 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3111 3112 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3113 for (int i = 0; i < a.length; i += SPECIES.length()) { 3114 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 3115 av.lanewise(VectorOperators.MAX, bcast_vec, vmask).intoArray(r, i); 3116 } 3117 } 3118 3119 assertArraysEquals(r, a, (short)10, mask, Short512VectorTests::MAX); 3120 } 3121 3122 static short MIN(short a, short b) { 3123 return (short)(Math.min(a, b)); 3124 } 3125 3126 @Test(dataProvider = "shortBinaryOpProvider") 3127 static void MINShort512VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { 3128 short[] a = fa.apply(SPECIES.length()); 3129 short[] b = fb.apply(SPECIES.length()); 3130 short[] r = fr.apply(SPECIES.length()); 3131 3132 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3133 for (int i = 0; i < a.length; i += SPECIES.length()) { 3134 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 3135 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 3136 av.lanewise(VectorOperators.MIN, bv).intoArray(r, i); 3137 } 3138 } 3139 3140 assertArraysEquals(r, a, b, Short512VectorTests::MIN); 3141 } 3142 3143 static short min(short a, short b) { 3144 return (short)(Math.min(a, b)); 3145 } 3146 3147 @Test(dataProvider = "shortBinaryOpProvider") 3148 static void minShort512VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { 3149 short[] a = fa.apply(SPECIES.length()); 3150 short[] b = fb.apply(SPECIES.length()); 3151 short[] r = fr.apply(SPECIES.length()); 3152 3153 for (int i = 0; i < a.length; i += SPECIES.length()) { 3154 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 3155 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 3156 av.min(bv).intoArray(r, i); 3157 } 3158 3159 assertArraysEquals(r, a, b, Short512VectorTests::min); 3160 } 3161 3162 static short MAX(short a, short b) { 3163 return (short)(Math.max(a, b)); 3164 } 3165 3166 @Test(dataProvider = "shortBinaryOpProvider") 3167 static void MAXShort512VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { 3168 short[] a = fa.apply(SPECIES.length()); 3169 short[] b = fb.apply(SPECIES.length()); 3170 short[] r = fr.apply(SPECIES.length()); 3171 3172 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3173 for (int i = 0; i < a.length; i += SPECIES.length()) { 3174 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 3175 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 3176 av.lanewise(VectorOperators.MAX, bv).intoArray(r, i); 3177 } 3178 } 3179 3180 assertArraysEquals(r, a, b, Short512VectorTests::MAX); 3181 } 3182 3183 static short max(short a, short b) { 3184 return (short)(Math.max(a, b)); 3185 } 3186 3187 @Test(dataProvider = "shortBinaryOpProvider") 3188 static void maxShort512VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { 3189 short[] a = fa.apply(SPECIES.length()); 3190 short[] b = fb.apply(SPECIES.length()); 3191 short[] r = fr.apply(SPECIES.length()); 3192 3193 for (int i = 0; i < a.length; i += SPECIES.length()) { 3194 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 3195 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 3196 av.max(bv).intoArray(r, i); 3197 } 3198 3199 assertArraysEquals(r, a, b, Short512VectorTests::max); 3200 } 3201 3202 static short UMIN(short a, short b) { 3203 return (short)(VectorMath.minUnsigned(a, b)); 3204 } 3205 3206 @Test(dataProvider = "shortBinaryOpProvider") 3207 static void UMINShort512VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { 3208 short[] a = fa.apply(SPECIES.length()); 3209 short[] b = fb.apply(SPECIES.length()); 3210 short[] r = fr.apply(SPECIES.length()); 3211 3212 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3213 for (int i = 0; i < a.length; i += SPECIES.length()) { 3214 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 3215 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 3216 av.lanewise(VectorOperators.UMIN, bv).intoArray(r, i); 3217 } 3218 } 3219 3220 assertArraysEquals(r, a, b, Short512VectorTests::UMIN); 3221 } 3222 3223 @Test(dataProvider = "shortBinaryOpMaskProvider") 3224 static void UMINShort512VectorTestsMasked(IntFunction<short[]> fa, IntFunction<short[]> fb, 3225 IntFunction<boolean[]> fm) { 3226 short[] a = fa.apply(SPECIES.length()); 3227 short[] b = fb.apply(SPECIES.length()); 3228 short[] r = fr.apply(SPECIES.length()); 3229 boolean[] mask = fm.apply(SPECIES.length()); 3230 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3231 3232 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3233 for (int i = 0; i < a.length; i += SPECIES.length()) { 3234 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 3235 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 3236 av.lanewise(VectorOperators.UMIN, bv, vmask).intoArray(r, i); 3237 } 3238 } 3239 3240 assertArraysEquals(r, a, b, mask, Short512VectorTests::UMIN); 3241 } 3242 3243 static short UMAX(short a, short b) { 3244 return (short)(VectorMath.maxUnsigned(a, b)); 3245 } 3246 3247 @Test(dataProvider = "shortBinaryOpProvider") 3248 static void UMAXShort512VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { 3249 short[] a = fa.apply(SPECIES.length()); 3250 short[] b = fb.apply(SPECIES.length()); 3251 short[] r = fr.apply(SPECIES.length()); 3252 3253 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3254 for (int i = 0; i < a.length; i += SPECIES.length()) { 3255 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 3256 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 3257 av.lanewise(VectorOperators.UMAX, bv).intoArray(r, i); 3258 } 3259 } 3260 3261 assertArraysEquals(r, a, b, Short512VectorTests::UMAX); 3262 } 3263 3264 @Test(dataProvider = "shortBinaryOpMaskProvider") 3265 static void UMAXShort512VectorTestsMasked(IntFunction<short[]> fa, IntFunction<short[]> fb, 3266 IntFunction<boolean[]> fm) { 3267 short[] a = fa.apply(SPECIES.length()); 3268 short[] b = fb.apply(SPECIES.length()); 3269 short[] r = fr.apply(SPECIES.length()); 3270 boolean[] mask = fm.apply(SPECIES.length()); 3271 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3272 3273 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3274 for (int i = 0; i < a.length; i += SPECIES.length()) { 3275 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 3276 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 3277 av.lanewise(VectorOperators.UMAX, bv, vmask).intoArray(r, i); 3278 } 3279 } 3280 3281 assertArraysEquals(r, a, b, mask, Short512VectorTests::UMAX); 3282 } 3283 3284 static short SADD(short a, short b) { 3285 return (short)(VectorMath.addSaturating(a, b)); 3286 } 3287 3288 @Test(dataProvider = "shortSaturatingBinaryOpProvider") 3289 static void SADDShort512VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { 3290 short[] a = fa.apply(SPECIES.length()); 3291 short[] b = fb.apply(SPECIES.length()); 3292 short[] r = fr.apply(SPECIES.length()); 3293 3294 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3295 for (int i = 0; i < a.length; i += SPECIES.length()) { 3296 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 3297 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 3298 av.lanewise(VectorOperators.SADD, bv).intoArray(r, i); 3299 } 3300 } 3301 3302 assertArraysEquals(r, a, b, Short512VectorTests::SADD); 3303 } 3304 3305 @Test(dataProvider = "shortSaturatingBinaryOpMaskProvider") 3306 static void SADDShort512VectorTestsMasked(IntFunction<short[]> fa, IntFunction<short[]> fb, 3307 IntFunction<boolean[]> fm) { 3308 short[] a = fa.apply(SPECIES.length()); 3309 short[] b = fb.apply(SPECIES.length()); 3310 short[] r = fr.apply(SPECIES.length()); 3311 boolean[] mask = fm.apply(SPECIES.length()); 3312 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3313 3314 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3315 for (int i = 0; i < a.length; i += SPECIES.length()) { 3316 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 3317 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 3318 av.lanewise(VectorOperators.SADD, bv, vmask).intoArray(r, i); 3319 } 3320 } 3321 3322 assertArraysEquals(r, a, b, mask, Short512VectorTests::SADD); 3323 } 3324 3325 static short SSUB(short a, short b) { 3326 return (short)(VectorMath.subSaturating(a, b)); 3327 } 3328 3329 @Test(dataProvider = "shortSaturatingBinaryOpProvider") 3330 static void SSUBShort512VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { 3331 short[] a = fa.apply(SPECIES.length()); 3332 short[] b = fb.apply(SPECIES.length()); 3333 short[] r = fr.apply(SPECIES.length()); 3334 3335 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3336 for (int i = 0; i < a.length; i += SPECIES.length()) { 3337 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 3338 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 3339 av.lanewise(VectorOperators.SSUB, bv).intoArray(r, i); 3340 } 3341 } 3342 3343 assertArraysEquals(r, a, b, Short512VectorTests::SSUB); 3344 } 3345 3346 @Test(dataProvider = "shortSaturatingBinaryOpMaskProvider") 3347 static void SSUBShort512VectorTestsMasked(IntFunction<short[]> fa, IntFunction<short[]> fb, 3348 IntFunction<boolean[]> fm) { 3349 short[] a = fa.apply(SPECIES.length()); 3350 short[] b = fb.apply(SPECIES.length()); 3351 short[] r = fr.apply(SPECIES.length()); 3352 boolean[] mask = fm.apply(SPECIES.length()); 3353 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3354 3355 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3356 for (int i = 0; i < a.length; i += SPECIES.length()) { 3357 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 3358 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 3359 av.lanewise(VectorOperators.SSUB, bv, vmask).intoArray(r, i); 3360 } 3361 } 3362 3363 assertArraysEquals(r, a, b, mask, Short512VectorTests::SSUB); 3364 } 3365 3366 static short SUADD(short a, short b) { 3367 return (short)(VectorMath.addSaturatingUnsigned(a, b)); 3368 } 3369 3370 @Test(dataProvider = "shortSaturatingBinaryOpProvider") 3371 static void SUADDShort512VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { 3372 short[] a = fa.apply(SPECIES.length()); 3373 short[] b = fb.apply(SPECIES.length()); 3374 short[] r = fr.apply(SPECIES.length()); 3375 3376 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3377 for (int i = 0; i < a.length; i += SPECIES.length()) { 3378 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 3379 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 3380 av.lanewise(VectorOperators.SUADD, bv).intoArray(r, i); 3381 } 3382 } 3383 3384 assertArraysEquals(r, a, b, Short512VectorTests::SUADD); 3385 } 3386 3387 @Test(dataProvider = "shortSaturatingBinaryOpMaskProvider") 3388 static void SUADDShort512VectorTestsMasked(IntFunction<short[]> fa, IntFunction<short[]> fb, 3389 IntFunction<boolean[]> fm) { 3390 short[] a = fa.apply(SPECIES.length()); 3391 short[] b = fb.apply(SPECIES.length()); 3392 short[] r = fr.apply(SPECIES.length()); 3393 boolean[] mask = fm.apply(SPECIES.length()); 3394 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3395 3396 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3397 for (int i = 0; i < a.length; i += SPECIES.length()) { 3398 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 3399 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 3400 av.lanewise(VectorOperators.SUADD, bv, vmask).intoArray(r, i); 3401 } 3402 } 3403 3404 assertArraysEquals(r, a, b, mask, Short512VectorTests::SUADD); 3405 } 3406 3407 static short SUSUB(short a, short b) { 3408 return (short)(VectorMath.subSaturatingUnsigned(a, b)); 3409 } 3410 3411 @Test(dataProvider = "shortSaturatingBinaryOpProvider") 3412 static void SUSUBShort512VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { 3413 short[] a = fa.apply(SPECIES.length()); 3414 short[] b = fb.apply(SPECIES.length()); 3415 short[] r = fr.apply(SPECIES.length()); 3416 3417 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3418 for (int i = 0; i < a.length; i += SPECIES.length()) { 3419 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 3420 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 3421 av.lanewise(VectorOperators.SUSUB, bv).intoArray(r, i); 3422 } 3423 } 3424 3425 assertArraysEquals(r, a, b, Short512VectorTests::SUSUB); 3426 } 3427 3428 @Test(dataProvider = "shortSaturatingBinaryOpMaskProvider") 3429 static void SUSUBShort512VectorTestsMasked(IntFunction<short[]> fa, IntFunction<short[]> fb, 3430 IntFunction<boolean[]> fm) { 3431 short[] a = fa.apply(SPECIES.length()); 3432 short[] b = fb.apply(SPECIES.length()); 3433 short[] r = fr.apply(SPECIES.length()); 3434 boolean[] mask = fm.apply(SPECIES.length()); 3435 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3436 3437 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3438 for (int i = 0; i < a.length; i += SPECIES.length()) { 3439 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 3440 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 3441 av.lanewise(VectorOperators.SUSUB, bv, vmask).intoArray(r, i); 3442 } 3443 } 3444 3445 assertArraysEquals(r, a, b, mask, Short512VectorTests::SUSUB); 3446 } 3447 3448 @Test(dataProvider = "shortBinaryOpProvider") 3449 static void MINShort512VectorTestsBroadcastSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb) { 3450 short[] a = fa.apply(SPECIES.length()); 3451 short[] b = fb.apply(SPECIES.length()); 3452 short[] r = fr.apply(SPECIES.length()); 3453 3454 for (int i = 0; i < a.length; i += SPECIES.length()) { 3455 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 3456 av.lanewise(VectorOperators.MIN, b[i]).intoArray(r, i); 3457 } 3458 3459 assertBroadcastArraysEquals(r, a, b, Short512VectorTests::MIN); 3460 } 3461 3462 @Test(dataProvider = "shortBinaryOpProvider") 3463 static void minShort512VectorTestsBroadcastSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb) { 3464 short[] a = fa.apply(SPECIES.length()); 3465 short[] b = fb.apply(SPECIES.length()); 3466 short[] r = fr.apply(SPECIES.length()); 3467 3468 for (int i = 0; i < a.length; i += SPECIES.length()) { 3469 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 3470 av.min(b[i]).intoArray(r, i); 3471 } 3472 3473 assertBroadcastArraysEquals(r, a, b, Short512VectorTests::min); 3474 } 3475 3476 @Test(dataProvider = "shortBinaryOpProvider") 3477 static void MAXShort512VectorTestsBroadcastSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb) { 3478 short[] a = fa.apply(SPECIES.length()); 3479 short[] b = fb.apply(SPECIES.length()); 3480 short[] r = fr.apply(SPECIES.length()); 3481 3482 for (int i = 0; i < a.length; i += SPECIES.length()) { 3483 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 3484 av.lanewise(VectorOperators.MAX, b[i]).intoArray(r, i); 3485 } 3486 3487 assertBroadcastArraysEquals(r, a, b, Short512VectorTests::MAX); 3488 } 3489 3490 @Test(dataProvider = "shortBinaryOpProvider") 3491 static void maxShort512VectorTestsBroadcastSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb) { 3492 short[] a = fa.apply(SPECIES.length()); 3493 short[] b = fb.apply(SPECIES.length()); 3494 short[] r = fr.apply(SPECIES.length()); 3495 3496 for (int i = 0; i < a.length; i += SPECIES.length()) { 3497 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 3498 av.max(b[i]).intoArray(r, i); 3499 } 3500 3501 assertBroadcastArraysEquals(r, a, b, Short512VectorTests::max); 3502 } 3503 @Test(dataProvider = "shortSaturatingBinaryOpAssocProvider") 3504 static void SUADDAssocShort512VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb, IntFunction<short[]> fc) { 3505 short[] a = fa.apply(SPECIES.length()); 3506 short[] b = fb.apply(SPECIES.length()); 3507 short[] c = fc.apply(SPECIES.length()); 3508 short[] rl = fr.apply(SPECIES.length()); 3509 short[] rr = fr.apply(SPECIES.length()); 3510 3511 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3512 for (int i = 0; i < a.length; i += SPECIES.length()) { 3513 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 3514 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 3515 ShortVector cv = ShortVector.fromArray(SPECIES, c, i); 3516 av.lanewise(VectorOperators.SUADD, bv).lanewise(VectorOperators.SUADD, cv).intoArray(rl, i); 3517 av.lanewise(VectorOperators.SUADD, bv.lanewise(VectorOperators.SUADD, cv)).intoArray(rr, i); 3518 } 3519 } 3520 3521 assertArraysEqualsAssociative(rl, rr, a, b, c, Short512VectorTests::SUADD); 3522 } 3523 3524 @Test(dataProvider = "shortSaturatingBinaryOpAssocMaskProvider") 3525 static void SUADDAssocShort512VectorTestsMasked(IntFunction<short[]> fa, IntFunction<short[]> fb, 3526 IntFunction<short[]> fc, IntFunction<boolean[]> fm) { 3527 short[] a = fa.apply(SPECIES.length()); 3528 short[] b = fb.apply(SPECIES.length()); 3529 short[] c = fc.apply(SPECIES.length()); 3530 boolean[] mask = fm.apply(SPECIES.length()); 3531 short[] rl = fr.apply(SPECIES.length()); 3532 short[] rr = fr.apply(SPECIES.length()); 3533 3534 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3535 3536 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3537 for (int i = 0; i < a.length; i += SPECIES.length()) { 3538 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 3539 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 3540 ShortVector cv = ShortVector.fromArray(SPECIES, c, i); 3541 av.lanewise(VectorOperators.SUADD, bv, vmask).lanewise(VectorOperators.SUADD, cv, vmask).intoArray(rl, i); 3542 av.lanewise(VectorOperators.SUADD, bv.lanewise(VectorOperators.SUADD, cv, vmask), vmask).intoArray(rr, i); 3543 } 3544 } 3545 3546 assertArraysEqualsAssociative(rl, rr, a, b, c, mask, Short512VectorTests::SUADD); 3547 } 3548 3549 static short ANDReduce(short[] a, int idx) { 3550 short res = -1; 3551 for (int i = idx; i < (idx + SPECIES.length()); i++) { 3552 res &= a[i]; 3553 } 3554 3555 return res; 3556 } 3557 3558 static short ANDReduceAll(short[] a) { 3559 short res = -1; 3560 for (int i = 0; i < a.length; i += SPECIES.length()) { 3561 res &= ANDReduce(a, i); 3562 } 3563 3564 return res; 3565 } 3566 3567 @Test(dataProvider = "shortUnaryOpProvider") 3568 static void ANDReduceShort512VectorTests(IntFunction<short[]> fa) { 3569 short[] a = fa.apply(SPECIES.length()); 3570 short[] r = fr.apply(SPECIES.length()); 3571 short ra = -1; 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 r[i] = av.reduceLanes(VectorOperators.AND); 3577 } 3578 } 3579 3580 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3581 ra = -1; 3582 for (int i = 0; i < a.length; i += SPECIES.length()) { 3583 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 3584 ra &= av.reduceLanes(VectorOperators.AND); 3585 } 3586 } 3587 3588 assertReductionArraysEquals(r, ra, a, 3589 Short512VectorTests::ANDReduce, Short512VectorTests::ANDReduceAll); 3590 } 3591 3592 static short ANDReduceMasked(short[] a, int idx, boolean[] mask) { 3593 short res = -1; 3594 for (int i = idx; i < (idx + SPECIES.length()); i++) { 3595 if (mask[i % SPECIES.length()]) 3596 res &= a[i]; 3597 } 3598 3599 return res; 3600 } 3601 3602 static short ANDReduceAllMasked(short[] a, boolean[] mask) { 3603 short res = -1; 3604 for (int i = 0; i < a.length; i += SPECIES.length()) { 3605 res &= ANDReduceMasked(a, i, mask); 3606 } 3607 3608 return res; 3609 } 3610 3611 @Test(dataProvider = "shortUnaryOpMaskProvider") 3612 static void ANDReduceShort512VectorTestsMasked(IntFunction<short[]> fa, IntFunction<boolean[]> fm) { 3613 short[] a = fa.apply(SPECIES.length()); 3614 short[] r = fr.apply(SPECIES.length()); 3615 boolean[] mask = fm.apply(SPECIES.length()); 3616 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3617 short ra = -1; 3618 3619 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3620 for (int i = 0; i < a.length; i += SPECIES.length()) { 3621 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 3622 r[i] = av.reduceLanes(VectorOperators.AND, vmask); 3623 } 3624 } 3625 3626 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3627 ra = -1; 3628 for (int i = 0; i < a.length; i += SPECIES.length()) { 3629 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 3630 ra &= av.reduceLanes(VectorOperators.AND, vmask); 3631 } 3632 } 3633 3634 assertReductionArraysEqualsMasked(r, ra, a, mask, 3635 Short512VectorTests::ANDReduceMasked, Short512VectorTests::ANDReduceAllMasked); 3636 } 3637 3638 static short ORReduce(short[] a, int idx) { 3639 short res = 0; 3640 for (int i = idx; i < (idx + SPECIES.length()); i++) { 3641 res |= a[i]; 3642 } 3643 3644 return res; 3645 } 3646 3647 static short ORReduceAll(short[] a) { 3648 short res = 0; 3649 for (int i = 0; i < a.length; i += SPECIES.length()) { 3650 res |= ORReduce(a, i); 3651 } 3652 3653 return res; 3654 } 3655 3656 @Test(dataProvider = "shortUnaryOpProvider") 3657 static void ORReduceShort512VectorTests(IntFunction<short[]> fa) { 3658 short[] a = fa.apply(SPECIES.length()); 3659 short[] r = fr.apply(SPECIES.length()); 3660 short ra = 0; 3661 3662 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3663 for (int i = 0; i < a.length; i += SPECIES.length()) { 3664 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 3665 r[i] = av.reduceLanes(VectorOperators.OR); 3666 } 3667 } 3668 3669 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3670 ra = 0; 3671 for (int i = 0; i < a.length; i += SPECIES.length()) { 3672 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 3673 ra |= av.reduceLanes(VectorOperators.OR); 3674 } 3675 } 3676 3677 assertReductionArraysEquals(r, ra, a, 3678 Short512VectorTests::ORReduce, Short512VectorTests::ORReduceAll); 3679 } 3680 3681 static short ORReduceMasked(short[] a, int idx, boolean[] mask) { 3682 short res = 0; 3683 for (int i = idx; i < (idx + SPECIES.length()); i++) { 3684 if (mask[i % SPECIES.length()]) 3685 res |= a[i]; 3686 } 3687 3688 return res; 3689 } 3690 3691 static short ORReduceAllMasked(short[] a, boolean[] mask) { 3692 short res = 0; 3693 for (int i = 0; i < a.length; i += SPECIES.length()) { 3694 res |= ORReduceMasked(a, i, mask); 3695 } 3696 3697 return res; 3698 } 3699 3700 @Test(dataProvider = "shortUnaryOpMaskProvider") 3701 static void ORReduceShort512VectorTestsMasked(IntFunction<short[]> fa, IntFunction<boolean[]> fm) { 3702 short[] a = fa.apply(SPECIES.length()); 3703 short[] r = fr.apply(SPECIES.length()); 3704 boolean[] mask = fm.apply(SPECIES.length()); 3705 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3706 short ra = 0; 3707 3708 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3709 for (int i = 0; i < a.length; i += SPECIES.length()) { 3710 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 3711 r[i] = av.reduceLanes(VectorOperators.OR, vmask); 3712 } 3713 } 3714 3715 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3716 ra = 0; 3717 for (int i = 0; i < a.length; i += SPECIES.length()) { 3718 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 3719 ra |= av.reduceLanes(VectorOperators.OR, vmask); 3720 } 3721 } 3722 3723 assertReductionArraysEqualsMasked(r, ra, a, mask, 3724 Short512VectorTests::ORReduceMasked, Short512VectorTests::ORReduceAllMasked); 3725 } 3726 3727 static short XORReduce(short[] a, int idx) { 3728 short res = 0; 3729 for (int i = idx; i < (idx + SPECIES.length()); i++) { 3730 res ^= a[i]; 3731 } 3732 3733 return res; 3734 } 3735 3736 static short XORReduceAll(short[] a) { 3737 short res = 0; 3738 for (int i = 0; i < a.length; i += SPECIES.length()) { 3739 res ^= XORReduce(a, i); 3740 } 3741 3742 return res; 3743 } 3744 3745 @Test(dataProvider = "shortUnaryOpProvider") 3746 static void XORReduceShort512VectorTests(IntFunction<short[]> fa) { 3747 short[] a = fa.apply(SPECIES.length()); 3748 short[] r = fr.apply(SPECIES.length()); 3749 short ra = 0; 3750 3751 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3752 for (int i = 0; i < a.length; i += SPECIES.length()) { 3753 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 3754 r[i] = av.reduceLanes(VectorOperators.XOR); 3755 } 3756 } 3757 3758 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3759 ra = 0; 3760 for (int i = 0; i < a.length; i += SPECIES.length()) { 3761 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 3762 ra ^= av.reduceLanes(VectorOperators.XOR); 3763 } 3764 } 3765 3766 assertReductionArraysEquals(r, ra, a, 3767 Short512VectorTests::XORReduce, Short512VectorTests::XORReduceAll); 3768 } 3769 3770 static short XORReduceMasked(short[] a, int idx, boolean[] mask) { 3771 short res = 0; 3772 for (int i = idx; i < (idx + SPECIES.length()); i++) { 3773 if (mask[i % SPECIES.length()]) 3774 res ^= a[i]; 3775 } 3776 3777 return res; 3778 } 3779 3780 static short XORReduceAllMasked(short[] a, boolean[] mask) { 3781 short res = 0; 3782 for (int i = 0; i < a.length; i += SPECIES.length()) { 3783 res ^= XORReduceMasked(a, i, mask); 3784 } 3785 3786 return res; 3787 } 3788 3789 @Test(dataProvider = "shortUnaryOpMaskProvider") 3790 static void XORReduceShort512VectorTestsMasked(IntFunction<short[]> fa, IntFunction<boolean[]> fm) { 3791 short[] a = fa.apply(SPECIES.length()); 3792 short[] r = fr.apply(SPECIES.length()); 3793 boolean[] mask = fm.apply(SPECIES.length()); 3794 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3795 short ra = 0; 3796 3797 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3798 for (int i = 0; i < a.length; i += SPECIES.length()) { 3799 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 3800 r[i] = av.reduceLanes(VectorOperators.XOR, vmask); 3801 } 3802 } 3803 3804 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3805 ra = 0; 3806 for (int i = 0; i < a.length; i += SPECIES.length()) { 3807 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 3808 ra ^= av.reduceLanes(VectorOperators.XOR, vmask); 3809 } 3810 } 3811 3812 assertReductionArraysEqualsMasked(r, ra, a, mask, 3813 Short512VectorTests::XORReduceMasked, Short512VectorTests::XORReduceAllMasked); 3814 } 3815 3816 static short ADDReduce(short[] a, int idx) { 3817 short res = 0; 3818 for (int i = idx; i < (idx + SPECIES.length()); i++) { 3819 res += a[i]; 3820 } 3821 3822 return res; 3823 } 3824 3825 static short ADDReduceAll(short[] a) { 3826 short res = 0; 3827 for (int i = 0; i < a.length; i += SPECIES.length()) { 3828 res += ADDReduce(a, i); 3829 } 3830 3831 return res; 3832 } 3833 3834 @Test(dataProvider = "shortUnaryOpProvider") 3835 static void ADDReduceShort512VectorTests(IntFunction<short[]> fa) { 3836 short[] a = fa.apply(SPECIES.length()); 3837 short[] r = fr.apply(SPECIES.length()); 3838 short ra = 0; 3839 3840 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3841 for (int i = 0; i < a.length; i += SPECIES.length()) { 3842 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 3843 r[i] = av.reduceLanes(VectorOperators.ADD); 3844 } 3845 } 3846 3847 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3848 ra = 0; 3849 for (int i = 0; i < a.length; i += SPECIES.length()) { 3850 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 3851 ra += av.reduceLanes(VectorOperators.ADD); 3852 } 3853 } 3854 3855 assertReductionArraysEquals(r, ra, a, 3856 Short512VectorTests::ADDReduce, Short512VectorTests::ADDReduceAll); 3857 } 3858 3859 static short ADDReduceMasked(short[] a, int idx, boolean[] mask) { 3860 short res = 0; 3861 for (int i = idx; i < (idx + SPECIES.length()); i++) { 3862 if (mask[i % SPECIES.length()]) 3863 res += a[i]; 3864 } 3865 3866 return res; 3867 } 3868 3869 static short ADDReduceAllMasked(short[] a, boolean[] mask) { 3870 short res = 0; 3871 for (int i = 0; i < a.length; i += SPECIES.length()) { 3872 res += ADDReduceMasked(a, i, mask); 3873 } 3874 3875 return res; 3876 } 3877 3878 @Test(dataProvider = "shortUnaryOpMaskProvider") 3879 static void ADDReduceShort512VectorTestsMasked(IntFunction<short[]> fa, IntFunction<boolean[]> fm) { 3880 short[] a = fa.apply(SPECIES.length()); 3881 short[] r = fr.apply(SPECIES.length()); 3882 boolean[] mask = fm.apply(SPECIES.length()); 3883 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3884 short ra = 0; 3885 3886 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3887 for (int i = 0; i < a.length; i += SPECIES.length()) { 3888 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 3889 r[i] = av.reduceLanes(VectorOperators.ADD, vmask); 3890 } 3891 } 3892 3893 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3894 ra = 0; 3895 for (int i = 0; i < a.length; i += SPECIES.length()) { 3896 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 3897 ra += av.reduceLanes(VectorOperators.ADD, vmask); 3898 } 3899 } 3900 3901 assertReductionArraysEqualsMasked(r, ra, a, mask, 3902 Short512VectorTests::ADDReduceMasked, Short512VectorTests::ADDReduceAllMasked); 3903 } 3904 3905 static short MULReduce(short[] a, int idx) { 3906 short res = 1; 3907 for (int i = idx; i < (idx + SPECIES.length()); i++) { 3908 res *= a[i]; 3909 } 3910 3911 return res; 3912 } 3913 3914 static short MULReduceAll(short[] a) { 3915 short res = 1; 3916 for (int i = 0; i < a.length; i += SPECIES.length()) { 3917 res *= MULReduce(a, i); 3918 } 3919 3920 return res; 3921 } 3922 3923 @Test(dataProvider = "shortUnaryOpProvider") 3924 static void MULReduceShort512VectorTests(IntFunction<short[]> fa) { 3925 short[] a = fa.apply(SPECIES.length()); 3926 short[] r = fr.apply(SPECIES.length()); 3927 short ra = 1; 3928 3929 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3930 for (int i = 0; i < a.length; i += SPECIES.length()) { 3931 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 3932 r[i] = av.reduceLanes(VectorOperators.MUL); 3933 } 3934 } 3935 3936 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3937 ra = 1; 3938 for (int i = 0; i < a.length; i += SPECIES.length()) { 3939 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 3940 ra *= av.reduceLanes(VectorOperators.MUL); 3941 } 3942 } 3943 3944 assertReductionArraysEquals(r, ra, a, 3945 Short512VectorTests::MULReduce, Short512VectorTests::MULReduceAll); 3946 } 3947 3948 static short MULReduceMasked(short[] a, int idx, boolean[] mask) { 3949 short res = 1; 3950 for (int i = idx; i < (idx + SPECIES.length()); i++) { 3951 if (mask[i % SPECIES.length()]) 3952 res *= a[i]; 3953 } 3954 3955 return res; 3956 } 3957 3958 static short MULReduceAllMasked(short[] a, boolean[] mask) { 3959 short res = 1; 3960 for (int i = 0; i < a.length; i += SPECIES.length()) { 3961 res *= MULReduceMasked(a, i, mask); 3962 } 3963 3964 return res; 3965 } 3966 3967 @Test(dataProvider = "shortUnaryOpMaskProvider") 3968 static void MULReduceShort512VectorTestsMasked(IntFunction<short[]> fa, IntFunction<boolean[]> fm) { 3969 short[] a = fa.apply(SPECIES.length()); 3970 short[] r = fr.apply(SPECIES.length()); 3971 boolean[] mask = fm.apply(SPECIES.length()); 3972 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3973 short ra = 1; 3974 3975 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3976 for (int i = 0; i < a.length; i += SPECIES.length()) { 3977 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 3978 r[i] = av.reduceLanes(VectorOperators.MUL, vmask); 3979 } 3980 } 3981 3982 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3983 ra = 1; 3984 for (int i = 0; i < a.length; i += SPECIES.length()) { 3985 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 3986 ra *= av.reduceLanes(VectorOperators.MUL, vmask); 3987 } 3988 } 3989 3990 assertReductionArraysEqualsMasked(r, ra, a, mask, 3991 Short512VectorTests::MULReduceMasked, Short512VectorTests::MULReduceAllMasked); 3992 } 3993 3994 static short MINReduce(short[] a, int idx) { 3995 short res = Short.MAX_VALUE; 3996 for (int i = idx; i < (idx + SPECIES.length()); i++) { 3997 res = (short) Math.min(res, a[i]); 3998 } 3999 4000 return res; 4001 } 4002 4003 static short MINReduceAll(short[] a) { 4004 short res = Short.MAX_VALUE; 4005 for (int i = 0; i < a.length; i += SPECIES.length()) { 4006 res = (short) Math.min(res, MINReduce(a, i)); 4007 } 4008 4009 return res; 4010 } 4011 4012 @Test(dataProvider = "shortUnaryOpProvider") 4013 static void MINReduceShort512VectorTests(IntFunction<short[]> fa) { 4014 short[] a = fa.apply(SPECIES.length()); 4015 short[] r = fr.apply(SPECIES.length()); 4016 short ra = Short.MAX_VALUE; 4017 4018 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4019 for (int i = 0; i < a.length; i += SPECIES.length()) { 4020 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 4021 r[i] = av.reduceLanes(VectorOperators.MIN); 4022 } 4023 } 4024 4025 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4026 ra = Short.MAX_VALUE; 4027 for (int i = 0; i < a.length; i += SPECIES.length()) { 4028 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 4029 ra = (short) Math.min(ra, av.reduceLanes(VectorOperators.MIN)); 4030 } 4031 } 4032 4033 assertReductionArraysEquals(r, ra, a, 4034 Short512VectorTests::MINReduce, Short512VectorTests::MINReduceAll); 4035 } 4036 4037 static short MINReduceMasked(short[] a, int idx, boolean[] mask) { 4038 short res = Short.MAX_VALUE; 4039 for (int i = idx; i < (idx + SPECIES.length()); i++) { 4040 if (mask[i % SPECIES.length()]) 4041 res = (short) Math.min(res, a[i]); 4042 } 4043 4044 return res; 4045 } 4046 4047 static short MINReduceAllMasked(short[] a, boolean[] mask) { 4048 short res = Short.MAX_VALUE; 4049 for (int i = 0; i < a.length; i += SPECIES.length()) { 4050 res = (short) Math.min(res, MINReduceMasked(a, i, mask)); 4051 } 4052 4053 return res; 4054 } 4055 4056 @Test(dataProvider = "shortUnaryOpMaskProvider") 4057 static void MINReduceShort512VectorTestsMasked(IntFunction<short[]> fa, IntFunction<boolean[]> fm) { 4058 short[] a = fa.apply(SPECIES.length()); 4059 short[] r = fr.apply(SPECIES.length()); 4060 boolean[] mask = fm.apply(SPECIES.length()); 4061 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 4062 short ra = Short.MAX_VALUE; 4063 4064 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4065 for (int i = 0; i < a.length; i += SPECIES.length()) { 4066 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 4067 r[i] = av.reduceLanes(VectorOperators.MIN, vmask); 4068 } 4069 } 4070 4071 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4072 ra = Short.MAX_VALUE; 4073 for (int i = 0; i < a.length; i += SPECIES.length()) { 4074 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 4075 ra = (short) Math.min(ra, av.reduceLanes(VectorOperators.MIN, vmask)); 4076 } 4077 } 4078 4079 assertReductionArraysEqualsMasked(r, ra, a, mask, 4080 Short512VectorTests::MINReduceMasked, Short512VectorTests::MINReduceAllMasked); 4081 } 4082 4083 static short MAXReduce(short[] a, int idx) { 4084 short res = Short.MIN_VALUE; 4085 for (int i = idx; i < (idx + SPECIES.length()); i++) { 4086 res = (short) Math.max(res, a[i]); 4087 } 4088 4089 return res; 4090 } 4091 4092 static short MAXReduceAll(short[] a) { 4093 short res = Short.MIN_VALUE; 4094 for (int i = 0; i < a.length; i += SPECIES.length()) { 4095 res = (short) Math.max(res, MAXReduce(a, i)); 4096 } 4097 4098 return res; 4099 } 4100 4101 @Test(dataProvider = "shortUnaryOpProvider") 4102 static void MAXReduceShort512VectorTests(IntFunction<short[]> fa) { 4103 short[] a = fa.apply(SPECIES.length()); 4104 short[] r = fr.apply(SPECIES.length()); 4105 short ra = Short.MIN_VALUE; 4106 4107 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4108 for (int i = 0; i < a.length; i += SPECIES.length()) { 4109 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 4110 r[i] = av.reduceLanes(VectorOperators.MAX); 4111 } 4112 } 4113 4114 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4115 ra = Short.MIN_VALUE; 4116 for (int i = 0; i < a.length; i += SPECIES.length()) { 4117 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 4118 ra = (short) Math.max(ra, av.reduceLanes(VectorOperators.MAX)); 4119 } 4120 } 4121 4122 assertReductionArraysEquals(r, ra, a, 4123 Short512VectorTests::MAXReduce, Short512VectorTests::MAXReduceAll); 4124 } 4125 4126 static short MAXReduceMasked(short[] a, int idx, boolean[] mask) { 4127 short res = Short.MIN_VALUE; 4128 for (int i = idx; i < (idx + SPECIES.length()); i++) { 4129 if (mask[i % SPECIES.length()]) 4130 res = (short) Math.max(res, a[i]); 4131 } 4132 4133 return res; 4134 } 4135 4136 static short MAXReduceAllMasked(short[] a, boolean[] mask) { 4137 short res = Short.MIN_VALUE; 4138 for (int i = 0; i < a.length; i += SPECIES.length()) { 4139 res = (short) Math.max(res, MAXReduceMasked(a, i, mask)); 4140 } 4141 4142 return res; 4143 } 4144 4145 @Test(dataProvider = "shortUnaryOpMaskProvider") 4146 static void MAXReduceShort512VectorTestsMasked(IntFunction<short[]> fa, IntFunction<boolean[]> fm) { 4147 short[] a = fa.apply(SPECIES.length()); 4148 short[] r = fr.apply(SPECIES.length()); 4149 boolean[] mask = fm.apply(SPECIES.length()); 4150 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 4151 short ra = Short.MIN_VALUE; 4152 4153 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4154 for (int i = 0; i < a.length; i += SPECIES.length()) { 4155 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 4156 r[i] = av.reduceLanes(VectorOperators.MAX, vmask); 4157 } 4158 } 4159 4160 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4161 ra = Short.MIN_VALUE; 4162 for (int i = 0; i < a.length; i += SPECIES.length()) { 4163 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 4164 ra = (short) Math.max(ra, av.reduceLanes(VectorOperators.MAX, vmask)); 4165 } 4166 } 4167 4168 assertReductionArraysEqualsMasked(r, ra, a, mask, 4169 Short512VectorTests::MAXReduceMasked, Short512VectorTests::MAXReduceAllMasked); 4170 } 4171 4172 static short UMINReduce(short[] a, int idx) { 4173 short res = Short.MAX_VALUE; 4174 for (int i = idx; i < (idx + SPECIES.length()); i++) { 4175 res = (short) VectorMath.minUnsigned(res, a[i]); 4176 } 4177 4178 return res; 4179 } 4180 4181 static short UMINReduceAll(short[] a) { 4182 short res = Short.MAX_VALUE; 4183 for (int i = 0; i < a.length; i += SPECIES.length()) { 4184 res = (short) VectorMath.minUnsigned(res, UMINReduce(a, i)); 4185 } 4186 4187 return res; 4188 } 4189 4190 @Test(dataProvider = "shortUnaryOpProvider") 4191 static void UMINReduceShort512VectorTests(IntFunction<short[]> fa) { 4192 short[] a = fa.apply(SPECIES.length()); 4193 short[] r = fr.apply(SPECIES.length()); 4194 short ra = Short.MAX_VALUE; 4195 4196 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4197 for (int i = 0; i < a.length; i += SPECIES.length()) { 4198 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 4199 r[i] = av.reduceLanes(VectorOperators.UMIN); 4200 } 4201 } 4202 4203 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4204 ra = Short.MAX_VALUE; 4205 for (int i = 0; i < a.length; i += SPECIES.length()) { 4206 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 4207 ra = (short) VectorMath.minUnsigned(ra, av.reduceLanes(VectorOperators.UMIN)); 4208 } 4209 } 4210 4211 assertReductionArraysEquals(r, ra, a, 4212 Short512VectorTests::UMINReduce, Short512VectorTests::UMINReduceAll); 4213 } 4214 4215 static short UMINReduceMasked(short[] a, int idx, boolean[] mask) { 4216 short res = Short.MAX_VALUE; 4217 for (int i = idx; i < (idx + SPECIES.length()); i++) { 4218 if (mask[i % SPECIES.length()]) 4219 res = (short) VectorMath.minUnsigned(res, a[i]); 4220 } 4221 4222 return res; 4223 } 4224 4225 static short UMINReduceAllMasked(short[] a, boolean[] mask) { 4226 short res = Short.MAX_VALUE; 4227 for (int i = 0; i < a.length; i += SPECIES.length()) { 4228 res = (short) VectorMath.minUnsigned(res, UMINReduceMasked(a, i, mask)); 4229 } 4230 4231 return res; 4232 } 4233 4234 @Test(dataProvider = "shortUnaryOpMaskProvider") 4235 static void UMINReduceShort512VectorTestsMasked(IntFunction<short[]> fa, IntFunction<boolean[]> fm) { 4236 short[] a = fa.apply(SPECIES.length()); 4237 short[] r = fr.apply(SPECIES.length()); 4238 boolean[] mask = fm.apply(SPECIES.length()); 4239 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 4240 short ra = Short.MAX_VALUE; 4241 4242 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4243 for (int i = 0; i < a.length; i += SPECIES.length()) { 4244 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 4245 r[i] = av.reduceLanes(VectorOperators.UMIN, vmask); 4246 } 4247 } 4248 4249 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4250 ra = Short.MAX_VALUE; 4251 for (int i = 0; i < a.length; i += SPECIES.length()) { 4252 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 4253 ra = (short) VectorMath.minUnsigned(ra, av.reduceLanes(VectorOperators.UMIN, vmask)); 4254 } 4255 } 4256 4257 assertReductionArraysEqualsMasked(r, ra, a, mask, 4258 Short512VectorTests::UMINReduceMasked, Short512VectorTests::UMINReduceAllMasked); 4259 } 4260 4261 static short UMAXReduce(short[] a, int idx) { 4262 short res = Short.MIN_VALUE; 4263 for (int i = idx; i < (idx + SPECIES.length()); i++) { 4264 res = (short) VectorMath.maxUnsigned(res, a[i]); 4265 } 4266 4267 return res; 4268 } 4269 4270 static short UMAXReduceAll(short[] a) { 4271 short res = Short.MIN_VALUE; 4272 for (int i = 0; i < a.length; i += SPECIES.length()) { 4273 res = (short) VectorMath.maxUnsigned(res, UMAXReduce(a, i)); 4274 } 4275 4276 return res; 4277 } 4278 4279 @Test(dataProvider = "shortUnaryOpProvider") 4280 static void UMAXReduceShort512VectorTests(IntFunction<short[]> fa) { 4281 short[] a = fa.apply(SPECIES.length()); 4282 short[] r = fr.apply(SPECIES.length()); 4283 short ra = Short.MIN_VALUE; 4284 4285 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4286 for (int i = 0; i < a.length; i += SPECIES.length()) { 4287 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 4288 r[i] = av.reduceLanes(VectorOperators.UMAX); 4289 } 4290 } 4291 4292 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4293 ra = Short.MIN_VALUE; 4294 for (int i = 0; i < a.length; i += SPECIES.length()) { 4295 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 4296 ra = (short) VectorMath.maxUnsigned(ra, av.reduceLanes(VectorOperators.UMAX)); 4297 } 4298 } 4299 4300 assertReductionArraysEquals(r, ra, a, 4301 Short512VectorTests::UMAXReduce, Short512VectorTests::UMAXReduceAll); 4302 } 4303 4304 static short UMAXReduceMasked(short[] a, int idx, boolean[] mask) { 4305 short res = Short.MIN_VALUE; 4306 for (int i = idx; i < (idx + SPECIES.length()); i++) { 4307 if (mask[i % SPECIES.length()]) 4308 res = (short) VectorMath.maxUnsigned(res, a[i]); 4309 } 4310 4311 return res; 4312 } 4313 4314 static short UMAXReduceAllMasked(short[] a, boolean[] mask) { 4315 short res = Short.MIN_VALUE; 4316 for (int i = 0; i < a.length; i += SPECIES.length()) { 4317 res = (short) VectorMath.maxUnsigned(res, UMAXReduceMasked(a, i, mask)); 4318 } 4319 4320 return res; 4321 } 4322 4323 @Test(dataProvider = "shortUnaryOpMaskProvider") 4324 static void UMAXReduceShort512VectorTestsMasked(IntFunction<short[]> fa, IntFunction<boolean[]> fm) { 4325 short[] a = fa.apply(SPECIES.length()); 4326 short[] r = fr.apply(SPECIES.length()); 4327 boolean[] mask = fm.apply(SPECIES.length()); 4328 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 4329 short ra = Short.MIN_VALUE; 4330 4331 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4332 for (int i = 0; i < a.length; i += SPECIES.length()) { 4333 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 4334 r[i] = av.reduceLanes(VectorOperators.UMAX, vmask); 4335 } 4336 } 4337 4338 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4339 ra = Short.MIN_VALUE; 4340 for (int i = 0; i < a.length; i += SPECIES.length()) { 4341 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 4342 ra = (short) VectorMath.maxUnsigned(ra, av.reduceLanes(VectorOperators.UMAX, vmask)); 4343 } 4344 } 4345 4346 assertReductionArraysEqualsMasked(r, ra, a, mask, 4347 Short512VectorTests::UMAXReduceMasked, Short512VectorTests::UMAXReduceAllMasked); 4348 } 4349 4350 static short FIRST_NONZEROReduce(short[] a, int idx) { 4351 short res = (short) 0; 4352 for (int i = idx; i < (idx + SPECIES.length()); i++) { 4353 res = firstNonZero(res, a[i]); 4354 } 4355 4356 return res; 4357 } 4358 4359 static short FIRST_NONZEROReduceAll(short[] a) { 4360 short res = (short) 0; 4361 for (int i = 0; i < a.length; i += SPECIES.length()) { 4362 res = firstNonZero(res, FIRST_NONZEROReduce(a, i)); 4363 } 4364 4365 return res; 4366 } 4367 4368 @Test(dataProvider = "shortUnaryOpProvider") 4369 static void FIRST_NONZEROReduceShort512VectorTests(IntFunction<short[]> fa) { 4370 short[] a = fa.apply(SPECIES.length()); 4371 short[] r = fr.apply(SPECIES.length()); 4372 short ra = (short) 0; 4373 4374 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4375 for (int i = 0; i < a.length; i += SPECIES.length()) { 4376 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 4377 r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO); 4378 } 4379 } 4380 4381 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4382 ra = (short) 0; 4383 for (int i = 0; i < a.length; i += SPECIES.length()) { 4384 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 4385 ra = firstNonZero(ra, av.reduceLanes(VectorOperators.FIRST_NONZERO)); 4386 } 4387 } 4388 4389 assertReductionArraysEquals(r, ra, a, 4390 Short512VectorTests::FIRST_NONZEROReduce, Short512VectorTests::FIRST_NONZEROReduceAll); 4391 } 4392 4393 static short FIRST_NONZEROReduceMasked(short[] a, int idx, boolean[] mask) { 4394 short res = (short) 0; 4395 for (int i = idx; i < (idx + SPECIES.length()); i++) { 4396 if (mask[i % SPECIES.length()]) 4397 res = firstNonZero(res, a[i]); 4398 } 4399 4400 return res; 4401 } 4402 4403 static short FIRST_NONZEROReduceAllMasked(short[] a, boolean[] mask) { 4404 short res = (short) 0; 4405 for (int i = 0; i < a.length; i += SPECIES.length()) { 4406 res = firstNonZero(res, FIRST_NONZEROReduceMasked(a, i, mask)); 4407 } 4408 4409 return res; 4410 } 4411 4412 @Test(dataProvider = "shortUnaryOpMaskProvider") 4413 static void FIRST_NONZEROReduceShort512VectorTestsMasked(IntFunction<short[]> fa, IntFunction<boolean[]> fm) { 4414 short[] a = fa.apply(SPECIES.length()); 4415 short[] r = fr.apply(SPECIES.length()); 4416 boolean[] mask = fm.apply(SPECIES.length()); 4417 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 4418 short ra = (short) 0; 4419 4420 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4421 for (int i = 0; i < a.length; i += SPECIES.length()) { 4422 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 4423 r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); 4424 } 4425 } 4426 4427 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4428 ra = (short) 0; 4429 for (int i = 0; i < a.length; i += SPECIES.length()) { 4430 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 4431 ra = firstNonZero(ra, av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask)); 4432 } 4433 } 4434 4435 assertReductionArraysEqualsMasked(r, ra, a, mask, 4436 Short512VectorTests::FIRST_NONZEROReduceMasked, Short512VectorTests::FIRST_NONZEROReduceAllMasked); 4437 } 4438 4439 static boolean anyTrue(boolean[] a, int idx) { 4440 boolean res = false; 4441 for (int i = idx; i < (idx + SPECIES.length()); i++) { 4442 res |= a[i]; 4443 } 4444 4445 return res; 4446 } 4447 4448 @Test(dataProvider = "boolUnaryOpProvider") 4449 static void anyTrueShort512VectorTests(IntFunction<boolean[]> fm) { 4450 boolean[] mask = fm.apply(SPECIES.length()); 4451 boolean[] r = fmr.apply(SPECIES.length()); 4452 4453 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4454 for (int i = 0; i < mask.length; i += SPECIES.length()) { 4455 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, i); 4456 r[i] = vmask.anyTrue(); 4457 } 4458 } 4459 4460 assertReductionBoolArraysEquals(r, mask, Short512VectorTests::anyTrue); 4461 } 4462 4463 static boolean allTrue(boolean[] a, int idx) { 4464 boolean res = true; 4465 for (int i = idx; i < (idx + SPECIES.length()); i++) { 4466 res &= a[i]; 4467 } 4468 4469 return res; 4470 } 4471 4472 @Test(dataProvider = "boolUnaryOpProvider") 4473 static void allTrueShort512VectorTests(IntFunction<boolean[]> fm) { 4474 boolean[] mask = fm.apply(SPECIES.length()); 4475 boolean[] r = fmr.apply(SPECIES.length()); 4476 4477 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4478 for (int i = 0; i < mask.length; i += SPECIES.length()) { 4479 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, i); 4480 r[i] = vmask.allTrue(); 4481 } 4482 } 4483 4484 assertReductionBoolArraysEquals(r, mask, Short512VectorTests::allTrue); 4485 } 4486 4487 static short SUADDReduce(short[] a, int idx) { 4488 short res = 0; 4489 for (int i = idx; i < (idx + SPECIES.length()); i++) { 4490 res = (short) VectorMath.addSaturatingUnsigned(res, a[i]); 4491 } 4492 4493 return res; 4494 } 4495 4496 static short SUADDReduceAll(short[] a) { 4497 short res = 0; 4498 for (int i = 0; i < a.length; i += SPECIES.length()) { 4499 res = (short) VectorMath.addSaturatingUnsigned(res, SUADDReduce(a, i)); 4500 } 4501 4502 return res; 4503 } 4504 4505 @Test(dataProvider = "shortSaturatingUnaryOpProvider") 4506 static void SUADDReduceShort512VectorTests(IntFunction<short[]> fa) { 4507 short[] a = fa.apply(SPECIES.length()); 4508 short[] r = fr.apply(SPECIES.length()); 4509 short ra = 0; 4510 4511 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4512 for (int i = 0; i < a.length; i += SPECIES.length()) { 4513 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 4514 r[i] = av.reduceLanes(VectorOperators.SUADD); 4515 } 4516 } 4517 4518 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4519 ra = 0; 4520 for (int i = 0; i < a.length; i += SPECIES.length()) { 4521 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 4522 ra = (short) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD)); 4523 } 4524 } 4525 4526 assertReductionArraysEquals(r, ra, a, 4527 Short512VectorTests::SUADDReduce, Short512VectorTests::SUADDReduceAll); 4528 } 4529 4530 static short SUADDReduceMasked(short[] a, int idx, boolean[] mask) { 4531 short res = 0; 4532 for (int i = idx; i < (idx + SPECIES.length()); i++) { 4533 if (mask[i % SPECIES.length()]) 4534 res = (short) VectorMath.addSaturatingUnsigned(res, a[i]); 4535 } 4536 4537 return res; 4538 } 4539 4540 static short SUADDReduceAllMasked(short[] a, boolean[] mask) { 4541 short res = 0; 4542 for (int i = 0; i < a.length; i += SPECIES.length()) { 4543 res = (short) VectorMath.addSaturatingUnsigned(res, SUADDReduceMasked(a, i, mask)); 4544 } 4545 4546 return res; 4547 } 4548 @Test(dataProvider = "shortSaturatingUnaryOpMaskProvider") 4549 static void SUADDReduceShort512VectorTestsMasked(IntFunction<short[]> fa, IntFunction<boolean[]> fm) { 4550 short[] a = fa.apply(SPECIES.length()); 4551 short[] r = fr.apply(SPECIES.length()); 4552 boolean[] mask = fm.apply(SPECIES.length()); 4553 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 4554 short ra = 0; 4555 4556 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4557 for (int i = 0; i < a.length; i += SPECIES.length()) { 4558 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 4559 r[i] = av.reduceLanes(VectorOperators.SUADD, vmask); 4560 } 4561 } 4562 4563 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4564 ra = 0; 4565 for (int i = 0; i < a.length; i += SPECIES.length()) { 4566 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 4567 ra = (short) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD, vmask)); 4568 } 4569 } 4570 4571 assertReductionArraysEqualsMasked(r, ra, a, mask, 4572 Short512VectorTests::SUADDReduceMasked, Short512VectorTests::SUADDReduceAllMasked); 4573 } 4574 4575 @Test(dataProvider = "shortBinaryOpProvider") 4576 static void withShort512VectorTests(IntFunction<short []> fa, IntFunction<short []> fb) { 4577 short[] a = fa.apply(SPECIES.length()); 4578 short[] b = fb.apply(SPECIES.length()); 4579 short[] r = fr.apply(SPECIES.length()); 4580 4581 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4582 for (int i = 0, j = 0; i < a.length; i += SPECIES.length()) { 4583 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 4584 av.withLane(j, b[i + j]).intoArray(r, i); 4585 a[i + j] = b[i + j]; 4586 j = (j + 1) & (SPECIES.length() - 1); 4587 } 4588 } 4589 4590 4591 assertArraysStrictlyEquals(r, a); 4592 } 4593 4594 static boolean testIS_DEFAULT(short a) { 4595 return bits(a)==0; 4596 } 4597 4598 @Test(dataProvider = "shortTestOpProvider") 4599 static void IS_DEFAULTShort512VectorTests(IntFunction<short[]> fa) { 4600 short[] a = fa.apply(SPECIES.length()); 4601 4602 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4603 for (int i = 0; i < a.length; i += SPECIES.length()) { 4604 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 4605 VectorMask<Short> mv = av.test(VectorOperators.IS_DEFAULT); 4606 4607 // Check results as part of computation. 4608 for (int j = 0; j < SPECIES.length(); j++) { 4609 Assert.assertEquals(mv.laneIsSet(j), testIS_DEFAULT(a[i + j])); 4610 } 4611 } 4612 } 4613 } 4614 4615 @Test(dataProvider = "shortTestOpMaskProvider") 4616 static void IS_DEFAULTMaskedShort512VectorTests(IntFunction<short[]> fa, 4617 IntFunction<boolean[]> fm) { 4618 short[] a = fa.apply(SPECIES.length()); 4619 boolean[] mask = fm.apply(SPECIES.length()); 4620 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 4621 4622 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4623 for (int i = 0; i < a.length; i += SPECIES.length()) { 4624 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 4625 VectorMask<Short> mv = av.test(VectorOperators.IS_DEFAULT, vmask); 4626 4627 // Check results as part of computation. 4628 for (int j = 0; j < SPECIES.length(); j++) { 4629 Assert.assertEquals(mv.laneIsSet(j), vmask.laneIsSet(j) && testIS_DEFAULT(a[i + j])); 4630 } 4631 } 4632 } 4633 } 4634 4635 static boolean testIS_NEGATIVE(short a) { 4636 return bits(a)<0; 4637 } 4638 4639 @Test(dataProvider = "shortTestOpProvider") 4640 static void IS_NEGATIVEShort512VectorTests(IntFunction<short[]> fa) { 4641 short[] a = fa.apply(SPECIES.length()); 4642 4643 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4644 for (int i = 0; i < a.length; i += SPECIES.length()) { 4645 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 4646 VectorMask<Short> mv = av.test(VectorOperators.IS_NEGATIVE); 4647 4648 // Check results as part of computation. 4649 for (int j = 0; j < SPECIES.length(); j++) { 4650 Assert.assertEquals(mv.laneIsSet(j), testIS_NEGATIVE(a[i + j])); 4651 } 4652 } 4653 } 4654 } 4655 4656 @Test(dataProvider = "shortTestOpMaskProvider") 4657 static void IS_NEGATIVEMaskedShort512VectorTests(IntFunction<short[]> fa, 4658 IntFunction<boolean[]> fm) { 4659 short[] a = fa.apply(SPECIES.length()); 4660 boolean[] mask = fm.apply(SPECIES.length()); 4661 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 4662 4663 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4664 for (int i = 0; i < a.length; i += SPECIES.length()) { 4665 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 4666 VectorMask<Short> mv = av.test(VectorOperators.IS_NEGATIVE, vmask); 4667 4668 // Check results as part of computation. 4669 for (int j = 0; j < SPECIES.length(); j++) { 4670 Assert.assertEquals(mv.laneIsSet(j), vmask.laneIsSet(j) && testIS_NEGATIVE(a[i + j])); 4671 } 4672 } 4673 } 4674 } 4675 4676 @Test(dataProvider = "shortCompareOpProvider") 4677 static void LTShort512VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { 4678 short[] a = fa.apply(SPECIES.length()); 4679 short[] b = fb.apply(SPECIES.length()); 4680 4681 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4682 for (int i = 0; i < a.length; i += SPECIES.length()) { 4683 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 4684 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 4685 VectorMask<Short> mv = av.compare(VectorOperators.LT, bv); 4686 4687 // Check results as part of computation. 4688 for (int j = 0; j < SPECIES.length(); j++) { 4689 Assert.assertEquals(mv.laneIsSet(j), lt(a[i + j], b[i + j])); 4690 } 4691 } 4692 } 4693 } 4694 4695 @Test(dataProvider = "shortCompareOpProvider") 4696 static void ltShort512VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { 4697 short[] a = fa.apply(SPECIES.length()); 4698 short[] b = fb.apply(SPECIES.length()); 4699 4700 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4701 for (int i = 0; i < a.length; i += SPECIES.length()) { 4702 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 4703 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 4704 VectorMask<Short> mv = av.lt(bv); 4705 4706 // Check results as part of computation. 4707 for (int j = 0; j < SPECIES.length(); j++) { 4708 Assert.assertEquals(mv.laneIsSet(j), lt(a[i + j], b[i + j])); 4709 } 4710 } 4711 } 4712 } 4713 4714 @Test(dataProvider = "shortCompareOpMaskProvider") 4715 static void LTShort512VectorTestsMasked(IntFunction<short[]> fa, IntFunction<short[]> fb, 4716 IntFunction<boolean[]> fm) { 4717 short[] a = fa.apply(SPECIES.length()); 4718 short[] b = fb.apply(SPECIES.length()); 4719 boolean[] mask = fm.apply(SPECIES.length()); 4720 4721 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 4722 4723 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4724 for (int i = 0; i < a.length; i += SPECIES.length()) { 4725 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 4726 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 4727 VectorMask<Short> mv = av.compare(VectorOperators.LT, bv, vmask); 4728 4729 // Check results as part of computation. 4730 for (int j = 0; j < SPECIES.length(); j++) { 4731 Assert.assertEquals(mv.laneIsSet(j), mask[j] && lt(a[i + j], b[i + j])); 4732 } 4733 } 4734 } 4735 } 4736 4737 @Test(dataProvider = "shortCompareOpProvider") 4738 static void GTShort512VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { 4739 short[] a = fa.apply(SPECIES.length()); 4740 short[] b = fb.apply(SPECIES.length()); 4741 4742 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4743 for (int i = 0; i < a.length; i += SPECIES.length()) { 4744 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 4745 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 4746 VectorMask<Short> mv = av.compare(VectorOperators.GT, bv); 4747 4748 // Check results as part of computation. 4749 for (int j = 0; j < SPECIES.length(); j++) { 4750 Assert.assertEquals(mv.laneIsSet(j), gt(a[i + j], b[i + j])); 4751 } 4752 } 4753 } 4754 } 4755 4756 @Test(dataProvider = "shortCompareOpMaskProvider") 4757 static void GTShort512VectorTestsMasked(IntFunction<short[]> fa, IntFunction<short[]> fb, 4758 IntFunction<boolean[]> fm) { 4759 short[] a = fa.apply(SPECIES.length()); 4760 short[] b = fb.apply(SPECIES.length()); 4761 boolean[] mask = fm.apply(SPECIES.length()); 4762 4763 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 4764 4765 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4766 for (int i = 0; i < a.length; i += SPECIES.length()) { 4767 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 4768 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 4769 VectorMask<Short> mv = av.compare(VectorOperators.GT, bv, vmask); 4770 4771 // Check results as part of computation. 4772 for (int j = 0; j < SPECIES.length(); j++) { 4773 Assert.assertEquals(mv.laneIsSet(j), mask[j] && gt(a[i + j], b[i + j])); 4774 } 4775 } 4776 } 4777 } 4778 4779 @Test(dataProvider = "shortCompareOpProvider") 4780 static void EQShort512VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { 4781 short[] a = fa.apply(SPECIES.length()); 4782 short[] b = fb.apply(SPECIES.length()); 4783 4784 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4785 for (int i = 0; i < a.length; i += SPECIES.length()) { 4786 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 4787 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 4788 VectorMask<Short> mv = av.compare(VectorOperators.EQ, bv); 4789 4790 // Check results as part of computation. 4791 for (int j = 0; j < SPECIES.length(); j++) { 4792 Assert.assertEquals(mv.laneIsSet(j), eq(a[i + j], b[i + j])); 4793 } 4794 } 4795 } 4796 } 4797 4798 @Test(dataProvider = "shortCompareOpProvider") 4799 static void eqShort512VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { 4800 short[] a = fa.apply(SPECIES.length()); 4801 short[] b = fb.apply(SPECIES.length()); 4802 4803 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4804 for (int i = 0; i < a.length; i += SPECIES.length()) { 4805 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 4806 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 4807 VectorMask<Short> mv = av.eq(bv); 4808 4809 // Check results as part of computation. 4810 for (int j = 0; j < SPECIES.length(); j++) { 4811 Assert.assertEquals(mv.laneIsSet(j), eq(a[i + j], b[i + j])); 4812 } 4813 } 4814 } 4815 } 4816 4817 @Test(dataProvider = "shortCompareOpMaskProvider") 4818 static void EQShort512VectorTestsMasked(IntFunction<short[]> fa, IntFunction<short[]> fb, 4819 IntFunction<boolean[]> fm) { 4820 short[] a = fa.apply(SPECIES.length()); 4821 short[] b = fb.apply(SPECIES.length()); 4822 boolean[] mask = fm.apply(SPECIES.length()); 4823 4824 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 4825 4826 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4827 for (int i = 0; i < a.length; i += SPECIES.length()) { 4828 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 4829 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 4830 VectorMask<Short> mv = av.compare(VectorOperators.EQ, bv, vmask); 4831 4832 // Check results as part of computation. 4833 for (int j = 0; j < SPECIES.length(); j++) { 4834 Assert.assertEquals(mv.laneIsSet(j), mask[j] && eq(a[i + j], b[i + j])); 4835 } 4836 } 4837 } 4838 } 4839 4840 @Test(dataProvider = "shortCompareOpProvider") 4841 static void NEShort512VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { 4842 short[] a = fa.apply(SPECIES.length()); 4843 short[] b = fb.apply(SPECIES.length()); 4844 4845 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4846 for (int i = 0; i < a.length; i += SPECIES.length()) { 4847 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 4848 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 4849 VectorMask<Short> mv = av.compare(VectorOperators.NE, bv); 4850 4851 // Check results as part of computation. 4852 for (int j = 0; j < SPECIES.length(); j++) { 4853 Assert.assertEquals(mv.laneIsSet(j), neq(a[i + j], b[i + j])); 4854 } 4855 } 4856 } 4857 } 4858 4859 @Test(dataProvider = "shortCompareOpMaskProvider") 4860 static void NEShort512VectorTestsMasked(IntFunction<short[]> fa, IntFunction<short[]> fb, 4861 IntFunction<boolean[]> fm) { 4862 short[] a = fa.apply(SPECIES.length()); 4863 short[] b = fb.apply(SPECIES.length()); 4864 boolean[] mask = fm.apply(SPECIES.length()); 4865 4866 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 4867 4868 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4869 for (int i = 0; i < a.length; i += SPECIES.length()) { 4870 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 4871 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 4872 VectorMask<Short> mv = av.compare(VectorOperators.NE, bv, vmask); 4873 4874 // Check results as part of computation. 4875 for (int j = 0; j < SPECIES.length(); j++) { 4876 Assert.assertEquals(mv.laneIsSet(j), mask[j] && neq(a[i + j], b[i + j])); 4877 } 4878 } 4879 } 4880 } 4881 4882 @Test(dataProvider = "shortCompareOpProvider") 4883 static void LEShort512VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { 4884 short[] a = fa.apply(SPECIES.length()); 4885 short[] b = fb.apply(SPECIES.length()); 4886 4887 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4888 for (int i = 0; i < a.length; i += SPECIES.length()) { 4889 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 4890 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 4891 VectorMask<Short> mv = av.compare(VectorOperators.LE, bv); 4892 4893 // Check results as part of computation. 4894 for (int j = 0; j < SPECIES.length(); j++) { 4895 Assert.assertEquals(mv.laneIsSet(j), le(a[i + j], b[i + j])); 4896 } 4897 } 4898 } 4899 } 4900 4901 @Test(dataProvider = "shortCompareOpMaskProvider") 4902 static void LEShort512VectorTestsMasked(IntFunction<short[]> fa, IntFunction<short[]> fb, 4903 IntFunction<boolean[]> fm) { 4904 short[] a = fa.apply(SPECIES.length()); 4905 short[] b = fb.apply(SPECIES.length()); 4906 boolean[] mask = fm.apply(SPECIES.length()); 4907 4908 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 4909 4910 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4911 for (int i = 0; i < a.length; i += SPECIES.length()) { 4912 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 4913 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 4914 VectorMask<Short> mv = av.compare(VectorOperators.LE, bv, vmask); 4915 4916 // Check results as part of computation. 4917 for (int j = 0; j < SPECIES.length(); j++) { 4918 Assert.assertEquals(mv.laneIsSet(j), mask[j] && le(a[i + j], b[i + j])); 4919 } 4920 } 4921 } 4922 } 4923 4924 @Test(dataProvider = "shortCompareOpProvider") 4925 static void GEShort512VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { 4926 short[] a = fa.apply(SPECIES.length()); 4927 short[] b = fb.apply(SPECIES.length()); 4928 4929 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4930 for (int i = 0; i < a.length; i += SPECIES.length()) { 4931 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 4932 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 4933 VectorMask<Short> mv = av.compare(VectorOperators.GE, bv); 4934 4935 // Check results as part of computation. 4936 for (int j = 0; j < SPECIES.length(); j++) { 4937 Assert.assertEquals(mv.laneIsSet(j), ge(a[i + j], b[i + j])); 4938 } 4939 } 4940 } 4941 } 4942 4943 @Test(dataProvider = "shortCompareOpMaskProvider") 4944 static void GEShort512VectorTestsMasked(IntFunction<short[]> fa, IntFunction<short[]> fb, 4945 IntFunction<boolean[]> fm) { 4946 short[] a = fa.apply(SPECIES.length()); 4947 short[] b = fb.apply(SPECIES.length()); 4948 boolean[] mask = fm.apply(SPECIES.length()); 4949 4950 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 4951 4952 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4953 for (int i = 0; i < a.length; i += SPECIES.length()) { 4954 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 4955 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 4956 VectorMask<Short> mv = av.compare(VectorOperators.GE, bv, vmask); 4957 4958 // Check results as part of computation. 4959 for (int j = 0; j < SPECIES.length(); j++) { 4960 Assert.assertEquals(mv.laneIsSet(j), mask[j] && ge(a[i + j], b[i + j])); 4961 } 4962 } 4963 } 4964 } 4965 4966 @Test(dataProvider = "shortCompareOpProvider") 4967 static void ULTShort512VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { 4968 short[] a = fa.apply(SPECIES.length()); 4969 short[] b = fb.apply(SPECIES.length()); 4970 4971 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4972 for (int i = 0; i < a.length; i += SPECIES.length()) { 4973 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 4974 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 4975 VectorMask<Short> mv = av.compare(VectorOperators.ULT, bv); 4976 4977 // Check results as part of computation. 4978 for (int j = 0; j < SPECIES.length(); j++) { 4979 Assert.assertEquals(mv.laneIsSet(j), ult(a[i + j], b[i + j])); 4980 } 4981 } 4982 } 4983 } 4984 4985 @Test(dataProvider = "shortCompareOpMaskProvider") 4986 static void ULTShort512VectorTestsMasked(IntFunction<short[]> fa, IntFunction<short[]> fb, 4987 IntFunction<boolean[]> fm) { 4988 short[] a = fa.apply(SPECIES.length()); 4989 short[] b = fb.apply(SPECIES.length()); 4990 boolean[] mask = fm.apply(SPECIES.length()); 4991 4992 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 4993 4994 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4995 for (int i = 0; i < a.length; i += SPECIES.length()) { 4996 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 4997 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 4998 VectorMask<Short> mv = av.compare(VectorOperators.ULT, bv, vmask); 4999 5000 // Check results as part of computation. 5001 for (int j = 0; j < SPECIES.length(); j++) { 5002 Assert.assertEquals(mv.laneIsSet(j), mask[j] && ult(a[i + j], b[i + j])); 5003 } 5004 } 5005 } 5006 } 5007 5008 @Test(dataProvider = "shortCompareOpProvider") 5009 static void UGTShort512VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { 5010 short[] a = fa.apply(SPECIES.length()); 5011 short[] b = fb.apply(SPECIES.length()); 5012 5013 for (int ic = 0; ic < INVOC_COUNT; ic++) { 5014 for (int i = 0; i < a.length; i += SPECIES.length()) { 5015 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 5016 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 5017 VectorMask<Short> mv = av.compare(VectorOperators.UGT, bv); 5018 5019 // Check results as part of computation. 5020 for (int j = 0; j < SPECIES.length(); j++) { 5021 Assert.assertEquals(mv.laneIsSet(j), ugt(a[i + j], b[i + j])); 5022 } 5023 } 5024 } 5025 } 5026 5027 @Test(dataProvider = "shortCompareOpMaskProvider") 5028 static void UGTShort512VectorTestsMasked(IntFunction<short[]> fa, IntFunction<short[]> fb, 5029 IntFunction<boolean[]> fm) { 5030 short[] a = fa.apply(SPECIES.length()); 5031 short[] b = fb.apply(SPECIES.length()); 5032 boolean[] mask = fm.apply(SPECIES.length()); 5033 5034 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 5035 5036 for (int ic = 0; ic < INVOC_COUNT; ic++) { 5037 for (int i = 0; i < a.length; i += SPECIES.length()) { 5038 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 5039 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 5040 VectorMask<Short> mv = av.compare(VectorOperators.UGT, bv, vmask); 5041 5042 // Check results as part of computation. 5043 for (int j = 0; j < SPECIES.length(); j++) { 5044 Assert.assertEquals(mv.laneIsSet(j), mask[j] && ugt(a[i + j], b[i + j])); 5045 } 5046 } 5047 } 5048 } 5049 5050 @Test(dataProvider = "shortCompareOpProvider") 5051 static void ULEShort512VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { 5052 short[] a = fa.apply(SPECIES.length()); 5053 short[] b = fb.apply(SPECIES.length()); 5054 5055 for (int ic = 0; ic < INVOC_COUNT; ic++) { 5056 for (int i = 0; i < a.length; i += SPECIES.length()) { 5057 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 5058 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 5059 VectorMask<Short> mv = av.compare(VectorOperators.ULE, bv); 5060 5061 // Check results as part of computation. 5062 for (int j = 0; j < SPECIES.length(); j++) { 5063 Assert.assertEquals(mv.laneIsSet(j), ule(a[i + j], b[i + j])); 5064 } 5065 } 5066 } 5067 } 5068 5069 @Test(dataProvider = "shortCompareOpMaskProvider") 5070 static void ULEShort512VectorTestsMasked(IntFunction<short[]> fa, IntFunction<short[]> fb, 5071 IntFunction<boolean[]> fm) { 5072 short[] a = fa.apply(SPECIES.length()); 5073 short[] b = fb.apply(SPECIES.length()); 5074 boolean[] mask = fm.apply(SPECIES.length()); 5075 5076 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 5077 5078 for (int ic = 0; ic < INVOC_COUNT; ic++) { 5079 for (int i = 0; i < a.length; i += SPECIES.length()) { 5080 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 5081 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 5082 VectorMask<Short> mv = av.compare(VectorOperators.ULE, bv, vmask); 5083 5084 // Check results as part of computation. 5085 for (int j = 0; j < SPECIES.length(); j++) { 5086 Assert.assertEquals(mv.laneIsSet(j), mask[j] && ule(a[i + j], b[i + j])); 5087 } 5088 } 5089 } 5090 } 5091 5092 @Test(dataProvider = "shortCompareOpProvider") 5093 static void UGEShort512VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb) { 5094 short[] a = fa.apply(SPECIES.length()); 5095 short[] b = fb.apply(SPECIES.length()); 5096 5097 for (int ic = 0; ic < INVOC_COUNT; ic++) { 5098 for (int i = 0; i < a.length; i += SPECIES.length()) { 5099 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 5100 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 5101 VectorMask<Short> mv = av.compare(VectorOperators.UGE, bv); 5102 5103 // Check results as part of computation. 5104 for (int j = 0; j < SPECIES.length(); j++) { 5105 Assert.assertEquals(mv.laneIsSet(j), uge(a[i + j], b[i + j])); 5106 } 5107 } 5108 } 5109 } 5110 5111 @Test(dataProvider = "shortCompareOpMaskProvider") 5112 static void UGEShort512VectorTestsMasked(IntFunction<short[]> fa, IntFunction<short[]> fb, 5113 IntFunction<boolean[]> fm) { 5114 short[] a = fa.apply(SPECIES.length()); 5115 short[] b = fb.apply(SPECIES.length()); 5116 boolean[] mask = fm.apply(SPECIES.length()); 5117 5118 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 5119 5120 for (int ic = 0; ic < INVOC_COUNT; ic++) { 5121 for (int i = 0; i < a.length; i += SPECIES.length()) { 5122 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 5123 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 5124 VectorMask<Short> mv = av.compare(VectorOperators.UGE, bv, vmask); 5125 5126 // Check results as part of computation. 5127 for (int j = 0; j < SPECIES.length(); j++) { 5128 Assert.assertEquals(mv.laneIsSet(j), mask[j] && uge(a[i + j], b[i + j])); 5129 } 5130 } 5131 } 5132 } 5133 5134 @Test(dataProvider = "shortCompareOpProvider") 5135 static void LTShort512VectorTestsBroadcastSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb) { 5136 short[] a = fa.apply(SPECIES.length()); 5137 short[] b = fb.apply(SPECIES.length()); 5138 5139 for (int i = 0; i < a.length; i += SPECIES.length()) { 5140 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 5141 VectorMask<Short> mv = av.compare(VectorOperators.LT, b[i]); 5142 5143 // Check results as part of computation. 5144 for (int j = 0; j < SPECIES.length(); j++) { 5145 Assert.assertEquals(mv.laneIsSet(j), a[i + j] < b[i]); 5146 } 5147 } 5148 } 5149 5150 @Test(dataProvider = "shortCompareOpMaskProvider") 5151 static void LTShort512VectorTestsBroadcastMaskedSmokeTest(IntFunction<short[]> fa, 5152 IntFunction<short[]> fb, IntFunction<boolean[]> fm) { 5153 short[] a = fa.apply(SPECIES.length()); 5154 short[] b = fb.apply(SPECIES.length()); 5155 boolean[] mask = fm.apply(SPECIES.length()); 5156 5157 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 5158 5159 for (int i = 0; i < a.length; i += SPECIES.length()) { 5160 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 5161 VectorMask<Short> mv = av.compare(VectorOperators.LT, b[i], vmask); 5162 5163 // Check results as part of computation. 5164 for (int j = 0; j < SPECIES.length(); j++) { 5165 Assert.assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] < b[i])); 5166 } 5167 } 5168 } 5169 5170 @Test(dataProvider = "shortCompareOpProvider") 5171 static void LTShort512VectorTestsBroadcastLongSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb) { 5172 short[] a = fa.apply(SPECIES.length()); 5173 short[] b = fb.apply(SPECIES.length()); 5174 5175 for (int i = 0; i < a.length; i += SPECIES.length()) { 5176 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 5177 VectorMask<Short> mv = av.compare(VectorOperators.LT, (long)b[i]); 5178 5179 // Check results as part of computation. 5180 for (int j = 0; j < SPECIES.length(); j++) { 5181 Assert.assertEquals(mv.laneIsSet(j), a[i + j] < (short)((long)b[i])); 5182 } 5183 } 5184 } 5185 5186 @Test(dataProvider = "shortCompareOpMaskProvider") 5187 static void LTShort512VectorTestsBroadcastLongMaskedSmokeTest(IntFunction<short[]> fa, 5188 IntFunction<short[]> fb, IntFunction<boolean[]> fm) { 5189 short[] a = fa.apply(SPECIES.length()); 5190 short[] b = fb.apply(SPECIES.length()); 5191 boolean[] mask = fm.apply(SPECIES.length()); 5192 5193 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 5194 5195 for (int i = 0; i < a.length; i += SPECIES.length()) { 5196 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 5197 VectorMask<Short> mv = av.compare(VectorOperators.LT, (long)b[i], vmask); 5198 5199 // Check results as part of computation. 5200 for (int j = 0; j < SPECIES.length(); j++) { 5201 Assert.assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] < (short)((long)b[i]))); 5202 } 5203 } 5204 } 5205 5206 @Test(dataProvider = "shortCompareOpProvider") 5207 static void EQShort512VectorTestsBroadcastSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb) { 5208 short[] a = fa.apply(SPECIES.length()); 5209 short[] b = fb.apply(SPECIES.length()); 5210 5211 for (int i = 0; i < a.length; i += SPECIES.length()) { 5212 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 5213 VectorMask<Short> mv = av.compare(VectorOperators.EQ, b[i]); 5214 5215 // Check results as part of computation. 5216 for (int j = 0; j < SPECIES.length(); j++) { 5217 Assert.assertEquals(mv.laneIsSet(j), a[i + j] == b[i]); 5218 } 5219 } 5220 } 5221 5222 @Test(dataProvider = "shortCompareOpMaskProvider") 5223 static void EQShort512VectorTestsBroadcastMaskedSmokeTest(IntFunction<short[]> fa, 5224 IntFunction<short[]> fb, IntFunction<boolean[]> fm) { 5225 short[] a = fa.apply(SPECIES.length()); 5226 short[] b = fb.apply(SPECIES.length()); 5227 boolean[] mask = fm.apply(SPECIES.length()); 5228 5229 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 5230 5231 for (int i = 0; i < a.length; i += SPECIES.length()) { 5232 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 5233 VectorMask<Short> mv = av.compare(VectorOperators.EQ, b[i], vmask); 5234 5235 // Check results as part of computation. 5236 for (int j = 0; j < SPECIES.length(); j++) { 5237 Assert.assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] == b[i])); 5238 } 5239 } 5240 } 5241 5242 @Test(dataProvider = "shortCompareOpProvider") 5243 static void EQShort512VectorTestsBroadcastLongSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb) { 5244 short[] a = fa.apply(SPECIES.length()); 5245 short[] b = fb.apply(SPECIES.length()); 5246 5247 for (int i = 0; i < a.length; i += SPECIES.length()) { 5248 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 5249 VectorMask<Short> mv = av.compare(VectorOperators.EQ, (long)b[i]); 5250 5251 // Check results as part of computation. 5252 for (int j = 0; j < SPECIES.length(); j++) { 5253 Assert.assertEquals(mv.laneIsSet(j), a[i + j] == (short)((long)b[i])); 5254 } 5255 } 5256 } 5257 5258 @Test(dataProvider = "shortCompareOpMaskProvider") 5259 static void EQShort512VectorTestsBroadcastLongMaskedSmokeTest(IntFunction<short[]> fa, 5260 IntFunction<short[]> fb, IntFunction<boolean[]> fm) { 5261 short[] a = fa.apply(SPECIES.length()); 5262 short[] b = fb.apply(SPECIES.length()); 5263 boolean[] mask = fm.apply(SPECIES.length()); 5264 5265 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 5266 5267 for (int i = 0; i < a.length; i += SPECIES.length()) { 5268 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 5269 VectorMask<Short> mv = av.compare(VectorOperators.EQ, (long)b[i], vmask); 5270 5271 // Check results as part of computation. 5272 for (int j = 0; j < SPECIES.length(); j++) { 5273 Assert.assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] == (short)((long)b[i]))); 5274 } 5275 } 5276 } 5277 5278 static short blend(short a, short b, boolean mask) { 5279 return mask ? b : a; 5280 } 5281 5282 @Test(dataProvider = "shortBinaryOpMaskProvider") 5283 static void blendShort512VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb, 5284 IntFunction<boolean[]> fm) { 5285 short[] a = fa.apply(SPECIES.length()); 5286 short[] b = fb.apply(SPECIES.length()); 5287 short[] r = fr.apply(SPECIES.length()); 5288 boolean[] mask = fm.apply(SPECIES.length()); 5289 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 5290 5291 for (int ic = 0; ic < INVOC_COUNT; ic++) { 5292 for (int i = 0; i < a.length; i += SPECIES.length()) { 5293 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 5294 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 5295 av.blend(bv, vmask).intoArray(r, i); 5296 } 5297 } 5298 5299 assertArraysEquals(r, a, b, mask, Short512VectorTests::blend); 5300 } 5301 5302 @Test(dataProvider = "shortUnaryOpShuffleProvider") 5303 static void RearrangeShort512VectorTests(IntFunction<short[]> fa, 5304 BiFunction<Integer,Integer,int[]> fs) { 5305 short[] a = fa.apply(SPECIES.length()); 5306 int[] order = fs.apply(a.length, SPECIES.length()); 5307 short[] r = fr.apply(SPECIES.length()); 5308 5309 for (int ic = 0; ic < INVOC_COUNT; ic++) { 5310 for (int i = 0; i < a.length; i += SPECIES.length()) { 5311 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 5312 av.rearrange(VectorShuffle.fromArray(SPECIES, order, i)).intoArray(r, i); 5313 } 5314 } 5315 5316 assertRearrangeArraysEquals(r, a, order, SPECIES.length()); 5317 } 5318 5319 @Test(dataProvider = "shortUnaryOpShuffleMaskProvider") 5320 static void RearrangeShort512VectorTestsMaskedSmokeTest(IntFunction<short[]> fa, 5321 BiFunction<Integer,Integer,int[]> fs, 5322 IntFunction<boolean[]> fm) { 5323 short[] a = fa.apply(SPECIES.length()); 5324 int[] order = fs.apply(a.length, SPECIES.length()); 5325 short[] r = fr.apply(SPECIES.length()); 5326 boolean[] mask = fm.apply(SPECIES.length()); 5327 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 5328 5329 for (int i = 0; i < a.length; i += SPECIES.length()) { 5330 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 5331 av.rearrange(VectorShuffle.fromArray(SPECIES, order, i), vmask).intoArray(r, i); 5332 } 5333 5334 assertRearrangeArraysEquals(r, a, order, mask, SPECIES.length()); 5335 } 5336 5337 @Test(dataProvider = "shortUnaryOpMaskProvider") 5338 static void compressShort512VectorTests(IntFunction<short[]> fa, 5339 IntFunction<boolean[]> fm) { 5340 short[] a = fa.apply(SPECIES.length()); 5341 short[] r = fr.apply(SPECIES.length()); 5342 boolean[] mask = fm.apply(SPECIES.length()); 5343 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 5344 5345 for (int ic = 0; ic < INVOC_COUNT; ic++) { 5346 for (int i = 0; i < a.length; i += SPECIES.length()) { 5347 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 5348 av.compress(vmask).intoArray(r, i); 5349 } 5350 } 5351 5352 assertcompressArraysEquals(r, a, mask, SPECIES.length()); 5353 } 5354 5355 @Test(dataProvider = "shortUnaryOpMaskProvider") 5356 static void expandShort512VectorTests(IntFunction<short[]> fa, 5357 IntFunction<boolean[]> fm) { 5358 short[] a = fa.apply(SPECIES.length()); 5359 short[] r = fr.apply(SPECIES.length()); 5360 boolean[] mask = fm.apply(SPECIES.length()); 5361 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 5362 5363 for (int ic = 0; ic < INVOC_COUNT; ic++) { 5364 for (int i = 0; i < a.length; i += SPECIES.length()) { 5365 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 5366 av.expand(vmask).intoArray(r, i); 5367 } 5368 } 5369 5370 assertexpandArraysEquals(r, a, mask, SPECIES.length()); 5371 } 5372 5373 @Test(dataProvider = "shortUnaryOpProvider") 5374 static void getShort512VectorTests(IntFunction<short[]> fa) { 5375 short[] a = fa.apply(SPECIES.length()); 5376 short[] r = fr.apply(SPECIES.length()); 5377 5378 for (int ic = 0; ic < INVOC_COUNT; ic++) { 5379 for (int i = 0; i < a.length; i += SPECIES.length()) { 5380 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 5381 int num_lanes = SPECIES.length(); 5382 // Manually unroll because full unroll happens after intrinsification. 5383 // Unroll is needed because get intrinsic requires for index to be a known constant. 5384 if (num_lanes == 1) { 5385 r[i]=av.lane(0); 5386 } else if (num_lanes == 2) { 5387 r[i]=av.lane(0); 5388 r[i+1]=av.lane(1); 5389 } else if (num_lanes == 4) { 5390 r[i]=av.lane(0); 5391 r[i+1]=av.lane(1); 5392 r[i+2]=av.lane(2); 5393 r[i+3]=av.lane(3); 5394 } else if (num_lanes == 8) { 5395 r[i]=av.lane(0); 5396 r[i+1]=av.lane(1); 5397 r[i+2]=av.lane(2); 5398 r[i+3]=av.lane(3); 5399 r[i+4]=av.lane(4); 5400 r[i+5]=av.lane(5); 5401 r[i+6]=av.lane(6); 5402 r[i+7]=av.lane(7); 5403 } else if (num_lanes == 16) { 5404 r[i]=av.lane(0); 5405 r[i+1]=av.lane(1); 5406 r[i+2]=av.lane(2); 5407 r[i+3]=av.lane(3); 5408 r[i+4]=av.lane(4); 5409 r[i+5]=av.lane(5); 5410 r[i+6]=av.lane(6); 5411 r[i+7]=av.lane(7); 5412 r[i+8]=av.lane(8); 5413 r[i+9]=av.lane(9); 5414 r[i+10]=av.lane(10); 5415 r[i+11]=av.lane(11); 5416 r[i+12]=av.lane(12); 5417 r[i+13]=av.lane(13); 5418 r[i+14]=av.lane(14); 5419 r[i+15]=av.lane(15); 5420 } else if (num_lanes == 32) { 5421 r[i]=av.lane(0); 5422 r[i+1]=av.lane(1); 5423 r[i+2]=av.lane(2); 5424 r[i+3]=av.lane(3); 5425 r[i+4]=av.lane(4); 5426 r[i+5]=av.lane(5); 5427 r[i+6]=av.lane(6); 5428 r[i+7]=av.lane(7); 5429 r[i+8]=av.lane(8); 5430 r[i+9]=av.lane(9); 5431 r[i+10]=av.lane(10); 5432 r[i+11]=av.lane(11); 5433 r[i+12]=av.lane(12); 5434 r[i+13]=av.lane(13); 5435 r[i+14]=av.lane(14); 5436 r[i+15]=av.lane(15); 5437 r[i+16]=av.lane(16); 5438 r[i+17]=av.lane(17); 5439 r[i+18]=av.lane(18); 5440 r[i+19]=av.lane(19); 5441 r[i+20]=av.lane(20); 5442 r[i+21]=av.lane(21); 5443 r[i+22]=av.lane(22); 5444 r[i+23]=av.lane(23); 5445 r[i+24]=av.lane(24); 5446 r[i+25]=av.lane(25); 5447 r[i+26]=av.lane(26); 5448 r[i+27]=av.lane(27); 5449 r[i+28]=av.lane(28); 5450 r[i+29]=av.lane(29); 5451 r[i+30]=av.lane(30); 5452 r[i+31]=av.lane(31); 5453 } else if (num_lanes == 64) { 5454 r[i]=av.lane(0); 5455 r[i+1]=av.lane(1); 5456 r[i+2]=av.lane(2); 5457 r[i+3]=av.lane(3); 5458 r[i+4]=av.lane(4); 5459 r[i+5]=av.lane(5); 5460 r[i+6]=av.lane(6); 5461 r[i+7]=av.lane(7); 5462 r[i+8]=av.lane(8); 5463 r[i+9]=av.lane(9); 5464 r[i+10]=av.lane(10); 5465 r[i+11]=av.lane(11); 5466 r[i+12]=av.lane(12); 5467 r[i+13]=av.lane(13); 5468 r[i+14]=av.lane(14); 5469 r[i+15]=av.lane(15); 5470 r[i+16]=av.lane(16); 5471 r[i+17]=av.lane(17); 5472 r[i+18]=av.lane(18); 5473 r[i+19]=av.lane(19); 5474 r[i+20]=av.lane(20); 5475 r[i+21]=av.lane(21); 5476 r[i+22]=av.lane(22); 5477 r[i+23]=av.lane(23); 5478 r[i+24]=av.lane(24); 5479 r[i+25]=av.lane(25); 5480 r[i+26]=av.lane(26); 5481 r[i+27]=av.lane(27); 5482 r[i+28]=av.lane(28); 5483 r[i+29]=av.lane(29); 5484 r[i+30]=av.lane(30); 5485 r[i+31]=av.lane(31); 5486 r[i+32]=av.lane(32); 5487 r[i+33]=av.lane(33); 5488 r[i+34]=av.lane(34); 5489 r[i+35]=av.lane(35); 5490 r[i+36]=av.lane(36); 5491 r[i+37]=av.lane(37); 5492 r[i+38]=av.lane(38); 5493 r[i+39]=av.lane(39); 5494 r[i+40]=av.lane(40); 5495 r[i+41]=av.lane(41); 5496 r[i+42]=av.lane(42); 5497 r[i+43]=av.lane(43); 5498 r[i+44]=av.lane(44); 5499 r[i+45]=av.lane(45); 5500 r[i+46]=av.lane(46); 5501 r[i+47]=av.lane(47); 5502 r[i+48]=av.lane(48); 5503 r[i+49]=av.lane(49); 5504 r[i+50]=av.lane(50); 5505 r[i+51]=av.lane(51); 5506 r[i+52]=av.lane(52); 5507 r[i+53]=av.lane(53); 5508 r[i+54]=av.lane(54); 5509 r[i+55]=av.lane(55); 5510 r[i+56]=av.lane(56); 5511 r[i+57]=av.lane(57); 5512 r[i+58]=av.lane(58); 5513 r[i+59]=av.lane(59); 5514 r[i+60]=av.lane(60); 5515 r[i+61]=av.lane(61); 5516 r[i+62]=av.lane(62); 5517 r[i+63]=av.lane(63); 5518 } else { 5519 for (int j = 0; j < SPECIES.length(); j++) { 5520 r[i+j]=av.lane(j); 5521 } 5522 } 5523 } 5524 } 5525 5526 assertArraysStrictlyEquals(r, a); 5527 } 5528 5529 @Test(dataProvider = "shortUnaryOpProvider") 5530 static void BroadcastShort512VectorTests(IntFunction<short[]> fa) { 5531 short[] a = fa.apply(SPECIES.length()); 5532 short[] r = new short[a.length]; 5533 5534 for (int ic = 0; ic < INVOC_COUNT; ic++) { 5535 for (int i = 0; i < a.length; i += SPECIES.length()) { 5536 ShortVector.broadcast(SPECIES, a[i]).intoArray(r, i); 5537 } 5538 } 5539 5540 assertBroadcastArraysEquals(r, a); 5541 } 5542 5543 @Test(dataProvider = "shortUnaryOpProvider") 5544 static void ZeroShort512VectorTests(IntFunction<short[]> fa) { 5545 short[] a = fa.apply(SPECIES.length()); 5546 short[] r = new short[a.length]; 5547 5548 for (int ic = 0; ic < INVOC_COUNT; ic++) { 5549 for (int i = 0; i < a.length; i += SPECIES.length()) { 5550 ShortVector.zero(SPECIES).intoArray(a, i); 5551 } 5552 } 5553 5554 Assert.assertEquals(a, r); 5555 } 5556 5557 static short[] sliceUnary(short[] a, int origin, int idx) { 5558 short[] res = new short[SPECIES.length()]; 5559 for (int i = 0; i < SPECIES.length(); i++){ 5560 if(i+origin < SPECIES.length()) 5561 res[i] = a[idx+i+origin]; 5562 else 5563 res[i] = (short)0; 5564 } 5565 return res; 5566 } 5567 5568 @Test(dataProvider = "shortUnaryOpProvider") 5569 static void sliceUnaryShort512VectorTests(IntFunction<short[]> fa) { 5570 short[] a = fa.apply(SPECIES.length()); 5571 short[] r = new short[a.length]; 5572 int origin = RAND.nextInt(SPECIES.length()); 5573 for (int ic = 0; ic < INVOC_COUNT; ic++) { 5574 for (int i = 0; i < a.length; i += SPECIES.length()) { 5575 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 5576 av.slice(origin).intoArray(r, i); 5577 } 5578 } 5579 5580 assertArraysEquals(r, a, origin, Short512VectorTests::sliceUnary); 5581 } 5582 5583 static short[] sliceBinary(short[] a, short[] b, int origin, int idx) { 5584 short[] res = new short[SPECIES.length()]; 5585 for (int i = 0, j = 0; i < SPECIES.length(); i++){ 5586 if(i+origin < SPECIES.length()) 5587 res[i] = a[idx+i+origin]; 5588 else { 5589 res[i] = b[idx+j]; 5590 j++; 5591 } 5592 } 5593 return res; 5594 } 5595 5596 @Test(dataProvider = "shortBinaryOpProvider") 5597 static void sliceBinaryShort512VectorTestsBinary(IntFunction<short[]> fa, IntFunction<short[]> fb) { 5598 short[] a = fa.apply(SPECIES.length()); 5599 short[] b = fb.apply(SPECIES.length()); 5600 short[] r = new short[a.length]; 5601 int origin = RAND.nextInt(SPECIES.length()); 5602 for (int ic = 0; ic < INVOC_COUNT; ic++) { 5603 for (int i = 0; i < a.length; i += SPECIES.length()) { 5604 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 5605 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 5606 av.slice(origin, bv).intoArray(r, i); 5607 } 5608 } 5609 5610 assertArraysEquals(r, a, b, origin, Short512VectorTests::sliceBinary); 5611 } 5612 5613 static short[] slice(short[] a, short[] b, int origin, boolean[] mask, int idx) { 5614 short[] res = new short[SPECIES.length()]; 5615 for (int i = 0, j = 0; i < SPECIES.length(); i++){ 5616 if(i+origin < SPECIES.length()) 5617 res[i] = mask[i] ? a[idx+i+origin] : (short)0; 5618 else { 5619 res[i] = mask[i] ? b[idx+j] : (short)0; 5620 j++; 5621 } 5622 } 5623 return res; 5624 } 5625 5626 @Test(dataProvider = "shortBinaryOpMaskProvider") 5627 static void sliceShort512VectorTestsMasked(IntFunction<short[]> fa, IntFunction<short[]> fb, 5628 IntFunction<boolean[]> fm) { 5629 short[] a = fa.apply(SPECIES.length()); 5630 short[] b = fb.apply(SPECIES.length()); 5631 boolean[] mask = fm.apply(SPECIES.length()); 5632 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 5633 5634 short[] r = new short[a.length]; 5635 int origin = RAND.nextInt(SPECIES.length()); 5636 for (int ic = 0; ic < INVOC_COUNT; ic++) { 5637 for (int i = 0; i < a.length; i += SPECIES.length()) { 5638 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 5639 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 5640 av.slice(origin, bv, vmask).intoArray(r, i); 5641 } 5642 } 5643 5644 assertArraysEquals(r, a, b, origin, mask, Short512VectorTests::slice); 5645 } 5646 5647 static short[] unsliceUnary(short[] a, int origin, int idx) { 5648 short[] res = new short[SPECIES.length()]; 5649 for (int i = 0, j = 0; i < SPECIES.length(); i++){ 5650 if(i < origin) 5651 res[i] = (short)0; 5652 else { 5653 res[i] = a[idx+j]; 5654 j++; 5655 } 5656 } 5657 return res; 5658 } 5659 5660 @Test(dataProvider = "shortUnaryOpProvider") 5661 static void unsliceUnaryShort512VectorTests(IntFunction<short[]> fa) { 5662 short[] a = fa.apply(SPECIES.length()); 5663 short[] r = new short[a.length]; 5664 int origin = RAND.nextInt(SPECIES.length()); 5665 for (int ic = 0; ic < INVOC_COUNT; ic++) { 5666 for (int i = 0; i < a.length; i += SPECIES.length()) { 5667 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 5668 av.unslice(origin).intoArray(r, i); 5669 } 5670 } 5671 5672 assertArraysEquals(r, a, origin, Short512VectorTests::unsliceUnary); 5673 } 5674 5675 static short[] unsliceBinary(short[] a, short[] b, int origin, int part, int idx) { 5676 short[] res = new short[SPECIES.length()]; 5677 for (int i = 0, j = 0; i < SPECIES.length(); i++){ 5678 if (part == 0) { 5679 if (i < origin) 5680 res[i] = b[idx+i]; 5681 else { 5682 res[i] = a[idx+j]; 5683 j++; 5684 } 5685 } else if (part == 1) { 5686 if (i < origin) 5687 res[i] = a[idx+SPECIES.length()-origin+i]; 5688 else { 5689 res[i] = b[idx+origin+j]; 5690 j++; 5691 } 5692 } 5693 } 5694 return res; 5695 } 5696 5697 @Test(dataProvider = "shortBinaryOpProvider") 5698 static void unsliceBinaryShort512VectorTestsBinary(IntFunction<short[]> fa, IntFunction<short[]> fb) { 5699 short[] a = fa.apply(SPECIES.length()); 5700 short[] b = fb.apply(SPECIES.length()); 5701 short[] r = new short[a.length]; 5702 int origin = RAND.nextInt(SPECIES.length()); 5703 int part = RAND.nextInt(2); 5704 for (int ic = 0; ic < INVOC_COUNT; ic++) { 5705 for (int i = 0; i < a.length; i += SPECIES.length()) { 5706 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 5707 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 5708 av.unslice(origin, bv, part).intoArray(r, i); 5709 } 5710 } 5711 5712 assertArraysEquals(r, a, b, origin, part, Short512VectorTests::unsliceBinary); 5713 } 5714 5715 static short[] unslice(short[] a, short[] b, int origin, int part, boolean[] mask, int idx) { 5716 short[] res = new short[SPECIES.length()]; 5717 for (int i = 0, j = 0; i < SPECIES.length(); i++){ 5718 if(i+origin < SPECIES.length()) 5719 res[i] = b[idx+i+origin]; 5720 else { 5721 res[i] = b[idx+j]; 5722 j++; 5723 } 5724 } 5725 for (int i = 0; i < SPECIES.length(); i++){ 5726 res[i] = mask[i] ? a[idx+i] : res[i]; 5727 } 5728 short[] res1 = new short[SPECIES.length()]; 5729 if (part == 0) { 5730 for (int i = 0, j = 0; i < SPECIES.length(); i++){ 5731 if (i < origin) 5732 res1[i] = b[idx+i]; 5733 else { 5734 res1[i] = res[j]; 5735 j++; 5736 } 5737 } 5738 } else if (part == 1) { 5739 for (int i = 0, j = 0; i < SPECIES.length(); i++){ 5740 if (i < origin) 5741 res1[i] = res[SPECIES.length()-origin+i]; 5742 else { 5743 res1[i] = b[idx+origin+j]; 5744 j++; 5745 } 5746 } 5747 } 5748 return res1; 5749 } 5750 5751 @Test(dataProvider = "shortBinaryOpMaskProvider") 5752 static void unsliceShort512VectorTestsMasked(IntFunction<short[]> fa, IntFunction<short[]> fb, 5753 IntFunction<boolean[]> fm) { 5754 short[] a = fa.apply(SPECIES.length()); 5755 short[] b = fb.apply(SPECIES.length()); 5756 boolean[] mask = fm.apply(SPECIES.length()); 5757 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 5758 short[] r = new short[a.length]; 5759 int origin = RAND.nextInt(SPECIES.length()); 5760 int part = RAND.nextInt(2); 5761 for (int ic = 0; ic < INVOC_COUNT; ic++) { 5762 for (int i = 0; i < a.length; i += SPECIES.length()) { 5763 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 5764 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 5765 av.unslice(origin, bv, part, vmask).intoArray(r, i); 5766 } 5767 } 5768 5769 assertArraysEquals(r, a, b, origin, part, mask, Short512VectorTests::unslice); 5770 } 5771 5772 static short BITWISE_BLEND(short a, short b, short c) { 5773 return (short)((a&~(c))|(b&c)); 5774 } 5775 5776 static short bitwiseBlend(short a, short b, short c) { 5777 return (short)((a&~(c))|(b&c)); 5778 } 5779 5780 @Test(dataProvider = "shortTernaryOpProvider") 5781 static void BITWISE_BLENDShort512VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb, IntFunction<short[]> fc) { 5782 short[] a = fa.apply(SPECIES.length()); 5783 short[] b = fb.apply(SPECIES.length()); 5784 short[] c = fc.apply(SPECIES.length()); 5785 short[] r = fr.apply(SPECIES.length()); 5786 5787 for (int ic = 0; ic < INVOC_COUNT; ic++) { 5788 for (int i = 0; i < a.length; i += SPECIES.length()) { 5789 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 5790 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 5791 ShortVector cv = ShortVector.fromArray(SPECIES, c, i); 5792 av.lanewise(VectorOperators.BITWISE_BLEND, bv, cv).intoArray(r, i); 5793 } 5794 } 5795 5796 assertArraysEquals(r, a, b, c, Short512VectorTests::BITWISE_BLEND); 5797 } 5798 5799 @Test(dataProvider = "shortTernaryOpProvider") 5800 static void bitwiseBlendShort512VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb, IntFunction<short[]> fc) { 5801 short[] a = fa.apply(SPECIES.length()); 5802 short[] b = fb.apply(SPECIES.length()); 5803 short[] c = fc.apply(SPECIES.length()); 5804 short[] r = fr.apply(SPECIES.length()); 5805 5806 for (int i = 0; i < a.length; i += SPECIES.length()) { 5807 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 5808 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 5809 ShortVector cv = ShortVector.fromArray(SPECIES, c, i); 5810 av.bitwiseBlend(bv, cv).intoArray(r, i); 5811 } 5812 5813 assertArraysEquals(r, a, b, c, Short512VectorTests::bitwiseBlend); 5814 } 5815 5816 @Test(dataProvider = "shortTernaryOpMaskProvider") 5817 static void BITWISE_BLENDShort512VectorTestsMasked(IntFunction<short[]> fa, IntFunction<short[]> fb, 5818 IntFunction<short[]> fc, IntFunction<boolean[]> fm) { 5819 short[] a = fa.apply(SPECIES.length()); 5820 short[] b = fb.apply(SPECIES.length()); 5821 short[] c = fc.apply(SPECIES.length()); 5822 short[] r = fr.apply(SPECIES.length()); 5823 boolean[] mask = fm.apply(SPECIES.length()); 5824 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 5825 5826 for (int ic = 0; ic < INVOC_COUNT; ic++) { 5827 for (int i = 0; i < a.length; i += SPECIES.length()) { 5828 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 5829 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 5830 ShortVector cv = ShortVector.fromArray(SPECIES, c, i); 5831 av.lanewise(VectorOperators.BITWISE_BLEND, bv, cv, vmask).intoArray(r, i); 5832 } 5833 } 5834 5835 assertArraysEquals(r, a, b, c, mask, Short512VectorTests::BITWISE_BLEND); 5836 } 5837 5838 @Test(dataProvider = "shortTernaryOpProvider") 5839 static void BITWISE_BLENDShort512VectorTestsBroadcastSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb, IntFunction<short[]> fc) { 5840 short[] a = fa.apply(SPECIES.length()); 5841 short[] b = fb.apply(SPECIES.length()); 5842 short[] c = fc.apply(SPECIES.length()); 5843 short[] r = fr.apply(SPECIES.length()); 5844 5845 for (int i = 0; i < a.length; i += SPECIES.length()) { 5846 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 5847 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 5848 av.lanewise(VectorOperators.BITWISE_BLEND, bv, c[i]).intoArray(r, i); 5849 } 5850 assertBroadcastArraysEquals(r, a, b, c, Short512VectorTests::BITWISE_BLEND); 5851 } 5852 5853 @Test(dataProvider = "shortTernaryOpProvider") 5854 static void BITWISE_BLENDShort512VectorTestsAltBroadcastSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb, IntFunction<short[]> fc) { 5855 short[] a = fa.apply(SPECIES.length()); 5856 short[] b = fb.apply(SPECIES.length()); 5857 short[] c = fc.apply(SPECIES.length()); 5858 short[] r = fr.apply(SPECIES.length()); 5859 5860 for (int i = 0; i < a.length; i += SPECIES.length()) { 5861 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 5862 ShortVector cv = ShortVector.fromArray(SPECIES, c, i); 5863 av.lanewise(VectorOperators.BITWISE_BLEND, b[i], cv).intoArray(r, i); 5864 } 5865 assertAltBroadcastArraysEquals(r, a, b, c, Short512VectorTests::BITWISE_BLEND); 5866 } 5867 5868 @Test(dataProvider = "shortTernaryOpProvider") 5869 static void bitwiseBlendShort512VectorTestsBroadcastSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb, IntFunction<short[]> fc) { 5870 short[] a = fa.apply(SPECIES.length()); 5871 short[] b = fb.apply(SPECIES.length()); 5872 short[] c = fc.apply(SPECIES.length()); 5873 short[] r = fr.apply(SPECIES.length()); 5874 5875 for (int i = 0; i < a.length; i += SPECIES.length()) { 5876 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 5877 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 5878 av.bitwiseBlend(bv, c[i]).intoArray(r, i); 5879 } 5880 assertBroadcastArraysEquals(r, a, b, c, Short512VectorTests::bitwiseBlend); 5881 } 5882 5883 @Test(dataProvider = "shortTernaryOpProvider") 5884 static void bitwiseBlendShort512VectorTestsAltBroadcastSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb, IntFunction<short[]> fc) { 5885 short[] a = fa.apply(SPECIES.length()); 5886 short[] b = fb.apply(SPECIES.length()); 5887 short[] c = fc.apply(SPECIES.length()); 5888 short[] r = fr.apply(SPECIES.length()); 5889 5890 for (int i = 0; i < a.length; i += SPECIES.length()) { 5891 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 5892 ShortVector cv = ShortVector.fromArray(SPECIES, c, i); 5893 av.bitwiseBlend(b[i], cv).intoArray(r, i); 5894 } 5895 assertAltBroadcastArraysEquals(r, a, b, c, Short512VectorTests::bitwiseBlend); 5896 } 5897 5898 @Test(dataProvider = "shortTernaryOpMaskProvider") 5899 static void BITWISE_BLENDShort512VectorTestsBroadcastMaskedSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb, 5900 IntFunction<short[]> fc, IntFunction<boolean[]> fm) { 5901 short[] a = fa.apply(SPECIES.length()); 5902 short[] b = fb.apply(SPECIES.length()); 5903 short[] c = fc.apply(SPECIES.length()); 5904 short[] r = fr.apply(SPECIES.length()); 5905 boolean[] mask = fm.apply(SPECIES.length()); 5906 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 5907 5908 for (int i = 0; i < a.length; i += SPECIES.length()) { 5909 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 5910 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 5911 av.lanewise(VectorOperators.BITWISE_BLEND, bv, c[i], vmask).intoArray(r, i); 5912 } 5913 5914 assertBroadcastArraysEquals(r, a, b, c, mask, Short512VectorTests::BITWISE_BLEND); 5915 } 5916 5917 @Test(dataProvider = "shortTernaryOpMaskProvider") 5918 static void BITWISE_BLENDShort512VectorTestsAltBroadcastMaskedSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb, 5919 IntFunction<short[]> fc, IntFunction<boolean[]> fm) { 5920 short[] a = fa.apply(SPECIES.length()); 5921 short[] b = fb.apply(SPECIES.length()); 5922 short[] c = fc.apply(SPECIES.length()); 5923 short[] r = fr.apply(SPECIES.length()); 5924 boolean[] mask = fm.apply(SPECIES.length()); 5925 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 5926 5927 for (int i = 0; i < a.length; i += SPECIES.length()) { 5928 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 5929 ShortVector cv = ShortVector.fromArray(SPECIES, c, i); 5930 av.lanewise(VectorOperators.BITWISE_BLEND, b[i], cv, vmask).intoArray(r, i); 5931 } 5932 5933 assertAltBroadcastArraysEquals(r, a, b, c, mask, Short512VectorTests::BITWISE_BLEND); 5934 } 5935 5936 @Test(dataProvider = "shortTernaryOpProvider") 5937 static void BITWISE_BLENDShort512VectorTestsDoubleBroadcastSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb, IntFunction<short[]> fc) { 5938 short[] a = fa.apply(SPECIES.length()); 5939 short[] b = fb.apply(SPECIES.length()); 5940 short[] c = fc.apply(SPECIES.length()); 5941 short[] r = fr.apply(SPECIES.length()); 5942 5943 for (int i = 0; i < a.length; i += SPECIES.length()) { 5944 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 5945 av.lanewise(VectorOperators.BITWISE_BLEND, b[i], c[i]).intoArray(r, i); 5946 } 5947 5948 assertDoubleBroadcastArraysEquals(r, a, b, c, Short512VectorTests::BITWISE_BLEND); 5949 } 5950 5951 @Test(dataProvider = "shortTernaryOpProvider") 5952 static void bitwiseBlendShort512VectorTestsDoubleBroadcastSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb, IntFunction<short[]> fc) { 5953 short[] a = fa.apply(SPECIES.length()); 5954 short[] b = fb.apply(SPECIES.length()); 5955 short[] c = fc.apply(SPECIES.length()); 5956 short[] r = fr.apply(SPECIES.length()); 5957 5958 for (int i = 0; i < a.length; i += SPECIES.length()) { 5959 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 5960 av.bitwiseBlend(b[i], c[i]).intoArray(r, i); 5961 } 5962 5963 assertDoubleBroadcastArraysEquals(r, a, b, c, Short512VectorTests::bitwiseBlend); 5964 } 5965 5966 @Test(dataProvider = "shortTernaryOpMaskProvider") 5967 static void BITWISE_BLENDShort512VectorTestsDoubleBroadcastMaskedSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb, 5968 IntFunction<short[]> fc, IntFunction<boolean[]> fm) { 5969 short[] a = fa.apply(SPECIES.length()); 5970 short[] b = fb.apply(SPECIES.length()); 5971 short[] c = fc.apply(SPECIES.length()); 5972 short[] r = fr.apply(SPECIES.length()); 5973 boolean[] mask = fm.apply(SPECIES.length()); 5974 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 5975 5976 for (int i = 0; i < a.length; i += SPECIES.length()) { 5977 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 5978 av.lanewise(VectorOperators.BITWISE_BLEND, b[i], c[i], vmask).intoArray(r, i); 5979 } 5980 5981 assertDoubleBroadcastArraysEquals(r, a, b, c, mask, Short512VectorTests::BITWISE_BLEND); 5982 } 5983 5984 static short NEG(short a) { 5985 return (short)(-((short)a)); 5986 } 5987 5988 static short neg(short a) { 5989 return (short)(-((short)a)); 5990 } 5991 5992 @Test(dataProvider = "shortUnaryOpProvider") 5993 static void NEGShort512VectorTests(IntFunction<short[]> fa) { 5994 short[] a = fa.apply(SPECIES.length()); 5995 short[] r = fr.apply(SPECIES.length()); 5996 5997 for (int ic = 0; ic < INVOC_COUNT; ic++) { 5998 for (int i = 0; i < a.length; i += SPECIES.length()) { 5999 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 6000 av.lanewise(VectorOperators.NEG).intoArray(r, i); 6001 } 6002 } 6003 6004 assertArraysEquals(r, a, Short512VectorTests::NEG); 6005 } 6006 6007 @Test(dataProvider = "shortUnaryOpProvider") 6008 static void negShort512VectorTests(IntFunction<short[]> fa) { 6009 short[] a = fa.apply(SPECIES.length()); 6010 short[] r = fr.apply(SPECIES.length()); 6011 6012 for (int ic = 0; ic < INVOC_COUNT; ic++) { 6013 for (int i = 0; i < a.length; i += SPECIES.length()) { 6014 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 6015 av.neg().intoArray(r, i); 6016 } 6017 } 6018 6019 assertArraysEquals(r, a, Short512VectorTests::neg); 6020 } 6021 6022 @Test(dataProvider = "shortUnaryOpMaskProvider") 6023 static void NEGMaskedShort512VectorTests(IntFunction<short[]> fa, 6024 IntFunction<boolean[]> fm) { 6025 short[] a = fa.apply(SPECIES.length()); 6026 short[] r = fr.apply(SPECIES.length()); 6027 boolean[] mask = fm.apply(SPECIES.length()); 6028 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 6029 6030 for (int ic = 0; ic < INVOC_COUNT; ic++) { 6031 for (int i = 0; i < a.length; i += SPECIES.length()) { 6032 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 6033 av.lanewise(VectorOperators.NEG, vmask).intoArray(r, i); 6034 } 6035 } 6036 6037 assertArraysEquals(r, a, mask, Short512VectorTests::NEG); 6038 } 6039 6040 static short ABS(short a) { 6041 return (short)(Math.abs((short)a)); 6042 } 6043 6044 static short abs(short a) { 6045 return (short)(Math.abs((short)a)); 6046 } 6047 6048 @Test(dataProvider = "shortUnaryOpProvider") 6049 static void ABSShort512VectorTests(IntFunction<short[]> fa) { 6050 short[] a = fa.apply(SPECIES.length()); 6051 short[] r = fr.apply(SPECIES.length()); 6052 6053 for (int ic = 0; ic < INVOC_COUNT; ic++) { 6054 for (int i = 0; i < a.length; i += SPECIES.length()) { 6055 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 6056 av.lanewise(VectorOperators.ABS).intoArray(r, i); 6057 } 6058 } 6059 6060 assertArraysEquals(r, a, Short512VectorTests::ABS); 6061 } 6062 6063 @Test(dataProvider = "shortUnaryOpProvider") 6064 static void absShort512VectorTests(IntFunction<short[]> fa) { 6065 short[] a = fa.apply(SPECIES.length()); 6066 short[] r = fr.apply(SPECIES.length()); 6067 6068 for (int ic = 0; ic < INVOC_COUNT; ic++) { 6069 for (int i = 0; i < a.length; i += SPECIES.length()) { 6070 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 6071 av.abs().intoArray(r, i); 6072 } 6073 } 6074 6075 assertArraysEquals(r, a, Short512VectorTests::abs); 6076 } 6077 6078 @Test(dataProvider = "shortUnaryOpMaskProvider") 6079 static void ABSMaskedShort512VectorTests(IntFunction<short[]> fa, 6080 IntFunction<boolean[]> fm) { 6081 short[] a = fa.apply(SPECIES.length()); 6082 short[] r = fr.apply(SPECIES.length()); 6083 boolean[] mask = fm.apply(SPECIES.length()); 6084 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 6085 6086 for (int ic = 0; ic < INVOC_COUNT; ic++) { 6087 for (int i = 0; i < a.length; i += SPECIES.length()) { 6088 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 6089 av.lanewise(VectorOperators.ABS, vmask).intoArray(r, i); 6090 } 6091 } 6092 6093 assertArraysEquals(r, a, mask, Short512VectorTests::ABS); 6094 } 6095 6096 static short NOT(short a) { 6097 return (short)(~((short)a)); 6098 } 6099 6100 static short not(short a) { 6101 return (short)(~((short)a)); 6102 } 6103 6104 @Test(dataProvider = "shortUnaryOpProvider") 6105 static void NOTShort512VectorTests(IntFunction<short[]> fa) { 6106 short[] a = fa.apply(SPECIES.length()); 6107 short[] r = fr.apply(SPECIES.length()); 6108 6109 for (int ic = 0; ic < INVOC_COUNT; ic++) { 6110 for (int i = 0; i < a.length; i += SPECIES.length()) { 6111 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 6112 av.lanewise(VectorOperators.NOT).intoArray(r, i); 6113 } 6114 } 6115 6116 assertArraysEquals(r, a, Short512VectorTests::NOT); 6117 } 6118 6119 @Test(dataProvider = "shortUnaryOpProvider") 6120 static void notShort512VectorTests(IntFunction<short[]> fa) { 6121 short[] a = fa.apply(SPECIES.length()); 6122 short[] r = fr.apply(SPECIES.length()); 6123 6124 for (int ic = 0; ic < INVOC_COUNT; ic++) { 6125 for (int i = 0; i < a.length; i += SPECIES.length()) { 6126 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 6127 av.not().intoArray(r, i); 6128 } 6129 } 6130 6131 assertArraysEquals(r, a, Short512VectorTests::not); 6132 } 6133 6134 @Test(dataProvider = "shortUnaryOpMaskProvider") 6135 static void NOTMaskedShort512VectorTests(IntFunction<short[]> fa, 6136 IntFunction<boolean[]> fm) { 6137 short[] a = fa.apply(SPECIES.length()); 6138 short[] r = fr.apply(SPECIES.length()); 6139 boolean[] mask = fm.apply(SPECIES.length()); 6140 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 6141 6142 for (int ic = 0; ic < INVOC_COUNT; ic++) { 6143 for (int i = 0; i < a.length; i += SPECIES.length()) { 6144 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 6145 av.lanewise(VectorOperators.NOT, vmask).intoArray(r, i); 6146 } 6147 } 6148 6149 assertArraysEquals(r, a, mask, Short512VectorTests::NOT); 6150 } 6151 6152 static short ZOMO(short a) { 6153 return (short)((a==0?0:-1)); 6154 } 6155 6156 @Test(dataProvider = "shortUnaryOpProvider") 6157 static void ZOMOShort512VectorTests(IntFunction<short[]> fa) { 6158 short[] a = fa.apply(SPECIES.length()); 6159 short[] r = fr.apply(SPECIES.length()); 6160 6161 for (int ic = 0; ic < INVOC_COUNT; ic++) { 6162 for (int i = 0; i < a.length; i += SPECIES.length()) { 6163 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 6164 av.lanewise(VectorOperators.ZOMO).intoArray(r, i); 6165 } 6166 } 6167 6168 assertArraysEquals(r, a, Short512VectorTests::ZOMO); 6169 } 6170 6171 @Test(dataProvider = "shortUnaryOpMaskProvider") 6172 static void ZOMOMaskedShort512VectorTests(IntFunction<short[]> fa, 6173 IntFunction<boolean[]> fm) { 6174 short[] a = fa.apply(SPECIES.length()); 6175 short[] r = fr.apply(SPECIES.length()); 6176 boolean[] mask = fm.apply(SPECIES.length()); 6177 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 6178 6179 for (int ic = 0; ic < INVOC_COUNT; ic++) { 6180 for (int i = 0; i < a.length; i += SPECIES.length()) { 6181 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 6182 av.lanewise(VectorOperators.ZOMO, vmask).intoArray(r, i); 6183 } 6184 } 6185 6186 assertArraysEquals(r, a, mask, Short512VectorTests::ZOMO); 6187 } 6188 6189 static short BIT_COUNT(short a) { 6190 return (short)(Integer.bitCount((int)a & 0xFFFF)); 6191 } 6192 6193 @Test(dataProvider = "shortUnaryOpProvider") 6194 static void BIT_COUNTShort512VectorTests(IntFunction<short[]> fa) { 6195 short[] a = fa.apply(SPECIES.length()); 6196 short[] r = fr.apply(SPECIES.length()); 6197 6198 for (int ic = 0; ic < INVOC_COUNT; ic++) { 6199 for (int i = 0; i < a.length; i += SPECIES.length()) { 6200 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 6201 av.lanewise(VectorOperators.BIT_COUNT).intoArray(r, i); 6202 } 6203 } 6204 6205 assertArraysEquals(r, a, Short512VectorTests::BIT_COUNT); 6206 } 6207 6208 @Test(dataProvider = "shortUnaryOpMaskProvider") 6209 static void BIT_COUNTMaskedShort512VectorTests(IntFunction<short[]> fa, 6210 IntFunction<boolean[]> fm) { 6211 short[] a = fa.apply(SPECIES.length()); 6212 short[] r = fr.apply(SPECIES.length()); 6213 boolean[] mask = fm.apply(SPECIES.length()); 6214 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 6215 6216 for (int ic = 0; ic < INVOC_COUNT; ic++) { 6217 for (int i = 0; i < a.length; i += SPECIES.length()) { 6218 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 6219 av.lanewise(VectorOperators.BIT_COUNT, vmask).intoArray(r, i); 6220 } 6221 } 6222 6223 assertArraysEquals(r, a, mask, Short512VectorTests::BIT_COUNT); 6224 } 6225 6226 static short TRAILING_ZEROS_COUNT(short a) { 6227 return (short)(TRAILING_ZEROS_COUNT_scalar(a)); 6228 } 6229 6230 @Test(dataProvider = "shortUnaryOpProvider") 6231 static void TRAILING_ZEROS_COUNTShort512VectorTests(IntFunction<short[]> fa) { 6232 short[] a = fa.apply(SPECIES.length()); 6233 short[] r = fr.apply(SPECIES.length()); 6234 6235 for (int ic = 0; ic < INVOC_COUNT; ic++) { 6236 for (int i = 0; i < a.length; i += SPECIES.length()) { 6237 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 6238 av.lanewise(VectorOperators.TRAILING_ZEROS_COUNT).intoArray(r, i); 6239 } 6240 } 6241 6242 assertArraysEquals(r, a, Short512VectorTests::TRAILING_ZEROS_COUNT); 6243 } 6244 6245 @Test(dataProvider = "shortUnaryOpMaskProvider") 6246 static void TRAILING_ZEROS_COUNTMaskedShort512VectorTests(IntFunction<short[]> fa, 6247 IntFunction<boolean[]> fm) { 6248 short[] a = fa.apply(SPECIES.length()); 6249 short[] r = fr.apply(SPECIES.length()); 6250 boolean[] mask = fm.apply(SPECIES.length()); 6251 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 6252 6253 for (int ic = 0; ic < INVOC_COUNT; ic++) { 6254 for (int i = 0; i < a.length; i += SPECIES.length()) { 6255 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 6256 av.lanewise(VectorOperators.TRAILING_ZEROS_COUNT, vmask).intoArray(r, i); 6257 } 6258 } 6259 6260 assertArraysEquals(r, a, mask, Short512VectorTests::TRAILING_ZEROS_COUNT); 6261 } 6262 6263 static short LEADING_ZEROS_COUNT(short a) { 6264 return (short)(LEADING_ZEROS_COUNT_scalar(a)); 6265 } 6266 6267 @Test(dataProvider = "shortUnaryOpProvider") 6268 static void LEADING_ZEROS_COUNTShort512VectorTests(IntFunction<short[]> fa) { 6269 short[] a = fa.apply(SPECIES.length()); 6270 short[] r = fr.apply(SPECIES.length()); 6271 6272 for (int ic = 0; ic < INVOC_COUNT; ic++) { 6273 for (int i = 0; i < a.length; i += SPECIES.length()) { 6274 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 6275 av.lanewise(VectorOperators.LEADING_ZEROS_COUNT).intoArray(r, i); 6276 } 6277 } 6278 6279 assertArraysEquals(r, a, Short512VectorTests::LEADING_ZEROS_COUNT); 6280 } 6281 6282 @Test(dataProvider = "shortUnaryOpMaskProvider") 6283 static void LEADING_ZEROS_COUNTMaskedShort512VectorTests(IntFunction<short[]> fa, 6284 IntFunction<boolean[]> fm) { 6285 short[] a = fa.apply(SPECIES.length()); 6286 short[] r = fr.apply(SPECIES.length()); 6287 boolean[] mask = fm.apply(SPECIES.length()); 6288 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 6289 6290 for (int ic = 0; ic < INVOC_COUNT; ic++) { 6291 for (int i = 0; i < a.length; i += SPECIES.length()) { 6292 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 6293 av.lanewise(VectorOperators.LEADING_ZEROS_COUNT, vmask).intoArray(r, i); 6294 } 6295 } 6296 6297 assertArraysEquals(r, a, mask, Short512VectorTests::LEADING_ZEROS_COUNT); 6298 } 6299 6300 static short REVERSE(short a) { 6301 return (short)(REVERSE_scalar(a)); 6302 } 6303 6304 @Test(dataProvider = "shortUnaryOpProvider") 6305 static void REVERSEShort512VectorTests(IntFunction<short[]> fa) { 6306 short[] a = fa.apply(SPECIES.length()); 6307 short[] r = fr.apply(SPECIES.length()); 6308 6309 for (int ic = 0; ic < INVOC_COUNT; ic++) { 6310 for (int i = 0; i < a.length; i += SPECIES.length()) { 6311 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 6312 av.lanewise(VectorOperators.REVERSE).intoArray(r, i); 6313 } 6314 } 6315 6316 assertArraysEquals(r, a, Short512VectorTests::REVERSE); 6317 } 6318 6319 @Test(dataProvider = "shortUnaryOpMaskProvider") 6320 static void REVERSEMaskedShort512VectorTests(IntFunction<short[]> fa, 6321 IntFunction<boolean[]> fm) { 6322 short[] a = fa.apply(SPECIES.length()); 6323 short[] r = fr.apply(SPECIES.length()); 6324 boolean[] mask = fm.apply(SPECIES.length()); 6325 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 6326 6327 for (int ic = 0; ic < INVOC_COUNT; ic++) { 6328 for (int i = 0; i < a.length; i += SPECIES.length()) { 6329 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 6330 av.lanewise(VectorOperators.REVERSE, vmask).intoArray(r, i); 6331 } 6332 } 6333 6334 assertArraysEquals(r, a, mask, Short512VectorTests::REVERSE); 6335 } 6336 6337 static short REVERSE_BYTES(short a) { 6338 return (short)(Short.reverseBytes(a)); 6339 } 6340 6341 @Test(dataProvider = "shortUnaryOpProvider") 6342 static void REVERSE_BYTESShort512VectorTests(IntFunction<short[]> fa) { 6343 short[] a = fa.apply(SPECIES.length()); 6344 short[] r = fr.apply(SPECIES.length()); 6345 6346 for (int ic = 0; ic < INVOC_COUNT; ic++) { 6347 for (int i = 0; i < a.length; i += SPECIES.length()) { 6348 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 6349 av.lanewise(VectorOperators.REVERSE_BYTES).intoArray(r, i); 6350 } 6351 } 6352 6353 assertArraysEquals(r, a, Short512VectorTests::REVERSE_BYTES); 6354 } 6355 6356 @Test(dataProvider = "shortUnaryOpMaskProvider") 6357 static void REVERSE_BYTESMaskedShort512VectorTests(IntFunction<short[]> fa, 6358 IntFunction<boolean[]> fm) { 6359 short[] a = fa.apply(SPECIES.length()); 6360 short[] r = fr.apply(SPECIES.length()); 6361 boolean[] mask = fm.apply(SPECIES.length()); 6362 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 6363 6364 for (int ic = 0; ic < INVOC_COUNT; ic++) { 6365 for (int i = 0; i < a.length; i += SPECIES.length()) { 6366 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 6367 av.lanewise(VectorOperators.REVERSE_BYTES, vmask).intoArray(r, i); 6368 } 6369 } 6370 6371 assertArraysEquals(r, a, mask, Short512VectorTests::REVERSE_BYTES); 6372 } 6373 6374 @Test(dataProvider = "shortCompareOpProvider") 6375 static void ltShort512VectorTestsBroadcastSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb) { 6376 short[] a = fa.apply(SPECIES.length()); 6377 short[] b = fb.apply(SPECIES.length()); 6378 6379 for (int i = 0; i < a.length; i += SPECIES.length()) { 6380 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 6381 VectorMask<Short> mv = av.lt(b[i]); 6382 6383 // Check results as part of computation. 6384 for (int j = 0; j < SPECIES.length(); j++) { 6385 Assert.assertEquals(mv.laneIsSet(j), a[i + j] < b[i]); 6386 } 6387 } 6388 } 6389 6390 @Test(dataProvider = "shortCompareOpProvider") 6391 static void eqShort512VectorTestsBroadcastMaskedSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb) { 6392 short[] a = fa.apply(SPECIES.length()); 6393 short[] b = fb.apply(SPECIES.length()); 6394 6395 for (int i = 0; i < a.length; i += SPECIES.length()) { 6396 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 6397 VectorMask<Short> mv = av.eq(b[i]); 6398 6399 // Check results as part of computation. 6400 for (int j = 0; j < SPECIES.length(); j++) { 6401 Assert.assertEquals(mv.laneIsSet(j), a[i + j] == b[i]); 6402 } 6403 } 6404 } 6405 6406 @Test(dataProvider = "shortUnaryOpProvider") 6407 static void toIntArrayShort512VectorTestsSmokeTest(IntFunction<short[]> fa) { 6408 short[] a = fa.apply(SPECIES.length()); 6409 6410 for (int i = 0; i < a.length; i += SPECIES.length()) { 6411 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 6412 int[] r = av.toIntArray(); 6413 assertArraysEquals(r, a, i); 6414 } 6415 } 6416 6417 @Test(dataProvider = "shortUnaryOpProvider") 6418 static void toLongArrayShort512VectorTestsSmokeTest(IntFunction<short[]> fa) { 6419 short[] a = fa.apply(SPECIES.length()); 6420 6421 for (int i = 0; i < a.length; i += SPECIES.length()) { 6422 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 6423 long[] r = av.toLongArray(); 6424 assertArraysEquals(r, a, i); 6425 } 6426 } 6427 6428 @Test(dataProvider = "shortUnaryOpProvider") 6429 static void toDoubleArrayShort512VectorTestsSmokeTest(IntFunction<short[]> fa) { 6430 short[] a = fa.apply(SPECIES.length()); 6431 6432 for (int i = 0; i < a.length; i += SPECIES.length()) { 6433 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 6434 double[] r = av.toDoubleArray(); 6435 assertArraysEquals(r, a, i); 6436 } 6437 } 6438 6439 @Test(dataProvider = "shortUnaryOpProvider") 6440 static void toStringShort512VectorTestsSmokeTest(IntFunction<short[]> fa) { 6441 short[] a = fa.apply(SPECIES.length()); 6442 6443 for (int i = 0; i < a.length; i += SPECIES.length()) { 6444 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 6445 String str = av.toString(); 6446 6447 short subarr[] = Arrays.copyOfRange(a, i, i + SPECIES.length()); 6448 Assert.assertTrue(str.equals(Arrays.toString(subarr)), "at index " + i + ", string should be = " + Arrays.toString(subarr) + ", but is = " + str); 6449 } 6450 } 6451 6452 @Test(dataProvider = "shortUnaryOpProvider") 6453 static void hashCodeShort512VectorTestsSmokeTest(IntFunction<short[]> fa) { 6454 short[] a = fa.apply(SPECIES.length()); 6455 6456 for (int i = 0; i < a.length; i += SPECIES.length()) { 6457 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 6458 int hash = av.hashCode(); 6459 6460 short subarr[] = Arrays.copyOfRange(a, i, i + SPECIES.length()); 6461 int expectedHash = Objects.hash(SPECIES, Arrays.hashCode(subarr)); 6462 Assert.assertTrue(hash == expectedHash, "at index " + i + ", hash should be = " + expectedHash + ", but is = " + hash); 6463 } 6464 } 6465 6466 6467 static long ADDReduceLong(short[] a, int idx) { 6468 short res = 0; 6469 for (int i = idx; i < (idx + SPECIES.length()); i++) { 6470 res += a[i]; 6471 } 6472 6473 return (long)res; 6474 } 6475 6476 static long ADDReduceAllLong(short[] a) { 6477 long res = 0; 6478 for (int i = 0; i < a.length; i += SPECIES.length()) { 6479 res += ADDReduceLong(a, i); 6480 } 6481 6482 return res; 6483 } 6484 6485 @Test(dataProvider = "shortUnaryOpProvider") 6486 static void ADDReduceLongShort512VectorTests(IntFunction<short[]> fa) { 6487 short[] a = fa.apply(SPECIES.length()); 6488 long[] r = lfr.apply(SPECIES.length()); 6489 long ra = 0; 6490 6491 for (int i = 0; i < a.length; i += SPECIES.length()) { 6492 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 6493 r[i] = av.reduceLanesToLong(VectorOperators.ADD); 6494 } 6495 6496 ra = 0; 6497 for (int i = 0; i < a.length; i ++) { 6498 ra += r[i]; 6499 } 6500 6501 assertReductionLongArraysEquals(r, ra, a, 6502 Short512VectorTests::ADDReduceLong, Short512VectorTests::ADDReduceAllLong); 6503 } 6504 6505 static long ADDReduceLongMasked(short[] a, int idx, boolean[] mask) { 6506 short res = 0; 6507 for (int i = idx; i < (idx + SPECIES.length()); i++) { 6508 if(mask[i % SPECIES.length()]) 6509 res += a[i]; 6510 } 6511 6512 return (long)res; 6513 } 6514 6515 static long ADDReduceAllLongMasked(short[] a, boolean[] mask) { 6516 long res = 0; 6517 for (int i = 0; i < a.length; i += SPECIES.length()) { 6518 res += ADDReduceLongMasked(a, i, mask); 6519 } 6520 6521 return res; 6522 } 6523 6524 @Test(dataProvider = "shortUnaryOpMaskProvider") 6525 static void ADDReduceLongShort512VectorTestsMasked(IntFunction<short[]> fa, IntFunction<boolean[]> fm) { 6526 short[] a = fa.apply(SPECIES.length()); 6527 long[] r = lfr.apply(SPECIES.length()); 6528 boolean[] mask = fm.apply(SPECIES.length()); 6529 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 6530 long ra = 0; 6531 6532 for (int i = 0; i < a.length; i += SPECIES.length()) { 6533 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 6534 r[i] = av.reduceLanesToLong(VectorOperators.ADD, vmask); 6535 } 6536 6537 ra = 0; 6538 for (int i = 0; i < a.length; i ++) { 6539 ra += r[i]; 6540 } 6541 6542 assertReductionLongArraysEqualsMasked(r, ra, a, mask, 6543 Short512VectorTests::ADDReduceLongMasked, Short512VectorTests::ADDReduceAllLongMasked); 6544 } 6545 6546 @Test(dataProvider = "shortUnaryOpProvider") 6547 static void BroadcastLongShort512VectorTestsSmokeTest(IntFunction<short[]> fa) { 6548 short[] a = fa.apply(SPECIES.length()); 6549 short[] r = new short[a.length]; 6550 6551 for (int i = 0; i < a.length; i += SPECIES.length()) { 6552 ShortVector.broadcast(SPECIES, (long)a[i]).intoArray(r, i); 6553 } 6554 assertBroadcastArraysEquals(r, a); 6555 } 6556 6557 @Test(dataProvider = "shortBinaryOpMaskProvider") 6558 static void blendShort512VectorTestsBroadcastLongSmokeTest(IntFunction<short[]> fa, IntFunction<short[]> fb, 6559 IntFunction<boolean[]> fm) { 6560 short[] a = fa.apply(SPECIES.length()); 6561 short[] b = fb.apply(SPECIES.length()); 6562 short[] r = fr.apply(SPECIES.length()); 6563 boolean[] mask = fm.apply(SPECIES.length()); 6564 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 6565 6566 for (int ic = 0; ic < INVOC_COUNT; ic++) { 6567 for (int i = 0; i < a.length; i += SPECIES.length()) { 6568 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 6569 av.blend((long)b[i], vmask).intoArray(r, i); 6570 } 6571 } 6572 assertBroadcastLongArraysEquals(r, a, b, mask, Short512VectorTests::blend); 6573 } 6574 6575 6576 @Test(dataProvider = "shortUnaryOpSelectFromProvider") 6577 static void SelectFromShort512VectorTests(IntFunction<short[]> fa, 6578 BiFunction<Integer,Integer,short[]> fs) { 6579 short[] a = fa.apply(SPECIES.length()); 6580 short[] order = fs.apply(a.length, SPECIES.length()); 6581 short[] r = fr.apply(SPECIES.length()); 6582 6583 for (int i = 0; i < a.length; i += SPECIES.length()) { 6584 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 6585 ShortVector bv = ShortVector.fromArray(SPECIES, order, i); 6586 bv.selectFrom(av).intoArray(r, i); 6587 } 6588 6589 assertSelectFromArraysEquals(r, a, order, SPECIES.length()); 6590 } 6591 6592 @Test(dataProvider = "shortSelectFromTwoVectorOpProvider") 6593 static void SelectFromTwoVectorShort512VectorTests(IntFunction<short[]> fa, IntFunction<short[]> fb, IntFunction<short[]> fc) { 6594 short[] a = fa.apply(SPECIES.length()); 6595 short[] b = fb.apply(SPECIES.length()); 6596 short[] idx = fc.apply(SPECIES.length()); 6597 short[] r = fr.apply(SPECIES.length()); 6598 6599 for (int ic = 0; ic < INVOC_COUNT; ic++) { 6600 for (int i = 0; i < idx.length; i += SPECIES.length()) { 6601 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 6602 ShortVector bv = ShortVector.fromArray(SPECIES, b, i); 6603 ShortVector idxv = ShortVector.fromArray(SPECIES, idx, i); 6604 idxv.selectFrom(av, bv).intoArray(r, i); 6605 } 6606 } 6607 assertSelectFromTwoVectorEquals(r, idx, a, b, SPECIES.length()); 6608 } 6609 6610 @Test(dataProvider = "shortUnaryOpSelectFromMaskProvider") 6611 static void SelectFromShort512VectorTestsMaskedSmokeTest(IntFunction<short[]> fa, 6612 BiFunction<Integer,Integer,short[]> fs, 6613 IntFunction<boolean[]> fm) { 6614 short[] a = fa.apply(SPECIES.length()); 6615 short[] order = fs.apply(a.length, SPECIES.length()); 6616 short[] r = fr.apply(SPECIES.length()); 6617 boolean[] mask = fm.apply(SPECIES.length()); 6618 VectorMask<Short> vmask = VectorMask.fromArray(SPECIES, mask, 0); 6619 6620 for (int i = 0; i < a.length; i += SPECIES.length()) { 6621 ShortVector av = ShortVector.fromArray(SPECIES, a, i); 6622 ShortVector bv = ShortVector.fromArray(SPECIES, order, i); 6623 bv.selectFrom(av, vmask).intoArray(r, i); 6624 } 6625 6626 assertSelectFromArraysEquals(r, a, order, mask, SPECIES.length()); 6627 } 6628 6629 @Test(dataProvider = "shuffleProvider") 6630 static void shuffleMiscellaneousShort512VectorTestsSmokeTest(BiFunction<Integer,Integer,int[]> fs) { 6631 int[] a = fs.apply(SPECIES.length() * BUFFER_REPS, SPECIES.length()); 6632 6633 for (int i = 0; i < a.length; i += SPECIES.length()) { 6634 var shuffle = VectorShuffle.fromArray(SPECIES, a, i); 6635 int hash = shuffle.hashCode(); 6636 int length = shuffle.length(); 6637 6638 int subarr[] = Arrays.copyOfRange(a, i, i + SPECIES.length()); 6639 int expectedHash = Objects.hash(SPECIES, Arrays.hashCode(subarr)); 6640 Assert.assertTrue(hash == expectedHash, "at index " + i + ", hash should be = " + expectedHash + ", but is = " + hash); 6641 Assert.assertEquals(length, SPECIES.length()); 6642 } 6643 } 6644 6645 @Test(dataProvider = "shuffleProvider") 6646 static void shuffleToStringShort512VectorTestsSmokeTest(BiFunction<Integer,Integer,int[]> fs) { 6647 int[] a = fs.apply(SPECIES.length() * BUFFER_REPS, SPECIES.length()); 6648 6649 for (int i = 0; i < a.length; i += SPECIES.length()) { 6650 var shuffle = VectorShuffle.fromArray(SPECIES, a, i); 6651 String str = shuffle.toString(); 6652 6653 int subarr[] = Arrays.copyOfRange(a, i, i + SPECIES.length()); 6654 Assert.assertTrue(str.equals("Shuffle" + Arrays.toString(subarr)), "at index " + 6655 i + ", string should be = " + Arrays.toString(subarr) + ", but is = " + str); 6656 } 6657 } 6658 6659 @Test(dataProvider = "shuffleCompareOpProvider") 6660 static void shuffleEqualsShort512VectorTestsSmokeTest(BiFunction<Integer,Integer,int[]> fa, BiFunction<Integer,Integer,int[]> fb) { 6661 int[] a = fa.apply(SPECIES.length() * BUFFER_REPS, SPECIES.length()); 6662 int[] b = fb.apply(SPECIES.length() * BUFFER_REPS, SPECIES.length()); 6663 6664 for (int i = 0; i < a.length; i += SPECIES.length()) { 6665 var av = VectorShuffle.fromArray(SPECIES, a, i); 6666 var bv = VectorShuffle.fromArray(SPECIES, b, i); 6667 boolean eq = av.equals(bv); 6668 int to = i + SPECIES.length(); 6669 Assert.assertEquals(eq, Arrays.equals(a, i, to, b, i, to)); 6670 } 6671 } 6672 6673 @Test(dataProvider = "maskCompareOpProvider") 6674 static void maskEqualsShort512VectorTestsSmokeTest(IntFunction<boolean[]> fa, IntFunction<boolean[]> fb) { 6675 boolean[] a = fa.apply(SPECIES.length()); 6676 boolean[] b = fb.apply(SPECIES.length()); 6677 6678 for (int i = 0; i < a.length; i += SPECIES.length()) { 6679 var av = SPECIES.loadMask(a, i); 6680 var bv = SPECIES.loadMask(b, i); 6681 boolean equals = av.equals(bv); 6682 int to = i + SPECIES.length(); 6683 Assert.assertEquals(equals, Arrays.equals(a, i, to, b, i, to)); 6684 } 6685 } 6686 6687 static boolean band(boolean a, boolean b) { 6688 return a & b; 6689 } 6690 6691 @Test(dataProvider = "maskCompareOpProvider") 6692 static void maskAndShort512VectorTestsSmokeTest(IntFunction<boolean[]> fa, IntFunction<boolean[]> fb) { 6693 boolean[] a = fa.apply(SPECIES.length()); 6694 boolean[] b = fb.apply(SPECIES.length()); 6695 boolean[] r = new boolean[a.length]; 6696 6697 for (int i = 0; i < a.length; i += SPECIES.length()) { 6698 var av = SPECIES.loadMask(a, i); 6699 var bv = SPECIES.loadMask(b, i); 6700 var cv = av.and(bv); 6701 cv.intoArray(r, i); 6702 } 6703 assertArraysEquals(r, a, b, Short512VectorTests::band); 6704 } 6705 6706 static boolean bor(boolean a, boolean b) { 6707 return a | b; 6708 } 6709 6710 @Test(dataProvider = "maskCompareOpProvider") 6711 static void maskOrShort512VectorTestsSmokeTest(IntFunction<boolean[]> fa, IntFunction<boolean[]> fb) { 6712 boolean[] a = fa.apply(SPECIES.length()); 6713 boolean[] b = fb.apply(SPECIES.length()); 6714 boolean[] r = new boolean[a.length]; 6715 6716 for (int i = 0; i < a.length; i += SPECIES.length()) { 6717 var av = SPECIES.loadMask(a, i); 6718 var bv = SPECIES.loadMask(b, i); 6719 var cv = av.or(bv); 6720 cv.intoArray(r, i); 6721 } 6722 assertArraysEquals(r, a, b, Short512VectorTests::bor); 6723 } 6724 6725 static boolean bxor(boolean a, boolean b) { 6726 return a != b; 6727 } 6728 6729 @Test(dataProvider = "maskCompareOpProvider") 6730 static void maskXorShort512VectorTestsSmokeTest(IntFunction<boolean[]> fa, IntFunction<boolean[]> fb) { 6731 boolean[] a = fa.apply(SPECIES.length()); 6732 boolean[] b = fb.apply(SPECIES.length()); 6733 boolean[] r = new boolean[a.length]; 6734 6735 for (int i = 0; i < a.length; i += SPECIES.length()) { 6736 var av = SPECIES.loadMask(a, i); 6737 var bv = SPECIES.loadMask(b, i); 6738 var cv = av.xor(bv); 6739 cv.intoArray(r, i); 6740 } 6741 assertArraysEquals(r, a, b, Short512VectorTests::bxor); 6742 } 6743 6744 static boolean bandNot(boolean a, boolean b) { 6745 return a & !b; 6746 } 6747 6748 @Test(dataProvider = "maskCompareOpProvider") 6749 static void maskAndNotShort512VectorTestsSmokeTest(IntFunction<boolean[]> fa, IntFunction<boolean[]> fb) { 6750 boolean[] a = fa.apply(SPECIES.length()); 6751 boolean[] b = fb.apply(SPECIES.length()); 6752 boolean[] r = new boolean[a.length]; 6753 6754 for (int i = 0; i < a.length; i += SPECIES.length()) { 6755 var av = SPECIES.loadMask(a, i); 6756 var bv = SPECIES.loadMask(b, i); 6757 var cv = av.andNot(bv); 6758 cv.intoArray(r, i); 6759 } 6760 assertArraysEquals(r, a, b, Short512VectorTests::bandNot); 6761 } 6762 6763 static boolean beq(boolean a, boolean b) { 6764 return (a == b); 6765 } 6766 6767 @Test(dataProvider = "maskCompareOpProvider") 6768 static void maskEqShort512VectorTestsSmokeTest(IntFunction<boolean[]> fa, IntFunction<boolean[]> fb) { 6769 boolean[] a = fa.apply(SPECIES.length()); 6770 boolean[] b = fb.apply(SPECIES.length()); 6771 boolean[] r = new boolean[a.length]; 6772 6773 for (int i = 0; i < a.length; i += SPECIES.length()) { 6774 var av = SPECIES.loadMask(a, i); 6775 var bv = SPECIES.loadMask(b, i); 6776 var cv = av.eq(bv); 6777 cv.intoArray(r, i); 6778 } 6779 assertArraysEquals(r, a, b, Short512VectorTests::beq); 6780 } 6781 6782 @Test(dataProvider = "maskProvider") 6783 static void maskHashCodeShort512VectorTestsSmokeTest(IntFunction<boolean[]> fa) { 6784 boolean[] a = fa.apply(SPECIES.length()); 6785 6786 for (int i = 0; i < a.length; i += SPECIES.length()) { 6787 var vmask = SPECIES.loadMask(a, i); 6788 int hash = vmask.hashCode(); 6789 6790 boolean subarr[] = Arrays.copyOfRange(a, i, i + SPECIES.length()); 6791 int expectedHash = Objects.hash(SPECIES, Arrays.hashCode(subarr)); 6792 Assert.assertTrue(hash == expectedHash, "at index " + i + ", hash should be = " + expectedHash + ", but is = " + hash); 6793 } 6794 } 6795 6796 static int maskTrueCount(boolean[] a, int idx) { 6797 int trueCount = 0; 6798 for (int i = idx; i < idx + SPECIES.length(); i++) { 6799 trueCount += a[i] ? 1 : 0; 6800 } 6801 return trueCount; 6802 } 6803 6804 @Test(dataProvider = "maskProvider") 6805 static void maskTrueCountShort512VectorTestsSmokeTest(IntFunction<boolean[]> fa) { 6806 boolean[] a = fa.apply(SPECIES.length()); 6807 int[] r = new int[a.length]; 6808 6809 for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { 6810 for (int i = 0; i < a.length; i += SPECIES.length()) { 6811 var vmask = SPECIES.loadMask(a, i); 6812 r[i] = vmask.trueCount(); 6813 } 6814 } 6815 6816 assertMaskReductionArraysEquals(r, a, Short512VectorTests::maskTrueCount); 6817 } 6818 6819 static int maskLastTrue(boolean[] a, int idx) { 6820 int i = idx + SPECIES.length() - 1; 6821 for (; i >= idx; i--) { 6822 if (a[i]) { 6823 break; 6824 } 6825 } 6826 return i - idx; 6827 } 6828 6829 @Test(dataProvider = "maskProvider") 6830 static void maskLastTrueShort512VectorTestsSmokeTest(IntFunction<boolean[]> fa) { 6831 boolean[] a = fa.apply(SPECIES.length()); 6832 int[] r = new int[a.length]; 6833 6834 for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { 6835 for (int i = 0; i < a.length; i += SPECIES.length()) { 6836 var vmask = SPECIES.loadMask(a, i); 6837 r[i] = vmask.lastTrue(); 6838 } 6839 } 6840 6841 assertMaskReductionArraysEquals(r, a, Short512VectorTests::maskLastTrue); 6842 } 6843 6844 static int maskFirstTrue(boolean[] a, int idx) { 6845 int i = idx; 6846 for (; i < idx + SPECIES.length(); i++) { 6847 if (a[i]) { 6848 break; 6849 } 6850 } 6851 return i - idx; 6852 } 6853 6854 @Test(dataProvider = "maskProvider") 6855 static void maskFirstTrueShort512VectorTestsSmokeTest(IntFunction<boolean[]> fa) { 6856 boolean[] a = fa.apply(SPECIES.length()); 6857 int[] r = new int[a.length]; 6858 6859 for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { 6860 for (int i = 0; i < a.length; i += SPECIES.length()) { 6861 var vmask = SPECIES.loadMask(a, i); 6862 r[i] = vmask.firstTrue(); 6863 } 6864 } 6865 6866 assertMaskReductionArraysEquals(r, a, Short512VectorTests::maskFirstTrue); 6867 } 6868 6869 @Test(dataProvider = "maskProvider") 6870 static void maskCompressShort512VectorTestsSmokeTest(IntFunction<boolean[]> fa) { 6871 int trueCount = 0; 6872 boolean[] a = fa.apply(SPECIES.length()); 6873 6874 for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { 6875 for (int i = 0; i < a.length; i += SPECIES.length()) { 6876 var vmask = SPECIES.loadMask(a, i); 6877 trueCount = vmask.trueCount(); 6878 var rmask = vmask.compress(); 6879 for (int j = 0; j < SPECIES.length(); j++) { 6880 Assert.assertEquals(rmask.laneIsSet(j), j < trueCount); 6881 } 6882 } 6883 } 6884 } 6885 6886 @DataProvider 6887 public static Object[][] longMaskProvider() { 6888 return new Object[][]{ 6889 {0xFFFFFFFFFFFFFFFFL}, 6890 {0x0000000000000000L}, 6891 {0x5555555555555555L}, 6892 {0x0123456789abcdefL}, 6893 }; 6894 } 6895 6896 @Test(dataProvider = "longMaskProvider") 6897 static void maskFromToLongShort512VectorTestsSmokeTest(long inputLong) { 6898 var vmask = VectorMask.fromLong(SPECIES, inputLong); 6899 long outputLong = vmask.toLong(); 6900 Assert.assertEquals(outputLong, (inputLong & (((0xFFFFFFFFFFFFFFFFL >>> (64 - SPECIES.length())))))); 6901 } 6902 6903 @DataProvider 6904 public static Object[][] offsetProvider() { 6905 return new Object[][]{ 6906 {0}, 6907 {-1}, 6908 {+1}, 6909 {+2}, 6910 {-2}, 6911 }; 6912 } 6913 6914 @Test(dataProvider = "offsetProvider") 6915 static void indexInRangeShort512VectorTestsSmokeTest(int offset) { 6916 int limit = SPECIES.length() * BUFFER_REPS; 6917 for (int i = 0; i < limit; i += SPECIES.length()) { 6918 var actualMask = SPECIES.indexInRange(i + offset, limit); 6919 var expectedMask = SPECIES.maskAll(true).indexInRange(i + offset, limit); 6920 assert(actualMask.equals(expectedMask)); 6921 for (int j = 0; j < SPECIES.length(); j++) { 6922 int index = i + j + offset; 6923 Assert.assertEquals(actualMask.laneIsSet(j), index >= 0 && index < limit); 6924 } 6925 } 6926 } 6927 6928 @Test(dataProvider = "offsetProvider") 6929 static void indexInRangeLongShort512VectorTestsSmokeTest(int offset) { 6930 long limit = SPECIES.length() * BUFFER_REPS; 6931 for (long i = 0; i < limit; i += SPECIES.length()) { 6932 var actualMask = SPECIES.indexInRange(i + offset, limit); 6933 var expectedMask = SPECIES.maskAll(true).indexInRange(i + offset, limit); 6934 assert(actualMask.equals(expectedMask)); 6935 for (int j = 0; j < SPECIES.length(); j++) { 6936 long index = i + j + offset; 6937 Assert.assertEquals(actualMask.laneIsSet(j), index >= 0 && index < limit); 6938 } 6939 } 6940 } 6941 6942 @DataProvider 6943 public static Object[][] lengthProvider() { 6944 return new Object[][]{ 6945 {0}, 6946 {1}, 6947 {32}, 6948 {37}, 6949 {1024}, 6950 {1024+1}, 6951 {1024+5}, 6952 }; 6953 } 6954 6955 @Test(dataProvider = "lengthProvider") 6956 static void loopBoundShort512VectorTestsSmokeTest(int length) { 6957 int actualLoopBound = SPECIES.loopBound(length); 6958 int expectedLoopBound = length - Math.floorMod(length, SPECIES.length()); 6959 Assert.assertEquals(actualLoopBound, expectedLoopBound); 6960 } 6961 6962 @Test(dataProvider = "lengthProvider") 6963 static void loopBoundLongShort512VectorTestsSmokeTest(int _length) { 6964 long length = _length; 6965 long actualLoopBound = SPECIES.loopBound(length); 6966 long expectedLoopBound = length - Math.floorMod(length, SPECIES.length()); 6967 Assert.assertEquals(actualLoopBound, expectedLoopBound); 6968 } 6969 6970 @Test 6971 static void ElementSizeShort512VectorTestsSmokeTest() { 6972 ShortVector av = ShortVector.zero(SPECIES); 6973 int elsize = av.elementSize(); 6974 Assert.assertEquals(elsize, Short.SIZE); 6975 } 6976 6977 @Test 6978 static void VectorShapeShort512VectorTestsSmokeTest() { 6979 ShortVector av = ShortVector.zero(SPECIES); 6980 VectorShape vsh = av.shape(); 6981 assert(vsh.equals(VectorShape.S_512_BIT)); 6982 } 6983 6984 @Test 6985 static void ShapeWithLanesShort512VectorTestsSmokeTest() { 6986 ShortVector av = ShortVector.zero(SPECIES); 6987 VectorShape vsh = av.shape(); 6988 VectorSpecies species = vsh.withLanes(short.class); 6989 assert(species.equals(SPECIES)); 6990 } 6991 6992 @Test 6993 static void ElementTypeShort512VectorTestsSmokeTest() { 6994 ShortVector av = ShortVector.zero(SPECIES); 6995 assert(av.species().elementType() == short.class); 6996 } 6997 6998 @Test 6999 static void SpeciesElementSizeShort512VectorTestsSmokeTest() { 7000 ShortVector av = ShortVector.zero(SPECIES); 7001 assert(av.species().elementSize() == Short.SIZE); 7002 } 7003 7004 @Test 7005 static void VectorTypeShort512VectorTestsSmokeTest() { 7006 ShortVector av = ShortVector.zero(SPECIES); 7007 assert(av.species().vectorType() == av.getClass()); 7008 } 7009 7010 @Test 7011 static void WithLanesShort512VectorTestsSmokeTest() { 7012 ShortVector av = ShortVector.zero(SPECIES); 7013 VectorSpecies species = av.species().withLanes(short.class); 7014 assert(species.equals(SPECIES)); 7015 } 7016 7017 @Test 7018 static void WithShapeShort512VectorTestsSmokeTest() { 7019 ShortVector av = ShortVector.zero(SPECIES); 7020 VectorShape vsh = av.shape(); 7021 VectorSpecies species = av.species().withShape(vsh); 7022 assert(species.equals(SPECIES)); 7023 } 7024 7025 @Test 7026 static void MaskAllTrueShort512VectorTestsSmokeTest() { 7027 for (int ic = 0; ic < INVOC_COUNT; ic++) { 7028 Assert.assertEquals(SPECIES.maskAll(true).toLong(), -1L >>> (64 - SPECIES.length())); 7029 } 7030 } 7031 }