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