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