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