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