1 /* 2 * Copyright (c) 2018, 2022, 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 -XX:-TieredCompilation Double256VectorTests 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.Objects; 51 import java.util.stream.Collectors; 52 import java.util.stream.Stream; 53 54 @Test 55 public class Double256VectorTests extends AbstractVectorTest { 56 57 static final VectorSpecies<Double> SPECIES = 58 DoubleVector.SPECIES_256; 59 60 static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100); 61 62 63 private static final double CONST_SHIFT = Double.SIZE / 2; 64 65 static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 256); 66 67 interface FUnOp { 68 double apply(double a); 69 } 70 71 static void assertArraysEquals(double[] r, double[] a, FUnOp f) { 72 int i = 0; 73 try { 74 for (; i < a.length; i++) { 75 Assert.assertEquals(r[i], f.apply(a[i])); 76 } 77 } catch (AssertionError e) { 78 Assert.assertEquals(r[i], f.apply(a[i]), "at index #" + i + ", input = " + a[i]); 79 } 80 } 81 82 interface FUnArrayOp { 83 double[] apply(double a); 84 } 85 86 static void assertArraysEquals(double[] r, double[] a, FUnArrayOp f) { 87 int i = 0; 88 try { 89 for (; i < a.length; i += SPECIES.length()) { 90 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()), 91 f.apply(a[i])); 92 } 93 } catch (AssertionError e) { 94 double[] ref = f.apply(a[i]); 95 double[] res = Arrays.copyOfRange(r, i, i+SPECIES.length()); 96 Assert.assertEquals(res, ref, "(ref: " + Arrays.toString(ref) 97 + ", res: " + Arrays.toString(res) 98 + "), at index #" + i); 99 } 100 } 101 102 static void assertArraysEquals(double[] r, double[] a, boolean[] mask, FUnOp f) { 103 int i = 0; 104 try { 105 for (; i < a.length; i++) { 106 Assert.assertEquals(r[i], mask[i % SPECIES.length()] ? f.apply(a[i]) : a[i]); 107 } 108 } catch (AssertionError e) { 109 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()]); 110 } 111 } 112 113 interface FReductionOp { 114 double apply(double[] a, int idx); 115 } 116 117 interface FReductionAllOp { 118 double apply(double[] a); 119 } 120 121 static void assertReductionArraysEquals(double[] r, double rc, double[] a, 122 FReductionOp f, FReductionAllOp fa) { 123 int i = 0; 124 try { 125 Assert.assertEquals(rc, fa.apply(a)); 126 for (; i < a.length; i += SPECIES.length()) { 127 Assert.assertEquals(r[i], f.apply(a, i)); 128 } 129 } catch (AssertionError e) { 130 Assert.assertEquals(rc, fa.apply(a), "Final result is incorrect!"); 131 Assert.assertEquals(r[i], f.apply(a, i), "at index #" + i); 132 } 133 } 134 135 interface FReductionMaskedOp { 136 double apply(double[] a, int idx, boolean[] mask); 137 } 138 139 interface FReductionAllMaskedOp { 140 double apply(double[] a, boolean[] mask); 141 } 142 143 static void assertReductionArraysEqualsMasked(double[] r, double rc, double[] a, boolean[] mask, 144 FReductionMaskedOp f, FReductionAllMaskedOp fa) { 145 int i = 0; 146 try { 147 Assert.assertEquals(rc, fa.apply(a, mask)); 148 for (; i < a.length; i += SPECIES.length()) { 149 Assert.assertEquals(r[i], f.apply(a, i, mask)); 150 } 151 } catch (AssertionError e) { 152 Assert.assertEquals(rc, fa.apply(a, mask), "Final result is incorrect!"); 153 Assert.assertEquals(r[i], f.apply(a, i, mask), "at index #" + i); 154 } 155 } 156 157 interface FReductionOpLong { 158 long apply(double[] a, int idx); 159 } 160 161 interface FReductionAllOpLong { 162 long apply(double[] a); 163 } 164 165 static void assertReductionLongArraysEquals(long[] r, long rc, double[] a, 166 FReductionOpLong f, FReductionAllOpLong fa) { 167 int i = 0; 168 try { 169 Assert.assertEquals(rc, fa.apply(a)); 170 for (; i < a.length; i += SPECIES.length()) { 171 Assert.assertEquals(r[i], f.apply(a, i)); 172 } 173 } catch (AssertionError e) { 174 Assert.assertEquals(rc, fa.apply(a), "Final result is incorrect!"); 175 Assert.assertEquals(r[i], f.apply(a, i), "at index #" + i); 176 } 177 } 178 179 interface FReductionMaskedOpLong { 180 long apply(double[] a, int idx, boolean[] mask); 181 } 182 183 interface FReductionAllMaskedOpLong { 184 long apply(double[] a, boolean[] mask); 185 } 186 187 static void assertReductionLongArraysEqualsMasked(long[] r, long rc, double[] a, boolean[] mask, 188 FReductionMaskedOpLong f, FReductionAllMaskedOpLong fa) { 189 int i = 0; 190 try { 191 Assert.assertEquals(rc, fa.apply(a, mask)); 192 for (; i < a.length; i += SPECIES.length()) { 193 Assert.assertEquals(r[i], f.apply(a, i, mask)); 194 } 195 } catch (AssertionError e) { 196 Assert.assertEquals(rc, fa.apply(a, mask), "Final result is incorrect!"); 197 Assert.assertEquals(r[i], f.apply(a, i, mask), "at index #" + i); 198 } 199 } 200 201 interface FBoolReductionOp { 202 boolean apply(boolean[] a, int idx); 203 } 204 205 static void assertReductionBoolArraysEquals(boolean[] r, boolean[] a, FBoolReductionOp f) { 206 int i = 0; 207 try { 208 for (; i < a.length; i += SPECIES.length()) { 209 Assert.assertEquals(r[i], f.apply(a, i)); 210 } 211 } catch (AssertionError e) { 212 Assert.assertEquals(r[i], f.apply(a, i), "at index #" + i); 213 } 214 } 215 216 interface FMaskReductionOp { 217 int apply(boolean[] a, int idx); 218 } 219 220 static void assertMaskReductionArraysEquals(int[] r, boolean[] a, FMaskReductionOp f) { 221 int i = 0; 222 try { 223 for (; i < a.length; i += SPECIES.length()) { 224 Assert.assertEquals(r[i], f.apply(a, i)); 225 } 226 } catch (AssertionError e) { 227 Assert.assertEquals(r[i], f.apply(a, i), "at index #" + i); 228 } 229 } 230 231 static void assertInsertArraysEquals(double[] r, double[] a, double element, int index, int start, int end) { 232 int i = start; 233 try { 234 for (; i < end; i += 1) { 235 if(i%SPECIES.length() == index) { 236 Assert.assertEquals(r[i], element); 237 } else { 238 Assert.assertEquals(r[i], a[i]); 239 } 240 } 241 } catch (AssertionError e) { 242 if (i%SPECIES.length() == index) { 243 Assert.assertEquals(r[i], element, "at index #" + i); 244 } else { 245 Assert.assertEquals(r[i], a[i], "at index #" + i); 246 } 247 } 248 } 249 250 static void assertRearrangeArraysEquals(double[] r, double[] a, int[] order, int vector_len) { 251 int i = 0, j = 0; 252 try { 253 for (; i < a.length; i += vector_len) { 254 for (j = 0; j < vector_len; j++) { 255 Assert.assertEquals(r[i+j], a[i+order[i+j]]); 256 } 257 } 258 } catch (AssertionError e) { 259 int idx = i + j; 260 Assert.assertEquals(r[i+j], a[i+order[i+j]], "at index #" + idx + ", input = " + a[i+order[i+j]]); 261 } 262 } 263 264 static void assertSelectFromArraysEquals(double[] r, double[] a, double[] order, int vector_len) { 265 int i = 0, j = 0; 266 try { 267 for (; i < a.length; i += vector_len) { 268 for (j = 0; j < vector_len; j++) { 269 Assert.assertEquals(r[i+j], a[i+(int)order[i+j]]); 270 } 271 } 272 } catch (AssertionError e) { 273 int idx = i + j; 274 Assert.assertEquals(r[i+j], a[i+(int)order[i+j]], "at index #" + idx + ", input = " + a[i+(int)order[i+j]]); 275 } 276 } 277 278 static void assertRearrangeArraysEquals(double[] r, double[] a, int[] order, boolean[] mask, int vector_len) { 279 int i = 0, j = 0; 280 try { 281 for (; i < a.length; i += vector_len) { 282 for (j = 0; j < vector_len; j++) { 283 if (mask[j % SPECIES.length()]) 284 Assert.assertEquals(r[i+j], a[i+order[i+j]]); 285 else 286 Assert.assertEquals(r[i+j], (double)0); 287 } 288 } 289 } catch (AssertionError e) { 290 int idx = i + j; 291 if (mask[j % SPECIES.length()]) 292 Assert.assertEquals(r[i+j], a[i+order[i+j]], "at index #" + idx + ", input = " + a[i+order[i+j]] + ", mask = " + mask[j % SPECIES.length()]); 293 else 294 Assert.assertEquals(r[i+j], (double)0, "at index #" + idx + ", input = " + a[i+order[i+j]] + ", mask = " + mask[j % SPECIES.length()]); 295 } 296 } 297 298 static void assertSelectFromArraysEquals(double[] r, double[] a, double[] order, boolean[] mask, int vector_len) { 299 int i = 0, j = 0; 300 try { 301 for (; i < a.length; i += vector_len) { 302 for (j = 0; j < vector_len; j++) { 303 if (mask[j % SPECIES.length()]) 304 Assert.assertEquals(r[i+j], a[i+(int)order[i+j]]); 305 else 306 Assert.assertEquals(r[i+j], (double)0); 307 } 308 } 309 } catch (AssertionError e) { 310 int idx = i + j; 311 if (mask[j % SPECIES.length()]) 312 Assert.assertEquals(r[i+j], a[i+(int)order[i+j]], "at index #" + idx + ", input = " + a[i+(int)order[i+j]] + ", mask = " + mask[j % SPECIES.length()]); 313 else 314 Assert.assertEquals(r[i+j], (double)0, "at index #" + idx + ", input = " + a[i+(int)order[i+j]] + ", mask = " + mask[j % SPECIES.length()]); 315 } 316 } 317 318 static void assertBroadcastArraysEquals(double[] r, double[] a) { 319 int i = 0; 320 for (; i < a.length; i += SPECIES.length()) { 321 int idx = i; 322 for (int j = idx; j < (idx + SPECIES.length()); j++) 323 a[j]=a[idx]; 324 } 325 326 try { 327 for (i = 0; i < a.length; i++) { 328 Assert.assertEquals(r[i], a[i]); 329 } 330 } catch (AssertionError e) { 331 Assert.assertEquals(r[i], a[i], "at index #" + i + ", input = " + a[i]); 332 } 333 } 334 335 interface FBinOp { 336 double apply(double a, double b); 337 } 338 339 interface FBinMaskOp { 340 double apply(double a, double b, boolean m); 341 342 static FBinMaskOp lift(FBinOp f) { 343 return (a, b, m) -> m ? f.apply(a, b) : a; 344 } 345 } 346 347 static void assertArraysEquals(double[] r, double[] a, double[] b, FBinOp f) { 348 int i = 0; 349 try { 350 for (; i < a.length; i++) { 351 Assert.assertEquals(r[i], f.apply(a[i], b[i])); 352 } 353 } catch (AssertionError e) { 354 Assert.assertEquals(r[i], f.apply(a[i], b[i]), "(" + a[i] + ", " + b[i] + ") at index #" + i); 355 } 356 } 357 358 static void assertBroadcastArraysEquals(double[] r, double[] a, double[] b, FBinOp f) { 359 int i = 0; 360 try { 361 for (; i < a.length; i++) { 362 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()])); 363 } 364 } catch (AssertionError e) { 365 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()]), 366 "(" + a[i] + ", " + b[(i / SPECIES.length()) * SPECIES.length()] + ") at index #" + i); 367 } 368 } 369 370 static void assertBroadcastLongArraysEquals(double[] r, double[] a, double[] b, FBinOp f) { 371 int i = 0; 372 try { 373 for (; i < a.length; i++) { 374 Assert.assertEquals(r[i], f.apply(a[i], (double)((long)b[(i / SPECIES.length()) * SPECIES.length()]))); 375 } 376 } catch (AssertionError e) { 377 Assert.assertEquals(r[i], f.apply(a[i], (double)((long)b[(i / SPECIES.length()) * SPECIES.length()])), 378 "(" + a[i] + ", " + b[(i / SPECIES.length()) * SPECIES.length()] + ") at index #" + i); 379 } 380 } 381 382 static void assertArraysEquals(double[] r, double[] a, double[] b, boolean[] mask, FBinOp f) { 383 assertArraysEquals(r, a, b, mask, FBinMaskOp.lift(f)); 384 } 385 386 static void assertArraysEquals(double[] r, double[] a, double[] b, boolean[] mask, FBinMaskOp f) { 387 int i = 0; 388 try { 389 for (; i < a.length; i++) { 390 Assert.assertEquals(r[i], f.apply(a[i], b[i], mask[i % SPECIES.length()])); 391 } 392 } catch (AssertionError err) { 393 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()]); 394 } 395 } 396 397 static void assertBroadcastArraysEquals(double[] r, double[] a, double[] b, boolean[] mask, FBinOp f) { 398 assertBroadcastArraysEquals(r, a, b, mask, FBinMaskOp.lift(f)); 399 } 400 401 static void assertBroadcastArraysEquals(double[] r, double[] a, double[] b, boolean[] mask, FBinMaskOp f) { 402 int i = 0; 403 try { 404 for (; i < a.length; i++) { 405 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], mask[i % SPECIES.length()])); 406 } 407 } catch (AssertionError err) { 408 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], 409 mask[i % SPECIES.length()]), "at index #" + i + ", input1 = " + a[i] + 410 ", input2 = " + b[(i / SPECIES.length()) * SPECIES.length()] + ", mask = " + 411 mask[i % SPECIES.length()]); 412 } 413 } 414 415 static void assertBroadcastLongArraysEquals(double[] r, double[] a, double[] b, boolean[] mask, FBinOp f) { 416 assertBroadcastLongArraysEquals(r, a, b, mask, FBinMaskOp.lift(f)); 417 } 418 419 static void assertBroadcastLongArraysEquals(double[] r, double[] a, double[] b, boolean[] mask, FBinMaskOp f) { 420 int i = 0; 421 try { 422 for (; i < a.length; i++) { 423 Assert.assertEquals(r[i], f.apply(a[i], (double)((long)b[(i / SPECIES.length()) * SPECIES.length()]), mask[i % SPECIES.length()])); 424 } 425 } catch (AssertionError err) { 426 Assert.assertEquals(r[i], f.apply(a[i], (double)((long)b[(i / SPECIES.length()) * SPECIES.length()]), 427 mask[i % SPECIES.length()]), "at index #" + i + ", input1 = " + a[i] + 428 ", input2 = " + b[(i / SPECIES.length()) * SPECIES.length()] + ", mask = " + 429 mask[i % SPECIES.length()]); 430 } 431 } 432 433 static void assertShiftArraysEquals(double[] r, double[] a, double[] b, FBinOp f) { 434 int i = 0; 435 int j = 0; 436 try { 437 for (; j < a.length; j += SPECIES.length()) { 438 for (i = 0; i < SPECIES.length(); i++) { 439 Assert.assertEquals(r[i+j], f.apply(a[i+j], b[j])); 440 } 441 } 442 } catch (AssertionError e) { 443 Assert.assertEquals(r[i+j], f.apply(a[i+j], b[j]), "at index #" + i + ", " + j); 444 } 445 } 446 447 static void assertShiftArraysEquals(double[] r, double[] a, double[] b, boolean[] mask, FBinOp f) { 448 assertShiftArraysEquals(r, a, b, mask, FBinMaskOp.lift(f)); 449 } 450 451 static void assertShiftArraysEquals(double[] r, double[] a, double[] b, boolean[] mask, FBinMaskOp f) { 452 int i = 0; 453 int j = 0; 454 try { 455 for (; j < a.length; j += SPECIES.length()) { 456 for (i = 0; i < SPECIES.length(); i++) { 457 Assert.assertEquals(r[i+j], f.apply(a[i+j], b[j], mask[i])); 458 } 459 } 460 } catch (AssertionError err) { 461 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]); 462 } 463 } 464 465 interface FBinConstOp { 466 double apply(double a); 467 } 468 469 interface FBinConstMaskOp { 470 double apply(double a, boolean m); 471 472 static FBinConstMaskOp lift(FBinConstOp f) { 473 return (a, m) -> m ? f.apply(a) : a; 474 } 475 } 476 477 static void assertShiftConstEquals(double[] r, double[] a, FBinConstOp f) { 478 int i = 0; 479 int j = 0; 480 try { 481 for (; j < a.length; j += SPECIES.length()) { 482 for (i = 0; i < SPECIES.length(); i++) { 483 Assert.assertEquals(r[i+j], f.apply(a[i+j])); 484 } 485 } 486 } catch (AssertionError e) { 487 Assert.assertEquals(r[i+j], f.apply(a[i+j]), "at index #" + i + ", " + j); 488 } 489 } 490 491 static void assertShiftConstEquals(double[] r, double[] a, boolean[] mask, FBinConstOp f) { 492 assertShiftConstEquals(r, a, mask, FBinConstMaskOp.lift(f)); 493 } 494 495 static void assertShiftConstEquals(double[] r, double[] a, boolean[] mask, FBinConstMaskOp f) { 496 int i = 0; 497 int j = 0; 498 try { 499 for (; j < a.length; j += SPECIES.length()) { 500 for (i = 0; i < SPECIES.length(); i++) { 501 Assert.assertEquals(r[i+j], f.apply(a[i+j], mask[i])); 502 } 503 } 504 } catch (AssertionError err) { 505 Assert.assertEquals(r[i+j], f.apply(a[i+j], mask[i]), "at index #" + i + ", input1 = " + a[i+j] + ", mask = " + mask[i]); 506 } 507 } 508 509 interface FTernOp { 510 double apply(double a, double b, double c); 511 } 512 513 interface FTernMaskOp { 514 double apply(double a, double b, double c, boolean m); 515 516 static FTernMaskOp lift(FTernOp f) { 517 return (a, b, c, m) -> m ? f.apply(a, b, c) : a; 518 } 519 } 520 521 static void assertArraysEquals(double[] r, double[] a, double[] b, double[] c, FTernOp f) { 522 int i = 0; 523 try { 524 for (; i < a.length; i++) { 525 Assert.assertEquals(r[i], f.apply(a[i], b[i], c[i])); 526 } 527 } catch (AssertionError e) { 528 Assert.assertEquals(r[i], f.apply(a[i], b[i], c[i]), "at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]); 529 } 530 } 531 532 static void assertArraysEquals(double[] r, double[] a, double[] b, double[] c, boolean[] mask, FTernOp f) { 533 assertArraysEquals(r, a, b, c, mask, FTernMaskOp.lift(f)); 534 } 535 536 static void assertArraysEquals(double[] r, double[] a, double[] b, double[] c, boolean[] mask, FTernMaskOp f) { 537 int i = 0; 538 try { 539 for (; i < a.length; i++) { 540 Assert.assertEquals(r[i], f.apply(a[i], b[i], c[i], mask[i % SPECIES.length()])); 541 } 542 } catch (AssertionError err) { 543 Assert.assertEquals(r[i], f.apply(a[i], b[i], c[i], mask[i % SPECIES.length()]), "at index #" + i + ", input1 = " + a[i] + ", input2 = " 544 + b[i] + ", input3 = " + c[i] + ", mask = " + mask[i % SPECIES.length()]); 545 } 546 } 547 548 static void assertBroadcastArraysEquals(double[] r, double[] a, double[] b, double[] c, FTernOp f) { 549 int i = 0; 550 try { 551 for (; i < a.length; i++) { 552 Assert.assertEquals(r[i], f.apply(a[i], b[i], c[(i / SPECIES.length()) * SPECIES.length()])); 553 } 554 } catch (AssertionError e) { 555 Assert.assertEquals(r[i], f.apply(a[i], b[i], c[(i / SPECIES.length()) * SPECIES.length()]), "at index #" + 556 i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + 557 c[(i / SPECIES.length()) * SPECIES.length()]); 558 } 559 } 560 561 static void assertAltBroadcastArraysEquals(double[] r, double[] a, double[] b, double[] c, FTernOp f) { 562 int i = 0; 563 try { 564 for (; i < a.length; i++) { 565 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], c[i])); 566 } 567 } catch (AssertionError e) { 568 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], c[i]), "at index #" + 569 i + ", input1 = " + a[i] + ", input2 = " + 570 b[(i / SPECIES.length()) * SPECIES.length()] + ", input3 = " + c[i]); 571 } 572 } 573 574 static void assertBroadcastArraysEquals(double[] r, double[] a, double[] b, double[] c, boolean[] mask, 575 FTernOp f) { 576 assertBroadcastArraysEquals(r, a, b, c, mask, FTernMaskOp.lift(f)); 577 } 578 579 static void assertBroadcastArraysEquals(double[] r, double[] a, double[] b, double[] c, boolean[] mask, 580 FTernMaskOp f) { 581 int i = 0; 582 try { 583 for (; i < a.length; i++) { 584 Assert.assertEquals(r[i], f.apply(a[i], b[i], c[(i / SPECIES.length()) * SPECIES.length()], 585 mask[i % SPECIES.length()])); 586 } 587 } catch (AssertionError err) { 588 Assert.assertEquals(r[i], f.apply(a[i], b[i], c[(i / SPECIES.length()) * SPECIES.length()], 589 mask[i % SPECIES.length()]), "at index #" + i + ", input1 = " + a[i] + ", input2 = " + 590 b[i] + ", input3 = " + c[(i / SPECIES.length()) * SPECIES.length()] + ", mask = " + 591 mask[i % SPECIES.length()]); 592 } 593 } 594 595 static void assertAltBroadcastArraysEquals(double[] r, double[] a, double[] b, double[] c, boolean[] mask, 596 FTernOp f) { 597 assertAltBroadcastArraysEquals(r, a, b, c, mask, FTernMaskOp.lift(f)); 598 } 599 600 static void assertAltBroadcastArraysEquals(double[] r, double[] a, double[] b, double[] c, boolean[] mask, 601 FTernMaskOp f) { 602 int i = 0; 603 try { 604 for (; i < a.length; i++) { 605 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], c[i], 606 mask[i % SPECIES.length()])); 607 } 608 } catch (AssertionError err) { 609 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], c[i], 610 mask[i % SPECIES.length()]), "at index #" + i + ", input1 = " + a[i] + 611 ", input2 = " + b[(i / SPECIES.length()) * SPECIES.length()] + 612 ", input3 = " + c[i] + ", mask = " + mask[i % SPECIES.length()]); 613 } 614 } 615 616 static void assertDoubleBroadcastArraysEquals(double[] r, double[] a, double[] b, double[] c, FTernOp f) { 617 int i = 0; 618 try { 619 for (; i < a.length; i++) { 620 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], 621 c[(i / SPECIES.length()) * SPECIES.length()])); 622 } 623 } catch (AssertionError e) { 624 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], 625 c[(i / SPECIES.length()) * SPECIES.length()]), "at index #" + i + ", input1 = " + a[i] 626 + ", input2 = " + b[(i / SPECIES.length()) * SPECIES.length()] + ", input3 = " + 627 c[(i / SPECIES.length()) * SPECIES.length()]); 628 } 629 } 630 631 static void assertDoubleBroadcastArraysEquals(double[] r, double[] a, double[] b, double[] c, boolean[] mask, 632 FTernOp f) { 633 assertDoubleBroadcastArraysEquals(r, a, b, c, mask, FTernMaskOp.lift(f)); 634 } 635 636 static void assertDoubleBroadcastArraysEquals(double[] r, double[] a, double[] b, double[] c, boolean[] mask, 637 FTernMaskOp f) { 638 int i = 0; 639 try { 640 for (; i < a.length; i++) { 641 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], 642 c[(i / SPECIES.length()) * SPECIES.length()], mask[i % SPECIES.length()])); 643 } 644 } catch (AssertionError err) { 645 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], 646 c[(i / SPECIES.length()) * SPECIES.length()], mask[i % SPECIES.length()]), "at index #" 647 + i + ", input1 = " + a[i] + ", input2 = " + b[(i / SPECIES.length()) * SPECIES.length()] + 648 ", input3 = " + c[(i / SPECIES.length()) * SPECIES.length()] + ", mask = " + 649 mask[i % SPECIES.length()]); 650 } 651 } 652 653 654 static boolean isWithin1Ulp(double actual, double expected) { 655 if (Double.isNaN(expected) && !Double.isNaN(actual)) { 656 return false; 657 } else if (!Double.isNaN(expected) && Double.isNaN(actual)) { 658 return false; 659 } 660 661 double low = Math.nextDown(expected); 662 double high = Math.nextUp(expected); 663 664 if (Double.compare(low, expected) > 0) { 665 return false; 666 } 667 668 if (Double.compare(high, expected) < 0) { 669 return false; 670 } 671 672 return true; 673 } 674 675 static void assertArraysEqualsWithinOneUlp(double[] r, double[] a, FUnOp mathf, FUnOp strictmathf) { 676 int i = 0; 677 try { 678 // Check that result is within 1 ulp of strict math or equivalent to math implementation. 679 for (; i < a.length; i++) { 680 Assert.assertTrue(Double.compare(r[i], mathf.apply(a[i])) == 0 || 681 isWithin1Ulp(r[i], strictmathf.apply(a[i]))); 682 } 683 } catch (AssertionError e) { 684 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])); 685 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])); 686 } 687 } 688 689 static void assertArraysEqualsWithinOneUlp(double[] r, double[] a, double[] b, FBinOp mathf, FBinOp strictmathf) { 690 int i = 0; 691 try { 692 // Check that result is within 1 ulp of strict math or equivalent to math implementation. 693 for (; i < a.length; i++) { 694 Assert.assertTrue(Double.compare(r[i], mathf.apply(a[i], b[i])) == 0 || 695 isWithin1Ulp(r[i], strictmathf.apply(a[i], b[i]))); 696 } 697 } catch (AssertionError e) { 698 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])); 699 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])); 700 } 701 } 702 703 static void assertBroadcastArraysEqualsWithinOneUlp(double[] r, double[] a, double[] b, 704 FBinOp mathf, FBinOp strictmathf) { 705 int i = 0; 706 try { 707 // Check that result is within 1 ulp of strict math or equivalent to math implementation. 708 for (; i < a.length; i++) { 709 Assert.assertTrue(Double.compare(r[i], 710 mathf.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()])) == 0 || 711 isWithin1Ulp(r[i], 712 strictmathf.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()]))); 713 } 714 } catch (AssertionError e) { 715 Assert.assertTrue(Double.compare(r[i], 716 mathf.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()])) == 0, 717 "at index #" + i + ", input1 = " + a[i] + ", input2 = " + 718 b[(i / SPECIES.length()) * SPECIES.length()] + ", actual = " + r[i] + 719 ", expected = " + mathf.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()])); 720 Assert.assertTrue(isWithin1Ulp(r[i], 721 strictmathf.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()])), 722 "at index #" + i + ", input1 = " + a[i] + ", input2 = " + 723 b[(i / SPECIES.length()) * SPECIES.length()] + ", actual = " + r[i] + 724 ", expected (within 1 ulp) = " + strictmathf.apply(a[i], 725 b[(i / SPECIES.length()) * SPECIES.length()])); 726 } 727 } 728 729 interface FBinArrayOp { 730 double apply(double[] a, int b); 731 } 732 733 static void assertArraysEquals(double[] r, double[] a, FBinArrayOp f) { 734 int i = 0; 735 try { 736 for (; i < a.length; i++) { 737 Assert.assertEquals(r[i], f.apply(a, i)); 738 } 739 } catch (AssertionError e) { 740 Assert.assertEquals(r[i], f.apply(a,i), "at index #" + i); 741 } 742 } 743 744 interface FGatherScatterOp { 745 double[] apply(double[] a, int ix, int[] b, int iy); 746 } 747 748 static void assertArraysEquals(double[] r, double[] a, int[] b, FGatherScatterOp f) { 749 int i = 0; 750 try { 751 for (; i < a.length; i += SPECIES.length()) { 752 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()), 753 f.apply(a, i, b, i)); 754 } 755 } catch (AssertionError e) { 756 double[] ref = f.apply(a, i, b, i); 757 double[] res = Arrays.copyOfRange(r, i, i+SPECIES.length()); 758 Assert.assertEquals(res, ref, 759 "(ref: " + Arrays.toString(ref) + ", res: " + Arrays.toString(res) + ", a: " 760 + Arrays.toString(Arrays.copyOfRange(a, i, i+SPECIES.length())) 761 + ", b: " 762 + Arrays.toString(Arrays.copyOfRange(b, i, i+SPECIES.length())) 763 + " at index #" + i); 764 } 765 } 766 767 interface FGatherMaskedOp { 768 double[] apply(double[] a, int ix, boolean[] mask, int[] b, int iy); 769 } 770 771 interface FScatterMaskedOp { 772 double[] apply(double[] r, double[] a, int ix, boolean[] mask, int[] b, int iy); 773 } 774 775 static void assertArraysEquals(double[] r, double[] a, int[] b, boolean[] mask, FGatherMaskedOp f) { 776 int i = 0; 777 try { 778 for (; i < a.length; i += SPECIES.length()) { 779 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()), 780 f.apply(a, i, mask, b, i)); 781 } 782 } catch (AssertionError e) { 783 double[] ref = f.apply(a, i, mask, b, i); 784 double[] res = Arrays.copyOfRange(r, i, i+SPECIES.length()); 785 Assert.assertEquals(res, ref, 786 "(ref: " + Arrays.toString(ref) + ", res: " + Arrays.toString(res) + ", a: " 787 + Arrays.toString(Arrays.copyOfRange(a, i, i+SPECIES.length())) 788 + ", b: " 789 + Arrays.toString(Arrays.copyOfRange(b, i, i+SPECIES.length())) 790 + ", mask: " 791 + Arrays.toString(mask) 792 + " at index #" + i); 793 } 794 } 795 796 static void assertArraysEquals(double[] r, double[] a, int[] b, boolean[] mask, FScatterMaskedOp f) { 797 int i = 0; 798 try { 799 for (; i < a.length; i += SPECIES.length()) { 800 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()), 801 f.apply(r, a, i, mask, b, i)); 802 } 803 } catch (AssertionError e) { 804 double[] ref = f.apply(r, a, i, mask, b, i); 805 double[] res = Arrays.copyOfRange(r, i, i+SPECIES.length()); 806 Assert.assertEquals(res, ref, 807 "(ref: " + Arrays.toString(ref) + ", res: " + Arrays.toString(res) + ", a: " 808 + Arrays.toString(Arrays.copyOfRange(a, i, i+SPECIES.length())) 809 + ", b: " 810 + Arrays.toString(Arrays.copyOfRange(b, i, i+SPECIES.length())) 811 + ", r: " 812 + Arrays.toString(Arrays.copyOfRange(r, i, i+SPECIES.length())) 813 + ", mask: " 814 + Arrays.toString(mask) 815 + " at index #" + i); 816 } 817 } 818 819 interface FLaneOp { 820 double[] apply(double[] a, int origin, int idx); 821 } 822 823 static void assertArraysEquals(double[] r, double[] a, int origin, FLaneOp f) { 824 int i = 0; 825 try { 826 for (; i < a.length; i += SPECIES.length()) { 827 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()), 828 f.apply(a, origin, i)); 829 } 830 } catch (AssertionError e) { 831 double[] ref = f.apply(a, origin, i); 832 double[] res = Arrays.copyOfRange(r, i, i+SPECIES.length()); 833 Assert.assertEquals(res, ref, "(ref: " + Arrays.toString(ref) 834 + ", res: " + Arrays.toString(res) 835 + "), at index #" + i); 836 } 837 } 838 839 interface FLaneBop { 840 double[] apply(double[] a, double[] b, int origin, int idx); 841 } 842 843 static void assertArraysEquals(double[] r, double[] a, double[] b, int origin, FLaneBop f) { 844 int i = 0; 845 try { 846 for (; i < a.length; i += SPECIES.length()) { 847 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()), 848 f.apply(a, b, origin, i)); 849 } 850 } catch (AssertionError e) { 851 double[] ref = f.apply(a, b, origin, i); 852 double[] res = Arrays.copyOfRange(r, i, i+SPECIES.length()); 853 Assert.assertEquals(res, ref, "(ref: " + Arrays.toString(ref) 854 + ", res: " + Arrays.toString(res) 855 + "), at index #" + i 856 + ", at origin #" + origin); 857 } 858 } 859 860 interface FLaneMaskedBop { 861 double[] apply(double[] a, double[] b, int origin, boolean[] mask, int idx); 862 } 863 864 static void assertArraysEquals(double[] r, double[] a, double[] b, int origin, boolean[] mask, FLaneMaskedBop f) { 865 int i = 0; 866 try { 867 for (; i < a.length; i += SPECIES.length()) { 868 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()), 869 f.apply(a, b, origin, mask, i)); 870 } 871 } catch (AssertionError e) { 872 double[] ref = f.apply(a, b, origin, mask, i); 873 double[] res = Arrays.copyOfRange(r, i, i+SPECIES.length()); 874 Assert.assertEquals(res, ref, "(ref: " + Arrays.toString(ref) 875 + ", res: " + Arrays.toString(res) 876 + "), at index #" + i 877 + ", at origin #" + origin); 878 } 879 } 880 881 interface FLanePartBop { 882 double[] apply(double[] a, double[] b, int origin, int part, int idx); 883 } 884 885 static void assertArraysEquals(double[] r, double[] a, double[] b, int origin, int part, FLanePartBop f) { 886 int i = 0; 887 try { 888 for (; i < a.length; i += SPECIES.length()) { 889 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()), 890 f.apply(a, b, origin, part, i)); 891 } 892 } catch (AssertionError e) { 893 double[] ref = f.apply(a, b, origin, part, i); 894 double[] res = Arrays.copyOfRange(r, i, i+SPECIES.length()); 895 Assert.assertEquals(res, ref, "(ref: " + Arrays.toString(ref) 896 + ", res: " + Arrays.toString(res) 897 + "), at index #" + i 898 + ", at origin #" + origin 899 + ", with part #" + part); 900 } 901 } 902 903 interface FLanePartMaskedBop { 904 double[] apply(double[] a, double[] b, int origin, int part, boolean[] mask, int idx); 905 } 906 907 static void assertArraysEquals(double[] r, double[] a, double[] b, int origin, int part, boolean[] mask, FLanePartMaskedBop f) { 908 int i = 0; 909 try { 910 for (; i < a.length; i += SPECIES.length()) { 911 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()), 912 f.apply(a, b, origin, part, mask, i)); 913 } 914 } catch (AssertionError e) { 915 double[] ref = f.apply(a, b, origin, part, mask, i); 916 double[] res = Arrays.copyOfRange(r, i, i+SPECIES.length()); 917 Assert.assertEquals(res, ref, "(ref: " + Arrays.toString(ref) 918 + ", res: " + Arrays.toString(res) 919 + "), at index #" + i 920 + ", at origin #" + origin 921 + ", with part #" + part); 922 } 923 } 924 925 static int intCornerCaseValue(int i) { 926 switch(i % 5) { 927 case 0: 928 return Integer.MAX_VALUE; 929 case 1: 930 return Integer.MIN_VALUE; 931 case 2: 932 return Integer.MIN_VALUE; 933 case 3: 934 return Integer.MAX_VALUE; 935 default: 936 return (int)0; 937 } 938 } 939 940 static final List<IntFunction<double[]>> INT_DOUBLE_GENERATORS = List.of( 941 withToString("double[-i * 5]", (int s) -> { 942 return fill(s * BUFFER_REPS, 943 i -> (double)(-i * 5)); 944 }), 945 withToString("double[i * 5]", (int s) -> { 946 return fill(s * BUFFER_REPS, 947 i -> (double)(i * 5)); 948 }), 949 withToString("double[i + 1]", (int s) -> { 950 return fill(s * BUFFER_REPS, 951 i -> (((double)(i + 1) == 0) ? 1 : (double)(i + 1))); 952 }), 953 withToString("double[intCornerCaseValue(i)]", (int s) -> { 954 return fill(s * BUFFER_REPS, 955 i -> (double)intCornerCaseValue(i)); 956 }) 957 ); 958 959 static void assertArraysEquals(int[] r, double[] a, int offs) { 960 int i = 0; 961 try { 962 for (; i < r.length; i++) { 963 Assert.assertEquals(r[i], (int)(a[i+offs])); 964 } 965 } catch (AssertionError e) { 966 Assert.assertEquals(r[i], (int)(a[i+offs]), "at index #" + i + ", input = " + a[i+offs]); 967 } 968 } 969 970 static long longCornerCaseValue(int i) { 971 switch(i % 5) { 972 case 0: 973 return Long.MAX_VALUE; 974 case 1: 975 return Long.MIN_VALUE; 976 case 2: 977 return Long.MIN_VALUE; 978 case 3: 979 return Long.MAX_VALUE; 980 default: 981 return (long)0; 982 } 983 } 984 985 static final List<IntFunction<double[]>> LONG_DOUBLE_GENERATORS = List.of( 986 withToString("double[-i * 5]", (int s) -> { 987 return fill(s * BUFFER_REPS, 988 i -> (double)(-i * 5)); 989 }), 990 withToString("double[i * 5]", (int s) -> { 991 return fill(s * BUFFER_REPS, 992 i -> (double)(i * 5)); 993 }), 994 withToString("double[i + 1]", (int s) -> { 995 return fill(s * BUFFER_REPS, 996 i -> (((double)(i + 1) == 0) ? 1 : (double)(i + 1))); 997 }), 998 withToString("double[cornerCaseValue(i)]", (int s) -> { 999 return fill(s * BUFFER_REPS, 1000 i -> (double)longCornerCaseValue(i)); 1001 }) 1002 ); 1003 1004 1005 static void assertArraysEquals(long[] r, double[] a, int offs) { 1006 int i = 0; 1007 try { 1008 for (; i < r.length; i++) { 1009 Assert.assertEquals(r[i], (long)(a[i+offs])); 1010 } 1011 } catch (AssertionError e) { 1012 Assert.assertEquals(r[i], (long)(a[i+offs]), "at index #" + i + ", input = " + a[i+offs]); 1013 } 1014 } 1015 1016 1017 1018 static long bits(double e) { 1019 return Double.doubleToLongBits(e); 1020 } 1021 1022 static final List<IntFunction<double[]>> DOUBLE_GENERATORS = List.of( 1023 withToString("double[-i * 5]", (int s) -> { 1024 return fill(s * BUFFER_REPS, 1025 i -> (double)(-i * 5)); 1026 }), 1027 withToString("double[i * 5]", (int s) -> { 1028 return fill(s * BUFFER_REPS, 1029 i -> (double)(i * 5)); 1030 }), 1031 withToString("double[i + 1]", (int s) -> { 1032 return fill(s * BUFFER_REPS, 1033 i -> (((double)(i + 1) == 0) ? 1 : (double)(i + 1))); 1034 }), 1035 withToString("double[cornerCaseValue(i)]", (int s) -> { 1036 return fill(s * BUFFER_REPS, 1037 i -> cornerCaseValue(i)); 1038 }) 1039 ); 1040 1041 // Create combinations of pairs 1042 // @@@ Might be sensitive to order e.g. div by 0 1043 static final List<List<IntFunction<double[]>>> DOUBLE_GENERATOR_PAIRS = 1044 Stream.of(DOUBLE_GENERATORS.get(0)). 1045 flatMap(fa -> DOUBLE_GENERATORS.stream().skip(1).map(fb -> List.of(fa, fb))). 1046 collect(Collectors.toList()); 1047 1048 @DataProvider 1049 public Object[][] boolUnaryOpProvider() { 1050 return BOOL_ARRAY_GENERATORS.stream(). 1051 map(f -> new Object[]{f}). 1052 toArray(Object[][]::new); 1053 } 1054 1055 static final List<List<IntFunction<double[]>>> DOUBLE_GENERATOR_TRIPLES = 1056 DOUBLE_GENERATOR_PAIRS.stream(). 1057 flatMap(pair -> DOUBLE_GENERATORS.stream().map(f -> List.of(pair.get(0), pair.get(1), f))). 1058 collect(Collectors.toList()); 1059 1060 @DataProvider 1061 public Object[][] doubleBinaryOpProvider() { 1062 return DOUBLE_GENERATOR_PAIRS.stream().map(List::toArray). 1063 toArray(Object[][]::new); 1064 } 1065 1066 @DataProvider 1067 public Object[][] doubleIndexedOpProvider() { 1068 return DOUBLE_GENERATOR_PAIRS.stream().map(List::toArray). 1069 toArray(Object[][]::new); 1070 } 1071 1072 @DataProvider 1073 public Object[][] doubleBinaryOpMaskProvider() { 1074 return BOOLEAN_MASK_GENERATORS.stream(). 1075 flatMap(fm -> DOUBLE_GENERATOR_PAIRS.stream().map(lfa -> { 1076 return Stream.concat(lfa.stream(), Stream.of(fm)).toArray(); 1077 })). 1078 toArray(Object[][]::new); 1079 } 1080 1081 @DataProvider 1082 public Object[][] doubleTernaryOpProvider() { 1083 return DOUBLE_GENERATOR_TRIPLES.stream().map(List::toArray). 1084 toArray(Object[][]::new); 1085 } 1086 1087 @DataProvider 1088 public Object[][] doubleTernaryOpMaskProvider() { 1089 return BOOLEAN_MASK_GENERATORS.stream(). 1090 flatMap(fm -> DOUBLE_GENERATOR_TRIPLES.stream().map(lfa -> { 1091 return Stream.concat(lfa.stream(), Stream.of(fm)).toArray(); 1092 })). 1093 toArray(Object[][]::new); 1094 } 1095 1096 @DataProvider 1097 public Object[][] doubleUnaryOpProvider() { 1098 return DOUBLE_GENERATORS.stream(). 1099 map(f -> new Object[]{f}). 1100 toArray(Object[][]::new); 1101 } 1102 1103 @DataProvider 1104 public Object[][] doubleUnaryOpMaskProvider() { 1105 return BOOLEAN_MASK_GENERATORS.stream(). 1106 flatMap(fm -> DOUBLE_GENERATORS.stream().map(fa -> { 1107 return new Object[] {fa, fm}; 1108 })). 1109 toArray(Object[][]::new); 1110 } 1111 1112 @DataProvider 1113 public Object[][] doubletoIntUnaryOpProvider() { 1114 return INT_DOUBLE_GENERATORS.stream(). 1115 map(f -> new Object[]{f}). 1116 toArray(Object[][]::new); 1117 } 1118 1119 @DataProvider 1120 public Object[][] doubletoLongUnaryOpProvider() { 1121 return LONG_DOUBLE_GENERATORS.stream(). 1122 map(f -> new Object[]{f}). 1123 toArray(Object[][]::new); 1124 } 1125 1126 @DataProvider 1127 public Object[][] maskProvider() { 1128 return BOOLEAN_MASK_GENERATORS.stream(). 1129 map(f -> new Object[]{f}). 1130 toArray(Object[][]::new); 1131 } 1132 1133 @DataProvider 1134 public Object[][] maskCompareOpProvider() { 1135 return BOOLEAN_MASK_COMPARE_GENERATOR_PAIRS.stream().map(List::toArray). 1136 toArray(Object[][]::new); 1137 } 1138 1139 @DataProvider 1140 public Object[][] shuffleProvider() { 1141 return INT_SHUFFLE_GENERATORS.stream(). 1142 map(f -> new Object[]{f}). 1143 toArray(Object[][]::new); 1144 } 1145 1146 @DataProvider 1147 public Object[][] shuffleCompareOpProvider() { 1148 return INT_SHUFFLE_COMPARE_GENERATOR_PAIRS.stream().map(List::toArray). 1149 toArray(Object[][]::new); 1150 } 1151 1152 @DataProvider 1153 public Object[][] doubleUnaryOpShuffleProvider() { 1154 return INT_SHUFFLE_GENERATORS.stream(). 1155 flatMap(fs -> DOUBLE_GENERATORS.stream().map(fa -> { 1156 return new Object[] {fa, fs}; 1157 })). 1158 toArray(Object[][]::new); 1159 } 1160 1161 @DataProvider 1162 public Object[][] doubleUnaryOpShuffleMaskProvider() { 1163 return BOOLEAN_MASK_GENERATORS.stream(). 1164 flatMap(fm -> INT_SHUFFLE_GENERATORS.stream(). 1165 flatMap(fs -> DOUBLE_GENERATORS.stream().map(fa -> { 1166 return new Object[] {fa, fs, fm}; 1167 }))). 1168 toArray(Object[][]::new); 1169 } 1170 1171 static final List<BiFunction<Integer,Integer,double[]>> DOUBLE_SHUFFLE_GENERATORS = List.of( 1172 withToStringBi("shuffle[random]", (Integer l, Integer m) -> { 1173 double[] a = new double[l]; 1174 int upper = m; 1175 for (int i = 0; i < 1; i++) { 1176 a[i] = (double)RAND.nextInt(upper); 1177 } 1178 return a; 1179 }) 1180 ); 1181 1182 @DataProvider 1183 public Object[][] doubleUnaryOpSelectFromProvider() { 1184 return DOUBLE_SHUFFLE_GENERATORS.stream(). 1185 flatMap(fs -> DOUBLE_GENERATORS.stream().map(fa -> { 1186 return new Object[] {fa, fs}; 1187 })). 1188 toArray(Object[][]::new); 1189 } 1190 1191 @DataProvider 1192 public Object[][] doubleUnaryOpSelectFromMaskProvider() { 1193 return BOOLEAN_MASK_GENERATORS.stream(). 1194 flatMap(fm -> DOUBLE_SHUFFLE_GENERATORS.stream(). 1195 flatMap(fs -> DOUBLE_GENERATORS.stream().map(fa -> { 1196 return new Object[] {fa, fs, fm}; 1197 }))). 1198 toArray(Object[][]::new); 1199 } 1200 1201 1202 static final List<IntFunction<double[]>> DOUBLE_COMPARE_GENERATORS = List.of( 1203 withToString("double[i]", (int s) -> { 1204 return fill(s * BUFFER_REPS, 1205 i -> (double)i); 1206 }), 1207 withToString("double[i - length / 2]", (int s) -> { 1208 return fill(s * BUFFER_REPS, 1209 i -> (double)(i - (s * BUFFER_REPS / 2))); 1210 }), 1211 withToString("double[i + 1]", (int s) -> { 1212 return fill(s * BUFFER_REPS, 1213 i -> (double)(i + 1)); 1214 }), 1215 withToString("double[i - 2]", (int s) -> { 1216 return fill(s * BUFFER_REPS, 1217 i -> (double)(i - 2)); 1218 }), 1219 withToString("double[zigZag(i)]", (int s) -> { 1220 return fill(s * BUFFER_REPS, 1221 i -> i%3 == 0 ? (double)i : (i%3 == 1 ? (double)(i + 1) : (double)(i - 2))); 1222 }), 1223 withToString("double[cornerCaseValue(i)]", (int s) -> { 1224 return fill(s * BUFFER_REPS, 1225 i -> cornerCaseValue(i)); 1226 }) 1227 ); 1228 1229 static final List<List<IntFunction<double[]>>> DOUBLE_TEST_GENERATOR_ARGS = 1230 DOUBLE_COMPARE_GENERATORS.stream(). 1231 map(fa -> List.of(fa)). 1232 collect(Collectors.toList()); 1233 1234 @DataProvider 1235 public Object[][] doubleTestOpProvider() { 1236 return DOUBLE_TEST_GENERATOR_ARGS.stream().map(List::toArray). 1237 toArray(Object[][]::new); 1238 } 1239 1240 @DataProvider 1241 public Object[][] doubleTestOpMaskProvider() { 1242 return BOOLEAN_MASK_GENERATORS.stream(). 1243 flatMap(fm -> DOUBLE_TEST_GENERATOR_ARGS.stream().map(lfa -> { 1244 return Stream.concat(lfa.stream(), Stream.of(fm)).toArray(); 1245 })). 1246 toArray(Object[][]::new); 1247 } 1248 1249 static final List<List<IntFunction<double[]>>> DOUBLE_COMPARE_GENERATOR_PAIRS = 1250 DOUBLE_COMPARE_GENERATORS.stream(). 1251 flatMap(fa -> DOUBLE_COMPARE_GENERATORS.stream().map(fb -> List.of(fa, fb))). 1252 collect(Collectors.toList()); 1253 1254 @DataProvider 1255 public Object[][] doubleCompareOpProvider() { 1256 return DOUBLE_COMPARE_GENERATOR_PAIRS.stream().map(List::toArray). 1257 toArray(Object[][]::new); 1258 } 1259 1260 @DataProvider 1261 public Object[][] doubleCompareOpMaskProvider() { 1262 return BOOLEAN_MASK_GENERATORS.stream(). 1263 flatMap(fm -> DOUBLE_COMPARE_GENERATOR_PAIRS.stream().map(lfa -> { 1264 return Stream.concat(lfa.stream(), Stream.of(fm)).toArray(); 1265 })). 1266 toArray(Object[][]::new); 1267 } 1268 1269 interface ToDoubleF { 1270 double apply(int i); 1271 } 1272 1273 static double[] fill(int s , ToDoubleF f) { 1274 return fill(new double[s], f); 1275 } 1276 1277 static double[] fill(double[] a, ToDoubleF f) { 1278 for (int i = 0; i < a.length; i++) { 1279 a[i] = f.apply(i); 1280 } 1281 return a; 1282 } 1283 1284 static double cornerCaseValue(int i) { 1285 switch(i % 7) { 1286 case 0: 1287 return Double.MAX_VALUE; 1288 case 1: 1289 return Double.MIN_VALUE; 1290 case 2: 1291 return Double.NEGATIVE_INFINITY; 1292 case 3: 1293 return Double.POSITIVE_INFINITY; 1294 case 4: 1295 return Double.NaN; 1296 case 5: 1297 return (double)0.0; 1298 default: 1299 return (double)-0.0; 1300 } 1301 } 1302 1303 static double get(double[] a, int i) { 1304 return (double) a[i]; 1305 } 1306 1307 static final IntFunction<double[]> fr = (vl) -> { 1308 int length = BUFFER_REPS * vl; 1309 return new double[length]; 1310 }; 1311 1312 static final IntFunction<boolean[]> fmr = (vl) -> { 1313 int length = BUFFER_REPS * vl; 1314 return new boolean[length]; 1315 }; 1316 1317 static final IntFunction<long[]> lfr = (vl) -> { 1318 int length = BUFFER_REPS * vl; 1319 return new long[length]; 1320 }; 1321 1322 1323 static boolean eq(double a, double b) { 1324 return a == b; 1325 } 1326 1327 static boolean neq(double a, double b) { 1328 return a != b; 1329 } 1330 1331 static boolean lt(double a, double b) { 1332 return a < b; 1333 } 1334 1335 static boolean le(double a, double b) { 1336 return a <= b; 1337 } 1338 1339 static boolean gt(double a, double b) { 1340 return a > b; 1341 } 1342 1343 static boolean ge(double a, double b) { 1344 return a >= b; 1345 } 1346 1347 1348 static double firstNonZero(double a, double b) { 1349 return Double.compare(a, (double) 0) != 0 ? a : b; 1350 } 1351 1352 @Test 1353 static void smokeTest1() { 1354 DoubleVector three = DoubleVector.broadcast(SPECIES, (byte)-3); 1355 DoubleVector three2 = (DoubleVector) SPECIES.broadcast(-3); 1356 assert(three.eq(three2).allTrue()); 1357 DoubleVector three3 = three2.broadcast(1).broadcast(-3); 1358 assert(three.eq(three3).allTrue()); 1359 int scale = 2; 1360 Class<?> ETYPE = double.class; 1361 if (ETYPE == double.class || ETYPE == long.class) 1362 scale = 1000000; 1363 else if (ETYPE == byte.class && SPECIES.length() >= 64) 1364 scale = 1; 1365 DoubleVector higher = three.addIndex(scale); 1366 VectorMask<Double> m = three.compare(VectorOperators.LE, higher); 1367 assert(m.allTrue()); 1368 m = higher.min((double)-1).test(VectorOperators.IS_NEGATIVE); 1369 assert(m.allTrue()); 1370 m = higher.test(VectorOperators.IS_FINITE); 1371 assert(m.allTrue()); 1372 double max = higher.reduceLanes(VectorOperators.MAX); 1373 assert(max == -3 + scale * (SPECIES.length()-1)); 1374 } 1375 1376 private static double[] 1377 bothToArray(DoubleVector a, DoubleVector b) { 1378 double[] r = new double[a.length() + b.length()]; 1379 a.intoArray(r, 0); 1380 b.intoArray(r, a.length()); 1381 return r; 1382 } 1383 1384 @Test 1385 static void smokeTest2() { 1386 // Do some zipping and shuffling. 1387 DoubleVector io = (DoubleVector) SPECIES.broadcast(0).addIndex(1); 1388 DoubleVector io2 = (DoubleVector) VectorShuffle.iota(SPECIES,0,1,false).toVector(); 1389 Assert.assertEquals(io, io2); 1390 DoubleVector a = io.add((double)1); //[1,2] 1391 DoubleVector b = a.neg(); //[-1,-2] 1392 double[] abValues = bothToArray(a,b); //[1,2,-1,-2] 1393 VectorShuffle<Double> zip0 = VectorShuffle.makeZip(SPECIES, 0); 1394 VectorShuffle<Double> zip1 = VectorShuffle.makeZip(SPECIES, 1); 1395 DoubleVector zab0 = a.rearrange(zip0,b); //[1,-1] 1396 DoubleVector zab1 = a.rearrange(zip1,b); //[2,-2] 1397 double[] zabValues = bothToArray(zab0, zab1); //[1,-1,2,-2] 1398 // manually zip 1399 double[] manual = new double[zabValues.length]; 1400 for (int i = 0; i < manual.length; i += 2) { 1401 manual[i+0] = abValues[i/2]; 1402 manual[i+1] = abValues[a.length() + i/2]; 1403 } 1404 Assert.assertEquals(Arrays.toString(zabValues), Arrays.toString(manual)); 1405 VectorShuffle<Double> unz0 = VectorShuffle.makeUnzip(SPECIES, 0); 1406 VectorShuffle<Double> unz1 = VectorShuffle.makeUnzip(SPECIES, 1); 1407 DoubleVector uab0 = zab0.rearrange(unz0,zab1); 1408 DoubleVector uab1 = zab0.rearrange(unz1,zab1); 1409 double[] abValues1 = bothToArray(uab0, uab1); 1410 Assert.assertEquals(Arrays.toString(abValues), Arrays.toString(abValues1)); 1411 } 1412 1413 static void iotaShuffle() { 1414 DoubleVector io = (DoubleVector) SPECIES.broadcast(0).addIndex(1); 1415 DoubleVector io2 = (DoubleVector) VectorShuffle.iota(SPECIES, 0 , 1, false).toVector(); 1416 Assert.assertEquals(io, io2); 1417 } 1418 1419 @Test 1420 // Test all shuffle related operations. 1421 static void shuffleTest() { 1422 // To test backend instructions, make sure that C2 is used. 1423 for (int loop = 0; loop < INVOC_COUNT * INVOC_COUNT; loop++) { 1424 iotaShuffle(); 1425 } 1426 } 1427 1428 @Test 1429 void viewAsIntegeralLanesTest() { 1430 Vector<?> asIntegral = SPECIES.zero().viewAsIntegralLanes(); 1431 VectorSpecies<?> asIntegralSpecies = asIntegral.species(); 1432 Assert.assertNotEquals(asIntegralSpecies.elementType(), SPECIES.elementType()); 1433 Assert.assertEquals(asIntegralSpecies.vectorShape(), SPECIES.vectorShape()); 1434 Assert.assertEquals(asIntegralSpecies.length(), SPECIES.length()); 1435 Assert.assertEquals(asIntegral.viewAsFloatingLanes().species(), SPECIES); 1436 } 1437 1438 @Test 1439 void viewAsFloatingLanesTest() { 1440 Vector<?> asFloating = SPECIES.zero().viewAsFloatingLanes(); 1441 Assert.assertEquals(asFloating.species(), SPECIES); 1442 } 1443 1444 static double ADD(double a, double b) { 1445 return (double)(a + b); 1446 } 1447 1448 @Test(dataProvider = "doubleBinaryOpProvider") 1449 static void ADDDouble256VectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) { 1450 double[] a = fa.apply(SPECIES.length()); 1451 double[] b = fb.apply(SPECIES.length()); 1452 double[] r = fr.apply(SPECIES.length()); 1453 1454 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1455 for (int i = 0; i < a.length; i += SPECIES.length()) { 1456 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 1457 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i); 1458 av.lanewise(VectorOperators.ADD, bv).intoArray(r, i); 1459 } 1460 } 1461 1462 assertArraysEquals(r, a, b, Double256VectorTests::ADD); 1463 } 1464 static double add(double a, double b) { 1465 return (double)(a + b); 1466 } 1467 1468 @Test(dataProvider = "doubleBinaryOpProvider") 1469 static void addDouble256VectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) { 1470 double[] a = fa.apply(SPECIES.length()); 1471 double[] b = fb.apply(SPECIES.length()); 1472 double[] r = fr.apply(SPECIES.length()); 1473 1474 for (int i = 0; i < a.length; i += SPECIES.length()) { 1475 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 1476 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i); 1477 av.add(bv).intoArray(r, i); 1478 } 1479 1480 assertArraysEquals(r, a, b, Double256VectorTests::add); 1481 } 1482 1483 @Test(dataProvider = "doubleBinaryOpMaskProvider") 1484 static void ADDDouble256VectorTestsMasked(IntFunction<double[]> fa, IntFunction<double[]> fb, 1485 IntFunction<boolean[]> fm) { 1486 double[] a = fa.apply(SPECIES.length()); 1487 double[] b = fb.apply(SPECIES.length()); 1488 double[] r = fr.apply(SPECIES.length()); 1489 boolean[] mask = fm.apply(SPECIES.length()); 1490 VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1491 1492 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1493 for (int i = 0; i < a.length; i += SPECIES.length()) { 1494 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 1495 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i); 1496 av.lanewise(VectorOperators.ADD, bv, vmask).intoArray(r, i); 1497 } 1498 } 1499 1500 assertArraysEquals(r, a, b, mask, Double256VectorTests::ADD); 1501 } 1502 1503 @Test(dataProvider = "doubleBinaryOpMaskProvider") 1504 static void addDouble256VectorTestsMasked(IntFunction<double[]> fa, IntFunction<double[]> fb, 1505 IntFunction<boolean[]> fm) { 1506 double[] a = fa.apply(SPECIES.length()); 1507 double[] b = fb.apply(SPECIES.length()); 1508 double[] r = fr.apply(SPECIES.length()); 1509 boolean[] mask = fm.apply(SPECIES.length()); 1510 VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1511 1512 for (int i = 0; i < a.length; i += SPECIES.length()) { 1513 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 1514 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i); 1515 av.add(bv, vmask).intoArray(r, i); 1516 } 1517 1518 assertArraysEquals(r, a, b, mask, Double256VectorTests::add); 1519 } 1520 static double SUB(double a, double b) { 1521 return (double)(a - b); 1522 } 1523 1524 @Test(dataProvider = "doubleBinaryOpProvider") 1525 static void SUBDouble256VectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) { 1526 double[] a = fa.apply(SPECIES.length()); 1527 double[] b = fb.apply(SPECIES.length()); 1528 double[] r = fr.apply(SPECIES.length()); 1529 1530 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1531 for (int i = 0; i < a.length; i += SPECIES.length()) { 1532 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 1533 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i); 1534 av.lanewise(VectorOperators.SUB, bv).intoArray(r, i); 1535 } 1536 } 1537 1538 assertArraysEquals(r, a, b, Double256VectorTests::SUB); 1539 } 1540 static double sub(double a, double b) { 1541 return (double)(a - b); 1542 } 1543 1544 @Test(dataProvider = "doubleBinaryOpProvider") 1545 static void subDouble256VectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) { 1546 double[] a = fa.apply(SPECIES.length()); 1547 double[] b = fb.apply(SPECIES.length()); 1548 double[] r = fr.apply(SPECIES.length()); 1549 1550 for (int i = 0; i < a.length; i += SPECIES.length()) { 1551 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 1552 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i); 1553 av.sub(bv).intoArray(r, i); 1554 } 1555 1556 assertArraysEquals(r, a, b, Double256VectorTests::sub); 1557 } 1558 1559 @Test(dataProvider = "doubleBinaryOpMaskProvider") 1560 static void SUBDouble256VectorTestsMasked(IntFunction<double[]> fa, IntFunction<double[]> fb, 1561 IntFunction<boolean[]> fm) { 1562 double[] a = fa.apply(SPECIES.length()); 1563 double[] b = fb.apply(SPECIES.length()); 1564 double[] r = fr.apply(SPECIES.length()); 1565 boolean[] mask = fm.apply(SPECIES.length()); 1566 VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1567 1568 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1569 for (int i = 0; i < a.length; i += SPECIES.length()) { 1570 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 1571 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i); 1572 av.lanewise(VectorOperators.SUB, bv, vmask).intoArray(r, i); 1573 } 1574 } 1575 1576 assertArraysEquals(r, a, b, mask, Double256VectorTests::SUB); 1577 } 1578 1579 @Test(dataProvider = "doubleBinaryOpMaskProvider") 1580 static void subDouble256VectorTestsMasked(IntFunction<double[]> fa, IntFunction<double[]> fb, 1581 IntFunction<boolean[]> fm) { 1582 double[] a = fa.apply(SPECIES.length()); 1583 double[] b = fb.apply(SPECIES.length()); 1584 double[] r = fr.apply(SPECIES.length()); 1585 boolean[] mask = fm.apply(SPECIES.length()); 1586 VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1587 1588 for (int i = 0; i < a.length; i += SPECIES.length()) { 1589 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 1590 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i); 1591 av.sub(bv, vmask).intoArray(r, i); 1592 } 1593 1594 assertArraysEquals(r, a, b, mask, Double256VectorTests::sub); 1595 } 1596 static double MUL(double a, double b) { 1597 return (double)(a * b); 1598 } 1599 1600 @Test(dataProvider = "doubleBinaryOpProvider") 1601 static void MULDouble256VectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) { 1602 double[] a = fa.apply(SPECIES.length()); 1603 double[] b = fb.apply(SPECIES.length()); 1604 double[] r = fr.apply(SPECIES.length()); 1605 1606 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1607 for (int i = 0; i < a.length; i += SPECIES.length()) { 1608 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 1609 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i); 1610 av.lanewise(VectorOperators.MUL, bv).intoArray(r, i); 1611 } 1612 } 1613 1614 assertArraysEquals(r, a, b, Double256VectorTests::MUL); 1615 } 1616 static double mul(double a, double b) { 1617 return (double)(a * b); 1618 } 1619 1620 @Test(dataProvider = "doubleBinaryOpProvider") 1621 static void mulDouble256VectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) { 1622 double[] a = fa.apply(SPECIES.length()); 1623 double[] b = fb.apply(SPECIES.length()); 1624 double[] r = fr.apply(SPECIES.length()); 1625 1626 for (int i = 0; i < a.length; i += SPECIES.length()) { 1627 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 1628 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i); 1629 av.mul(bv).intoArray(r, i); 1630 } 1631 1632 assertArraysEquals(r, a, b, Double256VectorTests::mul); 1633 } 1634 1635 @Test(dataProvider = "doubleBinaryOpMaskProvider") 1636 static void MULDouble256VectorTestsMasked(IntFunction<double[]> fa, IntFunction<double[]> fb, 1637 IntFunction<boolean[]> fm) { 1638 double[] a = fa.apply(SPECIES.length()); 1639 double[] b = fb.apply(SPECIES.length()); 1640 double[] r = fr.apply(SPECIES.length()); 1641 boolean[] mask = fm.apply(SPECIES.length()); 1642 VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1643 1644 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1645 for (int i = 0; i < a.length; i += SPECIES.length()) { 1646 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 1647 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i); 1648 av.lanewise(VectorOperators.MUL, bv, vmask).intoArray(r, i); 1649 } 1650 } 1651 1652 assertArraysEquals(r, a, b, mask, Double256VectorTests::MUL); 1653 } 1654 1655 @Test(dataProvider = "doubleBinaryOpMaskProvider") 1656 static void mulDouble256VectorTestsMasked(IntFunction<double[]> fa, IntFunction<double[]> fb, 1657 IntFunction<boolean[]> fm) { 1658 double[] a = fa.apply(SPECIES.length()); 1659 double[] b = fb.apply(SPECIES.length()); 1660 double[] r = fr.apply(SPECIES.length()); 1661 boolean[] mask = fm.apply(SPECIES.length()); 1662 VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1663 1664 for (int i = 0; i < a.length; i += SPECIES.length()) { 1665 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 1666 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i); 1667 av.mul(bv, vmask).intoArray(r, i); 1668 } 1669 1670 assertArraysEquals(r, a, b, mask, Double256VectorTests::mul); 1671 } 1672 1673 static double DIV(double a, double b) { 1674 return (double)(a / b); 1675 } 1676 1677 @Test(dataProvider = "doubleBinaryOpProvider") 1678 static void DIVDouble256VectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) { 1679 double[] a = fa.apply(SPECIES.length()); 1680 double[] b = fb.apply(SPECIES.length()); 1681 double[] r = fr.apply(SPECIES.length()); 1682 1683 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1684 for (int i = 0; i < a.length; i += SPECIES.length()) { 1685 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 1686 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i); 1687 av.lanewise(VectorOperators.DIV, bv).intoArray(r, i); 1688 } 1689 } 1690 1691 assertArraysEquals(r, a, b, Double256VectorTests::DIV); 1692 } 1693 static double div(double a, double b) { 1694 return (double)(a / b); 1695 } 1696 1697 @Test(dataProvider = "doubleBinaryOpProvider") 1698 static void divDouble256VectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) { 1699 double[] a = fa.apply(SPECIES.length()); 1700 double[] b = fb.apply(SPECIES.length()); 1701 double[] r = fr.apply(SPECIES.length()); 1702 1703 for (int i = 0; i < a.length; i += SPECIES.length()) { 1704 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 1705 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i); 1706 av.div(bv).intoArray(r, i); 1707 } 1708 1709 assertArraysEquals(r, a, b, Double256VectorTests::div); 1710 } 1711 1712 1713 1714 @Test(dataProvider = "doubleBinaryOpMaskProvider") 1715 static void DIVDouble256VectorTestsMasked(IntFunction<double[]> fa, IntFunction<double[]> fb, 1716 IntFunction<boolean[]> fm) { 1717 double[] a = fa.apply(SPECIES.length()); 1718 double[] b = fb.apply(SPECIES.length()); 1719 double[] r = fr.apply(SPECIES.length()); 1720 boolean[] mask = fm.apply(SPECIES.length()); 1721 VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1722 1723 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1724 for (int i = 0; i < a.length; i += SPECIES.length()) { 1725 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 1726 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i); 1727 av.lanewise(VectorOperators.DIV, bv, vmask).intoArray(r, i); 1728 } 1729 } 1730 1731 assertArraysEquals(r, a, b, mask, Double256VectorTests::DIV); 1732 } 1733 1734 @Test(dataProvider = "doubleBinaryOpMaskProvider") 1735 static void divDouble256VectorTestsMasked(IntFunction<double[]> fa, IntFunction<double[]> fb, 1736 IntFunction<boolean[]> fm) { 1737 double[] a = fa.apply(SPECIES.length()); 1738 double[] b = fb.apply(SPECIES.length()); 1739 double[] r = fr.apply(SPECIES.length()); 1740 boolean[] mask = fm.apply(SPECIES.length()); 1741 VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1742 1743 for (int i = 0; i < a.length; i += SPECIES.length()) { 1744 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 1745 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i); 1746 av.div(bv, vmask).intoArray(r, i); 1747 } 1748 1749 assertArraysEquals(r, a, b, mask, Double256VectorTests::div); 1750 } 1751 1752 1753 1754 static double FIRST_NONZERO(double a, double b) { 1755 return (double)(Double.doubleToLongBits(a)!=0?a:b); 1756 } 1757 1758 @Test(dataProvider = "doubleBinaryOpProvider") 1759 static void FIRST_NONZERODouble256VectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) { 1760 double[] a = fa.apply(SPECIES.length()); 1761 double[] b = fb.apply(SPECIES.length()); 1762 double[] r = fr.apply(SPECIES.length()); 1763 1764 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1765 for (int i = 0; i < a.length; i += SPECIES.length()) { 1766 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 1767 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i); 1768 av.lanewise(VectorOperators.FIRST_NONZERO, bv).intoArray(r, i); 1769 } 1770 } 1771 1772 assertArraysEquals(r, a, b, Double256VectorTests::FIRST_NONZERO); 1773 } 1774 1775 @Test(dataProvider = "doubleBinaryOpMaskProvider") 1776 static void FIRST_NONZERODouble256VectorTestsMasked(IntFunction<double[]> fa, IntFunction<double[]> fb, 1777 IntFunction<boolean[]> fm) { 1778 double[] a = fa.apply(SPECIES.length()); 1779 double[] b = fb.apply(SPECIES.length()); 1780 double[] r = fr.apply(SPECIES.length()); 1781 boolean[] mask = fm.apply(SPECIES.length()); 1782 VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1783 1784 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1785 for (int i = 0; i < a.length; i += SPECIES.length()) { 1786 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 1787 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i); 1788 av.lanewise(VectorOperators.FIRST_NONZERO, bv, vmask).intoArray(r, i); 1789 } 1790 } 1791 1792 assertArraysEquals(r, a, b, mask, Double256VectorTests::FIRST_NONZERO); 1793 } 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 @Test(dataProvider = "doubleBinaryOpProvider") 1804 static void addDouble256VectorTestsBroadcastSmokeTest(IntFunction<double[]> fa, IntFunction<double[]> fb) { 1805 double[] a = fa.apply(SPECIES.length()); 1806 double[] b = fb.apply(SPECIES.length()); 1807 double[] r = fr.apply(SPECIES.length()); 1808 1809 for (int i = 0; i < a.length; i += SPECIES.length()) { 1810 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 1811 av.add(b[i]).intoArray(r, i); 1812 } 1813 1814 assertBroadcastArraysEquals(r, a, b, Double256VectorTests::add); 1815 } 1816 1817 @Test(dataProvider = "doubleBinaryOpMaskProvider") 1818 static void addDouble256VectorTestsBroadcastMaskedSmokeTest(IntFunction<double[]> fa, IntFunction<double[]> fb, 1819 IntFunction<boolean[]> fm) { 1820 double[] a = fa.apply(SPECIES.length()); 1821 double[] b = fb.apply(SPECIES.length()); 1822 double[] r = fr.apply(SPECIES.length()); 1823 boolean[] mask = fm.apply(SPECIES.length()); 1824 VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1825 1826 for (int i = 0; i < a.length; i += SPECIES.length()) { 1827 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 1828 av.add(b[i], vmask).intoArray(r, i); 1829 } 1830 1831 assertBroadcastArraysEquals(r, a, b, mask, Double256VectorTests::add); 1832 } 1833 1834 @Test(dataProvider = "doubleBinaryOpProvider") 1835 static void subDouble256VectorTestsBroadcastSmokeTest(IntFunction<double[]> fa, IntFunction<double[]> fb) { 1836 double[] a = fa.apply(SPECIES.length()); 1837 double[] b = fb.apply(SPECIES.length()); 1838 double[] r = fr.apply(SPECIES.length()); 1839 1840 for (int i = 0; i < a.length; i += SPECIES.length()) { 1841 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 1842 av.sub(b[i]).intoArray(r, i); 1843 } 1844 1845 assertBroadcastArraysEquals(r, a, b, Double256VectorTests::sub); 1846 } 1847 1848 @Test(dataProvider = "doubleBinaryOpMaskProvider") 1849 static void subDouble256VectorTestsBroadcastMaskedSmokeTest(IntFunction<double[]> fa, IntFunction<double[]> fb, 1850 IntFunction<boolean[]> fm) { 1851 double[] a = fa.apply(SPECIES.length()); 1852 double[] b = fb.apply(SPECIES.length()); 1853 double[] r = fr.apply(SPECIES.length()); 1854 boolean[] mask = fm.apply(SPECIES.length()); 1855 VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1856 1857 for (int i = 0; i < a.length; i += SPECIES.length()) { 1858 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 1859 av.sub(b[i], vmask).intoArray(r, i); 1860 } 1861 1862 assertBroadcastArraysEquals(r, a, b, mask, Double256VectorTests::sub); 1863 } 1864 1865 @Test(dataProvider = "doubleBinaryOpProvider") 1866 static void mulDouble256VectorTestsBroadcastSmokeTest(IntFunction<double[]> fa, IntFunction<double[]> fb) { 1867 double[] a = fa.apply(SPECIES.length()); 1868 double[] b = fb.apply(SPECIES.length()); 1869 double[] r = fr.apply(SPECIES.length()); 1870 1871 for (int i = 0; i < a.length; i += SPECIES.length()) { 1872 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 1873 av.mul(b[i]).intoArray(r, i); 1874 } 1875 1876 assertBroadcastArraysEquals(r, a, b, Double256VectorTests::mul); 1877 } 1878 1879 @Test(dataProvider = "doubleBinaryOpMaskProvider") 1880 static void mulDouble256VectorTestsBroadcastMaskedSmokeTest(IntFunction<double[]> fa, IntFunction<double[]> fb, 1881 IntFunction<boolean[]> fm) { 1882 double[] a = fa.apply(SPECIES.length()); 1883 double[] b = fb.apply(SPECIES.length()); 1884 double[] r = fr.apply(SPECIES.length()); 1885 boolean[] mask = fm.apply(SPECIES.length()); 1886 VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1887 1888 for (int i = 0; i < a.length; i += SPECIES.length()) { 1889 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 1890 av.mul(b[i], vmask).intoArray(r, i); 1891 } 1892 1893 assertBroadcastArraysEquals(r, a, b, mask, Double256VectorTests::mul); 1894 } 1895 1896 1897 @Test(dataProvider = "doubleBinaryOpProvider") 1898 static void divDouble256VectorTestsBroadcastSmokeTest(IntFunction<double[]> fa, IntFunction<double[]> fb) { 1899 double[] a = fa.apply(SPECIES.length()); 1900 double[] b = fb.apply(SPECIES.length()); 1901 double[] r = fr.apply(SPECIES.length()); 1902 1903 for (int i = 0; i < a.length; i += SPECIES.length()) { 1904 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 1905 av.div(b[i]).intoArray(r, i); 1906 } 1907 1908 assertBroadcastArraysEquals(r, a, b, Double256VectorTests::div); 1909 } 1910 1911 1912 1913 @Test(dataProvider = "doubleBinaryOpMaskProvider") 1914 static void divDouble256VectorTestsBroadcastMaskedSmokeTest(IntFunction<double[]> fa, IntFunction<double[]> fb, 1915 IntFunction<boolean[]> fm) { 1916 double[] a = fa.apply(SPECIES.length()); 1917 double[] b = fb.apply(SPECIES.length()); 1918 double[] r = fr.apply(SPECIES.length()); 1919 boolean[] mask = fm.apply(SPECIES.length()); 1920 VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1921 1922 for (int i = 0; i < a.length; i += SPECIES.length()) { 1923 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 1924 av.div(b[i], vmask).intoArray(r, i); 1925 } 1926 1927 assertBroadcastArraysEquals(r, a, b, mask, Double256VectorTests::div); 1928 } 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 @Test(dataProvider = "doubleBinaryOpProvider") 1940 static void ADDDouble256VectorTestsBroadcastLongSmokeTest(IntFunction<double[]> fa, IntFunction<double[]> fb) { 1941 double[] a = fa.apply(SPECIES.length()); 1942 double[] b = fb.apply(SPECIES.length()); 1943 double[] r = fr.apply(SPECIES.length()); 1944 1945 for (int i = 0; i < a.length; i += SPECIES.length()) { 1946 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 1947 av.lanewise(VectorOperators.ADD, (long)b[i]).intoArray(r, i); 1948 } 1949 1950 assertBroadcastLongArraysEquals(r, a, b, Double256VectorTests::ADD); 1951 } 1952 1953 @Test(dataProvider = "doubleBinaryOpMaskProvider") 1954 static void ADDDouble256VectorTestsBroadcastMaskedLongSmokeTest(IntFunction<double[]> fa, IntFunction<double[]> fb, 1955 IntFunction<boolean[]> fm) { 1956 double[] a = fa.apply(SPECIES.length()); 1957 double[] b = fb.apply(SPECIES.length()); 1958 double[] r = fr.apply(SPECIES.length()); 1959 boolean[] mask = fm.apply(SPECIES.length()); 1960 VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1961 1962 for (int i = 0; i < a.length; i += SPECIES.length()) { 1963 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 1964 av.lanewise(VectorOperators.ADD, (long)b[i], vmask).intoArray(r, i); 1965 } 1966 1967 assertBroadcastLongArraysEquals(r, a, b, mask, Double256VectorTests::ADD); 1968 } 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 static double MIN(double a, double b) { 2028 return (double)(Math.min(a, b)); 2029 } 2030 2031 @Test(dataProvider = "doubleBinaryOpProvider") 2032 static void MINDouble256VectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) { 2033 double[] a = fa.apply(SPECIES.length()); 2034 double[] b = fb.apply(SPECIES.length()); 2035 double[] r = fr.apply(SPECIES.length()); 2036 2037 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2038 for (int i = 0; i < a.length; i += SPECIES.length()) { 2039 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 2040 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i); 2041 av.lanewise(VectorOperators.MIN, bv).intoArray(r, i); 2042 } 2043 } 2044 2045 assertArraysEquals(r, a, b, Double256VectorTests::MIN); 2046 } 2047 static double min(double a, double b) { 2048 return (double)(Math.min(a, b)); 2049 } 2050 2051 @Test(dataProvider = "doubleBinaryOpProvider") 2052 static void minDouble256VectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) { 2053 double[] a = fa.apply(SPECIES.length()); 2054 double[] b = fb.apply(SPECIES.length()); 2055 double[] r = fr.apply(SPECIES.length()); 2056 2057 for (int i = 0; i < a.length; i += SPECIES.length()) { 2058 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 2059 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i); 2060 av.min(bv).intoArray(r, i); 2061 } 2062 2063 assertArraysEquals(r, a, b, Double256VectorTests::min); 2064 } 2065 static double MAX(double a, double b) { 2066 return (double)(Math.max(a, b)); 2067 } 2068 2069 @Test(dataProvider = "doubleBinaryOpProvider") 2070 static void MAXDouble256VectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) { 2071 double[] a = fa.apply(SPECIES.length()); 2072 double[] b = fb.apply(SPECIES.length()); 2073 double[] r = fr.apply(SPECIES.length()); 2074 2075 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2076 for (int i = 0; i < a.length; i += SPECIES.length()) { 2077 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 2078 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i); 2079 av.lanewise(VectorOperators.MAX, bv).intoArray(r, i); 2080 } 2081 } 2082 2083 assertArraysEquals(r, a, b, Double256VectorTests::MAX); 2084 } 2085 static double max(double a, double b) { 2086 return (double)(Math.max(a, b)); 2087 } 2088 2089 @Test(dataProvider = "doubleBinaryOpProvider") 2090 static void maxDouble256VectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) { 2091 double[] a = fa.apply(SPECIES.length()); 2092 double[] b = fb.apply(SPECIES.length()); 2093 double[] r = fr.apply(SPECIES.length()); 2094 2095 for (int i = 0; i < a.length; i += SPECIES.length()) { 2096 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 2097 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i); 2098 av.max(bv).intoArray(r, i); 2099 } 2100 2101 assertArraysEquals(r, a, b, Double256VectorTests::max); 2102 } 2103 2104 @Test(dataProvider = "doubleBinaryOpProvider") 2105 static void MINDouble256VectorTestsBroadcastSmokeTest(IntFunction<double[]> fa, IntFunction<double[]> fb) { 2106 double[] a = fa.apply(SPECIES.length()); 2107 double[] b = fb.apply(SPECIES.length()); 2108 double[] r = fr.apply(SPECIES.length()); 2109 2110 for (int i = 0; i < a.length; i += SPECIES.length()) { 2111 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 2112 av.lanewise(VectorOperators.MIN, b[i]).intoArray(r, i); 2113 } 2114 2115 assertBroadcastArraysEquals(r, a, b, Double256VectorTests::MIN); 2116 } 2117 2118 @Test(dataProvider = "doubleBinaryOpProvider") 2119 static void minDouble256VectorTestsBroadcastSmokeTest(IntFunction<double[]> fa, IntFunction<double[]> fb) { 2120 double[] a = fa.apply(SPECIES.length()); 2121 double[] b = fb.apply(SPECIES.length()); 2122 double[] r = fr.apply(SPECIES.length()); 2123 2124 for (int i = 0; i < a.length; i += SPECIES.length()) { 2125 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 2126 av.min(b[i]).intoArray(r, i); 2127 } 2128 2129 assertBroadcastArraysEquals(r, a, b, Double256VectorTests::min); 2130 } 2131 2132 @Test(dataProvider = "doubleBinaryOpProvider") 2133 static void MAXDouble256VectorTestsBroadcastSmokeTest(IntFunction<double[]> fa, IntFunction<double[]> fb) { 2134 double[] a = fa.apply(SPECIES.length()); 2135 double[] b = fb.apply(SPECIES.length()); 2136 double[] r = fr.apply(SPECIES.length()); 2137 2138 for (int i = 0; i < a.length; i += SPECIES.length()) { 2139 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 2140 av.lanewise(VectorOperators.MAX, b[i]).intoArray(r, i); 2141 } 2142 2143 assertBroadcastArraysEquals(r, a, b, Double256VectorTests::MAX); 2144 } 2145 2146 @Test(dataProvider = "doubleBinaryOpProvider") 2147 static void maxDouble256VectorTestsBroadcastSmokeTest(IntFunction<double[]> fa, IntFunction<double[]> fb) { 2148 double[] a = fa.apply(SPECIES.length()); 2149 double[] b = fb.apply(SPECIES.length()); 2150 double[] r = fr.apply(SPECIES.length()); 2151 2152 for (int i = 0; i < a.length; i += SPECIES.length()) { 2153 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 2154 av.max(b[i]).intoArray(r, i); 2155 } 2156 2157 assertBroadcastArraysEquals(r, a, b, Double256VectorTests::max); 2158 } 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 static double ADDReduce(double[] a, int idx) { 2172 double res = 0; 2173 for (int i = idx; i < (idx + SPECIES.length()); i++) { 2174 res += a[i]; 2175 } 2176 2177 return res; 2178 } 2179 2180 static double ADDReduceAll(double[] a) { 2181 double res = 0; 2182 for (int i = 0; i < a.length; i += SPECIES.length()) { 2183 res += ADDReduce(a, i); 2184 } 2185 2186 return res; 2187 } 2188 @Test(dataProvider = "doubleUnaryOpProvider") 2189 static void ADDReduceDouble256VectorTests(IntFunction<double[]> fa) { 2190 double[] a = fa.apply(SPECIES.length()); 2191 double[] r = fr.apply(SPECIES.length()); 2192 double ra = 0; 2193 2194 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2195 for (int i = 0; i < a.length; i += SPECIES.length()) { 2196 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 2197 r[i] = av.reduceLanes(VectorOperators.ADD); 2198 } 2199 } 2200 2201 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2202 ra = 0; 2203 for (int i = 0; i < a.length; i += SPECIES.length()) { 2204 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 2205 ra += av.reduceLanes(VectorOperators.ADD); 2206 } 2207 } 2208 2209 assertReductionArraysEquals(r, ra, a, 2210 Double256VectorTests::ADDReduce, Double256VectorTests::ADDReduceAll); 2211 } 2212 static double ADDReduceMasked(double[] a, int idx, boolean[] mask) { 2213 double res = 0; 2214 for (int i = idx; i < (idx + SPECIES.length()); i++) { 2215 if (mask[i % SPECIES.length()]) 2216 res += a[i]; 2217 } 2218 2219 return res; 2220 } 2221 2222 static double ADDReduceAllMasked(double[] a, boolean[] mask) { 2223 double res = 0; 2224 for (int i = 0; i < a.length; i += SPECIES.length()) { 2225 res += ADDReduceMasked(a, i, mask); 2226 } 2227 2228 return res; 2229 } 2230 @Test(dataProvider = "doubleUnaryOpMaskProvider") 2231 static void ADDReduceDouble256VectorTestsMasked(IntFunction<double[]> fa, IntFunction<boolean[]> fm) { 2232 double[] a = fa.apply(SPECIES.length()); 2233 double[] r = fr.apply(SPECIES.length()); 2234 boolean[] mask = fm.apply(SPECIES.length()); 2235 VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2236 double ra = 0; 2237 2238 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2239 for (int i = 0; i < a.length; i += SPECIES.length()) { 2240 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 2241 r[i] = av.reduceLanes(VectorOperators.ADD, vmask); 2242 } 2243 } 2244 2245 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2246 ra = 0; 2247 for (int i = 0; i < a.length; i += SPECIES.length()) { 2248 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 2249 ra += av.reduceLanes(VectorOperators.ADD, vmask); 2250 } 2251 } 2252 2253 assertReductionArraysEqualsMasked(r, ra, a, mask, 2254 Double256VectorTests::ADDReduceMasked, Double256VectorTests::ADDReduceAllMasked); 2255 } 2256 static double MULReduce(double[] a, int idx) { 2257 double res = 1; 2258 for (int i = idx; i < (idx + SPECIES.length()); i++) { 2259 res *= a[i]; 2260 } 2261 2262 return res; 2263 } 2264 2265 static double MULReduceAll(double[] a) { 2266 double res = 1; 2267 for (int i = 0; i < a.length; i += SPECIES.length()) { 2268 res *= MULReduce(a, i); 2269 } 2270 2271 return res; 2272 } 2273 @Test(dataProvider = "doubleUnaryOpProvider") 2274 static void MULReduceDouble256VectorTests(IntFunction<double[]> fa) { 2275 double[] a = fa.apply(SPECIES.length()); 2276 double[] r = fr.apply(SPECIES.length()); 2277 double ra = 1; 2278 2279 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2280 for (int i = 0; i < a.length; i += SPECIES.length()) { 2281 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 2282 r[i] = av.reduceLanes(VectorOperators.MUL); 2283 } 2284 } 2285 2286 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2287 ra = 1; 2288 for (int i = 0; i < a.length; i += SPECIES.length()) { 2289 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 2290 ra *= av.reduceLanes(VectorOperators.MUL); 2291 } 2292 } 2293 2294 assertReductionArraysEquals(r, ra, a, 2295 Double256VectorTests::MULReduce, Double256VectorTests::MULReduceAll); 2296 } 2297 static double MULReduceMasked(double[] a, int idx, boolean[] mask) { 2298 double res = 1; 2299 for (int i = idx; i < (idx + SPECIES.length()); i++) { 2300 if (mask[i % SPECIES.length()]) 2301 res *= a[i]; 2302 } 2303 2304 return res; 2305 } 2306 2307 static double MULReduceAllMasked(double[] a, boolean[] mask) { 2308 double res = 1; 2309 for (int i = 0; i < a.length; i += SPECIES.length()) { 2310 res *= MULReduceMasked(a, i, mask); 2311 } 2312 2313 return res; 2314 } 2315 @Test(dataProvider = "doubleUnaryOpMaskProvider") 2316 static void MULReduceDouble256VectorTestsMasked(IntFunction<double[]> fa, IntFunction<boolean[]> fm) { 2317 double[] a = fa.apply(SPECIES.length()); 2318 double[] r = fr.apply(SPECIES.length()); 2319 boolean[] mask = fm.apply(SPECIES.length()); 2320 VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2321 double ra = 1; 2322 2323 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2324 for (int i = 0; i < a.length; i += SPECIES.length()) { 2325 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 2326 r[i] = av.reduceLanes(VectorOperators.MUL, vmask); 2327 } 2328 } 2329 2330 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2331 ra = 1; 2332 for (int i = 0; i < a.length; i += SPECIES.length()) { 2333 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 2334 ra *= av.reduceLanes(VectorOperators.MUL, vmask); 2335 } 2336 } 2337 2338 assertReductionArraysEqualsMasked(r, ra, a, mask, 2339 Double256VectorTests::MULReduceMasked, Double256VectorTests::MULReduceAllMasked); 2340 } 2341 static double MINReduce(double[] a, int idx) { 2342 double res = Double.POSITIVE_INFINITY; 2343 for (int i = idx; i < (idx + SPECIES.length()); i++) { 2344 res = (double) Math.min(res, a[i]); 2345 } 2346 2347 return res; 2348 } 2349 2350 static double MINReduceAll(double[] a) { 2351 double res = Double.POSITIVE_INFINITY; 2352 for (int i = 0; i < a.length; i += SPECIES.length()) { 2353 res = (double) Math.min(res, MINReduce(a, i)); 2354 } 2355 2356 return res; 2357 } 2358 @Test(dataProvider = "doubleUnaryOpProvider") 2359 static void MINReduceDouble256VectorTests(IntFunction<double[]> fa) { 2360 double[] a = fa.apply(SPECIES.length()); 2361 double[] r = fr.apply(SPECIES.length()); 2362 double ra = Double.POSITIVE_INFINITY; 2363 2364 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2365 for (int i = 0; i < a.length; i += SPECIES.length()) { 2366 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 2367 r[i] = av.reduceLanes(VectorOperators.MIN); 2368 } 2369 } 2370 2371 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2372 ra = Double.POSITIVE_INFINITY; 2373 for (int i = 0; i < a.length; i += SPECIES.length()) { 2374 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 2375 ra = (double) Math.min(ra, av.reduceLanes(VectorOperators.MIN)); 2376 } 2377 } 2378 2379 assertReductionArraysEquals(r, ra, a, 2380 Double256VectorTests::MINReduce, Double256VectorTests::MINReduceAll); 2381 } 2382 static double MINReduceMasked(double[] a, int idx, boolean[] mask) { 2383 double res = Double.POSITIVE_INFINITY; 2384 for (int i = idx; i < (idx + SPECIES.length()); i++) { 2385 if (mask[i % SPECIES.length()]) 2386 res = (double) Math.min(res, a[i]); 2387 } 2388 2389 return res; 2390 } 2391 2392 static double MINReduceAllMasked(double[] a, boolean[] mask) { 2393 double res = Double.POSITIVE_INFINITY; 2394 for (int i = 0; i < a.length; i += SPECIES.length()) { 2395 res = (double) Math.min(res, MINReduceMasked(a, i, mask)); 2396 } 2397 2398 return res; 2399 } 2400 @Test(dataProvider = "doubleUnaryOpMaskProvider") 2401 static void MINReduceDouble256VectorTestsMasked(IntFunction<double[]> fa, IntFunction<boolean[]> fm) { 2402 double[] a = fa.apply(SPECIES.length()); 2403 double[] r = fr.apply(SPECIES.length()); 2404 boolean[] mask = fm.apply(SPECIES.length()); 2405 VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2406 double ra = Double.POSITIVE_INFINITY; 2407 2408 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2409 for (int i = 0; i < a.length; i += SPECIES.length()) { 2410 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 2411 r[i] = av.reduceLanes(VectorOperators.MIN, vmask); 2412 } 2413 } 2414 2415 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2416 ra = Double.POSITIVE_INFINITY; 2417 for (int i = 0; i < a.length; i += SPECIES.length()) { 2418 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 2419 ra = (double) Math.min(ra, av.reduceLanes(VectorOperators.MIN, vmask)); 2420 } 2421 } 2422 2423 assertReductionArraysEqualsMasked(r, ra, a, mask, 2424 Double256VectorTests::MINReduceMasked, Double256VectorTests::MINReduceAllMasked); 2425 } 2426 static double MAXReduce(double[] a, int idx) { 2427 double res = Double.NEGATIVE_INFINITY; 2428 for (int i = idx; i < (idx + SPECIES.length()); i++) { 2429 res = (double) Math.max(res, a[i]); 2430 } 2431 2432 return res; 2433 } 2434 2435 static double MAXReduceAll(double[] a) { 2436 double res = Double.NEGATIVE_INFINITY; 2437 for (int i = 0; i < a.length; i += SPECIES.length()) { 2438 res = (double) Math.max(res, MAXReduce(a, i)); 2439 } 2440 2441 return res; 2442 } 2443 @Test(dataProvider = "doubleUnaryOpProvider") 2444 static void MAXReduceDouble256VectorTests(IntFunction<double[]> fa) { 2445 double[] a = fa.apply(SPECIES.length()); 2446 double[] r = fr.apply(SPECIES.length()); 2447 double ra = Double.NEGATIVE_INFINITY; 2448 2449 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2450 for (int i = 0; i < a.length; i += SPECIES.length()) { 2451 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 2452 r[i] = av.reduceLanes(VectorOperators.MAX); 2453 } 2454 } 2455 2456 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2457 ra = Double.NEGATIVE_INFINITY; 2458 for (int i = 0; i < a.length; i += SPECIES.length()) { 2459 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 2460 ra = (double) Math.max(ra, av.reduceLanes(VectorOperators.MAX)); 2461 } 2462 } 2463 2464 assertReductionArraysEquals(r, ra, a, 2465 Double256VectorTests::MAXReduce, Double256VectorTests::MAXReduceAll); 2466 } 2467 static double MAXReduceMasked(double[] a, int idx, boolean[] mask) { 2468 double res = Double.NEGATIVE_INFINITY; 2469 for (int i = idx; i < (idx + SPECIES.length()); i++) { 2470 if (mask[i % SPECIES.length()]) 2471 res = (double) Math.max(res, a[i]); 2472 } 2473 2474 return res; 2475 } 2476 2477 static double MAXReduceAllMasked(double[] a, boolean[] mask) { 2478 double res = Double.NEGATIVE_INFINITY; 2479 for (int i = 0; i < a.length; i += SPECIES.length()) { 2480 res = (double) Math.max(res, MAXReduceMasked(a, i, mask)); 2481 } 2482 2483 return res; 2484 } 2485 @Test(dataProvider = "doubleUnaryOpMaskProvider") 2486 static void MAXReduceDouble256VectorTestsMasked(IntFunction<double[]> fa, IntFunction<boolean[]> fm) { 2487 double[] a = fa.apply(SPECIES.length()); 2488 double[] r = fr.apply(SPECIES.length()); 2489 boolean[] mask = fm.apply(SPECIES.length()); 2490 VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2491 double ra = Double.NEGATIVE_INFINITY; 2492 2493 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2494 for (int i = 0; i < a.length; i += SPECIES.length()) { 2495 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 2496 r[i] = av.reduceLanes(VectorOperators.MAX, vmask); 2497 } 2498 } 2499 2500 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2501 ra = Double.NEGATIVE_INFINITY; 2502 for (int i = 0; i < a.length; i += SPECIES.length()) { 2503 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 2504 ra = (double) Math.max(ra, av.reduceLanes(VectorOperators.MAX, vmask)); 2505 } 2506 } 2507 2508 assertReductionArraysEqualsMasked(r, ra, a, mask, 2509 Double256VectorTests::MAXReduceMasked, Double256VectorTests::MAXReduceAllMasked); 2510 } 2511 static double FIRST_NONZEROReduce(double[] a, int idx) { 2512 double res = (double) 0; 2513 for (int i = idx; i < (idx + SPECIES.length()); i++) { 2514 res = firstNonZero(res, a[i]); 2515 } 2516 2517 return res; 2518 } 2519 2520 static double FIRST_NONZEROReduceAll(double[] a) { 2521 double res = (double) 0; 2522 for (int i = 0; i < a.length; i += SPECIES.length()) { 2523 res = firstNonZero(res, FIRST_NONZEROReduce(a, i)); 2524 } 2525 2526 return res; 2527 } 2528 @Test(dataProvider = "doubleUnaryOpProvider") 2529 static void FIRST_NONZEROReduceDouble256VectorTests(IntFunction<double[]> fa) { 2530 double[] a = fa.apply(SPECIES.length()); 2531 double[] r = fr.apply(SPECIES.length()); 2532 double ra = (double) 0; 2533 2534 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2535 for (int i = 0; i < a.length; i += SPECIES.length()) { 2536 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 2537 r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO); 2538 } 2539 } 2540 2541 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2542 ra = (double) 0; 2543 for (int i = 0; i < a.length; i += SPECIES.length()) { 2544 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 2545 ra = firstNonZero(ra, av.reduceLanes(VectorOperators.FIRST_NONZERO)); 2546 } 2547 } 2548 2549 assertReductionArraysEquals(r, ra, a, 2550 Double256VectorTests::FIRST_NONZEROReduce, Double256VectorTests::FIRST_NONZEROReduceAll); 2551 } 2552 static double FIRST_NONZEROReduceMasked(double[] a, int idx, boolean[] mask) { 2553 double res = (double) 0; 2554 for (int i = idx; i < (idx + SPECIES.length()); i++) { 2555 if (mask[i % SPECIES.length()]) 2556 res = firstNonZero(res, a[i]); 2557 } 2558 2559 return res; 2560 } 2561 2562 static double FIRST_NONZEROReduceAllMasked(double[] a, boolean[] mask) { 2563 double res = (double) 0; 2564 for (int i = 0; i < a.length; i += SPECIES.length()) { 2565 res = firstNonZero(res, FIRST_NONZEROReduceMasked(a, i, mask)); 2566 } 2567 2568 return res; 2569 } 2570 @Test(dataProvider = "doubleUnaryOpMaskProvider") 2571 static void FIRST_NONZEROReduceDouble256VectorTestsMasked(IntFunction<double[]> fa, IntFunction<boolean[]> fm) { 2572 double[] a = fa.apply(SPECIES.length()); 2573 double[] r = fr.apply(SPECIES.length()); 2574 boolean[] mask = fm.apply(SPECIES.length()); 2575 VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2576 double ra = (double) 0; 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 r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask); 2582 } 2583 } 2584 2585 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2586 ra = (double) 0; 2587 for (int i = 0; i < a.length; i += SPECIES.length()) { 2588 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 2589 ra = firstNonZero(ra, av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask)); 2590 } 2591 } 2592 2593 assertReductionArraysEqualsMasked(r, ra, a, mask, 2594 Double256VectorTests::FIRST_NONZEROReduceMasked, Double256VectorTests::FIRST_NONZEROReduceAllMasked); 2595 } 2596 2597 2598 2599 2600 2601 @Test(dataProvider = "doubleUnaryOpProvider") 2602 static void withDouble256VectorTests(IntFunction<double []> fa) { 2603 double[] a = fa.apply(SPECIES.length()); 2604 double[] r = fr.apply(SPECIES.length()); 2605 2606 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2607 for (int i = 0, j = 0; i < a.length; i += SPECIES.length()) { 2608 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 2609 av.withLane((j++ & (SPECIES.length()-1)), (double)(65535+i)).intoArray(r, i); 2610 } 2611 } 2612 2613 2614 for (int i = 0, j = 0; i < a.length; i += SPECIES.length()) { 2615 assertInsertArraysEquals(r, a, (double)(65535+i), (j++ & (SPECIES.length()-1)), i , i + SPECIES.length()); 2616 } 2617 } 2618 static boolean testIS_DEFAULT(double a) { 2619 return bits(a)==0; 2620 } 2621 2622 @Test(dataProvider = "doubleTestOpProvider") 2623 static void IS_DEFAULTDouble256VectorTests(IntFunction<double[]> fa) { 2624 double[] a = fa.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 VectorMask<Double> mv = av.test(VectorOperators.IS_DEFAULT); 2630 2631 // Check results as part of computation. 2632 for (int j = 0; j < SPECIES.length(); j++) { 2633 Assert.assertEquals(mv.laneIsSet(j), testIS_DEFAULT(a[i + j])); 2634 } 2635 } 2636 } 2637 } 2638 2639 @Test(dataProvider = "doubleTestOpMaskProvider") 2640 static void IS_DEFAULTMaskedDouble256VectorTests(IntFunction<double[]> fa, 2641 IntFunction<boolean[]> fm) { 2642 double[] a = fa.apply(SPECIES.length()); 2643 boolean[] mask = fm.apply(SPECIES.length()); 2644 VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2645 2646 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2647 for (int i = 0; i < a.length; i += SPECIES.length()) { 2648 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 2649 VectorMask<Double> mv = av.test(VectorOperators.IS_DEFAULT, vmask); 2650 2651 // Check results as part of computation. 2652 for (int j = 0; j < SPECIES.length(); j++) { 2653 Assert.assertEquals(mv.laneIsSet(j), vmask.laneIsSet(j) && testIS_DEFAULT(a[i + j])); 2654 } 2655 } 2656 } 2657 } 2658 static boolean testIS_NEGATIVE(double a) { 2659 return bits(a)<0; 2660 } 2661 2662 @Test(dataProvider = "doubleTestOpProvider") 2663 static void IS_NEGATIVEDouble256VectorTests(IntFunction<double[]> fa) { 2664 double[] a = fa.apply(SPECIES.length()); 2665 2666 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2667 for (int i = 0; i < a.length; i += SPECIES.length()) { 2668 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 2669 VectorMask<Double> mv = av.test(VectorOperators.IS_NEGATIVE); 2670 2671 // Check results as part of computation. 2672 for (int j = 0; j < SPECIES.length(); j++) { 2673 Assert.assertEquals(mv.laneIsSet(j), testIS_NEGATIVE(a[i + j])); 2674 } 2675 } 2676 } 2677 } 2678 2679 @Test(dataProvider = "doubleTestOpMaskProvider") 2680 static void IS_NEGATIVEMaskedDouble256VectorTests(IntFunction<double[]> fa, 2681 IntFunction<boolean[]> fm) { 2682 double[] a = fa.apply(SPECIES.length()); 2683 boolean[] mask = fm.apply(SPECIES.length()); 2684 VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2685 2686 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2687 for (int i = 0; i < a.length; i += SPECIES.length()) { 2688 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 2689 VectorMask<Double> mv = av.test(VectorOperators.IS_NEGATIVE, vmask); 2690 2691 // Check results as part of computation. 2692 for (int j = 0; j < SPECIES.length(); j++) { 2693 Assert.assertEquals(mv.laneIsSet(j), vmask.laneIsSet(j) && testIS_NEGATIVE(a[i + j])); 2694 } 2695 } 2696 } 2697 } 2698 2699 static boolean testIS_FINITE(double a) { 2700 return Double.isFinite(a); 2701 } 2702 2703 @Test(dataProvider = "doubleTestOpProvider") 2704 static void IS_FINITEDouble256VectorTests(IntFunction<double[]> fa) { 2705 double[] a = fa.apply(SPECIES.length()); 2706 2707 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2708 for (int i = 0; i < a.length; i += SPECIES.length()) { 2709 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 2710 VectorMask<Double> mv = av.test(VectorOperators.IS_FINITE); 2711 2712 // Check results as part of computation. 2713 for (int j = 0; j < SPECIES.length(); j++) { 2714 Assert.assertEquals(mv.laneIsSet(j), testIS_FINITE(a[i + j])); 2715 } 2716 } 2717 } 2718 } 2719 2720 @Test(dataProvider = "doubleTestOpMaskProvider") 2721 static void IS_FINITEMaskedDouble256VectorTests(IntFunction<double[]> fa, 2722 IntFunction<boolean[]> fm) { 2723 double[] a = fa.apply(SPECIES.length()); 2724 boolean[] mask = fm.apply(SPECIES.length()); 2725 VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2726 2727 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2728 for (int i = 0; i < a.length; i += SPECIES.length()) { 2729 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 2730 VectorMask<Double> mv = av.test(VectorOperators.IS_FINITE, vmask); 2731 2732 // Check results as part of computation. 2733 for (int j = 0; j < SPECIES.length(); j++) { 2734 Assert.assertEquals(mv.laneIsSet(j), vmask.laneIsSet(j) && testIS_FINITE(a[i + j])); 2735 } 2736 } 2737 } 2738 } 2739 2740 2741 static boolean testIS_NAN(double a) { 2742 return Double.isNaN(a); 2743 } 2744 2745 @Test(dataProvider = "doubleTestOpProvider") 2746 static void IS_NANDouble256VectorTests(IntFunction<double[]> fa) { 2747 double[] a = fa.apply(SPECIES.length()); 2748 2749 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2750 for (int i = 0; i < a.length; i += SPECIES.length()) { 2751 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 2752 VectorMask<Double> mv = av.test(VectorOperators.IS_NAN); 2753 2754 // Check results as part of computation. 2755 for (int j = 0; j < SPECIES.length(); j++) { 2756 Assert.assertEquals(mv.laneIsSet(j), testIS_NAN(a[i + j])); 2757 } 2758 } 2759 } 2760 } 2761 2762 @Test(dataProvider = "doubleTestOpMaskProvider") 2763 static void IS_NANMaskedDouble256VectorTests(IntFunction<double[]> fa, 2764 IntFunction<boolean[]> fm) { 2765 double[] a = fa.apply(SPECIES.length()); 2766 boolean[] mask = fm.apply(SPECIES.length()); 2767 VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2768 2769 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2770 for (int i = 0; i < a.length; i += SPECIES.length()) { 2771 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 2772 VectorMask<Double> mv = av.test(VectorOperators.IS_NAN, vmask); 2773 2774 // Check results as part of computation. 2775 for (int j = 0; j < SPECIES.length(); j++) { 2776 Assert.assertEquals(mv.laneIsSet(j), vmask.laneIsSet(j) && testIS_NAN(a[i + j])); 2777 } 2778 } 2779 } 2780 } 2781 2782 2783 static boolean testIS_INFINITE(double a) { 2784 return Double.isInfinite(a); 2785 } 2786 2787 @Test(dataProvider = "doubleTestOpProvider") 2788 static void IS_INFINITEDouble256VectorTests(IntFunction<double[]> fa) { 2789 double[] a = fa.apply(SPECIES.length()); 2790 2791 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2792 for (int i = 0; i < a.length; i += SPECIES.length()) { 2793 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 2794 VectorMask<Double> mv = av.test(VectorOperators.IS_INFINITE); 2795 2796 // Check results as part of computation. 2797 for (int j = 0; j < SPECIES.length(); j++) { 2798 Assert.assertEquals(mv.laneIsSet(j), testIS_INFINITE(a[i + j])); 2799 } 2800 } 2801 } 2802 } 2803 2804 @Test(dataProvider = "doubleTestOpMaskProvider") 2805 static void IS_INFINITEMaskedDouble256VectorTests(IntFunction<double[]> fa, 2806 IntFunction<boolean[]> fm) { 2807 double[] a = fa.apply(SPECIES.length()); 2808 boolean[] mask = fm.apply(SPECIES.length()); 2809 VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2810 2811 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2812 for (int i = 0; i < a.length; i += SPECIES.length()) { 2813 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 2814 VectorMask<Double> mv = av.test(VectorOperators.IS_INFINITE, vmask); 2815 2816 // Check results as part of computation. 2817 for (int j = 0; j < SPECIES.length(); j++) { 2818 Assert.assertEquals(mv.laneIsSet(j), vmask.laneIsSet(j) && testIS_INFINITE(a[i + j])); 2819 } 2820 } 2821 } 2822 } 2823 2824 2825 @Test(dataProvider = "doubleCompareOpProvider") 2826 static void LTDouble256VectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) { 2827 double[] a = fa.apply(SPECIES.length()); 2828 double[] b = fb.apply(SPECIES.length()); 2829 2830 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2831 for (int i = 0; i < a.length; i += SPECIES.length()) { 2832 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 2833 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i); 2834 VectorMask<Double> mv = av.compare(VectorOperators.LT, bv); 2835 2836 // Check results as part of computation. 2837 for (int j = 0; j < SPECIES.length(); j++) { 2838 Assert.assertEquals(mv.laneIsSet(j), lt(a[i + j], b[i + j])); 2839 } 2840 } 2841 } 2842 } 2843 2844 2845 @Test(dataProvider = "doubleCompareOpProvider") 2846 static void ltDouble256VectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) { 2847 double[] a = fa.apply(SPECIES.length()); 2848 double[] b = fb.apply(SPECIES.length()); 2849 2850 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2851 for (int i = 0; i < a.length; i += SPECIES.length()) { 2852 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 2853 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i); 2854 VectorMask<Double> mv = av.lt(bv); 2855 2856 // Check results as part of computation. 2857 for (int j = 0; j < SPECIES.length(); j++) { 2858 Assert.assertEquals(mv.laneIsSet(j), lt(a[i + j], b[i + j])); 2859 } 2860 } 2861 } 2862 } 2863 2864 @Test(dataProvider = "doubleCompareOpMaskProvider") 2865 static void LTDouble256VectorTestsMasked(IntFunction<double[]> fa, IntFunction<double[]> fb, 2866 IntFunction<boolean[]> fm) { 2867 double[] a = fa.apply(SPECIES.length()); 2868 double[] b = fb.apply(SPECIES.length()); 2869 boolean[] mask = fm.apply(SPECIES.length()); 2870 2871 VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2872 2873 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2874 for (int i = 0; i < a.length; i += SPECIES.length()) { 2875 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 2876 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i); 2877 VectorMask<Double> mv = av.compare(VectorOperators.LT, bv, vmask); 2878 2879 // Check results as part of computation. 2880 for (int j = 0; j < SPECIES.length(); j++) { 2881 Assert.assertEquals(mv.laneIsSet(j), mask[j] && lt(a[i + j], b[i + j])); 2882 } 2883 } 2884 } 2885 } 2886 2887 2888 @Test(dataProvider = "doubleCompareOpProvider") 2889 static void GTDouble256VectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) { 2890 double[] a = fa.apply(SPECIES.length()); 2891 double[] b = fb.apply(SPECIES.length()); 2892 2893 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2894 for (int i = 0; i < a.length; i += SPECIES.length()) { 2895 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 2896 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i); 2897 VectorMask<Double> mv = av.compare(VectorOperators.GT, bv); 2898 2899 // Check results as part of computation. 2900 for (int j = 0; j < SPECIES.length(); j++) { 2901 Assert.assertEquals(mv.laneIsSet(j), gt(a[i + j], b[i + j])); 2902 } 2903 } 2904 } 2905 } 2906 2907 @Test(dataProvider = "doubleCompareOpMaskProvider") 2908 static void GTDouble256VectorTestsMasked(IntFunction<double[]> fa, IntFunction<double[]> fb, 2909 IntFunction<boolean[]> fm) { 2910 double[] a = fa.apply(SPECIES.length()); 2911 double[] b = fb.apply(SPECIES.length()); 2912 boolean[] mask = fm.apply(SPECIES.length()); 2913 2914 VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2915 2916 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2917 for (int i = 0; i < a.length; i += SPECIES.length()) { 2918 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 2919 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i); 2920 VectorMask<Double> mv = av.compare(VectorOperators.GT, bv, vmask); 2921 2922 // Check results as part of computation. 2923 for (int j = 0; j < SPECIES.length(); j++) { 2924 Assert.assertEquals(mv.laneIsSet(j), mask[j] && gt(a[i + j], b[i + j])); 2925 } 2926 } 2927 } 2928 } 2929 2930 2931 @Test(dataProvider = "doubleCompareOpProvider") 2932 static void EQDouble256VectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) { 2933 double[] a = fa.apply(SPECIES.length()); 2934 double[] b = fb.apply(SPECIES.length()); 2935 2936 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2937 for (int i = 0; i < a.length; i += SPECIES.length()) { 2938 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 2939 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i); 2940 VectorMask<Double> mv = av.compare(VectorOperators.EQ, bv); 2941 2942 // Check results as part of computation. 2943 for (int j = 0; j < SPECIES.length(); j++) { 2944 Assert.assertEquals(mv.laneIsSet(j), eq(a[i + j], b[i + j])); 2945 } 2946 } 2947 } 2948 } 2949 2950 2951 @Test(dataProvider = "doubleCompareOpProvider") 2952 static void eqDouble256VectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) { 2953 double[] a = fa.apply(SPECIES.length()); 2954 double[] b = fb.apply(SPECIES.length()); 2955 2956 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2957 for (int i = 0; i < a.length; i += SPECIES.length()) { 2958 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 2959 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i); 2960 VectorMask<Double> mv = av.eq(bv); 2961 2962 // Check results as part of computation. 2963 for (int j = 0; j < SPECIES.length(); j++) { 2964 Assert.assertEquals(mv.laneIsSet(j), eq(a[i + j], b[i + j])); 2965 } 2966 } 2967 } 2968 } 2969 2970 @Test(dataProvider = "doubleCompareOpMaskProvider") 2971 static void EQDouble256VectorTestsMasked(IntFunction<double[]> fa, IntFunction<double[]> fb, 2972 IntFunction<boolean[]> fm) { 2973 double[] a = fa.apply(SPECIES.length()); 2974 double[] b = fb.apply(SPECIES.length()); 2975 boolean[] mask = fm.apply(SPECIES.length()); 2976 2977 VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2978 2979 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2980 for (int i = 0; i < a.length; i += SPECIES.length()) { 2981 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 2982 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i); 2983 VectorMask<Double> mv = av.compare(VectorOperators.EQ, bv, vmask); 2984 2985 // Check results as part of computation. 2986 for (int j = 0; j < SPECIES.length(); j++) { 2987 Assert.assertEquals(mv.laneIsSet(j), mask[j] && eq(a[i + j], b[i + j])); 2988 } 2989 } 2990 } 2991 } 2992 2993 2994 @Test(dataProvider = "doubleCompareOpProvider") 2995 static void NEDouble256VectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) { 2996 double[] a = fa.apply(SPECIES.length()); 2997 double[] b = fb.apply(SPECIES.length()); 2998 2999 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3000 for (int i = 0; i < a.length; i += SPECIES.length()) { 3001 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 3002 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i); 3003 VectorMask<Double> mv = av.compare(VectorOperators.NE, bv); 3004 3005 // Check results as part of computation. 3006 for (int j = 0; j < SPECIES.length(); j++) { 3007 Assert.assertEquals(mv.laneIsSet(j), neq(a[i + j], b[i + j])); 3008 } 3009 } 3010 } 3011 } 3012 3013 @Test(dataProvider = "doubleCompareOpMaskProvider") 3014 static void NEDouble256VectorTestsMasked(IntFunction<double[]> fa, IntFunction<double[]> fb, 3015 IntFunction<boolean[]> fm) { 3016 double[] a = fa.apply(SPECIES.length()); 3017 double[] b = fb.apply(SPECIES.length()); 3018 boolean[] mask = fm.apply(SPECIES.length()); 3019 3020 VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3021 3022 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3023 for (int i = 0; i < a.length; i += SPECIES.length()) { 3024 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 3025 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i); 3026 VectorMask<Double> mv = av.compare(VectorOperators.NE, bv, vmask); 3027 3028 // Check results as part of computation. 3029 for (int j = 0; j < SPECIES.length(); j++) { 3030 Assert.assertEquals(mv.laneIsSet(j), mask[j] && neq(a[i + j], b[i + j])); 3031 } 3032 } 3033 } 3034 } 3035 3036 3037 @Test(dataProvider = "doubleCompareOpProvider") 3038 static void LEDouble256VectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) { 3039 double[] a = fa.apply(SPECIES.length()); 3040 double[] b = fb.apply(SPECIES.length()); 3041 3042 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3043 for (int i = 0; i < a.length; i += SPECIES.length()) { 3044 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 3045 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i); 3046 VectorMask<Double> mv = av.compare(VectorOperators.LE, bv); 3047 3048 // Check results as part of computation. 3049 for (int j = 0; j < SPECIES.length(); j++) { 3050 Assert.assertEquals(mv.laneIsSet(j), le(a[i + j], b[i + j])); 3051 } 3052 } 3053 } 3054 } 3055 3056 @Test(dataProvider = "doubleCompareOpMaskProvider") 3057 static void LEDouble256VectorTestsMasked(IntFunction<double[]> fa, IntFunction<double[]> fb, 3058 IntFunction<boolean[]> fm) { 3059 double[] a = fa.apply(SPECIES.length()); 3060 double[] b = fb.apply(SPECIES.length()); 3061 boolean[] mask = fm.apply(SPECIES.length()); 3062 3063 VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3064 3065 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3066 for (int i = 0; i < a.length; i += SPECIES.length()) { 3067 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 3068 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i); 3069 VectorMask<Double> mv = av.compare(VectorOperators.LE, bv, vmask); 3070 3071 // Check results as part of computation. 3072 for (int j = 0; j < SPECIES.length(); j++) { 3073 Assert.assertEquals(mv.laneIsSet(j), mask[j] && le(a[i + j], b[i + j])); 3074 } 3075 } 3076 } 3077 } 3078 3079 3080 @Test(dataProvider = "doubleCompareOpProvider") 3081 static void GEDouble256VectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) { 3082 double[] a = fa.apply(SPECIES.length()); 3083 double[] b = fb.apply(SPECIES.length()); 3084 3085 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3086 for (int i = 0; i < a.length; i += SPECIES.length()) { 3087 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 3088 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i); 3089 VectorMask<Double> mv = av.compare(VectorOperators.GE, bv); 3090 3091 // Check results as part of computation. 3092 for (int j = 0; j < SPECIES.length(); j++) { 3093 Assert.assertEquals(mv.laneIsSet(j), ge(a[i + j], b[i + j])); 3094 } 3095 } 3096 } 3097 } 3098 3099 @Test(dataProvider = "doubleCompareOpMaskProvider") 3100 static void GEDouble256VectorTestsMasked(IntFunction<double[]> fa, IntFunction<double[]> fb, 3101 IntFunction<boolean[]> fm) { 3102 double[] a = fa.apply(SPECIES.length()); 3103 double[] b = fb.apply(SPECIES.length()); 3104 boolean[] mask = fm.apply(SPECIES.length()); 3105 3106 VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3107 3108 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3109 for (int i = 0; i < a.length; i += SPECIES.length()) { 3110 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 3111 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i); 3112 VectorMask<Double> mv = av.compare(VectorOperators.GE, bv, vmask); 3113 3114 // Check results as part of computation. 3115 for (int j = 0; j < SPECIES.length(); j++) { 3116 Assert.assertEquals(mv.laneIsSet(j), mask[j] && ge(a[i + j], b[i + j])); 3117 } 3118 } 3119 } 3120 } 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 @Test(dataProvider = "doubleCompareOpProvider") 3132 static void LTDouble256VectorTestsBroadcastSmokeTest(IntFunction<double[]> fa, IntFunction<double[]> fb) { 3133 double[] a = fa.apply(SPECIES.length()); 3134 double[] b = fb.apply(SPECIES.length()); 3135 3136 for (int i = 0; i < a.length; i += SPECIES.length()) { 3137 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 3138 VectorMask<Double> mv = av.compare(VectorOperators.LT, b[i]); 3139 3140 // Check results as part of computation. 3141 for (int j = 0; j < SPECIES.length(); j++) { 3142 Assert.assertEquals(mv.laneIsSet(j), a[i + j] < b[i]); 3143 } 3144 } 3145 } 3146 3147 3148 @Test(dataProvider = "doubleCompareOpMaskProvider") 3149 static void LTDouble256VectorTestsBroadcastMaskedSmokeTest(IntFunction<double[]> fa, 3150 IntFunction<double[]> fb, IntFunction<boolean[]> fm) { 3151 double[] a = fa.apply(SPECIES.length()); 3152 double[] b = fb.apply(SPECIES.length()); 3153 boolean[] mask = fm.apply(SPECIES.length()); 3154 3155 VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3156 3157 for (int i = 0; i < a.length; i += SPECIES.length()) { 3158 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 3159 VectorMask<Double> mv = av.compare(VectorOperators.LT, b[i], vmask); 3160 3161 // Check results as part of computation. 3162 for (int j = 0; j < SPECIES.length(); j++) { 3163 Assert.assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] < b[i])); 3164 } 3165 } 3166 } 3167 3168 @Test(dataProvider = "doubleCompareOpProvider") 3169 static void LTDouble256VectorTestsBroadcastLongSmokeTest(IntFunction<double[]> fa, IntFunction<double[]> fb) { 3170 double[] a = fa.apply(SPECIES.length()); 3171 double[] b = fb.apply(SPECIES.length()); 3172 3173 for (int i = 0; i < a.length; i += SPECIES.length()) { 3174 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 3175 VectorMask<Double> mv = av.compare(VectorOperators.LT, (long)b[i]); 3176 3177 // Check results as part of computation. 3178 for (int j = 0; j < SPECIES.length(); j++) { 3179 Assert.assertEquals(mv.laneIsSet(j), a[i + j] < (double)((long)b[i])); 3180 } 3181 } 3182 } 3183 3184 3185 @Test(dataProvider = "doubleCompareOpMaskProvider") 3186 static void LTDouble256VectorTestsBroadcastLongMaskedSmokeTest(IntFunction<double[]> fa, 3187 IntFunction<double[]> fb, IntFunction<boolean[]> fm) { 3188 double[] a = fa.apply(SPECIES.length()); 3189 double[] b = fb.apply(SPECIES.length()); 3190 boolean[] mask = fm.apply(SPECIES.length()); 3191 3192 VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3193 3194 for (int i = 0; i < a.length; i += SPECIES.length()) { 3195 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 3196 VectorMask<Double> mv = av.compare(VectorOperators.LT, (long)b[i], vmask); 3197 3198 // Check results as part of computation. 3199 for (int j = 0; j < SPECIES.length(); j++) { 3200 Assert.assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] < (double)((long)b[i]))); 3201 } 3202 } 3203 } 3204 3205 @Test(dataProvider = "doubleCompareOpProvider") 3206 static void EQDouble256VectorTestsBroadcastSmokeTest(IntFunction<double[]> fa, IntFunction<double[]> fb) { 3207 double[] a = fa.apply(SPECIES.length()); 3208 double[] b = fb.apply(SPECIES.length()); 3209 3210 for (int i = 0; i < a.length; i += SPECIES.length()) { 3211 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 3212 VectorMask<Double> mv = av.compare(VectorOperators.EQ, b[i]); 3213 3214 // Check results as part of computation. 3215 for (int j = 0; j < SPECIES.length(); j++) { 3216 Assert.assertEquals(mv.laneIsSet(j), a[i + j] == b[i]); 3217 } 3218 } 3219 } 3220 3221 3222 @Test(dataProvider = "doubleCompareOpMaskProvider") 3223 static void EQDouble256VectorTestsBroadcastMaskedSmokeTest(IntFunction<double[]> fa, 3224 IntFunction<double[]> fb, IntFunction<boolean[]> fm) { 3225 double[] a = fa.apply(SPECIES.length()); 3226 double[] b = fb.apply(SPECIES.length()); 3227 boolean[] mask = fm.apply(SPECIES.length()); 3228 3229 VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3230 3231 for (int i = 0; i < a.length; i += SPECIES.length()) { 3232 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 3233 VectorMask<Double> mv = av.compare(VectorOperators.EQ, b[i], vmask); 3234 3235 // Check results as part of computation. 3236 for (int j = 0; j < SPECIES.length(); j++) { 3237 Assert.assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] == b[i])); 3238 } 3239 } 3240 } 3241 3242 @Test(dataProvider = "doubleCompareOpProvider") 3243 static void EQDouble256VectorTestsBroadcastLongSmokeTest(IntFunction<double[]> fa, IntFunction<double[]> fb) { 3244 double[] a = fa.apply(SPECIES.length()); 3245 double[] b = fb.apply(SPECIES.length()); 3246 3247 for (int i = 0; i < a.length; i += SPECIES.length()) { 3248 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 3249 VectorMask<Double> mv = av.compare(VectorOperators.EQ, (long)b[i]); 3250 3251 // Check results as part of computation. 3252 for (int j = 0; j < SPECIES.length(); j++) { 3253 Assert.assertEquals(mv.laneIsSet(j), a[i + j] == (double)((long)b[i])); 3254 } 3255 } 3256 } 3257 3258 3259 @Test(dataProvider = "doubleCompareOpMaskProvider") 3260 static void EQDouble256VectorTestsBroadcastLongMaskedSmokeTest(IntFunction<double[]> fa, 3261 IntFunction<double[]> fb, IntFunction<boolean[]> fm) { 3262 double[] a = fa.apply(SPECIES.length()); 3263 double[] b = fb.apply(SPECIES.length()); 3264 boolean[] mask = fm.apply(SPECIES.length()); 3265 3266 VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3267 3268 for (int i = 0; i < a.length; i += SPECIES.length()) { 3269 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 3270 VectorMask<Double> mv = av.compare(VectorOperators.EQ, (long)b[i], vmask); 3271 3272 // Check results as part of computation. 3273 for (int j = 0; j < SPECIES.length(); j++) { 3274 Assert.assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] == (double)((long)b[i]))); 3275 } 3276 } 3277 } 3278 3279 static double blend(double a, double b, boolean mask) { 3280 return mask ? b : a; 3281 } 3282 3283 @Test(dataProvider = "doubleBinaryOpMaskProvider") 3284 static void blendDouble256VectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb, 3285 IntFunction<boolean[]> fm) { 3286 double[] a = fa.apply(SPECIES.length()); 3287 double[] b = fb.apply(SPECIES.length()); 3288 double[] r = fr.apply(SPECIES.length()); 3289 boolean[] mask = fm.apply(SPECIES.length()); 3290 VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3291 3292 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3293 for (int i = 0; i < a.length; i += SPECIES.length()) { 3294 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 3295 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i); 3296 av.blend(bv, vmask).intoArray(r, i); 3297 } 3298 } 3299 3300 assertArraysEquals(r, a, b, mask, Double256VectorTests::blend); 3301 } 3302 3303 @Test(dataProvider = "doubleUnaryOpShuffleProvider") 3304 static void RearrangeDouble256VectorTests(IntFunction<double[]> fa, 3305 BiFunction<Integer,Integer,int[]> fs) { 3306 double[] a = fa.apply(SPECIES.length()); 3307 int[] order = fs.apply(a.length, SPECIES.length()); 3308 double[] r = fr.apply(SPECIES.length()); 3309 3310 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3311 for (int i = 0; i < a.length; i += SPECIES.length()) { 3312 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 3313 av.rearrange(VectorShuffle.fromArray(SPECIES, order, i)).intoArray(r, i); 3314 } 3315 } 3316 3317 assertRearrangeArraysEquals(r, a, order, SPECIES.length()); 3318 } 3319 3320 @Test(dataProvider = "doubleUnaryOpShuffleMaskProvider") 3321 static void RearrangeDouble256VectorTestsMaskedSmokeTest(IntFunction<double[]> fa, 3322 BiFunction<Integer,Integer,int[]> fs, 3323 IntFunction<boolean[]> fm) { 3324 double[] a = fa.apply(SPECIES.length()); 3325 int[] order = fs.apply(a.length, SPECIES.length()); 3326 double[] r = fr.apply(SPECIES.length()); 3327 boolean[] mask = fm.apply(SPECIES.length()); 3328 VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3329 3330 for (int i = 0; i < a.length; i += SPECIES.length()) { 3331 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 3332 av.rearrange(VectorShuffle.fromArray(SPECIES, order, i), vmask).intoArray(r, i); 3333 } 3334 3335 assertRearrangeArraysEquals(r, a, order, mask, SPECIES.length()); 3336 } 3337 @Test(dataProvider = "doubleUnaryOpProvider") 3338 static void getDouble256VectorTests(IntFunction<double[]> fa) { 3339 double[] a = fa.apply(SPECIES.length()); 3340 double[] r = fr.apply(SPECIES.length()); 3341 3342 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3343 for (int i = 0; i < a.length; i += SPECIES.length()) { 3344 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 3345 int num_lanes = SPECIES.length(); 3346 // Manually unroll because full unroll happens after intrinsification. 3347 // Unroll is needed because get intrinsic requires for index to be a known constant. 3348 if (num_lanes == 1) { 3349 r[i]=av.lane(0); 3350 } else if (num_lanes == 2) { 3351 r[i]=av.lane(0); 3352 r[i+1]=av.lane(1); 3353 } else if (num_lanes == 4) { 3354 r[i]=av.lane(0); 3355 r[i+1]=av.lane(1); 3356 r[i+2]=av.lane(2); 3357 r[i+3]=av.lane(3); 3358 } else if (num_lanes == 8) { 3359 r[i]=av.lane(0); 3360 r[i+1]=av.lane(1); 3361 r[i+2]=av.lane(2); 3362 r[i+3]=av.lane(3); 3363 r[i+4]=av.lane(4); 3364 r[i+5]=av.lane(5); 3365 r[i+6]=av.lane(6); 3366 r[i+7]=av.lane(7); 3367 } else if (num_lanes == 16) { 3368 r[i]=av.lane(0); 3369 r[i+1]=av.lane(1); 3370 r[i+2]=av.lane(2); 3371 r[i+3]=av.lane(3); 3372 r[i+4]=av.lane(4); 3373 r[i+5]=av.lane(5); 3374 r[i+6]=av.lane(6); 3375 r[i+7]=av.lane(7); 3376 r[i+8]=av.lane(8); 3377 r[i+9]=av.lane(9); 3378 r[i+10]=av.lane(10); 3379 r[i+11]=av.lane(11); 3380 r[i+12]=av.lane(12); 3381 r[i+13]=av.lane(13); 3382 r[i+14]=av.lane(14); 3383 r[i+15]=av.lane(15); 3384 } else if (num_lanes == 32) { 3385 r[i]=av.lane(0); 3386 r[i+1]=av.lane(1); 3387 r[i+2]=av.lane(2); 3388 r[i+3]=av.lane(3); 3389 r[i+4]=av.lane(4); 3390 r[i+5]=av.lane(5); 3391 r[i+6]=av.lane(6); 3392 r[i+7]=av.lane(7); 3393 r[i+8]=av.lane(8); 3394 r[i+9]=av.lane(9); 3395 r[i+10]=av.lane(10); 3396 r[i+11]=av.lane(11); 3397 r[i+12]=av.lane(12); 3398 r[i+13]=av.lane(13); 3399 r[i+14]=av.lane(14); 3400 r[i+15]=av.lane(15); 3401 r[i+16]=av.lane(16); 3402 r[i+17]=av.lane(17); 3403 r[i+18]=av.lane(18); 3404 r[i+19]=av.lane(19); 3405 r[i+20]=av.lane(20); 3406 r[i+21]=av.lane(21); 3407 r[i+22]=av.lane(22); 3408 r[i+23]=av.lane(23); 3409 r[i+24]=av.lane(24); 3410 r[i+25]=av.lane(25); 3411 r[i+26]=av.lane(26); 3412 r[i+27]=av.lane(27); 3413 r[i+28]=av.lane(28); 3414 r[i+29]=av.lane(29); 3415 r[i+30]=av.lane(30); 3416 r[i+31]=av.lane(31); 3417 } else if (num_lanes == 64) { 3418 r[i]=av.lane(0); 3419 r[i+1]=av.lane(1); 3420 r[i+2]=av.lane(2); 3421 r[i+3]=av.lane(3); 3422 r[i+4]=av.lane(4); 3423 r[i+5]=av.lane(5); 3424 r[i+6]=av.lane(6); 3425 r[i+7]=av.lane(7); 3426 r[i+8]=av.lane(8); 3427 r[i+9]=av.lane(9); 3428 r[i+10]=av.lane(10); 3429 r[i+11]=av.lane(11); 3430 r[i+12]=av.lane(12); 3431 r[i+13]=av.lane(13); 3432 r[i+14]=av.lane(14); 3433 r[i+15]=av.lane(15); 3434 r[i+16]=av.lane(16); 3435 r[i+17]=av.lane(17); 3436 r[i+18]=av.lane(18); 3437 r[i+19]=av.lane(19); 3438 r[i+20]=av.lane(20); 3439 r[i+21]=av.lane(21); 3440 r[i+22]=av.lane(22); 3441 r[i+23]=av.lane(23); 3442 r[i+24]=av.lane(24); 3443 r[i+25]=av.lane(25); 3444 r[i+26]=av.lane(26); 3445 r[i+27]=av.lane(27); 3446 r[i+28]=av.lane(28); 3447 r[i+29]=av.lane(29); 3448 r[i+30]=av.lane(30); 3449 r[i+31]=av.lane(31); 3450 r[i+32]=av.lane(32); 3451 r[i+33]=av.lane(33); 3452 r[i+34]=av.lane(34); 3453 r[i+35]=av.lane(35); 3454 r[i+36]=av.lane(36); 3455 r[i+37]=av.lane(37); 3456 r[i+38]=av.lane(38); 3457 r[i+39]=av.lane(39); 3458 r[i+40]=av.lane(40); 3459 r[i+41]=av.lane(41); 3460 r[i+42]=av.lane(42); 3461 r[i+43]=av.lane(43); 3462 r[i+44]=av.lane(44); 3463 r[i+45]=av.lane(45); 3464 r[i+46]=av.lane(46); 3465 r[i+47]=av.lane(47); 3466 r[i+48]=av.lane(48); 3467 r[i+49]=av.lane(49); 3468 r[i+50]=av.lane(50); 3469 r[i+51]=av.lane(51); 3470 r[i+52]=av.lane(52); 3471 r[i+53]=av.lane(53); 3472 r[i+54]=av.lane(54); 3473 r[i+55]=av.lane(55); 3474 r[i+56]=av.lane(56); 3475 r[i+57]=av.lane(57); 3476 r[i+58]=av.lane(58); 3477 r[i+59]=av.lane(59); 3478 r[i+60]=av.lane(60); 3479 r[i+61]=av.lane(61); 3480 r[i+62]=av.lane(62); 3481 r[i+63]=av.lane(63); 3482 } else { 3483 for (int j = 0; j < SPECIES.length(); j++) { 3484 r[i+j]=av.lane(j); 3485 } 3486 } 3487 } 3488 } 3489 3490 assertArraysEquals(r, a, Double256VectorTests::get); 3491 } 3492 3493 @Test(dataProvider = "doubleUnaryOpProvider") 3494 static void BroadcastDouble256VectorTests(IntFunction<double[]> fa) { 3495 double[] a = fa.apply(SPECIES.length()); 3496 double[] r = new double[a.length]; 3497 3498 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3499 for (int i = 0; i < a.length; i += SPECIES.length()) { 3500 DoubleVector.broadcast(SPECIES, a[i]).intoArray(r, i); 3501 } 3502 } 3503 3504 assertBroadcastArraysEquals(r, a); 3505 } 3506 3507 3508 3509 3510 3511 @Test(dataProvider = "doubleUnaryOpProvider") 3512 static void ZeroDouble256VectorTests(IntFunction<double[]> fa) { 3513 double[] a = fa.apply(SPECIES.length()); 3514 double[] r = new double[a.length]; 3515 3516 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3517 for (int i = 0; i < a.length; i += SPECIES.length()) { 3518 DoubleVector.zero(SPECIES).intoArray(a, i); 3519 } 3520 } 3521 3522 Assert.assertEquals(a, r); 3523 } 3524 3525 3526 3527 3528 static double[] sliceUnary(double[] a, int origin, int idx) { 3529 double[] res = new double[SPECIES.length()]; 3530 for (int i = 0; i < SPECIES.length(); i++){ 3531 if(i+origin < SPECIES.length()) 3532 res[i] = a[idx+i+origin]; 3533 else 3534 res[i] = (double)0; 3535 } 3536 return res; 3537 } 3538 3539 @Test(dataProvider = "doubleUnaryOpProvider") 3540 static void sliceUnaryDouble256VectorTests(IntFunction<double[]> fa) { 3541 double[] a = fa.apply(SPECIES.length()); 3542 double[] r = new double[a.length]; 3543 int origin = (new java.util.Random()).nextInt(SPECIES.length()); 3544 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3545 for (int i = 0; i < a.length; i += SPECIES.length()) { 3546 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 3547 av.slice(origin).intoArray(r, i); 3548 } 3549 } 3550 3551 assertArraysEquals(r, a, origin, Double256VectorTests::sliceUnary); 3552 } 3553 static double[] sliceBinary(double[] a, double[] b, int origin, int idx) { 3554 double[] res = new double[SPECIES.length()]; 3555 for (int i = 0, j = 0; i < SPECIES.length(); i++){ 3556 if(i+origin < SPECIES.length()) 3557 res[i] = a[idx+i+origin]; 3558 else { 3559 res[i] = b[idx+j]; 3560 j++; 3561 } 3562 } 3563 return res; 3564 } 3565 3566 @Test(dataProvider = "doubleBinaryOpProvider") 3567 static void sliceBinaryDouble256VectorTestsBinary(IntFunction<double[]> fa, IntFunction<double[]> fb) { 3568 double[] a = fa.apply(SPECIES.length()); 3569 double[] b = fb.apply(SPECIES.length()); 3570 double[] r = new double[a.length]; 3571 int origin = (new java.util.Random()).nextInt(SPECIES.length()); 3572 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3573 for (int i = 0; i < a.length; i += SPECIES.length()) { 3574 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 3575 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i); 3576 av.slice(origin, bv).intoArray(r, i); 3577 } 3578 } 3579 3580 assertArraysEquals(r, a, b, origin, Double256VectorTests::sliceBinary); 3581 } 3582 static double[] slice(double[] a, double[] b, int origin, boolean[] mask, int idx) { 3583 double[] res = new double[SPECIES.length()]; 3584 for (int i = 0, j = 0; i < SPECIES.length(); i++){ 3585 if(i+origin < SPECIES.length()) 3586 res[i] = mask[i] ? a[idx+i+origin] : (double)0; 3587 else { 3588 res[i] = mask[i] ? b[idx+j] : (double)0; 3589 j++; 3590 } 3591 } 3592 return res; 3593 } 3594 3595 @Test(dataProvider = "doubleBinaryOpMaskProvider") 3596 static void sliceDouble256VectorTestsMasked(IntFunction<double[]> fa, IntFunction<double[]> fb, 3597 IntFunction<boolean[]> fm) { 3598 double[] a = fa.apply(SPECIES.length()); 3599 double[] b = fb.apply(SPECIES.length()); 3600 boolean[] mask = fm.apply(SPECIES.length()); 3601 VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3602 3603 double[] r = new double[a.length]; 3604 int origin = (new java.util.Random()).nextInt(SPECIES.length()); 3605 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3606 for (int i = 0; i < a.length; i += SPECIES.length()) { 3607 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 3608 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i); 3609 av.slice(origin, bv, vmask).intoArray(r, i); 3610 } 3611 } 3612 3613 assertArraysEquals(r, a, b, origin, mask, Double256VectorTests::slice); 3614 } 3615 static double[] unsliceUnary(double[] a, int origin, int idx) { 3616 double[] res = new double[SPECIES.length()]; 3617 for (int i = 0, j = 0; i < SPECIES.length(); i++){ 3618 if(i < origin) 3619 res[i] = (double)0; 3620 else { 3621 res[i] = a[idx+j]; 3622 j++; 3623 } 3624 } 3625 return res; 3626 } 3627 3628 @Test(dataProvider = "doubleUnaryOpProvider") 3629 static void unsliceUnaryDouble256VectorTests(IntFunction<double[]> fa) { 3630 double[] a = fa.apply(SPECIES.length()); 3631 double[] r = new double[a.length]; 3632 int origin = (new java.util.Random()).nextInt(SPECIES.length()); 3633 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3634 for (int i = 0; i < a.length; i += SPECIES.length()) { 3635 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 3636 av.unslice(origin).intoArray(r, i); 3637 } 3638 } 3639 3640 assertArraysEquals(r, a, origin, Double256VectorTests::unsliceUnary); 3641 } 3642 static double[] unsliceBinary(double[] a, double[] b, int origin, int part, int idx) { 3643 double[] res = new double[SPECIES.length()]; 3644 for (int i = 0, j = 0; i < SPECIES.length(); i++){ 3645 if (part == 0) { 3646 if (i < origin) 3647 res[i] = b[idx+i]; 3648 else { 3649 res[i] = a[idx+j]; 3650 j++; 3651 } 3652 } else if (part == 1) { 3653 if (i < origin) 3654 res[i] = a[idx+SPECIES.length()-origin+i]; 3655 else { 3656 res[i] = b[idx+origin+j]; 3657 j++; 3658 } 3659 } 3660 } 3661 return res; 3662 } 3663 3664 @Test(dataProvider = "doubleBinaryOpProvider") 3665 static void unsliceBinaryDouble256VectorTestsBinary(IntFunction<double[]> fa, IntFunction<double[]> fb) { 3666 double[] a = fa.apply(SPECIES.length()); 3667 double[] b = fb.apply(SPECIES.length()); 3668 double[] r = new double[a.length]; 3669 int origin = (new java.util.Random()).nextInt(SPECIES.length()); 3670 int part = (new java.util.Random()).nextInt(2); 3671 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3672 for (int i = 0; i < a.length; i += SPECIES.length()) { 3673 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 3674 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i); 3675 av.unslice(origin, bv, part).intoArray(r, i); 3676 } 3677 } 3678 3679 assertArraysEquals(r, a, b, origin, part, Double256VectorTests::unsliceBinary); 3680 } 3681 static double[] unslice(double[] a, double[] b, int origin, int part, boolean[] mask, int idx) { 3682 double[] res = new double[SPECIES.length()]; 3683 for (int i = 0, j = 0; i < SPECIES.length(); i++){ 3684 if(i+origin < SPECIES.length()) 3685 res[i] = b[idx+i+origin]; 3686 else { 3687 res[i] = b[idx+j]; 3688 j++; 3689 } 3690 } 3691 for (int i = 0; i < SPECIES.length(); i++){ 3692 res[i] = mask[i] ? a[idx+i] : res[i]; 3693 } 3694 double[] res1 = new double[SPECIES.length()]; 3695 if (part == 0) { 3696 for (int i = 0, j = 0; i < SPECIES.length(); i++){ 3697 if (i < origin) 3698 res1[i] = b[idx+i]; 3699 else { 3700 res1[i] = res[j]; 3701 j++; 3702 } 3703 } 3704 } else if (part == 1) { 3705 for (int i = 0, j = 0; i < SPECIES.length(); i++){ 3706 if (i < origin) 3707 res1[i] = res[SPECIES.length()-origin+i]; 3708 else { 3709 res1[i] = b[idx+origin+j]; 3710 j++; 3711 } 3712 } 3713 } 3714 return res1; 3715 } 3716 3717 @Test(dataProvider = "doubleBinaryOpMaskProvider") 3718 static void unsliceDouble256VectorTestsMasked(IntFunction<double[]> fa, IntFunction<double[]> fb, 3719 IntFunction<boolean[]> fm) { 3720 double[] a = fa.apply(SPECIES.length()); 3721 double[] b = fb.apply(SPECIES.length()); 3722 boolean[] mask = fm.apply(SPECIES.length()); 3723 VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3724 double[] r = new double[a.length]; 3725 int origin = (new java.util.Random()).nextInt(SPECIES.length()); 3726 int part = (new java.util.Random()).nextInt(2); 3727 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3728 for (int i = 0; i < a.length; i += SPECIES.length()) { 3729 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 3730 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i); 3731 av.unslice(origin, bv, part, vmask).intoArray(r, i); 3732 } 3733 } 3734 3735 assertArraysEquals(r, a, b, origin, part, mask, Double256VectorTests::unslice); 3736 } 3737 3738 static double SIN(double a) { 3739 return (double)(Math.sin((double)a)); 3740 } 3741 3742 static double strictSIN(double a) { 3743 return (double)(StrictMath.sin((double)a)); 3744 } 3745 3746 @Test(dataProvider = "doubleUnaryOpProvider") 3747 static void SINDouble256VectorTests(IntFunction<double[]> fa) { 3748 double[] a = fa.apply(SPECIES.length()); 3749 double[] r = fr.apply(SPECIES.length()); 3750 3751 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3752 for (int i = 0; i < a.length; i += SPECIES.length()) { 3753 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 3754 av.lanewise(VectorOperators.SIN).intoArray(r, i); 3755 } 3756 } 3757 3758 assertArraysEqualsWithinOneUlp(r, a, Double256VectorTests::SIN, Double256VectorTests::strictSIN); 3759 } 3760 3761 3762 static double EXP(double a) { 3763 return (double)(Math.exp((double)a)); 3764 } 3765 3766 static double strictEXP(double a) { 3767 return (double)(StrictMath.exp((double)a)); 3768 } 3769 3770 @Test(dataProvider = "doubleUnaryOpProvider") 3771 static void EXPDouble256VectorTests(IntFunction<double[]> fa) { 3772 double[] a = fa.apply(SPECIES.length()); 3773 double[] r = fr.apply(SPECIES.length()); 3774 3775 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3776 for (int i = 0; i < a.length; i += SPECIES.length()) { 3777 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 3778 av.lanewise(VectorOperators.EXP).intoArray(r, i); 3779 } 3780 } 3781 3782 assertArraysEqualsWithinOneUlp(r, a, Double256VectorTests::EXP, Double256VectorTests::strictEXP); 3783 } 3784 3785 3786 static double LOG1P(double a) { 3787 return (double)(Math.log1p((double)a)); 3788 } 3789 3790 static double strictLOG1P(double a) { 3791 return (double)(StrictMath.log1p((double)a)); 3792 } 3793 3794 @Test(dataProvider = "doubleUnaryOpProvider") 3795 static void LOG1PDouble256VectorTests(IntFunction<double[]> fa) { 3796 double[] a = fa.apply(SPECIES.length()); 3797 double[] r = fr.apply(SPECIES.length()); 3798 3799 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3800 for (int i = 0; i < a.length; i += SPECIES.length()) { 3801 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 3802 av.lanewise(VectorOperators.LOG1P).intoArray(r, i); 3803 } 3804 } 3805 3806 assertArraysEqualsWithinOneUlp(r, a, Double256VectorTests::LOG1P, Double256VectorTests::strictLOG1P); 3807 } 3808 3809 3810 static double LOG(double a) { 3811 return (double)(Math.log((double)a)); 3812 } 3813 3814 static double strictLOG(double a) { 3815 return (double)(StrictMath.log((double)a)); 3816 } 3817 3818 @Test(dataProvider = "doubleUnaryOpProvider") 3819 static void LOGDouble256VectorTests(IntFunction<double[]> fa) { 3820 double[] a = fa.apply(SPECIES.length()); 3821 double[] r = fr.apply(SPECIES.length()); 3822 3823 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3824 for (int i = 0; i < a.length; i += SPECIES.length()) { 3825 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 3826 av.lanewise(VectorOperators.LOG).intoArray(r, i); 3827 } 3828 } 3829 3830 assertArraysEqualsWithinOneUlp(r, a, Double256VectorTests::LOG, Double256VectorTests::strictLOG); 3831 } 3832 3833 3834 static double LOG10(double a) { 3835 return (double)(Math.log10((double)a)); 3836 } 3837 3838 static double strictLOG10(double a) { 3839 return (double)(StrictMath.log10((double)a)); 3840 } 3841 3842 @Test(dataProvider = "doubleUnaryOpProvider") 3843 static void LOG10Double256VectorTests(IntFunction<double[]> fa) { 3844 double[] a = fa.apply(SPECIES.length()); 3845 double[] r = fr.apply(SPECIES.length()); 3846 3847 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3848 for (int i = 0; i < a.length; i += SPECIES.length()) { 3849 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 3850 av.lanewise(VectorOperators.LOG10).intoArray(r, i); 3851 } 3852 } 3853 3854 assertArraysEqualsWithinOneUlp(r, a, Double256VectorTests::LOG10, Double256VectorTests::strictLOG10); 3855 } 3856 3857 3858 static double EXPM1(double a) { 3859 return (double)(Math.expm1((double)a)); 3860 } 3861 3862 static double strictEXPM1(double a) { 3863 return (double)(StrictMath.expm1((double)a)); 3864 } 3865 3866 @Test(dataProvider = "doubleUnaryOpProvider") 3867 static void EXPM1Double256VectorTests(IntFunction<double[]> fa) { 3868 double[] a = fa.apply(SPECIES.length()); 3869 double[] r = fr.apply(SPECIES.length()); 3870 3871 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3872 for (int i = 0; i < a.length; i += SPECIES.length()) { 3873 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 3874 av.lanewise(VectorOperators.EXPM1).intoArray(r, i); 3875 } 3876 } 3877 3878 assertArraysEqualsWithinOneUlp(r, a, Double256VectorTests::EXPM1, Double256VectorTests::strictEXPM1); 3879 } 3880 3881 3882 static double COS(double a) { 3883 return (double)(Math.cos((double)a)); 3884 } 3885 3886 static double strictCOS(double a) { 3887 return (double)(StrictMath.cos((double)a)); 3888 } 3889 3890 @Test(dataProvider = "doubleUnaryOpProvider") 3891 static void COSDouble256VectorTests(IntFunction<double[]> fa) { 3892 double[] a = fa.apply(SPECIES.length()); 3893 double[] r = fr.apply(SPECIES.length()); 3894 3895 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3896 for (int i = 0; i < a.length; i += SPECIES.length()) { 3897 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 3898 av.lanewise(VectorOperators.COS).intoArray(r, i); 3899 } 3900 } 3901 3902 assertArraysEqualsWithinOneUlp(r, a, Double256VectorTests::COS, Double256VectorTests::strictCOS); 3903 } 3904 3905 3906 static double TAN(double a) { 3907 return (double)(Math.tan((double)a)); 3908 } 3909 3910 static double strictTAN(double a) { 3911 return (double)(StrictMath.tan((double)a)); 3912 } 3913 3914 @Test(dataProvider = "doubleUnaryOpProvider") 3915 static void TANDouble256VectorTests(IntFunction<double[]> fa) { 3916 double[] a = fa.apply(SPECIES.length()); 3917 double[] r = fr.apply(SPECIES.length()); 3918 3919 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3920 for (int i = 0; i < a.length; i += SPECIES.length()) { 3921 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 3922 av.lanewise(VectorOperators.TAN).intoArray(r, i); 3923 } 3924 } 3925 3926 assertArraysEqualsWithinOneUlp(r, a, Double256VectorTests::TAN, Double256VectorTests::strictTAN); 3927 } 3928 3929 3930 static double SINH(double a) { 3931 return (double)(Math.sinh((double)a)); 3932 } 3933 3934 static double strictSINH(double a) { 3935 return (double)(StrictMath.sinh((double)a)); 3936 } 3937 3938 @Test(dataProvider = "doubleUnaryOpProvider") 3939 static void SINHDouble256VectorTests(IntFunction<double[]> fa) { 3940 double[] a = fa.apply(SPECIES.length()); 3941 double[] r = fr.apply(SPECIES.length()); 3942 3943 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3944 for (int i = 0; i < a.length; i += SPECIES.length()) { 3945 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 3946 av.lanewise(VectorOperators.SINH).intoArray(r, i); 3947 } 3948 } 3949 3950 assertArraysEqualsWithinOneUlp(r, a, Double256VectorTests::SINH, Double256VectorTests::strictSINH); 3951 } 3952 3953 3954 static double COSH(double a) { 3955 return (double)(Math.cosh((double)a)); 3956 } 3957 3958 static double strictCOSH(double a) { 3959 return (double)(StrictMath.cosh((double)a)); 3960 } 3961 3962 @Test(dataProvider = "doubleUnaryOpProvider") 3963 static void COSHDouble256VectorTests(IntFunction<double[]> fa) { 3964 double[] a = fa.apply(SPECIES.length()); 3965 double[] r = fr.apply(SPECIES.length()); 3966 3967 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3968 for (int i = 0; i < a.length; i += SPECIES.length()) { 3969 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 3970 av.lanewise(VectorOperators.COSH).intoArray(r, i); 3971 } 3972 } 3973 3974 assertArraysEqualsWithinOneUlp(r, a, Double256VectorTests::COSH, Double256VectorTests::strictCOSH); 3975 } 3976 3977 3978 static double TANH(double a) { 3979 return (double)(Math.tanh((double)a)); 3980 } 3981 3982 static double strictTANH(double a) { 3983 return (double)(StrictMath.tanh((double)a)); 3984 } 3985 3986 @Test(dataProvider = "doubleUnaryOpProvider") 3987 static void TANHDouble256VectorTests(IntFunction<double[]> fa) { 3988 double[] a = fa.apply(SPECIES.length()); 3989 double[] r = fr.apply(SPECIES.length()); 3990 3991 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3992 for (int i = 0; i < a.length; i += SPECIES.length()) { 3993 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 3994 av.lanewise(VectorOperators.TANH).intoArray(r, i); 3995 } 3996 } 3997 3998 assertArraysEqualsWithinOneUlp(r, a, Double256VectorTests::TANH, Double256VectorTests::strictTANH); 3999 } 4000 4001 4002 static double ASIN(double a) { 4003 return (double)(Math.asin((double)a)); 4004 } 4005 4006 static double strictASIN(double a) { 4007 return (double)(StrictMath.asin((double)a)); 4008 } 4009 4010 @Test(dataProvider = "doubleUnaryOpProvider") 4011 static void ASINDouble256VectorTests(IntFunction<double[]> fa) { 4012 double[] a = fa.apply(SPECIES.length()); 4013 double[] r = fr.apply(SPECIES.length()); 4014 4015 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4016 for (int i = 0; i < a.length; i += SPECIES.length()) { 4017 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 4018 av.lanewise(VectorOperators.ASIN).intoArray(r, i); 4019 } 4020 } 4021 4022 assertArraysEqualsWithinOneUlp(r, a, Double256VectorTests::ASIN, Double256VectorTests::strictASIN); 4023 } 4024 4025 4026 static double ACOS(double a) { 4027 return (double)(Math.acos((double)a)); 4028 } 4029 4030 static double strictACOS(double a) { 4031 return (double)(StrictMath.acos((double)a)); 4032 } 4033 4034 @Test(dataProvider = "doubleUnaryOpProvider") 4035 static void ACOSDouble256VectorTests(IntFunction<double[]> fa) { 4036 double[] a = fa.apply(SPECIES.length()); 4037 double[] r = fr.apply(SPECIES.length()); 4038 4039 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4040 for (int i = 0; i < a.length; i += SPECIES.length()) { 4041 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 4042 av.lanewise(VectorOperators.ACOS).intoArray(r, i); 4043 } 4044 } 4045 4046 assertArraysEqualsWithinOneUlp(r, a, Double256VectorTests::ACOS, Double256VectorTests::strictACOS); 4047 } 4048 4049 4050 static double ATAN(double a) { 4051 return (double)(Math.atan((double)a)); 4052 } 4053 4054 static double strictATAN(double a) { 4055 return (double)(StrictMath.atan((double)a)); 4056 } 4057 4058 @Test(dataProvider = "doubleUnaryOpProvider") 4059 static void ATANDouble256VectorTests(IntFunction<double[]> fa) { 4060 double[] a = fa.apply(SPECIES.length()); 4061 double[] r = fr.apply(SPECIES.length()); 4062 4063 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4064 for (int i = 0; i < a.length; i += SPECIES.length()) { 4065 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 4066 av.lanewise(VectorOperators.ATAN).intoArray(r, i); 4067 } 4068 } 4069 4070 assertArraysEqualsWithinOneUlp(r, a, Double256VectorTests::ATAN, Double256VectorTests::strictATAN); 4071 } 4072 4073 4074 static double CBRT(double a) { 4075 return (double)(Math.cbrt((double)a)); 4076 } 4077 4078 static double strictCBRT(double a) { 4079 return (double)(StrictMath.cbrt((double)a)); 4080 } 4081 4082 @Test(dataProvider = "doubleUnaryOpProvider") 4083 static void CBRTDouble256VectorTests(IntFunction<double[]> fa) { 4084 double[] a = fa.apply(SPECIES.length()); 4085 double[] r = fr.apply(SPECIES.length()); 4086 4087 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4088 for (int i = 0; i < a.length; i += SPECIES.length()) { 4089 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 4090 av.lanewise(VectorOperators.CBRT).intoArray(r, i); 4091 } 4092 } 4093 4094 assertArraysEqualsWithinOneUlp(r, a, Double256VectorTests::CBRT, Double256VectorTests::strictCBRT); 4095 } 4096 4097 4098 static double HYPOT(double a, double b) { 4099 return (double)(Math.hypot((double)a, (double)b)); 4100 } 4101 4102 static double strictHYPOT(double a, double b) { 4103 return (double)(StrictMath.hypot((double)a, (double)b)); 4104 } 4105 4106 @Test(dataProvider = "doubleBinaryOpProvider") 4107 static void HYPOTDouble256VectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) { 4108 double[] a = fa.apply(SPECIES.length()); 4109 double[] b = fb.apply(SPECIES.length()); 4110 double[] r = fr.apply(SPECIES.length()); 4111 4112 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4113 for (int i = 0; i < a.length; i += SPECIES.length()) { 4114 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 4115 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i); 4116 av.lanewise(VectorOperators.HYPOT, bv).intoArray(r, i); 4117 } 4118 } 4119 4120 assertArraysEqualsWithinOneUlp(r, a, b, Double256VectorTests::HYPOT, Double256VectorTests::strictHYPOT); 4121 } 4122 4123 4124 4125 static double POW(double a, double b) { 4126 return (double)(Math.pow((double)a, (double)b)); 4127 } 4128 4129 static double strictPOW(double a, double b) { 4130 return (double)(StrictMath.pow((double)a, (double)b)); 4131 } 4132 4133 @Test(dataProvider = "doubleBinaryOpProvider") 4134 static void POWDouble256VectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) { 4135 double[] a = fa.apply(SPECIES.length()); 4136 double[] b = fb.apply(SPECIES.length()); 4137 double[] r = fr.apply(SPECIES.length()); 4138 4139 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4140 for (int i = 0; i < a.length; i += SPECIES.length()) { 4141 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 4142 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i); 4143 av.lanewise(VectorOperators.POW, bv).intoArray(r, i); 4144 } 4145 } 4146 4147 assertArraysEqualsWithinOneUlp(r, a, b, Double256VectorTests::POW, Double256VectorTests::strictPOW); 4148 } 4149 4150 static double pow(double a, double b) { 4151 return (double)(Math.pow((double)a, (double)b)); 4152 } 4153 4154 static double strictpow(double a, double b) { 4155 return (double)(StrictMath.pow((double)a, (double)b)); 4156 } 4157 4158 @Test(dataProvider = "doubleBinaryOpProvider") 4159 static void powDouble256VectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) { 4160 double[] a = fa.apply(SPECIES.length()); 4161 double[] b = fb.apply(SPECIES.length()); 4162 double[] r = fr.apply(SPECIES.length()); 4163 4164 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4165 for (int i = 0; i < a.length; i += SPECIES.length()) { 4166 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 4167 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i); 4168 av.pow(bv).intoArray(r, i); 4169 } 4170 } 4171 4172 assertArraysEqualsWithinOneUlp(r, a, b, Double256VectorTests::pow, Double256VectorTests::strictpow); 4173 } 4174 4175 4176 4177 static double ATAN2(double a, double b) { 4178 return (double)(Math.atan2((double)a, (double)b)); 4179 } 4180 4181 static double strictATAN2(double a, double b) { 4182 return (double)(StrictMath.atan2((double)a, (double)b)); 4183 } 4184 4185 @Test(dataProvider = "doubleBinaryOpProvider") 4186 static void ATAN2Double256VectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb) { 4187 double[] a = fa.apply(SPECIES.length()); 4188 double[] b = fb.apply(SPECIES.length()); 4189 double[] r = fr.apply(SPECIES.length()); 4190 4191 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4192 for (int i = 0; i < a.length; i += SPECIES.length()) { 4193 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 4194 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i); 4195 av.lanewise(VectorOperators.ATAN2, bv).intoArray(r, i); 4196 } 4197 } 4198 4199 assertArraysEqualsWithinOneUlp(r, a, b, Double256VectorTests::ATAN2, Double256VectorTests::strictATAN2); 4200 } 4201 4202 4203 4204 @Test(dataProvider = "doubleBinaryOpProvider") 4205 static void POWDouble256VectorTestsBroadcastSmokeTest(IntFunction<double[]> fa, IntFunction<double[]> fb) { 4206 double[] a = fa.apply(SPECIES.length()); 4207 double[] b = fb.apply(SPECIES.length()); 4208 double[] r = fr.apply(SPECIES.length()); 4209 4210 for (int i = 0; i < a.length; i += SPECIES.length()) { 4211 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 4212 av.lanewise(VectorOperators.POW, b[i]).intoArray(r, i); 4213 } 4214 4215 assertBroadcastArraysEqualsWithinOneUlp(r, a, b, Double256VectorTests::POW, Double256VectorTests::strictPOW); 4216 } 4217 4218 @Test(dataProvider = "doubleBinaryOpProvider") 4219 static void powDouble256VectorTestsBroadcastSmokeTest(IntFunction<double[]> fa, IntFunction<double[]> fb) { 4220 double[] a = fa.apply(SPECIES.length()); 4221 double[] b = fb.apply(SPECIES.length()); 4222 double[] r = fr.apply(SPECIES.length()); 4223 4224 for (int i = 0; i < a.length; i += SPECIES.length()) { 4225 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 4226 av.pow(b[i]).intoArray(r, i); 4227 } 4228 4229 assertBroadcastArraysEqualsWithinOneUlp(r, a, b, Double256VectorTests::pow, Double256VectorTests::strictpow); 4230 } 4231 4232 4233 4234 static double FMA(double a, double b, double c) { 4235 return (double)(Math.fma(a, b, c)); 4236 } 4237 static double fma(double a, double b, double c) { 4238 return (double)(Math.fma(a, b, c)); 4239 } 4240 4241 4242 @Test(dataProvider = "doubleTernaryOpProvider") 4243 static void FMADouble256VectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb, IntFunction<double[]> fc) { 4244 int count = INVOC_COUNT; 4245 switch ("FMA") { 4246 case "fma": case "lanewise_FMA": 4247 // Math.fma uses BigDecimal 4248 count = Math.max(5, count/20); break; 4249 } 4250 final int INVOC_COUNT = count; 4251 double[] a = fa.apply(SPECIES.length()); 4252 double[] b = fb.apply(SPECIES.length()); 4253 double[] c = fc.apply(SPECIES.length()); 4254 double[] r = fr.apply(SPECIES.length()); 4255 4256 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4257 for (int i = 0; i < a.length; i += SPECIES.length()) { 4258 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 4259 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i); 4260 DoubleVector cv = DoubleVector.fromArray(SPECIES, c, i); 4261 av.lanewise(VectorOperators.FMA, bv, cv).intoArray(r, i); 4262 } 4263 } 4264 4265 assertArraysEquals(r, a, b, c, Double256VectorTests::FMA); 4266 } 4267 @Test(dataProvider = "doubleTernaryOpProvider") 4268 static void fmaDouble256VectorTests(IntFunction<double[]> fa, IntFunction<double[]> fb, IntFunction<double[]> fc) { 4269 int count = INVOC_COUNT; 4270 switch ("fma") { 4271 case "fma": case "lanewise_FMA": 4272 // Math.fma uses BigDecimal 4273 count = Math.max(5, count/20); break; 4274 } 4275 final int INVOC_COUNT = count; 4276 double[] a = fa.apply(SPECIES.length()); 4277 double[] b = fb.apply(SPECIES.length()); 4278 double[] c = fc.apply(SPECIES.length()); 4279 double[] r = fr.apply(SPECIES.length()); 4280 4281 for (int i = 0; i < a.length; i += SPECIES.length()) { 4282 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 4283 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i); 4284 DoubleVector cv = DoubleVector.fromArray(SPECIES, c, i); 4285 av.fma(bv, cv).intoArray(r, i); 4286 } 4287 4288 assertArraysEquals(r, a, b, c, Double256VectorTests::fma); 4289 } 4290 4291 4292 @Test(dataProvider = "doubleTernaryOpMaskProvider") 4293 static void FMADouble256VectorTestsMasked(IntFunction<double[]> fa, IntFunction<double[]> fb, 4294 IntFunction<double[]> fc, IntFunction<boolean[]> fm) { 4295 int count = INVOC_COUNT; 4296 switch ("FMA") { 4297 case "fma": case "lanewise_FMA": 4298 // Math.fma uses BigDecimal 4299 count = Math.max(5, count/20); break; 4300 } 4301 final int INVOC_COUNT = count; 4302 double[] a = fa.apply(SPECIES.length()); 4303 double[] b = fb.apply(SPECIES.length()); 4304 double[] c = fc.apply(SPECIES.length()); 4305 double[] r = fr.apply(SPECIES.length()); 4306 boolean[] mask = fm.apply(SPECIES.length()); 4307 VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0); 4308 4309 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4310 for (int i = 0; i < a.length; i += SPECIES.length()) { 4311 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 4312 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i); 4313 DoubleVector cv = DoubleVector.fromArray(SPECIES, c, i); 4314 av.lanewise(VectorOperators.FMA, bv, cv, vmask).intoArray(r, i); 4315 } 4316 } 4317 4318 assertArraysEquals(r, a, b, c, mask, Double256VectorTests::FMA); 4319 } 4320 4321 4322 4323 4324 4325 @Test(dataProvider = "doubleTernaryOpProvider") 4326 static void FMADouble256VectorTestsBroadcastSmokeTest(IntFunction<double[]> fa, IntFunction<double[]> fb, IntFunction<double[]> fc) { 4327 double[] a = fa.apply(SPECIES.length()); 4328 double[] b = fb.apply(SPECIES.length()); 4329 double[] c = fc.apply(SPECIES.length()); 4330 double[] r = fr.apply(SPECIES.length()); 4331 4332 for (int i = 0; i < a.length; i += SPECIES.length()) { 4333 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 4334 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i); 4335 av.lanewise(VectorOperators.FMA, bv, c[i]).intoArray(r, i); 4336 } 4337 assertBroadcastArraysEquals(r, a, b, c, Double256VectorTests::FMA); 4338 } 4339 4340 @Test(dataProvider = "doubleTernaryOpProvider") 4341 static void FMADouble256VectorTestsAltBroadcastSmokeTest(IntFunction<double[]> fa, IntFunction<double[]> fb, IntFunction<double[]> fc) { 4342 double[] a = fa.apply(SPECIES.length()); 4343 double[] b = fb.apply(SPECIES.length()); 4344 double[] c = fc.apply(SPECIES.length()); 4345 double[] r = fr.apply(SPECIES.length()); 4346 4347 for (int i = 0; i < a.length; i += SPECIES.length()) { 4348 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 4349 DoubleVector cv = DoubleVector.fromArray(SPECIES, c, i); 4350 av.lanewise(VectorOperators.FMA, b[i], cv).intoArray(r, i); 4351 } 4352 assertAltBroadcastArraysEquals(r, a, b, c, Double256VectorTests::FMA); 4353 } 4354 4355 4356 @Test(dataProvider = "doubleTernaryOpMaskProvider") 4357 static void FMADouble256VectorTestsBroadcastMaskedSmokeTest(IntFunction<double[]> fa, IntFunction<double[]> fb, 4358 IntFunction<double[]> fc, IntFunction<boolean[]> fm) { 4359 double[] a = fa.apply(SPECIES.length()); 4360 double[] b = fb.apply(SPECIES.length()); 4361 double[] c = fc.apply(SPECIES.length()); 4362 double[] r = fr.apply(SPECIES.length()); 4363 boolean[] mask = fm.apply(SPECIES.length()); 4364 VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0); 4365 4366 for (int i = 0; i < a.length; i += SPECIES.length()) { 4367 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 4368 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i); 4369 av.lanewise(VectorOperators.FMA, bv, c[i], vmask).intoArray(r, i); 4370 } 4371 4372 assertBroadcastArraysEquals(r, a, b, c, mask, Double256VectorTests::FMA); 4373 } 4374 4375 @Test(dataProvider = "doubleTernaryOpMaskProvider") 4376 static void FMADouble256VectorTestsAltBroadcastMaskedSmokeTest(IntFunction<double[]> fa, IntFunction<double[]> fb, 4377 IntFunction<double[]> fc, IntFunction<boolean[]> fm) { 4378 double[] a = fa.apply(SPECIES.length()); 4379 double[] b = fb.apply(SPECIES.length()); 4380 double[] c = fc.apply(SPECIES.length()); 4381 double[] r = fr.apply(SPECIES.length()); 4382 boolean[] mask = fm.apply(SPECIES.length()); 4383 VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0); 4384 4385 for (int i = 0; i < a.length; i += SPECIES.length()) { 4386 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 4387 DoubleVector cv = DoubleVector.fromArray(SPECIES, c, i); 4388 av.lanewise(VectorOperators.FMA, b[i], cv, vmask).intoArray(r, i); 4389 } 4390 4391 assertAltBroadcastArraysEquals(r, a, b, c, mask, Double256VectorTests::FMA); 4392 } 4393 4394 4395 4396 4397 @Test(dataProvider = "doubleTernaryOpProvider") 4398 static void FMADouble256VectorTestsDoubleBroadcastSmokeTest(IntFunction<double[]> fa, IntFunction<double[]> fb, IntFunction<double[]> fc) { 4399 int count = INVOC_COUNT; 4400 switch ("FMA") { 4401 case "fma": case "lanewise_FMA": 4402 // Math.fma uses BigDecimal 4403 count = Math.max(5, count/20); break; 4404 } 4405 final int INVOC_COUNT = count; 4406 double[] a = fa.apply(SPECIES.length()); 4407 double[] b = fb.apply(SPECIES.length()); 4408 double[] c = fc.apply(SPECIES.length()); 4409 double[] r = fr.apply(SPECIES.length()); 4410 4411 for (int i = 0; i < a.length; i += SPECIES.length()) { 4412 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 4413 av.lanewise(VectorOperators.FMA, b[i], c[i]).intoArray(r, i); 4414 } 4415 4416 assertDoubleBroadcastArraysEquals(r, a, b, c, Double256VectorTests::FMA); 4417 } 4418 @Test(dataProvider = "doubleTernaryOpProvider") 4419 static void fmaDouble256VectorTestsDoubleBroadcastSmokeTest(IntFunction<double[]> fa, IntFunction<double[]> fb, IntFunction<double[]> fc) { 4420 int count = INVOC_COUNT; 4421 switch ("fma") { 4422 case "fma": case "lanewise_FMA": 4423 // Math.fma uses BigDecimal 4424 count = Math.max(5, count/20); break; 4425 } 4426 final int INVOC_COUNT = count; 4427 double[] a = fa.apply(SPECIES.length()); 4428 double[] b = fb.apply(SPECIES.length()); 4429 double[] c = fc.apply(SPECIES.length()); 4430 double[] r = fr.apply(SPECIES.length()); 4431 4432 for (int i = 0; i < a.length; i += SPECIES.length()) { 4433 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 4434 av.fma(b[i], c[i]).intoArray(r, i); 4435 } 4436 4437 assertDoubleBroadcastArraysEquals(r, a, b, c, Double256VectorTests::fma); 4438 } 4439 4440 4441 @Test(dataProvider = "doubleTernaryOpMaskProvider") 4442 static void FMADouble256VectorTestsDoubleBroadcastMaskedSmokeTest(IntFunction<double[]> fa, IntFunction<double[]> fb, 4443 IntFunction<double[]> fc, IntFunction<boolean[]> fm) { 4444 int count = INVOC_COUNT; 4445 switch ("FMA") { 4446 case "fma": case "lanewise_FMA": 4447 // Math.fma uses BigDecimal 4448 count = Math.max(5, count/20); break; 4449 } 4450 final int INVOC_COUNT = count; 4451 double[] a = fa.apply(SPECIES.length()); 4452 double[] b = fb.apply(SPECIES.length()); 4453 double[] c = fc.apply(SPECIES.length()); 4454 double[] r = fr.apply(SPECIES.length()); 4455 boolean[] mask = fm.apply(SPECIES.length()); 4456 VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0); 4457 4458 for (int i = 0; i < a.length; i += SPECIES.length()) { 4459 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 4460 av.lanewise(VectorOperators.FMA, b[i], c[i], vmask).intoArray(r, i); 4461 } 4462 4463 assertDoubleBroadcastArraysEquals(r, a, b, c, mask, Double256VectorTests::FMA); 4464 } 4465 4466 4467 4468 4469 static double NEG(double a) { 4470 return (double)(-((double)a)); 4471 } 4472 4473 static double neg(double a) { 4474 return (double)(-((double)a)); 4475 } 4476 4477 @Test(dataProvider = "doubleUnaryOpProvider") 4478 static void NEGDouble256VectorTests(IntFunction<double[]> fa) { 4479 double[] a = fa.apply(SPECIES.length()); 4480 double[] r = fr.apply(SPECIES.length()); 4481 4482 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4483 for (int i = 0; i < a.length; i += SPECIES.length()) { 4484 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 4485 av.lanewise(VectorOperators.NEG).intoArray(r, i); 4486 } 4487 } 4488 4489 assertArraysEquals(r, a, Double256VectorTests::NEG); 4490 } 4491 4492 @Test(dataProvider = "doubleUnaryOpProvider") 4493 static void negDouble256VectorTests(IntFunction<double[]> fa) { 4494 double[] a = fa.apply(SPECIES.length()); 4495 double[] r = fr.apply(SPECIES.length()); 4496 4497 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4498 for (int i = 0; i < a.length; i += SPECIES.length()) { 4499 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 4500 av.neg().intoArray(r, i); 4501 } 4502 } 4503 4504 assertArraysEquals(r, a, Double256VectorTests::neg); 4505 } 4506 4507 @Test(dataProvider = "doubleUnaryOpMaskProvider") 4508 static void NEGMaskedDouble256VectorTests(IntFunction<double[]> fa, 4509 IntFunction<boolean[]> fm) { 4510 double[] a = fa.apply(SPECIES.length()); 4511 double[] r = fr.apply(SPECIES.length()); 4512 boolean[] mask = fm.apply(SPECIES.length()); 4513 VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0); 4514 4515 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4516 for (int i = 0; i < a.length; i += SPECIES.length()) { 4517 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 4518 av.lanewise(VectorOperators.NEG, vmask).intoArray(r, i); 4519 } 4520 } 4521 4522 assertArraysEquals(r, a, mask, Double256VectorTests::NEG); 4523 } 4524 4525 static double ABS(double a) { 4526 return (double)(Math.abs((double)a)); 4527 } 4528 4529 static double abs(double a) { 4530 return (double)(Math.abs((double)a)); 4531 } 4532 4533 @Test(dataProvider = "doubleUnaryOpProvider") 4534 static void ABSDouble256VectorTests(IntFunction<double[]> fa) { 4535 double[] a = fa.apply(SPECIES.length()); 4536 double[] r = fr.apply(SPECIES.length()); 4537 4538 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4539 for (int i = 0; i < a.length; i += SPECIES.length()) { 4540 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 4541 av.lanewise(VectorOperators.ABS).intoArray(r, i); 4542 } 4543 } 4544 4545 assertArraysEquals(r, a, Double256VectorTests::ABS); 4546 } 4547 4548 @Test(dataProvider = "doubleUnaryOpProvider") 4549 static void absDouble256VectorTests(IntFunction<double[]> fa) { 4550 double[] a = fa.apply(SPECIES.length()); 4551 double[] r = fr.apply(SPECIES.length()); 4552 4553 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4554 for (int i = 0; i < a.length; i += SPECIES.length()) { 4555 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 4556 av.abs().intoArray(r, i); 4557 } 4558 } 4559 4560 assertArraysEquals(r, a, Double256VectorTests::abs); 4561 } 4562 4563 @Test(dataProvider = "doubleUnaryOpMaskProvider") 4564 static void ABSMaskedDouble256VectorTests(IntFunction<double[]> fa, 4565 IntFunction<boolean[]> fm) { 4566 double[] a = fa.apply(SPECIES.length()); 4567 double[] r = fr.apply(SPECIES.length()); 4568 boolean[] mask = fm.apply(SPECIES.length()); 4569 VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0); 4570 4571 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4572 for (int i = 0; i < a.length; i += SPECIES.length()) { 4573 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 4574 av.lanewise(VectorOperators.ABS, vmask).intoArray(r, i); 4575 } 4576 } 4577 4578 assertArraysEquals(r, a, mask, Double256VectorTests::ABS); 4579 } 4580 4581 4582 4583 4584 4585 4586 4587 4588 static double SQRT(double a) { 4589 return (double)(Math.sqrt((double)a)); 4590 } 4591 4592 static double sqrt(double a) { 4593 return (double)(Math.sqrt((double)a)); 4594 } 4595 4596 4597 4598 @Test(dataProvider = "doubleUnaryOpProvider") 4599 static void SQRTDouble256VectorTests(IntFunction<double[]> fa) { 4600 double[] a = fa.apply(SPECIES.length()); 4601 double[] r = fr.apply(SPECIES.length()); 4602 4603 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4604 for (int i = 0; i < a.length; i += SPECIES.length()) { 4605 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 4606 av.lanewise(VectorOperators.SQRT).intoArray(r, i); 4607 } 4608 } 4609 4610 assertArraysEquals(r, a, Double256VectorTests::SQRT); 4611 } 4612 4613 @Test(dataProvider = "doubleUnaryOpProvider") 4614 static void sqrtDouble256VectorTests(IntFunction<double[]> fa) { 4615 double[] a = fa.apply(SPECIES.length()); 4616 double[] r = fr.apply(SPECIES.length()); 4617 4618 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4619 for (int i = 0; i < a.length; i += SPECIES.length()) { 4620 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 4621 av.sqrt().intoArray(r, i); 4622 } 4623 } 4624 4625 assertArraysEquals(r, a, Double256VectorTests::sqrt); 4626 } 4627 4628 4629 4630 @Test(dataProvider = "doubleUnaryOpMaskProvider") 4631 static void SQRTMaskedDouble256VectorTests(IntFunction<double[]> fa, 4632 IntFunction<boolean[]> fm) { 4633 double[] a = fa.apply(SPECIES.length()); 4634 double[] r = fr.apply(SPECIES.length()); 4635 boolean[] mask = fm.apply(SPECIES.length()); 4636 VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0); 4637 4638 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4639 for (int i = 0; i < a.length; i += SPECIES.length()) { 4640 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 4641 av.lanewise(VectorOperators.SQRT, vmask).intoArray(r, i); 4642 } 4643 } 4644 4645 assertArraysEquals(r, a, mask, Double256VectorTests::SQRT); 4646 } 4647 4648 4649 @Test(dataProvider = "doubleCompareOpProvider") 4650 static void ltDouble256VectorTestsBroadcastSmokeTest(IntFunction<double[]> fa, IntFunction<double[]> fb) { 4651 double[] a = fa.apply(SPECIES.length()); 4652 double[] b = fb.apply(SPECIES.length()); 4653 4654 for (int i = 0; i < a.length; i += SPECIES.length()) { 4655 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 4656 VectorMask<Double> mv = av.lt(b[i]); 4657 4658 // Check results as part of computation. 4659 for (int j = 0; j < SPECIES.length(); j++) { 4660 Assert.assertEquals(mv.laneIsSet(j), a[i + j] < b[i]); 4661 } 4662 } 4663 } 4664 4665 @Test(dataProvider = "doubleCompareOpProvider") 4666 static void eqDouble256VectorTestsBroadcastMaskedSmokeTest(IntFunction<double[]> fa, IntFunction<double[]> fb) { 4667 double[] a = fa.apply(SPECIES.length()); 4668 double[] b = fb.apply(SPECIES.length()); 4669 4670 for (int i = 0; i < a.length; i += SPECIES.length()) { 4671 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 4672 VectorMask<Double> mv = av.eq(b[i]); 4673 4674 // Check results as part of computation. 4675 for (int j = 0; j < SPECIES.length(); j++) { 4676 Assert.assertEquals(mv.laneIsSet(j), a[i + j] == b[i]); 4677 } 4678 } 4679 } 4680 4681 @Test(dataProvider = "doubletoIntUnaryOpProvider") 4682 static void toIntArrayDouble256VectorTestsSmokeTest(IntFunction<double[]> fa) { 4683 double[] a = fa.apply(SPECIES.length()); 4684 4685 for (int i = 0; i < a.length; i += SPECIES.length()) { 4686 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 4687 int[] r = av.toIntArray(); 4688 assertArraysEquals(r, a, i); 4689 } 4690 } 4691 4692 @Test(dataProvider = "doubletoLongUnaryOpProvider") 4693 static void toLongArrayDouble256VectorTestsSmokeTest(IntFunction<double[]> fa) { 4694 double[] a = fa.apply(SPECIES.length()); 4695 4696 for (int i = 0; i < a.length; i += SPECIES.length()) { 4697 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 4698 long[] r = av.toLongArray(); 4699 assertArraysEquals(r, a, i); 4700 } 4701 } 4702 4703 4704 @Test(dataProvider = "doubleUnaryOpProvider") 4705 static void toStringDouble256VectorTestsSmokeTest(IntFunction<double[]> fa) { 4706 double[] a = fa.apply(SPECIES.length()); 4707 4708 for (int i = 0; i < a.length; i += SPECIES.length()) { 4709 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 4710 String str = av.toString(); 4711 4712 double subarr[] = Arrays.copyOfRange(a, i, i + SPECIES.length()); 4713 Assert.assertTrue(str.equals(Arrays.toString(subarr)), "at index " + i + ", string should be = " + Arrays.toString(subarr) + ", but is = " + str); 4714 } 4715 } 4716 4717 @Test(dataProvider = "doubleUnaryOpProvider") 4718 static void hashCodeDouble256VectorTestsSmokeTest(IntFunction<double[]> fa) { 4719 double[] a = fa.apply(SPECIES.length()); 4720 4721 for (int i = 0; i < a.length; i += SPECIES.length()) { 4722 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 4723 int hash = av.hashCode(); 4724 4725 double subarr[] = Arrays.copyOfRange(a, i, i + SPECIES.length()); 4726 int expectedHash = Objects.hash(SPECIES, Arrays.hashCode(subarr)); 4727 Assert.assertTrue(hash == expectedHash, "at index " + i + ", hash should be = " + expectedHash + ", but is = " + hash); 4728 } 4729 } 4730 4731 4732 static long ADDReduceLong(double[] a, int idx) { 4733 double res = 0; 4734 for (int i = idx; i < (idx + SPECIES.length()); i++) { 4735 res += a[i]; 4736 } 4737 4738 return (long)res; 4739 } 4740 4741 static long ADDReduceAllLong(double[] a) { 4742 long res = 0; 4743 for (int i = 0; i < a.length; i += SPECIES.length()) { 4744 res += ADDReduceLong(a, i); 4745 } 4746 4747 return res; 4748 } 4749 4750 @Test(dataProvider = "doubleUnaryOpProvider") 4751 static void ADDReduceLongDouble256VectorTests(IntFunction<double[]> fa) { 4752 double[] a = fa.apply(SPECIES.length()); 4753 long[] r = lfr.apply(SPECIES.length()); 4754 long ra = 0; 4755 4756 for (int i = 0; i < a.length; i += SPECIES.length()) { 4757 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 4758 r[i] = av.reduceLanesToLong(VectorOperators.ADD); 4759 } 4760 4761 ra = 0; 4762 for (int i = 0; i < a.length; i ++) { 4763 ra += r[i]; 4764 } 4765 4766 assertReductionLongArraysEquals(r, ra, a, 4767 Double256VectorTests::ADDReduceLong, Double256VectorTests::ADDReduceAllLong); 4768 } 4769 4770 static long ADDReduceLongMasked(double[] a, int idx, boolean[] mask) { 4771 double res = 0; 4772 for (int i = idx; i < (idx + SPECIES.length()); i++) { 4773 if(mask[i % SPECIES.length()]) 4774 res += a[i]; 4775 } 4776 4777 return (long)res; 4778 } 4779 4780 static long ADDReduceAllLongMasked(double[] a, boolean[] mask) { 4781 long res = 0; 4782 for (int i = 0; i < a.length; i += SPECIES.length()) { 4783 res += ADDReduceLongMasked(a, i, mask); 4784 } 4785 4786 return res; 4787 } 4788 4789 @Test(dataProvider = "doubleUnaryOpMaskProvider") 4790 static void ADDReduceLongDouble256VectorTestsMasked(IntFunction<double[]> fa, IntFunction<boolean[]> fm) { 4791 double[] a = fa.apply(SPECIES.length()); 4792 long[] r = lfr.apply(SPECIES.length()); 4793 boolean[] mask = fm.apply(SPECIES.length()); 4794 VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0); 4795 long ra = 0; 4796 4797 for (int i = 0; i < a.length; i += SPECIES.length()) { 4798 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 4799 r[i] = av.reduceLanesToLong(VectorOperators.ADD, vmask); 4800 } 4801 4802 ra = 0; 4803 for (int i = 0; i < a.length; i ++) { 4804 ra += r[i]; 4805 } 4806 4807 assertReductionLongArraysEqualsMasked(r, ra, a, mask, 4808 Double256VectorTests::ADDReduceLongMasked, Double256VectorTests::ADDReduceAllLongMasked); 4809 } 4810 4811 @Test(dataProvider = "doubletoLongUnaryOpProvider") 4812 static void BroadcastLongDouble256VectorTestsSmokeTest(IntFunction<double[]> fa) { 4813 double[] a = fa.apply(SPECIES.length()); 4814 double[] r = new double[a.length]; 4815 4816 for (int i = 0; i < a.length; i += SPECIES.length()) { 4817 DoubleVector.broadcast(SPECIES, (long)a[i]).intoArray(r, i); 4818 } 4819 assertBroadcastArraysEquals(r, a); 4820 } 4821 4822 @Test(dataProvider = "doubleBinaryOpMaskProvider") 4823 static void blendDouble256VectorTestsBroadcastLongSmokeTest(IntFunction<double[]> fa, IntFunction<double[]> fb, 4824 IntFunction<boolean[]> fm) { 4825 double[] a = fa.apply(SPECIES.length()); 4826 double[] b = fb.apply(SPECIES.length()); 4827 double[] r = fr.apply(SPECIES.length()); 4828 boolean[] mask = fm.apply(SPECIES.length()); 4829 VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0); 4830 4831 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4832 for (int i = 0; i < a.length; i += SPECIES.length()) { 4833 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 4834 av.blend((long)b[i], vmask).intoArray(r, i); 4835 } 4836 } 4837 assertBroadcastLongArraysEquals(r, a, b, mask, Double256VectorTests::blend); 4838 } 4839 4840 4841 @Test(dataProvider = "doubleUnaryOpSelectFromProvider") 4842 static void SelectFromDouble256VectorTests(IntFunction<double[]> fa, 4843 BiFunction<Integer,Integer,double[]> fs) { 4844 double[] a = fa.apply(SPECIES.length()); 4845 double[] order = fs.apply(a.length, SPECIES.length()); 4846 double[] r = fr.apply(SPECIES.length()); 4847 4848 for (int i = 0; i < a.length; i += SPECIES.length()) { 4849 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 4850 DoubleVector bv = DoubleVector.fromArray(SPECIES, order, i); 4851 bv.selectFrom(av).intoArray(r, i); 4852 } 4853 4854 assertSelectFromArraysEquals(r, a, order, SPECIES.length()); 4855 } 4856 4857 @Test(dataProvider = "doubleUnaryOpSelectFromMaskProvider") 4858 static void SelectFromDouble256VectorTestsMaskedSmokeTest(IntFunction<double[]> fa, 4859 BiFunction<Integer,Integer,double[]> fs, 4860 IntFunction<boolean[]> fm) { 4861 double[] a = fa.apply(SPECIES.length()); 4862 double[] order = fs.apply(a.length, SPECIES.length()); 4863 double[] r = fr.apply(SPECIES.length()); 4864 boolean[] mask = fm.apply(SPECIES.length()); 4865 VectorMask<Double> vmask = VectorMask.fromArray(SPECIES, mask, 0); 4866 4867 for (int i = 0; i < a.length; i += SPECIES.length()) { 4868 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i); 4869 DoubleVector bv = DoubleVector.fromArray(SPECIES, order, i); 4870 bv.selectFrom(av, vmask).intoArray(r, i); 4871 } 4872 4873 assertSelectFromArraysEquals(r, a, order, mask, SPECIES.length()); 4874 } 4875 4876 @Test(dataProvider = "shuffleProvider") 4877 static void shuffleMiscellaneousDouble256VectorTestsSmokeTest(BiFunction<Integer,Integer,int[]> fs) { 4878 int[] a = fs.apply(SPECIES.length() * BUFFER_REPS, SPECIES.length()); 4879 4880 for (int i = 0; i < a.length; i += SPECIES.length()) { 4881 var shuffle = VectorShuffle.fromArray(SPECIES, a, i); 4882 int hash = shuffle.hashCode(); 4883 int length = shuffle.length(); 4884 4885 int subarr[] = Arrays.copyOfRange(a, i, i + SPECIES.length()); 4886 int expectedHash = Objects.hash(SPECIES, Arrays.hashCode(subarr)); 4887 Assert.assertTrue(hash == expectedHash, "at index " + i + ", hash should be = " + expectedHash + ", but is = " + hash); 4888 Assert.assertEquals(length, SPECIES.length()); 4889 } 4890 } 4891 4892 @Test(dataProvider = "shuffleProvider") 4893 static void shuffleToStringDouble256VectorTestsSmokeTest(BiFunction<Integer,Integer,int[]> fs) { 4894 int[] a = fs.apply(SPECIES.length() * BUFFER_REPS, SPECIES.length()); 4895 4896 for (int i = 0; i < a.length; i += SPECIES.length()) { 4897 var shuffle = VectorShuffle.fromArray(SPECIES, a, i); 4898 String str = shuffle.toString(); 4899 4900 int subarr[] = Arrays.copyOfRange(a, i, i + SPECIES.length()); 4901 Assert.assertTrue(str.equals("Shuffle" + Arrays.toString(subarr)), "at index " + 4902 i + ", string should be = " + Arrays.toString(subarr) + ", but is = " + str); 4903 } 4904 } 4905 4906 @Test(dataProvider = "shuffleCompareOpProvider") 4907 static void shuffleEqualsDouble256VectorTestsSmokeTest(BiFunction<Integer,Integer,int[]> fa, BiFunction<Integer,Integer,int[]> fb) { 4908 int[] a = fa.apply(SPECIES.length() * BUFFER_REPS, SPECIES.length()); 4909 int[] b = fb.apply(SPECIES.length() * BUFFER_REPS, SPECIES.length()); 4910 4911 for (int i = 0; i < a.length; i += SPECIES.length()) { 4912 var av = VectorShuffle.fromArray(SPECIES, a, i); 4913 var bv = VectorShuffle.fromArray(SPECIES, b, i); 4914 boolean eq = av.equals(bv); 4915 int to = i + SPECIES.length(); 4916 Assert.assertEquals(eq, Arrays.equals(a, i, to, b, i, to)); 4917 } 4918 } 4919 4920 @Test(dataProvider = "maskCompareOpProvider") 4921 static void maskEqualsDouble256VectorTestsSmokeTest(IntFunction<boolean[]> fa, IntFunction<boolean[]> fb) { 4922 boolean[] a = fa.apply(SPECIES.length()); 4923 boolean[] b = fb.apply(SPECIES.length()); 4924 4925 for (int i = 0; i < a.length; i += SPECIES.length()) { 4926 var av = SPECIES.loadMask(a, i); 4927 var bv = SPECIES.loadMask(b, i); 4928 boolean equals = av.equals(bv); 4929 int to = i + SPECIES.length(); 4930 Assert.assertEquals(equals, Arrays.equals(a, i, to, b, i, to)); 4931 } 4932 } 4933 4934 static boolean beq(boolean a, boolean b) { 4935 return (a == b); 4936 } 4937 4938 @Test(dataProvider = "maskCompareOpProvider") 4939 static void maskEqDouble256VectorTestsSmokeTest(IntFunction<boolean[]> fa, IntFunction<boolean[]> fb) { 4940 boolean[] a = fa.apply(SPECIES.length()); 4941 boolean[] b = fb.apply(SPECIES.length()); 4942 boolean[] r = new boolean[a.length]; 4943 4944 for (int i = 0; i < a.length; i += SPECIES.length()) { 4945 var av = SPECIES.loadMask(a, i); 4946 var bv = SPECIES.loadMask(b, i); 4947 var cv = av.eq(bv); 4948 cv.intoArray(r, i); 4949 } 4950 assertArraysEquals(r, a, b, Double256VectorTests::beq); 4951 } 4952 4953 @Test(dataProvider = "maskProvider") 4954 static void maskHashCodeDouble256VectorTestsSmokeTest(IntFunction<boolean[]> fa) { 4955 boolean[] a = fa.apply(SPECIES.length()); 4956 4957 for (int i = 0; i < a.length; i += SPECIES.length()) { 4958 var vmask = SPECIES.loadMask(a, i); 4959 int hash = vmask.hashCode(); 4960 4961 boolean subarr[] = Arrays.copyOfRange(a, i, i + SPECIES.length()); 4962 int expectedHash = Objects.hash(SPECIES, Arrays.hashCode(subarr)); 4963 Assert.assertTrue(hash == expectedHash, "at index " + i + ", hash should be = " + expectedHash + ", but is = " + hash); 4964 } 4965 } 4966 4967 static int maskTrueCount(boolean[] a, int idx) { 4968 int trueCount = 0; 4969 for (int i = idx; i < idx + SPECIES.length(); i++) { 4970 trueCount += a[i] ? 1 : 0; 4971 } 4972 return trueCount; 4973 } 4974 4975 @Test(dataProvider = "maskProvider") 4976 static void maskTrueCountDouble256VectorTestsSmokeTest(IntFunction<boolean[]> fa) { 4977 boolean[] a = fa.apply(SPECIES.length()); 4978 int[] r = new int[a.length]; 4979 4980 for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { 4981 for (int i = 0; i < a.length; i += SPECIES.length()) { 4982 var vmask = SPECIES.loadMask(a, i); 4983 r[i] = vmask.trueCount(); 4984 } 4985 } 4986 4987 assertMaskReductionArraysEquals(r, a, Double256VectorTests::maskTrueCount); 4988 } 4989 4990 static int maskLastTrue(boolean[] a, int idx) { 4991 int i = idx + SPECIES.length() - 1; 4992 for (; i >= idx; i--) { 4993 if (a[i]) { 4994 break; 4995 } 4996 } 4997 return i - idx; 4998 } 4999 5000 @Test(dataProvider = "maskProvider") 5001 static void maskLastTrueDouble256VectorTestsSmokeTest(IntFunction<boolean[]> fa) { 5002 boolean[] a = fa.apply(SPECIES.length()); 5003 int[] r = new int[a.length]; 5004 5005 for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { 5006 for (int i = 0; i < a.length; i += SPECIES.length()) { 5007 var vmask = SPECIES.loadMask(a, i); 5008 r[i] = vmask.lastTrue(); 5009 } 5010 } 5011 5012 assertMaskReductionArraysEquals(r, a, Double256VectorTests::maskLastTrue); 5013 } 5014 5015 static int maskFirstTrue(boolean[] a, int idx) { 5016 int i = idx; 5017 for (; i < idx + SPECIES.length(); i++) { 5018 if (a[i]) { 5019 break; 5020 } 5021 } 5022 return i - idx; 5023 } 5024 5025 @Test(dataProvider = "maskProvider") 5026 static void maskFirstTrueDouble256VectorTestsSmokeTest(IntFunction<boolean[]> fa) { 5027 boolean[] a = fa.apply(SPECIES.length()); 5028 int[] r = new int[a.length]; 5029 5030 for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) { 5031 for (int i = 0; i < a.length; i += SPECIES.length()) { 5032 var vmask = SPECIES.loadMask(a, i); 5033 r[i] = vmask.firstTrue(); 5034 } 5035 } 5036 5037 assertMaskReductionArraysEquals(r, a, Double256VectorTests::maskFirstTrue); 5038 } 5039 5040 @DataProvider 5041 public static Object[][] longMaskProvider() { 5042 return new Object[][]{ 5043 {0xFFFFFFFFFFFFFFFFL}, 5044 {0x0000000000000000L}, 5045 {0x5555555555555555L}, 5046 {0x0123456789abcdefL}, 5047 }; 5048 } 5049 5050 @Test(dataProvider = "longMaskProvider") 5051 static void maskFromToLongDouble256VectorTestsSmokeTest(long inputLong) { 5052 var vmask = VectorMask.fromLong(SPECIES, inputLong); 5053 long outputLong = vmask.toLong(); 5054 Assert.assertEquals(outputLong, (inputLong & (((0xFFFFFFFFFFFFFFFFL >>> (64 - SPECIES.length())))))); 5055 } 5056 5057 @DataProvider 5058 public static Object[][] offsetProvider() { 5059 return new Object[][]{ 5060 {0}, 5061 {-1}, 5062 {+1}, 5063 {+2}, 5064 {-2}, 5065 }; 5066 } 5067 5068 @Test(dataProvider = "offsetProvider") 5069 static void indexInRangeDouble256VectorTestsSmokeTest(int offset) { 5070 int limit = SPECIES.length() * BUFFER_REPS; 5071 for (int i = 0; i < limit; i += SPECIES.length()) { 5072 var actualMask = SPECIES.indexInRange(i + offset, limit); 5073 var expectedMask = SPECIES.maskAll(true).indexInRange(i + offset, limit); 5074 assert(actualMask.equals(expectedMask)); 5075 for (int j = 0; j < SPECIES.length(); j++) { 5076 int index = i + j + offset; 5077 Assert.assertEquals(actualMask.laneIsSet(j), index >= 0 && index < limit); 5078 } 5079 } 5080 } 5081 5082 @DataProvider 5083 public static Object[][] lengthProvider() { 5084 return new Object[][]{ 5085 {0}, 5086 {1}, 5087 {32}, 5088 {37}, 5089 {1024}, 5090 {1024+1}, 5091 {1024+5}, 5092 }; 5093 } 5094 5095 @Test(dataProvider = "lengthProvider") 5096 static void loopBoundDouble256VectorTestsSmokeTest(int length) { 5097 int actualLoopBound = SPECIES.loopBound(length); 5098 int expectedLoopBound = length - Math.floorMod(length, SPECIES.length()); 5099 Assert.assertEquals(actualLoopBound, expectedLoopBound); 5100 } 5101 5102 @Test 5103 static void ElementSizeDouble256VectorTestsSmokeTest() { 5104 DoubleVector av = DoubleVector.zero(SPECIES); 5105 int elsize = av.elementSize(); 5106 Assert.assertEquals(elsize, Double.SIZE); 5107 } 5108 5109 @Test 5110 static void VectorShapeDouble256VectorTestsSmokeTest() { 5111 DoubleVector av = DoubleVector.zero(SPECIES); 5112 VectorShape vsh = av.shape(); 5113 assert(vsh.equals(VectorShape.S_256_BIT)); 5114 } 5115 5116 @Test 5117 static void ShapeWithLanesDouble256VectorTestsSmokeTest() { 5118 DoubleVector av = DoubleVector.zero(SPECIES); 5119 VectorShape vsh = av.shape(); 5120 VectorSpecies species = vsh.withLanes(double.class); 5121 assert(species.equals(SPECIES)); 5122 } 5123 5124 @Test 5125 static void ElementTypeDouble256VectorTestsSmokeTest() { 5126 DoubleVector av = DoubleVector.zero(SPECIES); 5127 assert(av.species().elementType() == double.class); 5128 } 5129 5130 @Test 5131 static void SpeciesElementSizeDouble256VectorTestsSmokeTest() { 5132 DoubleVector av = DoubleVector.zero(SPECIES); 5133 assert(av.species().elementSize() == Double.SIZE); 5134 } 5135 5136 @Test 5137 static void VectorTypeDouble256VectorTestsSmokeTest() { 5138 DoubleVector av = DoubleVector.zero(SPECIES); 5139 assert(av.species().vectorType() == av.getClass()); 5140 } 5141 5142 @Test 5143 static void WithLanesDouble256VectorTestsSmokeTest() { 5144 DoubleVector av = DoubleVector.zero(SPECIES); 5145 VectorSpecies species = av.species().withLanes(double.class); 5146 assert(species.equals(SPECIES)); 5147 } 5148 5149 @Test 5150 static void WithShapeDouble256VectorTestsSmokeTest() { 5151 DoubleVector av = DoubleVector.zero(SPECIES); 5152 VectorShape vsh = av.shape(); 5153 VectorSpecies species = av.species().withShape(vsh); 5154 assert(species.equals(SPECIES)); 5155 } 5156 5157 @Test 5158 static void MaskAllTrueDouble256VectorTestsSmokeTest() { 5159 for (int ic = 0; ic < INVOC_COUNT; ic++) { 5160 Assert.assertEquals(SPECIES.maskAll(true).toLong(), -1L >>> (64 - SPECIES.length())); 5161 } 5162 } 5163 } 5164