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