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