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