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