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