1 /* 2 * Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 * @test 26 * @modules jdk.incubator.vector 27 * @run testng/othervm -ea -esa -Xbatch FloatMaxVectorTests 28 */ 29 30 // -- This file was mechanically generated: Do not edit! -- // 31 32 import jdk.incubator.vector.VectorShape; 33 import jdk.incubator.vector.VectorSpecies; 34 import jdk.incubator.vector.VectorShuffle; 35 import jdk.incubator.vector.VectorMask; 36 import jdk.incubator.vector.VectorOperators; 37 import jdk.incubator.vector.Vector; 38 39 import jdk.incubator.vector.FloatVector; 40 41 import org.testng.Assert; 42 import org.testng.annotations.DataProvider; 43 import org.testng.annotations.Test; 44 45 import java.lang.Integer; 46 import java.util.List; 47 import java.util.Arrays; 48 import java.util.function.BiFunction; 49 import java.util.function.IntFunction; 50 import java.util.Objects; 51 import java.util.stream.Collectors; 52 import java.util.stream.Stream; 53 54 @Test 55 public class FloatMaxVectorTests extends AbstractVectorTest { 56 57 static final VectorSpecies<Float> SPECIES = 58 FloatVector.SPECIES_MAX; 59 60 static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100); 61 getMaxBit()62 static VectorShape getMaxBit() { 63 return VectorShape.S_Max_BIT; 64 } 65 66 private static final int Max = 256; // juts so we can do N/Max 67 68 static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / Max); 69 70 static final int BUFFER_SIZE = Integer.getInteger("jdk.incubator.vector.test.buffer-size", BUFFER_REPS * (Max / 8)); 71 72 interface FUnOp { apply(float a)73 float apply(float a); 74 } 75 assertArraysEquals(float[] a, float[] r, FUnOp f)76 static void assertArraysEquals(float[] a, float[] r, FUnOp f) { 77 int i = 0; 78 try { 79 for (; i < a.length; i++) { 80 Assert.assertEquals(r[i], f.apply(a[i])); 81 } 82 } catch (AssertionError e) { 83 Assert.assertEquals(r[i], f.apply(a[i]), "at index #" + i + ", input = " + a[i]); 84 } 85 } 86 87 interface FUnArrayOp { apply(float a)88 float[] apply(float a); 89 } 90 assertArraysEquals(float[] a, float[] r, FUnArrayOp f)91 static void assertArraysEquals(float[] a, float[] r, FUnArrayOp f) { 92 int i = 0; 93 try { 94 for (; i < a.length; i += SPECIES.length()) { 95 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()), 96 f.apply(a[i])); 97 } 98 } catch (AssertionError e) { 99 float[] ref = f.apply(a[i]); 100 float[] res = Arrays.copyOfRange(r, i, i+SPECIES.length()); 101 Assert.assertEquals(ref, res, "(ref: " + Arrays.toString(ref) 102 + ", res: " + Arrays.toString(res) 103 + "), at index #" + i); 104 } 105 } 106 assertArraysEquals(float[] a, float[] r, boolean[] mask, FUnOp f)107 static void assertArraysEquals(float[] a, float[] r, boolean[] mask, FUnOp f) { 108 int i = 0; 109 try { 110 for (; i < a.length; i++) { 111 Assert.assertEquals(r[i], mask[i % SPECIES.length()] ? f.apply(a[i]) : a[i]); 112 } 113 } catch (AssertionError e) { 114 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()]); 115 } 116 } 117 118 interface FReductionOp { apply(float[] a, int idx)119 float apply(float[] a, int idx); 120 } 121 122 interface FReductionAllOp { apply(float[] a)123 float apply(float[] a); 124 } 125 assertReductionArraysEquals(float[] a, float[] b, float c, FReductionOp f, FReductionAllOp fa)126 static void assertReductionArraysEquals(float[] a, float[] b, float c, 127 FReductionOp f, FReductionAllOp fa) { 128 int i = 0; 129 try { 130 Assert.assertEquals(c, fa.apply(a)); 131 for (; i < a.length; i += SPECIES.length()) { 132 Assert.assertEquals(b[i], f.apply(a, i)); 133 } 134 } catch (AssertionError e) { 135 Assert.assertEquals(c, fa.apply(a), "Final result is incorrect!"); 136 Assert.assertEquals(b[i], f.apply(a, i), "at index #" + i); 137 } 138 } 139 140 interface FReductionMaskedOp { apply(float[] a, int idx, boolean[] mask)141 float apply(float[] a, int idx, boolean[] mask); 142 } 143 144 interface FReductionAllMaskedOp { apply(float[] a, boolean[] mask)145 float apply(float[] a, boolean[] mask); 146 } 147 assertReductionArraysEqualsMasked(float[] a, float[] b, float c, boolean[] mask, FReductionMaskedOp f, FReductionAllMaskedOp fa)148 static void assertReductionArraysEqualsMasked(float[] a, float[] b, float c, boolean[] mask, 149 FReductionMaskedOp f, FReductionAllMaskedOp fa) { 150 int i = 0; 151 try { 152 Assert.assertEquals(c, fa.apply(a, mask)); 153 for (; i < a.length; i += SPECIES.length()) { 154 Assert.assertEquals(b[i], f.apply(a, i, mask)); 155 } 156 } catch (AssertionError e) { 157 Assert.assertEquals(c, fa.apply(a, mask), "Final result is incorrect!"); 158 Assert.assertEquals(b[i], f.apply(a, i, mask), "at index #" + i); 159 } 160 } 161 162 interface FReductionOpLong { apply(float[] a, int idx)163 long apply(float[] a, int idx); 164 } 165 166 interface FReductionAllOpLong { apply(float[] a)167 long apply(float[] a); 168 } 169 assertReductionLongArraysEquals(float[] a, long[] b, long c, FReductionOpLong f, FReductionAllOpLong fa)170 static void assertReductionLongArraysEquals(float[] a, long[] b, long c, 171 FReductionOpLong f, FReductionAllOpLong fa) { 172 int i = 0; 173 try { 174 Assert.assertEquals(c, fa.apply(a)); 175 for (; i < a.length; i += SPECIES.length()) { 176 Assert.assertEquals(b[i], f.apply(a, i)); 177 } 178 } catch (AssertionError e) { 179 Assert.assertEquals(c, fa.apply(a), "Final result is incorrect!"); 180 Assert.assertEquals(b[i], f.apply(a, i), "at index #" + i); 181 } 182 } 183 184 interface FReductionMaskedOpLong { apply(float[] a, int idx, boolean[] mask)185 long apply(float[] a, int idx, boolean[] mask); 186 } 187 188 interface FReductionAllMaskedOpLong { apply(float[] a, boolean[] mask)189 long apply(float[] a, boolean[] mask); 190 } 191 assertReductionLongArraysEqualsMasked(float[] a, long[] b, long c, boolean[] mask, FReductionMaskedOpLong f, FReductionAllMaskedOpLong fa)192 static void assertReductionLongArraysEqualsMasked(float[] a, long[] b, long c, boolean[] mask, 193 FReductionMaskedOpLong f, FReductionAllMaskedOpLong fa) { 194 int i = 0; 195 try { 196 Assert.assertEquals(c, fa.apply(a, mask)); 197 for (; i < a.length; i += SPECIES.length()) { 198 Assert.assertEquals(b[i], f.apply(a, i, mask)); 199 } 200 } catch (AssertionError e) { 201 Assert.assertEquals(c, fa.apply(a, mask), "Final result is incorrect!"); 202 Assert.assertEquals(b[i], f.apply(a, i, mask), "at index #" + i); 203 } 204 } 205 206 interface FBoolReductionOp { apply(boolean[] a, int idx)207 boolean apply(boolean[] a, int idx); 208 } 209 assertReductionBoolArraysEquals(boolean[] a, boolean[] b, FBoolReductionOp f)210 static void assertReductionBoolArraysEquals(boolean[] a, boolean[] b, FBoolReductionOp f) { 211 int i = 0; 212 try { 213 for (; i < a.length; i += SPECIES.length()) { 214 Assert.assertEquals(b[i], f.apply(a, i)); 215 } 216 } catch (AssertionError e) { 217 Assert.assertEquals(b[i], f.apply(a, i), "at index #" + i); 218 } 219 } 220 assertInsertArraysEquals(float[] a, float[] b, float element, int index)221 static void assertInsertArraysEquals(float[] a, float[] b, float element, int index) { 222 int i = 0; 223 try { 224 for (; i < a.length; i += 1) { 225 if(i%SPECIES.length() == index) { 226 Assert.assertEquals(b[i], element); 227 } else { 228 Assert.assertEquals(b[i], a[i]); 229 } 230 } 231 } catch (AssertionError e) { 232 if (i%SPECIES.length() == index) { 233 Assert.assertEquals(b[i], element, "at index #" + i); 234 } else { 235 Assert.assertEquals(b[i], a[i], "at index #" + i); 236 } 237 } 238 } 239 assertRearrangeArraysEquals(float[] a, float[] r, int[] order, int vector_len)240 static void assertRearrangeArraysEquals(float[] a, float[] r, int[] order, int vector_len) { 241 int i = 0, j = 0; 242 try { 243 for (; i < a.length; i += vector_len) { 244 for (j = 0; j < vector_len; j++) { 245 Assert.assertEquals(r[i+j], a[i+order[i+j]]); 246 } 247 } 248 } catch (AssertionError e) { 249 int idx = i + j; 250 Assert.assertEquals(r[i+j], a[i+order[i+j]], "at index #" + idx + ", input = " + a[i+order[i+j]]); 251 } 252 } 253 assertSelectFromArraysEquals(float[] a, float[] r, float[] order, int vector_len)254 static void assertSelectFromArraysEquals(float[] a, float[] r, float[] order, int vector_len) { 255 int i = 0, j = 0; 256 try { 257 for (; i < a.length; i += vector_len) { 258 for (j = 0; j < vector_len; j++) { 259 Assert.assertEquals(r[i+j], a[i+(int)order[i+j]]); 260 } 261 } 262 } catch (AssertionError e) { 263 int idx = i + j; 264 Assert.assertEquals(r[i+j], a[i+(int)order[i+j]], "at index #" + idx + ", input = " + a[i+(int)order[i+j]]); 265 } 266 } 267 assertRearrangeArraysEquals(float[] a, float[] r, int[] order, boolean[] mask, int vector_len)268 static void assertRearrangeArraysEquals(float[] a, float[] r, int[] order, boolean[] mask, int vector_len) { 269 int i = 0, j = 0; 270 try { 271 for (; i < a.length; i += vector_len) { 272 for (j = 0; j < vector_len; j++) { 273 if (mask[j % SPECIES.length()]) 274 Assert.assertEquals(r[i+j], a[i+order[i+j]]); 275 else 276 Assert.assertEquals(r[i+j], (float)0); 277 } 278 } 279 } catch (AssertionError e) { 280 int idx = i + j; 281 if (mask[j % SPECIES.length()]) 282 Assert.assertEquals(r[i+j], a[i+order[i+j]], "at index #" + idx + ", input = " + a[i+order[i+j]] + ", mask = " + mask[j % SPECIES.length()]); 283 else 284 Assert.assertEquals(r[i+j], (float)0, "at index #" + idx + ", input = " + a[i+order[i+j]] + ", mask = " + mask[j % SPECIES.length()]); 285 } 286 } 287 assertSelectFromArraysEquals(float[] a, float[] r, float[] order, boolean[] mask, int vector_len)288 static void assertSelectFromArraysEquals(float[] a, float[] r, float[] order, boolean[] mask, int vector_len) { 289 int i = 0, j = 0; 290 try { 291 for (; i < a.length; i += vector_len) { 292 for (j = 0; j < vector_len; j++) { 293 if (mask[j % SPECIES.length()]) 294 Assert.assertEquals(r[i+j], a[i+(int)order[i+j]]); 295 else 296 Assert.assertEquals(r[i+j], (float)0); 297 } 298 } 299 } catch (AssertionError e) { 300 int idx = i + j; 301 if (mask[j % SPECIES.length()]) 302 Assert.assertEquals(r[i+j], a[i+(int)order[i+j]], "at index #" + idx + ", input = " + a[i+(int)order[i+j]] + ", mask = " + mask[j % SPECIES.length()]); 303 else 304 Assert.assertEquals(r[i+j], (float)0, "at index #" + idx + ", input = " + a[i+(int)order[i+j]] + ", mask = " + mask[j % SPECIES.length()]); 305 } 306 } 307 assertBroadcastArraysEquals(float[]a, float[]r)308 static void assertBroadcastArraysEquals(float[]a, float[]r) { 309 int i = 0; 310 for (; i < a.length; i += SPECIES.length()) { 311 int idx = i; 312 for (int j = idx; j < (idx + SPECIES.length()); j++) 313 a[j]=a[idx]; 314 } 315 316 try { 317 for (i = 0; i < a.length; i++) { 318 Assert.assertEquals(r[i], a[i]); 319 } 320 } catch (AssertionError e) { 321 Assert.assertEquals(r[i], a[i], "at index #" + i + ", input = " + a[i]); 322 } 323 } 324 325 interface FBinOp { apply(float a, float b)326 float apply(float a, float b); 327 } 328 329 interface FBinMaskOp { apply(float a, float b, boolean m)330 float apply(float a, float b, boolean m); 331 lift(FBinOp f)332 static FBinMaskOp lift(FBinOp f) { 333 return (a, b, m) -> m ? f.apply(a, b) : a; 334 } 335 } 336 assertArraysEquals(float[] a, float[] b, float[] r, FBinOp f)337 static void assertArraysEquals(float[] a, float[] b, float[] r, FBinOp f) { 338 int i = 0; 339 try { 340 for (; i < a.length; i++) { 341 Assert.assertEquals(r[i], f.apply(a[i], b[i])); 342 } 343 } catch (AssertionError e) { 344 Assert.assertEquals(r[i], f.apply(a[i], b[i]), "(" + a[i] + ", " + b[i] + ") at index #" + i); 345 } 346 } 347 assertBroadcastArraysEquals(float[] a, float[] b, float[] r, FBinOp f)348 static void assertBroadcastArraysEquals(float[] a, float[] b, float[] r, FBinOp f) { 349 int i = 0; 350 try { 351 for (; i < a.length; i++) { 352 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()])); 353 } 354 } catch (AssertionError e) { 355 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()]), 356 "(" + a[i] + ", " + b[(i / SPECIES.length()) * SPECIES.length()] + ") at index #" + i); 357 } 358 } 359 assertBroadcastLongArraysEquals(float[] a, float[] b, float[] r, FBinOp f)360 static void assertBroadcastLongArraysEquals(float[] a, float[] b, float[] r, FBinOp f) { 361 int i = 0; 362 try { 363 for (; i < a.length; i++) { 364 Assert.assertEquals(r[i], f.apply(a[i], (float)((long)b[(i / SPECIES.length()) * SPECIES.length()]))); 365 } 366 } catch (AssertionError e) { 367 Assert.assertEquals(r[i], f.apply(a[i], (float)((long)b[(i / SPECIES.length()) * SPECIES.length()])), 368 "(" + a[i] + ", " + b[(i / SPECIES.length()) * SPECIES.length()] + ") at index #" + i); 369 } 370 } 371 assertArraysEquals(float[] a, float[] b, float[] r, boolean[] mask, FBinOp f)372 static void assertArraysEquals(float[] a, float[] b, float[] r, boolean[] mask, FBinOp f) { 373 assertArraysEquals(a, b, r, mask, FBinMaskOp.lift(f)); 374 } 375 assertArraysEquals(float[] a, float[] b, float[] r, boolean[] mask, FBinMaskOp f)376 static void assertArraysEquals(float[] a, float[] b, float[] r, boolean[] mask, FBinMaskOp f) { 377 int i = 0; 378 try { 379 for (; i < a.length; i++) { 380 Assert.assertEquals(r[i], f.apply(a[i], b[i], mask[i % SPECIES.length()])); 381 } 382 } catch (AssertionError err) { 383 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()]); 384 } 385 } 386 assertBroadcastArraysEquals(float[] a, float[] b, float[] r, boolean[] mask, FBinOp f)387 static void assertBroadcastArraysEquals(float[] a, float[] b, float[] r, boolean[] mask, FBinOp f) { 388 assertBroadcastArraysEquals(a, b, r, mask, FBinMaskOp.lift(f)); 389 } 390 assertBroadcastArraysEquals(float[] a, float[] b, float[] r, boolean[] mask, FBinMaskOp f)391 static void assertBroadcastArraysEquals(float[] a, float[] b, float[] r, boolean[] mask, FBinMaskOp f) { 392 int i = 0; 393 try { 394 for (; i < a.length; i++) { 395 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], mask[i % SPECIES.length()])); 396 } 397 } catch (AssertionError err) { 398 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], 399 mask[i % SPECIES.length()]), "at index #" + i + ", input1 = " + a[i] + 400 ", input2 = " + b[(i / SPECIES.length()) * SPECIES.length()] + ", mask = " + 401 mask[i % SPECIES.length()]); 402 } 403 } 404 assertBroadcastLongArraysEquals(float[] a, float[] b, float[] r, boolean[] mask, FBinOp f)405 static void assertBroadcastLongArraysEquals(float[] a, float[] b, float[] r, boolean[] mask, FBinOp f) { 406 assertBroadcastLongArraysEquals(a, b, r, mask, FBinMaskOp.lift(f)); 407 } 408 assertBroadcastLongArraysEquals(float[] a, float[] b, float[] r, boolean[] mask, FBinMaskOp f)409 static void assertBroadcastLongArraysEquals(float[] a, float[] b, float[] r, boolean[] mask, FBinMaskOp f) { 410 int i = 0; 411 try { 412 for (; i < a.length; i++) { 413 Assert.assertEquals(r[i], f.apply(a[i], (float)((long)b[(i / SPECIES.length()) * SPECIES.length()]), mask[i % SPECIES.length()])); 414 } 415 } catch (AssertionError err) { 416 Assert.assertEquals(r[i], f.apply(a[i], (float)((long)b[(i / SPECIES.length()) * SPECIES.length()]), 417 mask[i % SPECIES.length()]), "at index #" + i + ", input1 = " + a[i] + 418 ", input2 = " + b[(i / SPECIES.length()) * SPECIES.length()] + ", mask = " + 419 mask[i % SPECIES.length()]); 420 } 421 } 422 assertShiftArraysEquals(float[] a, float[] b, float[] r, FBinOp f)423 static void assertShiftArraysEquals(float[] a, float[] b, float[] r, FBinOp f) { 424 int i = 0; 425 int j = 0; 426 try { 427 for (; j < a.length; j += SPECIES.length()) { 428 for (i = 0; i < SPECIES.length(); i++) { 429 Assert.assertEquals(r[i+j], f.apply(a[i+j], b[j])); 430 } 431 } 432 } catch (AssertionError e) { 433 Assert.assertEquals(r[i+j], f.apply(a[i+j], b[j]), "at index #" + i + ", " + j); 434 } 435 } 436 assertShiftArraysEquals(float[] a, float[] b, float[] r, boolean[] mask, FBinOp f)437 static void assertShiftArraysEquals(float[] a, float[] b, float[] r, boolean[] mask, FBinOp f) { 438 assertShiftArraysEquals(a, b, r, mask, FBinMaskOp.lift(f)); 439 } 440 assertShiftArraysEquals(float[] a, float[] b, float[] r, boolean[] mask, FBinMaskOp f)441 static void assertShiftArraysEquals(float[] a, float[] b, float[] r, boolean[] mask, FBinMaskOp f) { 442 int i = 0; 443 int j = 0; 444 try { 445 for (; j < a.length; j += SPECIES.length()) { 446 for (i = 0; i < SPECIES.length(); i++) { 447 Assert.assertEquals(r[i+j], f.apply(a[i+j], b[j], mask[i])); 448 } 449 } 450 } catch (AssertionError err) { 451 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]); 452 } 453 } 454 455 interface FTernOp { apply(float a, float b, float c)456 float apply(float a, float b, float c); 457 } 458 459 interface FTernMaskOp { apply(float a, float b, float c, boolean m)460 float apply(float a, float b, float c, boolean m); 461 lift(FTernOp f)462 static FTernMaskOp lift(FTernOp f) { 463 return (a, b, c, m) -> m ? f.apply(a, b, c) : a; 464 } 465 } 466 assertArraysEquals(float[] a, float[] b, float[] c, float[] r, FTernOp f)467 static void assertArraysEquals(float[] a, float[] b, float[] c, float[] r, FTernOp f) { 468 int i = 0; 469 try { 470 for (; i < a.length; i++) { 471 Assert.assertEquals(r[i], f.apply(a[i], b[i], c[i])); 472 } 473 } catch (AssertionError e) { 474 Assert.assertEquals(r[i], f.apply(a[i], b[i], c[i]), "at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]); 475 } 476 } 477 assertArraysEquals(float[] a, float[] b, float[] c, float[] r, boolean[] mask, FTernOp f)478 static void assertArraysEquals(float[] a, float[] b, float[] c, float[] r, boolean[] mask, FTernOp f) { 479 assertArraysEquals(a, b, c, r, mask, FTernMaskOp.lift(f)); 480 } 481 assertArraysEquals(float[] a, float[] b, float[] c, float[] r, boolean[] mask, FTernMaskOp f)482 static void assertArraysEquals(float[] a, float[] b, float[] c, float[] r, boolean[] mask, FTernMaskOp f) { 483 int i = 0; 484 try { 485 for (; i < a.length; i++) { 486 Assert.assertEquals(r[i], f.apply(a[i], b[i], c[i], mask[i % SPECIES.length()])); 487 } 488 } catch (AssertionError err) { 489 Assert.assertEquals(r[i], f.apply(a[i], b[i], c[i], mask[i % SPECIES.length()]), "at index #" + i + ", input1 = " + a[i] + ", input2 = " 490 + b[i] + ", input3 = " + c[i] + ", mask = " + mask[i % SPECIES.length()]); 491 } 492 } 493 assertBroadcastArraysEquals(float[] a, float[] b, float[] c, float[] r, FTernOp f)494 static void assertBroadcastArraysEquals(float[] a, float[] b, float[] c, float[] r, FTernOp f) { 495 int i = 0; 496 try { 497 for (; i < a.length; i++) { 498 Assert.assertEquals(r[i], f.apply(a[i], b[i], c[(i / SPECIES.length()) * SPECIES.length()])); 499 } 500 } catch (AssertionError e) { 501 Assert.assertEquals(r[i], f.apply(a[i], b[i], c[(i / SPECIES.length()) * SPECIES.length()]), "at index #" + 502 i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + 503 c[(i / SPECIES.length()) * SPECIES.length()]); 504 } 505 } 506 assertAltBroadcastArraysEquals(float[] a, float[] b, float[] c, float[] r, FTernOp f)507 static void assertAltBroadcastArraysEquals(float[] a, float[] b, float[] c, float[] r, FTernOp f) { 508 int i = 0; 509 try { 510 for (; i < a.length; i++) { 511 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], c[i])); 512 } 513 } catch (AssertionError e) { 514 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], c[i]), "at index #" + 515 i + ", input1 = " + a[i] + ", input2 = " + 516 b[(i / SPECIES.length()) * SPECIES.length()] + ", input3 = " + c[i]); 517 } 518 } 519 assertBroadcastArraysEquals(float[] a, float[] b, float[] c, float[] r, boolean[] mask, FTernOp f)520 static void assertBroadcastArraysEquals(float[] a, float[] b, float[] c, float[] r, boolean[] mask, 521 FTernOp f) { 522 assertBroadcastArraysEquals(a, b, c, r, mask, FTernMaskOp.lift(f)); 523 } 524 assertBroadcastArraysEquals(float[] a, float[] b, float[] c, float[] r, boolean[] mask, FTernMaskOp f)525 static void assertBroadcastArraysEquals(float[] a, float[] b, float[] c, float[] r, boolean[] mask, 526 FTernMaskOp f) { 527 int i = 0; 528 try { 529 for (; i < a.length; i++) { 530 Assert.assertEquals(r[i], f.apply(a[i], b[i], c[(i / SPECIES.length()) * SPECIES.length()], 531 mask[i % SPECIES.length()])); 532 } 533 } catch (AssertionError err) { 534 Assert.assertEquals(r[i], f.apply(a[i], b[i], c[(i / SPECIES.length()) * SPECIES.length()], 535 mask[i % SPECIES.length()]), "at index #" + i + ", input1 = " + a[i] + ", input2 = " + 536 b[i] + ", input3 = " + c[(i / SPECIES.length()) * SPECIES.length()] + ", mask = " + 537 mask[i % SPECIES.length()]); 538 } 539 } 540 assertAltBroadcastArraysEquals(float[] a, float[] b, float[] c, float[] r, boolean[] mask, FTernOp f)541 static void assertAltBroadcastArraysEquals(float[] a, float[] b, float[] c, float[] r, boolean[] mask, 542 FTernOp f) { 543 assertAltBroadcastArraysEquals(a, b, c, r, mask, FTernMaskOp.lift(f)); 544 } 545 assertAltBroadcastArraysEquals(float[] a, float[] b, float[] c, float[] r, boolean[] mask, FTernMaskOp f)546 static void assertAltBroadcastArraysEquals(float[] a, float[] b, float[] c, float[] r, boolean[] mask, 547 FTernMaskOp f) { 548 int i = 0; 549 try { 550 for (; i < a.length; i++) { 551 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], c[i], 552 mask[i % SPECIES.length()])); 553 } 554 } catch (AssertionError err) { 555 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], c[i], 556 mask[i % SPECIES.length()]), "at index #" + i + ", input1 = " + a[i] + 557 ", input2 = " + b[(i / SPECIES.length()) * SPECIES.length()] + 558 ", input3 = " + c[i] + ", mask = " + mask[i % SPECIES.length()]); 559 } 560 } 561 assertDoubleBroadcastArraysEquals(float[] a, float[] b, float[] c, float[] r, FTernOp f)562 static void assertDoubleBroadcastArraysEquals(float[] a, float[] b, float[] c, float[] r, FTernOp f) { 563 int i = 0; 564 try { 565 for (; i < a.length; i++) { 566 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], 567 c[(i / SPECIES.length()) * SPECIES.length()])); 568 } 569 } catch (AssertionError e) { 570 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], 571 c[(i / SPECIES.length()) * SPECIES.length()]), "at index #" + i + ", input1 = " + a[i] 572 + ", input2 = " + b[(i / SPECIES.length()) * SPECIES.length()] + ", input3 = " + 573 c[(i / SPECIES.length()) * SPECIES.length()]); 574 } 575 } 576 assertDoubleBroadcastArraysEquals(float[] a, float[] b, float[] c, float[] r, boolean[] mask, FTernOp f)577 static void assertDoubleBroadcastArraysEquals(float[] a, float[] b, float[] c, float[] r, boolean[] mask, 578 FTernOp f) { 579 assertDoubleBroadcastArraysEquals(a, b, c, r, mask, FTernMaskOp.lift(f)); 580 } 581 assertDoubleBroadcastArraysEquals(float[] a, float[] b, float[] c, float[] r, boolean[] mask, FTernMaskOp f)582 static void assertDoubleBroadcastArraysEquals(float[] a, float[] b, float[] c, float[] r, boolean[] mask, 583 FTernMaskOp f) { 584 int i = 0; 585 try { 586 for (; i < a.length; i++) { 587 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], 588 c[(i / SPECIES.length()) * SPECIES.length()], mask[i % SPECIES.length()])); 589 } 590 } catch (AssertionError err) { 591 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], 592 c[(i / SPECIES.length()) * SPECIES.length()], mask[i % SPECIES.length()]), "at index #" 593 + i + ", input1 = " + a[i] + ", input2 = " + b[(i / SPECIES.length()) * SPECIES.length()] + 594 ", input3 = " + c[(i / SPECIES.length()) * SPECIES.length()] + ", mask = " + 595 mask[i % SPECIES.length()]); 596 } 597 } 598 599 isWithin1Ulp(float actual, float expected)600 static boolean isWithin1Ulp(float actual, float expected) { 601 if (Float.isNaN(expected) && !Float.isNaN(actual)) { 602 return false; 603 } else if (!Float.isNaN(expected) && Float.isNaN(actual)) { 604 return false; 605 } 606 607 float low = Math.nextDown(expected); 608 float high = Math.nextUp(expected); 609 610 if (Float.compare(low, expected) > 0) { 611 return false; 612 } 613 614 if (Float.compare(high, expected) < 0) { 615 return false; 616 } 617 618 return true; 619 } 620 assertArraysEqualsWithinOneUlp(float[] a, float[] r, FUnOp mathf, FUnOp strictmathf)621 static void assertArraysEqualsWithinOneUlp(float[] a, float[] r, FUnOp mathf, FUnOp strictmathf) { 622 int i = 0; 623 try { 624 // Check that result is within 1 ulp of strict math or equivalent to math implementation. 625 for (; i < a.length; i++) { 626 Assert.assertTrue(Float.compare(r[i], mathf.apply(a[i])) == 0 || 627 isWithin1Ulp(r[i], strictmathf.apply(a[i]))); 628 } 629 } catch (AssertionError e) { 630 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])); 631 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])); 632 } 633 } 634 assertArraysEqualsWithinOneUlp(float[] a, float[] b, float[] r, FBinOp mathf, FBinOp strictmathf)635 static void assertArraysEqualsWithinOneUlp(float[] a, float[] b, float[] r, FBinOp mathf, FBinOp strictmathf) { 636 int i = 0; 637 try { 638 // Check that result is within 1 ulp of strict math or equivalent to math implementation. 639 for (; i < a.length; i++) { 640 Assert.assertTrue(Float.compare(r[i], mathf.apply(a[i], b[i])) == 0 || 641 isWithin1Ulp(r[i], strictmathf.apply(a[i], b[i]))); 642 } 643 } catch (AssertionError e) { 644 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])); 645 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])); 646 } 647 } 648 assertBroadcastArraysEqualsWithinOneUlp(float[] a, float[] b, float[] r, FBinOp mathf, FBinOp strictmathf)649 static void assertBroadcastArraysEqualsWithinOneUlp(float[] a, float[] b, float[] r, 650 FBinOp mathf, FBinOp strictmathf) { 651 int i = 0; 652 try { 653 // Check that result is within 1 ulp of strict math or equivalent to math implementation. 654 for (; i < a.length; i++) { 655 Assert.assertTrue(Float.compare(r[i], 656 mathf.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()])) == 0 || 657 isWithin1Ulp(r[i], 658 strictmathf.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()]))); 659 } 660 } catch (AssertionError e) { 661 Assert.assertTrue(Float.compare(r[i], 662 mathf.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()])) == 0, 663 "at index #" + i + ", input1 = " + a[i] + ", input2 = " + 664 b[(i / SPECIES.length()) * SPECIES.length()] + ", actual = " + r[i] + 665 ", expected = " + mathf.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()])); 666 Assert.assertTrue(isWithin1Ulp(r[i], 667 strictmathf.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()])), 668 "at index #" + i + ", input1 = " + a[i] + ", input2 = " + 669 b[(i / SPECIES.length()) * SPECIES.length()] + ", actual = " + r[i] + 670 ", expected (within 1 ulp) = " + strictmathf.apply(a[i], 671 b[(i / SPECIES.length()) * SPECIES.length()])); 672 } 673 } 674 675 interface FBinArrayOp { apply(float[] a, int b)676 float apply(float[] a, int b); 677 } 678 assertArraysEquals(float[] a, float[] r, FBinArrayOp f)679 static void assertArraysEquals(float[] a, float[] r, FBinArrayOp f) { 680 int i = 0; 681 try { 682 for (; i < a.length; i++) { 683 Assert.assertEquals(r[i], f.apply(a, i)); 684 } 685 } catch (AssertionError e) { 686 Assert.assertEquals(r[i], f.apply(a,i), "at index #" + i); 687 } 688 } 689 690 interface FGatherScatterOp { apply(float[] a, int ix, int[] b, int iy)691 float[] apply(float[] a, int ix, int[] b, int iy); 692 } 693 assertArraysEquals(float[] a, int[] b, float[] r, FGatherScatterOp f)694 static void assertArraysEquals(float[] a, int[] b, float[] r, FGatherScatterOp f) { 695 int i = 0; 696 try { 697 for (; i < a.length; i += SPECIES.length()) { 698 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()), 699 f.apply(a, i, b, i)); 700 } 701 } catch (AssertionError e) { 702 float[] ref = f.apply(a, i, b, i); 703 float[] res = Arrays.copyOfRange(r, i, i+SPECIES.length()); 704 Assert.assertEquals(res, ref, 705 "(ref: " + Arrays.toString(ref) + ", res: " + Arrays.toString(res) + ", a: " 706 + Arrays.toString(Arrays.copyOfRange(a, i, i+SPECIES.length())) 707 + ", b: " 708 + Arrays.toString(Arrays.copyOfRange(b, i, i+SPECIES.length())) 709 + " at index #" + i); 710 } 711 } 712 713 interface FGatherMaskedOp { apply(float[] a, int ix, boolean[] mask, int[] b, int iy)714 float[] apply(float[] a, int ix, boolean[] mask, int[] b, int iy); 715 } 716 717 interface FScatterMaskedOp { apply(float[] r, float[] a, int ix, boolean[] mask, int[] b, int iy)718 float[] apply(float[] r, float[] a, int ix, boolean[] mask, int[] b, int iy); 719 } 720 assertArraysEquals(float[] a, int[] b, float[] r, boolean[] mask, FGatherMaskedOp f)721 static void assertArraysEquals(float[] a, int[] b, float[] r, boolean[] mask, FGatherMaskedOp f) { 722 int i = 0; 723 try { 724 for (; i < a.length; i += SPECIES.length()) { 725 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()), 726 f.apply(a, i, mask, b, i)); 727 } 728 } catch (AssertionError e) { 729 float[] ref = f.apply(a, i, mask, b, i); 730 float[] res = Arrays.copyOfRange(r, i, i+SPECIES.length()); 731 Assert.assertEquals(ref, res, 732 "(ref: " + Arrays.toString(ref) + ", res: " + Arrays.toString(res) + ", a: " 733 + Arrays.toString(Arrays.copyOfRange(a, i, i+SPECIES.length())) 734 + ", b: " 735 + Arrays.toString(Arrays.copyOfRange(b, i, i+SPECIES.length())) 736 + ", mask: " 737 + Arrays.toString(mask) 738 + " at index #" + i); 739 } 740 } 741 assertArraysEquals(float[] a, int[] b, float[] r, boolean[] mask, FScatterMaskedOp f)742 static void assertArraysEquals(float[] a, int[] b, float[] r, boolean[] mask, FScatterMaskedOp f) { 743 int i = 0; 744 try { 745 for (; i < a.length; i += SPECIES.length()) { 746 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()), 747 f.apply(r, a, i, mask, b, i)); 748 } 749 } catch (AssertionError e) { 750 float[] ref = f.apply(r, a, i, mask, b, i); 751 float[] res = Arrays.copyOfRange(r, i, i+SPECIES.length()); 752 Assert.assertEquals(ref, res, 753 "(ref: " + Arrays.toString(ref) + ", res: " + Arrays.toString(res) + ", a: " 754 + Arrays.toString(Arrays.copyOfRange(a, i, i+SPECIES.length())) 755 + ", b: " 756 + Arrays.toString(Arrays.copyOfRange(b, i, i+SPECIES.length())) 757 + ", r: " 758 + Arrays.toString(Arrays.copyOfRange(r, i, i+SPECIES.length())) 759 + ", mask: " 760 + Arrays.toString(mask) 761 + " at index #" + i); 762 } 763 } 764 765 interface FLaneOp { apply(float[] a, int origin, int idx)766 float[] apply(float[] a, int origin, int idx); 767 } 768 assertArraysEquals(float[] a, float[] r, int origin, FLaneOp f)769 static void assertArraysEquals(float[] a, float[] r, int origin, FLaneOp f) { 770 int i = 0; 771 try { 772 for (; i < a.length; i += SPECIES.length()) { 773 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()), 774 f.apply(a, origin, i)); 775 } 776 } catch (AssertionError e) { 777 float[] ref = f.apply(a, origin, i); 778 float[] res = Arrays.copyOfRange(r, i, i+SPECIES.length()); 779 Assert.assertEquals(ref, res, "(ref: " + Arrays.toString(ref) 780 + ", res: " + Arrays.toString(res) 781 + "), at index #" + i); 782 } 783 } 784 785 interface FLaneBop { apply(float[] a, float[] b, int origin, int idx)786 float[] apply(float[] a, float[] b, int origin, int idx); 787 } 788 assertArraysEquals(float[] a, float[] b, float[] r, int origin, FLaneBop f)789 static void assertArraysEquals(float[] a, float[] b, float[] r, int origin, FLaneBop f) { 790 int i = 0; 791 try { 792 for (; i < a.length; i += SPECIES.length()) { 793 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()), 794 f.apply(a, b, origin, i)); 795 } 796 } catch (AssertionError e) { 797 float[] ref = f.apply(a, b, origin, i); 798 float[] res = Arrays.copyOfRange(r, i, i+SPECIES.length()); 799 Assert.assertEquals(ref, res, "(ref: " + Arrays.toString(ref) 800 + ", res: " + Arrays.toString(res) 801 + "), at index #" + i 802 + ", at origin #" + origin); 803 } 804 } 805 806 interface FLaneMaskedBop { apply(float[] a, float[] b, int origin, boolean[] mask, int idx)807 float[] apply(float[] a, float[] b, int origin, boolean[] mask, int idx); 808 } 809 assertArraysEquals(float[] a, float[] b, float[] r, int origin, boolean[] mask, FLaneMaskedBop f)810 static void assertArraysEquals(float[] a, float[] b, float[] r, int origin, boolean[] mask, FLaneMaskedBop f) { 811 int i = 0; 812 try { 813 for (; i < a.length; i += SPECIES.length()) { 814 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()), 815 f.apply(a, b, origin, mask, i)); 816 } 817 } catch (AssertionError e) { 818 float[] ref = f.apply(a, b, origin, mask, i); 819 float[] res = Arrays.copyOfRange(r, i, i+SPECIES.length()); 820 Assert.assertEquals(ref, res, "(ref: " + Arrays.toString(ref) 821 + ", res: " + Arrays.toString(res) 822 + "), at index #" + i 823 + ", at origin #" + origin); 824 } 825 } 826 827 interface FLanePartBop { apply(float[] a, float[] b, int origin, int part, int idx)828 float[] apply(float[] a, float[] b, int origin, int part, int idx); 829 } 830 assertArraysEquals(float[] a, float[] b, float[] r, int origin, int part, FLanePartBop f)831 static void assertArraysEquals(float[] a, float[] b, float[] r, int origin, int part, FLanePartBop f) { 832 int i = 0; 833 try { 834 for (; i < a.length; i += SPECIES.length()) { 835 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()), 836 f.apply(a, b, origin, part, i)); 837 } 838 } catch (AssertionError e) { 839 float[] ref = f.apply(a, b, origin, part, i); 840 float[] res = Arrays.copyOfRange(r, i, i+SPECIES.length()); 841 Assert.assertEquals(ref, res, "(ref: " + Arrays.toString(ref) 842 + ", res: " + Arrays.toString(res) 843 + "), at index #" + i 844 + ", at origin #" + origin 845 + ", with part #" + part); 846 } 847 } 848 849 interface FLanePartMaskedBop { apply(float[] a, float[] b, int origin, int part, boolean[] mask, int idx)850 float[] apply(float[] a, float[] b, int origin, int part, boolean[] mask, int idx); 851 } 852 assertArraysEquals(float[] a, float[] b, float[] r, int origin, int part, boolean[] mask, FLanePartMaskedBop f)853 static void assertArraysEquals(float[] a, float[] b, float[] r, int origin, int part, boolean[] mask, FLanePartMaskedBop f) { 854 int i = 0; 855 try { 856 for (; i < a.length; i += SPECIES.length()) { 857 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()), 858 f.apply(a, b, origin, part, mask, i)); 859 } 860 } catch (AssertionError e) { 861 float[] ref = f.apply(a, b, origin, part, mask, i); 862 float[] res = Arrays.copyOfRange(r, i, i+SPECIES.length()); 863 Assert.assertEquals(ref, res, "(ref: " + Arrays.toString(ref) 864 + ", res: " + Arrays.toString(res) 865 + "), at index #" + i 866 + ", at origin #" + origin 867 + ", with part #" + part); 868 } 869 } 870 intCornerCaseValue(int i)871 static int intCornerCaseValue(int i) { 872 switch(i % 5) { 873 case 0: 874 return Integer.MAX_VALUE; 875 case 1: 876 return Integer.MIN_VALUE; 877 case 2: 878 return Integer.MIN_VALUE; 879 case 3: 880 return Integer.MAX_VALUE; 881 default: 882 return (int)0; 883 } 884 } 885 886 static final List<IntFunction<float[]>> INT_FLOAT_GENERATORS = List.of( 887 withToString("float[-i * 5]", (int s) -> { 888 return fill(s * BUFFER_REPS, 889 i -> (float)(-i * 5)); 890 }), 891 withToString("float[i * 5]", (int s) -> { 892 return fill(s * BUFFER_REPS, 893 i -> (float)(i * 5)); 894 }), 895 withToString("float[i + 1]", (int s) -> { 896 return fill(s * BUFFER_REPS, 897 i -> (((float)(i + 1) == 0) ? 1 : (float)(i + 1))); 898 }), 899 withToString("float[intCornerCaseValue(i)]", (int s) -> { 900 return fill(s * BUFFER_REPS, 901 i -> (float)intCornerCaseValue(i)); 902 }) 903 ); 904 assertArraysEquals(float[] a, int[] r, int offs)905 static void assertArraysEquals(float[] a, int[] r, int offs) { 906 int i = 0; 907 try { 908 for (; i < r.length; i++) { 909 Assert.assertEquals(r[i], (int)(a[i+offs])); 910 } 911 } catch (AssertionError e) { 912 Assert.assertEquals(r[i], (int)(a[i+offs]), "at index #" + i + ", input = " + a[i+offs]); 913 } 914 } 915 longCornerCaseValue(int i)916 static long longCornerCaseValue(int i) { 917 switch(i % 5) { 918 case 0: 919 return Long.MAX_VALUE; 920 case 1: 921 return Long.MIN_VALUE; 922 case 2: 923 return Long.MIN_VALUE; 924 case 3: 925 return Long.MAX_VALUE; 926 default: 927 return (long)0; 928 } 929 } 930 931 static final List<IntFunction<float[]>> LONG_FLOAT_GENERATORS = List.of( 932 withToString("float[-i * 5]", (int s) -> { 933 return fill(s * BUFFER_REPS, 934 i -> (float)(-i * 5)); 935 }), 936 withToString("float[i * 5]", (int s) -> { 937 return fill(s * BUFFER_REPS, 938 i -> (float)(i * 5)); 939 }), 940 withToString("float[i + 1]", (int s) -> { 941 return fill(s * BUFFER_REPS, 942 i -> (((float)(i + 1) == 0) ? 1 : (float)(i + 1))); 943 }), 944 withToString("float[cornerCaseValue(i)]", (int s) -> { 945 return fill(s * BUFFER_REPS, 946 i -> (float)longCornerCaseValue(i)); 947 }) 948 ); 949 950 assertArraysEquals(float[] a, long[] r, int offs)951 static void assertArraysEquals(float[] a, long[] r, int offs) { 952 int i = 0; 953 try { 954 for (; i < r.length; i++) { 955 Assert.assertEquals(r[i], (long)(a[i+offs])); 956 } 957 } catch (AssertionError e) { 958 Assert.assertEquals(r[i], (long)(a[i+offs]), "at index #" + i + ", input = " + a[i+offs]); 959 } 960 } 961 assertArraysEquals(float[] a, double[] r, int offs)962 static void assertArraysEquals(float[] a, double[] r, int offs) { 963 int i = 0; 964 try { 965 for (; i < r.length; i++) { 966 Assert.assertEquals(r[i], (double)(a[i+offs])); 967 } 968 } catch (AssertionError e) { 969 Assert.assertEquals(r[i], (double)(a[i+offs]), "at index #" + i + ", input = " + a[i+offs]); 970 } 971 } 972 973 bits(float e)974 static int bits(float e) { 975 return Float.floatToIntBits(e); 976 } 977 978 static final List<IntFunction<float[]>> FLOAT_GENERATORS = List.of( 979 withToString("float[-i * 5]", (int s) -> { 980 return fill(s * BUFFER_REPS, 981 i -> (float)(-i * 5)); 982 }), 983 withToString("float[i * 5]", (int s) -> { 984 return fill(s * BUFFER_REPS, 985 i -> (float)(i * 5)); 986 }), 987 withToString("float[i + 1]", (int s) -> { 988 return fill(s * BUFFER_REPS, 989 i -> (((float)(i + 1) == 0) ? 1 : (float)(i + 1))); 990 }), 991 withToString("float[cornerCaseValue(i)]", (int s) -> { 992 return fill(s * BUFFER_REPS, 993 i -> cornerCaseValue(i)); 994 }) 995 ); 996 997 // Create combinations of pairs 998 // @@@ Might be sensitive to order e.g. div by 0 999 static final List<List<IntFunction<float[]>>> FLOAT_GENERATOR_PAIRS = 1000 Stream.of(FLOAT_GENERATORS.get(0)). 1001 flatMap(fa -> FLOAT_GENERATORS.stream().skip(1).map(fb -> List.of(fa, fb))). 1002 collect(Collectors.toList()); 1003 1004 @DataProvider boolUnaryOpProvider()1005 public Object[][] boolUnaryOpProvider() { 1006 return BOOL_ARRAY_GENERATORS.stream(). 1007 map(f -> new Object[]{f}). 1008 toArray(Object[][]::new); 1009 } 1010 1011 static final List<List<IntFunction<float[]>>> FLOAT_GENERATOR_TRIPLES = 1012 FLOAT_GENERATOR_PAIRS.stream(). 1013 flatMap(pair -> FLOAT_GENERATORS.stream().map(f -> List.of(pair.get(0), pair.get(1), f))). 1014 collect(Collectors.toList()); 1015 1016 @DataProvider floatBinaryOpProvider()1017 public Object[][] floatBinaryOpProvider() { 1018 return FLOAT_GENERATOR_PAIRS.stream().map(List::toArray). 1019 toArray(Object[][]::new); 1020 } 1021 1022 @DataProvider floatIndexedOpProvider()1023 public Object[][] floatIndexedOpProvider() { 1024 return FLOAT_GENERATOR_PAIRS.stream().map(List::toArray). 1025 toArray(Object[][]::new); 1026 } 1027 1028 @DataProvider floatBinaryOpMaskProvider()1029 public Object[][] floatBinaryOpMaskProvider() { 1030 return BOOLEAN_MASK_GENERATORS.stream(). 1031 flatMap(fm -> FLOAT_GENERATOR_PAIRS.stream().map(lfa -> { 1032 return Stream.concat(lfa.stream(), Stream.of(fm)).toArray(); 1033 })). 1034 toArray(Object[][]::new); 1035 } 1036 1037 @DataProvider floatTernaryOpProvider()1038 public Object[][] floatTernaryOpProvider() { 1039 return FLOAT_GENERATOR_TRIPLES.stream().map(List::toArray). 1040 toArray(Object[][]::new); 1041 } 1042 1043 @DataProvider floatTernaryOpMaskProvider()1044 public Object[][] floatTernaryOpMaskProvider() { 1045 return BOOLEAN_MASK_GENERATORS.stream(). 1046 flatMap(fm -> FLOAT_GENERATOR_TRIPLES.stream().map(lfa -> { 1047 return Stream.concat(lfa.stream(), Stream.of(fm)).toArray(); 1048 })). 1049 toArray(Object[][]::new); 1050 } 1051 1052 @DataProvider 1053 public Object[][] floatUnaryOpProvider() { 1054 return FLOAT_GENERATORS.stream(). 1055 map(f -> new Object[]{f}). 1056 toArray(Object[][]::new); 1057 } 1058 1059 @DataProvider 1060 public Object[][] floatUnaryOpMaskProvider() { 1061 return BOOLEAN_MASK_GENERATORS.stream(). 1062 flatMap(fm -> FLOAT_GENERATORS.stream().map(fa -> { 1063 return new Object[] {fa, fm}; 1064 })). 1065 toArray(Object[][]::new); 1066 } 1067 1068 @DataProvider 1069 public Object[][] floattoIntUnaryOpProvider() { 1070 return INT_FLOAT_GENERATORS.stream(). 1071 map(f -> new Object[]{f}). 1072 toArray(Object[][]::new); 1073 } 1074 1075 @DataProvider 1076 public Object[][] floattoLongUnaryOpProvider() { 1077 return LONG_FLOAT_GENERATORS.stream(). 1078 map(f -> new Object[]{f}). 1079 toArray(Object[][]::new); 1080 } 1081 1082 @DataProvider 1083 public Object[][] maskProvider() { 1084 return BOOLEAN_MASK_GENERATORS.stream(). 1085 map(f -> new Object[]{f}). 1086 toArray(Object[][]::new); 1087 } 1088 1089 @DataProvider 1090 public Object[][] maskCompareOpProvider() { 1091 return BOOLEAN_MASK_COMPARE_GENERATOR_PAIRS.stream().map(List::toArray). 1092 toArray(Object[][]::new); 1093 } 1094 1095 @DataProvider 1096 public Object[][] shuffleProvider() { 1097 return INT_SHUFFLE_GENERATORS.stream(). 1098 map(f -> new Object[]{f}). 1099 toArray(Object[][]::new); 1100 } 1101 1102 @DataProvider 1103 public Object[][] shuffleCompareOpProvider() { 1104 return INT_SHUFFLE_COMPARE_GENERATOR_PAIRS.stream().map(List::toArray). 1105 toArray(Object[][]::new); 1106 } 1107 1108 @DataProvider 1109 public Object[][] floatUnaryOpShuffleProvider() { 1110 return INT_SHUFFLE_GENERATORS.stream(). 1111 flatMap(fs -> FLOAT_GENERATORS.stream().map(fa -> { 1112 return new Object[] {fa, fs}; 1113 })). 1114 toArray(Object[][]::new); 1115 } 1116 1117 @DataProvider 1118 public Object[][] floatUnaryOpShuffleMaskProvider() { 1119 return BOOLEAN_MASK_GENERATORS.stream(). 1120 flatMap(fm -> INT_SHUFFLE_GENERATORS.stream(). 1121 flatMap(fs -> FLOAT_GENERATORS.stream().map(fa -> { 1122 return new Object[] {fa, fs, fm}; 1123 }))). 1124 toArray(Object[][]::new); 1125 } 1126 1127 static final List<BiFunction<Integer,Integer,float[]>> FLOAT_SHUFFLE_GENERATORS = List.of( 1128 withToStringBi("shuffle[random]", (Integer l, Integer m) -> { 1129 float[] a = new float[l]; 1130 for (int i = 0; i < 1; i++) { 1131 a[i] = (float)RAND.nextInt(m); 1132 } 1133 return a; 1134 }) 1135 ); 1136 1137 @DataProvider 1138 public Object[][] floatUnaryOpSelectFromProvider() { 1139 return FLOAT_SHUFFLE_GENERATORS.stream(). 1140 flatMap(fs -> FLOAT_GENERATORS.stream().map(fa -> { 1141 return new Object[] {fa, fs}; 1142 })). 1143 toArray(Object[][]::new); 1144 } 1145 1146 @DataProvider 1147 public Object[][] floatUnaryOpSelectFromMaskProvider() { 1148 return BOOLEAN_MASK_GENERATORS.stream(). 1149 flatMap(fm -> FLOAT_SHUFFLE_GENERATORS.stream(). 1150 flatMap(fs -> FLOAT_GENERATORS.stream().map(fa -> { 1151 return new Object[] {fa, fs, fm}; 1152 }))). 1153 toArray(Object[][]::new); 1154 } 1155 1156 1157 @DataProvider 1158 public Object[][] floatUnaryOpIndexProvider() { 1159 return INT_INDEX_GENERATORS.stream(). 1160 flatMap(fs -> FLOAT_GENERATORS.stream().map(fa -> { 1161 return new Object[] {fa, fs}; 1162 })). 1163 toArray(Object[][]::new); 1164 } 1165 1166 @DataProvider 1167 public Object[][] floatUnaryMaskedOpIndexProvider() { 1168 return BOOLEAN_MASK_GENERATORS.stream(). 1169 flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> 1170 FLOAT_GENERATORS.stream().map(fa -> { 1171 return new Object[] {fa, fm, fs}; 1172 }))). 1173 toArray(Object[][]::new); 1174 } 1175 1176 @DataProvider 1177 public Object[][] scatterMaskedOpIndexProvider() { 1178 return BOOLEAN_MASK_GENERATORS.stream(). 1179 flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> 1180 FLOAT_GENERATORS.stream().flatMap(fn -> 1181 FLOAT_GENERATORS.stream().map(fa -> { 1182 return new Object[] {fa, fn, fm, fs}; 1183 })))). 1184 toArray(Object[][]::new); 1185 } 1186 1187 static final List<IntFunction<float[]>> FLOAT_COMPARE_GENERATORS = List.of( 1188 withToString("float[i]", (int s) -> { 1189 return fill(s * BUFFER_REPS, 1190 i -> (float)i); 1191 }), 1192 withToString("float[i + 1]", (int s) -> { 1193 return fill(s * BUFFER_REPS, 1194 i -> (float)(i + 1)); 1195 }), 1196 withToString("float[i - 2]", (int s) -> { 1197 return fill(s * BUFFER_REPS, 1198 i -> (float)(i - 2)); 1199 }), 1200 withToString("float[zigZag(i)]", (int s) -> { 1201 return fill(s * BUFFER_REPS, 1202 i -> i%3 == 0 ? (float)i : (i%3 == 1 ? (float)(i + 1) : (float)(i - 2))); 1203 }), 1204 withToString("float[cornerCaseValue(i)]", (int s) -> { 1205 return fill(s * BUFFER_REPS, 1206 i -> cornerCaseValue(i)); 1207 }) 1208 ); 1209 1210 static final List<List<IntFunction<float[]>>> FLOAT_TEST_GENERATOR_ARGS = 1211 FLOAT_COMPARE_GENERATORS.stream(). 1212 map(fa -> List.of(fa)). 1213 collect(Collectors.toList()); 1214 1215 @DataProvider 1216 public Object[][] floatTestOpProvider() { 1217 return FLOAT_TEST_GENERATOR_ARGS.stream().map(List::toArray). 1218 toArray(Object[][]::new); 1219 } 1220 1221 @DataProvider 1222 public Object[][] floatTestOpMaskProvider() { 1223 return BOOLEAN_MASK_GENERATORS.stream(). 1224 flatMap(fm -> FLOAT_TEST_GENERATOR_ARGS.stream().map(lfa -> { 1225 return Stream.concat(lfa.stream(), Stream.of(fm)).toArray(); 1226 })). 1227 toArray(Object[][]::new); 1228 } 1229 1230 static final List<List<IntFunction<float[]>>> FLOAT_COMPARE_GENERATOR_PAIRS = 1231 FLOAT_COMPARE_GENERATORS.stream(). 1232 flatMap(fa -> FLOAT_COMPARE_GENERATORS.stream().map(fb -> List.of(fa, fb))). 1233 collect(Collectors.toList()); 1234 1235 @DataProvider 1236 public Object[][] floatCompareOpProvider() { 1237 return FLOAT_COMPARE_GENERATOR_PAIRS.stream().map(List::toArray). 1238 toArray(Object[][]::new); 1239 } 1240 1241 @DataProvider 1242 public Object[][] floatCompareOpMaskProvider() { 1243 return BOOLEAN_MASK_GENERATORS.stream(). 1244 flatMap(fm -> FLOAT_COMPARE_GENERATOR_PAIRS.stream().map(lfa -> { 1245 return Stream.concat(lfa.stream(), Stream.of(fm)).toArray(); 1246 })). 1247 toArray(Object[][]::new); 1248 } 1249 1250 interface ToFloatF { 1251 float apply(int i); 1252 } 1253 1254 static float[] fill(int s , ToFloatF f) { 1255 return fill(new float[s], f); 1256 } 1257 1258 static float[] fill(float[] a, ToFloatF f) { 1259 for (int i = 0; i < a.length; i++) { 1260 a[i] = f.apply(i); 1261 } 1262 return a; 1263 } 1264 1265 static float cornerCaseValue(int i) { 1266 switch(i % 7) { 1267 case 0: 1268 return Float.MAX_VALUE; 1269 case 1: 1270 return Float.MIN_VALUE; 1271 case 2: 1272 return Float.NEGATIVE_INFINITY; 1273 case 3: 1274 return Float.POSITIVE_INFINITY; 1275 case 4: 1276 return Float.NaN; 1277 case 5: 1278 return (float)0.0; 1279 default: 1280 return (float)-0.0; 1281 } 1282 } 1283 1284 static float get(float[] a, int i) { 1285 return (float) a[i]; 1286 } 1287 1288 static final IntFunction<float[]> fr = (vl) -> { 1289 int length = BUFFER_REPS * vl; 1290 return new float[length]; 1291 }; 1292 1293 static final IntFunction<boolean[]> fmr = (vl) -> { 1294 int length = BUFFER_REPS * vl; 1295 return new boolean[length]; 1296 }; 1297 1298 static final IntFunction<long[]> lfr = (vl) -> { 1299 int length = BUFFER_REPS * vl; 1300 return new long[length]; 1301 }; 1302 1303 1304 @Test 1305 static void smokeTest1() { 1306 FloatVector three = FloatVector.broadcast(SPECIES, (byte)-3); 1307 FloatVector three2 = (FloatVector) SPECIES.broadcast(-3); 1308 assert(three.eq(three2).allTrue()); 1309 FloatVector three3 = three2.broadcast(1).broadcast(-3); 1310 assert(three.eq(three3).allTrue()); 1311 int scale = 2; 1312 Class<?> ETYPE = float.class; 1313 if (ETYPE == double.class || ETYPE == long.class) 1314 scale = 1000000; 1315 else if (ETYPE == byte.class && SPECIES.length() >= 64) 1316 scale = 1; 1317 FloatVector higher = three.addIndex(scale); 1318 VectorMask<Float> m = three.compare(VectorOperators.LE, higher); 1319 assert(m.allTrue()); 1320 m = higher.min((float)-1).test(VectorOperators.IS_NEGATIVE); 1321 assert(m.allTrue()); 1322 m = higher.test(VectorOperators.IS_FINITE); 1323 assert(m.allTrue()); 1324 float max = higher.reduceLanes(VectorOperators.MAX); 1325 assert(max == -3 + scale * (SPECIES.length()-1)); 1326 } 1327 1328 private static float[] 1329 bothToArray(FloatVector a, FloatVector b) { 1330 float[] r = new float[a.length() + b.length()]; 1331 a.intoArray(r, 0); 1332 b.intoArray(r, a.length()); 1333 return r; 1334 } 1335 1336 @Test 1337 static void smokeTest2() { 1338 // Do some zipping and shuffling. 1339 FloatVector io = (FloatVector) SPECIES.broadcast(0).addIndex(1); 1340 FloatVector io2 = (FloatVector) VectorShuffle.iota(SPECIES,0,1,false).toVector(); 1341 Assert.assertEquals(io, io2); 1342 FloatVector a = io.add((float)1); //[1,2] 1343 FloatVector b = a.neg(); //[-1,-2] 1344 float[] abValues = bothToArray(a,b); //[1,2,-1,-2] 1345 VectorShuffle<Float> zip0 = VectorShuffle.makeZip(SPECIES, 0); 1346 VectorShuffle<Float> zip1 = VectorShuffle.makeZip(SPECIES, 1); 1347 FloatVector zab0 = a.rearrange(zip0,b); //[1,-1] 1348 FloatVector zab1 = a.rearrange(zip1,b); //[2,-2] 1349 float[] zabValues = bothToArray(zab0, zab1); //[1,-1,2,-2] 1350 // manually zip 1351 float[] manual = new float[zabValues.length]; 1352 for (int i = 0; i < manual.length; i += 2) { 1353 manual[i+0] = abValues[i/2]; 1354 manual[i+1] = abValues[a.length() + i/2]; 1355 } 1356 Assert.assertEquals(Arrays.toString(zabValues), Arrays.toString(manual)); 1357 VectorShuffle<Float> unz0 = VectorShuffle.makeUnzip(SPECIES, 0); 1358 VectorShuffle<Float> unz1 = VectorShuffle.makeUnzip(SPECIES, 1); 1359 FloatVector uab0 = zab0.rearrange(unz0,zab1); 1360 FloatVector uab1 = zab0.rearrange(unz1,zab1); 1361 float[] abValues1 = bothToArray(uab0, uab1); 1362 Assert.assertEquals(Arrays.toString(abValues), Arrays.toString(abValues1)); 1363 } 1364 1365 static void iotaShuffle() { 1366 FloatVector io = (FloatVector) SPECIES.broadcast(0).addIndex(1); 1367 FloatVector io2 = (FloatVector) VectorShuffle.iota(SPECIES, 0 , 1, false).toVector(); 1368 Assert.assertEquals(io, io2); 1369 } 1370 1371 @Test 1372 // Test all shuffle related operations. 1373 static void shuffleTest() { 1374 // To test backend instructions, make sure that C2 is used. 1375 for (int loop = 0; loop < INVOC_COUNT * INVOC_COUNT; loop++) { 1376 iotaShuffle(); 1377 } 1378 } 1379 1380 @Test 1381 void viewAsIntegeralLanesTest() { 1382 Vector<?> asIntegral = SPECIES.zero().viewAsIntegralLanes(); 1383 VectorSpecies<?> asIntegralSpecies = asIntegral.species(); 1384 Assert.assertNotEquals(asIntegralSpecies.elementType(), SPECIES.elementType()); 1385 Assert.assertEquals(asIntegralSpecies.vectorShape(), SPECIES.vectorShape()); 1386 Assert.assertEquals(asIntegralSpecies.length(), SPECIES.length()); 1387 Assert.assertEquals(asIntegral.viewAsFloatingLanes().species(), SPECIES); 1388 } 1389 1390 @Test 1391 void viewAsFloatingLanesTest() { 1392 Vector<?> asFloating = SPECIES.zero().viewAsFloatingLanes(); 1393 Assert.assertEquals(asFloating.species(), SPECIES); 1394 } 1395 1396 static float ADD(float a, float b) { 1397 return (float)(a + b); 1398 } 1399 1400 @Test(dataProvider = "floatBinaryOpProvider") 1401 static void ADDFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) { 1402 float[] a = fa.apply(SPECIES.length()); 1403 float[] b = fb.apply(SPECIES.length()); 1404 float[] r = fr.apply(SPECIES.length()); 1405 1406 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1407 for (int i = 0; i < a.length; i += SPECIES.length()) { 1408 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1409 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 1410 av.lanewise(VectorOperators.ADD, bv).intoArray(r, i); 1411 } 1412 } 1413 1414 assertArraysEquals(a, b, r, FloatMaxVectorTests::ADD); 1415 } 1416 static float add(float a, float b) { 1417 return (float)(a + b); 1418 } 1419 1420 @Test(dataProvider = "floatBinaryOpProvider") 1421 static void addFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) { 1422 float[] a = fa.apply(SPECIES.length()); 1423 float[] b = fb.apply(SPECIES.length()); 1424 float[] r = fr.apply(SPECIES.length()); 1425 1426 for (int i = 0; i < a.length; i += SPECIES.length()) { 1427 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1428 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 1429 av.add(bv).intoArray(r, i); 1430 } 1431 1432 assertArraysEquals(a, b, r, FloatMaxVectorTests::add); 1433 } 1434 1435 @Test(dataProvider = "floatBinaryOpMaskProvider") 1436 static void ADDFloatMaxVectorTestsMasked(IntFunction<float[]> fa, IntFunction<float[]> fb, 1437 IntFunction<boolean[]> fm) { 1438 float[] a = fa.apply(SPECIES.length()); 1439 float[] b = fb.apply(SPECIES.length()); 1440 float[] r = fr.apply(SPECIES.length()); 1441 boolean[] mask = fm.apply(SPECIES.length()); 1442 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1443 1444 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1445 for (int i = 0; i < a.length; i += SPECIES.length()) { 1446 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1447 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 1448 av.lanewise(VectorOperators.ADD, bv, vmask).intoArray(r, i); 1449 } 1450 } 1451 1452 assertArraysEquals(a, b, r, mask, FloatMaxVectorTests::ADD); 1453 } 1454 1455 @Test(dataProvider = "floatBinaryOpMaskProvider") 1456 static void addFloatMaxVectorTestsMasked(IntFunction<float[]> fa, IntFunction<float[]> fb, 1457 IntFunction<boolean[]> fm) { 1458 float[] a = fa.apply(SPECIES.length()); 1459 float[] b = fb.apply(SPECIES.length()); 1460 float[] r = fr.apply(SPECIES.length()); 1461 boolean[] mask = fm.apply(SPECIES.length()); 1462 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1463 1464 for (int i = 0; i < a.length; i += SPECIES.length()) { 1465 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1466 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 1467 av.add(bv, vmask).intoArray(r, i); 1468 } 1469 1470 assertArraysEquals(a, b, r, mask, FloatMaxVectorTests::add); 1471 } 1472 static float SUB(float a, float b) { 1473 return (float)(a - b); 1474 } 1475 1476 @Test(dataProvider = "floatBinaryOpProvider") 1477 static void SUBFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) { 1478 float[] a = fa.apply(SPECIES.length()); 1479 float[] b = fb.apply(SPECIES.length()); 1480 float[] r = fr.apply(SPECIES.length()); 1481 1482 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1483 for (int i = 0; i < a.length; i += SPECIES.length()) { 1484 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1485 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 1486 av.lanewise(VectorOperators.SUB, bv).intoArray(r, i); 1487 } 1488 } 1489 1490 assertArraysEquals(a, b, r, FloatMaxVectorTests::SUB); 1491 } 1492 static float sub(float a, float b) { 1493 return (float)(a - b); 1494 } 1495 1496 @Test(dataProvider = "floatBinaryOpProvider") 1497 static void subFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) { 1498 float[] a = fa.apply(SPECIES.length()); 1499 float[] b = fb.apply(SPECIES.length()); 1500 float[] r = fr.apply(SPECIES.length()); 1501 1502 for (int i = 0; i < a.length; i += SPECIES.length()) { 1503 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1504 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 1505 av.sub(bv).intoArray(r, i); 1506 } 1507 1508 assertArraysEquals(a, b, r, FloatMaxVectorTests::sub); 1509 } 1510 1511 @Test(dataProvider = "floatBinaryOpMaskProvider") 1512 static void SUBFloatMaxVectorTestsMasked(IntFunction<float[]> fa, IntFunction<float[]> fb, 1513 IntFunction<boolean[]> fm) { 1514 float[] a = fa.apply(SPECIES.length()); 1515 float[] b = fb.apply(SPECIES.length()); 1516 float[] r = fr.apply(SPECIES.length()); 1517 boolean[] mask = fm.apply(SPECIES.length()); 1518 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1519 1520 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1521 for (int i = 0; i < a.length; i += SPECIES.length()) { 1522 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1523 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 1524 av.lanewise(VectorOperators.SUB, bv, vmask).intoArray(r, i); 1525 } 1526 } 1527 1528 assertArraysEquals(a, b, r, mask, FloatMaxVectorTests::SUB); 1529 } 1530 1531 @Test(dataProvider = "floatBinaryOpMaskProvider") 1532 static void subFloatMaxVectorTestsMasked(IntFunction<float[]> fa, IntFunction<float[]> fb, 1533 IntFunction<boolean[]> fm) { 1534 float[] a = fa.apply(SPECIES.length()); 1535 float[] b = fb.apply(SPECIES.length()); 1536 float[] r = fr.apply(SPECIES.length()); 1537 boolean[] mask = fm.apply(SPECIES.length()); 1538 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1539 1540 for (int i = 0; i < a.length; i += SPECIES.length()) { 1541 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1542 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 1543 av.sub(bv, vmask).intoArray(r, i); 1544 } 1545 1546 assertArraysEquals(a, b, r, mask, FloatMaxVectorTests::sub); 1547 } 1548 static float MUL(float a, float b) { 1549 return (float)(a * b); 1550 } 1551 1552 @Test(dataProvider = "floatBinaryOpProvider") 1553 static void MULFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) { 1554 float[] a = fa.apply(SPECIES.length()); 1555 float[] b = fb.apply(SPECIES.length()); 1556 float[] r = fr.apply(SPECIES.length()); 1557 1558 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1559 for (int i = 0; i < a.length; i += SPECIES.length()) { 1560 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1561 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 1562 av.lanewise(VectorOperators.MUL, bv).intoArray(r, i); 1563 } 1564 } 1565 1566 assertArraysEquals(a, b, r, FloatMaxVectorTests::MUL); 1567 } 1568 static float mul(float a, float b) { 1569 return (float)(a * b); 1570 } 1571 1572 @Test(dataProvider = "floatBinaryOpProvider") 1573 static void mulFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) { 1574 float[] a = fa.apply(SPECIES.length()); 1575 float[] b = fb.apply(SPECIES.length()); 1576 float[] r = fr.apply(SPECIES.length()); 1577 1578 for (int i = 0; i < a.length; i += SPECIES.length()) { 1579 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1580 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 1581 av.mul(bv).intoArray(r, i); 1582 } 1583 1584 assertArraysEquals(a, b, r, FloatMaxVectorTests::mul); 1585 } 1586 1587 @Test(dataProvider = "floatBinaryOpMaskProvider") 1588 static void MULFloatMaxVectorTestsMasked(IntFunction<float[]> fa, IntFunction<float[]> fb, 1589 IntFunction<boolean[]> fm) { 1590 float[] a = fa.apply(SPECIES.length()); 1591 float[] b = fb.apply(SPECIES.length()); 1592 float[] r = fr.apply(SPECIES.length()); 1593 boolean[] mask = fm.apply(SPECIES.length()); 1594 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1595 1596 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1597 for (int i = 0; i < a.length; i += SPECIES.length()) { 1598 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1599 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 1600 av.lanewise(VectorOperators.MUL, bv, vmask).intoArray(r, i); 1601 } 1602 } 1603 1604 assertArraysEquals(a, b, r, mask, FloatMaxVectorTests::MUL); 1605 } 1606 1607 @Test(dataProvider = "floatBinaryOpMaskProvider") 1608 static void mulFloatMaxVectorTestsMasked(IntFunction<float[]> fa, IntFunction<float[]> fb, 1609 IntFunction<boolean[]> fm) { 1610 float[] a = fa.apply(SPECIES.length()); 1611 float[] b = fb.apply(SPECIES.length()); 1612 float[] r = fr.apply(SPECIES.length()); 1613 boolean[] mask = fm.apply(SPECIES.length()); 1614 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1615 1616 for (int i = 0; i < a.length; i += SPECIES.length()) { 1617 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1618 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 1619 av.mul(bv, vmask).intoArray(r, i); 1620 } 1621 1622 assertArraysEquals(a, b, r, mask, FloatMaxVectorTests::mul); 1623 } 1624 1625 static float DIV(float a, float b) { 1626 return (float)(a / b); 1627 } 1628 1629 @Test(dataProvider = "floatBinaryOpProvider") 1630 static void DIVFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) { 1631 float[] a = fa.apply(SPECIES.length()); 1632 float[] b = fb.apply(SPECIES.length()); 1633 float[] r = fr.apply(SPECIES.length()); 1634 1635 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1636 for (int i = 0; i < a.length; i += SPECIES.length()) { 1637 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1638 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 1639 av.lanewise(VectorOperators.DIV, bv).intoArray(r, i); 1640 } 1641 } 1642 1643 assertArraysEquals(a, b, r, FloatMaxVectorTests::DIV); 1644 } 1645 static float div(float a, float b) { 1646 return (float)(a / b); 1647 } 1648 1649 @Test(dataProvider = "floatBinaryOpProvider") 1650 static void divFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) { 1651 float[] a = fa.apply(SPECIES.length()); 1652 float[] b = fb.apply(SPECIES.length()); 1653 float[] r = fr.apply(SPECIES.length()); 1654 1655 for (int i = 0; i < a.length; i += SPECIES.length()) { 1656 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1657 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 1658 av.div(bv).intoArray(r, i); 1659 } 1660 1661 assertArraysEquals(a, b, r, FloatMaxVectorTests::div); 1662 } 1663 1664 1665 1666 @Test(dataProvider = "floatBinaryOpMaskProvider") 1667 static void DIVFloatMaxVectorTestsMasked(IntFunction<float[]> fa, IntFunction<float[]> fb, 1668 IntFunction<boolean[]> fm) { 1669 float[] a = fa.apply(SPECIES.length()); 1670 float[] b = fb.apply(SPECIES.length()); 1671 float[] r = fr.apply(SPECIES.length()); 1672 boolean[] mask = fm.apply(SPECIES.length()); 1673 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1674 1675 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1676 for (int i = 0; i < a.length; i += SPECIES.length()) { 1677 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1678 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 1679 av.lanewise(VectorOperators.DIV, bv, vmask).intoArray(r, i); 1680 } 1681 } 1682 1683 assertArraysEquals(a, b, r, mask, FloatMaxVectorTests::DIV); 1684 } 1685 1686 @Test(dataProvider = "floatBinaryOpMaskProvider") 1687 static void divFloatMaxVectorTestsMasked(IntFunction<float[]> fa, IntFunction<float[]> fb, 1688 IntFunction<boolean[]> fm) { 1689 float[] a = fa.apply(SPECIES.length()); 1690 float[] b = fb.apply(SPECIES.length()); 1691 float[] r = fr.apply(SPECIES.length()); 1692 boolean[] mask = fm.apply(SPECIES.length()); 1693 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1694 1695 for (int i = 0; i < a.length; i += SPECIES.length()) { 1696 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1697 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 1698 av.div(bv, vmask).intoArray(r, i); 1699 } 1700 1701 assertArraysEquals(a, b, r, mask, FloatMaxVectorTests::div); 1702 } 1703 1704 1705 1706 static float FIRST_NONZERO(float a, float b) { 1707 return (float)(Double.doubleToLongBits(a)!=0?a:b); 1708 } 1709 1710 @Test(dataProvider = "floatBinaryOpProvider") 1711 static void FIRST_NONZEROFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) { 1712 float[] a = fa.apply(SPECIES.length()); 1713 float[] b = fb.apply(SPECIES.length()); 1714 float[] r = fr.apply(SPECIES.length()); 1715 1716 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1717 for (int i = 0; i < a.length; i += SPECIES.length()) { 1718 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1719 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 1720 av.lanewise(VectorOperators.FIRST_NONZERO, bv).intoArray(r, i); 1721 } 1722 } 1723 1724 assertArraysEquals(a, b, r, FloatMaxVectorTests::FIRST_NONZERO); 1725 } 1726 1727 @Test(dataProvider = "floatBinaryOpMaskProvider") 1728 static void FIRST_NONZEROFloatMaxVectorTestsMasked(IntFunction<float[]> fa, IntFunction<float[]> fb, 1729 IntFunction<boolean[]> fm) { 1730 float[] a = fa.apply(SPECIES.length()); 1731 float[] b = fb.apply(SPECIES.length()); 1732 float[] r = fr.apply(SPECIES.length()); 1733 boolean[] mask = fm.apply(SPECIES.length()); 1734 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1735 1736 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1737 for (int i = 0; i < a.length; i += SPECIES.length()) { 1738 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1739 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 1740 av.lanewise(VectorOperators.FIRST_NONZERO, bv, vmask).intoArray(r, i); 1741 } 1742 } 1743 1744 assertArraysEquals(a, b, r, mask, FloatMaxVectorTests::FIRST_NONZERO); 1745 } 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 @Test(dataProvider = "floatBinaryOpProvider") 1756 static void addFloatMaxVectorTestsBroadcastSmokeTest(IntFunction<float[]> fa, IntFunction<float[]> fb) { 1757 float[] a = fa.apply(SPECIES.length()); 1758 float[] b = fb.apply(SPECIES.length()); 1759 float[] r = fr.apply(SPECIES.length()); 1760 1761 for (int i = 0; i < a.length; i += SPECIES.length()) { 1762 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1763 av.add(b[i]).intoArray(r, i); 1764 } 1765 1766 assertBroadcastArraysEquals(a, b, r, FloatMaxVectorTests::add); 1767 } 1768 1769 @Test(dataProvider = "floatBinaryOpMaskProvider") 1770 static void addFloatMaxVectorTestsBroadcastMaskedSmokeTest(IntFunction<float[]> fa, IntFunction<float[]> fb, 1771 IntFunction<boolean[]> fm) { 1772 float[] a = fa.apply(SPECIES.length()); 1773 float[] b = fb.apply(SPECIES.length()); 1774 float[] r = fr.apply(SPECIES.length()); 1775 boolean[] mask = fm.apply(SPECIES.length()); 1776 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1777 1778 for (int i = 0; i < a.length; i += SPECIES.length()) { 1779 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1780 av.add(b[i], vmask).intoArray(r, i); 1781 } 1782 1783 assertBroadcastArraysEquals(a, b, r, mask, FloatMaxVectorTests::add); 1784 } 1785 1786 @Test(dataProvider = "floatBinaryOpProvider") 1787 static void subFloatMaxVectorTestsBroadcastSmokeTest(IntFunction<float[]> fa, IntFunction<float[]> fb) { 1788 float[] a = fa.apply(SPECIES.length()); 1789 float[] b = fb.apply(SPECIES.length()); 1790 float[] r = fr.apply(SPECIES.length()); 1791 1792 for (int i = 0; i < a.length; i += SPECIES.length()) { 1793 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1794 av.sub(b[i]).intoArray(r, i); 1795 } 1796 1797 assertBroadcastArraysEquals(a, b, r, FloatMaxVectorTests::sub); 1798 } 1799 1800 @Test(dataProvider = "floatBinaryOpMaskProvider") 1801 static void subFloatMaxVectorTestsBroadcastMaskedSmokeTest(IntFunction<float[]> fa, IntFunction<float[]> fb, 1802 IntFunction<boolean[]> fm) { 1803 float[] a = fa.apply(SPECIES.length()); 1804 float[] b = fb.apply(SPECIES.length()); 1805 float[] r = fr.apply(SPECIES.length()); 1806 boolean[] mask = fm.apply(SPECIES.length()); 1807 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1808 1809 for (int i = 0; i < a.length; i += SPECIES.length()) { 1810 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1811 av.sub(b[i], vmask).intoArray(r, i); 1812 } 1813 1814 assertBroadcastArraysEquals(a, b, r, mask, FloatMaxVectorTests::sub); 1815 } 1816 1817 @Test(dataProvider = "floatBinaryOpProvider") 1818 static void mulFloatMaxVectorTestsBroadcastSmokeTest(IntFunction<float[]> fa, IntFunction<float[]> fb) { 1819 float[] a = fa.apply(SPECIES.length()); 1820 float[] b = fb.apply(SPECIES.length()); 1821 float[] r = fr.apply(SPECIES.length()); 1822 1823 for (int i = 0; i < a.length; i += SPECIES.length()) { 1824 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1825 av.mul(b[i]).intoArray(r, i); 1826 } 1827 1828 assertBroadcastArraysEquals(a, b, r, FloatMaxVectorTests::mul); 1829 } 1830 1831 @Test(dataProvider = "floatBinaryOpMaskProvider") 1832 static void mulFloatMaxVectorTestsBroadcastMaskedSmokeTest(IntFunction<float[]> fa, IntFunction<float[]> fb, 1833 IntFunction<boolean[]> fm) { 1834 float[] a = fa.apply(SPECIES.length()); 1835 float[] b = fb.apply(SPECIES.length()); 1836 float[] r = fr.apply(SPECIES.length()); 1837 boolean[] mask = fm.apply(SPECIES.length()); 1838 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1839 1840 for (int i = 0; i < a.length; i += SPECIES.length()) { 1841 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1842 av.mul(b[i], vmask).intoArray(r, i); 1843 } 1844 1845 assertBroadcastArraysEquals(a, b, r, mask, FloatMaxVectorTests::mul); 1846 } 1847 1848 1849 @Test(dataProvider = "floatBinaryOpProvider") 1850 static void divFloatMaxVectorTestsBroadcastSmokeTest(IntFunction<float[]> fa, IntFunction<float[]> fb) { 1851 float[] a = fa.apply(SPECIES.length()); 1852 float[] b = fb.apply(SPECIES.length()); 1853 float[] r = fr.apply(SPECIES.length()); 1854 1855 for (int i = 0; i < a.length; i += SPECIES.length()) { 1856 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1857 av.div(b[i]).intoArray(r, i); 1858 } 1859 1860 assertBroadcastArraysEquals(a, b, r, FloatMaxVectorTests::div); 1861 } 1862 1863 1864 1865 @Test(dataProvider = "floatBinaryOpMaskProvider") 1866 static void divFloatMaxVectorTestsBroadcastMaskedSmokeTest(IntFunction<float[]> fa, IntFunction<float[]> fb, 1867 IntFunction<boolean[]> fm) { 1868 float[] a = fa.apply(SPECIES.length()); 1869 float[] b = fb.apply(SPECIES.length()); 1870 float[] r = fr.apply(SPECIES.length()); 1871 boolean[] mask = fm.apply(SPECIES.length()); 1872 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1873 1874 for (int i = 0; i < a.length; i += SPECIES.length()) { 1875 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1876 av.div(b[i], vmask).intoArray(r, i); 1877 } 1878 1879 assertBroadcastArraysEquals(a, b, r, mask, FloatMaxVectorTests::div); 1880 } 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 @Test(dataProvider = "floatBinaryOpProvider") 1892 static void ADDFloatMaxVectorTestsBroadcastLongSmokeTest(IntFunction<float[]> fa, IntFunction<float[]> fb) { 1893 float[] a = fa.apply(SPECIES.length()); 1894 float[] b = fb.apply(SPECIES.length()); 1895 float[] r = fr.apply(SPECIES.length()); 1896 1897 for (int i = 0; i < a.length; i += SPECIES.length()) { 1898 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1899 av.lanewise(VectorOperators.ADD, (long)b[i]).intoArray(r, i); 1900 } 1901 1902 assertBroadcastLongArraysEquals(a, b, r, FloatMaxVectorTests::ADD); 1903 } 1904 1905 @Test(dataProvider = "floatBinaryOpMaskProvider") 1906 static void ADDFloatMaxVectorTestsBroadcastMaskedLongSmokeTest(IntFunction<float[]> fa, IntFunction<float[]> fb, 1907 IntFunction<boolean[]> fm) { 1908 float[] a = fa.apply(SPECIES.length()); 1909 float[] b = fb.apply(SPECIES.length()); 1910 float[] r = fr.apply(SPECIES.length()); 1911 boolean[] mask = fm.apply(SPECIES.length()); 1912 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1913 1914 for (int i = 0; i < a.length; i += SPECIES.length()) { 1915 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1916 av.lanewise(VectorOperators.ADD, (long)b[i], vmask).intoArray(r, i); 1917 } 1918 1919 assertBroadcastLongArraysEquals(a, b, r, mask, FloatMaxVectorTests::ADD); 1920 } 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 static float MIN(float a, float b) { 1958 return (float)(Math.min(a, b)); 1959 } 1960 1961 @Test(dataProvider = "floatBinaryOpProvider") 1962 static void MINFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) { 1963 float[] a = fa.apply(SPECIES.length()); 1964 float[] b = fb.apply(SPECIES.length()); 1965 float[] r = fr.apply(SPECIES.length()); 1966 1967 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1968 for (int i = 0; i < a.length; i += SPECIES.length()) { 1969 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1970 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 1971 av.lanewise(VectorOperators.MIN, bv).intoArray(r, i); 1972 } 1973 } 1974 1975 assertArraysEquals(a, b, r, FloatMaxVectorTests::MIN); 1976 } 1977 static float min(float a, float b) { 1978 return (float)(Math.min(a, b)); 1979 } 1980 1981 @Test(dataProvider = "floatBinaryOpProvider") 1982 static void minFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) { 1983 float[] a = fa.apply(SPECIES.length()); 1984 float[] b = fb.apply(SPECIES.length()); 1985 float[] r = fr.apply(SPECIES.length()); 1986 1987 for (int i = 0; i < a.length; i += SPECIES.length()) { 1988 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1989 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 1990 av.min(bv).intoArray(r, i); 1991 } 1992 1993 assertArraysEquals(a, b, r, FloatMaxVectorTests::min); 1994 } 1995 static float MAX(float a, float b) { 1996 return (float)(Math.max(a, b)); 1997 } 1998 1999 @Test(dataProvider = "floatBinaryOpProvider") 2000 static void MAXFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) { 2001 float[] a = fa.apply(SPECIES.length()); 2002 float[] b = fb.apply(SPECIES.length()); 2003 float[] r = fr.apply(SPECIES.length()); 2004 2005 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2006 for (int i = 0; i < a.length; i += SPECIES.length()) { 2007 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2008 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 2009 av.lanewise(VectorOperators.MAX, bv).intoArray(r, i); 2010 } 2011 } 2012 2013 assertArraysEquals(a, b, r, FloatMaxVectorTests::MAX); 2014 } 2015 static float max(float a, float b) { 2016 return (float)(Math.max(a, b)); 2017 } 2018 2019 @Test(dataProvider = "floatBinaryOpProvider") 2020 static void maxFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) { 2021 float[] a = fa.apply(SPECIES.length()); 2022 float[] b = fb.apply(SPECIES.length()); 2023 float[] r = fr.apply(SPECIES.length()); 2024 2025 for (int i = 0; i < a.length; i += SPECIES.length()) { 2026 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2027 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 2028 av.max(bv).intoArray(r, i); 2029 } 2030 2031 assertArraysEquals(a, b, r, FloatMaxVectorTests::max); 2032 } 2033 2034 @Test(dataProvider = "floatBinaryOpProvider") 2035 static void MINFloatMaxVectorTestsBroadcastSmokeTest(IntFunction<float[]> fa, IntFunction<float[]> fb) { 2036 float[] a = fa.apply(SPECIES.length()); 2037 float[] b = fb.apply(SPECIES.length()); 2038 float[] r = fr.apply(SPECIES.length()); 2039 2040 for (int i = 0; i < a.length; i += SPECIES.length()) { 2041 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2042 av.lanewise(VectorOperators.MIN, b[i]).intoArray(r, i); 2043 } 2044 2045 assertBroadcastArraysEquals(a, b, r, FloatMaxVectorTests::MIN); 2046 } 2047 2048 @Test(dataProvider = "floatBinaryOpProvider") 2049 static void minFloatMaxVectorTestsBroadcastSmokeTest(IntFunction<float[]> fa, IntFunction<float[]> fb) { 2050 float[] a = fa.apply(SPECIES.length()); 2051 float[] b = fb.apply(SPECIES.length()); 2052 float[] r = fr.apply(SPECIES.length()); 2053 2054 for (int i = 0; i < a.length; i += SPECIES.length()) { 2055 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2056 av.min(b[i]).intoArray(r, i); 2057 } 2058 2059 assertBroadcastArraysEquals(a, b, r, FloatMaxVectorTests::min); 2060 } 2061 2062 @Test(dataProvider = "floatBinaryOpProvider") 2063 static void MAXFloatMaxVectorTestsBroadcastSmokeTest(IntFunction<float[]> fa, IntFunction<float[]> fb) { 2064 float[] a = fa.apply(SPECIES.length()); 2065 float[] b = fb.apply(SPECIES.length()); 2066 float[] r = fr.apply(SPECIES.length()); 2067 2068 for (int i = 0; i < a.length; i += SPECIES.length()) { 2069 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2070 av.lanewise(VectorOperators.MAX, b[i]).intoArray(r, i); 2071 } 2072 2073 assertBroadcastArraysEquals(a, b, r, FloatMaxVectorTests::MAX); 2074 } 2075 2076 @Test(dataProvider = "floatBinaryOpProvider") 2077 static void maxFloatMaxVectorTestsBroadcastSmokeTest(IntFunction<float[]> fa, IntFunction<float[]> fb) { 2078 float[] a = fa.apply(SPECIES.length()); 2079 float[] b = fb.apply(SPECIES.length()); 2080 float[] r = fr.apply(SPECIES.length()); 2081 2082 for (int i = 0; i < a.length; i += SPECIES.length()) { 2083 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2084 av.max(b[i]).intoArray(r, i); 2085 } 2086 2087 assertBroadcastArraysEquals(a, b, r, FloatMaxVectorTests::max); 2088 } 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 static float ADDReduce(float[] a, int idx) { 2102 float res = 0; 2103 for (int i = idx; i < (idx + SPECIES.length()); i++) { 2104 res += a[i]; 2105 } 2106 2107 return res; 2108 } 2109 2110 static float ADDReduceAll(float[] a) { 2111 float res = 0; 2112 for (int i = 0; i < a.length; i += SPECIES.length()) { 2113 res += ADDReduce(a, i); 2114 } 2115 2116 return res; 2117 } 2118 @Test(dataProvider = "floatUnaryOpProvider") 2119 static void ADDReduceFloatMaxVectorTests(IntFunction<float[]> fa) { 2120 float[] a = fa.apply(SPECIES.length()); 2121 float[] r = fr.apply(SPECIES.length()); 2122 float ra = 0; 2123 2124 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2125 for (int i = 0; i < a.length; i += SPECIES.length()) { 2126 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2127 r[i] = av.reduceLanes(VectorOperators.ADD); 2128 } 2129 } 2130 2131 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2132 ra = 0; 2133 for (int i = 0; i < a.length; i += SPECIES.length()) { 2134 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2135 ra += av.reduceLanes(VectorOperators.ADD); 2136 } 2137 } 2138 2139 assertReductionArraysEquals(a, r, ra, 2140 FloatMaxVectorTests::ADDReduce, FloatMaxVectorTests::ADDReduceAll); 2141 } 2142 static float ADDReduceMasked(float[] a, int idx, boolean[] mask) { 2143 float res = 0; 2144 for (int i = idx; i < (idx + SPECIES.length()); i++) { 2145 if (mask[i % SPECIES.length()]) 2146 res += a[i]; 2147 } 2148 2149 return res; 2150 } 2151 2152 static float ADDReduceAllMasked(float[] a, boolean[] mask) { 2153 float res = 0; 2154 for (int i = 0; i < a.length; i += SPECIES.length()) { 2155 res += ADDReduceMasked(a, i, mask); 2156 } 2157 2158 return res; 2159 } 2160 @Test(dataProvider = "floatUnaryOpMaskProvider") 2161 static void ADDReduceFloatMaxVectorTestsMasked(IntFunction<float[]> fa, IntFunction<boolean[]> fm) { 2162 float[] a = fa.apply(SPECIES.length()); 2163 float[] r = fr.apply(SPECIES.length()); 2164 boolean[] mask = fm.apply(SPECIES.length()); 2165 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2166 float ra = 0; 2167 2168 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2169 for (int i = 0; i < a.length; i += SPECIES.length()) { 2170 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2171 r[i] = av.reduceLanes(VectorOperators.ADD, vmask); 2172 } 2173 } 2174 2175 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2176 ra = 0; 2177 for (int i = 0; i < a.length; i += SPECIES.length()) { 2178 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2179 ra += av.reduceLanes(VectorOperators.ADD, vmask); 2180 } 2181 } 2182 2183 assertReductionArraysEqualsMasked(a, r, ra, mask, 2184 FloatMaxVectorTests::ADDReduceMasked, FloatMaxVectorTests::ADDReduceAllMasked); 2185 } 2186 static float MULReduce(float[] a, int idx) { 2187 float res = 1; 2188 for (int i = idx; i < (idx + SPECIES.length()); i++) { 2189 res *= a[i]; 2190 } 2191 2192 return res; 2193 } 2194 2195 static float MULReduceAll(float[] a) { 2196 float res = 1; 2197 for (int i = 0; i < a.length; i += SPECIES.length()) { 2198 res *= MULReduce(a, i); 2199 } 2200 2201 return res; 2202 } 2203 @Test(dataProvider = "floatUnaryOpProvider") 2204 static void MULReduceFloatMaxVectorTests(IntFunction<float[]> fa) { 2205 float[] a = fa.apply(SPECIES.length()); 2206 float[] r = fr.apply(SPECIES.length()); 2207 float ra = 1; 2208 2209 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2210 for (int i = 0; i < a.length; i += SPECIES.length()) { 2211 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2212 r[i] = av.reduceLanes(VectorOperators.MUL); 2213 } 2214 } 2215 2216 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2217 ra = 1; 2218 for (int i = 0; i < a.length; i += SPECIES.length()) { 2219 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2220 ra *= av.reduceLanes(VectorOperators.MUL); 2221 } 2222 } 2223 2224 assertReductionArraysEquals(a, r, ra, 2225 FloatMaxVectorTests::MULReduce, FloatMaxVectorTests::MULReduceAll); 2226 } 2227 static float MULReduceMasked(float[] a, int idx, boolean[] mask) { 2228 float res = 1; 2229 for (int i = idx; i < (idx + SPECIES.length()); i++) { 2230 if (mask[i % SPECIES.length()]) 2231 res *= a[i]; 2232 } 2233 2234 return res; 2235 } 2236 2237 static float MULReduceAllMasked(float[] a, boolean[] mask) { 2238 float res = 1; 2239 for (int i = 0; i < a.length; i += SPECIES.length()) { 2240 res *= MULReduceMasked(a, i, mask); 2241 } 2242 2243 return res; 2244 } 2245 @Test(dataProvider = "floatUnaryOpMaskProvider") 2246 static void MULReduceFloatMaxVectorTestsMasked(IntFunction<float[]> fa, IntFunction<boolean[]> fm) { 2247 float[] a = fa.apply(SPECIES.length()); 2248 float[] r = fr.apply(SPECIES.length()); 2249 boolean[] mask = fm.apply(SPECIES.length()); 2250 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2251 float ra = 1; 2252 2253 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2254 for (int i = 0; i < a.length; i += SPECIES.length()) { 2255 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2256 r[i] = av.reduceLanes(VectorOperators.MUL, vmask); 2257 } 2258 } 2259 2260 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2261 ra = 1; 2262 for (int i = 0; i < a.length; i += SPECIES.length()) { 2263 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2264 ra *= av.reduceLanes(VectorOperators.MUL, vmask); 2265 } 2266 } 2267 2268 assertReductionArraysEqualsMasked(a, r, ra, mask, 2269 FloatMaxVectorTests::MULReduceMasked, FloatMaxVectorTests::MULReduceAllMasked); 2270 } 2271 static float MINReduce(float[] a, int idx) { 2272 float res = Float.POSITIVE_INFINITY; 2273 for (int i = idx; i < (idx + SPECIES.length()); i++) { 2274 res = (float)Math.min(res, a[i]); 2275 } 2276 2277 return res; 2278 } 2279 2280 static float MINReduceAll(float[] a) { 2281 float res = Float.POSITIVE_INFINITY; 2282 for (int i = 0; i < a.length; i++) { 2283 res = (float)Math.min(res, a[i]); 2284 } 2285 2286 return res; 2287 } 2288 @Test(dataProvider = "floatUnaryOpProvider") 2289 static void MINReduceFloatMaxVectorTests(IntFunction<float[]> fa) { 2290 float[] a = fa.apply(SPECIES.length()); 2291 float[] r = fr.apply(SPECIES.length()); 2292 float ra = Float.POSITIVE_INFINITY; 2293 2294 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2295 for (int i = 0; i < a.length; i += SPECIES.length()) { 2296 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2297 r[i] = av.reduceLanes(VectorOperators.MIN); 2298 } 2299 } 2300 2301 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2302 ra = Float.POSITIVE_INFINITY; 2303 for (int i = 0; i < a.length; i += SPECIES.length()) { 2304 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2305 ra = (float)Math.min(ra, av.reduceLanes(VectorOperators.MIN)); 2306 } 2307 } 2308 2309 assertReductionArraysEquals(a, r, ra, 2310 FloatMaxVectorTests::MINReduce, FloatMaxVectorTests::MINReduceAll); 2311 } 2312 static float MINReduceMasked(float[] a, int idx, boolean[] mask) { 2313 float res = Float.POSITIVE_INFINITY; 2314 for (int i = idx; i < (idx + SPECIES.length()); i++) { 2315 if(mask[i % SPECIES.length()]) 2316 res = (float)Math.min(res, a[i]); 2317 } 2318 2319 return res; 2320 } 2321 2322 static float MINReduceAllMasked(float[] a, boolean[] mask) { 2323 float res = Float.POSITIVE_INFINITY; 2324 for (int i = 0; i < a.length; i++) { 2325 if(mask[i % SPECIES.length()]) 2326 res = (float)Math.min(res, a[i]); 2327 } 2328 2329 return res; 2330 } 2331 @Test(dataProvider = "floatUnaryOpMaskProvider") 2332 static void MINReduceFloatMaxVectorTestsMasked(IntFunction<float[]> fa, IntFunction<boolean[]> fm) { 2333 float[] a = fa.apply(SPECIES.length()); 2334 float[] r = fr.apply(SPECIES.length()); 2335 boolean[] mask = fm.apply(SPECIES.length()); 2336 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2337 float ra = Float.POSITIVE_INFINITY; 2338 2339 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2340 for (int i = 0; i < a.length; i += SPECIES.length()) { 2341 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2342 r[i] = av.reduceLanes(VectorOperators.MIN, vmask); 2343 } 2344 } 2345 2346 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2347 ra = Float.POSITIVE_INFINITY; 2348 for (int i = 0; i < a.length; i += SPECIES.length()) { 2349 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2350 ra = (float)Math.min(ra, av.reduceLanes(VectorOperators.MIN, vmask)); 2351 } 2352 } 2353 2354 assertReductionArraysEqualsMasked(a, r, ra, mask, 2355 FloatMaxVectorTests::MINReduceMasked, FloatMaxVectorTests::MINReduceAllMasked); 2356 } 2357 static float MAXReduce(float[] a, int idx) { 2358 float res = Float.NEGATIVE_INFINITY; 2359 for (int i = idx; i < (idx + SPECIES.length()); i++) { 2360 res = (float)Math.max(res, a[i]); 2361 } 2362 2363 return res; 2364 } 2365 2366 static float MAXReduceAll(float[] a) { 2367 float res = Float.NEGATIVE_INFINITY; 2368 for (int i = 0; i < a.length; i++) { 2369 res = (float)Math.max(res, a[i]); 2370 } 2371 2372 return res; 2373 } 2374 @Test(dataProvider = "floatUnaryOpProvider") 2375 static void MAXReduceFloatMaxVectorTests(IntFunction<float[]> fa) { 2376 float[] a = fa.apply(SPECIES.length()); 2377 float[] r = fr.apply(SPECIES.length()); 2378 float ra = Float.NEGATIVE_INFINITY; 2379 2380 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2381 for (int i = 0; i < a.length; i += SPECIES.length()) { 2382 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2383 r[i] = av.reduceLanes(VectorOperators.MAX); 2384 } 2385 } 2386 2387 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2388 ra = Float.NEGATIVE_INFINITY; 2389 for (int i = 0; i < a.length; i += SPECIES.length()) { 2390 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2391 ra = (float)Math.max(ra, av.reduceLanes(VectorOperators.MAX)); 2392 } 2393 } 2394 2395 assertReductionArraysEquals(a, r, ra, 2396 FloatMaxVectorTests::MAXReduce, FloatMaxVectorTests::MAXReduceAll); 2397 } 2398 static float MAXReduceMasked(float[] a, int idx, boolean[] mask) { 2399 float res = Float.NEGATIVE_INFINITY; 2400 for (int i = idx; i < (idx + SPECIES.length()); i++) { 2401 if(mask[i % SPECIES.length()]) 2402 res = (float)Math.max(res, a[i]); 2403 } 2404 2405 return res; 2406 } 2407 2408 static float MAXReduceAllMasked(float[] a, boolean[] mask) { 2409 float res = Float.NEGATIVE_INFINITY; 2410 for (int i = 0; i < a.length; i++) { 2411 if(mask[i % SPECIES.length()]) 2412 res = (float)Math.max(res, a[i]); 2413 } 2414 2415 return res; 2416 } 2417 @Test(dataProvider = "floatUnaryOpMaskProvider") 2418 static void MAXReduceFloatMaxVectorTestsMasked(IntFunction<float[]> fa, IntFunction<boolean[]> fm) { 2419 float[] a = fa.apply(SPECIES.length()); 2420 float[] r = fr.apply(SPECIES.length()); 2421 boolean[] mask = fm.apply(SPECIES.length()); 2422 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2423 float ra = Float.NEGATIVE_INFINITY; 2424 2425 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2426 for (int i = 0; i < a.length; i += SPECIES.length()) { 2427 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2428 r[i] = av.reduceLanes(VectorOperators.MAX, vmask); 2429 } 2430 } 2431 2432 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2433 ra = Float.NEGATIVE_INFINITY; 2434 for (int i = 0; i < a.length; i += SPECIES.length()) { 2435 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2436 ra = (float)Math.max(ra, av.reduceLanes(VectorOperators.MAX, vmask)); 2437 } 2438 } 2439 2440 assertReductionArraysEqualsMasked(a, r, ra, mask, 2441 FloatMaxVectorTests::MAXReduceMasked, FloatMaxVectorTests::MAXReduceAllMasked); 2442 } 2443 2444 2445 2446 2447 2448 @Test(dataProvider = "floatUnaryOpProvider") 2449 static void withFloatMaxVectorTests(IntFunction<float []> fa) { 2450 float[] a = fa.apply(SPECIES.length()); 2451 float[] r = fr.apply(SPECIES.length()); 2452 2453 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2454 for (int i = 0; i < a.length; i += SPECIES.length()) { 2455 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2456 av.withLane(0, (float)4).intoArray(r, i); 2457 } 2458 } 2459 2460 assertInsertArraysEquals(a, r, (float)4, 0); 2461 } 2462 static boolean testIS_DEFAULT(float a) { 2463 return bits(a)==0; 2464 } 2465 2466 @Test(dataProvider = "floatTestOpProvider") 2467 static void IS_DEFAULTFloatMaxVectorTests(IntFunction<float[]> fa) { 2468 float[] a = fa.apply(SPECIES.length()); 2469 2470 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2471 for (int i = 0; i < a.length; i += SPECIES.length()) { 2472 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2473 VectorMask<Float> mv = av.test(VectorOperators.IS_DEFAULT); 2474 2475 // Check results as part of computation. 2476 for (int j = 0; j < SPECIES.length(); j++) { 2477 Assert.assertEquals(mv.laneIsSet(j), testIS_DEFAULT(a[i + j])); 2478 } 2479 } 2480 } 2481 } 2482 2483 @Test(dataProvider = "floatTestOpMaskProvider") 2484 static void IS_DEFAULTMaskedFloatMaxVectorTestsSmokeTest(IntFunction<float[]> fa, 2485 IntFunction<boolean[]> fm) { 2486 float[] a = fa.apply(SPECIES.length()); 2487 boolean[] mask = fm.apply(SPECIES.length()); 2488 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2489 2490 for (int i = 0; i < a.length; i += SPECIES.length()) { 2491 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2492 VectorMask<Float> mv = av.test(VectorOperators.IS_DEFAULT, vmask); 2493 2494 // Check results as part of computation. 2495 for (int j = 0; j < SPECIES.length(); j++) { 2496 Assert.assertEquals(mv.laneIsSet(j), vmask.laneIsSet(j) && testIS_DEFAULT(a[i + j])); 2497 } 2498 } 2499 } 2500 static boolean testIS_NEGATIVE(float a) { 2501 return bits(a)<0; 2502 } 2503 2504 @Test(dataProvider = "floatTestOpProvider") 2505 static void IS_NEGATIVEFloatMaxVectorTests(IntFunction<float[]> fa) { 2506 float[] a = fa.apply(SPECIES.length()); 2507 2508 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2509 for (int i = 0; i < a.length; i += SPECIES.length()) { 2510 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2511 VectorMask<Float> mv = av.test(VectorOperators.IS_NEGATIVE); 2512 2513 // Check results as part of computation. 2514 for (int j = 0; j < SPECIES.length(); j++) { 2515 Assert.assertEquals(mv.laneIsSet(j), testIS_NEGATIVE(a[i + j])); 2516 } 2517 } 2518 } 2519 } 2520 2521 @Test(dataProvider = "floatTestOpMaskProvider") 2522 static void IS_NEGATIVEMaskedFloatMaxVectorTestsSmokeTest(IntFunction<float[]> fa, 2523 IntFunction<boolean[]> fm) { 2524 float[] a = fa.apply(SPECIES.length()); 2525 boolean[] mask = fm.apply(SPECIES.length()); 2526 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2527 2528 for (int i = 0; i < a.length; i += SPECIES.length()) { 2529 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2530 VectorMask<Float> mv = av.test(VectorOperators.IS_NEGATIVE, vmask); 2531 2532 // Check results as part of computation. 2533 for (int j = 0; j < SPECIES.length(); j++) { 2534 Assert.assertEquals(mv.laneIsSet(j), vmask.laneIsSet(j) && testIS_NEGATIVE(a[i + j])); 2535 } 2536 } 2537 } 2538 2539 static boolean testIS_FINITE(float a) { 2540 return Float.isFinite(a); 2541 } 2542 2543 @Test(dataProvider = "floatTestOpProvider") 2544 static void IS_FINITEFloatMaxVectorTests(IntFunction<float[]> fa) { 2545 float[] a = fa.apply(SPECIES.length()); 2546 2547 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2548 for (int i = 0; i < a.length; i += SPECIES.length()) { 2549 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2550 VectorMask<Float> mv = av.test(VectorOperators.IS_FINITE); 2551 2552 // Check results as part of computation. 2553 for (int j = 0; j < SPECIES.length(); j++) { 2554 Assert.assertEquals(mv.laneIsSet(j), testIS_FINITE(a[i + j])); 2555 } 2556 } 2557 } 2558 } 2559 2560 @Test(dataProvider = "floatTestOpMaskProvider") 2561 static void IS_FINITEMaskedFloatMaxVectorTestsSmokeTest(IntFunction<float[]> fa, 2562 IntFunction<boolean[]> fm) { 2563 float[] a = fa.apply(SPECIES.length()); 2564 boolean[] mask = fm.apply(SPECIES.length()); 2565 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2566 2567 for (int i = 0; i < a.length; i += SPECIES.length()) { 2568 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2569 VectorMask<Float> mv = av.test(VectorOperators.IS_FINITE, vmask); 2570 2571 // Check results as part of computation. 2572 for (int j = 0; j < SPECIES.length(); j++) { 2573 Assert.assertEquals(mv.laneIsSet(j), vmask.laneIsSet(j) && testIS_FINITE(a[i + j])); 2574 } 2575 } 2576 } 2577 2578 2579 static boolean testIS_NAN(float a) { 2580 return Float.isNaN(a); 2581 } 2582 2583 @Test(dataProvider = "floatTestOpProvider") 2584 static void IS_NANFloatMaxVectorTests(IntFunction<float[]> fa) { 2585 float[] a = fa.apply(SPECIES.length()); 2586 2587 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2588 for (int i = 0; i < a.length; i += SPECIES.length()) { 2589 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2590 VectorMask<Float> mv = av.test(VectorOperators.IS_NAN); 2591 2592 // Check results as part of computation. 2593 for (int j = 0; j < SPECIES.length(); j++) { 2594 Assert.assertEquals(mv.laneIsSet(j), testIS_NAN(a[i + j])); 2595 } 2596 } 2597 } 2598 } 2599 2600 @Test(dataProvider = "floatTestOpMaskProvider") 2601 static void IS_NANMaskedFloatMaxVectorTestsSmokeTest(IntFunction<float[]> fa, 2602 IntFunction<boolean[]> fm) { 2603 float[] a = fa.apply(SPECIES.length()); 2604 boolean[] mask = fm.apply(SPECIES.length()); 2605 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2606 2607 for (int i = 0; i < a.length; i += SPECIES.length()) { 2608 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2609 VectorMask<Float> mv = av.test(VectorOperators.IS_NAN, vmask); 2610 2611 // Check results as part of computation. 2612 for (int j = 0; j < SPECIES.length(); j++) { 2613 Assert.assertEquals(mv.laneIsSet(j), vmask.laneIsSet(j) && testIS_NAN(a[i + j])); 2614 } 2615 } 2616 } 2617 2618 2619 static boolean testIS_INFINITE(float a) { 2620 return Float.isInfinite(a); 2621 } 2622 2623 @Test(dataProvider = "floatTestOpProvider") 2624 static void IS_INFINITEFloatMaxVectorTests(IntFunction<float[]> fa) { 2625 float[] a = fa.apply(SPECIES.length()); 2626 2627 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2628 for (int i = 0; i < a.length; i += SPECIES.length()) { 2629 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2630 VectorMask<Float> mv = av.test(VectorOperators.IS_INFINITE); 2631 2632 // Check results as part of computation. 2633 for (int j = 0; j < SPECIES.length(); j++) { 2634 Assert.assertEquals(mv.laneIsSet(j), testIS_INFINITE(a[i + j])); 2635 } 2636 } 2637 } 2638 } 2639 2640 @Test(dataProvider = "floatTestOpMaskProvider") 2641 static void IS_INFINITEMaskedFloatMaxVectorTestsSmokeTest(IntFunction<float[]> fa, 2642 IntFunction<boolean[]> fm) { 2643 float[] a = fa.apply(SPECIES.length()); 2644 boolean[] mask = fm.apply(SPECIES.length()); 2645 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2646 2647 for (int i = 0; i < a.length; i += SPECIES.length()) { 2648 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2649 VectorMask<Float> mv = av.test(VectorOperators.IS_INFINITE, vmask); 2650 2651 // Check results as part of computation. 2652 for (int j = 0; j < SPECIES.length(); j++) { 2653 Assert.assertEquals(mv.laneIsSet(j), vmask.laneIsSet(j) && testIS_INFINITE(a[i + j])); 2654 } 2655 } 2656 } 2657 2658 2659 @Test(dataProvider = "floatCompareOpProvider") 2660 static void LTFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) { 2661 float[] a = fa.apply(SPECIES.length()); 2662 float[] b = fb.apply(SPECIES.length()); 2663 2664 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2665 for (int i = 0; i < a.length; i += SPECIES.length()) { 2666 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2667 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 2668 VectorMask<Float> mv = av.compare(VectorOperators.LT, bv); 2669 2670 // Check results as part of computation. 2671 for (int j = 0; j < SPECIES.length(); j++) { 2672 Assert.assertEquals(mv.laneIsSet(j), a[i + j] < b[i + j]); 2673 } 2674 } 2675 } 2676 } 2677 2678 2679 @Test(dataProvider = "floatCompareOpProvider") 2680 static void ltFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) { 2681 float[] a = fa.apply(SPECIES.length()); 2682 float[] b = fb.apply(SPECIES.length()); 2683 2684 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2685 for (int i = 0; i < a.length; i += SPECIES.length()) { 2686 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2687 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 2688 VectorMask<Float> mv = av.lt(bv); 2689 2690 // Check results as part of computation. 2691 for (int j = 0; j < SPECIES.length(); j++) { 2692 Assert.assertEquals(mv.laneIsSet(j), a[i + j] < b[i + j]); 2693 } 2694 } 2695 } 2696 } 2697 2698 @Test(dataProvider = "floatCompareOpMaskProvider") 2699 static void LTFloatMaxVectorTestsMasked(IntFunction<float[]> fa, IntFunction<float[]> fb, 2700 IntFunction<boolean[]> fm) { 2701 float[] a = fa.apply(SPECIES.length()); 2702 float[] b = fb.apply(SPECIES.length()); 2703 boolean[] mask = fm.apply(SPECIES.length()); 2704 2705 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2706 2707 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2708 for (int i = 0; i < a.length; i += SPECIES.length()) { 2709 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2710 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 2711 VectorMask<Float> mv = av.compare(VectorOperators.LT, bv, vmask); 2712 2713 // Check results as part of computation. 2714 for (int j = 0; j < SPECIES.length(); j++) { 2715 Assert.assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] < b[i + j])); 2716 } 2717 } 2718 } 2719 } 2720 2721 2722 @Test(dataProvider = "floatCompareOpProvider") 2723 static void GTFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) { 2724 float[] a = fa.apply(SPECIES.length()); 2725 float[] b = fb.apply(SPECIES.length()); 2726 2727 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2728 for (int i = 0; i < a.length; i += SPECIES.length()) { 2729 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2730 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 2731 VectorMask<Float> mv = av.compare(VectorOperators.GT, bv); 2732 2733 // Check results as part of computation. 2734 for (int j = 0; j < SPECIES.length(); j++) { 2735 Assert.assertEquals(mv.laneIsSet(j), a[i + j] > b[i + j]); 2736 } 2737 } 2738 } 2739 } 2740 2741 @Test(dataProvider = "floatCompareOpMaskProvider") 2742 static void GTFloatMaxVectorTestsMasked(IntFunction<float[]> fa, IntFunction<float[]> fb, 2743 IntFunction<boolean[]> fm) { 2744 float[] a = fa.apply(SPECIES.length()); 2745 float[] b = fb.apply(SPECIES.length()); 2746 boolean[] mask = fm.apply(SPECIES.length()); 2747 2748 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2749 2750 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2751 for (int i = 0; i < a.length; i += SPECIES.length()) { 2752 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2753 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 2754 VectorMask<Float> mv = av.compare(VectorOperators.GT, bv, vmask); 2755 2756 // Check results as part of computation. 2757 for (int j = 0; j < SPECIES.length(); j++) { 2758 Assert.assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] > b[i + j])); 2759 } 2760 } 2761 } 2762 } 2763 2764 2765 @Test(dataProvider = "floatCompareOpProvider") 2766 static void EQFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) { 2767 float[] a = fa.apply(SPECIES.length()); 2768 float[] b = fb.apply(SPECIES.length()); 2769 2770 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2771 for (int i = 0; i < a.length; i += SPECIES.length()) { 2772 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2773 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 2774 VectorMask<Float> mv = av.compare(VectorOperators.EQ, bv); 2775 2776 // Check results as part of computation. 2777 for (int j = 0; j < SPECIES.length(); j++) { 2778 Assert.assertEquals(mv.laneIsSet(j), a[i + j] == b[i + j]); 2779 } 2780 } 2781 } 2782 } 2783 2784 2785 @Test(dataProvider = "floatCompareOpProvider") 2786 static void eqFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) { 2787 float[] a = fa.apply(SPECIES.length()); 2788 float[] b = fb.apply(SPECIES.length()); 2789 2790 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2791 for (int i = 0; i < a.length; i += SPECIES.length()) { 2792 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2793 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 2794 VectorMask<Float> mv = av.eq(bv); 2795 2796 // Check results as part of computation. 2797 for (int j = 0; j < SPECIES.length(); j++) { 2798 Assert.assertEquals(mv.laneIsSet(j), a[i + j] == b[i + j]); 2799 } 2800 } 2801 } 2802 } 2803 2804 @Test(dataProvider = "floatCompareOpMaskProvider") 2805 static void EQFloatMaxVectorTestsMasked(IntFunction<float[]> fa, IntFunction<float[]> fb, 2806 IntFunction<boolean[]> fm) { 2807 float[] a = fa.apply(SPECIES.length()); 2808 float[] b = fb.apply(SPECIES.length()); 2809 boolean[] mask = fm.apply(SPECIES.length()); 2810 2811 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2812 2813 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2814 for (int i = 0; i < a.length; i += SPECIES.length()) { 2815 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2816 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 2817 VectorMask<Float> mv = av.compare(VectorOperators.EQ, bv, vmask); 2818 2819 // Check results as part of computation. 2820 for (int j = 0; j < SPECIES.length(); j++) { 2821 Assert.assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] == b[i + j])); 2822 } 2823 } 2824 } 2825 } 2826 2827 2828 @Test(dataProvider = "floatCompareOpProvider") 2829 static void NEFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) { 2830 float[] a = fa.apply(SPECIES.length()); 2831 float[] b = fb.apply(SPECIES.length()); 2832 2833 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2834 for (int i = 0; i < a.length; i += SPECIES.length()) { 2835 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2836 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 2837 VectorMask<Float> mv = av.compare(VectorOperators.NE, bv); 2838 2839 // Check results as part of computation. 2840 for (int j = 0; j < SPECIES.length(); j++) { 2841 Assert.assertEquals(mv.laneIsSet(j), a[i + j] != b[i + j]); 2842 } 2843 } 2844 } 2845 } 2846 2847 @Test(dataProvider = "floatCompareOpMaskProvider") 2848 static void NEFloatMaxVectorTestsMasked(IntFunction<float[]> fa, IntFunction<float[]> fb, 2849 IntFunction<boolean[]> fm) { 2850 float[] a = fa.apply(SPECIES.length()); 2851 float[] b = fb.apply(SPECIES.length()); 2852 boolean[] mask = fm.apply(SPECIES.length()); 2853 2854 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2855 2856 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2857 for (int i = 0; i < a.length; i += SPECIES.length()) { 2858 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2859 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 2860 VectorMask<Float> mv = av.compare(VectorOperators.NE, bv, vmask); 2861 2862 // Check results as part of computation. 2863 for (int j = 0; j < SPECIES.length(); j++) { 2864 Assert.assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] != b[i + j])); 2865 } 2866 } 2867 } 2868 } 2869 2870 2871 @Test(dataProvider = "floatCompareOpProvider") 2872 static void LEFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) { 2873 float[] a = fa.apply(SPECIES.length()); 2874 float[] b = fb.apply(SPECIES.length()); 2875 2876 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2877 for (int i = 0; i < a.length; i += SPECIES.length()) { 2878 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2879 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 2880 VectorMask<Float> mv = av.compare(VectorOperators.LE, bv); 2881 2882 // Check results as part of computation. 2883 for (int j = 0; j < SPECIES.length(); j++) { 2884 Assert.assertEquals(mv.laneIsSet(j), a[i + j] <= b[i + j]); 2885 } 2886 } 2887 } 2888 } 2889 2890 @Test(dataProvider = "floatCompareOpMaskProvider") 2891 static void LEFloatMaxVectorTestsMasked(IntFunction<float[]> fa, IntFunction<float[]> fb, 2892 IntFunction<boolean[]> fm) { 2893 float[] a = fa.apply(SPECIES.length()); 2894 float[] b = fb.apply(SPECIES.length()); 2895 boolean[] mask = fm.apply(SPECIES.length()); 2896 2897 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2898 2899 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2900 for (int i = 0; i < a.length; i += SPECIES.length()) { 2901 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2902 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 2903 VectorMask<Float> mv = av.compare(VectorOperators.LE, bv, vmask); 2904 2905 // Check results as part of computation. 2906 for (int j = 0; j < SPECIES.length(); j++) { 2907 Assert.assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] <= b[i + j])); 2908 } 2909 } 2910 } 2911 } 2912 2913 2914 @Test(dataProvider = "floatCompareOpProvider") 2915 static void GEFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) { 2916 float[] a = fa.apply(SPECIES.length()); 2917 float[] b = fb.apply(SPECIES.length()); 2918 2919 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2920 for (int i = 0; i < a.length; i += SPECIES.length()) { 2921 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2922 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 2923 VectorMask<Float> mv = av.compare(VectorOperators.GE, bv); 2924 2925 // Check results as part of computation. 2926 for (int j = 0; j < SPECIES.length(); j++) { 2927 Assert.assertEquals(mv.laneIsSet(j), a[i + j] >= b[i + j]); 2928 } 2929 } 2930 } 2931 } 2932 2933 @Test(dataProvider = "floatCompareOpMaskProvider") 2934 static void GEFloatMaxVectorTestsMasked(IntFunction<float[]> fa, IntFunction<float[]> fb, 2935 IntFunction<boolean[]> fm) { 2936 float[] a = fa.apply(SPECIES.length()); 2937 float[] b = fb.apply(SPECIES.length()); 2938 boolean[] mask = fm.apply(SPECIES.length()); 2939 2940 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2941 2942 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2943 for (int i = 0; i < a.length; i += SPECIES.length()) { 2944 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2945 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 2946 VectorMask<Float> mv = av.compare(VectorOperators.GE, bv, vmask); 2947 2948 // Check results as part of computation. 2949 for (int j = 0; j < SPECIES.length(); j++) { 2950 Assert.assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] >= b[i + j])); 2951 } 2952 } 2953 } 2954 } 2955 2956 2957 @Test(dataProvider = "floatCompareOpProvider") 2958 static void LTFloatMaxVectorTestsBroadcastSmokeTest(IntFunction<float[]> fa, IntFunction<float[]> fb) { 2959 float[] a = fa.apply(SPECIES.length()); 2960 float[] b = fb.apply(SPECIES.length()); 2961 2962 for (int i = 0; i < a.length; i += SPECIES.length()) { 2963 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2964 VectorMask<Float> mv = av.compare(VectorOperators.LT, b[i]); 2965 2966 // Check results as part of computation. 2967 for (int j = 0; j < SPECIES.length(); j++) { 2968 Assert.assertEquals(mv.laneIsSet(j), a[i + j] < b[i]); 2969 } 2970 } 2971 } 2972 2973 2974 @Test(dataProvider = "floatCompareOpMaskProvider") 2975 static void LTFloatMaxVectorTestsBroadcastMaskedSmokeTest(IntFunction<float[]> fa, 2976 IntFunction<float[]> fb, IntFunction<boolean[]> fm) { 2977 float[] a = fa.apply(SPECIES.length()); 2978 float[] b = fb.apply(SPECIES.length()); 2979 boolean[] mask = fm.apply(SPECIES.length()); 2980 2981 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2982 2983 for (int i = 0; i < a.length; i += SPECIES.length()) { 2984 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2985 VectorMask<Float> mv = av.compare(VectorOperators.LT, b[i], vmask); 2986 2987 // Check results as part of computation. 2988 for (int j = 0; j < SPECIES.length(); j++) { 2989 Assert.assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] < b[i])); 2990 } 2991 } 2992 } 2993 2994 @Test(dataProvider = "floatCompareOpProvider") 2995 static void LTFloatMaxVectorTestsBroadcastLongSmokeTest(IntFunction<float[]> fa, IntFunction<float[]> fb) { 2996 float[] a = fa.apply(SPECIES.length()); 2997 float[] b = fb.apply(SPECIES.length()); 2998 2999 for (int i = 0; i < a.length; i += SPECIES.length()) { 3000 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 3001 VectorMask<Float> mv = av.compare(VectorOperators.LT, (long)b[i]); 3002 3003 // Check results as part of computation. 3004 for (int j = 0; j < SPECIES.length(); j++) { 3005 Assert.assertEquals(mv.laneIsSet(j), a[i + j] < (float)((long)b[i])); 3006 } 3007 } 3008 } 3009 3010 3011 @Test(dataProvider = "floatCompareOpMaskProvider") 3012 static void LTFloatMaxVectorTestsBroadcastLongMaskedSmokeTest(IntFunction<float[]> fa, 3013 IntFunction<float[]> fb, IntFunction<boolean[]> fm) { 3014 float[] a = fa.apply(SPECIES.length()); 3015 float[] b = fb.apply(SPECIES.length()); 3016 boolean[] mask = fm.apply(SPECIES.length()); 3017 3018 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3019 3020 for (int i = 0; i < a.length; i += SPECIES.length()) { 3021 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 3022 VectorMask<Float> mv = av.compare(VectorOperators.LT, (long)b[i], vmask); 3023 3024 // Check results as part of computation. 3025 for (int j = 0; j < SPECIES.length(); j++) { 3026 Assert.assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] < (float)((long)b[i]))); 3027 } 3028 } 3029 } 3030 3031 @Test(dataProvider = "floatCompareOpProvider") 3032 static void EQFloatMaxVectorTestsBroadcastSmokeTest(IntFunction<float[]> fa, IntFunction<float[]> fb) { 3033 float[] a = fa.apply(SPECIES.length()); 3034 float[] b = fb.apply(SPECIES.length()); 3035 3036 for (int i = 0; i < a.length; i += SPECIES.length()) { 3037 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 3038 VectorMask<Float> mv = av.compare(VectorOperators.EQ, b[i]); 3039 3040 // Check results as part of computation. 3041 for (int j = 0; j < SPECIES.length(); j++) { 3042 Assert.assertEquals(mv.laneIsSet(j), a[i + j] == b[i]); 3043 } 3044 } 3045 } 3046 3047 3048 @Test(dataProvider = "floatCompareOpMaskProvider") 3049 static void EQFloatMaxVectorTestsBroadcastMaskedSmokeTest(IntFunction<float[]> fa, 3050 IntFunction<float[]> fb, IntFunction<boolean[]> fm) { 3051 float[] a = fa.apply(SPECIES.length()); 3052 float[] b = fb.apply(SPECIES.length()); 3053 boolean[] mask = fm.apply(SPECIES.length()); 3054 3055 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3056 3057 for (int i = 0; i < a.length; i += SPECIES.length()) { 3058 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 3059 VectorMask<Float> mv = av.compare(VectorOperators.EQ, b[i], vmask); 3060 3061 // Check results as part of computation. 3062 for (int j = 0; j < SPECIES.length(); j++) { 3063 Assert.assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] == b[i])); 3064 } 3065 } 3066 } 3067 3068 @Test(dataProvider = "floatCompareOpProvider") 3069 static void EQFloatMaxVectorTestsBroadcastLongSmokeTest(IntFunction<float[]> fa, IntFunction<float[]> fb) { 3070 float[] a = fa.apply(SPECIES.length()); 3071 float[] b = fb.apply(SPECIES.length()); 3072 3073 for (int i = 0; i < a.length; i += SPECIES.length()) { 3074 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 3075 VectorMask<Float> mv = av.compare(VectorOperators.EQ, (long)b[i]); 3076 3077 // Check results as part of computation. 3078 for (int j = 0; j < SPECIES.length(); j++) { 3079 Assert.assertEquals(mv.laneIsSet(j), a[i + j] == (float)((long)b[i])); 3080 } 3081 } 3082 } 3083 3084 3085 @Test(dataProvider = "floatCompareOpMaskProvider") 3086 static void EQFloatMaxVectorTestsBroadcastLongMaskedSmokeTest(IntFunction<float[]> fa, 3087 IntFunction<float[]> fb, IntFunction<boolean[]> fm) { 3088 float[] a = fa.apply(SPECIES.length()); 3089 float[] b = fb.apply(SPECIES.length()); 3090 boolean[] mask = fm.apply(SPECIES.length()); 3091 3092 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3093 3094 for (int i = 0; i < a.length; i += SPECIES.length()) { 3095 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 3096 VectorMask<Float> mv = av.compare(VectorOperators.EQ, (long)b[i], vmask); 3097 3098 // Check results as part of computation. 3099 for (int j = 0; j < SPECIES.length(); j++) { 3100 Assert.assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] == (float)((long)b[i]))); 3101 } 3102 } 3103 } 3104 3105 static float blend(float a, float b, boolean mask) { 3106 return mask ? b : a; 3107 } 3108 3109 @Test(dataProvider = "floatBinaryOpMaskProvider") 3110 static void blendFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb, 3111 IntFunction<boolean[]> fm) { 3112 float[] a = fa.apply(SPECIES.length()); 3113 float[] b = fb.apply(SPECIES.length()); 3114 float[] r = fr.apply(SPECIES.length()); 3115 boolean[] mask = fm.apply(SPECIES.length()); 3116 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3117 3118 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3119 for (int i = 0; i < a.length; i += SPECIES.length()) { 3120 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 3121 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 3122 av.blend(bv, vmask).intoArray(r, i); 3123 } 3124 } 3125 3126 assertArraysEquals(a, b, r, mask, FloatMaxVectorTests::blend); 3127 } 3128 3129 @Test(dataProvider = "floatUnaryOpShuffleProvider") 3130 static void RearrangeFloatMaxVectorTests(IntFunction<float[]> fa, 3131 BiFunction<Integer,Integer,int[]> fs) { 3132 float[] a = fa.apply(SPECIES.length()); 3133 int[] order = fs.apply(a.length, SPECIES.length()); 3134 float[] r = fr.apply(SPECIES.length()); 3135 3136 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3137 for (int i = 0; i < a.length; i += SPECIES.length()) { 3138 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 3139 av.rearrange(VectorShuffle.fromArray(SPECIES, order, i)).intoArray(r, i); 3140 } 3141 } 3142 3143 assertRearrangeArraysEquals(a, r, order, SPECIES.length()); 3144 } 3145 3146 @Test(dataProvider = "floatUnaryOpShuffleMaskProvider") 3147 static void RearrangeFloatMaxVectorTestsMaskedSmokeTest(IntFunction<float[]> fa, 3148 BiFunction<Integer,Integer,int[]> fs, 3149 IntFunction<boolean[]> fm) { 3150 float[] a = fa.apply(SPECIES.length()); 3151 int[] order = fs.apply(a.length, SPECIES.length()); 3152 float[] r = fr.apply(SPECIES.length()); 3153 boolean[] mask = fm.apply(SPECIES.length()); 3154 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3155 3156 for (int i = 0; i < a.length; i += SPECIES.length()) { 3157 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 3158 av.rearrange(VectorShuffle.fromArray(SPECIES, order, i), vmask).intoArray(r, i); 3159 } 3160 3161 assertRearrangeArraysEquals(a, r, order, mask, SPECIES.length()); 3162 } 3163 @Test(dataProvider = "floatUnaryOpProvider") 3164 static void getFloatMaxVectorTests(IntFunction<float[]> fa) { 3165 float[] a = fa.apply(SPECIES.length()); 3166 float[] r = fr.apply(SPECIES.length()); 3167 3168 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3169 for (int i = 0; i < a.length; i += SPECIES.length()) { 3170 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 3171 int num_lanes = SPECIES.length(); 3172 // Manually unroll because full unroll happens after intrinsification. 3173 // Unroll is needed because get intrinsic requires for index to be a known constant. 3174 if (num_lanes == 1) { 3175 r[i]=av.lane(0); 3176 } else if (num_lanes == 2) { 3177 r[i]=av.lane(0); 3178 r[i+1]=av.lane(1); 3179 } else if (num_lanes == 4) { 3180 r[i]=av.lane(0); 3181 r[i+1]=av.lane(1); 3182 r[i+2]=av.lane(2); 3183 r[i+3]=av.lane(3); 3184 } else if (num_lanes == 8) { 3185 r[i]=av.lane(0); 3186 r[i+1]=av.lane(1); 3187 r[i+2]=av.lane(2); 3188 r[i+3]=av.lane(3); 3189 r[i+4]=av.lane(4); 3190 r[i+5]=av.lane(5); 3191 r[i+6]=av.lane(6); 3192 r[i+7]=av.lane(7); 3193 } else if (num_lanes == 16) { 3194 r[i]=av.lane(0); 3195 r[i+1]=av.lane(1); 3196 r[i+2]=av.lane(2); 3197 r[i+3]=av.lane(3); 3198 r[i+4]=av.lane(4); 3199 r[i+5]=av.lane(5); 3200 r[i+6]=av.lane(6); 3201 r[i+7]=av.lane(7); 3202 r[i+8]=av.lane(8); 3203 r[i+9]=av.lane(9); 3204 r[i+10]=av.lane(10); 3205 r[i+11]=av.lane(11); 3206 r[i+12]=av.lane(12); 3207 r[i+13]=av.lane(13); 3208 r[i+14]=av.lane(14); 3209 r[i+15]=av.lane(15); 3210 } else if (num_lanes == 32) { 3211 r[i]=av.lane(0); 3212 r[i+1]=av.lane(1); 3213 r[i+2]=av.lane(2); 3214 r[i+3]=av.lane(3); 3215 r[i+4]=av.lane(4); 3216 r[i+5]=av.lane(5); 3217 r[i+6]=av.lane(6); 3218 r[i+7]=av.lane(7); 3219 r[i+8]=av.lane(8); 3220 r[i+9]=av.lane(9); 3221 r[i+10]=av.lane(10); 3222 r[i+11]=av.lane(11); 3223 r[i+12]=av.lane(12); 3224 r[i+13]=av.lane(13); 3225 r[i+14]=av.lane(14); 3226 r[i+15]=av.lane(15); 3227 r[i+16]=av.lane(16); 3228 r[i+17]=av.lane(17); 3229 r[i+18]=av.lane(18); 3230 r[i+19]=av.lane(19); 3231 r[i+20]=av.lane(20); 3232 r[i+21]=av.lane(21); 3233 r[i+22]=av.lane(22); 3234 r[i+23]=av.lane(23); 3235 r[i+24]=av.lane(24); 3236 r[i+25]=av.lane(25); 3237 r[i+26]=av.lane(26); 3238 r[i+27]=av.lane(27); 3239 r[i+28]=av.lane(28); 3240 r[i+29]=av.lane(29); 3241 r[i+30]=av.lane(30); 3242 r[i+31]=av.lane(31); 3243 } else if (num_lanes == 64) { 3244 r[i]=av.lane(0); 3245 r[i+1]=av.lane(1); 3246 r[i+2]=av.lane(2); 3247 r[i+3]=av.lane(3); 3248 r[i+4]=av.lane(4); 3249 r[i+5]=av.lane(5); 3250 r[i+6]=av.lane(6); 3251 r[i+7]=av.lane(7); 3252 r[i+8]=av.lane(8); 3253 r[i+9]=av.lane(9); 3254 r[i+10]=av.lane(10); 3255 r[i+11]=av.lane(11); 3256 r[i+12]=av.lane(12); 3257 r[i+13]=av.lane(13); 3258 r[i+14]=av.lane(14); 3259 r[i+15]=av.lane(15); 3260 r[i+16]=av.lane(16); 3261 r[i+17]=av.lane(17); 3262 r[i+18]=av.lane(18); 3263 r[i+19]=av.lane(19); 3264 r[i+20]=av.lane(20); 3265 r[i+21]=av.lane(21); 3266 r[i+22]=av.lane(22); 3267 r[i+23]=av.lane(23); 3268 r[i+24]=av.lane(24); 3269 r[i+25]=av.lane(25); 3270 r[i+26]=av.lane(26); 3271 r[i+27]=av.lane(27); 3272 r[i+28]=av.lane(28); 3273 r[i+29]=av.lane(29); 3274 r[i+30]=av.lane(30); 3275 r[i+31]=av.lane(31); 3276 r[i+32]=av.lane(32); 3277 r[i+33]=av.lane(33); 3278 r[i+34]=av.lane(34); 3279 r[i+35]=av.lane(35); 3280 r[i+36]=av.lane(36); 3281 r[i+37]=av.lane(37); 3282 r[i+38]=av.lane(38); 3283 r[i+39]=av.lane(39); 3284 r[i+40]=av.lane(40); 3285 r[i+41]=av.lane(41); 3286 r[i+42]=av.lane(42); 3287 r[i+43]=av.lane(43); 3288 r[i+44]=av.lane(44); 3289 r[i+45]=av.lane(45); 3290 r[i+46]=av.lane(46); 3291 r[i+47]=av.lane(47); 3292 r[i+48]=av.lane(48); 3293 r[i+49]=av.lane(49); 3294 r[i+50]=av.lane(50); 3295 r[i+51]=av.lane(51); 3296 r[i+52]=av.lane(52); 3297 r[i+53]=av.lane(53); 3298 r[i+54]=av.lane(54); 3299 r[i+55]=av.lane(55); 3300 r[i+56]=av.lane(56); 3301 r[i+57]=av.lane(57); 3302 r[i+58]=av.lane(58); 3303 r[i+59]=av.lane(59); 3304 r[i+60]=av.lane(60); 3305 r[i+61]=av.lane(61); 3306 r[i+62]=av.lane(62); 3307 r[i+63]=av.lane(63); 3308 } else { 3309 for (int j = 0; j < SPECIES.length(); j++) { 3310 r[i+j]=av.lane(j); 3311 } 3312 } 3313 } 3314 } 3315 3316 assertArraysEquals(a, r, FloatMaxVectorTests::get); 3317 } 3318 3319 @Test(dataProvider = "floatUnaryOpProvider") 3320 static void BroadcastFloatMaxVectorTests(IntFunction<float[]> fa) { 3321 float[] a = fa.apply(SPECIES.length()); 3322 float[] r = new float[a.length]; 3323 3324 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3325 for (int i = 0; i < a.length; i += SPECIES.length()) { 3326 FloatVector.broadcast(SPECIES, a[i]).intoArray(r, i); 3327 } 3328 } 3329 3330 assertBroadcastArraysEquals(a, r); 3331 } 3332 3333 3334 3335 3336 3337 @Test(dataProvider = "floatUnaryOpProvider") 3338 static void ZeroFloatMaxVectorTests(IntFunction<float[]> fa) { 3339 float[] a = fa.apply(SPECIES.length()); 3340 float[] r = new float[a.length]; 3341 3342 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3343 for (int i = 0; i < a.length; i += SPECIES.length()) { 3344 FloatVector.zero(SPECIES).intoArray(a, i); 3345 } 3346 } 3347 3348 Assert.assertEquals(a, r); 3349 } 3350 3351 3352 3353 3354 static float[] sliceUnary(float[] a, int origin, int idx) { 3355 float[] res = new float[SPECIES.length()]; 3356 for (int i = 0; i < SPECIES.length(); i++){ 3357 if(i+origin < SPECIES.length()) 3358 res[i] = a[idx+i+origin]; 3359 else 3360 res[i] = (float)0; 3361 } 3362 return res; 3363 } 3364 3365 @Test(dataProvider = "floatUnaryOpProvider") 3366 static void sliceUnaryFloatMaxVectorTests(IntFunction<float[]> fa) { 3367 float[] a = fa.apply(SPECIES.length()); 3368 float[] r = new float[a.length]; 3369 int origin = (new java.util.Random()).nextInt(SPECIES.length()); 3370 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3371 for (int i = 0; i < a.length; i += SPECIES.length()) { 3372 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 3373 av.slice(origin).intoArray(r, i); 3374 } 3375 } 3376 3377 assertArraysEquals(a, r, origin, FloatMaxVectorTests::sliceUnary); 3378 } 3379 static float[] sliceBinary(float[] a, float[] b, int origin, int idx) { 3380 float[] res = new float[SPECIES.length()]; 3381 for (int i = 0, j = 0; i < SPECIES.length(); i++){ 3382 if(i+origin < SPECIES.length()) 3383 res[i] = a[idx+i+origin]; 3384 else { 3385 res[i] = b[idx+j]; 3386 j++; 3387 } 3388 } 3389 return res; 3390 } 3391 3392 @Test(dataProvider = "floatBinaryOpProvider") 3393 static void sliceBinaryFloatMaxVectorTestsBinary(IntFunction<float[]> fa, IntFunction<float[]> fb) { 3394 float[] a = fa.apply(SPECIES.length()); 3395 float[] b = fb.apply(SPECIES.length()); 3396 float[] r = new float[a.length]; 3397 int origin = (new java.util.Random()).nextInt(SPECIES.length()); 3398 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3399 for (int i = 0; i < a.length; i += SPECIES.length()) { 3400 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 3401 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 3402 av.slice(origin, bv).intoArray(r, i); 3403 } 3404 } 3405 3406 assertArraysEquals(a, b, r, origin, FloatMaxVectorTests::sliceBinary); 3407 } 3408 static float[] slice(float[] a, float[] b, int origin, boolean[] mask, int idx) { 3409 float[] res = new float[SPECIES.length()]; 3410 for (int i = 0, j = 0; i < SPECIES.length(); i++){ 3411 if(i+origin < SPECIES.length()) 3412 res[i] = mask[i] ? a[idx+i+origin] : (float)0; 3413 else { 3414 res[i] = mask[i] ? b[idx+j] : (float)0; 3415 j++; 3416 } 3417 } 3418 return res; 3419 } 3420 3421 @Test(dataProvider = "floatBinaryOpMaskProvider") 3422 static void sliceFloatMaxVectorTestsMasked(IntFunction<float[]> fa, IntFunction<float[]> fb, 3423 IntFunction<boolean[]> fm) { 3424 float[] a = fa.apply(SPECIES.length()); 3425 float[] b = fb.apply(SPECIES.length()); 3426 boolean[] mask = fm.apply(SPECIES.length()); 3427 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3428 3429 float[] r = new float[a.length]; 3430 int origin = (new java.util.Random()).nextInt(SPECIES.length()); 3431 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3432 for (int i = 0; i < a.length; i += SPECIES.length()) { 3433 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 3434 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 3435 av.slice(origin, bv, vmask).intoArray(r, i); 3436 } 3437 } 3438 3439 assertArraysEquals(a, b, r, origin, mask, FloatMaxVectorTests::slice); 3440 } 3441 static float[] unsliceUnary(float[] a, int origin, int idx) { 3442 float[] res = new float[SPECIES.length()]; 3443 for (int i = 0, j = 0; i < SPECIES.length(); i++){ 3444 if(i < origin) 3445 res[i] = (float)0; 3446 else { 3447 res[i] = a[idx+j]; 3448 j++; 3449 } 3450 } 3451 return res; 3452 } 3453 3454 @Test(dataProvider = "floatUnaryOpProvider") 3455 static void unsliceUnaryFloatMaxVectorTests(IntFunction<float[]> fa) { 3456 float[] a = fa.apply(SPECIES.length()); 3457 float[] r = new float[a.length]; 3458 int origin = (new java.util.Random()).nextInt(SPECIES.length()); 3459 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3460 for (int i = 0; i < a.length; i += SPECIES.length()) { 3461 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 3462 av.unslice(origin).intoArray(r, i); 3463 } 3464 } 3465 3466 assertArraysEquals(a, r, origin, FloatMaxVectorTests::unsliceUnary); 3467 } 3468 static float[] unsliceBinary(float[] a, float[] b, int origin, int part, int idx) { 3469 float[] res = new float[SPECIES.length()]; 3470 for (int i = 0, j = 0; i < SPECIES.length(); i++){ 3471 if (part == 0) { 3472 if (i < origin) 3473 res[i] = b[idx+i]; 3474 else { 3475 res[i] = a[idx+j]; 3476 j++; 3477 } 3478 } else if (part == 1) { 3479 if (i < origin) 3480 res[i] = a[idx+SPECIES.length()-origin+i]; 3481 else { 3482 res[i] = b[idx+origin+j]; 3483 j++; 3484 } 3485 } 3486 } 3487 return res; 3488 } 3489 3490 @Test(dataProvider = "floatBinaryOpProvider") 3491 static void unsliceBinaryFloatMaxVectorTestsBinary(IntFunction<float[]> fa, IntFunction<float[]> fb) { 3492 float[] a = fa.apply(SPECIES.length()); 3493 float[] b = fb.apply(SPECIES.length()); 3494 float[] r = new float[a.length]; 3495 int origin = (new java.util.Random()).nextInt(SPECIES.length()); 3496 int part = (new java.util.Random()).nextInt(2); 3497 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3498 for (int i = 0; i < a.length; i += SPECIES.length()) { 3499 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 3500 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 3501 av.unslice(origin, bv, part).intoArray(r, i); 3502 } 3503 } 3504 3505 assertArraysEquals(a, b, r, origin, part, FloatMaxVectorTests::unsliceBinary); 3506 } 3507 static float[] unslice(float[] a, float[] b, int origin, int part, boolean[] mask, int idx) { 3508 float[] res = new float[SPECIES.length()]; 3509 for (int i = 0, j = 0; i < SPECIES.length(); i++){ 3510 if(i+origin < SPECIES.length()) 3511 res[i] = b[idx+i+origin]; 3512 else { 3513 res[i] = b[idx+j]; 3514 j++; 3515 } 3516 } 3517 for (int i = 0; i < SPECIES.length(); i++){ 3518 res[i] = mask[i] ? a[idx+i] : res[i]; 3519 } 3520 float[] res1 = new float[SPECIES.length()]; 3521 if (part == 0) { 3522 for (int i = 0, j = 0; i < SPECIES.length(); i++){ 3523 if (i < origin) 3524 res1[i] = b[idx+i]; 3525 else { 3526 res1[i] = res[j]; 3527 j++; 3528 } 3529 } 3530 } else if (part == 1) { 3531 for (int i = 0, j = 0; i < SPECIES.length(); i++){ 3532 if (i < origin) 3533 res1[i] = res[SPECIES.length()-origin+i]; 3534 else { 3535 res1[i] = b[idx+origin+j]; 3536 j++; 3537 } 3538 } 3539 } 3540 return res1; 3541 } 3542 3543 @Test(dataProvider = "floatBinaryOpMaskProvider") 3544 static void unsliceFloatMaxVectorTestsMasked(IntFunction<float[]> fa, IntFunction<float[]> fb, 3545 IntFunction<boolean[]> fm) { 3546 float[] a = fa.apply(SPECIES.length()); 3547 float[] b = fb.apply(SPECIES.length()); 3548 boolean[] mask = fm.apply(SPECIES.length()); 3549 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3550 float[] r = new float[a.length]; 3551 int origin = (new java.util.Random()).nextInt(SPECIES.length()); 3552 int part = (new java.util.Random()).nextInt(2); 3553 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3554 for (int i = 0; i < a.length; i += SPECIES.length()) { 3555 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 3556 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 3557 av.unslice(origin, bv, part, vmask).intoArray(r, i); 3558 } 3559 } 3560 3561 assertArraysEquals(a, b, r, origin, part, mask, FloatMaxVectorTests::unslice); 3562 } 3563 3564 static float SIN(float a) { 3565 return (float)(Math.sin((double)a)); 3566 } 3567 3568 static float strictSIN(float a) { 3569 return (float)(StrictMath.sin((double)a)); 3570 } 3571 3572 @Test(dataProvider = "floatUnaryOpProvider") 3573 static void SINFloatMaxVectorTests(IntFunction<float[]> fa) { 3574 float[] a = fa.apply(SPECIES.length()); 3575 float[] r = fr.apply(SPECIES.length()); 3576 3577 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3578 for (int i = 0; i < a.length; i += SPECIES.length()) { 3579 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 3580 av.lanewise(VectorOperators.SIN).intoArray(r, i); 3581 } 3582 } 3583 3584 assertArraysEqualsWithinOneUlp(a, r, FloatMaxVectorTests::SIN, FloatMaxVectorTests::strictSIN); 3585 } 3586 3587 3588 static float EXP(float a) { 3589 return (float)(Math.exp((double)a)); 3590 } 3591 3592 static float strictEXP(float a) { 3593 return (float)(StrictMath.exp((double)a)); 3594 } 3595 3596 @Test(dataProvider = "floatUnaryOpProvider") 3597 static void EXPFloatMaxVectorTests(IntFunction<float[]> fa) { 3598 float[] a = fa.apply(SPECIES.length()); 3599 float[] r = fr.apply(SPECIES.length()); 3600 3601 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3602 for (int i = 0; i < a.length; i += SPECIES.length()) { 3603 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 3604 av.lanewise(VectorOperators.EXP).intoArray(r, i); 3605 } 3606 } 3607 3608 assertArraysEqualsWithinOneUlp(a, r, FloatMaxVectorTests::EXP, FloatMaxVectorTests::strictEXP); 3609 } 3610 3611 3612 static float LOG1P(float a) { 3613 return (float)(Math.log1p((double)a)); 3614 } 3615 3616 static float strictLOG1P(float a) { 3617 return (float)(StrictMath.log1p((double)a)); 3618 } 3619 3620 @Test(dataProvider = "floatUnaryOpProvider") 3621 static void LOG1PFloatMaxVectorTests(IntFunction<float[]> fa) { 3622 float[] a = fa.apply(SPECIES.length()); 3623 float[] r = fr.apply(SPECIES.length()); 3624 3625 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3626 for (int i = 0; i < a.length; i += SPECIES.length()) { 3627 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 3628 av.lanewise(VectorOperators.LOG1P).intoArray(r, i); 3629 } 3630 } 3631 3632 assertArraysEqualsWithinOneUlp(a, r, FloatMaxVectorTests::LOG1P, FloatMaxVectorTests::strictLOG1P); 3633 } 3634 3635 3636 static float LOG(float a) { 3637 return (float)(Math.log((double)a)); 3638 } 3639 3640 static float strictLOG(float a) { 3641 return (float)(StrictMath.log((double)a)); 3642 } 3643 3644 @Test(dataProvider = "floatUnaryOpProvider") 3645 static void LOGFloatMaxVectorTests(IntFunction<float[]> fa) { 3646 float[] a = fa.apply(SPECIES.length()); 3647 float[] r = fr.apply(SPECIES.length()); 3648 3649 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3650 for (int i = 0; i < a.length; i += SPECIES.length()) { 3651 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 3652 av.lanewise(VectorOperators.LOG).intoArray(r, i); 3653 } 3654 } 3655 3656 assertArraysEqualsWithinOneUlp(a, r, FloatMaxVectorTests::LOG, FloatMaxVectorTests::strictLOG); 3657 } 3658 3659 3660 static float LOG10(float a) { 3661 return (float)(Math.log10((double)a)); 3662 } 3663 3664 static float strictLOG10(float a) { 3665 return (float)(StrictMath.log10((double)a)); 3666 } 3667 3668 @Test(dataProvider = "floatUnaryOpProvider") 3669 static void LOG10FloatMaxVectorTests(IntFunction<float[]> fa) { 3670 float[] a = fa.apply(SPECIES.length()); 3671 float[] r = fr.apply(SPECIES.length()); 3672 3673 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3674 for (int i = 0; i < a.length; i += SPECIES.length()) { 3675 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 3676 av.lanewise(VectorOperators.LOG10).intoArray(r, i); 3677 } 3678 } 3679 3680 assertArraysEqualsWithinOneUlp(a, r, FloatMaxVectorTests::LOG10, FloatMaxVectorTests::strictLOG10); 3681 } 3682 3683 3684 static float EXPM1(float a) { 3685 return (float)(Math.expm1((double)a)); 3686 } 3687 3688 static float strictEXPM1(float a) { 3689 return (float)(StrictMath.expm1((double)a)); 3690 } 3691 3692 @Test(dataProvider = "floatUnaryOpProvider") 3693 static void EXPM1FloatMaxVectorTests(IntFunction<float[]> fa) { 3694 float[] a = fa.apply(SPECIES.length()); 3695 float[] r = fr.apply(SPECIES.length()); 3696 3697 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3698 for (int i = 0; i < a.length; i += SPECIES.length()) { 3699 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 3700 av.lanewise(VectorOperators.EXPM1).intoArray(r, i); 3701 } 3702 } 3703 3704 assertArraysEqualsWithinOneUlp(a, r, FloatMaxVectorTests::EXPM1, FloatMaxVectorTests::strictEXPM1); 3705 } 3706 3707 3708 static float COS(float a) { 3709 return (float)(Math.cos((double)a)); 3710 } 3711 3712 static float strictCOS(float a) { 3713 return (float)(StrictMath.cos((double)a)); 3714 } 3715 3716 @Test(dataProvider = "floatUnaryOpProvider") 3717 static void COSFloatMaxVectorTests(IntFunction<float[]> fa) { 3718 float[] a = fa.apply(SPECIES.length()); 3719 float[] r = fr.apply(SPECIES.length()); 3720 3721 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3722 for (int i = 0; i < a.length; i += SPECIES.length()) { 3723 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 3724 av.lanewise(VectorOperators.COS).intoArray(r, i); 3725 } 3726 } 3727 3728 assertArraysEqualsWithinOneUlp(a, r, FloatMaxVectorTests::COS, FloatMaxVectorTests::strictCOS); 3729 } 3730 3731 3732 static float TAN(float a) { 3733 return (float)(Math.tan((double)a)); 3734 } 3735 3736 static float strictTAN(float a) { 3737 return (float)(StrictMath.tan((double)a)); 3738 } 3739 3740 @Test(dataProvider = "floatUnaryOpProvider") 3741 static void TANFloatMaxVectorTests(IntFunction<float[]> fa) { 3742 float[] a = fa.apply(SPECIES.length()); 3743 float[] r = fr.apply(SPECIES.length()); 3744 3745 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3746 for (int i = 0; i < a.length; i += SPECIES.length()) { 3747 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 3748 av.lanewise(VectorOperators.TAN).intoArray(r, i); 3749 } 3750 } 3751 3752 assertArraysEqualsWithinOneUlp(a, r, FloatMaxVectorTests::TAN, FloatMaxVectorTests::strictTAN); 3753 } 3754 3755 3756 static float SINH(float a) { 3757 return (float)(Math.sinh((double)a)); 3758 } 3759 3760 static float strictSINH(float a) { 3761 return (float)(StrictMath.sinh((double)a)); 3762 } 3763 3764 @Test(dataProvider = "floatUnaryOpProvider") 3765 static void SINHFloatMaxVectorTests(IntFunction<float[]> fa) { 3766 float[] a = fa.apply(SPECIES.length()); 3767 float[] r = fr.apply(SPECIES.length()); 3768 3769 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3770 for (int i = 0; i < a.length; i += SPECIES.length()) { 3771 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 3772 av.lanewise(VectorOperators.SINH).intoArray(r, i); 3773 } 3774 } 3775 3776 assertArraysEqualsWithinOneUlp(a, r, FloatMaxVectorTests::SINH, FloatMaxVectorTests::strictSINH); 3777 } 3778 3779 3780 static float COSH(float a) { 3781 return (float)(Math.cosh((double)a)); 3782 } 3783 3784 static float strictCOSH(float a) { 3785 return (float)(StrictMath.cosh((double)a)); 3786 } 3787 3788 @Test(dataProvider = "floatUnaryOpProvider") 3789 static void COSHFloatMaxVectorTests(IntFunction<float[]> fa) { 3790 float[] a = fa.apply(SPECIES.length()); 3791 float[] r = fr.apply(SPECIES.length()); 3792 3793 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3794 for (int i = 0; i < a.length; i += SPECIES.length()) { 3795 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 3796 av.lanewise(VectorOperators.COSH).intoArray(r, i); 3797 } 3798 } 3799 3800 assertArraysEqualsWithinOneUlp(a, r, FloatMaxVectorTests::COSH, FloatMaxVectorTests::strictCOSH); 3801 } 3802 3803 3804 static float TANH(float a) { 3805 return (float)(Math.tanh((double)a)); 3806 } 3807 3808 static float strictTANH(float a) { 3809 return (float)(StrictMath.tanh((double)a)); 3810 } 3811 3812 @Test(dataProvider = "floatUnaryOpProvider") 3813 static void TANHFloatMaxVectorTests(IntFunction<float[]> fa) { 3814 float[] a = fa.apply(SPECIES.length()); 3815 float[] r = fr.apply(SPECIES.length()); 3816 3817 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3818 for (int i = 0; i < a.length; i += SPECIES.length()) { 3819 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 3820 av.lanewise(VectorOperators.TANH).intoArray(r, i); 3821 } 3822 } 3823 3824 assertArraysEqualsWithinOneUlp(a, r, FloatMaxVectorTests::TANH, FloatMaxVectorTests::strictTANH); 3825 } 3826 3827 3828 static float ASIN(float a) { 3829 return (float)(Math.asin((double)a)); 3830 } 3831 3832 static float strictASIN(float a) { 3833 return (float)(StrictMath.asin((double)a)); 3834 } 3835 3836 @Test(dataProvider = "floatUnaryOpProvider") 3837 static void ASINFloatMaxVectorTests(IntFunction<float[]> fa) { 3838 float[] a = fa.apply(SPECIES.length()); 3839 float[] r = fr.apply(SPECIES.length()); 3840 3841 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3842 for (int i = 0; i < a.length; i += SPECIES.length()) { 3843 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 3844 av.lanewise(VectorOperators.ASIN).intoArray(r, i); 3845 } 3846 } 3847 3848 assertArraysEqualsWithinOneUlp(a, r, FloatMaxVectorTests::ASIN, FloatMaxVectorTests::strictASIN); 3849 } 3850 3851 3852 static float ACOS(float a) { 3853 return (float)(Math.acos((double)a)); 3854 } 3855 3856 static float strictACOS(float a) { 3857 return (float)(StrictMath.acos((double)a)); 3858 } 3859 3860 @Test(dataProvider = "floatUnaryOpProvider") 3861 static void ACOSFloatMaxVectorTests(IntFunction<float[]> fa) { 3862 float[] a = fa.apply(SPECIES.length()); 3863 float[] r = fr.apply(SPECIES.length()); 3864 3865 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3866 for (int i = 0; i < a.length; i += SPECIES.length()) { 3867 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 3868 av.lanewise(VectorOperators.ACOS).intoArray(r, i); 3869 } 3870 } 3871 3872 assertArraysEqualsWithinOneUlp(a, r, FloatMaxVectorTests::ACOS, FloatMaxVectorTests::strictACOS); 3873 } 3874 3875 3876 static float ATAN(float a) { 3877 return (float)(Math.atan((double)a)); 3878 } 3879 3880 static float strictATAN(float a) { 3881 return (float)(StrictMath.atan((double)a)); 3882 } 3883 3884 @Test(dataProvider = "floatUnaryOpProvider") 3885 static void ATANFloatMaxVectorTests(IntFunction<float[]> fa) { 3886 float[] a = fa.apply(SPECIES.length()); 3887 float[] r = fr.apply(SPECIES.length()); 3888 3889 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3890 for (int i = 0; i < a.length; i += SPECIES.length()) { 3891 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 3892 av.lanewise(VectorOperators.ATAN).intoArray(r, i); 3893 } 3894 } 3895 3896 assertArraysEqualsWithinOneUlp(a, r, FloatMaxVectorTests::ATAN, FloatMaxVectorTests::strictATAN); 3897 } 3898 3899 3900 static float CBRT(float a) { 3901 return (float)(Math.cbrt((double)a)); 3902 } 3903 3904 static float strictCBRT(float a) { 3905 return (float)(StrictMath.cbrt((double)a)); 3906 } 3907 3908 @Test(dataProvider = "floatUnaryOpProvider") 3909 static void CBRTFloatMaxVectorTests(IntFunction<float[]> fa) { 3910 float[] a = fa.apply(SPECIES.length()); 3911 float[] r = fr.apply(SPECIES.length()); 3912 3913 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3914 for (int i = 0; i < a.length; i += SPECIES.length()) { 3915 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 3916 av.lanewise(VectorOperators.CBRT).intoArray(r, i); 3917 } 3918 } 3919 3920 assertArraysEqualsWithinOneUlp(a, r, FloatMaxVectorTests::CBRT, FloatMaxVectorTests::strictCBRT); 3921 } 3922 3923 3924 static float HYPOT(float a, float b) { 3925 return (float)(Math.hypot((double)a, (double)b)); 3926 } 3927 3928 static float strictHYPOT(float a, float b) { 3929 return (float)(StrictMath.hypot((double)a, (double)b)); 3930 } 3931 3932 @Test(dataProvider = "floatBinaryOpProvider") 3933 static void HYPOTFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) { 3934 float[] a = fa.apply(SPECIES.length()); 3935 float[] b = fb.apply(SPECIES.length()); 3936 float[] r = fr.apply(SPECIES.length()); 3937 3938 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3939 for (int i = 0; i < a.length; i += SPECIES.length()) { 3940 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 3941 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 3942 av.lanewise(VectorOperators.HYPOT, bv).intoArray(r, i); 3943 } 3944 } 3945 3946 assertArraysEqualsWithinOneUlp(a, b, r, FloatMaxVectorTests::HYPOT, FloatMaxVectorTests::strictHYPOT); 3947 } 3948 3949 3950 3951 static float POW(float a, float b) { 3952 return (float)(Math.pow((double)a, (double)b)); 3953 } 3954 3955 static float strictPOW(float a, float b) { 3956 return (float)(StrictMath.pow((double)a, (double)b)); 3957 } 3958 3959 @Test(dataProvider = "floatBinaryOpProvider") 3960 static void POWFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) { 3961 float[] a = fa.apply(SPECIES.length()); 3962 float[] b = fb.apply(SPECIES.length()); 3963 float[] r = fr.apply(SPECIES.length()); 3964 3965 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3966 for (int i = 0; i < a.length; i += SPECIES.length()) { 3967 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 3968 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 3969 av.lanewise(VectorOperators.POW, bv).intoArray(r, i); 3970 } 3971 } 3972 3973 assertArraysEqualsWithinOneUlp(a, b, r, FloatMaxVectorTests::POW, FloatMaxVectorTests::strictPOW); 3974 } 3975 3976 static float pow(float a, float b) { 3977 return (float)(Math.pow((double)a, (double)b)); 3978 } 3979 3980 static float strictpow(float a, float b) { 3981 return (float)(StrictMath.pow((double)a, (double)b)); 3982 } 3983 3984 @Test(dataProvider = "floatBinaryOpProvider") 3985 static void powFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) { 3986 float[] a = fa.apply(SPECIES.length()); 3987 float[] b = fb.apply(SPECIES.length()); 3988 float[] r = fr.apply(SPECIES.length()); 3989 3990 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3991 for (int i = 0; i < a.length; i += SPECIES.length()) { 3992 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 3993 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 3994 av.pow(bv).intoArray(r, i); 3995 } 3996 } 3997 3998 assertArraysEqualsWithinOneUlp(a, b, r, FloatMaxVectorTests::pow, FloatMaxVectorTests::strictpow); 3999 } 4000 4001 4002 4003 static float ATAN2(float a, float b) { 4004 return (float)(Math.atan2((double)a, (double)b)); 4005 } 4006 4007 static float strictATAN2(float a, float b) { 4008 return (float)(StrictMath.atan2((double)a, (double)b)); 4009 } 4010 4011 @Test(dataProvider = "floatBinaryOpProvider") 4012 static void ATAN2FloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) { 4013 float[] a = fa.apply(SPECIES.length()); 4014 float[] b = fb.apply(SPECIES.length()); 4015 float[] r = fr.apply(SPECIES.length()); 4016 4017 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4018 for (int i = 0; i < a.length; i += SPECIES.length()) { 4019 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 4020 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 4021 av.lanewise(VectorOperators.ATAN2, bv).intoArray(r, i); 4022 } 4023 } 4024 4025 assertArraysEqualsWithinOneUlp(a, b, r, FloatMaxVectorTests::ATAN2, FloatMaxVectorTests::strictATAN2); 4026 } 4027 4028 4029 4030 @Test(dataProvider = "floatBinaryOpProvider") 4031 static void POWFloatMaxVectorTestsBroadcastSmokeTest(IntFunction<float[]> fa, IntFunction<float[]> fb) { 4032 float[] a = fa.apply(SPECIES.length()); 4033 float[] b = fb.apply(SPECIES.length()); 4034 float[] r = fr.apply(SPECIES.length()); 4035 4036 for (int i = 0; i < a.length; i += SPECIES.length()) { 4037 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 4038 av.lanewise(VectorOperators.POW, b[i]).intoArray(r, i); 4039 } 4040 4041 assertBroadcastArraysEqualsWithinOneUlp(a, b, r, FloatMaxVectorTests::POW, FloatMaxVectorTests::strictPOW); 4042 } 4043 4044 @Test(dataProvider = "floatBinaryOpProvider") 4045 static void powFloatMaxVectorTestsBroadcastSmokeTest(IntFunction<float[]> fa, IntFunction<float[]> fb) { 4046 float[] a = fa.apply(SPECIES.length()); 4047 float[] b = fb.apply(SPECIES.length()); 4048 float[] r = fr.apply(SPECIES.length()); 4049 4050 for (int i = 0; i < a.length; i += SPECIES.length()) { 4051 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 4052 av.pow(b[i]).intoArray(r, i); 4053 } 4054 4055 assertBroadcastArraysEqualsWithinOneUlp(a, b, r, FloatMaxVectorTests::pow, FloatMaxVectorTests::strictpow); 4056 } 4057 4058 4059 4060 static float FMA(float a, float b, float c) { 4061 return (float)(Math.fma(a, b, c)); 4062 } 4063 static float fma(float a, float b, float c) { 4064 return (float)(Math.fma(a, b, c)); 4065 } 4066 4067 4068 @Test(dataProvider = "floatTernaryOpProvider") 4069 static void FMAFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb, IntFunction<float[]> fc) { 4070 float[] a = fa.apply(SPECIES.length()); 4071 float[] b = fb.apply(SPECIES.length()); 4072 float[] c = fc.apply(SPECIES.length()); 4073 float[] r = fr.apply(SPECIES.length()); 4074 4075 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4076 for (int i = 0; i < a.length; i += SPECIES.length()) { 4077 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 4078 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 4079 FloatVector cv = FloatVector.fromArray(SPECIES, c, i); 4080 av.lanewise(VectorOperators.FMA, bv, cv).intoArray(r, i); 4081 } 4082 } 4083 4084 assertArraysEquals(a, b, c, r, FloatMaxVectorTests::FMA); 4085 } 4086 @Test(dataProvider = "floatTernaryOpProvider") 4087 static void fmaFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb, IntFunction<float[]> fc) { 4088 float[] a = fa.apply(SPECIES.length()); 4089 float[] b = fb.apply(SPECIES.length()); 4090 float[] c = fc.apply(SPECIES.length()); 4091 float[] r = fr.apply(SPECIES.length()); 4092 4093 for (int i = 0; i < a.length; i += SPECIES.length()) { 4094 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 4095 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 4096 FloatVector cv = FloatVector.fromArray(SPECIES, c, i); 4097 av.fma(bv, cv).intoArray(r, i); 4098 } 4099 4100 assertArraysEquals(a, b, c, r, FloatMaxVectorTests::fma); 4101 } 4102 4103 4104 @Test(dataProvider = "floatTernaryOpMaskProvider") 4105 static void FMAFloatMaxVectorTestsMasked(IntFunction<float[]> fa, IntFunction<float[]> fb, 4106 IntFunction<float[]> fc, IntFunction<boolean[]> fm) { 4107 float[] a = fa.apply(SPECIES.length()); 4108 float[] b = fb.apply(SPECIES.length()); 4109 float[] c = fc.apply(SPECIES.length()); 4110 float[] r = fr.apply(SPECIES.length()); 4111 boolean[] mask = fm.apply(SPECIES.length()); 4112 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0); 4113 4114 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4115 for (int i = 0; i < a.length; i += SPECIES.length()) { 4116 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 4117 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 4118 FloatVector cv = FloatVector.fromArray(SPECIES, c, i); 4119 av.lanewise(VectorOperators.FMA, bv, cv, vmask).intoArray(r, i); 4120 } 4121 } 4122 4123 assertArraysEquals(a, b, c, r, mask, FloatMaxVectorTests::FMA); 4124 } 4125 4126 4127 4128 4129 4130 @Test(dataProvider = "floatTernaryOpProvider") 4131 static void FMAFloatMaxVectorTestsBroadcastSmokeTest(IntFunction<float[]> fa, IntFunction<float[]> fb, IntFunction<float[]> fc) { 4132 float[] a = fa.apply(SPECIES.length()); 4133 float[] b = fb.apply(SPECIES.length()); 4134 float[] c = fc.apply(SPECIES.length()); 4135 float[] r = fr.apply(SPECIES.length()); 4136 4137 for (int i = 0; i < a.length; i += SPECIES.length()) { 4138 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 4139 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 4140 av.lanewise(VectorOperators.FMA, bv, c[i]).intoArray(r, i); 4141 } 4142 assertBroadcastArraysEquals(a, b, c, r, FloatMaxVectorTests::FMA); 4143 } 4144 4145 @Test(dataProvider = "floatTernaryOpProvider") 4146 static void FMAFloatMaxVectorTestsAltBroadcastSmokeTest(IntFunction<float[]> fa, IntFunction<float[]> fb, IntFunction<float[]> fc) { 4147 float[] a = fa.apply(SPECIES.length()); 4148 float[] b = fb.apply(SPECIES.length()); 4149 float[] c = fc.apply(SPECIES.length()); 4150 float[] r = fr.apply(SPECIES.length()); 4151 4152 for (int i = 0; i < a.length; i += SPECIES.length()) { 4153 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 4154 FloatVector cv = FloatVector.fromArray(SPECIES, c, i); 4155 av.lanewise(VectorOperators.FMA, b[i], cv).intoArray(r, i); 4156 } 4157 assertAltBroadcastArraysEquals(a, b, c, r, FloatMaxVectorTests::FMA); 4158 } 4159 4160 4161 @Test(dataProvider = "floatTernaryOpMaskProvider") 4162 static void FMAFloatMaxVectorTestsBroadcastMaskedSmokeTest(IntFunction<float[]> fa, IntFunction<float[]> fb, 4163 IntFunction<float[]> fc, IntFunction<boolean[]> fm) { 4164 float[] a = fa.apply(SPECIES.length()); 4165 float[] b = fb.apply(SPECIES.length()); 4166 float[] c = fc.apply(SPECIES.length()); 4167 float[] r = fr.apply(SPECIES.length()); 4168 boolean[] mask = fm.apply(SPECIES.length()); 4169 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0); 4170 4171 for (int i = 0; i < a.length; i += SPECIES.length()) { 4172 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 4173 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 4174 av.lanewise(VectorOperators.FMA, bv, c[i], vmask).intoArray(r, i); 4175 } 4176 4177 assertBroadcastArraysEquals(a, b, c, r, mask, FloatMaxVectorTests::FMA); 4178 } 4179 4180 @Test(dataProvider = "floatTernaryOpMaskProvider") 4181 static void FMAFloatMaxVectorTestsAltBroadcastMaskedSmokeTest(IntFunction<float[]> fa, IntFunction<float[]> fb, 4182 IntFunction<float[]> fc, IntFunction<boolean[]> fm) { 4183 float[] a = fa.apply(SPECIES.length()); 4184 float[] b = fb.apply(SPECIES.length()); 4185 float[] c = fc.apply(SPECIES.length()); 4186 float[] r = fr.apply(SPECIES.length()); 4187 boolean[] mask = fm.apply(SPECIES.length()); 4188 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0); 4189 4190 for (int i = 0; i < a.length; i += SPECIES.length()) { 4191 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 4192 FloatVector cv = FloatVector.fromArray(SPECIES, c, i); 4193 av.lanewise(VectorOperators.FMA, b[i], cv, vmask).intoArray(r, i); 4194 } 4195 4196 assertAltBroadcastArraysEquals(a, b, c, r, mask, FloatMaxVectorTests::FMA); 4197 } 4198 4199 4200 4201 4202 @Test(dataProvider = "floatTernaryOpProvider") 4203 static void FMAFloatMaxVectorTestsDoubleBroadcastSmokeTest(IntFunction<float[]> fa, IntFunction<float[]> fb, IntFunction<float[]> fc) { 4204 float[] a = fa.apply(SPECIES.length()); 4205 float[] b = fb.apply(SPECIES.length()); 4206 float[] c = fc.apply(SPECIES.length()); 4207 float[] r = fr.apply(SPECIES.length()); 4208 4209 for (int i = 0; i < a.length; i += SPECIES.length()) { 4210 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 4211 av.lanewise(VectorOperators.FMA, b[i], c[i]).intoArray(r, i); 4212 } 4213 4214 assertDoubleBroadcastArraysEquals(a, b, c, r, FloatMaxVectorTests::FMA); 4215 } 4216 @Test(dataProvider = "floatTernaryOpProvider") 4217 static void fmaFloatMaxVectorTestsDoubleBroadcastSmokeTest(IntFunction<float[]> fa, IntFunction<float[]> fb, IntFunction<float[]> fc) { 4218 float[] a = fa.apply(SPECIES.length()); 4219 float[] b = fb.apply(SPECIES.length()); 4220 float[] c = fc.apply(SPECIES.length()); 4221 float[] r = fr.apply(SPECIES.length()); 4222 4223 for (int i = 0; i < a.length; i += SPECIES.length()) { 4224 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 4225 av.fma(b[i], c[i]).intoArray(r, i); 4226 } 4227 4228 assertDoubleBroadcastArraysEquals(a, b, c, r, FloatMaxVectorTests::fma); 4229 } 4230 4231 4232 @Test(dataProvider = "floatTernaryOpMaskProvider") 4233 static void FMAFloatMaxVectorTestsDoubleBroadcastMaskedSmokeTest(IntFunction<float[]> fa, IntFunction<float[]> fb, 4234 IntFunction<float[]> fc, IntFunction<boolean[]> fm) { 4235 float[] a = fa.apply(SPECIES.length()); 4236 float[] b = fb.apply(SPECIES.length()); 4237 float[] c = fc.apply(SPECIES.length()); 4238 float[] r = fr.apply(SPECIES.length()); 4239 boolean[] mask = fm.apply(SPECIES.length()); 4240 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0); 4241 4242 for (int i = 0; i < a.length; i += SPECIES.length()) { 4243 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 4244 av.lanewise(VectorOperators.FMA, b[i], c[i], vmask).intoArray(r, i); 4245 } 4246 4247 assertDoubleBroadcastArraysEquals(a, b, c, r, mask, FloatMaxVectorTests::FMA); 4248 } 4249 4250 4251 4252 4253 static float NEG(float a) { 4254 return (float)(-((float)a)); 4255 } 4256 4257 static float neg(float a) { 4258 return (float)(-((float)a)); 4259 } 4260 4261 @Test(dataProvider = "floatUnaryOpProvider") 4262 static void NEGFloatMaxVectorTests(IntFunction<float[]> fa) { 4263 float[] a = fa.apply(SPECIES.length()); 4264 float[] r = fr.apply(SPECIES.length()); 4265 4266 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4267 for (int i = 0; i < a.length; i += SPECIES.length()) { 4268 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 4269 av.lanewise(VectorOperators.NEG).intoArray(r, i); 4270 } 4271 } 4272 4273 assertArraysEquals(a, r, FloatMaxVectorTests::NEG); 4274 } 4275 4276 @Test(dataProvider = "floatUnaryOpProvider") 4277 static void negFloatMaxVectorTests(IntFunction<float[]> fa) { 4278 float[] a = fa.apply(SPECIES.length()); 4279 float[] r = fr.apply(SPECIES.length()); 4280 4281 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4282 for (int i = 0; i < a.length; i += SPECIES.length()) { 4283 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 4284 av.neg().intoArray(r, i); 4285 } 4286 } 4287 4288 assertArraysEquals(a, r, FloatMaxVectorTests::neg); 4289 } 4290 4291 @Test(dataProvider = "floatUnaryOpMaskProvider") 4292 static void NEGMaskedFloatMaxVectorTests(IntFunction<float[]> fa, 4293 IntFunction<boolean[]> fm) { 4294 float[] a = fa.apply(SPECIES.length()); 4295 float[] r = fr.apply(SPECIES.length()); 4296 boolean[] mask = fm.apply(SPECIES.length()); 4297 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0); 4298 4299 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4300 for (int i = 0; i < a.length; i += SPECIES.length()) { 4301 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 4302 av.lanewise(VectorOperators.NEG, vmask).intoArray(r, i); 4303 } 4304 } 4305 4306 assertArraysEquals(a, r, mask, FloatMaxVectorTests::NEG); 4307 } 4308 4309 static float ABS(float a) { 4310 return (float)(Math.abs((float)a)); 4311 } 4312 4313 static float abs(float a) { 4314 return (float)(Math.abs((float)a)); 4315 } 4316 4317 @Test(dataProvider = "floatUnaryOpProvider") 4318 static void ABSFloatMaxVectorTests(IntFunction<float[]> fa) { 4319 float[] a = fa.apply(SPECIES.length()); 4320 float[] r = fr.apply(SPECIES.length()); 4321 4322 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4323 for (int i = 0; i < a.length; i += SPECIES.length()) { 4324 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 4325 av.lanewise(VectorOperators.ABS).intoArray(r, i); 4326 } 4327 } 4328 4329 assertArraysEquals(a, r, FloatMaxVectorTests::ABS); 4330 } 4331 4332 @Test(dataProvider = "floatUnaryOpProvider") 4333 static void absFloatMaxVectorTests(IntFunction<float[]> fa) { 4334 float[] a = fa.apply(SPECIES.length()); 4335 float[] r = fr.apply(SPECIES.length()); 4336 4337 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4338 for (int i = 0; i < a.length; i += SPECIES.length()) { 4339 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 4340 av.abs().intoArray(r, i); 4341 } 4342 } 4343 4344 assertArraysEquals(a, r, FloatMaxVectorTests::abs); 4345 } 4346 4347 @Test(dataProvider = "floatUnaryOpMaskProvider") 4348 static void ABSMaskedFloatMaxVectorTests(IntFunction<float[]> fa, 4349 IntFunction<boolean[]> fm) { 4350 float[] a = fa.apply(SPECIES.length()); 4351 float[] r = fr.apply(SPECIES.length()); 4352 boolean[] mask = fm.apply(SPECIES.length()); 4353 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0); 4354 4355 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4356 for (int i = 0; i < a.length; i += SPECIES.length()) { 4357 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 4358 av.lanewise(VectorOperators.ABS, vmask).intoArray(r, i); 4359 } 4360 } 4361 4362 assertArraysEquals(a, r, mask, FloatMaxVectorTests::ABS); 4363 } 4364 4365 4366 4367 4368 4369 4370 4371 4372 static float SQRT(float a) { 4373 return (float)(Math.sqrt((double)a)); 4374 } 4375 4376 static float sqrt(float a) { 4377 return (float)(Math.sqrt((double)a)); 4378 } 4379 4380 4381 4382 @Test(dataProvider = "floatUnaryOpProvider") 4383 static void SQRTFloatMaxVectorTests(IntFunction<float[]> fa) { 4384 float[] a = fa.apply(SPECIES.length()); 4385 float[] r = fr.apply(SPECIES.length()); 4386 4387 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4388 for (int i = 0; i < a.length; i += SPECIES.length()) { 4389 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 4390 av.lanewise(VectorOperators.SQRT).intoArray(r, i); 4391 } 4392 } 4393 4394 assertArraysEquals(a, r, FloatMaxVectorTests::SQRT); 4395 } 4396 4397 @Test(dataProvider = "floatUnaryOpProvider") 4398 static void sqrtFloatMaxVectorTests(IntFunction<float[]> fa) { 4399 float[] a = fa.apply(SPECIES.length()); 4400 float[] r = fr.apply(SPECIES.length()); 4401 4402 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4403 for (int i = 0; i < a.length; i += SPECIES.length()) { 4404 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 4405 av.sqrt().intoArray(r, i); 4406 } 4407 } 4408 4409 assertArraysEquals(a, r, FloatMaxVectorTests::sqrt); 4410 } 4411 4412 4413 4414 @Test(dataProvider = "floatUnaryOpMaskProvider") 4415 static void SQRTMaskedFloatMaxVectorTests(IntFunction<float[]> fa, 4416 IntFunction<boolean[]> fm) { 4417 float[] a = fa.apply(SPECIES.length()); 4418 float[] r = fr.apply(SPECIES.length()); 4419 boolean[] mask = fm.apply(SPECIES.length()); 4420 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0); 4421 4422 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4423 for (int i = 0; i < a.length; i += SPECIES.length()) { 4424 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 4425 av.lanewise(VectorOperators.SQRT, vmask).intoArray(r, i); 4426 } 4427 } 4428 4429 assertArraysEquals(a, r, mask, FloatMaxVectorTests::SQRT); 4430 } 4431 4432 static float[] gather(float a[], int ix, int[] b, int iy) { 4433 float[] res = new float[SPECIES.length()]; 4434 for (int i = 0; i < SPECIES.length(); i++) { 4435 int bi = iy + i; 4436 res[i] = a[b[bi] + ix]; 4437 } 4438 return res; 4439 } 4440 4441 @Test(dataProvider = "floatUnaryOpIndexProvider") 4442 static void gatherFloatMaxVectorTests(IntFunction<float[]> fa, BiFunction<Integer,Integer,int[]> fs) { 4443 float[] a = fa.apply(SPECIES.length()); 4444 int[] b = fs.apply(a.length, SPECIES.length()); 4445 float[] r = new float[a.length]; 4446 4447 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4448 for (int i = 0; i < a.length; i += SPECIES.length()) { 4449 FloatVector av = FloatVector.fromArray(SPECIES, a, i, b, i); 4450 av.intoArray(r, i); 4451 } 4452 } 4453 4454 assertArraysEquals(a, b, r, FloatMaxVectorTests::gather); 4455 } 4456 static float[] gatherMasked(float a[], int ix, boolean[] mask, int[] b, int iy) { 4457 float[] res = new float[SPECIES.length()]; 4458 for (int i = 0; i < SPECIES.length(); i++) { 4459 int bi = iy + i; 4460 if (mask[i]) { 4461 res[i] = a[b[bi] + ix]; 4462 } 4463 } 4464 return res; 4465 } 4466 4467 @Test(dataProvider = "floatUnaryMaskedOpIndexProvider") 4468 static void gatherMaskedFloatMaxVectorTests(IntFunction<float[]> fa, BiFunction<Integer,Integer,int[]> fs, IntFunction<boolean[]> fm) { 4469 float[] a = fa.apply(SPECIES.length()); 4470 int[] b = fs.apply(a.length, SPECIES.length()); 4471 float[] r = new float[a.length]; 4472 boolean[] mask = fm.apply(SPECIES.length()); 4473 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0); 4474 4475 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4476 for (int i = 0; i < a.length; i += SPECIES.length()) { 4477 FloatVector av = FloatVector.fromArray(SPECIES, a, i, b, i, vmask); 4478 av.intoArray(r, i); 4479 } 4480 } 4481 4482 assertArraysEquals(a, b, r, mask, FloatMaxVectorTests::gatherMasked); 4483 } 4484 4485 static float[] scatter(float a[], int ix, int[] b, int iy) { 4486 float[] res = new float[SPECIES.length()]; 4487 for (int i = 0; i < SPECIES.length(); i++) { 4488 int bi = iy + i; 4489 res[b[bi]] = a[i + ix]; 4490 } 4491 return res; 4492 } 4493 4494 @Test(dataProvider = "floatUnaryOpIndexProvider") 4495 static void scatterFloatMaxVectorTests(IntFunction<float[]> fa, BiFunction<Integer,Integer,int[]> fs) { 4496 float[] a = fa.apply(SPECIES.length()); 4497 int[] b = fs.apply(a.length, SPECIES.length()); 4498 float[] r = new float[a.length]; 4499 4500 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4501 for (int i = 0; i < a.length; i += SPECIES.length()) { 4502 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 4503 av.intoArray(r, i, b, i); 4504 } 4505 } 4506 4507 assertArraysEquals(a, b, r, FloatMaxVectorTests::scatter); 4508 } 4509 4510 static float[] scatterMasked(float r[], float a[], int ix, boolean[] mask, int[] b, int iy) { 4511 // First, gather r. 4512 float[] oldVal = gather(r, ix, b, iy); 4513 float[] newVal = new float[SPECIES.length()]; 4514 4515 // Second, blending it with a. 4516 for (int i = 0; i < SPECIES.length(); i++) { 4517 newVal[i] = blend(oldVal[i], a[i+ix], mask[i]); 4518 } 4519 4520 // Third, scatter: copy old value of r, and scatter it manually. 4521 float[] res = Arrays.copyOfRange(r, ix, ix+SPECIES.length()); 4522 for (int i = 0; i < SPECIES.length(); i++) { 4523 int bi = iy + i; 4524 res[b[bi]] = newVal[i]; 4525 } 4526 4527 return res; 4528 } 4529 4530 @Test(dataProvider = "scatterMaskedOpIndexProvider") 4531 static void scatterMaskedFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb, BiFunction<Integer,Integer,int[]> fs, IntFunction<boolean[]> fm) { 4532 float[] a = fa.apply(SPECIES.length()); 4533 int[] b = fs.apply(a.length, SPECIES.length()); 4534 float[] r = fb.apply(SPECIES.length()); 4535 boolean[] mask = fm.apply(SPECIES.length()); 4536 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0); 4537 4538 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4539 for (int i = 0; i < a.length; i += SPECIES.length()) { 4540 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 4541 av.intoArray(r, i, b, i, vmask); 4542 } 4543 } 4544 4545 assertArraysEquals(a, b, r, mask, FloatMaxVectorTests::scatterMasked); 4546 } 4547 4548 4549 @Test(dataProvider = "floatCompareOpProvider") 4550 static void ltFloatMaxVectorTestsBroadcastSmokeTest(IntFunction<float[]> fa, IntFunction<float[]> fb) { 4551 float[] a = fa.apply(SPECIES.length()); 4552 float[] b = fb.apply(SPECIES.length()); 4553 4554 for (int i = 0; i < a.length; i += SPECIES.length()) { 4555 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 4556 VectorMask<Float> mv = av.lt(b[i]); 4557 4558 // Check results as part of computation. 4559 for (int j = 0; j < SPECIES.length(); j++) { 4560 Assert.assertEquals(mv.laneIsSet(j), a[i + j] < b[i]); 4561 } 4562 } 4563 } 4564 4565 @Test(dataProvider = "floatCompareOpProvider") 4566 static void eqFloatMaxVectorTestsBroadcastMaskedSmokeTest(IntFunction<float[]> fa, IntFunction<float[]> fb) { 4567 float[] a = fa.apply(SPECIES.length()); 4568 float[] b = fb.apply(SPECIES.length()); 4569 4570 for (int i = 0; i < a.length; i += SPECIES.length()) { 4571 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 4572 VectorMask<Float> mv = av.eq(b[i]); 4573 4574 // Check results as part of computation. 4575 for (int j = 0; j < SPECIES.length(); j++) { 4576 Assert.assertEquals(mv.laneIsSet(j), a[i + j] == b[i]); 4577 } 4578 } 4579 } 4580 4581 @Test(dataProvider = "floattoIntUnaryOpProvider") 4582 static void toIntArrayFloatMaxVectorTestsSmokeTest(IntFunction<float[]> fa) { 4583 float[] a = fa.apply(SPECIES.length()); 4584 4585 for (int i = 0; i < a.length; i += SPECIES.length()) { 4586 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 4587 int [] r = av.toIntArray(); 4588 assertArraysEquals(a, r, i); 4589 } 4590 } 4591 4592 @Test(dataProvider = "floattoLongUnaryOpProvider") 4593 static void toLongArrayFloatMaxVectorTestsSmokeTest(IntFunction<float[]> fa) { 4594 float[] a = fa.apply(SPECIES.length()); 4595 4596 for (int i = 0; i < a.length; i += SPECIES.length()) { 4597 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 4598 long [] r = av.toLongArray(); 4599 assertArraysEquals(a, r, i); 4600 } 4601 } 4602 4603 @Test(dataProvider = "floatUnaryOpProvider") 4604 static void toDoubleArrayFloatMaxVectorTestsSmokeTest(IntFunction<float[]> fa) { 4605 float[] a = fa.apply(SPECIES.length()); 4606 4607 for (int i = 0; i < a.length; i += SPECIES.length()) { 4608 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 4609 double [] r = av.toDoubleArray(); 4610 assertArraysEquals(a, r, i); 4611 } 4612 } 4613 4614 @Test(dataProvider = "floatUnaryOpProvider") 4615 static void toStringFloatMaxVectorTestsSmokeTest(IntFunction<float[]> fa) { 4616 float[] a = fa.apply(SPECIES.length()); 4617 4618 for (int i = 0; i < a.length; i += SPECIES.length()) { 4619 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 4620 String str = av.toString(); 4621 4622 float subarr[] = Arrays.copyOfRange(a, i, i + SPECIES.length()); 4623 Assert.assertTrue(str.equals(Arrays.toString(subarr)), "at index " + i + ", string should be = " + Arrays.toString(subarr) + ", but is = " + str); 4624 } 4625 } 4626 4627 @Test(dataProvider = "floatUnaryOpProvider") 4628 static void hashCodeFloatMaxVectorTestsSmokeTest(IntFunction<float[]> fa) { 4629 float[] a = fa.apply(SPECIES.length()); 4630 4631 for (int i = 0; i < a.length; i += SPECIES.length()) { 4632 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 4633 int hash = av.hashCode(); 4634 4635 float subarr[] = Arrays.copyOfRange(a, i, i + SPECIES.length()); 4636 int expectedHash = Objects.hash(SPECIES, Arrays.hashCode(subarr)); 4637 Assert.assertTrue(hash == expectedHash, "at index " + i + ", hash should be = " + expectedHash + ", but is = " + hash); 4638 } 4639 } 4640 4641 4642 static long ADDReduceLong(float[] a, int idx) { 4643 float res = 0; 4644 for (int i = idx; i < (idx + SPECIES.length()); i++) { 4645 res += a[i]; 4646 } 4647 4648 return (long)res; 4649 } 4650 4651 static long ADDReduceAllLong(float[] a) { 4652 long res = 0; 4653 for (int i = 0; i < a.length; i += SPECIES.length()) { 4654 res += ADDReduceLong(a, i); 4655 } 4656 4657 return res; 4658 } 4659 4660 @Test(dataProvider = "floatUnaryOpProvider") 4661 static void ADDReduceLongFloatMaxVectorTests(IntFunction<float[]> fa) { 4662 float[] a = fa.apply(SPECIES.length()); 4663 long[] r = lfr.apply(SPECIES.length()); 4664 long ra = 0; 4665 4666 for (int i = 0; i < a.length; i += SPECIES.length()) { 4667 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 4668 r[i] = av.reduceLanesToLong(VectorOperators.ADD); 4669 } 4670 4671 ra = 0; 4672 for (int i = 0; i < a.length; i ++) { 4673 ra += r[i]; 4674 } 4675 4676 assertReductionLongArraysEquals(a, r, ra, 4677 FloatMaxVectorTests::ADDReduceLong, FloatMaxVectorTests::ADDReduceAllLong); 4678 } 4679 4680 static long ADDReduceLongMasked(float[] a, int idx, boolean[] mask) { 4681 float res = 0; 4682 for (int i = idx; i < (idx + SPECIES.length()); i++) { 4683 if(mask[i % SPECIES.length()]) 4684 res += a[i]; 4685 } 4686 4687 return (long)res; 4688 } 4689 4690 static long ADDReduceAllLongMasked(float[] a, boolean[] mask) { 4691 long res = 0; 4692 for (int i = 0; i < a.length; i += SPECIES.length()) { 4693 res += ADDReduceLongMasked(a, i, mask); 4694 } 4695 4696 return res; 4697 } 4698 4699 @Test(dataProvider = "floatUnaryOpMaskProvider") 4700 static void ADDReduceLongFloatMaxVectorTestsMasked(IntFunction<float[]> fa, IntFunction<boolean[]> fm) { 4701 float[] a = fa.apply(SPECIES.length()); 4702 long[] r = lfr.apply(SPECIES.length()); 4703 boolean[] mask = fm.apply(SPECIES.length()); 4704 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0); 4705 long ra = 0; 4706 4707 for (int i = 0; i < a.length; i += SPECIES.length()) { 4708 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 4709 r[i] = av.reduceLanesToLong(VectorOperators.ADD, vmask); 4710 } 4711 4712 ra = 0; 4713 for (int i = 0; i < a.length; i ++) { 4714 ra += r[i]; 4715 } 4716 4717 assertReductionLongArraysEqualsMasked(a, r, ra, mask, 4718 FloatMaxVectorTests::ADDReduceLongMasked, FloatMaxVectorTests::ADDReduceAllLongMasked); 4719 } 4720 4721 @Test(dataProvider = "floattoLongUnaryOpProvider") 4722 static void BroadcastLongFloatMaxVectorTestsSmokeTest(IntFunction<float[]> fa) { 4723 float[] a = fa.apply(SPECIES.length()); 4724 float[] r = new float[a.length]; 4725 4726 for (int i = 0; i < a.length; i += SPECIES.length()) { 4727 FloatVector.broadcast(SPECIES, (long)a[i]).intoArray(r, i); 4728 } 4729 assertBroadcastArraysEquals(a, r); 4730 } 4731 4732 @Test(dataProvider = "floatBinaryOpMaskProvider") 4733 static void blendFloatMaxVectorTestsBroadcastLongSmokeTest(IntFunction<float[]> fa, IntFunction<float[]> fb, 4734 IntFunction<boolean[]> fm) { 4735 float[] a = fa.apply(SPECIES.length()); 4736 float[] b = fb.apply(SPECIES.length()); 4737 float[] r = fr.apply(SPECIES.length()); 4738 boolean[] mask = fm.apply(SPECIES.length()); 4739 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0); 4740 4741 for (int ic = 0; ic < INVOC_COUNT; ic++) { 4742 for (int i = 0; i < a.length; i += SPECIES.length()) { 4743 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 4744 av.blend((long)b[i], vmask).intoArray(r, i); 4745 } 4746 } 4747 assertBroadcastLongArraysEquals(a, b, r, mask, FloatMaxVectorTests::blend); 4748 } 4749 4750 4751 @Test(dataProvider = "floatUnaryOpSelectFromProvider") 4752 static void SelectFromFloatMaxVectorTests(IntFunction<float[]> fa, 4753 BiFunction<Integer,Integer,float[]> fs) { 4754 float[] a = fa.apply(SPECIES.length()); 4755 float[] order = fs.apply(a.length, SPECIES.length()); 4756 float[] r = fr.apply(SPECIES.length()); 4757 4758 for (int i = 0; i < a.length; i += SPECIES.length()) { 4759 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 4760 FloatVector bv = FloatVector.fromArray(SPECIES, order, i); 4761 bv.selectFrom(av).intoArray(r, i); 4762 } 4763 4764 assertSelectFromArraysEquals(a, r, order, SPECIES.length()); 4765 } 4766 4767 @Test(dataProvider = "floatUnaryOpSelectFromMaskProvider") 4768 static void SelectFromFloatMaxVectorTestsMaskedSmokeTest(IntFunction<float[]> fa, 4769 BiFunction<Integer,Integer,float[]> fs, 4770 IntFunction<boolean[]> fm) { 4771 float[] a = fa.apply(SPECIES.length()); 4772 float[] order = fs.apply(a.length, SPECIES.length()); 4773 float[] r = fr.apply(SPECIES.length()); 4774 boolean[] mask = fm.apply(SPECIES.length()); 4775 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0); 4776 4777 for (int i = 0; i < a.length; i += SPECIES.length()) { 4778 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 4779 FloatVector bv = FloatVector.fromArray(SPECIES, order, i); 4780 bv.selectFrom(av, vmask).intoArray(r, i); 4781 } 4782 4783 assertSelectFromArraysEquals(a, r, order, mask, SPECIES.length()); 4784 } 4785 4786 @Test(dataProvider = "shuffleProvider") 4787 static void shuffleMiscellaneousFloatMaxVectorTestsSmokeTest(BiFunction<Integer,Integer,int[]> fs) { 4788 int[] a = fs.apply(SPECIES.length() * BUFFER_REPS, SPECIES.length()); 4789 4790 for (int i = 0; i < a.length; i += SPECIES.length()) { 4791 var shuffle = VectorShuffle.fromArray(SPECIES, a, i); 4792 int hash = shuffle.hashCode(); 4793 int length = shuffle.length(); 4794 4795 int subarr[] = Arrays.copyOfRange(a, i, i + SPECIES.length()); 4796 int expectedHash = Objects.hash(SPECIES, Arrays.hashCode(subarr)); 4797 Assert.assertTrue(hash == expectedHash, "at index " + i + ", hash should be = " + expectedHash + ", but is = " + hash); 4798 Assert.assertEquals(length, SPECIES.length()); 4799 } 4800 } 4801 4802 @Test(dataProvider = "shuffleProvider") 4803 static void shuffleToStringFloatMaxVectorTestsSmokeTest(BiFunction<Integer,Integer,int[]> fs) { 4804 int[] a = fs.apply(SPECIES.length() * BUFFER_REPS, SPECIES.length()); 4805 4806 for (int i = 0; i < a.length; i += SPECIES.length()) { 4807 var shuffle = VectorShuffle.fromArray(SPECIES, a, i); 4808 String str = shuffle.toString(); 4809 4810 int subarr[] = Arrays.copyOfRange(a, i, i + SPECIES.length()); 4811 Assert.assertTrue(str.equals("Shuffle" + Arrays.toString(subarr)), "at index " + 4812 i + ", string should be = " + Arrays.toString(subarr) + ", but is = " + str); 4813 } 4814 } 4815 4816 @Test(dataProvider = "shuffleCompareOpProvider") 4817 static void shuffleEqualsFloatMaxVectorTestsSmokeTest(BiFunction<Integer,Integer,int[]> fa, BiFunction<Integer,Integer,int[]> fb) { 4818 int[] a = fa.apply(SPECIES.length() * BUFFER_REPS, SPECIES.length()); 4819 int[] b = fb.apply(SPECIES.length() * BUFFER_REPS, SPECIES.length()); 4820 4821 for (int i = 0; i < a.length; i += SPECIES.length()) { 4822 var av = VectorShuffle.fromArray(SPECIES, a, i); 4823 var bv = VectorShuffle.fromArray(SPECIES, b, i); 4824 boolean eq = av.equals(bv); 4825 int to = i + SPECIES.length(); 4826 Assert.assertEquals(eq, Arrays.equals(a, i, to, b, i, to)); 4827 } 4828 } 4829 4830 @Test(dataProvider = "maskCompareOpProvider") 4831 static void maskEqualsFloatMaxVectorTestsSmokeTest(IntFunction<boolean[]> fa, IntFunction<boolean[]> fb) { 4832 boolean[] a = fa.apply(SPECIES.length()); 4833 boolean[] b = fb.apply(SPECIES.length()); 4834 4835 for (int i = 0; i < a.length; i += SPECIES.length()) { 4836 var av = SPECIES.loadMask(a, i); 4837 var bv = SPECIES.loadMask(b, i); 4838 boolean equals = av.equals(bv); 4839 int to = i + SPECIES.length(); 4840 Assert.assertEquals(equals, Arrays.equals(a, i, to, b, i, to)); 4841 } 4842 } 4843 4844 static boolean beq(boolean a, boolean b) { 4845 return (a == b); 4846 } 4847 4848 @Test(dataProvider = "maskCompareOpProvider") 4849 static void maskEqFloatMaxVectorTestsSmokeTest(IntFunction<boolean[]> fa, IntFunction<boolean[]> fb) { 4850 boolean[] a = fa.apply(SPECIES.length()); 4851 boolean[] b = fb.apply(SPECIES.length()); 4852 boolean[] r = new boolean[a.length]; 4853 4854 for (int i = 0; i < a.length; i += SPECIES.length()) { 4855 var av = SPECIES.loadMask(a, i); 4856 var bv = SPECIES.loadMask(b, i); 4857 var cv = av.eq(bv); 4858 cv.intoArray(r, i); 4859 } 4860 assertArraysEquals(a, b, r, FloatMaxVectorTests::beq); 4861 } 4862 4863 @Test(dataProvider = "maskProvider") 4864 static void maskHashCodeFloatMaxVectorTestsSmokeTest(IntFunction<boolean[]> fa) { 4865 boolean[] a = fa.apply(SPECIES.length()); 4866 4867 for (int i = 0; i < a.length; i += SPECIES.length()) { 4868 var vmask = SPECIES.loadMask(a, i); 4869 int hash = vmask.hashCode(); 4870 4871 boolean subarr[] = Arrays.copyOfRange(a, i, i + SPECIES.length()); 4872 int expectedHash = Objects.hash(SPECIES, Arrays.hashCode(subarr)); 4873 Assert.assertTrue(hash == expectedHash, "at index " + i + ", hash should be = " + expectedHash + ", but is = " + hash); 4874 } 4875 } 4876 4877 @Test(dataProvider = "maskProvider") 4878 static void maskTrueCountFloatMaxVectorTestsSmokeTest(IntFunction<boolean[]> fa) { 4879 boolean[] a = fa.apply(SPECIES.length()); 4880 4881 for (int i = 0; i < a.length; i += SPECIES.length()) { 4882 var vmask = SPECIES.loadMask(a, i); 4883 int tcount = vmask.trueCount(); 4884 int expectedTcount = 0; 4885 for (int j = i; j < i + SPECIES.length(); j++) { 4886 expectedTcount += a[j] ? 1 : 0; 4887 } 4888 Assert.assertTrue(tcount == expectedTcount, "at index " + i + ", trueCount should be = " + expectedTcount + ", but is = " + tcount); 4889 } 4890 } 4891 4892 @Test(dataProvider = "maskProvider") 4893 static void maskLastTrueFloatMaxVectorTestsSmokeTest(IntFunction<boolean[]> fa) { 4894 boolean[] a = fa.apply(SPECIES.length()); 4895 4896 for (int i = 0; i < a.length; i += SPECIES.length()) { 4897 var vmask = SPECIES.loadMask(a, i); 4898 int ltrue = vmask.lastTrue(); 4899 int j = i + SPECIES.length() - 1; 4900 for (; j >= i; j--) { 4901 if (a[j]) break; 4902 } 4903 int expectedLtrue = j - i; 4904 4905 Assert.assertTrue(ltrue == expectedLtrue, "at index " + i + 4906 ", lastTrue should be = " + expectedLtrue + ", but is = " + ltrue); 4907 } 4908 } 4909 4910 4911 @DataProvider 4912 public static Object[][] offsetProvider() { 4913 return new Object[][]{ 4914 {0}, 4915 {-1}, 4916 {+1}, 4917 {+2}, 4918 {-2}, 4919 }; 4920 } 4921 4922 @Test(dataProvider = "offsetProvider") 4923 static void indexInRangeFloatMaxVectorTestsSmokeTest(int offset) { 4924 int limit = SPECIES.length() * BUFFER_REPS; 4925 for (int i = 0; i < limit; i += SPECIES.length()) { 4926 var actualMask = SPECIES.indexInRange(i + offset, limit); 4927 var expectedMask = SPECIES.maskAll(true).indexInRange(i + offset, limit); 4928 assert(actualMask.equals(expectedMask)); 4929 for (int j = 0; j < SPECIES.length(); j++) { 4930 int index = i + j + offset; 4931 Assert.assertEquals(actualMask.laneIsSet(j), index >= 0 && index < limit); 4932 } 4933 } 4934 } 4935 4936 @DataProvider 4937 public static Object[][] lengthProvider() { 4938 return new Object[][]{ 4939 {0}, 4940 {1}, 4941 {32}, 4942 {37}, 4943 {1024}, 4944 {1024+1}, 4945 {1024+5}, 4946 }; 4947 } 4948 4949 @Test(dataProvider = "lengthProvider") 4950 static void loopBoundFloatMaxVectorTestsSmokeTest(int length) { 4951 int actualLoopBound = SPECIES.loopBound(length); 4952 int expectedLoopBound = length - Math.floorMod(length, SPECIES.length()); 4953 Assert.assertEquals(actualLoopBound, expectedLoopBound); 4954 } 4955 4956 @Test 4957 static void ElementSizeFloatMaxVectorTestsSmokeTest() { 4958 FloatVector av = FloatVector.zero(SPECIES); 4959 int elsize = av.elementSize(); 4960 Assert.assertEquals(elsize, Float.SIZE); 4961 } 4962 4963 @Test 4964 static void VectorShapeFloatMaxVectorTestsSmokeTest() { 4965 FloatVector av = FloatVector.zero(SPECIES); 4966 VectorShape vsh = av.shape(); 4967 assert(vsh.equals(VectorShape.S_Max_BIT)); 4968 } 4969 4970 @Test 4971 static void ShapeWithLanesFloatMaxVectorTestsSmokeTest() { 4972 FloatVector av = FloatVector.zero(SPECIES); 4973 VectorShape vsh = av.shape(); 4974 VectorSpecies species = vsh.withLanes(float.class); 4975 assert(species.equals(SPECIES)); 4976 } 4977 4978 @Test 4979 static void ElementTypeFloatMaxVectorTestsSmokeTest() { 4980 FloatVector av = FloatVector.zero(SPECIES); 4981 assert(av.species().elementType() == float.class); 4982 } 4983 4984 @Test 4985 static void SpeciesElementSizeFloatMaxVectorTestsSmokeTest() { 4986 FloatVector av = FloatVector.zero(SPECIES); 4987 assert(av.species().elementSize() == Float.SIZE); 4988 } 4989 4990 @Test 4991 static void VectorTypeFloatMaxVectorTestsSmokeTest() { 4992 FloatVector av = FloatVector.zero(SPECIES); 4993 assert(av.species().vectorType() == av.getClass()); 4994 } 4995 4996 @Test 4997 static void WithLanesFloatMaxVectorTestsSmokeTest() { 4998 FloatVector av = FloatVector.zero(SPECIES); 4999 VectorSpecies species = av.species().withLanes(float.class); 5000 assert(species.equals(SPECIES)); 5001 } 5002 5003 @Test 5004 static void WithShapeFloatMaxVectorTestsSmokeTest() { 5005 FloatVector av = FloatVector.zero(SPECIES); 5006 VectorShape vsh = av.shape(); 5007 VectorSpecies species = av.species().withShape(vsh); 5008 assert(species.equals(SPECIES)); 5009 } 5010 } 5011 5012