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