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