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