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