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