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