1 /* 2 * Copyright (c) 2018, 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 21 * questions. 22 */ 23 24 /* 25 * @test 26 * @modules jdk.incubator.vector 27 * @run testng/othervm -ea -esa FloatMaxVectorTests 28 */ 29 30 import jdk.incubator.vector.VectorShape; 31 import jdk.incubator.vector.VectorSpecies; 32 import jdk.incubator.vector.VectorShuffle; 33 import jdk.incubator.vector.VectorMask; 34 import jdk.incubator.vector.Vector; 35 36 import jdk.incubator.vector.FloatVector; 37 38 import org.testng.Assert; 39 import org.testng.annotations.DataProvider; 40 import org.testng.annotations.Test; 41 42 import java.lang.Integer; 43 import java.util.List; 44 import java.util.Arrays; 45 import java.util.function.BiFunction; 46 import java.util.function.IntFunction; 47 import java.util.stream.Collectors; 48 import java.util.stream.Stream; 49 50 @Test 51 public class FloatMaxVectorTests extends AbstractVectorTest { 52 53 static final VectorSpecies<Float> SPECIES = 54 FloatVector.SPECIES_MAX; 55 56 static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100); 57 58 static VectorShape getMaxBit() { 59 return VectorShape.S_Max_BIT; 60 } 61 62 interface FUnOp { 63 float apply(float a); 64 } 65 66 static void assertArraysEquals(float[] a, float[] r, FUnOp f) { 67 int i = 0; 68 try { 69 for (; i < a.length; i++) { 70 Assert.assertEquals(r[i], f.apply(a[i])); 71 } 72 } catch (AssertionError e) { 73 Assert.assertEquals(r[i], f.apply(a[i]), "at index #" + i + ", input = " + a[i]); 74 } 75 } 76 77 static void assertArraysEquals(float[] a, float[] r, boolean[] mask, FUnOp f) { 78 int i = 0; 79 try { 80 for (; i < a.length; i++) { 81 Assert.assertEquals(r[i], mask[i % SPECIES.length()] ? f.apply(a[i]) : a[i]); 82 } 83 } catch (AssertionError e) { 84 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()]); 85 } 86 } 87 88 interface FReductionOp { 89 float apply(float[] a, int idx); 90 } 91 92 interface FReductionAllOp { 93 float apply(float[] a); 94 } 95 96 static void assertReductionArraysEquals(float[] a, float[] b, float c, 97 FReductionOp f, FReductionAllOp fa) { 98 int i = 0; 99 try { 100 Assert.assertEquals(c, fa.apply(a)); 101 for (; i < a.length; i += SPECIES.length()) { 102 Assert.assertEquals(b[i], f.apply(a, i)); 103 } 104 } catch (AssertionError e) { 105 Assert.assertEquals(c, fa.apply(a), "Final result is incorrect!"); 106 Assert.assertEquals(b[i], f.apply(a, i), "at index #" + i); 107 } 108 } 109 110 interface FBoolReductionOp { 111 boolean apply(boolean[] a, int idx); 112 } 113 114 static void assertReductionBoolArraysEquals(boolean[] a, boolean[] b, FBoolReductionOp f) { 115 int i = 0; 116 try { 117 for (; i < a.length; i += SPECIES.length()) { 118 Assert.assertEquals(f.apply(a, i), b[i]); 119 } 120 } catch (AssertionError e) { 121 Assert.assertEquals(f.apply(a, i), b[i], "at index #" + i); 122 } 123 } 124 125 static void assertInsertArraysEquals(float[] a, float[] b, float element, int index) { 126 int i = 0; 127 try { 128 for (; i < a.length; i += 1) { 129 if(i%SPECIES.length() == index) { 130 Assert.assertEquals(b[i], element); 131 } else { 132 Assert.assertEquals(b[i], a[i]); 133 } 134 } 135 } catch (AssertionError e) { 136 if (i%SPECIES.length() == index) { 137 Assert.assertEquals(b[i], element, "at index #" + i); 138 } else { 139 Assert.assertEquals(b[i], a[i], "at index #" + i); 140 } 141 } 142 } 143 144 static void assertRearrangeArraysEquals(float[] a, float[] r, int[] order, int vector_len) { 145 int i = 0, j = 0; 146 try { 147 for (; i < a.length; i += vector_len) { 148 for (j = 0; j < vector_len; j++) { 149 Assert.assertEquals(r[i+j], a[i+order[i+j]]); 150 } 151 } 152 } catch (AssertionError e) { 153 int idx = i + j; 154 Assert.assertEquals(r[i+j], a[i+order[i+j]], "at index #" + idx + ", input = " + a[i+order[i+j]]); 155 } 156 } 157 158 interface FBinOp { 159 float apply(float a, float b); 160 } 161 162 interface FBinMaskOp { 163 float apply(float a, float b, boolean m); 164 165 static FBinMaskOp lift(FBinOp f) { 166 return (a, b, m) -> m ? f.apply(a, b) : a; 167 } 168 } 169 170 static void assertArraysEquals(float[] a, float[] b, float[] r, FBinOp f) { 171 int i = 0; 172 try { 173 for (; i < a.length; i++) { 174 Assert.assertEquals(r[i], f.apply(a[i], b[i])); 175 } 176 } catch (AssertionError e) { 177 Assert.assertEquals(f.apply(a[i], b[i]), r[i], "(" + a[i] + ", " + b[i] + ") at index #" + i); 178 } 179 } 180 181 static void assertArraysEquals(float[] a, float[] b, float[] r, boolean[] mask, FBinOp f) { 182 assertArraysEquals(a, b, r, mask, FBinMaskOp.lift(f)); 183 } 184 185 static void assertArraysEquals(float[] a, float[] b, float[] r, boolean[] mask, FBinMaskOp f) { 186 int i = 0; 187 try { 188 for (; i < a.length; i++) { 189 Assert.assertEquals(r[i], f.apply(a[i], b[i], mask[i % SPECIES.length()])); 190 } 191 } catch (AssertionError err) { 192 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()]); 193 } 194 } 195 196 static void assertShiftArraysEquals(float[] a, float[] b, float[] r, FBinOp f) { 197 int i = 0; 198 int j = 0; 199 try { 200 for (; j < a.length; j += SPECIES.length()) { 201 for (i = 0; i < SPECIES.length(); i++) { 202 Assert.assertEquals(f.apply(a[i+j], b[j]), r[i+j]); 203 } 204 } 205 } catch (AssertionError e) { 206 Assert.assertEquals(f.apply(a[i+j], b[j]), r[i+j], "at index #" + i + ", " + j); 207 } 208 } 209 210 static void assertShiftArraysEquals(float[] a, float[] b, float[] r, boolean[] mask, FBinOp f) { 211 assertShiftArraysEquals(a, b, r, mask, FBinMaskOp.lift(f)); 212 } 213 214 static void assertShiftArraysEquals(float[] a, float[] b, float[] r, boolean[] mask, FBinMaskOp f) { 215 int i = 0; 216 int j = 0; 217 try { 218 for (; j < a.length; j += SPECIES.length()) { 219 for (i = 0; i < SPECIES.length(); i++) { 220 Assert.assertEquals(r[i+j], f.apply(a[i+j], b[j], mask[i])); 221 } 222 } 223 } catch (AssertionError err) { 224 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]); 225 } 226 } 227 228 interface FTernOp { 229 float apply(float a, float b, float c); 230 } 231 232 interface FTernMaskOp { 233 float apply(float a, float b, float c, boolean m); 234 235 static FTernMaskOp lift(FTernOp f) { 236 return (a, b, c, m) -> m ? f.apply(a, b, c) : a; 237 } 238 } 239 240 static void assertArraysEquals(float[] a, float[] b, float[] c, float[] r, FTernOp f) { 241 int i = 0; 242 try { 243 for (; i < a.length; i++) { 244 Assert.assertEquals(r[i], f.apply(a[i], b[i], c[i])); 245 } 246 } catch (AssertionError e) { 247 Assert.assertEquals(r[i], f.apply(a[i], b[i], c[i]), "at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]); 248 } 249 } 250 251 static void assertArraysEquals(float[] a, float[] b, float[] c, float[] r, boolean[] mask, FTernOp f) { 252 assertArraysEquals(a, b, c, r, mask, FTernMaskOp.lift(f)); 253 } 254 255 static void assertArraysEquals(float[] a, float[] b, float[] c, float[] r, boolean[] mask, FTernMaskOp f) { 256 int i = 0; 257 try { 258 for (; i < a.length; i++) { 259 Assert.assertEquals(r[i], f.apply(a[i], b[i], c[i], mask[i % SPECIES.length()])); 260 } 261 } catch (AssertionError err) { 262 Assert.assertEquals(r[i], f.apply(a[i], b[i], c[i], mask[i % SPECIES.length()]), "at index #" + i + ", input1 = " + a[i] + ", input2 = " 263 + b[i] + ", input3 = " + c[i] + ", mask = " + mask[i % SPECIES.length()]); 264 } 265 } 266 267 static boolean isWithin1Ulp(float actual, float expected) { 268 if (Float.isNaN(expected) && !Float.isNaN(actual)) { 269 return false; 270 } else if (!Float.isNaN(expected) && Float.isNaN(actual)) { 271 return false; 272 } 273 274 float low = Math.nextDown(expected); 275 float high = Math.nextUp(expected); 276 277 if (Float.compare(low, expected) > 0) { 278 return false; 279 } 280 281 if (Float.compare(high, expected) < 0) { 282 return false; 283 } 284 285 return true; 286 } 287 288 static void assertArraysEqualsWithinOneUlp(float[] a, float[] r, FUnOp mathf, FUnOp strictmathf) { 289 int i = 0; 290 try { 291 // Check that result is within 1 ulp of strict math or equivalent to math implementation. 292 for (; i < a.length; i++) { 293 Assert.assertTrue(Float.compare(r[i], mathf.apply(a[i])) == 0 || 294 isWithin1Ulp(r[i], strictmathf.apply(a[i]))); 295 } 296 } catch (AssertionError e) { 297 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])); 298 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])); 299 } 300 } 301 302 static void assertArraysEqualsWithinOneUlp(float[] a, float[] b, float[] r, FBinOp mathf, FBinOp strictmathf) { 303 int i = 0; 304 try { 305 // Check that result is within 1 ulp of strict math or equivalent to math implementation. 306 for (; i < a.length; i++) { 307 Assert.assertTrue(Float.compare(r[i], mathf.apply(a[i], b[i])) == 0 || 308 isWithin1Ulp(r[i], strictmathf.apply(a[i], b[i]))); 309 } 310 } catch (AssertionError e) { 311 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])); 312 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])); 313 } 314 } 315 316 interface FBinArrayOp { 317 float apply(float[] a, int b); 318 } 319 320 static void assertArraysEquals(float[] a, float[] r, FBinArrayOp f) { 321 int i = 0; 322 try { 323 for (; i < a.length; i++) { 324 Assert.assertEquals(f.apply(a, i), r[i]); 325 } 326 } catch (AssertionError e) { 327 Assert.assertEquals(f.apply(a,i), r[i], "at index #" + i); 328 } 329 } 330 interface FGatherScatterOp { 331 float[] apply(float[] a, int ix, int[] b, int iy); 332 } 333 334 static void assertArraysEquals(float[] a, int[] b, float[] r, FGatherScatterOp f) { 335 int i = 0; 336 try { 337 for (; i < a.length; i += SPECIES.length()) { 338 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()), 339 f.apply(a, i, b, i)); 340 } 341 } catch (AssertionError e) { 342 float[] ref = f.apply(a, i, b, i); 343 float[] res = Arrays.copyOfRange(r, i, i+SPECIES.length()); 344 Assert.assertEquals(ref, res, 345 "(ref: " + Arrays.toString(ref) + ", res: " + Arrays.toString(res) + ", a: " 346 + Arrays.toString(Arrays.copyOfRange(a, i, i+SPECIES.length())) 347 + ", b: " 348 + Arrays.toString(Arrays.copyOfRange(b, i, i+SPECIES.length())) 349 + " at index #" + i); 350 } 351 } 352 353 354 static final List<IntFunction<float[]>> FLOAT_GENERATORS = List.of( 355 withToString("float[-i * 5]", (int s) -> { 356 return fill(s * 1000, 357 i -> (float)(-i * 5)); 358 }), 359 withToString("float[i * 5]", (int s) -> { 360 return fill(s * 1000, 361 i -> (float)(i * 5)); 362 }), 363 withToString("float[i + 1]", (int s) -> { 364 return fill(s * 1000, 365 i -> (((float)(i + 1) == 0) ? 1 : (float)(i + 1))); 366 }), 367 withToString("float[cornerCaseValue(i)]", (int s) -> { 368 return fill(s * 1000, 369 i -> cornerCaseValue(i)); 370 }) 371 ); 372 373 // Create combinations of pairs 374 // @@@ Might be sensitive to order e.g. div by 0 375 static final List<List<IntFunction<float[]>>> FLOAT_GENERATOR_PAIRS = 376 Stream.of(FLOAT_GENERATORS.get(0)). 377 flatMap(fa -> FLOAT_GENERATORS.stream().skip(1).map(fb -> List.of(fa, fb))). 378 collect(Collectors.toList()); 379 380 @DataProvider 381 public Object[][] boolUnaryOpProvider() { 382 return BOOL_ARRAY_GENERATORS.stream(). 383 map(f -> new Object[]{f}). 384 toArray(Object[][]::new); 385 } 386 387 static final List<List<IntFunction<float[]>>> FLOAT_GENERATOR_TRIPLES = 388 FLOAT_GENERATOR_PAIRS.stream(). 389 flatMap(pair -> FLOAT_GENERATORS.stream().map(f -> List.of(pair.get(0), pair.get(1), f))). 390 collect(Collectors.toList()); 391 392 @DataProvider 393 public Object[][] floatBinaryOpProvider() { 394 return FLOAT_GENERATOR_PAIRS.stream().map(List::toArray). 395 toArray(Object[][]::new); 396 } 397 398 @DataProvider 399 public Object[][] floatIndexedOpProvider() { 400 return FLOAT_GENERATOR_PAIRS.stream().map(List::toArray). 401 toArray(Object[][]::new); 402 } 403 404 @DataProvider 405 public Object[][] floatBinaryOpMaskProvider() { 406 return BOOLEAN_MASK_GENERATORS.stream(). 407 flatMap(fm -> FLOAT_GENERATOR_PAIRS.stream().map(lfa -> { 408 return Stream.concat(lfa.stream(), Stream.of(fm)).toArray(); 409 })). 410 toArray(Object[][]::new); 411 } 412 413 @DataProvider 414 public Object[][] floatTernaryOpProvider() { 415 return FLOAT_GENERATOR_TRIPLES.stream().map(List::toArray). 416 toArray(Object[][]::new); 417 } 418 419 @DataProvider 420 public Object[][] floatTernaryOpMaskProvider() { 421 return BOOLEAN_MASK_GENERATORS.stream(). 422 flatMap(fm -> FLOAT_GENERATOR_TRIPLES.stream().map(lfa -> { 423 return Stream.concat(lfa.stream(), Stream.of(fm)).toArray(); 424 })). 425 toArray(Object[][]::new); 426 } 427 428 @DataProvider 429 public Object[][] floatUnaryOpProvider() { 430 return FLOAT_GENERATORS.stream(). 431 map(f -> new Object[]{f}). 432 toArray(Object[][]::new); 433 } 434 435 @DataProvider 436 public Object[][] floatUnaryOpMaskProvider() { 437 return BOOLEAN_MASK_GENERATORS.stream(). 438 flatMap(fm -> FLOAT_GENERATORS.stream().map(fa -> { 439 return new Object[] {fa, fm}; 440 })). 441 toArray(Object[][]::new); 442 } 443 444 @DataProvider 445 public Object[][] floatUnaryOpShuffleProvider() { 446 return INT_SHUFFLE_GENERATORS.stream(). 447 flatMap(fs -> FLOAT_GENERATORS.stream().map(fa -> { 448 return new Object[] {fa, fs}; 449 })). 450 toArray(Object[][]::new); 451 } 452 453 @DataProvider 454 public Object[][] floatUnaryOpIndexProvider() { 455 return INT_INDEX_GENERATORS.stream(). 456 flatMap(fs -> FLOAT_GENERATORS.stream().map(fa -> { 457 return new Object[] {fa, fs}; 458 })). 459 toArray(Object[][]::new); 460 } 461 462 463 static final List<IntFunction<float[]>> FLOAT_COMPARE_GENERATORS = List.of( 464 withToString("float[i]", (int s) -> { 465 return fill(s * 1000, 466 i -> (float)i); 467 }), 468 withToString("float[i + 1]", (int s) -> { 469 return fill(s * 1000, 470 i -> (float)(i + 1)); 471 }), 472 withToString("float[i - 2]", (int s) -> { 473 return fill(s * 1000, 474 i -> (float)(i - 2)); 475 }), 476 withToString("float[zigZag(i)]", (int s) -> { 477 return fill(s * 1000, 478 i -> i%3 == 0 ? (float)i : (i%3 == 1 ? (float)(i + 1) : (float)(i - 2))); 479 }), 480 withToString("float[cornerCaseValue(i)]", (int s) -> { 481 return fill(s * 1000, 482 i -> cornerCaseValue(i)); 483 }) 484 ); 485 486 static final List<List<IntFunction<float[]>>> FLOAT_COMPARE_GENERATOR_PAIRS = 487 FLOAT_COMPARE_GENERATORS.stream(). 488 flatMap(fa -> FLOAT_COMPARE_GENERATORS.stream().map(fb -> List.of(fa, fb))). 489 collect(Collectors.toList()); 490 491 @DataProvider 492 public Object[][] floatCompareOpProvider() { 493 return FLOAT_COMPARE_GENERATOR_PAIRS.stream().map(List::toArray). 494 toArray(Object[][]::new); 495 } 496 497 interface ToFloatF { 498 float apply(int i); 499 } 500 501 static float[] fill(int s , ToFloatF f) { 502 return fill(new float[s], f); 503 } 504 505 static float[] fill(float[] a, ToFloatF f) { 506 for (int i = 0; i < a.length; i++) { 507 a[i] = f.apply(i); 508 } 509 return a; 510 } 511 512 static float cornerCaseValue(int i) { 513 switch(i % 7) { 514 case 0: 515 return Float.MAX_VALUE; 516 case 1: 517 return Float.MIN_VALUE; 518 case 2: 519 return Float.NEGATIVE_INFINITY; 520 case 3: 521 return Float.POSITIVE_INFINITY; 522 case 4: 523 return Float.NaN; 524 case 5: 525 return (float)0.0; 526 default: 527 return (float)-0.0; 528 } 529 } 530 static float get(float[] a, int i) { 531 return (float) a[i]; 532 } 533 534 static final IntFunction<float[]> fr = (vl) -> { 535 int length = 1000 * vl; 536 return new float[length]; 537 }; 538 539 static final IntFunction<boolean[]> fmr = (vl) -> { 540 int length = 1000 * vl; 541 return new boolean[length]; 542 }; 543 static float add(float a, float b) { 544 return (float)(a + b); 545 } 546 547 @Test(dataProvider = "floatBinaryOpProvider") 548 static void addFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) { 549 float[] a = fa.apply(SPECIES.length()); 550 float[] b = fb.apply(SPECIES.length()); 551 float[] r = fr.apply(SPECIES.length()); 552 553 for (int ic = 0; ic < INVOC_COUNT; ic++) { 554 for (int i = 0; i < a.length; i += SPECIES.length()) { 555 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 556 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 557 av.add(bv).intoArray(r, i); 558 } 559 } 560 561 assertArraysEquals(a, b, r, FloatMaxVectorTests::add); 562 } 563 564 @Test(dataProvider = "floatBinaryOpMaskProvider") 565 static void addFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb, 566 IntFunction<boolean[]> fm) { 567 float[] a = fa.apply(SPECIES.length()); 568 float[] b = fb.apply(SPECIES.length()); 569 float[] r = fr.apply(SPECIES.length()); 570 boolean[] mask = fm.apply(SPECIES.length()); 571 VectorMask<Float> vmask = VectorMask.fromValues(SPECIES, mask); 572 573 for (int ic = 0; ic < INVOC_COUNT; ic++) { 574 for (int i = 0; i < a.length; i += SPECIES.length()) { 575 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 576 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 577 av.add(bv, vmask).intoArray(r, i); 578 } 579 } 580 581 assertArraysEquals(a, b, r, mask, FloatMaxVectorTests::add); 582 } 583 static float sub(float a, float b) { 584 return (float)(a - b); 585 } 586 587 @Test(dataProvider = "floatBinaryOpProvider") 588 static void subFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) { 589 float[] a = fa.apply(SPECIES.length()); 590 float[] b = fb.apply(SPECIES.length()); 591 float[] r = fr.apply(SPECIES.length()); 592 593 for (int ic = 0; ic < INVOC_COUNT; ic++) { 594 for (int i = 0; i < a.length; i += SPECIES.length()) { 595 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 596 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 597 av.sub(bv).intoArray(r, i); 598 } 599 } 600 601 assertArraysEquals(a, b, r, FloatMaxVectorTests::sub); 602 } 603 604 @Test(dataProvider = "floatBinaryOpMaskProvider") 605 static void subFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb, 606 IntFunction<boolean[]> fm) { 607 float[] a = fa.apply(SPECIES.length()); 608 float[] b = fb.apply(SPECIES.length()); 609 float[] r = fr.apply(SPECIES.length()); 610 boolean[] mask = fm.apply(SPECIES.length()); 611 VectorMask<Float> vmask = VectorMask.fromValues(SPECIES, mask); 612 613 for (int ic = 0; ic < INVOC_COUNT; ic++) { 614 for (int i = 0; i < a.length; i += SPECIES.length()) { 615 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 616 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 617 av.sub(bv, vmask).intoArray(r, i); 618 } 619 } 620 621 assertArraysEquals(a, b, r, mask, FloatMaxVectorTests::sub); 622 } 623 624 static float div(float a, float b) { 625 return (float)(a / b); 626 } 627 628 @Test(dataProvider = "floatBinaryOpProvider") 629 static void divFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) { 630 float[] a = fa.apply(SPECIES.length()); 631 float[] b = fb.apply(SPECIES.length()); 632 float[] r = fr.apply(SPECIES.length()); 633 634 for (int ic = 0; ic < INVOC_COUNT; ic++) { 635 for (int i = 0; i < a.length; i += SPECIES.length()) { 636 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 637 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 638 av.div(bv).intoArray(r, i); 639 } 640 } 641 642 assertArraysEquals(a, b, r, FloatMaxVectorTests::div); 643 } 644 645 646 647 @Test(dataProvider = "floatBinaryOpMaskProvider") 648 static void divFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb, 649 IntFunction<boolean[]> fm) { 650 float[] a = fa.apply(SPECIES.length()); 651 float[] b = fb.apply(SPECIES.length()); 652 float[] r = fr.apply(SPECIES.length()); 653 boolean[] mask = fm.apply(SPECIES.length()); 654 VectorMask<Float> vmask = VectorMask.fromValues(SPECIES, mask); 655 656 for (int ic = 0; ic < INVOC_COUNT; ic++) { 657 for (int i = 0; i < a.length; i += SPECIES.length()) { 658 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 659 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 660 av.div(bv, vmask).intoArray(r, i); 661 } 662 } 663 664 assertArraysEquals(a, b, r, mask, FloatMaxVectorTests::div); 665 } 666 667 static float mul(float a, float b) { 668 return (float)(a * b); 669 } 670 671 @Test(dataProvider = "floatBinaryOpProvider") 672 static void mulFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) { 673 float[] a = fa.apply(SPECIES.length()); 674 float[] b = fb.apply(SPECIES.length()); 675 float[] r = fr.apply(SPECIES.length()); 676 677 for (int ic = 0; ic < INVOC_COUNT; ic++) { 678 for (int i = 0; i < a.length; i += SPECIES.length()) { 679 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 680 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 681 av.mul(bv).intoArray(r, i); 682 } 683 } 684 685 assertArraysEquals(a, b, r, FloatMaxVectorTests::mul); 686 } 687 688 @Test(dataProvider = "floatBinaryOpMaskProvider") 689 static void mulFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb, 690 IntFunction<boolean[]> fm) { 691 float[] a = fa.apply(SPECIES.length()); 692 float[] b = fb.apply(SPECIES.length()); 693 float[] r = fr.apply(SPECIES.length()); 694 boolean[] mask = fm.apply(SPECIES.length()); 695 VectorMask<Float> vmask = VectorMask.fromValues(SPECIES, mask); 696 697 for (int ic = 0; ic < INVOC_COUNT; ic++) { 698 for (int i = 0; i < a.length; i += SPECIES.length()) { 699 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 700 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 701 av.mul(bv, vmask).intoArray(r, i); 702 } 703 } 704 705 assertArraysEquals(a, b, r, mask, FloatMaxVectorTests::mul); 706 } 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 static float max(float a, float b) { 738 return (float)(Math.max(a, b)); 739 } 740 741 @Test(dataProvider = "floatBinaryOpProvider") 742 static void maxFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) { 743 float[] a = fa.apply(SPECIES.length()); 744 float[] b = fb.apply(SPECIES.length()); 745 float[] r = fr.apply(SPECIES.length()); 746 747 for (int ic = 0; ic < INVOC_COUNT; ic++) { 748 for (int i = 0; i < a.length; i += SPECIES.length()) { 749 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 750 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 751 av.max(bv).intoArray(r, i); 752 } 753 } 754 755 assertArraysEquals(a, b, r, FloatMaxVectorTests::max); 756 } 757 static float min(float a, float b) { 758 return (float)(Math.min(a, b)); 759 } 760 761 @Test(dataProvider = "floatBinaryOpProvider") 762 static void minFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) { 763 float[] a = fa.apply(SPECIES.length()); 764 float[] b = fb.apply(SPECIES.length()); 765 float[] r = fr.apply(SPECIES.length()); 766 767 for (int ic = 0; ic < INVOC_COUNT; ic++) { 768 for (int i = 0; i < a.length; i += SPECIES.length()) { 769 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 770 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 771 av.min(bv).intoArray(r, i); 772 } 773 } 774 775 assertArraysEquals(a, b, r, FloatMaxVectorTests::min); 776 } 777 778 779 780 781 782 783 static float addAll(float[] a, int idx) { 784 float res = 0; 785 for (int i = idx; i < (idx + SPECIES.length()); i++) { 786 res += a[i]; 787 } 788 789 return res; 790 } 791 792 static float addAll(float[] a) { 793 float res = 0; 794 for (int i = 0; i < a.length; i += SPECIES.length()) { 795 float tmp = 0; 796 for (int j = 0; j < SPECIES.length(); j++) { 797 tmp += a[i + j]; 798 } 799 res += tmp; 800 } 801 802 return res; 803 } 804 @Test(dataProvider = "floatUnaryOpProvider") 805 static void addAllFloatMaxVectorTests(IntFunction<float[]> fa) { 806 float[] a = fa.apply(SPECIES.length()); 807 float[] r = fr.apply(SPECIES.length()); 808 float ra = 0; 809 810 for (int ic = 0; ic < INVOC_COUNT; ic++) { 811 for (int i = 0; i < a.length; i += SPECIES.length()) { 812 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 813 r[i] = av.addAll(); 814 } 815 } 816 817 for (int ic = 0; ic < INVOC_COUNT; ic++) { 818 ra = 0; 819 for (int i = 0; i < a.length; i += SPECIES.length()) { 820 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 821 ra += av.addAll(); 822 } 823 } 824 825 assertReductionArraysEquals(a, r, ra, FloatMaxVectorTests::addAll, FloatMaxVectorTests::addAll); 826 } 827 static float mulAll(float[] a, int idx) { 828 float res = 1; 829 for (int i = idx; i < (idx + SPECIES.length()); i++) { 830 res *= a[i]; 831 } 832 833 return res; 834 } 835 836 static float mulAll(float[] a) { 837 float res = 1; 838 for (int i = 0; i < a.length; i += SPECIES.length()) { 839 float tmp = 1; 840 for (int j = 0; j < SPECIES.length(); j++) { 841 tmp *= a[i + j]; 842 } 843 res *= tmp; 844 } 845 846 return res; 847 } 848 @Test(dataProvider = "floatUnaryOpProvider") 849 static void mulAllFloatMaxVectorTests(IntFunction<float[]> fa) { 850 float[] a = fa.apply(SPECIES.length()); 851 float[] r = fr.apply(SPECIES.length()); 852 float ra = 1; 853 854 for (int ic = 0; ic < INVOC_COUNT; ic++) { 855 for (int i = 0; i < a.length; i += SPECIES.length()) { 856 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 857 r[i] = av.mulAll(); 858 } 859 } 860 861 for (int ic = 0; ic < INVOC_COUNT; ic++) { 862 ra = 1; 863 for (int i = 0; i < a.length; i += SPECIES.length()) { 864 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 865 ra *= av.mulAll(); 866 } 867 } 868 869 assertReductionArraysEquals(a, r, ra, FloatMaxVectorTests::mulAll, FloatMaxVectorTests::mulAll); 870 } 871 static float minAll(float[] a, int idx) { 872 float res = Float.POSITIVE_INFINITY; 873 for (int i = idx; i < (idx + SPECIES.length()); i++) { 874 res = (float)Math.min(res, a[i]); 875 } 876 877 return res; 878 } 879 880 static float minAll(float[] a) { 881 float res = Float.POSITIVE_INFINITY; 882 for (int i = 0; i < a.length; i++) { 883 res = (float)Math.min(res, a[i]); 884 } 885 886 return res; 887 } 888 @Test(dataProvider = "floatUnaryOpProvider") 889 static void minAllFloatMaxVectorTests(IntFunction<float[]> fa) { 890 float[] a = fa.apply(SPECIES.length()); 891 float[] r = fr.apply(SPECIES.length()); 892 float ra = Float.POSITIVE_INFINITY; 893 894 for (int ic = 0; ic < INVOC_COUNT; ic++) { 895 for (int i = 0; i < a.length; i += SPECIES.length()) { 896 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 897 r[i] = av.minAll(); 898 } 899 } 900 901 for (int ic = 0; ic < INVOC_COUNT; ic++) { 902 ra = Float.POSITIVE_INFINITY; 903 for (int i = 0; i < a.length; i += SPECIES.length()) { 904 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 905 ra = (float)Math.min(ra, av.minAll()); 906 } 907 } 908 909 assertReductionArraysEquals(a, r, ra, FloatMaxVectorTests::minAll, FloatMaxVectorTests::minAll); 910 } 911 static float maxAll(float[] a, int idx) { 912 float res = Float.NEGATIVE_INFINITY; 913 for (int i = idx; i < (idx + SPECIES.length()); i++) { 914 res = (float)Math.max(res, a[i]); 915 } 916 917 return res; 918 } 919 920 static float maxAll(float[] a) { 921 float res = Float.NEGATIVE_INFINITY; 922 for (int i = 0; i < a.length; i++) { 923 res = (float)Math.max(res, a[i]); 924 } 925 926 return res; 927 } 928 @Test(dataProvider = "floatUnaryOpProvider") 929 static void maxAllFloatMaxVectorTests(IntFunction<float[]> fa) { 930 float[] a = fa.apply(SPECIES.length()); 931 float[] r = fr.apply(SPECIES.length()); 932 float ra = Float.NEGATIVE_INFINITY; 933 934 for (int ic = 0; ic < INVOC_COUNT; ic++) { 935 for (int i = 0; i < a.length; i += SPECIES.length()) { 936 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 937 r[i] = av.maxAll(); 938 } 939 } 940 941 for (int ic = 0; ic < INVOC_COUNT; ic++) { 942 ra = Float.NEGATIVE_INFINITY; 943 for (int i = 0; i < a.length; i += SPECIES.length()) { 944 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 945 ra = (float)Math.max(ra, av.maxAll()); 946 } 947 } 948 949 assertReductionArraysEquals(a, r, ra, FloatMaxVectorTests::maxAll, FloatMaxVectorTests::maxAll); 950 } 951 952 953 954 955 956 @Test(dataProvider = "floatUnaryOpProvider") 957 static void withFloatMaxVectorTests(IntFunction<float []> fa) { 958 float[] a = fa.apply(SPECIES.length()); 959 float[] r = fr.apply(SPECIES.length()); 960 961 for (int ic = 0; ic < INVOC_COUNT; ic++) { 962 for (int i = 0; i < a.length; i += SPECIES.length()) { 963 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 964 av.with(0, (float)4).intoArray(r, i); 965 } 966 } 967 968 assertInsertArraysEquals(a, r, (float)4, 0); 969 } 970 971 @Test(dataProvider = "floatCompareOpProvider") 972 static void lessThanFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) { 973 float[] a = fa.apply(SPECIES.length()); 974 float[] b = fb.apply(SPECIES.length()); 975 976 for (int ic = 0; ic < INVOC_COUNT; ic++) { 977 for (int i = 0; i < a.length; i += SPECIES.length()) { 978 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 979 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 980 VectorMask<Float> mv = av.lessThan(bv); 981 982 // Check results as part of computation. 983 for (int j = 0; j < SPECIES.length(); j++) { 984 Assert.assertEquals(mv.getElement(j), a[i + j] < b[i + j]); 985 } 986 } 987 } 988 } 989 990 991 @Test(dataProvider = "floatCompareOpProvider") 992 static void greaterThanFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) { 993 float[] a = fa.apply(SPECIES.length()); 994 float[] b = fb.apply(SPECIES.length()); 995 996 for (int ic = 0; ic < INVOC_COUNT; ic++) { 997 for (int i = 0; i < a.length; i += SPECIES.length()) { 998 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 999 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 1000 VectorMask<Float> mv = av.greaterThan(bv); 1001 1002 // Check results as part of computation. 1003 for (int j = 0; j < SPECIES.length(); j++) { 1004 Assert.assertEquals(mv.getElement(j), a[i + j] > b[i + j]); 1005 } 1006 } 1007 } 1008 } 1009 1010 1011 @Test(dataProvider = "floatCompareOpProvider") 1012 static void equalFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) { 1013 float[] a = fa.apply(SPECIES.length()); 1014 float[] b = fb.apply(SPECIES.length()); 1015 1016 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1017 for (int i = 0; i < a.length; i += SPECIES.length()) { 1018 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1019 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 1020 VectorMask<Float> mv = av.equal(bv); 1021 1022 // Check results as part of computation. 1023 for (int j = 0; j < SPECIES.length(); j++) { 1024 Assert.assertEquals(mv.getElement(j), a[i + j] == b[i + j]); 1025 } 1026 } 1027 } 1028 } 1029 1030 1031 @Test(dataProvider = "floatCompareOpProvider") 1032 static void notEqualFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) { 1033 float[] a = fa.apply(SPECIES.length()); 1034 float[] b = fb.apply(SPECIES.length()); 1035 1036 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1037 for (int i = 0; i < a.length; i += SPECIES.length()) { 1038 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1039 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 1040 VectorMask<Float> mv = av.notEqual(bv); 1041 1042 // Check results as part of computation. 1043 for (int j = 0; j < SPECIES.length(); j++) { 1044 Assert.assertEquals(mv.getElement(j), a[i + j] != b[i + j]); 1045 } 1046 } 1047 } 1048 } 1049 1050 1051 @Test(dataProvider = "floatCompareOpProvider") 1052 static void lessThanEqFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) { 1053 float[] a = fa.apply(SPECIES.length()); 1054 float[] b = fb.apply(SPECIES.length()); 1055 1056 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1057 for (int i = 0; i < a.length; i += SPECIES.length()) { 1058 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1059 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 1060 VectorMask<Float> mv = av.lessThanEq(bv); 1061 1062 // Check results as part of computation. 1063 for (int j = 0; j < SPECIES.length(); j++) { 1064 Assert.assertEquals(mv.getElement(j), a[i + j] <= b[i + j]); 1065 } 1066 } 1067 } 1068 } 1069 1070 1071 @Test(dataProvider = "floatCompareOpProvider") 1072 static void greaterThanEqFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) { 1073 float[] a = fa.apply(SPECIES.length()); 1074 float[] b = fb.apply(SPECIES.length()); 1075 1076 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1077 for (int i = 0; i < a.length; i += SPECIES.length()) { 1078 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1079 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 1080 VectorMask<Float> mv = av.greaterThanEq(bv); 1081 1082 // Check results as part of computation. 1083 for (int j = 0; j < SPECIES.length(); j++) { 1084 Assert.assertEquals(mv.getElement(j), a[i + j] >= b[i + j]); 1085 } 1086 } 1087 } 1088 } 1089 1090 1091 static float blend(float a, float b, boolean mask) { 1092 return mask ? b : a; 1093 } 1094 1095 @Test(dataProvider = "floatBinaryOpMaskProvider") 1096 static void blendFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb, 1097 IntFunction<boolean[]> fm) { 1098 float[] a = fa.apply(SPECIES.length()); 1099 float[] b = fb.apply(SPECIES.length()); 1100 float[] r = fr.apply(SPECIES.length()); 1101 boolean[] mask = fm.apply(SPECIES.length()); 1102 VectorMask<Float> vmask = VectorMask.fromValues(SPECIES, mask); 1103 1104 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1105 for (int i = 0; i < a.length; i += SPECIES.length()) { 1106 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1107 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 1108 av.blend(bv, vmask).intoArray(r, i); 1109 } 1110 } 1111 1112 assertArraysEquals(a, b, r, mask, FloatMaxVectorTests::blend); 1113 } 1114 1115 @Test(dataProvider = "floatUnaryOpShuffleProvider") 1116 static void RearrangeFloatMaxVectorTests(IntFunction<float[]> fa, 1117 BiFunction<Integer,Integer,int[]> fs) { 1118 float[] a = fa.apply(SPECIES.length()); 1119 int[] order = fs.apply(a.length, SPECIES.length()); 1120 float[] r = fr.apply(SPECIES.length()); 1121 1122 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1123 for (int i = 0; i < a.length; i += SPECIES.length()) { 1124 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1125 av.rearrange(VectorShuffle.fromArray(SPECIES, order, i)).intoArray(r, i); 1126 } 1127 } 1128 1129 assertRearrangeArraysEquals(a, r, order, SPECIES.length()); 1130 } 1131 1132 1133 1134 1135 @Test(dataProvider = "floatUnaryOpProvider") 1136 static void getFloatMaxVectorTests(IntFunction<float[]> fa) { 1137 float[] a = fa.apply(SPECIES.length()); 1138 float[] r = fr.apply(SPECIES.length()); 1139 1140 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1141 for (int i = 0; i < a.length; i += SPECIES.length()) { 1142 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1143 int num_lanes = SPECIES.length(); 1144 // Manually unroll because full unroll happens after intrinsification. 1145 // Unroll is needed because get intrinsic requires for index to be a known constant. 1146 if (num_lanes == 1) { 1147 r[i]=av.get(0); 1148 } else if (num_lanes == 2) { 1149 r[i]=av.get(0); 1150 r[i+1]=av.get(1); 1151 } else if (num_lanes == 4) { 1152 r[i]=av.get(0); 1153 r[i+1]=av.get(1); 1154 r[i+2]=av.get(2); 1155 r[i+3]=av.get(3); 1156 } else if (num_lanes == 8) { 1157 r[i]=av.get(0); 1158 r[i+1]=av.get(1); 1159 r[i+2]=av.get(2); 1160 r[i+3]=av.get(3); 1161 r[i+4]=av.get(4); 1162 r[i+5]=av.get(5); 1163 r[i+6]=av.get(6); 1164 r[i+7]=av.get(7); 1165 } else if (num_lanes == 16) { 1166 r[i]=av.get(0); 1167 r[i+1]=av.get(1); 1168 r[i+2]=av.get(2); 1169 r[i+3]=av.get(3); 1170 r[i+4]=av.get(4); 1171 r[i+5]=av.get(5); 1172 r[i+6]=av.get(6); 1173 r[i+7]=av.get(7); 1174 r[i+8]=av.get(8); 1175 r[i+9]=av.get(9); 1176 r[i+10]=av.get(10); 1177 r[i+11]=av.get(11); 1178 r[i+12]=av.get(12); 1179 r[i+13]=av.get(13); 1180 r[i+14]=av.get(14); 1181 r[i+15]=av.get(15); 1182 } else if (num_lanes == 32) { 1183 r[i]=av.get(0); 1184 r[i+1]=av.get(1); 1185 r[i+2]=av.get(2); 1186 r[i+3]=av.get(3); 1187 r[i+4]=av.get(4); 1188 r[i+5]=av.get(5); 1189 r[i+6]=av.get(6); 1190 r[i+7]=av.get(7); 1191 r[i+8]=av.get(8); 1192 r[i+9]=av.get(9); 1193 r[i+10]=av.get(10); 1194 r[i+11]=av.get(11); 1195 r[i+12]=av.get(12); 1196 r[i+13]=av.get(13); 1197 r[i+14]=av.get(14); 1198 r[i+15]=av.get(15); 1199 r[i+16]=av.get(16); 1200 r[i+17]=av.get(17); 1201 r[i+18]=av.get(18); 1202 r[i+19]=av.get(19); 1203 r[i+20]=av.get(20); 1204 r[i+21]=av.get(21); 1205 r[i+22]=av.get(22); 1206 r[i+23]=av.get(23); 1207 r[i+24]=av.get(24); 1208 r[i+25]=av.get(25); 1209 r[i+26]=av.get(26); 1210 r[i+27]=av.get(27); 1211 r[i+28]=av.get(28); 1212 r[i+29]=av.get(29); 1213 r[i+30]=av.get(30); 1214 r[i+31]=av.get(31); 1215 } else if (num_lanes == 64) { 1216 r[i]=av.get(0); 1217 r[i+1]=av.get(1); 1218 r[i+2]=av.get(2); 1219 r[i+3]=av.get(3); 1220 r[i+4]=av.get(4); 1221 r[i+5]=av.get(5); 1222 r[i+6]=av.get(6); 1223 r[i+7]=av.get(7); 1224 r[i+8]=av.get(8); 1225 r[i+9]=av.get(9); 1226 r[i+10]=av.get(10); 1227 r[i+11]=av.get(11); 1228 r[i+12]=av.get(12); 1229 r[i+13]=av.get(13); 1230 r[i+14]=av.get(14); 1231 r[i+15]=av.get(15); 1232 r[i+16]=av.get(16); 1233 r[i+17]=av.get(17); 1234 r[i+18]=av.get(18); 1235 r[i+19]=av.get(19); 1236 r[i+20]=av.get(20); 1237 r[i+21]=av.get(21); 1238 r[i+22]=av.get(22); 1239 r[i+23]=av.get(23); 1240 r[i+24]=av.get(24); 1241 r[i+25]=av.get(25); 1242 r[i+26]=av.get(26); 1243 r[i+27]=av.get(27); 1244 r[i+28]=av.get(28); 1245 r[i+29]=av.get(29); 1246 r[i+30]=av.get(30); 1247 r[i+31]=av.get(31); 1248 r[i+32]=av.get(32); 1249 r[i+33]=av.get(33); 1250 r[i+34]=av.get(34); 1251 r[i+35]=av.get(35); 1252 r[i+36]=av.get(36); 1253 r[i+37]=av.get(37); 1254 r[i+38]=av.get(38); 1255 r[i+39]=av.get(39); 1256 r[i+40]=av.get(40); 1257 r[i+41]=av.get(41); 1258 r[i+42]=av.get(42); 1259 r[i+43]=av.get(43); 1260 r[i+44]=av.get(44); 1261 r[i+45]=av.get(45); 1262 r[i+46]=av.get(46); 1263 r[i+47]=av.get(47); 1264 r[i+48]=av.get(48); 1265 r[i+49]=av.get(49); 1266 r[i+50]=av.get(50); 1267 r[i+51]=av.get(51); 1268 r[i+52]=av.get(52); 1269 r[i+53]=av.get(53); 1270 r[i+54]=av.get(54); 1271 r[i+55]=av.get(55); 1272 r[i+56]=av.get(56); 1273 r[i+57]=av.get(57); 1274 r[i+58]=av.get(58); 1275 r[i+59]=av.get(59); 1276 r[i+60]=av.get(60); 1277 r[i+61]=av.get(61); 1278 r[i+62]=av.get(62); 1279 r[i+63]=av.get(63); 1280 } else { 1281 for (int j = 0; j < SPECIES.length(); j++) { 1282 r[i+j]=av.get(j); 1283 } 1284 } 1285 } 1286 } 1287 1288 assertArraysEquals(a, r, FloatMaxVectorTests::get); 1289 } 1290 1291 static float sin(float a) { 1292 return (float)(Math.sin((double)a)); 1293 } 1294 1295 static float strictsin(float a) { 1296 return (float)(StrictMath.sin((double)a)); 1297 } 1298 1299 @Test(dataProvider = "floatUnaryOpProvider") 1300 static void sinFloatMaxVectorTests(IntFunction<float[]> fa) { 1301 float[] a = fa.apply(SPECIES.length()); 1302 float[] r = fr.apply(SPECIES.length()); 1303 1304 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1305 for (int i = 0; i < a.length; i += SPECIES.length()) { 1306 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1307 av.sin().intoArray(r, i); 1308 } 1309 } 1310 1311 assertArraysEqualsWithinOneUlp(a, r, FloatMaxVectorTests::sin, FloatMaxVectorTests::strictsin); 1312 } 1313 1314 1315 static float exp(float a) { 1316 return (float)(Math.exp((double)a)); 1317 } 1318 1319 static float strictexp(float a) { 1320 return (float)(StrictMath.exp((double)a)); 1321 } 1322 1323 @Test(dataProvider = "floatUnaryOpProvider") 1324 static void expFloatMaxVectorTests(IntFunction<float[]> fa) { 1325 float[] a = fa.apply(SPECIES.length()); 1326 float[] r = fr.apply(SPECIES.length()); 1327 1328 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1329 for (int i = 0; i < a.length; i += SPECIES.length()) { 1330 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1331 av.exp().intoArray(r, i); 1332 } 1333 } 1334 1335 assertArraysEqualsWithinOneUlp(a, r, FloatMaxVectorTests::exp, FloatMaxVectorTests::strictexp); 1336 } 1337 1338 1339 static float log1p(float a) { 1340 return (float)(Math.log1p((double)a)); 1341 } 1342 1343 static float strictlog1p(float a) { 1344 return (float)(StrictMath.log1p((double)a)); 1345 } 1346 1347 @Test(dataProvider = "floatUnaryOpProvider") 1348 static void log1pFloatMaxVectorTests(IntFunction<float[]> fa) { 1349 float[] a = fa.apply(SPECIES.length()); 1350 float[] r = fr.apply(SPECIES.length()); 1351 1352 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1353 for (int i = 0; i < a.length; i += SPECIES.length()) { 1354 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1355 av.log1p().intoArray(r, i); 1356 } 1357 } 1358 1359 assertArraysEqualsWithinOneUlp(a, r, FloatMaxVectorTests::log1p, FloatMaxVectorTests::strictlog1p); 1360 } 1361 1362 1363 static float log(float a) { 1364 return (float)(Math.log((double)a)); 1365 } 1366 1367 static float strictlog(float a) { 1368 return (float)(StrictMath.log((double)a)); 1369 } 1370 1371 @Test(dataProvider = "floatUnaryOpProvider") 1372 static void logFloatMaxVectorTests(IntFunction<float[]> fa) { 1373 float[] a = fa.apply(SPECIES.length()); 1374 float[] r = fr.apply(SPECIES.length()); 1375 1376 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1377 for (int i = 0; i < a.length; i += SPECIES.length()) { 1378 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1379 av.log().intoArray(r, i); 1380 } 1381 } 1382 1383 assertArraysEqualsWithinOneUlp(a, r, FloatMaxVectorTests::log, FloatMaxVectorTests::strictlog); 1384 } 1385 1386 1387 static float log10(float a) { 1388 return (float)(Math.log10((double)a)); 1389 } 1390 1391 static float strictlog10(float a) { 1392 return (float)(StrictMath.log10((double)a)); 1393 } 1394 1395 @Test(dataProvider = "floatUnaryOpProvider") 1396 static void log10FloatMaxVectorTests(IntFunction<float[]> fa) { 1397 float[] a = fa.apply(SPECIES.length()); 1398 float[] r = fr.apply(SPECIES.length()); 1399 1400 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1401 for (int i = 0; i < a.length; i += SPECIES.length()) { 1402 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1403 av.log10().intoArray(r, i); 1404 } 1405 } 1406 1407 assertArraysEqualsWithinOneUlp(a, r, FloatMaxVectorTests::log10, FloatMaxVectorTests::strictlog10); 1408 } 1409 1410 1411 static float expm1(float a) { 1412 return (float)(Math.expm1((double)a)); 1413 } 1414 1415 static float strictexpm1(float a) { 1416 return (float)(StrictMath.expm1((double)a)); 1417 } 1418 1419 @Test(dataProvider = "floatUnaryOpProvider") 1420 static void expm1FloatMaxVectorTests(IntFunction<float[]> fa) { 1421 float[] a = fa.apply(SPECIES.length()); 1422 float[] r = fr.apply(SPECIES.length()); 1423 1424 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1425 for (int i = 0; i < a.length; i += SPECIES.length()) { 1426 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1427 av.expm1().intoArray(r, i); 1428 } 1429 } 1430 1431 assertArraysEqualsWithinOneUlp(a, r, FloatMaxVectorTests::expm1, FloatMaxVectorTests::strictexpm1); 1432 } 1433 1434 1435 static float cos(float a) { 1436 return (float)(Math.cos((double)a)); 1437 } 1438 1439 static float strictcos(float a) { 1440 return (float)(StrictMath.cos((double)a)); 1441 } 1442 1443 @Test(dataProvider = "floatUnaryOpProvider") 1444 static void cosFloatMaxVectorTests(IntFunction<float[]> fa) { 1445 float[] a = fa.apply(SPECIES.length()); 1446 float[] r = fr.apply(SPECIES.length()); 1447 1448 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1449 for (int i = 0; i < a.length; i += SPECIES.length()) { 1450 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1451 av.cos().intoArray(r, i); 1452 } 1453 } 1454 1455 assertArraysEqualsWithinOneUlp(a, r, FloatMaxVectorTests::cos, FloatMaxVectorTests::strictcos); 1456 } 1457 1458 1459 static float tan(float a) { 1460 return (float)(Math.tan((double)a)); 1461 } 1462 1463 static float stricttan(float a) { 1464 return (float)(StrictMath.tan((double)a)); 1465 } 1466 1467 @Test(dataProvider = "floatUnaryOpProvider") 1468 static void tanFloatMaxVectorTests(IntFunction<float[]> fa) { 1469 float[] a = fa.apply(SPECIES.length()); 1470 float[] r = fr.apply(SPECIES.length()); 1471 1472 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1473 for (int i = 0; i < a.length; i += SPECIES.length()) { 1474 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1475 av.tan().intoArray(r, i); 1476 } 1477 } 1478 1479 assertArraysEqualsWithinOneUlp(a, r, FloatMaxVectorTests::tan, FloatMaxVectorTests::stricttan); 1480 } 1481 1482 1483 static float sinh(float a) { 1484 return (float)(Math.sinh((double)a)); 1485 } 1486 1487 static float strictsinh(float a) { 1488 return (float)(StrictMath.sinh((double)a)); 1489 } 1490 1491 @Test(dataProvider = "floatUnaryOpProvider") 1492 static void sinhFloatMaxVectorTests(IntFunction<float[]> fa) { 1493 float[] a = fa.apply(SPECIES.length()); 1494 float[] r = fr.apply(SPECIES.length()); 1495 1496 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1497 for (int i = 0; i < a.length; i += SPECIES.length()) { 1498 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1499 av.sinh().intoArray(r, i); 1500 } 1501 } 1502 1503 assertArraysEqualsWithinOneUlp(a, r, FloatMaxVectorTests::sinh, FloatMaxVectorTests::strictsinh); 1504 } 1505 1506 1507 static float cosh(float a) { 1508 return (float)(Math.cosh((double)a)); 1509 } 1510 1511 static float strictcosh(float a) { 1512 return (float)(StrictMath.cosh((double)a)); 1513 } 1514 1515 @Test(dataProvider = "floatUnaryOpProvider") 1516 static void coshFloatMaxVectorTests(IntFunction<float[]> fa) { 1517 float[] a = fa.apply(SPECIES.length()); 1518 float[] r = fr.apply(SPECIES.length()); 1519 1520 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1521 for (int i = 0; i < a.length; i += SPECIES.length()) { 1522 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1523 av.cosh().intoArray(r, i); 1524 } 1525 } 1526 1527 assertArraysEqualsWithinOneUlp(a, r, FloatMaxVectorTests::cosh, FloatMaxVectorTests::strictcosh); 1528 } 1529 1530 1531 static float tanh(float a) { 1532 return (float)(Math.tanh((double)a)); 1533 } 1534 1535 static float stricttanh(float a) { 1536 return (float)(StrictMath.tanh((double)a)); 1537 } 1538 1539 @Test(dataProvider = "floatUnaryOpProvider") 1540 static void tanhFloatMaxVectorTests(IntFunction<float[]> fa) { 1541 float[] a = fa.apply(SPECIES.length()); 1542 float[] r = fr.apply(SPECIES.length()); 1543 1544 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1545 for (int i = 0; i < a.length; i += SPECIES.length()) { 1546 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1547 av.tanh().intoArray(r, i); 1548 } 1549 } 1550 1551 assertArraysEqualsWithinOneUlp(a, r, FloatMaxVectorTests::tanh, FloatMaxVectorTests::stricttanh); 1552 } 1553 1554 1555 static float asin(float a) { 1556 return (float)(Math.asin((double)a)); 1557 } 1558 1559 static float strictasin(float a) { 1560 return (float)(StrictMath.asin((double)a)); 1561 } 1562 1563 @Test(dataProvider = "floatUnaryOpProvider") 1564 static void asinFloatMaxVectorTests(IntFunction<float[]> fa) { 1565 float[] a = fa.apply(SPECIES.length()); 1566 float[] r = fr.apply(SPECIES.length()); 1567 1568 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1569 for (int i = 0; i < a.length; i += SPECIES.length()) { 1570 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1571 av.asin().intoArray(r, i); 1572 } 1573 } 1574 1575 assertArraysEqualsWithinOneUlp(a, r, FloatMaxVectorTests::asin, FloatMaxVectorTests::strictasin); 1576 } 1577 1578 1579 static float acos(float a) { 1580 return (float)(Math.acos((double)a)); 1581 } 1582 1583 static float strictacos(float a) { 1584 return (float)(StrictMath.acos((double)a)); 1585 } 1586 1587 @Test(dataProvider = "floatUnaryOpProvider") 1588 static void acosFloatMaxVectorTests(IntFunction<float[]> fa) { 1589 float[] a = fa.apply(SPECIES.length()); 1590 float[] r = fr.apply(SPECIES.length()); 1591 1592 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1593 for (int i = 0; i < a.length; i += SPECIES.length()) { 1594 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1595 av.acos().intoArray(r, i); 1596 } 1597 } 1598 1599 assertArraysEqualsWithinOneUlp(a, r, FloatMaxVectorTests::acos, FloatMaxVectorTests::strictacos); 1600 } 1601 1602 1603 static float atan(float a) { 1604 return (float)(Math.atan((double)a)); 1605 } 1606 1607 static float strictatan(float a) { 1608 return (float)(StrictMath.atan((double)a)); 1609 } 1610 1611 @Test(dataProvider = "floatUnaryOpProvider") 1612 static void atanFloatMaxVectorTests(IntFunction<float[]> fa) { 1613 float[] a = fa.apply(SPECIES.length()); 1614 float[] r = fr.apply(SPECIES.length()); 1615 1616 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1617 for (int i = 0; i < a.length; i += SPECIES.length()) { 1618 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1619 av.atan().intoArray(r, i); 1620 } 1621 } 1622 1623 assertArraysEqualsWithinOneUlp(a, r, FloatMaxVectorTests::atan, FloatMaxVectorTests::strictatan); 1624 } 1625 1626 1627 static float cbrt(float a) { 1628 return (float)(Math.cbrt((double)a)); 1629 } 1630 1631 static float strictcbrt(float a) { 1632 return (float)(StrictMath.cbrt((double)a)); 1633 } 1634 1635 @Test(dataProvider = "floatUnaryOpProvider") 1636 static void cbrtFloatMaxVectorTests(IntFunction<float[]> fa) { 1637 float[] a = fa.apply(SPECIES.length()); 1638 float[] r = fr.apply(SPECIES.length()); 1639 1640 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1641 for (int i = 0; i < a.length; i += SPECIES.length()) { 1642 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1643 av.cbrt().intoArray(r, i); 1644 } 1645 } 1646 1647 assertArraysEqualsWithinOneUlp(a, r, FloatMaxVectorTests::cbrt, FloatMaxVectorTests::strictcbrt); 1648 } 1649 1650 1651 static float hypot(float a, float b) { 1652 return (float)(Math.hypot((double)a, (double)b)); 1653 } 1654 1655 static float stricthypot(float a, float b) { 1656 return (float)(StrictMath.hypot((double)a, (double)b)); 1657 } 1658 1659 @Test(dataProvider = "floatBinaryOpProvider") 1660 static void hypotFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) { 1661 float[] a = fa.apply(SPECIES.length()); 1662 float[] b = fb.apply(SPECIES.length()); 1663 float[] r = fr.apply(SPECIES.length()); 1664 1665 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1666 for (int i = 0; i < a.length; i += SPECIES.length()) { 1667 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1668 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 1669 av.hypot(bv).intoArray(r, i); 1670 } 1671 } 1672 1673 assertArraysEqualsWithinOneUlp(a, b, r, FloatMaxVectorTests::hypot, FloatMaxVectorTests::stricthypot); 1674 } 1675 1676 1677 1678 static float pow(float a, float b) { 1679 return (float)(Math.pow((double)a, (double)b)); 1680 } 1681 1682 static float strictpow(float a, float b) { 1683 return (float)(StrictMath.pow((double)a, (double)b)); 1684 } 1685 1686 @Test(dataProvider = "floatBinaryOpProvider") 1687 static void powFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) { 1688 float[] a = fa.apply(SPECIES.length()); 1689 float[] b = fb.apply(SPECIES.length()); 1690 float[] r = fr.apply(SPECIES.length()); 1691 1692 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1693 for (int i = 0; i < a.length; i += SPECIES.length()) { 1694 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1695 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 1696 av.pow(bv).intoArray(r, i); 1697 } 1698 } 1699 1700 assertArraysEqualsWithinOneUlp(a, b, r, FloatMaxVectorTests::pow, FloatMaxVectorTests::strictpow); 1701 } 1702 1703 1704 1705 static float atan2(float a, float b) { 1706 return (float)(Math.atan2((double)a, (double)b)); 1707 } 1708 1709 static float strictatan2(float a, float b) { 1710 return (float)(StrictMath.atan2((double)a, (double)b)); 1711 } 1712 1713 @Test(dataProvider = "floatBinaryOpProvider") 1714 static void atan2FloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) { 1715 float[] a = fa.apply(SPECIES.length()); 1716 float[] b = fb.apply(SPECIES.length()); 1717 float[] r = fr.apply(SPECIES.length()); 1718 1719 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1720 for (int i = 0; i < a.length; i += SPECIES.length()) { 1721 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1722 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 1723 av.atan2(bv).intoArray(r, i); 1724 } 1725 } 1726 1727 assertArraysEqualsWithinOneUlp(a, b, r, FloatMaxVectorTests::atan2, FloatMaxVectorTests::strictatan2); 1728 } 1729 1730 1731 1732 static float fma(float a, float b, float c) { 1733 return (float)(Math.fma(a, b, c)); 1734 } 1735 1736 1737 @Test(dataProvider = "floatTernaryOpProvider") 1738 static void fmaFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb, IntFunction<float[]> fc) { 1739 float[] a = fa.apply(SPECIES.length()); 1740 float[] b = fb.apply(SPECIES.length()); 1741 float[] c = fc.apply(SPECIES.length()); 1742 float[] r = fr.apply(SPECIES.length()); 1743 1744 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1745 for (int i = 0; i < a.length; i += SPECIES.length()) { 1746 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1747 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 1748 FloatVector cv = FloatVector.fromArray(SPECIES, c, i); 1749 av.fma(bv, cv).intoArray(r, i); 1750 } 1751 } 1752 1753 assertArraysEquals(a, b, c, r, FloatMaxVectorTests::fma); 1754 } 1755 1756 1757 @Test(dataProvider = "floatTernaryOpMaskProvider") 1758 static void fmaFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb, 1759 IntFunction<float[]> fc, IntFunction<boolean[]> fm) { 1760 float[] a = fa.apply(SPECIES.length()); 1761 float[] b = fb.apply(SPECIES.length()); 1762 float[] c = fc.apply(SPECIES.length()); 1763 float[] r = fr.apply(SPECIES.length()); 1764 boolean[] mask = fm.apply(SPECIES.length()); 1765 VectorMask<Float> vmask = VectorMask.fromValues(SPECIES, mask); 1766 1767 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1768 for (int i = 0; i < a.length; i += SPECIES.length()) { 1769 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1770 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 1771 FloatVector cv = FloatVector.fromArray(SPECIES, c, i); 1772 av.fma(bv, cv, vmask).intoArray(r, i); 1773 } 1774 } 1775 1776 assertArraysEquals(a, b, c, r, mask, FloatMaxVectorTests::fma); 1777 } 1778 1779 1780 static float neg(float a) { 1781 return (float)(-((float)a)); 1782 } 1783 1784 @Test(dataProvider = "floatUnaryOpProvider") 1785 static void negFloatMaxVectorTests(IntFunction<float[]> fa) { 1786 float[] a = fa.apply(SPECIES.length()); 1787 float[] r = fr.apply(SPECIES.length()); 1788 1789 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1790 for (int i = 0; i < a.length; i += SPECIES.length()) { 1791 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1792 av.neg().intoArray(r, i); 1793 } 1794 } 1795 1796 assertArraysEquals(a, r, FloatMaxVectorTests::neg); 1797 } 1798 1799 @Test(dataProvider = "floatUnaryOpMaskProvider") 1800 static void negMaskedFloatMaxVectorTests(IntFunction<float[]> fa, 1801 IntFunction<boolean[]> fm) { 1802 float[] a = fa.apply(SPECIES.length()); 1803 float[] r = fr.apply(SPECIES.length()); 1804 boolean[] mask = fm.apply(SPECIES.length()); 1805 VectorMask<Float> vmask = VectorMask.fromValues(SPECIES, mask); 1806 1807 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1808 for (int i = 0; i < a.length; i += SPECIES.length()) { 1809 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1810 av.neg(vmask).intoArray(r, i); 1811 } 1812 } 1813 1814 assertArraysEquals(a, r, mask, FloatMaxVectorTests::neg); 1815 } 1816 1817 static float abs(float a) { 1818 return (float)(Math.abs((float)a)); 1819 } 1820 1821 @Test(dataProvider = "floatUnaryOpProvider") 1822 static void absFloatMaxVectorTests(IntFunction<float[]> fa) { 1823 float[] a = fa.apply(SPECIES.length()); 1824 float[] r = fr.apply(SPECIES.length()); 1825 1826 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1827 for (int i = 0; i < a.length; i += SPECIES.length()) { 1828 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1829 av.abs().intoArray(r, i); 1830 } 1831 } 1832 1833 assertArraysEquals(a, r, FloatMaxVectorTests::abs); 1834 } 1835 1836 @Test(dataProvider = "floatUnaryOpMaskProvider") 1837 static void absMaskedFloatMaxVectorTests(IntFunction<float[]> fa, 1838 IntFunction<boolean[]> fm) { 1839 float[] a = fa.apply(SPECIES.length()); 1840 float[] r = fr.apply(SPECIES.length()); 1841 boolean[] mask = fm.apply(SPECIES.length()); 1842 VectorMask<Float> vmask = VectorMask.fromValues(SPECIES, mask); 1843 1844 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1845 for (int i = 0; i < a.length; i += SPECIES.length()) { 1846 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1847 av.abs(vmask).intoArray(r, i); 1848 } 1849 } 1850 1851 assertArraysEquals(a, r, mask, FloatMaxVectorTests::abs); 1852 } 1853 1854 1855 1856 1857 1858 static float sqrt(float a) { 1859 return (float)(Math.sqrt((double)a)); 1860 } 1861 1862 1863 1864 @Test(dataProvider = "floatUnaryOpProvider") 1865 static void sqrtFloatMaxVectorTests(IntFunction<float[]> fa) { 1866 float[] a = fa.apply(SPECIES.length()); 1867 float[] r = fr.apply(SPECIES.length()); 1868 1869 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1870 for (int i = 0; i < a.length; i += SPECIES.length()) { 1871 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1872 av.sqrt().intoArray(r, i); 1873 } 1874 } 1875 1876 assertArraysEquals(a, r, FloatMaxVectorTests::sqrt); 1877 } 1878 1879 1880 1881 @Test(dataProvider = "floatUnaryOpMaskProvider") 1882 static void sqrtMaskedFloatMaxVectorTests(IntFunction<float[]> fa, 1883 IntFunction<boolean[]> fm) { 1884 float[] a = fa.apply(SPECIES.length()); 1885 float[] r = fr.apply(SPECIES.length()); 1886 boolean[] mask = fm.apply(SPECIES.length()); 1887 VectorMask<Float> vmask = VectorMask.fromValues(SPECIES, mask); 1888 1889 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1890 for (int i = 0; i < a.length; i += SPECIES.length()) { 1891 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1892 av.sqrt(vmask).intoArray(r, i); 1893 } 1894 } 1895 1896 assertArraysEquals(a, r, mask, FloatMaxVectorTests::sqrt); 1897 } 1898 1899 1900 static float[] gather(float a[], int ix, int[] b, int iy) { 1901 float[] res = new float[SPECIES.length()]; 1902 for (int i = 0; i < SPECIES.length(); i++) { 1903 int bi = iy + i; 1904 res[i] = a[b[bi] + ix]; 1905 } 1906 return res; 1907 } 1908 1909 @Test(dataProvider = "floatUnaryOpIndexProvider") 1910 static void gatherFloatMaxVectorTests(IntFunction<float[]> fa, BiFunction<Integer,Integer,int[]> fs) { 1911 float[] a = fa.apply(SPECIES.length()); 1912 int[] b = fs.apply(a.length, SPECIES.length()); 1913 float[] r = new float[a.length]; 1914 1915 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1916 for (int i = 0; i < a.length; i += SPECIES.length()) { 1917 FloatVector av = FloatVector.fromArray(SPECIES, a, i, b, i); 1918 av.intoArray(r, i); 1919 } 1920 } 1921 1922 assertArraysEquals(a, b, r, FloatMaxVectorTests::gather); 1923 } 1924 1925 1926 static float[] scatter(float a[], int ix, int[] b, int iy) { 1927 float[] res = new float[SPECIES.length()]; 1928 for (int i = 0; i < SPECIES.length(); i++) { 1929 int bi = iy + i; 1930 res[b[bi]] = a[i + ix]; 1931 } 1932 return res; 1933 } 1934 1935 @Test(dataProvider = "floatUnaryOpIndexProvider") 1936 static void scatterFloatMaxVectorTests(IntFunction<float[]> fa, BiFunction<Integer,Integer,int[]> fs) { 1937 float[] a = fa.apply(SPECIES.length()); 1938 int[] b = fs.apply(a.length, SPECIES.length()); 1939 float[] r = new float[a.length]; 1940 1941 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1942 for (int i = 0; i < a.length; i += SPECIES.length()) { 1943 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1944 av.intoArray(r, i, b, i); 1945 } 1946 } 1947 1948 assertArraysEquals(a, b, r, FloatMaxVectorTests::scatter); 1949 } 1950 1951 } 1952