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.stream.Collectors; 51 import java.util.stream.Stream; 52 53 @Test 54 public class FloatMaxVectorTests extends AbstractVectorTest { 55 56 static final VectorSpecies<Float> SPECIES = 57 FloatVector.SPECIES_MAX; 58 59 static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100); 60 61 static VectorShape getMaxBit() { 62 return VectorShape.S_Max_BIT; 63 } 64 65 private static final int Max = 256; // juts so we can do N/Max 66 67 static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / Max); 68 69 static final int BUFFER_SIZE = Integer.getInteger("jdk.incubator.vector.test.buffer-size", BUFFER_REPS * (Max / 8)); 70 71 interface FUnOp { 72 float apply(float a); 73 } 74 75 static void assertArraysEquals(float[] a, float[] r, FUnOp f) { 76 int i = 0; 77 try { 78 for (; i < a.length; i++) { 79 Assert.assertEquals(r[i], f.apply(a[i])); 80 } 81 } catch (AssertionError e) { 82 Assert.assertEquals(r[i], f.apply(a[i]), "at index #" + i + ", input = " + a[i]); 83 } 84 } 85 86 interface FUnArrayOp { 87 float[] apply(float a); 88 } 89 90 static void assertArraysEquals(float[] a, float[] r, FUnArrayOp f) { 91 int i = 0; 92 try { 93 for (; i < a.length; i += SPECIES.length()) { 94 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()), 95 f.apply(a[i])); 96 } 97 } catch (AssertionError e) { 98 float[] ref = f.apply(a[i]); 99 float[] res = Arrays.copyOfRange(r, i, i+SPECIES.length()); 100 Assert.assertEquals(ref, res, "(ref: " + Arrays.toString(ref) 101 + ", res: " + Arrays.toString(res) 102 + "), at index #" + i); 103 } 104 } 105 106 static void assertArraysEquals(float[] a, float[] r, boolean[] mask, FUnOp f) { 107 int i = 0; 108 try { 109 for (; i < a.length; i++) { 110 Assert.assertEquals(r[i], mask[i % SPECIES.length()] ? f.apply(a[i]) : a[i]); 111 } 112 } catch (AssertionError e) { 113 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()]); 114 } 115 } 116 117 interface FReductionOp { 118 float apply(float[] a, int idx); 119 } 120 121 interface FReductionAllOp { 122 float apply(float[] a); 123 } 124 125 static void assertReductionArraysEquals(float[] a, float[] b, float c, 126 FReductionOp f, FReductionAllOp fa) { 127 int i = 0; 128 try { 129 Assert.assertEquals(c, fa.apply(a)); 130 for (; i < a.length; i += SPECIES.length()) { 131 Assert.assertEquals(b[i], f.apply(a, i)); 132 } 133 } catch (AssertionError e) { 134 Assert.assertEquals(c, fa.apply(a), "Final result is incorrect!"); 135 Assert.assertEquals(b[i], f.apply(a, i), "at index #" + i); 136 } 137 } 138 139 interface FReductionMaskedOp { 140 float apply(float[] a, int idx, boolean[] mask); 141 } 142 143 interface FReductionAllMaskedOp { 144 float apply(float[] a, boolean[] mask); 145 } 146 147 static void assertReductionArraysEqualsMasked(float[] a, float[] b, float c, boolean[] mask, 148 FReductionMaskedOp f, FReductionAllMaskedOp fa) { 149 int i = 0; 150 try { 151 Assert.assertEquals(c, fa.apply(a, mask)); 152 for (; i < a.length; i += SPECIES.length()) { 153 Assert.assertEquals(b[i], f.apply(a, i, mask)); 154 } 155 } catch (AssertionError e) { 156 Assert.assertEquals(c, fa.apply(a, mask), "Final result is incorrect!"); 157 Assert.assertEquals(b[i], f.apply(a, i, mask), "at index #" + i); 158 } 159 } 160 161 interface FBoolReductionOp { 162 boolean apply(boolean[] a, int idx); 163 } 164 165 static void assertReductionBoolArraysEquals(boolean[] a, boolean[] b, FBoolReductionOp f) { 166 int i = 0; 167 try { 168 for (; i < a.length; i += SPECIES.length()) { 169 Assert.assertEquals(b[i], f.apply(a, i)); 170 } 171 } catch (AssertionError e) { 172 Assert.assertEquals(b[i], f.apply(a, i), "at index #" + i); 173 } 174 } 175 176 static void assertInsertArraysEquals(float[] a, float[] b, float element, int index) { 177 int i = 0; 178 try { 179 for (; i < a.length; i += 1) { 180 if(i%SPECIES.length() == index) { 181 Assert.assertEquals(b[i], element); 182 } else { 183 Assert.assertEquals(b[i], a[i]); 184 } 185 } 186 } catch (AssertionError e) { 187 if (i%SPECIES.length() == index) { 188 Assert.assertEquals(b[i], element, "at index #" + i); 189 } else { 190 Assert.assertEquals(b[i], a[i], "at index #" + i); 191 } 192 } 193 } 194 195 static void assertRearrangeArraysEquals(float[] a, float[] r, int[] order, int vector_len) { 196 int i = 0, j = 0; 197 try { 198 for (; i < a.length; i += vector_len) { 199 for (j = 0; j < vector_len; j++) { 200 Assert.assertEquals(r[i+j], a[i+order[i+j]]); 201 } 202 } 203 } catch (AssertionError e) { 204 int idx = i + j; 205 Assert.assertEquals(r[i+j], a[i+order[i+j]], "at index #" + idx + ", input = " + a[i+order[i+j]]); 206 } 207 } 208 209 static void assertBroadcastArraysEquals(float[]a, float[]r) { 210 int i = 0; 211 for (; i < a.length; i += SPECIES.length()) { 212 int idx = i; 213 for (int j = idx; j < (idx + SPECIES.length()); j++) 214 a[j]=a[idx]; 215 } 216 217 try { 218 for (i = 0; i < a.length; i++) { 219 Assert.assertEquals(r[i], a[i]); 220 } 221 } catch (AssertionError e) { 222 Assert.assertEquals(r[i], a[i], "at index #" + i + ", input = " + a[i]); 223 } 224 } 225 226 interface FBinOp { 227 float apply(float a, float b); 228 } 229 230 interface FBinMaskOp { 231 float apply(float a, float b, boolean m); 232 233 static FBinMaskOp lift(FBinOp f) { 234 return (a, b, m) -> m ? f.apply(a, b) : a; 235 } 236 } 237 238 static void assertArraysEquals(float[] a, float[] b, float[] r, FBinOp f) { 239 int i = 0; 240 try { 241 for (; i < a.length; i++) { 242 Assert.assertEquals(r[i], f.apply(a[i], b[i])); 243 } 244 } catch (AssertionError e) { 245 Assert.assertEquals(r[i], f.apply(a[i], b[i]), "(" + a[i] + ", " + b[i] + ") at index #" + i); 246 } 247 } 248 249 static void assertBroadcastArraysEquals(float[] a, float[] b, float[] r, FBinOp f) { 250 int i = 0; 251 try { 252 for (; i < a.length; i++) { 253 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()])); 254 } 255 } catch (AssertionError e) { 256 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()]), "(" + a[i] + ", " + b[(i / SPECIES.length()) * SPECIES.length()] + ") at index #" + i); 257 } 258 } 259 260 static void assertArraysEquals(float[] a, float[] b, float[] r, boolean[] mask, FBinOp f) { 261 assertArraysEquals(a, b, r, mask, FBinMaskOp.lift(f)); 262 } 263 264 static void assertArraysEquals(float[] a, float[] b, float[] r, boolean[] mask, FBinMaskOp f) { 265 int i = 0; 266 try { 267 for (; i < a.length; i++) { 268 Assert.assertEquals(r[i], f.apply(a[i], b[i], mask[i % SPECIES.length()])); 269 } 270 } catch (AssertionError err) { 271 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()]); 272 } 273 } 274 275 static void assertBroadcastArraysEquals(float[] a, float[] b, float[] r, boolean[] mask, FBinOp f) { 276 assertBroadcastArraysEquals(a, b, r, mask, FBinMaskOp.lift(f)); 277 } 278 279 static void assertBroadcastArraysEquals(float[] a, float[] b, float[] r, boolean[] mask, FBinMaskOp f) { 280 int i = 0; 281 try { 282 for (; i < a.length; i++) { 283 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], mask[i % SPECIES.length()])); 284 } 285 } catch (AssertionError err) { 286 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], mask[i % SPECIES.length()]), "at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[(i / SPECIES.length()) * SPECIES.length()] + ", mask = " + mask[i % SPECIES.length()]); 287 } 288 } 289 290 static void assertShiftArraysEquals(float[] a, float[] b, float[] r, FBinOp f) { 291 int i = 0; 292 int j = 0; 293 try { 294 for (; j < a.length; j += SPECIES.length()) { 295 for (i = 0; i < SPECIES.length(); i++) { 296 Assert.assertEquals(r[i+j], f.apply(a[i+j], b[j])); 297 } 298 } 299 } catch (AssertionError e) { 300 Assert.assertEquals(r[i+j], f.apply(a[i+j], b[j]), "at index #" + i + ", " + j); 301 } 302 } 303 304 static void assertShiftArraysEquals(float[] a, float[] b, float[] r, boolean[] mask, FBinOp f) { 305 assertShiftArraysEquals(a, b, r, mask, FBinMaskOp.lift(f)); 306 } 307 308 static void assertShiftArraysEquals(float[] a, float[] b, float[] r, boolean[] mask, FBinMaskOp f) { 309 int i = 0; 310 int j = 0; 311 try { 312 for (; j < a.length; j += SPECIES.length()) { 313 for (i = 0; i < SPECIES.length(); i++) { 314 Assert.assertEquals(r[i+j], f.apply(a[i+j], b[j], mask[i])); 315 } 316 } 317 } catch (AssertionError err) { 318 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]); 319 } 320 } 321 322 interface FTernOp { 323 float apply(float a, float b, float c); 324 } 325 326 interface FTernMaskOp { 327 float apply(float a, float b, float c, boolean m); 328 329 static FTernMaskOp lift(FTernOp f) { 330 return (a, b, c, m) -> m ? f.apply(a, b, c) : a; 331 } 332 } 333 334 static void assertArraysEquals(float[] a, float[] b, float[] c, float[] r, FTernOp f) { 335 int i = 0; 336 try { 337 for (; i < a.length; i++) { 338 Assert.assertEquals(r[i], f.apply(a[i], b[i], c[i])); 339 } 340 } catch (AssertionError e) { 341 Assert.assertEquals(r[i], f.apply(a[i], b[i], c[i]), "at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]); 342 } 343 } 344 345 static void assertArraysEquals(float[] a, float[] b, float[] c, float[] r, boolean[] mask, FTernOp f) { 346 assertArraysEquals(a, b, c, r, mask, FTernMaskOp.lift(f)); 347 } 348 349 static void assertArraysEquals(float[] a, float[] b, float[] c, float[] r, boolean[] mask, FTernMaskOp f) { 350 int i = 0; 351 try { 352 for (; i < a.length; i++) { 353 Assert.assertEquals(r[i], f.apply(a[i], b[i], c[i], mask[i % SPECIES.length()])); 354 } 355 } catch (AssertionError err) { 356 Assert.assertEquals(r[i], f.apply(a[i], b[i], c[i], mask[i % SPECIES.length()]), "at index #" + i + ", input1 = " + a[i] + ", input2 = " 357 + b[i] + ", input3 = " + c[i] + ", mask = " + mask[i % SPECIES.length()]); 358 } 359 } 360 361 static boolean isWithin1Ulp(float actual, float expected) { 362 if (Float.isNaN(expected) && !Float.isNaN(actual)) { 363 return false; 364 } else if (!Float.isNaN(expected) && Float.isNaN(actual)) { 365 return false; 366 } 367 368 float low = Math.nextDown(expected); 369 float high = Math.nextUp(expected); 370 371 if (Float.compare(low, expected) > 0) { 372 return false; 373 } 374 375 if (Float.compare(high, expected) < 0) { 376 return false; 377 } 378 379 return true; 380 } 381 382 static void assertArraysEqualsWithinOneUlp(float[] a, float[] r, FUnOp mathf, FUnOp strictmathf) { 383 int i = 0; 384 try { 385 // Check that result is within 1 ulp of strict math or equivalent to math implementation. 386 for (; i < a.length; i++) { 387 Assert.assertTrue(Float.compare(r[i], mathf.apply(a[i])) == 0 || 388 isWithin1Ulp(r[i], strictmathf.apply(a[i]))); 389 } 390 } catch (AssertionError e) { 391 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])); 392 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])); 393 } 394 } 395 396 static void assertArraysEqualsWithinOneUlp(float[] a, float[] b, float[] r, FBinOp mathf, FBinOp strictmathf) { 397 int i = 0; 398 try { 399 // Check that result is within 1 ulp of strict math or equivalent to math implementation. 400 for (; i < a.length; i++) { 401 Assert.assertTrue(Float.compare(r[i], mathf.apply(a[i], b[i])) == 0 || 402 isWithin1Ulp(r[i], strictmathf.apply(a[i], b[i]))); 403 } 404 } catch (AssertionError e) { 405 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])); 406 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])); 407 } 408 } 409 410 interface FBinArrayOp { 411 float apply(float[] a, int b); 412 } 413 414 static void assertArraysEquals(float[] a, float[] r, FBinArrayOp f) { 415 int i = 0; 416 try { 417 for (; i < a.length; i++) { 418 Assert.assertEquals(r[i], f.apply(a, i)); 419 } 420 } catch (AssertionError e) { 421 Assert.assertEquals(r[i], f.apply(a,i), "at index #" + i); 422 } 423 } 424 425 interface FGatherScatterOp { 426 float[] apply(float[] a, int ix, int[] b, int iy); 427 } 428 429 static void assertArraysEquals(float[] a, int[] b, float[] r, FGatherScatterOp f) { 430 int i = 0; 431 try { 432 for (; i < a.length; i += SPECIES.length()) { 433 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()), 434 f.apply(a, i, b, i)); 435 } 436 } catch (AssertionError e) { 437 float[] ref = f.apply(a, i, b, i); 438 float[] res = Arrays.copyOfRange(r, i, i+SPECIES.length()); 439 Assert.assertEquals(res, ref, 440 "(ref: " + Arrays.toString(ref) + ", res: " + Arrays.toString(res) + ", a: " 441 + Arrays.toString(Arrays.copyOfRange(a, i, i+SPECIES.length())) 442 + ", b: " 443 + Arrays.toString(Arrays.copyOfRange(b, i, i+SPECIES.length())) 444 + " at index #" + i); 445 } 446 } 447 448 interface FGatherMaskedOp { 449 float[] apply(float[] a, int ix, boolean[] mask, int[] b, int iy); 450 } 451 452 interface FScatterMaskedOp { 453 float[] apply(float[] r, float[] a, int ix, boolean[] mask, int[] b, int iy); 454 } 455 456 static void assertArraysEquals(float[] a, int[] b, float[] r, boolean[] mask, FGatherMaskedOp f) { 457 int i = 0; 458 try { 459 for (; i < a.length; i += SPECIES.length()) { 460 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()), 461 f.apply(a, i, mask, b, i)); 462 } 463 } catch (AssertionError e) { 464 float[] ref = f.apply(a, i, mask, b, i); 465 float[] res = Arrays.copyOfRange(r, i, i+SPECIES.length()); 466 Assert.assertEquals(ref, res, 467 "(ref: " + Arrays.toString(ref) + ", res: " + Arrays.toString(res) + ", a: " 468 + Arrays.toString(Arrays.copyOfRange(a, i, i+SPECIES.length())) 469 + ", b: " 470 + Arrays.toString(Arrays.copyOfRange(b, i, i+SPECIES.length())) 471 + ", mask: " 472 + Arrays.toString(mask) 473 + " at index #" + i); 474 } 475 } 476 477 static void assertArraysEquals(float[] a, int[] b, float[] r, boolean[] mask, FScatterMaskedOp f) { 478 int i = 0; 479 try { 480 for (; i < a.length; i += SPECIES.length()) { 481 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()), 482 f.apply(r, a, i, mask, b, i)); 483 } 484 } catch (AssertionError e) { 485 float[] ref = f.apply(r, a, i, mask, b, i); 486 float[] res = Arrays.copyOfRange(r, i, i+SPECIES.length()); 487 Assert.assertEquals(ref, res, 488 "(ref: " + Arrays.toString(ref) + ", res: " + Arrays.toString(res) + ", a: " 489 + Arrays.toString(Arrays.copyOfRange(a, i, i+SPECIES.length())) 490 + ", b: " 491 + Arrays.toString(Arrays.copyOfRange(b, i, i+SPECIES.length())) 492 + ", r: " 493 + Arrays.toString(Arrays.copyOfRange(r, i, i+SPECIES.length())) 494 + ", mask: " 495 + Arrays.toString(mask) 496 + " at index #" + i); 497 } 498 } 499 500 interface FLaneOp { 501 float[] apply(float[] a, int origin, int idx); 502 } 503 504 static void assertArraysEquals(float[] a, float[] r, int origin, FLaneOp f) { 505 int i = 0; 506 try { 507 for (; i < a.length; i += SPECIES.length()) { 508 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()), 509 f.apply(a, origin, i)); 510 } 511 } catch (AssertionError e) { 512 float[] ref = f.apply(a, origin, i); 513 float[] res = Arrays.copyOfRange(r, i, i+SPECIES.length()); 514 Assert.assertEquals(ref, res, "(ref: " + Arrays.toString(ref) 515 + ", res: " + Arrays.toString(res) 516 + "), at index #" + i); 517 } 518 } 519 520 interface FLaneBop { 521 float[] apply(float[] a, float[] b, int origin, int idx); 522 } 523 524 static void assertArraysEquals(float[] a, float[] b, float[] r, int origin, FLaneBop f) { 525 int i = 0; 526 try { 527 for (; i < a.length; i += SPECIES.length()) { 528 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()), 529 f.apply(a, b, origin, i)); 530 } 531 } catch (AssertionError e) { 532 float[] ref = f.apply(a, b, origin, i); 533 float[] res = Arrays.copyOfRange(r, i, i+SPECIES.length()); 534 Assert.assertEquals(ref, res, "(ref: " + Arrays.toString(ref) 535 + ", res: " + Arrays.toString(res) 536 + "), at index #" + i 537 + ", at origin #" + origin); 538 } 539 } 540 541 interface FLaneMaskedBop { 542 float[] apply(float[] a, float[] b, int origin, boolean[] mask, int idx); 543 } 544 545 static void assertArraysEquals(float[] a, float[] b, float[] r, int origin, boolean[] mask, FLaneMaskedBop f) { 546 int i = 0; 547 try { 548 for (; i < a.length; i += SPECIES.length()) { 549 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()), 550 f.apply(a, b, origin, mask, i)); 551 } 552 } catch (AssertionError e) { 553 float[] ref = f.apply(a, b, origin, mask, i); 554 float[] res = Arrays.copyOfRange(r, i, i+SPECIES.length()); 555 Assert.assertEquals(ref, res, "(ref: " + Arrays.toString(ref) 556 + ", res: " + Arrays.toString(res) 557 + "), at index #" + i 558 + ", at origin #" + origin); 559 } 560 } 561 562 interface FLanePartBop { 563 float[] apply(float[] a, float[] b, int origin, int part, int idx); 564 } 565 566 static void assertArraysEquals(float[] a, float[] b, float[] r, int origin, int part, FLanePartBop f) { 567 int i = 0; 568 try { 569 for (; i < a.length; i += SPECIES.length()) { 570 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()), 571 f.apply(a, b, origin, part, i)); 572 } 573 } catch (AssertionError e) { 574 float[] ref = f.apply(a, b, origin, part, i); 575 float[] res = Arrays.copyOfRange(r, i, i+SPECIES.length()); 576 Assert.assertEquals(ref, res, "(ref: " + Arrays.toString(ref) 577 + ", res: " + Arrays.toString(res) 578 + "), at index #" + i 579 + ", at origin #" + origin 580 + ", with part #" + part); 581 } 582 } 583 584 interface FLanePartMaskedBop { 585 float[] apply(float[] a, float[] b, int origin, int part, boolean[] mask, int idx); 586 } 587 588 static void assertArraysEquals(float[] a, float[] b, float[] r, int origin, int part, boolean[] mask, FLanePartMaskedBop f) { 589 int i = 0; 590 try { 591 for (; i < a.length; i += SPECIES.length()) { 592 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()), 593 f.apply(a, b, origin, part, mask, i)); 594 } 595 } catch (AssertionError e) { 596 float[] ref = f.apply(a, b, origin, part, mask, i); 597 float[] res = Arrays.copyOfRange(r, i, i+SPECIES.length()); 598 Assert.assertEquals(ref, res, "(ref: " + Arrays.toString(ref) 599 + ", res: " + Arrays.toString(res) 600 + "), at index #" + i 601 + ", at origin #" + origin 602 + ", with part #" + part); 603 } 604 } 605 606 static int bits(float e) { 607 return Float.floatToIntBits(e); 608 } 609 610 static final List<IntFunction<float[]>> FLOAT_GENERATORS = List.of( 611 withToString("float[-i * 5]", (int s) -> { 612 return fill(s * BUFFER_REPS, 613 i -> (float)(-i * 5)); 614 }), 615 withToString("float[i * 5]", (int s) -> { 616 return fill(s * BUFFER_REPS, 617 i -> (float)(i * 5)); 618 }), 619 withToString("float[i + 1]", (int s) -> { 620 return fill(s * BUFFER_REPS, 621 i -> (((float)(i + 1) == 0) ? 1 : (float)(i + 1))); 622 }), 623 withToString("float[cornerCaseValue(i)]", (int s) -> { 624 return fill(s * BUFFER_REPS, 625 i -> cornerCaseValue(i)); 626 }) 627 ); 628 629 // Create combinations of pairs 630 // @@@ Might be sensitive to order e.g. div by 0 631 static final List<List<IntFunction<float[]>>> FLOAT_GENERATOR_PAIRS = 632 Stream.of(FLOAT_GENERATORS.get(0)). 633 flatMap(fa -> FLOAT_GENERATORS.stream().skip(1).map(fb -> List.of(fa, fb))). 634 collect(Collectors.toList()); 635 636 @DataProvider 637 public Object[][] boolUnaryOpProvider() { 638 return BOOL_ARRAY_GENERATORS.stream(). 639 map(f -> new Object[]{f}). 640 toArray(Object[][]::new); 641 } 642 643 static final List<List<IntFunction<float[]>>> FLOAT_GENERATOR_TRIPLES = 644 FLOAT_GENERATOR_PAIRS.stream(). 645 flatMap(pair -> FLOAT_GENERATORS.stream().map(f -> List.of(pair.get(0), pair.get(1), f))). 646 collect(Collectors.toList()); 647 648 @DataProvider 649 public Object[][] floatBinaryOpProvider() { 650 return FLOAT_GENERATOR_PAIRS.stream().map(List::toArray). 651 toArray(Object[][]::new); 652 } 653 654 @DataProvider 655 public Object[][] floatIndexedOpProvider() { 656 return FLOAT_GENERATOR_PAIRS.stream().map(List::toArray). 657 toArray(Object[][]::new); 658 } 659 660 @DataProvider 661 public Object[][] floatBinaryOpMaskProvider() { 662 return BOOLEAN_MASK_GENERATORS.stream(). 663 flatMap(fm -> FLOAT_GENERATOR_PAIRS.stream().map(lfa -> { 664 return Stream.concat(lfa.stream(), Stream.of(fm)).toArray(); 665 })). 666 toArray(Object[][]::new); 667 } 668 669 @DataProvider 670 public Object[][] floatTernaryOpProvider() { 671 return FLOAT_GENERATOR_TRIPLES.stream().map(List::toArray). 672 toArray(Object[][]::new); 673 } 674 675 @DataProvider 676 public Object[][] floatTernaryOpMaskProvider() { 677 return BOOLEAN_MASK_GENERATORS.stream(). 678 flatMap(fm -> FLOAT_GENERATOR_TRIPLES.stream().map(lfa -> { 679 return Stream.concat(lfa.stream(), Stream.of(fm)).toArray(); 680 })). 681 toArray(Object[][]::new); 682 } 683 684 @DataProvider 685 public Object[][] floatUnaryOpProvider() { 686 return FLOAT_GENERATORS.stream(). 687 map(f -> new Object[]{f}). 688 toArray(Object[][]::new); 689 } 690 691 @DataProvider 692 public Object[][] floatUnaryOpMaskProvider() { 693 return BOOLEAN_MASK_GENERATORS.stream(). 694 flatMap(fm -> FLOAT_GENERATORS.stream().map(fa -> { 695 return new Object[] {fa, fm}; 696 })). 697 toArray(Object[][]::new); 698 } 699 700 @DataProvider 701 public Object[][] floatUnaryOpShuffleProvider() { 702 return INT_SHUFFLE_GENERATORS.stream(). 703 flatMap(fs -> FLOAT_GENERATORS.stream().map(fa -> { 704 return new Object[] {fa, fs}; 705 })). 706 toArray(Object[][]::new); 707 } 708 709 @DataProvider 710 public Object[][] floatUnaryOpIndexProvider() { 711 return INT_INDEX_GENERATORS.stream(). 712 flatMap(fs -> FLOAT_GENERATORS.stream().map(fa -> { 713 return new Object[] {fa, fs}; 714 })). 715 toArray(Object[][]::new); 716 } 717 718 @DataProvider 719 public Object[][] floatUnaryMaskedOpIndexProvider() { 720 return BOOLEAN_MASK_GENERATORS.stream(). 721 flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> 722 FLOAT_GENERATORS.stream().map(fa -> { 723 return new Object[] {fa, fm, fs}; 724 }))). 725 toArray(Object[][]::new); 726 } 727 728 @DataProvider 729 public Object[][] scatterMaskedOpIndexProvider() { 730 return BOOLEAN_MASK_GENERATORS.stream(). 731 flatMap(fs -> INT_INDEX_GENERATORS.stream().flatMap(fm -> 732 FLOAT_GENERATORS.stream().flatMap(fn -> 733 FLOAT_GENERATORS.stream().map(fa -> { 734 return new Object[] {fa, fn, fm, fs}; 735 })))). 736 toArray(Object[][]::new); 737 } 738 739 static final List<IntFunction<float[]>> FLOAT_COMPARE_GENERATORS = List.of( 740 withToString("float[i]", (int s) -> { 741 return fill(s * BUFFER_REPS, 742 i -> (float)i); 743 }), 744 withToString("float[i + 1]", (int s) -> { 745 return fill(s * BUFFER_REPS, 746 i -> (float)(i + 1)); 747 }), 748 withToString("float[i - 2]", (int s) -> { 749 return fill(s * BUFFER_REPS, 750 i -> (float)(i - 2)); 751 }), 752 withToString("float[zigZag(i)]", (int s) -> { 753 return fill(s * BUFFER_REPS, 754 i -> i%3 == 0 ? (float)i : (i%3 == 1 ? (float)(i + 1) : (float)(i - 2))); 755 }), 756 withToString("float[cornerCaseValue(i)]", (int s) -> { 757 return fill(s * BUFFER_REPS, 758 i -> cornerCaseValue(i)); 759 }) 760 ); 761 762 static final List<List<IntFunction<float[]>>> FLOAT_TEST_GENERATOR_ARGS = 763 FLOAT_COMPARE_GENERATORS.stream(). 764 map(fa -> List.of(fa)). 765 collect(Collectors.toList()); 766 767 @DataProvider 768 public Object[][] floatTestOpProvider() { 769 return FLOAT_TEST_GENERATOR_ARGS.stream().map(List::toArray). 770 toArray(Object[][]::new); 771 } 772 773 static final List<List<IntFunction<float[]>>> FLOAT_COMPARE_GENERATOR_PAIRS = 774 FLOAT_COMPARE_GENERATORS.stream(). 775 flatMap(fa -> FLOAT_COMPARE_GENERATORS.stream().map(fb -> List.of(fa, fb))). 776 collect(Collectors.toList()); 777 778 @DataProvider 779 public Object[][] floatCompareOpProvider() { 780 return FLOAT_COMPARE_GENERATOR_PAIRS.stream().map(List::toArray). 781 toArray(Object[][]::new); 782 } 783 784 interface ToFloatF { 785 float apply(int i); 786 } 787 788 static float[] fill(int s , ToFloatF f) { 789 return fill(new float[s], f); 790 } 791 792 static float[] fill(float[] a, ToFloatF f) { 793 for (int i = 0; i < a.length; i++) { 794 a[i] = f.apply(i); 795 } 796 return a; 797 } 798 799 static float cornerCaseValue(int i) { 800 switch(i % 7) { 801 case 0: 802 return Float.MAX_VALUE; 803 case 1: 804 return Float.MIN_VALUE; 805 case 2: 806 return Float.NEGATIVE_INFINITY; 807 case 3: 808 return Float.POSITIVE_INFINITY; 809 case 4: 810 return Float.NaN; 811 case 5: 812 return (float)0.0; 813 default: 814 return (float)-0.0; 815 } 816 } 817 static float get(float[] a, int i) { 818 return (float) a[i]; 819 } 820 821 static final IntFunction<float[]> fr = (vl) -> { 822 int length = BUFFER_REPS * vl; 823 return new float[length]; 824 }; 825 826 static final IntFunction<boolean[]> fmr = (vl) -> { 827 int length = BUFFER_REPS * vl; 828 return new boolean[length]; 829 }; 830 831 832 @Test 833 static void smokeTest1() { 834 FloatVector three = FloatVector.broadcast(SPECIES, (byte)-3); 835 FloatVector three2 = (FloatVector) SPECIES.broadcast(-3); 836 assert(three.eq(three2).allTrue()); 837 FloatVector three3 = three2.broadcast(1).broadcast(-3); 838 assert(three.eq(three3).allTrue()); 839 int scale = 2; 840 Class<?> ETYPE = float.class; 841 if (ETYPE == double.class || ETYPE == long.class) 842 scale = 1000000; 843 else if (ETYPE == byte.class && SPECIES.length() >= 64) 844 scale = 1; 845 FloatVector higher = three.addIndex(scale); 846 VectorMask<Float> m = three.compare(VectorOperators.LE, higher); 847 assert(m.allTrue()); 848 m = higher.min((float)-1).test(VectorOperators.IS_NEGATIVE); 849 assert(m.allTrue()); 850 m = higher.test(VectorOperators.IS_FINITE); 851 assert(m.allTrue()); 852 float max = higher.reduceLanes(VectorOperators.MAX); 853 assert(max == -3 + scale * (SPECIES.length()-1)); 854 } 855 856 private static float[] 857 bothToArray(FloatVector a, FloatVector b) { 858 float[] r = new float[a.length() + b.length()]; 859 a.intoArray(r, 0); 860 b.intoArray(r, a.length()); 861 return r; 862 } 863 864 @Test 865 static void smokeTest2() { 866 // Do some zipping and shuffling. 867 FloatVector io = (FloatVector) SPECIES.broadcast(0).addIndex(1); 868 FloatVector io2 = (FloatVector) VectorShuffle.iota(SPECIES,0,1,false).toVector(); 869 Assert.assertEquals(io, io2); 870 FloatVector a = io.add((float)1); //[1,2] 871 FloatVector b = a.neg(); //[-1,-2] 872 float[] abValues = bothToArray(a,b); //[1,2,-1,-2] 873 VectorShuffle<Float> zip0 = VectorShuffle.makeZip(SPECIES, 0); 874 VectorShuffle<Float> zip1 = VectorShuffle.makeZip(SPECIES, 1); 875 FloatVector zab0 = a.rearrange(zip0,b); //[1,-1] 876 FloatVector zab1 = a.rearrange(zip1,b); //[2,-2] 877 float[] zabValues = bothToArray(zab0, zab1); //[1,-1,2,-2] 878 // manually zip 879 float[] manual = new float[zabValues.length]; 880 for (int i = 0; i < manual.length; i += 2) { 881 manual[i+0] = abValues[i/2]; 882 manual[i+1] = abValues[a.length() + i/2]; 883 } 884 Assert.assertEquals(Arrays.toString(zabValues), Arrays.toString(manual)); 885 VectorShuffle<Float> unz0 = VectorShuffle.makeUnzip(SPECIES, 0); 886 VectorShuffle<Float> unz1 = VectorShuffle.makeUnzip(SPECIES, 1); 887 FloatVector uab0 = zab0.rearrange(unz0,zab1); 888 FloatVector uab1 = zab0.rearrange(unz1,zab1); 889 float[] abValues1 = bothToArray(uab0, uab1); 890 Assert.assertEquals(Arrays.toString(abValues), Arrays.toString(abValues1)); 891 } 892 893 static void iotaShuffle() { 894 FloatVector io = (FloatVector) SPECIES.broadcast(0).addIndex(1); 895 FloatVector io2 = (FloatVector) VectorShuffle.iota(SPECIES, 0 , 1, false).toVector(); 896 Assert.assertEquals(io, io2); 897 } 898 899 @Test 900 // Test all shuffle related operations. 901 static void shuffleTest() { 902 // To test backend instructions, make sure that C2 is used. 903 for (int loop = 0; loop < INVOC_COUNT * INVOC_COUNT; loop++) { 904 iotaShuffle(); 905 } 906 } 907 908 @Test 909 void viewAsIntegeralLanesTest() { 910 Vector<?> asIntegral = SPECIES.zero().viewAsIntegralLanes(); 911 VectorSpecies<?> asIntegralSpecies = asIntegral.species(); 912 Assert.assertNotEquals(asIntegralSpecies.elementType(), SPECIES.elementType()); 913 Assert.assertEquals(asIntegralSpecies.vectorShape(), SPECIES.vectorShape()); 914 Assert.assertEquals(asIntegralSpecies.length(), SPECIES.length()); 915 Assert.assertEquals(asIntegral.viewAsFloatingLanes().species(), SPECIES); 916 } 917 918 @Test 919 void viewAsFloatingLanesTest() { 920 Vector<?> asFloating = SPECIES.zero().viewAsFloatingLanes(); 921 Assert.assertEquals(asFloating.species(), SPECIES); 922 } 923 924 static float ADD(float a, float b) { 925 return (float)(a + b); 926 } 927 928 @Test(dataProvider = "floatBinaryOpProvider") 929 static void ADDFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) { 930 float[] a = fa.apply(SPECIES.length()); 931 float[] b = fb.apply(SPECIES.length()); 932 float[] r = fr.apply(SPECIES.length()); 933 934 for (int ic = 0; ic < INVOC_COUNT; ic++) { 935 for (int i = 0; i < a.length; i += SPECIES.length()) { 936 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 937 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 938 av.lanewise(VectorOperators.ADD, bv).intoArray(r, i); 939 } 940 } 941 942 assertArraysEquals(a, b, r, FloatMaxVectorTests::ADD); 943 } 944 static float add(float a, float b) { 945 return (float)(a + b); 946 } 947 948 @Test(dataProvider = "floatBinaryOpProvider") 949 static void addFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) { 950 float[] a = fa.apply(SPECIES.length()); 951 float[] b = fb.apply(SPECIES.length()); 952 float[] r = fr.apply(SPECIES.length()); 953 954 for (int ic = 0; ic < INVOC_COUNT; ic++) { 955 for (int i = 0; i < a.length; i += SPECIES.length()) { 956 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 957 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 958 av.add(bv).intoArray(r, i); 959 } 960 } 961 962 assertArraysEquals(a, b, r, FloatMaxVectorTests::add); 963 } 964 965 @Test(dataProvider = "floatBinaryOpMaskProvider") 966 static void ADDFloatMaxVectorTestsMasked(IntFunction<float[]> fa, IntFunction<float[]> fb, 967 IntFunction<boolean[]> fm) { 968 float[] a = fa.apply(SPECIES.length()); 969 float[] b = fb.apply(SPECIES.length()); 970 float[] r = fr.apply(SPECIES.length()); 971 boolean[] mask = fm.apply(SPECIES.length()); 972 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0); 973 974 for (int ic = 0; ic < INVOC_COUNT; ic++) { 975 for (int i = 0; i < a.length; i += SPECIES.length()) { 976 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 977 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 978 av.lanewise(VectorOperators.ADD, bv, vmask).intoArray(r, i); 979 } 980 } 981 982 assertArraysEquals(a, b, r, mask, FloatMaxVectorTests::ADD); 983 } 984 985 @Test(dataProvider = "floatBinaryOpMaskProvider") 986 static void addFloatMaxVectorTestsMasked(IntFunction<float[]> fa, IntFunction<float[]> fb, 987 IntFunction<boolean[]> fm) { 988 float[] a = fa.apply(SPECIES.length()); 989 float[] b = fb.apply(SPECIES.length()); 990 float[] r = fr.apply(SPECIES.length()); 991 boolean[] mask = fm.apply(SPECIES.length()); 992 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0); 993 994 for (int ic = 0; ic < INVOC_COUNT; ic++) { 995 for (int i = 0; i < a.length; i += SPECIES.length()) { 996 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 997 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 998 av.add(bv, vmask).intoArray(r, i); 999 } 1000 } 1001 1002 assertArraysEquals(a, b, r, mask, FloatMaxVectorTests::add); 1003 } 1004 static float SUB(float a, float b) { 1005 return (float)(a - b); 1006 } 1007 1008 @Test(dataProvider = "floatBinaryOpProvider") 1009 static void SUBFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) { 1010 float[] a = fa.apply(SPECIES.length()); 1011 float[] b = fb.apply(SPECIES.length()); 1012 float[] r = fr.apply(SPECIES.length()); 1013 1014 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1015 for (int i = 0; i < a.length; i += SPECIES.length()) { 1016 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1017 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 1018 av.lanewise(VectorOperators.SUB, bv).intoArray(r, i); 1019 } 1020 } 1021 1022 assertArraysEquals(a, b, r, FloatMaxVectorTests::SUB); 1023 } 1024 static float sub(float a, float b) { 1025 return (float)(a - b); 1026 } 1027 1028 @Test(dataProvider = "floatBinaryOpProvider") 1029 static void subFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) { 1030 float[] a = fa.apply(SPECIES.length()); 1031 float[] b = fb.apply(SPECIES.length()); 1032 float[] r = fr.apply(SPECIES.length()); 1033 1034 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1035 for (int i = 0; i < a.length; i += SPECIES.length()) { 1036 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1037 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 1038 av.sub(bv).intoArray(r, i); 1039 } 1040 } 1041 1042 assertArraysEquals(a, b, r, FloatMaxVectorTests::sub); 1043 } 1044 1045 @Test(dataProvider = "floatBinaryOpMaskProvider") 1046 static void SUBFloatMaxVectorTestsMasked(IntFunction<float[]> fa, IntFunction<float[]> fb, 1047 IntFunction<boolean[]> fm) { 1048 float[] a = fa.apply(SPECIES.length()); 1049 float[] b = fb.apply(SPECIES.length()); 1050 float[] r = fr.apply(SPECIES.length()); 1051 boolean[] mask = fm.apply(SPECIES.length()); 1052 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1053 1054 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1055 for (int i = 0; i < a.length; i += SPECIES.length()) { 1056 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1057 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 1058 av.lanewise(VectorOperators.SUB, bv, vmask).intoArray(r, i); 1059 } 1060 } 1061 1062 assertArraysEquals(a, b, r, mask, FloatMaxVectorTests::SUB); 1063 } 1064 1065 @Test(dataProvider = "floatBinaryOpMaskProvider") 1066 static void subFloatMaxVectorTestsMasked(IntFunction<float[]> fa, IntFunction<float[]> fb, 1067 IntFunction<boolean[]> fm) { 1068 float[] a = fa.apply(SPECIES.length()); 1069 float[] b = fb.apply(SPECIES.length()); 1070 float[] r = fr.apply(SPECIES.length()); 1071 boolean[] mask = fm.apply(SPECIES.length()); 1072 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1073 1074 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1075 for (int i = 0; i < a.length; i += SPECIES.length()) { 1076 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1077 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 1078 av.sub(bv, vmask).intoArray(r, i); 1079 } 1080 } 1081 1082 assertArraysEquals(a, b, r, mask, FloatMaxVectorTests::sub); 1083 } 1084 static float MUL(float a, float b) { 1085 return (float)(a * b); 1086 } 1087 1088 @Test(dataProvider = "floatBinaryOpProvider") 1089 static void MULFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) { 1090 float[] a = fa.apply(SPECIES.length()); 1091 float[] b = fb.apply(SPECIES.length()); 1092 float[] r = fr.apply(SPECIES.length()); 1093 1094 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1095 for (int i = 0; i < a.length; i += SPECIES.length()) { 1096 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1097 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 1098 av.lanewise(VectorOperators.MUL, bv).intoArray(r, i); 1099 } 1100 } 1101 1102 assertArraysEquals(a, b, r, FloatMaxVectorTests::MUL); 1103 } 1104 static float mul(float a, float b) { 1105 return (float)(a * b); 1106 } 1107 1108 @Test(dataProvider = "floatBinaryOpProvider") 1109 static void mulFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) { 1110 float[] a = fa.apply(SPECIES.length()); 1111 float[] b = fb.apply(SPECIES.length()); 1112 float[] r = fr.apply(SPECIES.length()); 1113 1114 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1115 for (int i = 0; i < a.length; i += SPECIES.length()) { 1116 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1117 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 1118 av.mul(bv).intoArray(r, i); 1119 } 1120 } 1121 1122 assertArraysEquals(a, b, r, FloatMaxVectorTests::mul); 1123 } 1124 1125 @Test(dataProvider = "floatBinaryOpMaskProvider") 1126 static void MULFloatMaxVectorTestsMasked(IntFunction<float[]> fa, IntFunction<float[]> fb, 1127 IntFunction<boolean[]> fm) { 1128 float[] a = fa.apply(SPECIES.length()); 1129 float[] b = fb.apply(SPECIES.length()); 1130 float[] r = fr.apply(SPECIES.length()); 1131 boolean[] mask = fm.apply(SPECIES.length()); 1132 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1133 1134 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1135 for (int i = 0; i < a.length; i += SPECIES.length()) { 1136 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1137 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 1138 av.lanewise(VectorOperators.MUL, bv, vmask).intoArray(r, i); 1139 } 1140 } 1141 1142 assertArraysEquals(a, b, r, mask, FloatMaxVectorTests::MUL); 1143 } 1144 1145 @Test(dataProvider = "floatBinaryOpMaskProvider") 1146 static void mulFloatMaxVectorTestsMasked(IntFunction<float[]> fa, IntFunction<float[]> fb, 1147 IntFunction<boolean[]> fm) { 1148 float[] a = fa.apply(SPECIES.length()); 1149 float[] b = fb.apply(SPECIES.length()); 1150 float[] r = fr.apply(SPECIES.length()); 1151 boolean[] mask = fm.apply(SPECIES.length()); 1152 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1153 1154 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1155 for (int i = 0; i < a.length; i += SPECIES.length()) { 1156 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1157 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 1158 av.mul(bv, vmask).intoArray(r, i); 1159 } 1160 } 1161 1162 assertArraysEquals(a, b, r, mask, FloatMaxVectorTests::mul); 1163 } 1164 1165 static float DIV(float a, float b) { 1166 return (float)(a / b); 1167 } 1168 1169 @Test(dataProvider = "floatBinaryOpProvider") 1170 static void DIVFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) { 1171 float[] a = fa.apply(SPECIES.length()); 1172 float[] b = fb.apply(SPECIES.length()); 1173 float[] r = fr.apply(SPECIES.length()); 1174 1175 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1176 for (int i = 0; i < a.length; i += SPECIES.length()) { 1177 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1178 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 1179 av.lanewise(VectorOperators.DIV, bv).intoArray(r, i); 1180 } 1181 } 1182 1183 assertArraysEquals(a, b, r, FloatMaxVectorTests::DIV); 1184 } 1185 static float div(float a, float b) { 1186 return (float)(a / b); 1187 } 1188 1189 @Test(dataProvider = "floatBinaryOpProvider") 1190 static void divFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) { 1191 float[] a = fa.apply(SPECIES.length()); 1192 float[] b = fb.apply(SPECIES.length()); 1193 float[] r = fr.apply(SPECIES.length()); 1194 1195 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1196 for (int i = 0; i < a.length; i += SPECIES.length()) { 1197 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1198 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 1199 av.div(bv).intoArray(r, i); 1200 } 1201 } 1202 1203 assertArraysEquals(a, b, r, FloatMaxVectorTests::div); 1204 } 1205 1206 1207 1208 @Test(dataProvider = "floatBinaryOpMaskProvider") 1209 static void DIVFloatMaxVectorTestsMasked(IntFunction<float[]> fa, IntFunction<float[]> fb, 1210 IntFunction<boolean[]> fm) { 1211 float[] a = fa.apply(SPECIES.length()); 1212 float[] b = fb.apply(SPECIES.length()); 1213 float[] r = fr.apply(SPECIES.length()); 1214 boolean[] mask = fm.apply(SPECIES.length()); 1215 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1216 1217 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1218 for (int i = 0; i < a.length; i += SPECIES.length()) { 1219 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1220 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 1221 av.lanewise(VectorOperators.DIV, bv, vmask).intoArray(r, i); 1222 } 1223 } 1224 1225 assertArraysEquals(a, b, r, mask, FloatMaxVectorTests::DIV); 1226 } 1227 1228 @Test(dataProvider = "floatBinaryOpMaskProvider") 1229 static void divFloatMaxVectorTestsMasked(IntFunction<float[]> fa, IntFunction<float[]> fb, 1230 IntFunction<boolean[]> fm) { 1231 float[] a = fa.apply(SPECIES.length()); 1232 float[] b = fb.apply(SPECIES.length()); 1233 float[] r = fr.apply(SPECIES.length()); 1234 boolean[] mask = fm.apply(SPECIES.length()); 1235 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1236 1237 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1238 for (int i = 0; i < a.length; i += SPECIES.length()) { 1239 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1240 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 1241 av.div(bv, vmask).intoArray(r, i); 1242 } 1243 } 1244 1245 assertArraysEquals(a, b, r, mask, FloatMaxVectorTests::div); 1246 } 1247 1248 1249 1250 static float FIRST_NONZERO(float a, float b) { 1251 return (float)(Double.doubleToLongBits(a)!=0?a:b); 1252 } 1253 1254 @Test(dataProvider = "floatBinaryOpProvider") 1255 static void FIRST_NONZEROFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) { 1256 float[] a = fa.apply(SPECIES.length()); 1257 float[] b = fb.apply(SPECIES.length()); 1258 float[] r = fr.apply(SPECIES.length()); 1259 1260 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1261 for (int i = 0; i < a.length; i += SPECIES.length()) { 1262 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1263 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 1264 av.lanewise(VectorOperators.FIRST_NONZERO, bv).intoArray(r, i); 1265 } 1266 } 1267 1268 assertArraysEquals(a, b, r, FloatMaxVectorTests::FIRST_NONZERO); 1269 } 1270 1271 @Test(dataProvider = "floatBinaryOpMaskProvider") 1272 static void FIRST_NONZEROFloatMaxVectorTestsMasked(IntFunction<float[]> fa, IntFunction<float[]> fb, 1273 IntFunction<boolean[]> fm) { 1274 float[] a = fa.apply(SPECIES.length()); 1275 float[] b = fb.apply(SPECIES.length()); 1276 float[] r = fr.apply(SPECIES.length()); 1277 boolean[] mask = fm.apply(SPECIES.length()); 1278 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1279 1280 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1281 for (int i = 0; i < a.length; i += SPECIES.length()) { 1282 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1283 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 1284 av.lanewise(VectorOperators.FIRST_NONZERO, bv, vmask).intoArray(r, i); 1285 } 1286 } 1287 1288 assertArraysEquals(a, b, r, mask, FloatMaxVectorTests::FIRST_NONZERO); 1289 } 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 @Test(dataProvider = "floatBinaryOpProvider") 1300 static void addFloatMaxVectorTestsBroadcastSmokeTest(IntFunction<float[]> fa, IntFunction<float[]> fb) { 1301 float[] a = fa.apply(SPECIES.length()); 1302 float[] b = fb.apply(SPECIES.length()); 1303 float[] r = fr.apply(SPECIES.length()); 1304 1305 for (int i = 0; i < a.length; i += SPECIES.length()) { 1306 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1307 av.add(b[i]).intoArray(r, i); 1308 } 1309 1310 assertBroadcastArraysEquals(a, b, r, FloatMaxVectorTests::add); 1311 } 1312 1313 @Test(dataProvider = "floatBinaryOpMaskProvider") 1314 static void addFloatMaxVectorTestsBroadcastMaskedSmokeTest(IntFunction<float[]> fa, IntFunction<float[]> fb, 1315 IntFunction<boolean[]> fm) { 1316 float[] a = fa.apply(SPECIES.length()); 1317 float[] b = fb.apply(SPECIES.length()); 1318 float[] r = fr.apply(SPECIES.length()); 1319 boolean[] mask = fm.apply(SPECIES.length()); 1320 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1321 1322 for (int i = 0; i < a.length; i += SPECIES.length()) { 1323 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1324 av.add(b[i], vmask).intoArray(r, i); 1325 } 1326 1327 assertBroadcastArraysEquals(a, b, r, mask, FloatMaxVectorTests::add); 1328 } 1329 1330 @Test(dataProvider = "floatBinaryOpProvider") 1331 static void subFloatMaxVectorTestsBroadcastSmokeTest(IntFunction<float[]> fa, IntFunction<float[]> fb) { 1332 float[] a = fa.apply(SPECIES.length()); 1333 float[] b = fb.apply(SPECIES.length()); 1334 float[] r = fr.apply(SPECIES.length()); 1335 1336 for (int i = 0; i < a.length; i += SPECIES.length()) { 1337 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1338 av.sub(b[i]).intoArray(r, i); 1339 } 1340 1341 assertBroadcastArraysEquals(a, b, r, FloatMaxVectorTests::sub); 1342 } 1343 1344 @Test(dataProvider = "floatBinaryOpMaskProvider") 1345 static void subFloatMaxVectorTestsBroadcastMaskedSmokeTest(IntFunction<float[]> fa, IntFunction<float[]> fb, 1346 IntFunction<boolean[]> fm) { 1347 float[] a = fa.apply(SPECIES.length()); 1348 float[] b = fb.apply(SPECIES.length()); 1349 float[] r = fr.apply(SPECIES.length()); 1350 boolean[] mask = fm.apply(SPECIES.length()); 1351 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1352 1353 for (int i = 0; i < a.length; i += SPECIES.length()) { 1354 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1355 av.sub(b[i], vmask).intoArray(r, i); 1356 } 1357 1358 assertBroadcastArraysEquals(a, b, r, mask, FloatMaxVectorTests::sub); 1359 } 1360 1361 @Test(dataProvider = "floatBinaryOpProvider") 1362 static void mulFloatMaxVectorTestsBroadcastSmokeTest(IntFunction<float[]> fa, IntFunction<float[]> fb) { 1363 float[] a = fa.apply(SPECIES.length()); 1364 float[] b = fb.apply(SPECIES.length()); 1365 float[] r = fr.apply(SPECIES.length()); 1366 1367 for (int i = 0; i < a.length; i += SPECIES.length()) { 1368 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1369 av.mul(b[i]).intoArray(r, i); 1370 } 1371 1372 assertBroadcastArraysEquals(a, b, r, FloatMaxVectorTests::mul); 1373 } 1374 1375 @Test(dataProvider = "floatBinaryOpMaskProvider") 1376 static void mulFloatMaxVectorTestsBroadcastMaskedSmokeTest(IntFunction<float[]> fa, IntFunction<float[]> fb, 1377 IntFunction<boolean[]> fm) { 1378 float[] a = fa.apply(SPECIES.length()); 1379 float[] b = fb.apply(SPECIES.length()); 1380 float[] r = fr.apply(SPECIES.length()); 1381 boolean[] mask = fm.apply(SPECIES.length()); 1382 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1383 1384 for (int i = 0; i < a.length; i += SPECIES.length()) { 1385 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1386 av.mul(b[i], vmask).intoArray(r, i); 1387 } 1388 1389 assertBroadcastArraysEquals(a, b, r, mask, FloatMaxVectorTests::mul); 1390 } 1391 1392 1393 @Test(dataProvider = "floatBinaryOpProvider") 1394 static void divFloatMaxVectorTestsBroadcastSmokeTest(IntFunction<float[]> fa, IntFunction<float[]> fb) { 1395 float[] a = fa.apply(SPECIES.length()); 1396 float[] b = fb.apply(SPECIES.length()); 1397 float[] r = fr.apply(SPECIES.length()); 1398 1399 for (int i = 0; i < a.length; i += SPECIES.length()) { 1400 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1401 av.div(b[i]).intoArray(r, i); 1402 } 1403 1404 assertBroadcastArraysEquals(a, b, r, FloatMaxVectorTests::div); 1405 } 1406 1407 1408 1409 @Test(dataProvider = "floatBinaryOpMaskProvider") 1410 static void divFloatMaxVectorTestsBroadcastMaskedSmokeTest(IntFunction<float[]> fa, IntFunction<float[]> fb, 1411 IntFunction<boolean[]> fm) { 1412 float[] a = fa.apply(SPECIES.length()); 1413 float[] b = fb.apply(SPECIES.length()); 1414 float[] r = fr.apply(SPECIES.length()); 1415 boolean[] mask = fm.apply(SPECIES.length()); 1416 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1417 1418 for (int i = 0; i < a.length; i += SPECIES.length()) { 1419 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1420 av.div(b[i], vmask).intoArray(r, i); 1421 } 1422 1423 assertBroadcastArraysEquals(a, b, r, mask, FloatMaxVectorTests::div); 1424 } 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 static float MIN(float a, float b) { 1467 return (float)(Math.min(a, b)); 1468 } 1469 1470 @Test(dataProvider = "floatBinaryOpProvider") 1471 static void MINFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) { 1472 float[] a = fa.apply(SPECIES.length()); 1473 float[] b = fb.apply(SPECIES.length()); 1474 float[] r = fr.apply(SPECIES.length()); 1475 1476 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1477 for (int i = 0; i < a.length; i += SPECIES.length()) { 1478 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1479 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 1480 av.lanewise(VectorOperators.MIN, bv).intoArray(r, i); 1481 } 1482 } 1483 1484 assertArraysEquals(a, b, r, FloatMaxVectorTests::MIN); 1485 } 1486 static float min(float a, float b) { 1487 return (float)(Math.min(a, b)); 1488 } 1489 1490 @Test(dataProvider = "floatBinaryOpProvider") 1491 static void minFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) { 1492 float[] a = fa.apply(SPECIES.length()); 1493 float[] b = fb.apply(SPECIES.length()); 1494 float[] r = fr.apply(SPECIES.length()); 1495 1496 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1497 for (int i = 0; i < a.length; i += SPECIES.length()) { 1498 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1499 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 1500 av.min(bv).intoArray(r, i); 1501 } 1502 } 1503 1504 assertArraysEquals(a, b, r, FloatMaxVectorTests::min); 1505 } 1506 static float MAX(float a, float b) { 1507 return (float)(Math.max(a, b)); 1508 } 1509 1510 @Test(dataProvider = "floatBinaryOpProvider") 1511 static void MAXFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) { 1512 float[] a = fa.apply(SPECIES.length()); 1513 float[] b = fb.apply(SPECIES.length()); 1514 float[] r = fr.apply(SPECIES.length()); 1515 1516 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1517 for (int i = 0; i < a.length; i += SPECIES.length()) { 1518 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1519 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 1520 av.lanewise(VectorOperators.MAX, bv).intoArray(r, i); 1521 } 1522 } 1523 1524 assertArraysEquals(a, b, r, FloatMaxVectorTests::MAX); 1525 } 1526 static float max(float a, float b) { 1527 return (float)(Math.max(a, b)); 1528 } 1529 1530 @Test(dataProvider = "floatBinaryOpProvider") 1531 static void maxFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) { 1532 float[] a = fa.apply(SPECIES.length()); 1533 float[] b = fb.apply(SPECIES.length()); 1534 float[] r = fr.apply(SPECIES.length()); 1535 1536 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1537 for (int i = 0; i < a.length; i += SPECIES.length()) { 1538 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1539 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 1540 av.max(bv).intoArray(r, i); 1541 } 1542 } 1543 1544 assertArraysEquals(a, b, r, FloatMaxVectorTests::max); 1545 } 1546 1547 @Test(dataProvider = "floatBinaryOpProvider") 1548 static void MINFloatMaxVectorTestsBroadcastSmokeTest(IntFunction<float[]> fa, IntFunction<float[]> fb) { 1549 float[] a = fa.apply(SPECIES.length()); 1550 float[] b = fb.apply(SPECIES.length()); 1551 float[] r = fr.apply(SPECIES.length()); 1552 1553 for (int i = 0; i < a.length; i += SPECIES.length()) { 1554 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1555 av.lanewise(VectorOperators.MIN, b[i]).intoArray(r, i); 1556 } 1557 1558 assertBroadcastArraysEquals(a, b, r, FloatMaxVectorTests::MIN); 1559 } 1560 1561 @Test(dataProvider = "floatBinaryOpProvider") 1562 static void minFloatMaxVectorTestsBroadcastSmokeTest(IntFunction<float[]> fa, IntFunction<float[]> fb) { 1563 float[] a = fa.apply(SPECIES.length()); 1564 float[] b = fb.apply(SPECIES.length()); 1565 float[] r = fr.apply(SPECIES.length()); 1566 1567 for (int i = 0; i < a.length; i += SPECIES.length()) { 1568 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1569 av.min(b[i]).intoArray(r, i); 1570 } 1571 1572 assertBroadcastArraysEquals(a, b, r, FloatMaxVectorTests::min); 1573 } 1574 1575 @Test(dataProvider = "floatBinaryOpProvider") 1576 static void MAXFloatMaxVectorTestsBroadcastSmokeTest(IntFunction<float[]> fa, IntFunction<float[]> fb) { 1577 float[] a = fa.apply(SPECIES.length()); 1578 float[] b = fb.apply(SPECIES.length()); 1579 float[] r = fr.apply(SPECIES.length()); 1580 1581 for (int i = 0; i < a.length; i += SPECIES.length()) { 1582 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1583 av.lanewise(VectorOperators.MAX, b[i]).intoArray(r, i); 1584 } 1585 1586 assertBroadcastArraysEquals(a, b, r, FloatMaxVectorTests::MAX); 1587 } 1588 1589 @Test(dataProvider = "floatBinaryOpProvider") 1590 static void maxFloatMaxVectorTestsBroadcastSmokeTest(IntFunction<float[]> fa, IntFunction<float[]> fb) { 1591 float[] a = fa.apply(SPECIES.length()); 1592 float[] b = fb.apply(SPECIES.length()); 1593 float[] r = fr.apply(SPECIES.length()); 1594 1595 for (int i = 0; i < a.length; i += SPECIES.length()) { 1596 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1597 av.max(b[i]).intoArray(r, i); 1598 } 1599 1600 assertBroadcastArraysEquals(a, b, r, FloatMaxVectorTests::max); 1601 } 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 static float ADD(float[] a, int idx) { 1615 float res = 0; 1616 for (int i = idx; i < (idx + SPECIES.length()); i++) { 1617 res += a[i]; 1618 } 1619 1620 return res; 1621 } 1622 1623 static float ADD(float[] a) { 1624 float res = 0; 1625 for (int i = 0; i < a.length; i += SPECIES.length()) { 1626 float tmp = 0; 1627 for (int j = 0; j < SPECIES.length(); j++) { 1628 tmp += a[i + j]; 1629 } 1630 res += tmp; 1631 } 1632 1633 return res; 1634 } 1635 @Test(dataProvider = "floatUnaryOpProvider") 1636 static void ADDFloatMaxVectorTests(IntFunction<float[]> fa) { 1637 float[] a = fa.apply(SPECIES.length()); 1638 float[] r = fr.apply(SPECIES.length()); 1639 float ra = 0; 1640 1641 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1642 for (int i = 0; i < a.length; i += SPECIES.length()) { 1643 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1644 r[i] = av.reduceLanes(VectorOperators.ADD); 1645 } 1646 } 1647 1648 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1649 ra = 0; 1650 for (int i = 0; i < a.length; i += SPECIES.length()) { 1651 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1652 ra += av.reduceLanes(VectorOperators.ADD); 1653 } 1654 } 1655 1656 assertReductionArraysEquals(a, r, ra, FloatMaxVectorTests::ADD, FloatMaxVectorTests::ADD); 1657 } 1658 static float ADDMasked(float[] a, int idx, boolean[] mask) { 1659 float res = 0; 1660 for (int i = idx; i < (idx + SPECIES.length()); i++) { 1661 if(mask[i % SPECIES.length()]) 1662 res += a[i]; 1663 } 1664 1665 return res; 1666 } 1667 1668 static float ADDMasked(float[] a, boolean[] mask) { 1669 float res = 0; 1670 for (int i = 0; i < a.length; i += SPECIES.length()) { 1671 float tmp = 0; 1672 for (int j = 0; j < SPECIES.length(); j++) { 1673 if(mask[(i + j) % SPECIES.length()]) 1674 tmp += a[i + j]; 1675 } 1676 res += tmp; 1677 } 1678 1679 return res; 1680 } 1681 @Test(dataProvider = "floatUnaryOpMaskProvider") 1682 static void ADDFloatMaxVectorTestsMasked(IntFunction<float[]> fa, IntFunction<boolean[]> fm) { 1683 float[] a = fa.apply(SPECIES.length()); 1684 float[] r = fr.apply(SPECIES.length()); 1685 boolean[] mask = fm.apply(SPECIES.length()); 1686 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1687 float ra = 0; 1688 1689 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1690 for (int i = 0; i < a.length; i += SPECIES.length()) { 1691 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1692 r[i] = av.reduceLanes(VectorOperators.ADD, vmask); 1693 } 1694 } 1695 1696 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1697 ra = 0; 1698 for (int i = 0; i < a.length; i += SPECIES.length()) { 1699 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1700 ra += av.reduceLanes(VectorOperators.ADD, vmask); 1701 } 1702 } 1703 1704 assertReductionArraysEqualsMasked(a, r, ra, mask, FloatMaxVectorTests::ADDMasked, FloatMaxVectorTests::ADDMasked); 1705 } 1706 static float MUL(float[] a, int idx) { 1707 float res = 1; 1708 for (int i = idx; i < (idx + SPECIES.length()); i++) { 1709 res *= a[i]; 1710 } 1711 1712 return res; 1713 } 1714 1715 static float MUL(float[] a) { 1716 float res = 1; 1717 for (int i = 0; i < a.length; i += SPECIES.length()) { 1718 float tmp = 1; 1719 for (int j = 0; j < SPECIES.length(); j++) { 1720 tmp *= a[i + j]; 1721 } 1722 res *= tmp; 1723 } 1724 1725 return res; 1726 } 1727 @Test(dataProvider = "floatUnaryOpProvider") 1728 static void MULFloatMaxVectorTests(IntFunction<float[]> fa) { 1729 float[] a = fa.apply(SPECIES.length()); 1730 float[] r = fr.apply(SPECIES.length()); 1731 float ra = 1; 1732 1733 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1734 for (int i = 0; i < a.length; i += SPECIES.length()) { 1735 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1736 r[i] = av.reduceLanes(VectorOperators.MUL); 1737 } 1738 } 1739 1740 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1741 ra = 1; 1742 for (int i = 0; i < a.length; i += SPECIES.length()) { 1743 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1744 ra *= av.reduceLanes(VectorOperators.MUL); 1745 } 1746 } 1747 1748 assertReductionArraysEquals(a, r, ra, FloatMaxVectorTests::MUL, FloatMaxVectorTests::MUL); 1749 } 1750 static float MULMasked(float[] a, int idx, boolean[] mask) { 1751 float res = 1; 1752 for (int i = idx; i < (idx + SPECIES.length()); i++) { 1753 if(mask[i % SPECIES.length()]) 1754 res *= a[i]; 1755 } 1756 1757 return res; 1758 } 1759 1760 static float MULMasked(float[] a, boolean[] mask) { 1761 float res = 1; 1762 for (int i = 0; i < a.length; i += SPECIES.length()) { 1763 float tmp = 1; 1764 for (int j = 0; j < SPECIES.length(); j++) { 1765 if(mask[(i + j) % SPECIES.length()]) 1766 tmp *= a[i + j]; 1767 } 1768 res *= tmp; 1769 } 1770 1771 return res; 1772 } 1773 @Test(dataProvider = "floatUnaryOpMaskProvider") 1774 static void MULFloatMaxVectorTestsMasked(IntFunction<float[]> fa, IntFunction<boolean[]> fm) { 1775 float[] a = fa.apply(SPECIES.length()); 1776 float[] r = fr.apply(SPECIES.length()); 1777 boolean[] mask = fm.apply(SPECIES.length()); 1778 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1779 float ra = 1; 1780 1781 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1782 for (int i = 0; i < a.length; i += SPECIES.length()) { 1783 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1784 r[i] = av.reduceLanes(VectorOperators.MUL, vmask); 1785 } 1786 } 1787 1788 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1789 ra = 1; 1790 for (int i = 0; i < a.length; i += SPECIES.length()) { 1791 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1792 ra *= av.reduceLanes(VectorOperators.MUL, vmask); 1793 } 1794 } 1795 1796 assertReductionArraysEqualsMasked(a, r, ra, mask, FloatMaxVectorTests::MULMasked, FloatMaxVectorTests::MULMasked); 1797 } 1798 static float MIN(float[] a, int idx) { 1799 float res = Float.POSITIVE_INFINITY; 1800 for (int i = idx; i < (idx + SPECIES.length()); i++) { 1801 res = (float)Math.min(res, a[i]); 1802 } 1803 1804 return res; 1805 } 1806 1807 static float MIN(float[] a) { 1808 float res = Float.POSITIVE_INFINITY; 1809 for (int i = 0; i < a.length; i++) { 1810 res = (float)Math.min(res, a[i]); 1811 } 1812 1813 return res; 1814 } 1815 @Test(dataProvider = "floatUnaryOpProvider") 1816 static void MINFloatMaxVectorTests(IntFunction<float[]> fa) { 1817 float[] a = fa.apply(SPECIES.length()); 1818 float[] r = fr.apply(SPECIES.length()); 1819 float ra = Float.POSITIVE_INFINITY; 1820 1821 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1822 for (int i = 0; i < a.length; i += SPECIES.length()) { 1823 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1824 r[i] = av.reduceLanes(VectorOperators.MIN); 1825 } 1826 } 1827 1828 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1829 ra = Float.POSITIVE_INFINITY; 1830 for (int i = 0; i < a.length; i += SPECIES.length()) { 1831 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1832 ra = (float)Math.min(ra, av.reduceLanes(VectorOperators.MIN)); 1833 } 1834 } 1835 1836 assertReductionArraysEquals(a, r, ra, FloatMaxVectorTests::MIN, FloatMaxVectorTests::MIN); 1837 } 1838 static float MINMasked(float[] a, int idx, boolean[] mask) { 1839 float res = Float.POSITIVE_INFINITY; 1840 for (int i = idx; i < (idx + SPECIES.length()); i++) { 1841 if(mask[i % SPECIES.length()]) 1842 res = (float)Math.min(res, a[i]); 1843 } 1844 1845 return res; 1846 } 1847 1848 static float MINMasked(float[] a, boolean[] mask) { 1849 float res = Float.POSITIVE_INFINITY; 1850 for (int i = 0; i < a.length; i++) { 1851 if(mask[i % SPECIES.length()]) 1852 res = (float)Math.min(res, a[i]); 1853 } 1854 1855 return res; 1856 } 1857 @Test(dataProvider = "floatUnaryOpMaskProvider") 1858 static void MINFloatMaxVectorTestsMasked(IntFunction<float[]> fa, IntFunction<boolean[]> fm) { 1859 float[] a = fa.apply(SPECIES.length()); 1860 float[] r = fr.apply(SPECIES.length()); 1861 boolean[] mask = fm.apply(SPECIES.length()); 1862 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1863 float ra = Float.POSITIVE_INFINITY; 1864 1865 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1866 for (int i = 0; i < a.length; i += SPECIES.length()) { 1867 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1868 r[i] = av.reduceLanes(VectorOperators.MIN, vmask); 1869 } 1870 } 1871 1872 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1873 ra = Float.POSITIVE_INFINITY; 1874 for (int i = 0; i < a.length; i += SPECIES.length()) { 1875 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1876 ra = (float)Math.min(ra, av.reduceLanes(VectorOperators.MIN, vmask)); 1877 } 1878 } 1879 1880 assertReductionArraysEqualsMasked(a, r, ra, mask, FloatMaxVectorTests::MINMasked, FloatMaxVectorTests::MINMasked); 1881 } 1882 static float MAX(float[] a, int idx) { 1883 float res = Float.NEGATIVE_INFINITY; 1884 for (int i = idx; i < (idx + SPECIES.length()); i++) { 1885 res = (float)Math.max(res, a[i]); 1886 } 1887 1888 return res; 1889 } 1890 1891 static float MAX(float[] a) { 1892 float res = Float.NEGATIVE_INFINITY; 1893 for (int i = 0; i < a.length; i++) { 1894 res = (float)Math.max(res, a[i]); 1895 } 1896 1897 return res; 1898 } 1899 @Test(dataProvider = "floatUnaryOpProvider") 1900 static void MAXFloatMaxVectorTests(IntFunction<float[]> fa) { 1901 float[] a = fa.apply(SPECIES.length()); 1902 float[] r = fr.apply(SPECIES.length()); 1903 float ra = Float.NEGATIVE_INFINITY; 1904 1905 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1906 for (int i = 0; i < a.length; i += SPECIES.length()) { 1907 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1908 r[i] = av.reduceLanes(VectorOperators.MAX); 1909 } 1910 } 1911 1912 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1913 ra = Float.NEGATIVE_INFINITY; 1914 for (int i = 0; i < a.length; i += SPECIES.length()) { 1915 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1916 ra = (float)Math.max(ra, av.reduceLanes(VectorOperators.MAX)); 1917 } 1918 } 1919 1920 assertReductionArraysEquals(a, r, ra, FloatMaxVectorTests::MAX, FloatMaxVectorTests::MAX); 1921 } 1922 static float MAXMasked(float[] a, int idx, boolean[] mask) { 1923 float res = Float.NEGATIVE_INFINITY; 1924 for (int i = idx; i < (idx + SPECIES.length()); i++) { 1925 if(mask[i % SPECIES.length()]) 1926 res = (float)Math.max(res, a[i]); 1927 } 1928 1929 return res; 1930 } 1931 1932 static float MAXMasked(float[] a, boolean[] mask) { 1933 float res = Float.NEGATIVE_INFINITY; 1934 for (int i = 0; i < a.length; i++) { 1935 if(mask[i % SPECIES.length()]) 1936 res = (float)Math.max(res, a[i]); 1937 } 1938 1939 return res; 1940 } 1941 @Test(dataProvider = "floatUnaryOpMaskProvider") 1942 static void MAXFloatMaxVectorTestsMasked(IntFunction<float[]> fa, IntFunction<boolean[]> fm) { 1943 float[] a = fa.apply(SPECIES.length()); 1944 float[] r = fr.apply(SPECIES.length()); 1945 boolean[] mask = fm.apply(SPECIES.length()); 1946 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0); 1947 float ra = Float.NEGATIVE_INFINITY; 1948 1949 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1950 for (int i = 0; i < a.length; i += SPECIES.length()) { 1951 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1952 r[i] = av.reduceLanes(VectorOperators.MAX, vmask); 1953 } 1954 } 1955 1956 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1957 ra = Float.NEGATIVE_INFINITY; 1958 for (int i = 0; i < a.length; i += SPECIES.length()) { 1959 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1960 ra = (float)Math.max(ra, av.reduceLanes(VectorOperators.MAX, vmask)); 1961 } 1962 } 1963 1964 assertReductionArraysEqualsMasked(a, r, ra, mask, FloatMaxVectorTests::MAXMasked, FloatMaxVectorTests::MAXMasked); 1965 } 1966 1967 1968 1969 1970 1971 @Test(dataProvider = "floatUnaryOpProvider") 1972 static void withFloatMaxVectorTests(IntFunction<float []> fa) { 1973 float[] a = fa.apply(SPECIES.length()); 1974 float[] r = fr.apply(SPECIES.length()); 1975 1976 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1977 for (int i = 0; i < a.length; i += SPECIES.length()) { 1978 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1979 av.withLane(0, (float)4).intoArray(r, i); 1980 } 1981 } 1982 1983 assertInsertArraysEquals(a, r, (float)4, 0); 1984 } 1985 static boolean testIS_DEFAULT(float a) { 1986 return bits(a)==0; 1987 } 1988 1989 @Test(dataProvider = "floatTestOpProvider") 1990 static void IS_DEFAULTFloatMaxVectorTests(IntFunction<float[]> fa) { 1991 float[] a = fa.apply(SPECIES.length()); 1992 1993 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1994 for (int i = 0; i < a.length; i += SPECIES.length()) { 1995 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 1996 VectorMask<Float> mv = av.test(VectorOperators.IS_DEFAULT); 1997 1998 // Check results as part of computation. 1999 for (int j = 0; j < SPECIES.length(); j++) { 2000 2001 Assert.assertEquals(mv.laneIsSet(j), testIS_DEFAULT(a[i + j])); 2002 } 2003 } 2004 } 2005 } 2006 2007 static boolean testIS_NEGATIVE(float a) { 2008 return bits(a)<0; 2009 } 2010 2011 @Test(dataProvider = "floatTestOpProvider") 2012 static void IS_NEGATIVEFloatMaxVectorTests(IntFunction<float[]> fa) { 2013 float[] a = fa.apply(SPECIES.length()); 2014 2015 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2016 for (int i = 0; i < a.length; i += SPECIES.length()) { 2017 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2018 VectorMask<Float> mv = av.test(VectorOperators.IS_NEGATIVE); 2019 2020 // Check results as part of computation. 2021 for (int j = 0; j < SPECIES.length(); j++) { 2022 2023 Assert.assertEquals(mv.laneIsSet(j), testIS_NEGATIVE(a[i + j])); 2024 } 2025 } 2026 } 2027 } 2028 2029 2030 static boolean testIS_FINITE(float a) { 2031 return Float.isFinite(a); 2032 } 2033 2034 @Test(dataProvider = "floatTestOpProvider") 2035 static void IS_FINITEFloatMaxVectorTests(IntFunction<float[]> fa) { 2036 float[] a = fa.apply(SPECIES.length()); 2037 2038 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2039 for (int i = 0; i < a.length; i += SPECIES.length()) { 2040 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2041 VectorMask<Float> mv = av.test(VectorOperators.IS_FINITE); 2042 2043 // Check results as part of computation. 2044 for (int j = 0; j < SPECIES.length(); j++) { 2045 2046 Assert.assertEquals(mv.laneIsSet(j), testIS_FINITE(a[i + j])); 2047 } 2048 } 2049 } 2050 } 2051 2052 2053 2054 static boolean testIS_NAN(float a) { 2055 return Float.isNaN(a); 2056 } 2057 2058 @Test(dataProvider = "floatTestOpProvider") 2059 static void IS_NANFloatMaxVectorTests(IntFunction<float[]> fa) { 2060 float[] a = fa.apply(SPECIES.length()); 2061 2062 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2063 for (int i = 0; i < a.length; i += SPECIES.length()) { 2064 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2065 VectorMask<Float> mv = av.test(VectorOperators.IS_NAN); 2066 2067 // Check results as part of computation. 2068 for (int j = 0; j < SPECIES.length(); j++) { 2069 2070 Assert.assertEquals(mv.laneIsSet(j), testIS_NAN(a[i + j])); 2071 } 2072 } 2073 } 2074 } 2075 2076 2077 2078 static boolean testIS_INFINITE(float a) { 2079 return Float.isInfinite(a); 2080 } 2081 2082 @Test(dataProvider = "floatTestOpProvider") 2083 static void IS_INFINITEFloatMaxVectorTests(IntFunction<float[]> fa) { 2084 float[] a = fa.apply(SPECIES.length()); 2085 2086 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2087 for (int i = 0; i < a.length; i += SPECIES.length()) { 2088 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2089 VectorMask<Float> mv = av.test(VectorOperators.IS_INFINITE); 2090 2091 // Check results as part of computation. 2092 for (int j = 0; j < SPECIES.length(); j++) { 2093 2094 Assert.assertEquals(mv.laneIsSet(j), testIS_INFINITE(a[i + j])); 2095 } 2096 } 2097 } 2098 } 2099 2100 2101 2102 @Test(dataProvider = "floatCompareOpProvider") 2103 static void LTFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) { 2104 float[] a = fa.apply(SPECIES.length()); 2105 float[] b = fb.apply(SPECIES.length()); 2106 2107 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2108 for (int i = 0; i < a.length; i += SPECIES.length()) { 2109 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2110 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 2111 VectorMask<Float> mv = av.compare(VectorOperators.LT, bv); 2112 2113 // Check results as part of computation. 2114 for (int j = 0; j < SPECIES.length(); j++) { 2115 Assert.assertEquals(mv.laneIsSet(j), a[i + j] < b[i + j]); 2116 } 2117 } 2118 } 2119 } 2120 2121 2122 @Test(dataProvider = "floatCompareOpProvider") 2123 static void ltFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) { 2124 float[] a = fa.apply(SPECIES.length()); 2125 float[] b = fb.apply(SPECIES.length()); 2126 2127 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2128 for (int i = 0; i < a.length; i += SPECIES.length()) { 2129 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2130 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 2131 VectorMask<Float> mv = av.lt(bv); 2132 2133 // Check results as part of computation. 2134 for (int j = 0; j < SPECIES.length(); j++) { 2135 Assert.assertEquals(mv.laneIsSet(j), a[i + j] < b[i + j]); 2136 } 2137 } 2138 } 2139 } 2140 2141 2142 @Test(dataProvider = "floatCompareOpProvider") 2143 static void GTFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) { 2144 float[] a = fa.apply(SPECIES.length()); 2145 float[] b = fb.apply(SPECIES.length()); 2146 2147 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2148 for (int i = 0; i < a.length; i += SPECIES.length()) { 2149 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2150 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 2151 VectorMask<Float> mv = av.compare(VectorOperators.GT, bv); 2152 2153 // Check results as part of computation. 2154 for (int j = 0; j < SPECIES.length(); j++) { 2155 Assert.assertEquals(mv.laneIsSet(j), a[i + j] > b[i + j]); 2156 } 2157 } 2158 } 2159 } 2160 2161 2162 @Test(dataProvider = "floatCompareOpProvider") 2163 static void EQFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) { 2164 float[] a = fa.apply(SPECIES.length()); 2165 float[] b = fb.apply(SPECIES.length()); 2166 2167 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2168 for (int i = 0; i < a.length; i += SPECIES.length()) { 2169 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2170 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 2171 VectorMask<Float> mv = av.compare(VectorOperators.EQ, bv); 2172 2173 // Check results as part of computation. 2174 for (int j = 0; j < SPECIES.length(); j++) { 2175 Assert.assertEquals(mv.laneIsSet(j), a[i + j] == b[i + j]); 2176 } 2177 } 2178 } 2179 } 2180 2181 2182 @Test(dataProvider = "floatCompareOpProvider") 2183 static void eqFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) { 2184 float[] a = fa.apply(SPECIES.length()); 2185 float[] b = fb.apply(SPECIES.length()); 2186 2187 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2188 for (int i = 0; i < a.length; i += SPECIES.length()) { 2189 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2190 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 2191 VectorMask<Float> mv = av.eq(bv); 2192 2193 // Check results as part of computation. 2194 for (int j = 0; j < SPECIES.length(); j++) { 2195 Assert.assertEquals(mv.laneIsSet(j), a[i + j] == b[i + j]); 2196 } 2197 } 2198 } 2199 } 2200 2201 2202 @Test(dataProvider = "floatCompareOpProvider") 2203 static void NEFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) { 2204 float[] a = fa.apply(SPECIES.length()); 2205 float[] b = fb.apply(SPECIES.length()); 2206 2207 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2208 for (int i = 0; i < a.length; i += SPECIES.length()) { 2209 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2210 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 2211 VectorMask<Float> mv = av.compare(VectorOperators.NE, bv); 2212 2213 // Check results as part of computation. 2214 for (int j = 0; j < SPECIES.length(); j++) { 2215 Assert.assertEquals(mv.laneIsSet(j), a[i + j] != b[i + j]); 2216 } 2217 } 2218 } 2219 } 2220 2221 2222 @Test(dataProvider = "floatCompareOpProvider") 2223 static void LEFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) { 2224 float[] a = fa.apply(SPECIES.length()); 2225 float[] b = fb.apply(SPECIES.length()); 2226 2227 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2228 for (int i = 0; i < a.length; i += SPECIES.length()) { 2229 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2230 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 2231 VectorMask<Float> mv = av.compare(VectorOperators.LE, bv); 2232 2233 // Check results as part of computation. 2234 for (int j = 0; j < SPECIES.length(); j++) { 2235 Assert.assertEquals(mv.laneIsSet(j), a[i + j] <= b[i + j]); 2236 } 2237 } 2238 } 2239 } 2240 2241 2242 @Test(dataProvider = "floatCompareOpProvider") 2243 static void GEFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) { 2244 float[] a = fa.apply(SPECIES.length()); 2245 float[] b = fb.apply(SPECIES.length()); 2246 2247 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2248 for (int i = 0; i < a.length; i += SPECIES.length()) { 2249 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2250 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 2251 VectorMask<Float> mv = av.compare(VectorOperators.GE, bv); 2252 2253 // Check results as part of computation. 2254 for (int j = 0; j < SPECIES.length(); j++) { 2255 Assert.assertEquals(mv.laneIsSet(j), a[i + j] >= b[i + j]); 2256 } 2257 } 2258 } 2259 } 2260 2261 2262 static float blend(float a, float b, boolean mask) { 2263 return mask ? b : a; 2264 } 2265 2266 @Test(dataProvider = "floatBinaryOpMaskProvider") 2267 static void blendFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb, 2268 IntFunction<boolean[]> fm) { 2269 float[] a = fa.apply(SPECIES.length()); 2270 float[] b = fb.apply(SPECIES.length()); 2271 float[] r = fr.apply(SPECIES.length()); 2272 boolean[] mask = fm.apply(SPECIES.length()); 2273 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2274 2275 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2276 for (int i = 0; i < a.length; i += SPECIES.length()) { 2277 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2278 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 2279 av.blend(bv, vmask).intoArray(r, i); 2280 } 2281 } 2282 2283 assertArraysEquals(a, b, r, mask, FloatMaxVectorTests::blend); 2284 } 2285 2286 @Test(dataProvider = "floatUnaryOpShuffleProvider") 2287 static void RearrangeFloatMaxVectorTests(IntFunction<float[]> fa, 2288 BiFunction<Integer,Integer,int[]> fs) { 2289 float[] a = fa.apply(SPECIES.length()); 2290 int[] order = fs.apply(a.length, SPECIES.length()); 2291 float[] r = fr.apply(SPECIES.length()); 2292 2293 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2294 for (int i = 0; i < a.length; i += SPECIES.length()) { 2295 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2296 av.rearrange(VectorShuffle.fromArray(SPECIES, order, i)).intoArray(r, i); 2297 } 2298 } 2299 2300 assertRearrangeArraysEquals(a, r, order, SPECIES.length()); 2301 } 2302 2303 2304 2305 2306 @Test(dataProvider = "floatUnaryOpProvider") 2307 static void getFloatMaxVectorTests(IntFunction<float[]> fa) { 2308 float[] a = fa.apply(SPECIES.length()); 2309 float[] r = fr.apply(SPECIES.length()); 2310 2311 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2312 for (int i = 0; i < a.length; i += SPECIES.length()) { 2313 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2314 int num_lanes = SPECIES.length(); 2315 // Manually unroll because full unroll happens after intrinsification. 2316 // Unroll is needed because get intrinsic requires for index to be a known constant. 2317 if (num_lanes == 1) { 2318 r[i]=av.lane(0); 2319 } else if (num_lanes == 2) { 2320 r[i]=av.lane(0); 2321 r[i+1]=av.lane(1); 2322 } else if (num_lanes == 4) { 2323 r[i]=av.lane(0); 2324 r[i+1]=av.lane(1); 2325 r[i+2]=av.lane(2); 2326 r[i+3]=av.lane(3); 2327 } else if (num_lanes == 8) { 2328 r[i]=av.lane(0); 2329 r[i+1]=av.lane(1); 2330 r[i+2]=av.lane(2); 2331 r[i+3]=av.lane(3); 2332 r[i+4]=av.lane(4); 2333 r[i+5]=av.lane(5); 2334 r[i+6]=av.lane(6); 2335 r[i+7]=av.lane(7); 2336 } else if (num_lanes == 16) { 2337 r[i]=av.lane(0); 2338 r[i+1]=av.lane(1); 2339 r[i+2]=av.lane(2); 2340 r[i+3]=av.lane(3); 2341 r[i+4]=av.lane(4); 2342 r[i+5]=av.lane(5); 2343 r[i+6]=av.lane(6); 2344 r[i+7]=av.lane(7); 2345 r[i+8]=av.lane(8); 2346 r[i+9]=av.lane(9); 2347 r[i+10]=av.lane(10); 2348 r[i+11]=av.lane(11); 2349 r[i+12]=av.lane(12); 2350 r[i+13]=av.lane(13); 2351 r[i+14]=av.lane(14); 2352 r[i+15]=av.lane(15); 2353 } else if (num_lanes == 32) { 2354 r[i]=av.lane(0); 2355 r[i+1]=av.lane(1); 2356 r[i+2]=av.lane(2); 2357 r[i+3]=av.lane(3); 2358 r[i+4]=av.lane(4); 2359 r[i+5]=av.lane(5); 2360 r[i+6]=av.lane(6); 2361 r[i+7]=av.lane(7); 2362 r[i+8]=av.lane(8); 2363 r[i+9]=av.lane(9); 2364 r[i+10]=av.lane(10); 2365 r[i+11]=av.lane(11); 2366 r[i+12]=av.lane(12); 2367 r[i+13]=av.lane(13); 2368 r[i+14]=av.lane(14); 2369 r[i+15]=av.lane(15); 2370 r[i+16]=av.lane(16); 2371 r[i+17]=av.lane(17); 2372 r[i+18]=av.lane(18); 2373 r[i+19]=av.lane(19); 2374 r[i+20]=av.lane(20); 2375 r[i+21]=av.lane(21); 2376 r[i+22]=av.lane(22); 2377 r[i+23]=av.lane(23); 2378 r[i+24]=av.lane(24); 2379 r[i+25]=av.lane(25); 2380 r[i+26]=av.lane(26); 2381 r[i+27]=av.lane(27); 2382 r[i+28]=av.lane(28); 2383 r[i+29]=av.lane(29); 2384 r[i+30]=av.lane(30); 2385 r[i+31]=av.lane(31); 2386 } else if (num_lanes == 64) { 2387 r[i]=av.lane(0); 2388 r[i+1]=av.lane(1); 2389 r[i+2]=av.lane(2); 2390 r[i+3]=av.lane(3); 2391 r[i+4]=av.lane(4); 2392 r[i+5]=av.lane(5); 2393 r[i+6]=av.lane(6); 2394 r[i+7]=av.lane(7); 2395 r[i+8]=av.lane(8); 2396 r[i+9]=av.lane(9); 2397 r[i+10]=av.lane(10); 2398 r[i+11]=av.lane(11); 2399 r[i+12]=av.lane(12); 2400 r[i+13]=av.lane(13); 2401 r[i+14]=av.lane(14); 2402 r[i+15]=av.lane(15); 2403 r[i+16]=av.lane(16); 2404 r[i+17]=av.lane(17); 2405 r[i+18]=av.lane(18); 2406 r[i+19]=av.lane(19); 2407 r[i+20]=av.lane(20); 2408 r[i+21]=av.lane(21); 2409 r[i+22]=av.lane(22); 2410 r[i+23]=av.lane(23); 2411 r[i+24]=av.lane(24); 2412 r[i+25]=av.lane(25); 2413 r[i+26]=av.lane(26); 2414 r[i+27]=av.lane(27); 2415 r[i+28]=av.lane(28); 2416 r[i+29]=av.lane(29); 2417 r[i+30]=av.lane(30); 2418 r[i+31]=av.lane(31); 2419 r[i+32]=av.lane(32); 2420 r[i+33]=av.lane(33); 2421 r[i+34]=av.lane(34); 2422 r[i+35]=av.lane(35); 2423 r[i+36]=av.lane(36); 2424 r[i+37]=av.lane(37); 2425 r[i+38]=av.lane(38); 2426 r[i+39]=av.lane(39); 2427 r[i+40]=av.lane(40); 2428 r[i+41]=av.lane(41); 2429 r[i+42]=av.lane(42); 2430 r[i+43]=av.lane(43); 2431 r[i+44]=av.lane(44); 2432 r[i+45]=av.lane(45); 2433 r[i+46]=av.lane(46); 2434 r[i+47]=av.lane(47); 2435 r[i+48]=av.lane(48); 2436 r[i+49]=av.lane(49); 2437 r[i+50]=av.lane(50); 2438 r[i+51]=av.lane(51); 2439 r[i+52]=av.lane(52); 2440 r[i+53]=av.lane(53); 2441 r[i+54]=av.lane(54); 2442 r[i+55]=av.lane(55); 2443 r[i+56]=av.lane(56); 2444 r[i+57]=av.lane(57); 2445 r[i+58]=av.lane(58); 2446 r[i+59]=av.lane(59); 2447 r[i+60]=av.lane(60); 2448 r[i+61]=av.lane(61); 2449 r[i+62]=av.lane(62); 2450 r[i+63]=av.lane(63); 2451 } else { 2452 for (int j = 0; j < SPECIES.length(); j++) { 2453 r[i+j]=av.lane(j); 2454 } 2455 } 2456 } 2457 } 2458 2459 assertArraysEquals(a, r, FloatMaxVectorTests::get); 2460 } 2461 2462 @Test(dataProvider = "floatUnaryOpProvider") 2463 static void BroadcastFloatMaxVectorTests(IntFunction<float[]> fa) { 2464 float[] a = fa.apply(SPECIES.length()); 2465 float[] r = new float[a.length]; 2466 2467 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2468 for (int i = 0; i < a.length; i += SPECIES.length()) { 2469 FloatVector.broadcast(SPECIES, a[i]).intoArray(r, i); 2470 } 2471 } 2472 2473 assertBroadcastArraysEquals(a, r); 2474 } 2475 2476 2477 2478 2479 2480 @Test(dataProvider = "floatUnaryOpProvider") 2481 static void ZeroFloatMaxVectorTests(IntFunction<float[]> fa) { 2482 float[] a = fa.apply(SPECIES.length()); 2483 float[] r = new float[a.length]; 2484 2485 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2486 for (int i = 0; i < a.length; i += SPECIES.length()) { 2487 FloatVector.zero(SPECIES).intoArray(a, i); 2488 } 2489 } 2490 2491 Assert.assertEquals(a, r); 2492 } 2493 2494 2495 2496 2497 static float[] sliceUnary(float[] a, int origin, int idx) { 2498 float[] res = new float[SPECIES.length()]; 2499 for (int i = 0; i < SPECIES.length(); i++){ 2500 if(i+origin < SPECIES.length()) 2501 res[i] = a[idx+i+origin]; 2502 else 2503 res[i] = (float)0; 2504 } 2505 return res; 2506 } 2507 2508 @Test(dataProvider = "floatUnaryOpProvider") 2509 static void sliceUnaryFloatMaxVectorTests(IntFunction<float[]> fa) { 2510 float[] a = fa.apply(SPECIES.length()); 2511 float[] r = new float[a.length]; 2512 int origin = (new java.util.Random()).nextInt(SPECIES.length()); 2513 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2514 for (int i = 0; i < a.length; i += SPECIES.length()) { 2515 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2516 av.slice(origin).intoArray(r, i); 2517 } 2518 } 2519 2520 assertArraysEquals(a, r, origin, FloatMaxVectorTests::sliceUnary); 2521 } 2522 static float[] sliceBinary(float[] a, float[] b, int origin, int idx) { 2523 float[] res = new float[SPECIES.length()]; 2524 for (int i = 0, j = 0; i < SPECIES.length(); i++){ 2525 if(i+origin < SPECIES.length()) 2526 res[i] = a[idx+i+origin]; 2527 else { 2528 res[i] = b[idx+j]; 2529 j++; 2530 } 2531 } 2532 return res; 2533 } 2534 2535 @Test(dataProvider = "floatBinaryOpProvider") 2536 static void sliceBinaryFloatMaxVectorTestsBinary(IntFunction<float[]> fa, IntFunction<float[]> fb) { 2537 float[] a = fa.apply(SPECIES.length()); 2538 float[] b = fb.apply(SPECIES.length()); 2539 float[] r = new float[a.length]; 2540 int origin = (new java.util.Random()).nextInt(SPECIES.length()); 2541 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2542 for (int i = 0; i < a.length; i += SPECIES.length()) { 2543 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2544 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 2545 av.slice(origin, bv).intoArray(r, i); 2546 } 2547 } 2548 2549 assertArraysEquals(a, b, r, origin, FloatMaxVectorTests::sliceBinary); 2550 } 2551 static float[] slice(float[] a, float[] b, int origin, boolean[] mask, int idx) { 2552 float[] res = new float[SPECIES.length()]; 2553 for (int i = 0, j = 0; i < SPECIES.length(); i++){ 2554 if(i+origin < SPECIES.length()) 2555 res[i] = mask[i] ? a[idx+i+origin] : (float)0; 2556 else { 2557 res[i] = mask[i] ? b[idx+j] : (float)0; 2558 j++; 2559 } 2560 } 2561 return res; 2562 } 2563 2564 @Test(dataProvider = "floatBinaryOpMaskProvider") 2565 static void sliceFloatMaxVectorTestsMasked(IntFunction<float[]> fa, IntFunction<float[]> fb, 2566 IntFunction<boolean[]> fm) { 2567 float[] a = fa.apply(SPECIES.length()); 2568 float[] b = fb.apply(SPECIES.length()); 2569 boolean[] mask = fm.apply(SPECIES.length()); 2570 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2571 2572 float[] r = new float[a.length]; 2573 int origin = (new java.util.Random()).nextInt(SPECIES.length()); 2574 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2575 for (int i = 0; i < a.length; i += SPECIES.length()) { 2576 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2577 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 2578 av.slice(origin, bv, vmask).intoArray(r, i); 2579 } 2580 } 2581 2582 assertArraysEquals(a, b, r, origin, mask, FloatMaxVectorTests::slice); 2583 } 2584 static float[] unsliceUnary(float[] a, int origin, int idx) { 2585 float[] res = new float[SPECIES.length()]; 2586 for (int i = 0, j = 0; i < SPECIES.length(); i++){ 2587 if(i < origin) 2588 res[i] = (float)0; 2589 else { 2590 res[i] = a[idx+j]; 2591 j++; 2592 } 2593 } 2594 return res; 2595 } 2596 2597 @Test(dataProvider = "floatUnaryOpProvider") 2598 static void unsliceUnaryFloatMaxVectorTests(IntFunction<float[]> fa) { 2599 float[] a = fa.apply(SPECIES.length()); 2600 float[] r = new float[a.length]; 2601 int origin = (new java.util.Random()).nextInt(SPECIES.length()); 2602 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2603 for (int i = 0; i < a.length; i += SPECIES.length()) { 2604 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2605 av.unslice(origin).intoArray(r, i); 2606 } 2607 } 2608 2609 assertArraysEquals(a, r, origin, FloatMaxVectorTests::unsliceUnary); 2610 } 2611 static float[] unsliceBinary(float[] a, float[] b, int origin, int part, int idx) { 2612 float[] res = new float[SPECIES.length()]; 2613 for (int i = 0, j = 0; i < SPECIES.length(); i++){ 2614 if (part == 0) { 2615 if (i < origin) 2616 res[i] = b[idx+i]; 2617 else { 2618 res[i] = a[idx+j]; 2619 j++; 2620 } 2621 } else if (part == 1) { 2622 if (i < origin) 2623 res[i] = a[idx+SPECIES.length()-origin+i]; 2624 else { 2625 res[i] = b[idx+origin+j]; 2626 j++; 2627 } 2628 } 2629 } 2630 return res; 2631 } 2632 2633 @Test(dataProvider = "floatBinaryOpProvider") 2634 static void unsliceBinaryFloatMaxVectorTestsBinary(IntFunction<float[]> fa, IntFunction<float[]> fb) { 2635 float[] a = fa.apply(SPECIES.length()); 2636 float[] b = fb.apply(SPECIES.length()); 2637 float[] r = new float[a.length]; 2638 int origin = (new java.util.Random()).nextInt(SPECIES.length()); 2639 int part = (new java.util.Random()).nextInt(2); 2640 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2641 for (int i = 0; i < a.length; i += SPECIES.length()) { 2642 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2643 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 2644 av.unslice(origin, bv, part).intoArray(r, i); 2645 } 2646 } 2647 2648 assertArraysEquals(a, b, r, origin, part, FloatMaxVectorTests::unsliceBinary); 2649 } 2650 static float[] unslice(float[] a, float[] b, int origin, int part, boolean[] mask, int idx) { 2651 float[] res = new float[SPECIES.length()]; 2652 for (int i = 0, j = 0; i < SPECIES.length(); i++){ 2653 if(i+origin < SPECIES.length()) 2654 res[i] = b[idx+i+origin]; 2655 else { 2656 res[i] = b[idx+j]; 2657 j++; 2658 } 2659 } 2660 for (int i = 0; i < SPECIES.length(); i++){ 2661 res[i] = mask[i] ? a[idx+i] : res[i]; 2662 } 2663 float[] res1 = new float[SPECIES.length()]; 2664 if (part == 0) { 2665 for (int i = 0, j = 0; i < SPECIES.length(); i++){ 2666 if (i < origin) 2667 res1[i] = b[idx+i]; 2668 else { 2669 res1[i] = res[j]; 2670 j++; 2671 } 2672 } 2673 } else if (part == 1) { 2674 for (int i = 0, j = 0; i < SPECIES.length(); i++){ 2675 if (i < origin) 2676 res1[i] = res[SPECIES.length()-origin+i]; 2677 else { 2678 res1[i] = b[idx+origin+j]; 2679 j++; 2680 } 2681 } 2682 } 2683 return res1; 2684 } 2685 2686 @Test(dataProvider = "floatBinaryOpMaskProvider") 2687 static void unsliceFloatMaxVectorTestsMasked(IntFunction<float[]> fa, IntFunction<float[]> fb, 2688 IntFunction<boolean[]> fm) { 2689 float[] a = fa.apply(SPECIES.length()); 2690 float[] b = fb.apply(SPECIES.length()); 2691 boolean[] mask = fm.apply(SPECIES.length()); 2692 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0); 2693 float[] r = new float[a.length]; 2694 int origin = (new java.util.Random()).nextInt(SPECIES.length()); 2695 int part = (new java.util.Random()).nextInt(2); 2696 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2697 for (int i = 0; i < a.length; i += SPECIES.length()) { 2698 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2699 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 2700 av.unslice(origin, bv, part, vmask).intoArray(r, i); 2701 } 2702 } 2703 2704 assertArraysEquals(a, b, r, origin, part, mask, FloatMaxVectorTests::unslice); 2705 } 2706 2707 static float SIN(float a) { 2708 return (float)(Math.sin((double)a)); 2709 } 2710 2711 static float strictSIN(float a) { 2712 return (float)(StrictMath.sin((double)a)); 2713 } 2714 2715 @Test(dataProvider = "floatUnaryOpProvider") 2716 static void SINFloatMaxVectorTests(IntFunction<float[]> fa) { 2717 float[] a = fa.apply(SPECIES.length()); 2718 float[] r = fr.apply(SPECIES.length()); 2719 2720 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2721 for (int i = 0; i < a.length; i += SPECIES.length()) { 2722 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2723 av.lanewise(VectorOperators.SIN).intoArray(r, i); 2724 } 2725 } 2726 2727 assertArraysEqualsWithinOneUlp(a, r, FloatMaxVectorTests::SIN, FloatMaxVectorTests::strictSIN); 2728 } 2729 2730 2731 static float EXP(float a) { 2732 return (float)(Math.exp((double)a)); 2733 } 2734 2735 static float strictEXP(float a) { 2736 return (float)(StrictMath.exp((double)a)); 2737 } 2738 2739 @Test(dataProvider = "floatUnaryOpProvider") 2740 static void EXPFloatMaxVectorTests(IntFunction<float[]> fa) { 2741 float[] a = fa.apply(SPECIES.length()); 2742 float[] r = fr.apply(SPECIES.length()); 2743 2744 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2745 for (int i = 0; i < a.length; i += SPECIES.length()) { 2746 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2747 av.lanewise(VectorOperators.EXP).intoArray(r, i); 2748 } 2749 } 2750 2751 assertArraysEqualsWithinOneUlp(a, r, FloatMaxVectorTests::EXP, FloatMaxVectorTests::strictEXP); 2752 } 2753 2754 2755 static float LOG1P(float a) { 2756 return (float)(Math.log1p((double)a)); 2757 } 2758 2759 static float strictLOG1P(float a) { 2760 return (float)(StrictMath.log1p((double)a)); 2761 } 2762 2763 @Test(dataProvider = "floatUnaryOpProvider") 2764 static void LOG1PFloatMaxVectorTests(IntFunction<float[]> fa) { 2765 float[] a = fa.apply(SPECIES.length()); 2766 float[] r = fr.apply(SPECIES.length()); 2767 2768 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2769 for (int i = 0; i < a.length; i += SPECIES.length()) { 2770 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2771 av.lanewise(VectorOperators.LOG1P).intoArray(r, i); 2772 } 2773 } 2774 2775 assertArraysEqualsWithinOneUlp(a, r, FloatMaxVectorTests::LOG1P, FloatMaxVectorTests::strictLOG1P); 2776 } 2777 2778 2779 static float LOG(float a) { 2780 return (float)(Math.log((double)a)); 2781 } 2782 2783 static float strictLOG(float a) { 2784 return (float)(StrictMath.log((double)a)); 2785 } 2786 2787 @Test(dataProvider = "floatUnaryOpProvider") 2788 static void LOGFloatMaxVectorTests(IntFunction<float[]> fa) { 2789 float[] a = fa.apply(SPECIES.length()); 2790 float[] r = fr.apply(SPECIES.length()); 2791 2792 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2793 for (int i = 0; i < a.length; i += SPECIES.length()) { 2794 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2795 av.lanewise(VectorOperators.LOG).intoArray(r, i); 2796 } 2797 } 2798 2799 assertArraysEqualsWithinOneUlp(a, r, FloatMaxVectorTests::LOG, FloatMaxVectorTests::strictLOG); 2800 } 2801 2802 2803 static float LOG10(float a) { 2804 return (float)(Math.log10((double)a)); 2805 } 2806 2807 static float strictLOG10(float a) { 2808 return (float)(StrictMath.log10((double)a)); 2809 } 2810 2811 @Test(dataProvider = "floatUnaryOpProvider") 2812 static void LOG10FloatMaxVectorTests(IntFunction<float[]> fa) { 2813 float[] a = fa.apply(SPECIES.length()); 2814 float[] r = fr.apply(SPECIES.length()); 2815 2816 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2817 for (int i = 0; i < a.length; i += SPECIES.length()) { 2818 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2819 av.lanewise(VectorOperators.LOG10).intoArray(r, i); 2820 } 2821 } 2822 2823 assertArraysEqualsWithinOneUlp(a, r, FloatMaxVectorTests::LOG10, FloatMaxVectorTests::strictLOG10); 2824 } 2825 2826 2827 static float EXPM1(float a) { 2828 return (float)(Math.expm1((double)a)); 2829 } 2830 2831 static float strictEXPM1(float a) { 2832 return (float)(StrictMath.expm1((double)a)); 2833 } 2834 2835 @Test(dataProvider = "floatUnaryOpProvider") 2836 static void EXPM1FloatMaxVectorTests(IntFunction<float[]> fa) { 2837 float[] a = fa.apply(SPECIES.length()); 2838 float[] r = fr.apply(SPECIES.length()); 2839 2840 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2841 for (int i = 0; i < a.length; i += SPECIES.length()) { 2842 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2843 av.lanewise(VectorOperators.EXPM1).intoArray(r, i); 2844 } 2845 } 2846 2847 assertArraysEqualsWithinOneUlp(a, r, FloatMaxVectorTests::EXPM1, FloatMaxVectorTests::strictEXPM1); 2848 } 2849 2850 2851 static float COS(float a) { 2852 return (float)(Math.cos((double)a)); 2853 } 2854 2855 static float strictCOS(float a) { 2856 return (float)(StrictMath.cos((double)a)); 2857 } 2858 2859 @Test(dataProvider = "floatUnaryOpProvider") 2860 static void COSFloatMaxVectorTests(IntFunction<float[]> fa) { 2861 float[] a = fa.apply(SPECIES.length()); 2862 float[] r = fr.apply(SPECIES.length()); 2863 2864 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2865 for (int i = 0; i < a.length; i += SPECIES.length()) { 2866 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2867 av.lanewise(VectorOperators.COS).intoArray(r, i); 2868 } 2869 } 2870 2871 assertArraysEqualsWithinOneUlp(a, r, FloatMaxVectorTests::COS, FloatMaxVectorTests::strictCOS); 2872 } 2873 2874 2875 static float TAN(float a) { 2876 return (float)(Math.tan((double)a)); 2877 } 2878 2879 static float strictTAN(float a) { 2880 return (float)(StrictMath.tan((double)a)); 2881 } 2882 2883 @Test(dataProvider = "floatUnaryOpProvider") 2884 static void TANFloatMaxVectorTests(IntFunction<float[]> fa) { 2885 float[] a = fa.apply(SPECIES.length()); 2886 float[] r = fr.apply(SPECIES.length()); 2887 2888 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2889 for (int i = 0; i < a.length; i += SPECIES.length()) { 2890 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2891 av.lanewise(VectorOperators.TAN).intoArray(r, i); 2892 } 2893 } 2894 2895 assertArraysEqualsWithinOneUlp(a, r, FloatMaxVectorTests::TAN, FloatMaxVectorTests::strictTAN); 2896 } 2897 2898 2899 static float SINH(float a) { 2900 return (float)(Math.sinh((double)a)); 2901 } 2902 2903 static float strictSINH(float a) { 2904 return (float)(StrictMath.sinh((double)a)); 2905 } 2906 2907 @Test(dataProvider = "floatUnaryOpProvider") 2908 static void SINHFloatMaxVectorTests(IntFunction<float[]> fa) { 2909 float[] a = fa.apply(SPECIES.length()); 2910 float[] r = fr.apply(SPECIES.length()); 2911 2912 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2913 for (int i = 0; i < a.length; i += SPECIES.length()) { 2914 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2915 av.lanewise(VectorOperators.SINH).intoArray(r, i); 2916 } 2917 } 2918 2919 assertArraysEqualsWithinOneUlp(a, r, FloatMaxVectorTests::SINH, FloatMaxVectorTests::strictSINH); 2920 } 2921 2922 2923 static float COSH(float a) { 2924 return (float)(Math.cosh((double)a)); 2925 } 2926 2927 static float strictCOSH(float a) { 2928 return (float)(StrictMath.cosh((double)a)); 2929 } 2930 2931 @Test(dataProvider = "floatUnaryOpProvider") 2932 static void COSHFloatMaxVectorTests(IntFunction<float[]> fa) { 2933 float[] a = fa.apply(SPECIES.length()); 2934 float[] r = fr.apply(SPECIES.length()); 2935 2936 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2937 for (int i = 0; i < a.length; i += SPECIES.length()) { 2938 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2939 av.lanewise(VectorOperators.COSH).intoArray(r, i); 2940 } 2941 } 2942 2943 assertArraysEqualsWithinOneUlp(a, r, FloatMaxVectorTests::COSH, FloatMaxVectorTests::strictCOSH); 2944 } 2945 2946 2947 static float TANH(float a) { 2948 return (float)(Math.tanh((double)a)); 2949 } 2950 2951 static float strictTANH(float a) { 2952 return (float)(StrictMath.tanh((double)a)); 2953 } 2954 2955 @Test(dataProvider = "floatUnaryOpProvider") 2956 static void TANHFloatMaxVectorTests(IntFunction<float[]> fa) { 2957 float[] a = fa.apply(SPECIES.length()); 2958 float[] r = fr.apply(SPECIES.length()); 2959 2960 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2961 for (int i = 0; i < a.length; i += SPECIES.length()) { 2962 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2963 av.lanewise(VectorOperators.TANH).intoArray(r, i); 2964 } 2965 } 2966 2967 assertArraysEqualsWithinOneUlp(a, r, FloatMaxVectorTests::TANH, FloatMaxVectorTests::strictTANH); 2968 } 2969 2970 2971 static float ASIN(float a) { 2972 return (float)(Math.asin((double)a)); 2973 } 2974 2975 static float strictASIN(float a) { 2976 return (float)(StrictMath.asin((double)a)); 2977 } 2978 2979 @Test(dataProvider = "floatUnaryOpProvider") 2980 static void ASINFloatMaxVectorTests(IntFunction<float[]> fa) { 2981 float[] a = fa.apply(SPECIES.length()); 2982 float[] r = fr.apply(SPECIES.length()); 2983 2984 for (int ic = 0; ic < INVOC_COUNT; ic++) { 2985 for (int i = 0; i < a.length; i += SPECIES.length()) { 2986 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 2987 av.lanewise(VectorOperators.ASIN).intoArray(r, i); 2988 } 2989 } 2990 2991 assertArraysEqualsWithinOneUlp(a, r, FloatMaxVectorTests::ASIN, FloatMaxVectorTests::strictASIN); 2992 } 2993 2994 2995 static float ACOS(float a) { 2996 return (float)(Math.acos((double)a)); 2997 } 2998 2999 static float strictACOS(float a) { 3000 return (float)(StrictMath.acos((double)a)); 3001 } 3002 3003 @Test(dataProvider = "floatUnaryOpProvider") 3004 static void ACOSFloatMaxVectorTests(IntFunction<float[]> fa) { 3005 float[] a = fa.apply(SPECIES.length()); 3006 float[] r = fr.apply(SPECIES.length()); 3007 3008 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3009 for (int i = 0; i < a.length; i += SPECIES.length()) { 3010 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 3011 av.lanewise(VectorOperators.ACOS).intoArray(r, i); 3012 } 3013 } 3014 3015 assertArraysEqualsWithinOneUlp(a, r, FloatMaxVectorTests::ACOS, FloatMaxVectorTests::strictACOS); 3016 } 3017 3018 3019 static float ATAN(float a) { 3020 return (float)(Math.atan((double)a)); 3021 } 3022 3023 static float strictATAN(float a) { 3024 return (float)(StrictMath.atan((double)a)); 3025 } 3026 3027 @Test(dataProvider = "floatUnaryOpProvider") 3028 static void ATANFloatMaxVectorTests(IntFunction<float[]> fa) { 3029 float[] a = fa.apply(SPECIES.length()); 3030 float[] r = fr.apply(SPECIES.length()); 3031 3032 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3033 for (int i = 0; i < a.length; i += SPECIES.length()) { 3034 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 3035 av.lanewise(VectorOperators.ATAN).intoArray(r, i); 3036 } 3037 } 3038 3039 assertArraysEqualsWithinOneUlp(a, r, FloatMaxVectorTests::ATAN, FloatMaxVectorTests::strictATAN); 3040 } 3041 3042 3043 static float CBRT(float a) { 3044 return (float)(Math.cbrt((double)a)); 3045 } 3046 3047 static float strictCBRT(float a) { 3048 return (float)(StrictMath.cbrt((double)a)); 3049 } 3050 3051 @Test(dataProvider = "floatUnaryOpProvider") 3052 static void CBRTFloatMaxVectorTests(IntFunction<float[]> fa) { 3053 float[] a = fa.apply(SPECIES.length()); 3054 float[] r = fr.apply(SPECIES.length()); 3055 3056 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3057 for (int i = 0; i < a.length; i += SPECIES.length()) { 3058 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 3059 av.lanewise(VectorOperators.CBRT).intoArray(r, i); 3060 } 3061 } 3062 3063 assertArraysEqualsWithinOneUlp(a, r, FloatMaxVectorTests::CBRT, FloatMaxVectorTests::strictCBRT); 3064 } 3065 3066 3067 static float HYPOT(float a, float b) { 3068 return (float)(Math.hypot((double)a, (double)b)); 3069 } 3070 3071 static float strictHYPOT(float a, float b) { 3072 return (float)(StrictMath.hypot((double)a, (double)b)); 3073 } 3074 3075 @Test(dataProvider = "floatBinaryOpProvider") 3076 static void HYPOTFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) { 3077 float[] a = fa.apply(SPECIES.length()); 3078 float[] b = fb.apply(SPECIES.length()); 3079 float[] r = fr.apply(SPECIES.length()); 3080 3081 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3082 for (int i = 0; i < a.length; i += SPECIES.length()) { 3083 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 3084 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 3085 av.lanewise(VectorOperators.HYPOT, bv).intoArray(r, i); 3086 } 3087 } 3088 3089 assertArraysEqualsWithinOneUlp(a, b, r, FloatMaxVectorTests::HYPOT, FloatMaxVectorTests::strictHYPOT); 3090 } 3091 3092 3093 3094 static float POW(float a, float b) { 3095 return (float)(Math.pow((double)a, (double)b)); 3096 } 3097 3098 static float strictPOW(float a, float b) { 3099 return (float)(StrictMath.pow((double)a, (double)b)); 3100 } 3101 3102 @Test(dataProvider = "floatBinaryOpProvider") 3103 static void POWFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) { 3104 float[] a = fa.apply(SPECIES.length()); 3105 float[] b = fb.apply(SPECIES.length()); 3106 float[] r = fr.apply(SPECIES.length()); 3107 3108 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3109 for (int i = 0; i < a.length; i += SPECIES.length()) { 3110 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 3111 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 3112 av.lanewise(VectorOperators.POW, bv).intoArray(r, i); 3113 } 3114 } 3115 3116 assertArraysEqualsWithinOneUlp(a, b, r, FloatMaxVectorTests::POW, FloatMaxVectorTests::strictPOW); 3117 } 3118 3119 3120 3121 static float ATAN2(float a, float b) { 3122 return (float)(Math.atan2((double)a, (double)b)); 3123 } 3124 3125 static float strictATAN2(float a, float b) { 3126 return (float)(StrictMath.atan2((double)a, (double)b)); 3127 } 3128 3129 @Test(dataProvider = "floatBinaryOpProvider") 3130 static void ATAN2FloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) { 3131 float[] a = fa.apply(SPECIES.length()); 3132 float[] b = fb.apply(SPECIES.length()); 3133 float[] r = fr.apply(SPECIES.length()); 3134 3135 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3136 for (int i = 0; i < a.length; i += SPECIES.length()) { 3137 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 3138 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 3139 av.lanewise(VectorOperators.ATAN2, bv).intoArray(r, i); 3140 } 3141 } 3142 3143 assertArraysEqualsWithinOneUlp(a, b, r, FloatMaxVectorTests::ATAN2, FloatMaxVectorTests::strictATAN2); 3144 } 3145 3146 3147 3148 static float FMA(float a, float b, float c) { 3149 return (float)(Math.fma(a, b, c)); 3150 } 3151 3152 3153 @Test(dataProvider = "floatTernaryOpProvider") 3154 static void FMAFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb, IntFunction<float[]> fc) { 3155 float[] a = fa.apply(SPECIES.length()); 3156 float[] b = fb.apply(SPECIES.length()); 3157 float[] c = fc.apply(SPECIES.length()); 3158 float[] r = fr.apply(SPECIES.length()); 3159 3160 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3161 for (int i = 0; i < a.length; i += SPECIES.length()) { 3162 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 3163 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 3164 FloatVector cv = FloatVector.fromArray(SPECIES, c, i); 3165 av.lanewise(VectorOperators.FMA, bv, cv).intoArray(r, i); 3166 } 3167 } 3168 3169 assertArraysEquals(a, b, c, r, FloatMaxVectorTests::FMA); 3170 } 3171 3172 3173 @Test(dataProvider = "floatTernaryOpMaskProvider") 3174 static void FMAFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb, 3175 IntFunction<float[]> fc, IntFunction<boolean[]> fm) { 3176 float[] a = fa.apply(SPECIES.length()); 3177 float[] b = fb.apply(SPECIES.length()); 3178 float[] c = fc.apply(SPECIES.length()); 3179 float[] r = fr.apply(SPECIES.length()); 3180 boolean[] mask = fm.apply(SPECIES.length()); 3181 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3182 3183 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3184 for (int i = 0; i < a.length; i += SPECIES.length()) { 3185 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 3186 FloatVector bv = FloatVector.fromArray(SPECIES, b, i); 3187 FloatVector cv = FloatVector.fromArray(SPECIES, c, i); 3188 av.lanewise(VectorOperators.FMA, bv, cv, vmask).intoArray(r, i); 3189 } 3190 } 3191 3192 assertArraysEquals(a, b, c, r, mask, FloatMaxVectorTests::FMA); 3193 } 3194 3195 3196 3197 3198 3199 static float NEG(float a) { 3200 return (float)(-((float)a)); 3201 } 3202 3203 static float neg(float a) { 3204 return (float)(-((float)a)); 3205 } 3206 3207 @Test(dataProvider = "floatUnaryOpProvider") 3208 static void NEGFloatMaxVectorTests(IntFunction<float[]> fa) { 3209 float[] a = fa.apply(SPECIES.length()); 3210 float[] r = fr.apply(SPECIES.length()); 3211 3212 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3213 for (int i = 0; i < a.length; i += SPECIES.length()) { 3214 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 3215 av.lanewise(VectorOperators.NEG).intoArray(r, i); 3216 } 3217 } 3218 3219 assertArraysEquals(a, r, FloatMaxVectorTests::NEG); 3220 } 3221 3222 @Test(dataProvider = "floatUnaryOpProvider") 3223 static void negFloatMaxVectorTests(IntFunction<float[]> fa) { 3224 float[] a = fa.apply(SPECIES.length()); 3225 float[] r = fr.apply(SPECIES.length()); 3226 3227 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3228 for (int i = 0; i < a.length; i += SPECIES.length()) { 3229 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 3230 av.neg().intoArray(r, i); 3231 } 3232 } 3233 3234 assertArraysEquals(a, r, FloatMaxVectorTests::neg); 3235 } 3236 3237 @Test(dataProvider = "floatUnaryOpMaskProvider") 3238 static void NEGMaskedFloatMaxVectorTests(IntFunction<float[]> fa, 3239 IntFunction<boolean[]> fm) { 3240 float[] a = fa.apply(SPECIES.length()); 3241 float[] r = fr.apply(SPECIES.length()); 3242 boolean[] mask = fm.apply(SPECIES.length()); 3243 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3244 3245 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3246 for (int i = 0; i < a.length; i += SPECIES.length()) { 3247 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 3248 av.lanewise(VectorOperators.NEG, vmask).intoArray(r, i); 3249 } 3250 } 3251 3252 assertArraysEquals(a, r, mask, FloatMaxVectorTests::NEG); 3253 } 3254 3255 static float ABS(float a) { 3256 return (float)(Math.abs((float)a)); 3257 } 3258 3259 static float abs(float a) { 3260 return (float)(Math.abs((float)a)); 3261 } 3262 3263 @Test(dataProvider = "floatUnaryOpProvider") 3264 static void ABSFloatMaxVectorTests(IntFunction<float[]> fa) { 3265 float[] a = fa.apply(SPECIES.length()); 3266 float[] r = fr.apply(SPECIES.length()); 3267 3268 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3269 for (int i = 0; i < a.length; i += SPECIES.length()) { 3270 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 3271 av.lanewise(VectorOperators.ABS).intoArray(r, i); 3272 } 3273 } 3274 3275 assertArraysEquals(a, r, FloatMaxVectorTests::ABS); 3276 } 3277 3278 @Test(dataProvider = "floatUnaryOpProvider") 3279 static void absFloatMaxVectorTests(IntFunction<float[]> fa) { 3280 float[] a = fa.apply(SPECIES.length()); 3281 float[] r = fr.apply(SPECIES.length()); 3282 3283 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3284 for (int i = 0; i < a.length; i += SPECIES.length()) { 3285 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 3286 av.abs().intoArray(r, i); 3287 } 3288 } 3289 3290 assertArraysEquals(a, r, FloatMaxVectorTests::abs); 3291 } 3292 3293 @Test(dataProvider = "floatUnaryOpMaskProvider") 3294 static void ABSMaskedFloatMaxVectorTests(IntFunction<float[]> fa, 3295 IntFunction<boolean[]> fm) { 3296 float[] a = fa.apply(SPECIES.length()); 3297 float[] r = fr.apply(SPECIES.length()); 3298 boolean[] mask = fm.apply(SPECIES.length()); 3299 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3300 3301 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3302 for (int i = 0; i < a.length; i += SPECIES.length()) { 3303 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 3304 av.lanewise(VectorOperators.ABS, vmask).intoArray(r, i); 3305 } 3306 } 3307 3308 assertArraysEquals(a, r, mask, FloatMaxVectorTests::ABS); 3309 } 3310 3311 3312 3313 3314 3315 3316 3317 3318 static float SQRT(float a) { 3319 return (float)(Math.sqrt((double)a)); 3320 } 3321 3322 3323 3324 @Test(dataProvider = "floatUnaryOpProvider") 3325 static void SQRTFloatMaxVectorTests(IntFunction<float[]> fa) { 3326 float[] a = fa.apply(SPECIES.length()); 3327 float[] r = fr.apply(SPECIES.length()); 3328 3329 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3330 for (int i = 0; i < a.length; i += SPECIES.length()) { 3331 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 3332 av.lanewise(VectorOperators.SQRT).intoArray(r, i); 3333 } 3334 } 3335 3336 assertArraysEquals(a, r, FloatMaxVectorTests::SQRT); 3337 } 3338 3339 3340 3341 @Test(dataProvider = "floatUnaryOpMaskProvider") 3342 static void SQRTMaskedFloatMaxVectorTests(IntFunction<float[]> fa, 3343 IntFunction<boolean[]> fm) { 3344 float[] a = fa.apply(SPECIES.length()); 3345 float[] r = fr.apply(SPECIES.length()); 3346 boolean[] mask = fm.apply(SPECIES.length()); 3347 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3348 3349 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3350 for (int i = 0; i < a.length; i += SPECIES.length()) { 3351 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 3352 av.lanewise(VectorOperators.SQRT, vmask).intoArray(r, i); 3353 } 3354 } 3355 3356 assertArraysEquals(a, r, mask, FloatMaxVectorTests::SQRT); 3357 } 3358 3359 static float[] gather(float a[], int ix, int[] b, int iy) { 3360 float[] res = new float[SPECIES.length()]; 3361 for (int i = 0; i < SPECIES.length(); i++) { 3362 int bi = iy + i; 3363 res[i] = a[b[bi] + ix]; 3364 } 3365 return res; 3366 } 3367 3368 @Test(dataProvider = "floatUnaryOpIndexProvider") 3369 static void gatherFloatMaxVectorTests(IntFunction<float[]> fa, BiFunction<Integer,Integer,int[]> fs) { 3370 float[] a = fa.apply(SPECIES.length()); 3371 int[] b = fs.apply(a.length, SPECIES.length()); 3372 float[] r = new float[a.length]; 3373 3374 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3375 for (int i = 0; i < a.length; i += SPECIES.length()) { 3376 FloatVector av = FloatVector.fromArray(SPECIES, a, i, b, i); 3377 av.intoArray(r, i); 3378 } 3379 } 3380 3381 assertArraysEquals(a, b, r, FloatMaxVectorTests::gather); 3382 } 3383 static float[] gatherMasked(float a[], int ix, boolean[] mask, int[] b, int iy) { 3384 float[] res = new float[SPECIES.length()]; 3385 for (int i = 0; i < SPECIES.length(); i++) { 3386 int bi = iy + i; 3387 if (mask[i]) { 3388 res[i] = a[b[bi] + ix]; 3389 } 3390 } 3391 return res; 3392 } 3393 3394 @Test(dataProvider = "floatUnaryMaskedOpIndexProvider") 3395 static void gatherMaskedFloatMaxVectorTests(IntFunction<float[]> fa, BiFunction<Integer,Integer,int[]> fs, IntFunction<boolean[]> fm) { 3396 float[] a = fa.apply(SPECIES.length()); 3397 int[] b = fs.apply(a.length, SPECIES.length()); 3398 float[] r = new float[a.length]; 3399 boolean[] mask = fm.apply(SPECIES.length()); 3400 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3401 3402 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3403 for (int i = 0; i < a.length; i += SPECIES.length()) { 3404 FloatVector av = FloatVector.fromArray(SPECIES, a, i, b, i, vmask); 3405 av.intoArray(r, i); 3406 } 3407 } 3408 3409 assertArraysEquals(a, b, r, mask, FloatMaxVectorTests::gatherMasked); 3410 } 3411 3412 static float[] scatter(float a[], int ix, int[] b, int iy) { 3413 float[] res = new float[SPECIES.length()]; 3414 for (int i = 0; i < SPECIES.length(); i++) { 3415 int bi = iy + i; 3416 res[b[bi]] = a[i + ix]; 3417 } 3418 return res; 3419 } 3420 3421 @Test(dataProvider = "floatUnaryOpIndexProvider") 3422 static void scatterFloatMaxVectorTests(IntFunction<float[]> fa, BiFunction<Integer,Integer,int[]> fs) { 3423 float[] a = fa.apply(SPECIES.length()); 3424 int[] b = fs.apply(a.length, SPECIES.length()); 3425 float[] r = new float[a.length]; 3426 3427 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3428 for (int i = 0; i < a.length; i += SPECIES.length()) { 3429 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 3430 av.intoArray(r, i, b, i); 3431 } 3432 } 3433 3434 assertArraysEquals(a, b, r, FloatMaxVectorTests::scatter); 3435 } 3436 3437 static float[] scatterMasked(float r[], float a[], int ix, boolean[] mask, int[] b, int iy) { 3438 // First, gather r. 3439 float[] oldVal = gather(r, ix, b, iy); 3440 float[] newVal = new float[SPECIES.length()]; 3441 3442 // Second, blending it with a. 3443 for (int i = 0; i < SPECIES.length(); i++) { 3444 newVal[i] = blend(oldVal[i], a[i+ix], mask[i]); 3445 } 3446 3447 // Third, scatter: copy old value of r, and scatter it manually. 3448 float[] res = Arrays.copyOfRange(r, ix, ix+SPECIES.length()); 3449 for (int i = 0; i < SPECIES.length(); i++) { 3450 int bi = iy + i; 3451 res[b[bi]] = newVal[i]; 3452 } 3453 3454 return res; 3455 } 3456 3457 @Test(dataProvider = "scatterMaskedOpIndexProvider") 3458 static void scatterMaskedFloatMaxVectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb, BiFunction<Integer,Integer,int[]> fs, IntFunction<boolean[]> fm) { 3459 float[] a = fa.apply(SPECIES.length()); 3460 int[] b = fs.apply(a.length, SPECIES.length()); 3461 float[] r = fb.apply(SPECIES.length()); 3462 boolean[] mask = fm.apply(SPECIES.length()); 3463 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0); 3464 3465 for (int ic = 0; ic < INVOC_COUNT; ic++) { 3466 for (int i = 0; i < a.length; i += SPECIES.length()) { 3467 FloatVector av = FloatVector.fromArray(SPECIES, a, i); 3468 av.intoArray(r, i, b, i, vmask); 3469 } 3470 } 3471 3472 assertArraysEquals(a, b, r, mask, FloatMaxVectorTests::scatterMasked); 3473 } 3474 3475 } 3476