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