1 /*
2 * Copyright (c) 2018, 2024, 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 ByteMaxVectorTests
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 import jdk.incubator.vector.VectorMath;
42
43 import jdk.incubator.vector.ByteVector;
44
45 import org.testng.Assert;
46 import org.testng.annotations.DataProvider;
47 import org.testng.annotations.Test;
48
49 import java.lang.Integer;
50 import java.util.List;
51 import java.util.Arrays;
52 import java.util.function.BiFunction;
53 import java.util.function.IntFunction;
54 import java.util.Objects;
55 import java.util.stream.Collectors;
56 import java.util.stream.Stream;
57
58 @Test
59 public class ByteMaxVectorTests extends AbstractVectorTest {
60
61 static final VectorSpecies<Byte> SPECIES =
62 ByteVector.SPECIES_MAX;
63
64 static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100);
65
66 static VectorShape getMaxBit() {
67 return VectorShape.S_Max_BIT;
68 }
69
70 private static final int Max = 256; // juts so we can do N/Max
71
72 private static final byte CONST_SHIFT = Byte.SIZE / 2;
73
74 static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / Max);
75
76 static void assertArraysStrictlyEquals(byte[] r, byte[] a) {
77 for (int i = 0; i < a.length; i++) {
78 if (r[i] != a[i]) {
79 Assert.fail("at index #" + i + ", expected = " + a[i] + ", actual = " + r[i]);
80 }
81 }
82 }
83
84 interface FUnOp {
85 byte apply(byte a);
86 }
87
88 static void assertArraysEquals(byte[] r, byte[] a, FUnOp f) {
89 int i = 0;
90 try {
91 for (; i < a.length; i++) {
92 Assert.assertEquals(r[i], f.apply(a[i]));
93 }
94 } catch (AssertionError e) {
95 Assert.assertEquals(r[i], f.apply(a[i]), "at index #" + i + ", input = " + a[i]);
96 }
97 }
98
99 interface FUnArrayOp {
100 byte[] apply(byte a);
101 }
102
103 static void assertArraysEquals(byte[] r, byte[] a, FUnArrayOp f) {
104 int i = 0;
105 try {
106 for (; i < a.length; i += SPECIES.length()) {
107 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()),
108 f.apply(a[i]));
109 }
110 } catch (AssertionError e) {
111 byte[] ref = f.apply(a[i]);
112 byte[] res = Arrays.copyOfRange(r, i, i+SPECIES.length());
113 Assert.assertEquals(res, ref, "(ref: " + Arrays.toString(ref)
114 + ", res: " + Arrays.toString(res)
115 + "), at index #" + i);
116 }
117 }
118
119 static void assertArraysEquals(byte[] r, byte[] a, boolean[] mask, FUnOp f) {
120 int i = 0;
121 try {
122 for (; i < a.length; i++) {
123 Assert.assertEquals(r[i], mask[i % SPECIES.length()] ? f.apply(a[i]) : a[i]);
124 }
125 } catch (AssertionError e) {
126 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()]);
127 }
128 }
129
130 interface FReductionOp {
131 byte apply(byte[] a, int idx);
132 }
133
134 interface FReductionAllOp {
135 byte apply(byte[] a);
136 }
137
138 static void assertReductionArraysEquals(byte[] r, byte rc, byte[] a,
139 FReductionOp f, FReductionAllOp fa) {
140 int i = 0;
141 try {
142 Assert.assertEquals(rc, fa.apply(a));
143 for (; i < a.length; i += SPECIES.length()) {
144 Assert.assertEquals(r[i], f.apply(a, i));
145 }
146 } catch (AssertionError e) {
147 Assert.assertEquals(rc, fa.apply(a), "Final result is incorrect!");
148 Assert.assertEquals(r[i], f.apply(a, i), "at index #" + i);
149 }
150 }
151
152 interface FReductionMaskedOp {
153 byte apply(byte[] a, int idx, boolean[] mask);
154 }
155
156 interface FReductionAllMaskedOp {
157 byte apply(byte[] a, boolean[] mask);
158 }
159
160 static void assertReductionArraysEqualsMasked(byte[] r, byte rc, byte[] a, boolean[] mask,
161 FReductionMaskedOp f, FReductionAllMaskedOp fa) {
162 int i = 0;
163 try {
164 Assert.assertEquals(rc, fa.apply(a, mask));
165 for (; i < a.length; i += SPECIES.length()) {
166 Assert.assertEquals(r[i], f.apply(a, i, mask));
167 }
168 } catch (AssertionError e) {
169 Assert.assertEquals(rc, fa.apply(a, mask), "Final result is incorrect!");
170 Assert.assertEquals(r[i], f.apply(a, i, mask), "at index #" + i);
171 }
172 }
173
174 interface FReductionOpLong {
175 long apply(byte[] a, int idx);
176 }
177
178 interface FReductionAllOpLong {
179 long apply(byte[] a);
180 }
181
182 static void assertReductionLongArraysEquals(long[] r, long rc, byte[] a,
183 FReductionOpLong f, FReductionAllOpLong fa) {
184 int i = 0;
185 try {
186 Assert.assertEquals(rc, fa.apply(a));
187 for (; i < a.length; i += SPECIES.length()) {
188 Assert.assertEquals(r[i], f.apply(a, i));
189 }
190 } catch (AssertionError e) {
191 Assert.assertEquals(rc, fa.apply(a), "Final result is incorrect!");
192 Assert.assertEquals(r[i], f.apply(a, i), "at index #" + i);
193 }
194 }
195
196 interface FReductionMaskedOpLong {
197 long apply(byte[] a, int idx, boolean[] mask);
198 }
199
200 interface FReductionAllMaskedOpLong {
201 long apply(byte[] a, boolean[] mask);
202 }
203
204 static void assertReductionLongArraysEqualsMasked(long[] r, long rc, byte[] a, boolean[] mask,
205 FReductionMaskedOpLong f, FReductionAllMaskedOpLong fa) {
206 int i = 0;
207 try {
208 Assert.assertEquals(rc, fa.apply(a, mask));
209 for (; i < a.length; i += SPECIES.length()) {
210 Assert.assertEquals(r[i], f.apply(a, i, mask));
211 }
212 } catch (AssertionError e) {
213 Assert.assertEquals(rc, fa.apply(a, mask), "Final result is incorrect!");
214 Assert.assertEquals(r[i], f.apply(a, i, mask), "at index #" + i);
215 }
216 }
217
218 interface FBoolReductionOp {
219 boolean apply(boolean[] a, int idx);
220 }
221
222 static void assertReductionBoolArraysEquals(boolean[] r, boolean[] a, FBoolReductionOp f) {
223 int i = 0;
224 try {
225 for (; i < a.length; i += SPECIES.length()) {
226 Assert.assertEquals(r[i], f.apply(a, i));
227 }
228 } catch (AssertionError e) {
229 Assert.assertEquals(r[i], f.apply(a, i), "at index #" + i);
230 }
231 }
232
233 interface FMaskReductionOp {
234 int apply(boolean[] a, int idx);
235 }
236
237 static void assertMaskReductionArraysEquals(int[] r, boolean[] a, FMaskReductionOp f) {
238 int i = 0;
239 try {
240 for (; i < a.length; i += SPECIES.length()) {
241 Assert.assertEquals(r[i], f.apply(a, i));
242 }
243 } catch (AssertionError e) {
244 Assert.assertEquals(r[i], f.apply(a, i), "at index #" + i);
245 }
246 }
247
248 static void assertRearrangeArraysEquals(byte[] r, byte[] a, int[] order, int vector_len) {
249 int i = 0, j = 0;
250 try {
251 for (; i < a.length; i += vector_len) {
252 for (j = 0; j < vector_len; j++) {
253 Assert.assertEquals(r[i+j], a[i+order[i+j]]);
254 }
255 }
256 } catch (AssertionError e) {
257 int idx = i + j;
258 Assert.assertEquals(r[i+j], a[i+order[i+j]], "at index #" + idx + ", input = " + a[i+order[i+j]]);
259 }
260 }
261
262 static void assertcompressArraysEquals(byte[] r, byte[] a, boolean[] m, int vector_len) {
263 int i = 0, j = 0, k = 0;
264 try {
265 for (; i < a.length; i += vector_len) {
266 k = 0;
267 for (j = 0; j < vector_len; j++) {
268 if (m[(i + j) % SPECIES.length()]) {
269 Assert.assertEquals(r[i + k], a[i + j]);
270 k++;
271 }
272 }
273 for (; k < vector_len; k++) {
274 Assert.assertEquals(r[i + k], (byte)0);
275 }
276 }
277 } catch (AssertionError e) {
278 int idx = i + k;
279 if (m[(i + j) % SPECIES.length()]) {
280 Assert.assertEquals(r[idx], a[i + j], "at index #" + idx);
281 } else {
282 Assert.assertEquals(r[idx], (byte)0, "at index #" + idx);
283 }
284 }
285 }
286
287 static void assertexpandArraysEquals(byte[] r, byte[] a, boolean[] m, int vector_len) {
288 int i = 0, j = 0, k = 0;
289 try {
290 for (; i < a.length; i += vector_len) {
291 k = 0;
292 for (j = 0; j < vector_len; j++) {
293 if (m[(i + j) % SPECIES.length()]) {
294 Assert.assertEquals(r[i + j], a[i + k]);
295 k++;
296 } else {
297 Assert.assertEquals(r[i + j], (byte)0);
298 }
299 }
300 }
301 } catch (AssertionError e) {
302 int idx = i + j;
303 if (m[idx % SPECIES.length()]) {
304 Assert.assertEquals(r[idx], a[i + k], "at index #" + idx);
305 } else {
306 Assert.assertEquals(r[idx], (byte)0, "at index #" + idx);
307 }
308 }
309 }
310
311 static void assertSelectFromTwoVectorEquals(byte[] r, byte[] order, byte[] a, byte[] b, int vector_len) {
312 int i = 0, j = 0;
313 boolean is_exceptional_idx = false;
314 int idx = 0, wrapped_index = 0, oidx = 0;
315 try {
316 for (; i < a.length; i += vector_len) {
317 for (j = 0; j < vector_len; j++) {
318 idx = i + j;
319 wrapped_index = Math.floorMod((int)order[idx], 2 * vector_len);
320 is_exceptional_idx = wrapped_index >= vector_len;
321 oidx = is_exceptional_idx ? (wrapped_index - vector_len) : wrapped_index;
322 Assert.assertEquals(r[idx], (is_exceptional_idx ? b[i + oidx] : a[i + oidx]));
323 }
324 }
325 } catch (AssertionError e) {
326 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]);
327 }
328 }
329
330 static void assertSelectFromArraysEquals(byte[] r, byte[] a, byte[] order, int vector_len) {
331 int i = 0, j = 0;
332 try {
333 for (; i < a.length; i += vector_len) {
334 for (j = 0; j < vector_len; j++) {
335 Assert.assertEquals(r[i+j], a[i+(int)order[i+j]]);
336 }
337 }
338 } catch (AssertionError e) {
339 int idx = i + j;
340 Assert.assertEquals(r[i+j], a[i+(int)order[i+j]], "at index #" + idx + ", input = " + a[i+(int)order[i+j]]);
341 }
342 }
343
344 static void assertRearrangeArraysEquals(byte[] r, byte[] a, int[] order, boolean[] mask, int vector_len) {
345 int i = 0, j = 0;
346 try {
347 for (; i < a.length; i += vector_len) {
348 for (j = 0; j < vector_len; j++) {
349 if (mask[j % SPECIES.length()])
350 Assert.assertEquals(r[i+j], a[i+order[i+j]]);
351 else
352 Assert.assertEquals(r[i+j], (byte)0);
353 }
354 }
355 } catch (AssertionError e) {
356 int idx = i + j;
357 if (mask[j % SPECIES.length()])
358 Assert.assertEquals(r[i+j], a[i+order[i+j]], "at index #" + idx + ", input = " + a[i+order[i+j]] + ", mask = " + mask[j % SPECIES.length()]);
359 else
360 Assert.assertEquals(r[i+j], (byte)0, "at index #" + idx + ", input = " + a[i+order[i+j]] + ", mask = " + mask[j % SPECIES.length()]);
361 }
362 }
363
364 static void assertSelectFromArraysEquals(byte[] r, byte[] a, byte[] 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+(int)order[i+j]]);
371 else
372 Assert.assertEquals(r[i+j], (byte)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+(int)order[i+j]], "at index #" + idx + ", input = " + a[i+(int)order[i+j]] + ", mask = " + mask[j % SPECIES.length()]);
379 else
380 Assert.assertEquals(r[i+j], (byte)0, "at index #" + idx + ", input = " + a[i+(int)order[i+j]] + ", mask = " + mask[j % SPECIES.length()]);
381 }
382 }
383
384 static void assertBroadcastArraysEquals(byte[] r, byte[] a) {
385 int i = 0;
386 for (; i < a.length; i += SPECIES.length()) {
387 int idx = i;
388 for (int j = idx; j < (idx + SPECIES.length()); j++)
389 a[j]=a[idx];
390 }
391
392 try {
393 for (i = 0; i < a.length; i++) {
394 Assert.assertEquals(r[i], a[i]);
395 }
396 } catch (AssertionError e) {
397 Assert.assertEquals(r[i], a[i], "at index #" + i + ", input = " + a[i]);
398 }
399 }
400
401 interface FBinOp {
402 byte apply(byte a, byte b);
403 }
404
405 interface FBinMaskOp {
406 byte apply(byte a, byte b, boolean m);
407
408 static FBinMaskOp lift(FBinOp f) {
409 return (a, b, m) -> m ? f.apply(a, b) : a;
410 }
411 }
412
413 static void assertArraysEqualsAssociative(byte[] rl, byte[] rr, byte[] a, byte[] b, byte[] c, FBinOp f) {
414 int i = 0;
415 try {
416 for (; i < a.length; i++) {
417 //Left associative
418 Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i]), c[i]));
419
420 //Right associative
421 Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i])));
422
423 //Results equal sanity check
424 Assert.assertEquals(rl[i], rr[i]);
425 }
426 } catch (AssertionError e) {
427 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]);
428 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]);
429 Assert.assertEquals(rl[i], rr[i], "Result checks not equal at index #" + i + "leftRes = " + rl[i] + ", rightRes = " + rr[i]);
430 }
431 }
432
433 static void assertArraysEqualsAssociative(byte[] rl, byte[] rr, byte[] a, byte[] b, byte[] c, boolean[] mask, FBinOp f) {
434 assertArraysEqualsAssociative(rl, rr, a, b, c, mask, FBinMaskOp.lift(f));
435 }
436
437 static void assertArraysEqualsAssociative(byte[] rl, byte[] rr, byte[] a, byte[] b, byte[] c, boolean[] mask, FBinMaskOp f) {
438 int i = 0;
439 boolean mask_bit = false;
440 try {
441 for (; i < a.length; i++) {
442 mask_bit = mask[i % SPECIES.length()];
443 //Left associative
444 Assert.assertEquals(rl[i], f.apply(f.apply(a[i], b[i], mask_bit), c[i], mask_bit));
445
446 //Right associative
447 Assert.assertEquals(rr[i], f.apply(a[i], f.apply(b[i], c[i], mask_bit), mask_bit));
448
449 //Results equal sanity check
450 Assert.assertEquals(rl[i], rr[i]);
451 }
452 } catch (AssertionError e) {
453 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);
454 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);
455 Assert.assertEquals(rl[i], rr[i], "Result checks not equal at index #" + i + "leftRes = " + rl[i] + ", rightRes = " + rr[i]);
456 }
457 }
458
459 static void assertArraysEquals(byte[] r, byte[] a, byte[] b, FBinOp f) {
460 int i = 0;
461 try {
462 for (; i < a.length; i++) {
463 Assert.assertEquals(r[i], f.apply(a[i], b[i]));
464 }
465 } catch (AssertionError e) {
466 Assert.assertEquals(r[i], f.apply(a[i], b[i]), "(" + a[i] + ", " + b[i] + ") at index #" + i);
467 }
468 }
469
470 static void assertArraysEquals(byte[] r, byte[] a, byte b, FBinOp f) {
471 int i = 0;
472 try {
473 for (; i < a.length; i++) {
474 Assert.assertEquals(r[i], f.apply(a[i], b));
475 }
476 } catch (AssertionError e) {
477 Assert.assertEquals(r[i], f.apply(a[i], b), "(" + a[i] + ", " + b + ") at index #" + i);
478 }
479 }
480
481 static void assertBroadcastArraysEquals(byte[] r, byte[] a, byte[] b, FBinOp f) {
482 int i = 0;
483 try {
484 for (; i < a.length; i++) {
485 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()]));
486 }
487 } catch (AssertionError e) {
488 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()]),
489 "(" + a[i] + ", " + b[(i / SPECIES.length()) * SPECIES.length()] + ") at index #" + i);
490 }
491 }
492
493 static void assertBroadcastLongArraysEquals(byte[] r, byte[] a, byte[] b, FBinOp f) {
494 int i = 0;
495 try {
496 for (; i < a.length; i++) {
497 Assert.assertEquals(r[i], f.apply(a[i], (byte)((long)b[(i / SPECIES.length()) * SPECIES.length()])));
498 }
499 } catch (AssertionError e) {
500 Assert.assertEquals(r[i], f.apply(a[i], (byte)((long)b[(i / SPECIES.length()) * SPECIES.length()])),
501 "(" + a[i] + ", " + b[(i / SPECIES.length()) * SPECIES.length()] + ") at index #" + i);
502 }
503 }
504
505 static void assertArraysEquals(byte[] r, byte[] a, byte[] b, boolean[] mask, FBinOp f) {
506 assertArraysEquals(r, a, b, mask, FBinMaskOp.lift(f));
507 }
508
509 static void assertArraysEquals(byte[] r, byte[] a, byte[] b, boolean[] mask, FBinMaskOp f) {
510 int i = 0;
511 try {
512 for (; i < a.length; i++) {
513 Assert.assertEquals(r[i], f.apply(a[i], b[i], mask[i % SPECIES.length()]));
514 }
515 } catch (AssertionError err) {
516 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()]);
517 }
518 }
519
520 static void assertArraysEquals(byte[] r, byte[] a, byte b, boolean[] mask, FBinOp f) {
521 assertArraysEquals(r, a, b, mask, FBinMaskOp.lift(f));
522 }
523
524 static void assertArraysEquals(byte[] r, byte[] a, byte b, boolean[] mask, FBinMaskOp f) {
525 int i = 0;
526 try {
527 for (; i < a.length; i++) {
528 Assert.assertEquals(r[i], f.apply(a[i], b, mask[i % SPECIES.length()]));
529 }
530 } catch (AssertionError err) {
531 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()]);
532 }
533 }
534
535 static void assertBroadcastArraysEquals(byte[] r, byte[] a, byte[] b, boolean[] mask, FBinOp f) {
536 assertBroadcastArraysEquals(r, a, b, mask, FBinMaskOp.lift(f));
537 }
538
539 static void assertBroadcastArraysEquals(byte[] r, byte[] a, byte[] b, boolean[] mask, FBinMaskOp f) {
540 int i = 0;
541 try {
542 for (; i < a.length; i++) {
543 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], mask[i % SPECIES.length()]));
544 }
545 } catch (AssertionError err) {
546 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()],
547 mask[i % SPECIES.length()]), "at index #" + i + ", input1 = " + a[i] +
548 ", input2 = " + b[(i / SPECIES.length()) * SPECIES.length()] + ", mask = " +
549 mask[i % SPECIES.length()]);
550 }
551 }
552
553 static void assertBroadcastLongArraysEquals(byte[] r, byte[] a, byte[] b, boolean[] mask, FBinOp f) {
554 assertBroadcastLongArraysEquals(r, a, b, mask, FBinMaskOp.lift(f));
555 }
556
557 static void assertBroadcastLongArraysEquals(byte[] r, byte[] a, byte[] b, boolean[] mask, FBinMaskOp f) {
558 int i = 0;
559 try {
560 for (; i < a.length; i++) {
561 Assert.assertEquals(r[i], f.apply(a[i], (byte)((long)b[(i / SPECIES.length()) * SPECIES.length()]), mask[i % SPECIES.length()]));
562 }
563 } catch (AssertionError err) {
564 Assert.assertEquals(r[i], f.apply(a[i], (byte)((long)b[(i / SPECIES.length()) * SPECIES.length()]),
565 mask[i % SPECIES.length()]), "at index #" + i + ", input1 = " + a[i] +
566 ", input2 = " + b[(i / SPECIES.length()) * SPECIES.length()] + ", mask = " +
567 mask[i % SPECIES.length()]);
568 }
569 }
570
571 static void assertShiftArraysEquals(byte[] r, byte[] a, byte[] b, FBinOp f) {
572 int i = 0;
573 int j = 0;
574 try {
575 for (; j < a.length; j += SPECIES.length()) {
576 for (i = 0; i < SPECIES.length(); i++) {
577 Assert.assertEquals(r[i+j], f.apply(a[i+j], b[j]));
578 }
579 }
580 } catch (AssertionError e) {
581 Assert.assertEquals(r[i+j], f.apply(a[i+j], b[j]), "at index #" + i + ", " + j);
582 }
583 }
584
585 static void assertShiftArraysEquals(byte[] r, byte[] a, byte[] b, boolean[] mask, FBinOp f) {
586 assertShiftArraysEquals(r, a, b, mask, FBinMaskOp.lift(f));
587 }
588
589 static void assertShiftArraysEquals(byte[] r, byte[] a, byte[] b, boolean[] mask, FBinMaskOp f) {
590 int i = 0;
591 int j = 0;
592 try {
593 for (; j < a.length; j += SPECIES.length()) {
594 for (i = 0; i < SPECIES.length(); i++) {
595 Assert.assertEquals(r[i+j], f.apply(a[i+j], b[j], mask[i]));
596 }
597 }
598 } catch (AssertionError err) {
599 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]);
600 }
601 }
602
603 interface FBinConstOp {
604 byte apply(byte a);
605 }
606
607 interface FBinConstMaskOp {
608 byte apply(byte a, boolean m);
609
610 static FBinConstMaskOp lift(FBinConstOp f) {
611 return (a, m) -> m ? f.apply(a) : a;
612 }
613 }
614
615 static void assertShiftConstEquals(byte[] r, byte[] a, FBinConstOp f) {
616 int i = 0;
617 int j = 0;
618 try {
619 for (; j < a.length; j += SPECIES.length()) {
620 for (i = 0; i < SPECIES.length(); i++) {
621 Assert.assertEquals(r[i+j], f.apply(a[i+j]));
622 }
623 }
624 } catch (AssertionError e) {
625 Assert.assertEquals(r[i+j], f.apply(a[i+j]), "at index #" + i + ", " + j);
626 }
627 }
628
629 static void assertShiftConstEquals(byte[] r, byte[] a, boolean[] mask, FBinConstOp f) {
630 assertShiftConstEquals(r, a, mask, FBinConstMaskOp.lift(f));
631 }
632
633 static void assertShiftConstEquals(byte[] r, byte[] a, boolean[] mask, FBinConstMaskOp f) {
634 int i = 0;
635 int j = 0;
636 try {
637 for (; j < a.length; j += SPECIES.length()) {
638 for (i = 0; i < SPECIES.length(); i++) {
639 Assert.assertEquals(r[i+j], f.apply(a[i+j], mask[i]));
640 }
641 }
642 } catch (AssertionError err) {
643 Assert.assertEquals(r[i+j], f.apply(a[i+j], mask[i]), "at index #" + i + ", input1 = " + a[i+j] + ", mask = " + mask[i]);
644 }
645 }
646
647 interface FTernOp {
648 byte apply(byte a, byte b, byte c);
649 }
650
651 interface FTernMaskOp {
652 byte apply(byte a, byte b, byte c, boolean m);
653
654 static FTernMaskOp lift(FTernOp f) {
655 return (a, b, c, m) -> m ? f.apply(a, b, c) : a;
656 }
657 }
658
659 static void assertArraysEquals(byte[] r, byte[] a, byte[] b, byte[] c, FTernOp f) {
660 int i = 0;
661 try {
662 for (; i < a.length; i++) {
663 Assert.assertEquals(r[i], f.apply(a[i], b[i], c[i]));
664 }
665 } catch (AssertionError e) {
666 Assert.assertEquals(r[i], f.apply(a[i], b[i], c[i]), "at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " + c[i]);
667 }
668 }
669
670 static void assertArraysEquals(byte[] r, byte[] a, byte[] b, byte[] c, boolean[] mask, FTernOp f) {
671 assertArraysEquals(r, a, b, c, mask, FTernMaskOp.lift(f));
672 }
673
674 static void assertArraysEquals(byte[] r, byte[] a, byte[] b, byte[] c, boolean[] mask, FTernMaskOp f) {
675 int i = 0;
676 try {
677 for (; i < a.length; i++) {
678 Assert.assertEquals(r[i], f.apply(a[i], b[i], c[i], mask[i % SPECIES.length()]));
679 }
680 } catch (AssertionError err) {
681 Assert.assertEquals(r[i], f.apply(a[i], b[i], c[i], mask[i % SPECIES.length()]), "at index #" + i + ", input1 = " + a[i] + ", input2 = "
682 + b[i] + ", input3 = " + c[i] + ", mask = " + mask[i % SPECIES.length()]);
683 }
684 }
685
686 static void assertBroadcastArraysEquals(byte[] r, byte[] a, byte[] b, byte[] c, FTernOp f) {
687 int i = 0;
688 try {
689 for (; i < a.length; i++) {
690 Assert.assertEquals(r[i], f.apply(a[i], b[i], c[(i / SPECIES.length()) * SPECIES.length()]));
691 }
692 } catch (AssertionError e) {
693 Assert.assertEquals(r[i], f.apply(a[i], b[i], c[(i / SPECIES.length()) * SPECIES.length()]), "at index #" +
694 i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", input3 = " +
695 c[(i / SPECIES.length()) * SPECIES.length()]);
696 }
697 }
698
699 static void assertAltBroadcastArraysEquals(byte[] r, byte[] a, byte[] b, byte[] c, FTernOp f) {
700 int i = 0;
701 try {
702 for (; i < a.length; i++) {
703 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], c[i]));
704 }
705 } catch (AssertionError e) {
706 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], c[i]), "at index #" +
707 i + ", input1 = " + a[i] + ", input2 = " +
708 b[(i / SPECIES.length()) * SPECIES.length()] + ", input3 = " + c[i]);
709 }
710 }
711
712 static void assertBroadcastArraysEquals(byte[] r, byte[] a, byte[] b, byte[] c, boolean[] mask,
713 FTernOp f) {
714 assertBroadcastArraysEquals(r, a, b, c, mask, FTernMaskOp.lift(f));
715 }
716
717 static void assertBroadcastArraysEquals(byte[] r, byte[] a, byte[] b, byte[] c, boolean[] mask,
718 FTernMaskOp f) {
719 int i = 0;
720 try {
721 for (; i < a.length; i++) {
722 Assert.assertEquals(r[i], f.apply(a[i], b[i], c[(i / SPECIES.length()) * SPECIES.length()],
723 mask[i % SPECIES.length()]));
724 }
725 } catch (AssertionError err) {
726 Assert.assertEquals(r[i], f.apply(a[i], b[i], c[(i / SPECIES.length()) * SPECIES.length()],
727 mask[i % SPECIES.length()]), "at index #" + i + ", input1 = " + a[i] + ", input2 = " +
728 b[i] + ", input3 = " + c[(i / SPECIES.length()) * SPECIES.length()] + ", mask = " +
729 mask[i % SPECIES.length()]);
730 }
731 }
732
733 static void assertAltBroadcastArraysEquals(byte[] r, byte[] a, byte[] b, byte[] c, boolean[] mask,
734 FTernOp f) {
735 assertAltBroadcastArraysEquals(r, a, b, c, mask, FTernMaskOp.lift(f));
736 }
737
738 static void assertAltBroadcastArraysEquals(byte[] r, byte[] a, byte[] b, byte[] c, boolean[] mask,
739 FTernMaskOp f) {
740 int i = 0;
741 try {
742 for (; i < a.length; i++) {
743 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], c[i],
744 mask[i % SPECIES.length()]));
745 }
746 } catch (AssertionError err) {
747 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], c[i],
748 mask[i % SPECIES.length()]), "at index #" + i + ", input1 = " + a[i] +
749 ", input2 = " + b[(i / SPECIES.length()) * SPECIES.length()] +
750 ", input3 = " + c[i] + ", mask = " + mask[i % SPECIES.length()]);
751 }
752 }
753
754 static void assertDoubleBroadcastArraysEquals(byte[] r, byte[] a, byte[] b, byte[] c, FTernOp f) {
755 int i = 0;
756 try {
757 for (; i < a.length; i++) {
758 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()],
759 c[(i / SPECIES.length()) * SPECIES.length()]));
760 }
761 } catch (AssertionError e) {
762 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()],
763 c[(i / SPECIES.length()) * SPECIES.length()]), "at index #" + i + ", input1 = " + a[i]
764 + ", input2 = " + b[(i / SPECIES.length()) * SPECIES.length()] + ", input3 = " +
765 c[(i / SPECIES.length()) * SPECIES.length()]);
766 }
767 }
768
769 static void assertDoubleBroadcastArraysEquals(byte[] r, byte[] a, byte[] b, byte[] c, boolean[] mask,
770 FTernOp f) {
771 assertDoubleBroadcastArraysEquals(r, a, b, c, mask, FTernMaskOp.lift(f));
772 }
773
774 static void assertDoubleBroadcastArraysEquals(byte[] r, byte[] a, byte[] b, byte[] c, boolean[] mask,
775 FTernMaskOp f) {
776 int i = 0;
777 try {
778 for (; i < a.length; i++) {
779 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()],
780 c[(i / SPECIES.length()) * SPECIES.length()], mask[i % SPECIES.length()]));
781 }
782 } catch (AssertionError err) {
783 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()],
784 c[(i / SPECIES.length()) * SPECIES.length()], mask[i % SPECIES.length()]), "at index #"
785 + i + ", input1 = " + a[i] + ", input2 = " + b[(i / SPECIES.length()) * SPECIES.length()] +
786 ", input3 = " + c[(i / SPECIES.length()) * SPECIES.length()] + ", mask = " +
787 mask[i % SPECIES.length()]);
788 }
789 }
790
791
792
793 interface FGatherScatterOp {
794 byte[] apply(byte[] a, int ix, int[] b, int iy);
795 }
796
797 static void assertArraysEquals(byte[] r, byte[] a, int[] b, FGatherScatterOp f) {
798 int i = 0;
799 try {
800 for (; i < a.length; i += SPECIES.length()) {
801 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()),
802 f.apply(a, i, b, i));
803 }
804 } catch (AssertionError e) {
805 byte[] ref = f.apply(a, i, b, i);
806 byte[] res = Arrays.copyOfRange(r, i, i+SPECIES.length());
807 Assert.assertEquals(res, ref,
808 "(ref: " + Arrays.toString(ref) + ", res: " + Arrays.toString(res) + ", a: "
809 + Arrays.toString(Arrays.copyOfRange(a, i, i+SPECIES.length()))
810 + ", b: "
811 + Arrays.toString(Arrays.copyOfRange(b, i, i+SPECIES.length()))
812 + " at index #" + i);
813 }
814 }
815
816 interface FGatherMaskedOp {
817 byte[] apply(byte[] a, int ix, boolean[] mask, int[] b, int iy);
818 }
819
820 interface FScatterMaskedOp {
821 byte[] apply(byte[] r, byte[] a, int ix, boolean[] mask, int[] b, int iy);
822 }
823
824 static void assertArraysEquals(byte[] r, byte[] a, int[] b, boolean[] mask, FGatherMaskedOp f) {
825 int i = 0;
826 try {
827 for (; i < a.length; i += SPECIES.length()) {
828 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()),
829 f.apply(a, i, mask, b, i));
830 }
831 } catch (AssertionError e) {
832 byte[] ref = f.apply(a, i, mask, b, i);
833 byte[] res = Arrays.copyOfRange(r, i, i+SPECIES.length());
834 Assert.assertEquals(res, ref,
835 "(ref: " + Arrays.toString(ref) + ", res: " + Arrays.toString(res) + ", a: "
836 + Arrays.toString(Arrays.copyOfRange(a, i, i+SPECIES.length()))
837 + ", b: "
838 + Arrays.toString(Arrays.copyOfRange(b, i, i+SPECIES.length()))
839 + ", mask: "
840 + Arrays.toString(mask)
841 + " at index #" + i);
842 }
843 }
844
845 static void assertArraysEquals(byte[] r, byte[] a, int[] b, boolean[] mask, FScatterMaskedOp f) {
846 int i = 0;
847 try {
848 for (; i < a.length; i += SPECIES.length()) {
849 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()),
850 f.apply(r, a, i, mask, b, i));
851 }
852 } catch (AssertionError e) {
853 byte[] ref = f.apply(r, a, i, mask, b, i);
854 byte[] res = Arrays.copyOfRange(r, i, i+SPECIES.length());
855 Assert.assertEquals(res, ref,
856 "(ref: " + Arrays.toString(ref) + ", res: " + Arrays.toString(res) + ", a: "
857 + Arrays.toString(Arrays.copyOfRange(a, i, i+SPECIES.length()))
858 + ", b: "
859 + Arrays.toString(Arrays.copyOfRange(b, i, i+SPECIES.length()))
860 + ", r: "
861 + Arrays.toString(Arrays.copyOfRange(r, i, i+SPECIES.length()))
862 + ", mask: "
863 + Arrays.toString(mask)
864 + " at index #" + i);
865 }
866 }
867
868 interface FLaneOp {
869 byte[] apply(byte[] a, int origin, int idx);
870 }
871
872 static void assertArraysEquals(byte[] r, byte[] a, int origin, FLaneOp f) {
873 int i = 0;
874 try {
875 for (; i < a.length; i += SPECIES.length()) {
876 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()),
877 f.apply(a, origin, i));
878 }
879 } catch (AssertionError e) {
880 byte[] ref = f.apply(a, origin, i);
881 byte[] res = Arrays.copyOfRange(r, i, i+SPECIES.length());
882 Assert.assertEquals(res, ref, "(ref: " + Arrays.toString(ref)
883 + ", res: " + Arrays.toString(res)
884 + "), at index #" + i);
885 }
886 }
887
888 interface FLaneBop {
889 byte[] apply(byte[] a, byte[] b, int origin, int idx);
890 }
891
892 static void assertArraysEquals(byte[] r, byte[] a, byte[] b, int origin, FLaneBop f) {
893 int i = 0;
894 try {
895 for (; i < a.length; i += SPECIES.length()) {
896 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()),
897 f.apply(a, b, origin, i));
898 }
899 } catch (AssertionError e) {
900 byte[] ref = f.apply(a, b, origin, i);
901 byte[] res = Arrays.copyOfRange(r, i, i+SPECIES.length());
902 Assert.assertEquals(res, ref, "(ref: " + Arrays.toString(ref)
903 + ", res: " + Arrays.toString(res)
904 + "), at index #" + i
905 + ", at origin #" + origin);
906 }
907 }
908
909 interface FLaneMaskedBop {
910 byte[] apply(byte[] a, byte[] b, int origin, boolean[] mask, int idx);
911 }
912
913 static void assertArraysEquals(byte[] r, byte[] a, byte[] b, int origin, boolean[] mask, FLaneMaskedBop f) {
914 int i = 0;
915 try {
916 for (; i < a.length; i += SPECIES.length()) {
917 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()),
918 f.apply(a, b, origin, mask, i));
919 }
920 } catch (AssertionError e) {
921 byte[] ref = f.apply(a, b, origin, mask, i);
922 byte[] res = Arrays.copyOfRange(r, i, i+SPECIES.length());
923 Assert.assertEquals(res, ref, "(ref: " + Arrays.toString(ref)
924 + ", res: " + Arrays.toString(res)
925 + "), at index #" + i
926 + ", at origin #" + origin);
927 }
928 }
929
930 interface FLanePartBop {
931 byte[] apply(byte[] a, byte[] b, int origin, int part, int idx);
932 }
933
934 static void assertArraysEquals(byte[] r, byte[] a, byte[] b, int origin, int part, FLanePartBop f) {
935 int i = 0;
936 try {
937 for (; i < a.length; i += SPECIES.length()) {
938 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()),
939 f.apply(a, b, origin, part, i));
940 }
941 } catch (AssertionError e) {
942 byte[] ref = f.apply(a, b, origin, part, i);
943 byte[] res = Arrays.copyOfRange(r, i, i+SPECIES.length());
944 Assert.assertEquals(res, ref, "(ref: " + Arrays.toString(ref)
945 + ", res: " + Arrays.toString(res)
946 + "), at index #" + i
947 + ", at origin #" + origin
948 + ", with part #" + part);
949 }
950 }
951
952 interface FLanePartMaskedBop {
953 byte[] apply(byte[] a, byte[] b, int origin, int part, boolean[] mask, int idx);
954 }
955
956 static void assertArraysEquals(byte[] r, byte[] a, byte[] b, int origin, int part, boolean[] mask, FLanePartMaskedBop f) {
957 int i = 0;
958 try {
959 for (; i < a.length; i += SPECIES.length()) {
960 Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()),
961 f.apply(a, b, origin, part, mask, i));
962 }
963 } catch (AssertionError e) {
964 byte[] ref = f.apply(a, b, origin, part, mask, i);
965 byte[] res = Arrays.copyOfRange(r, i, i+SPECIES.length());
966 Assert.assertEquals(res, ref, "(ref: " + Arrays.toString(ref)
967 + ", res: " + Arrays.toString(res)
968 + "), at index #" + i
969 + ", at origin #" + origin
970 + ", with part #" + part);
971 }
972 }
973
974
975 static void assertArraysEquals(int[] r, byte[] a, int offs) {
976 int i = 0;
977 try {
978 for (; i < r.length; i++) {
979 Assert.assertEquals(r[i], (int)(a[i+offs]));
980 }
981 } catch (AssertionError e) {
982 Assert.assertEquals(r[i], (int)(a[i+offs]), "at index #" + i + ", input = " + a[i+offs]);
983 }
984 }
985
986
987 static void assertArraysEquals(byte[] r, byte[] a, int offs) {
988 int i = 0;
989 try {
990 for (; i < r.length; i++) {
991 Assert.assertEquals(r[i], (long)(a[i+offs]));
992 }
993 } catch (AssertionError e) {
994 Assert.assertEquals(r[i], (long)(a[i+offs]), "at index #" + i + ", input = " + a[i+offs]);
995 }
996 }
997
998 static void assertArraysEquals(long[] r, byte[] a, int offs) {
999 int i = 0;
1000 try {
1001 for (; i < r.length; i++) {
1002 Assert.assertEquals(r[i], (long)(a[i+offs]));
1003 }
1004 } catch (AssertionError e) {
1005 Assert.assertEquals(r[i], (long)(a[i+offs]), "at index #" + i + ", input = " + a[i+offs]);
1006 }
1007 }
1008
1009 static void assertArraysEquals(double[] r, byte[] a, int offs) {
1010 int i = 0;
1011 try {
1012 for (; i < r.length; i++) {
1013 Assert.assertEquals(r[i], (double)(a[i+offs]));
1014 }
1015 } catch (AssertionError e) {
1016 Assert.assertEquals(r[i], (double)(a[i+offs]), "at index #" + i + ", input = " + a[i+offs]);
1017 }
1018 }
1019
1020 static byte bits(byte e) {
1021 return e;
1022 }
1023
1024 static final List<IntFunction<byte[]>> BYTE_GENERATORS = List.of(
1025 withToString("byte[-i * 5]", (int s) -> {
1026 return fill(s * BUFFER_REPS,
1027 i -> (byte)(-i * 5));
1028 }),
1029 withToString("byte[i * 5]", (int s) -> {
1030 return fill(s * BUFFER_REPS,
1031 i -> (byte)(i * 5));
1032 }),
1033 withToString("byte[i + 1]", (int s) -> {
1034 return fill(s * BUFFER_REPS,
1035 i -> (((byte)(i + 1) == 0) ? 1 : (byte)(i + 1)));
1036 }),
1037 withToString("byte[cornerCaseValue(i)]", (int s) -> {
1038 return fill(s * BUFFER_REPS,
1039 i -> cornerCaseValue(i));
1040 })
1041 );
1042
1043 static final List<IntFunction<byte[]>> BYTE_SATURATING_GENERATORS = List.of(
1044 withToString("byte[Byte.MIN_VALUE]", (int s) -> {
1045 return fill(s * BUFFER_REPS,
1046 i -> (byte)(Byte.MIN_VALUE));
1047 }),
1048 withToString("byte[Byte.MAX_VALUE]", (int s) -> {
1049 return fill(s * BUFFER_REPS,
1050 i -> (byte)(Byte.MAX_VALUE));
1051 }),
1052 withToString("byte[Byte.MAX_VALUE - 100]", (int s) -> {
1053 return fill(s * BUFFER_REPS,
1054 i -> (byte)(Byte.MAX_VALUE - 100));
1055 }),
1056 withToString("byte[Byte.MIN_VALUE + 100]", (int s) -> {
1057 return fill(s * BUFFER_REPS,
1058 i -> (byte)(Byte.MIN_VALUE + 100));
1059 }),
1060 withToString("byte[-i * 5]", (int s) -> {
1061 return fill(s * BUFFER_REPS,
1062 i -> (byte)(-i * 5));
1063 }),
1064 withToString("byte[i * 5]", (int s) -> {
1065 return fill(s * BUFFER_REPS,
1066 i -> (byte)(i * 5));
1067 })
1068 );
1069
1070 static final List<IntFunction<byte[]>> BYTE_SATURATING_GENERATORS_ASSOC = List.of(
1071 withToString("byte[Byte.MAX_VALUE]", (int s) -> {
1072 return fill(s * BUFFER_REPS,
1073 i -> (byte)(Byte.MAX_VALUE));
1074 }),
1075 withToString("byte[Byte.MAX_VALUE - 100]", (int s) -> {
1076 return fill(s * BUFFER_REPS,
1077 i -> (byte)(Byte.MAX_VALUE - 100));
1078 }),
1079 withToString("byte[-1]", (int s) -> {
1080 return fill(s * BUFFER_REPS,
1081 i -> (byte)(-1));
1082 })
1083 );
1084
1085 // Create combinations of pairs
1086 // @@@ Might be sensitive to order e.g. div by 0
1087 static final List<List<IntFunction<byte[]>>> BYTE_GENERATOR_PAIRS =
1088 Stream.of(BYTE_GENERATORS.get(0)).
1089 flatMap(fa -> BYTE_GENERATORS.stream().skip(1).map(fb -> List.of(fa, fb))).
1090 collect(Collectors.toList());
1091
1092 static final List<List<IntFunction<byte[]>>> BYTE_SATURATING_GENERATOR_PAIRS =
1093 Stream.of(BYTE_GENERATORS.get(0)).
1094 flatMap(fa -> BYTE_SATURATING_GENERATORS.stream().skip(1).map(fb -> List.of(fa, fb))).
1095 collect(Collectors.toList());
1096
1097 static final List<List<IntFunction<byte[]>>> BYTE_SATURATING_GENERATOR_TRIPLETS =
1098 Stream.of(BYTE_GENERATORS.get(1))
1099 .flatMap(fa -> BYTE_SATURATING_GENERATORS_ASSOC.stream().map(fb -> List.of(fa, fb)))
1100 .flatMap(pair -> BYTE_SATURATING_GENERATORS_ASSOC.stream().map(f -> List.of(pair.get(0), pair.get(1), f)))
1101 .collect(Collectors.toList());
1102
1103 @DataProvider
1104 public Object[][] boolUnaryOpProvider() {
1105 return BOOL_ARRAY_GENERATORS.stream().
1106 map(f -> new Object[]{f}).
1107 toArray(Object[][]::new);
1108 }
1109
1110 static final List<List<IntFunction<byte[]>>> BYTE_GENERATOR_TRIPLES =
1111 BYTE_GENERATOR_PAIRS.stream().
1112 flatMap(pair -> BYTE_GENERATORS.stream().map(f -> List.of(pair.get(0), pair.get(1), f))).
1113 collect(Collectors.toList());
1114
1115 static final List<IntFunction<byte[]>> SELECT_FROM_INDEX_GENERATORS = List.of(
1116 withToString("byte[0..VECLEN*2)", (int s) -> {
1117 return fill(s * BUFFER_REPS,
1118 i -> (byte)(RAND.nextInt()));
1119 })
1120 );
1121
1122 static final List<List<IntFunction<byte[]>>> BYTE_GENERATOR_SELECT_FROM_TRIPLES =
1123 BYTE_GENERATOR_PAIRS.stream().
1124 flatMap(pair -> SELECT_FROM_INDEX_GENERATORS.stream().map(f -> List.of(pair.get(0), pair.get(1), f))).
1125 collect(Collectors.toList());
1126
1127 @DataProvider
1128 public Object[][] byteBinaryOpProvider() {
1129 return BYTE_GENERATOR_PAIRS.stream().map(List::toArray).
1130 toArray(Object[][]::new);
1131 }
1132
1133 @DataProvider
1134 public Object[][] byteSaturatingBinaryOpProvider() {
1135 return BYTE_SATURATING_GENERATOR_PAIRS.stream().map(List::toArray).
1136 toArray(Object[][]::new);
1137 }
1138
1139 @DataProvider
1140 public Object[][] byteSaturatingBinaryOpAssocProvider() {
1141 return BYTE_SATURATING_GENERATOR_TRIPLETS.stream().map(List::toArray).
1142 toArray(Object[][]::new);
1143 }
1144
1145 @DataProvider
1146 public Object[][] byteSaturatingBinaryOpAssocMaskProvider() {
1147 return BOOLEAN_MASK_GENERATORS.stream().
1148 flatMap(fm -> BYTE_SATURATING_GENERATOR_TRIPLETS.stream().map(lfa -> {
1149 return Stream.concat(lfa.stream(), Stream.of(fm)).toArray();
1150 })).
1151 toArray(Object[][]::new);
1152 }
1153
1154
1155 @DataProvider
1156 public Object[][] byteIndexedOpProvider() {
1157 return BYTE_GENERATOR_PAIRS.stream().map(List::toArray).
1158 toArray(Object[][]::new);
1159 }
1160
1161 @DataProvider
1162 public Object[][] byteSaturatingBinaryOpMaskProvider() {
1163 return BOOLEAN_MASK_GENERATORS.stream().
1164 flatMap(fm -> BYTE_SATURATING_GENERATOR_PAIRS.stream().map(lfa -> {
1165 return Stream.concat(lfa.stream(), Stream.of(fm)).toArray();
1166 })).
1167 toArray(Object[][]::new);
1168 }
1169
1170 @DataProvider
1171 public Object[][] byteSaturatingUnaryOpProvider() {
1172 return BYTE_SATURATING_GENERATORS.stream().
1173 map(f -> new Object[]{f}).
1174 toArray(Object[][]::new);
1175 }
1176
1177 @DataProvider
1178 public Object[][] byteSaturatingUnaryOpMaskProvider() {
1179 return BOOLEAN_MASK_GENERATORS.stream().
1180 flatMap(fm -> BYTE_SATURATING_GENERATORS.stream().map(fa -> {
1181 return new Object[] {fa, fm};
1182 })).
1183 toArray(Object[][]::new);
1184 }
1185
1186 @DataProvider
1187 public Object[][] byteBinaryOpMaskProvider() {
1188 return BOOLEAN_MASK_GENERATORS.stream().
1189 flatMap(fm -> BYTE_GENERATOR_PAIRS.stream().map(lfa -> {
1190 return Stream.concat(lfa.stream(), Stream.of(fm)).toArray();
1191 })).
1192 toArray(Object[][]::new);
1193 }
1194
1195 @DataProvider
1196 public Object[][] byteTernaryOpProvider() {
1197 return BYTE_GENERATOR_TRIPLES.stream().map(List::toArray).
1198 toArray(Object[][]::new);
1199 }
1200
1201 @DataProvider
1202 public Object[][] byteSelectFromTwoVectorOpProvider() {
1203 return BYTE_GENERATOR_SELECT_FROM_TRIPLES.stream().map(List::toArray).
1204 toArray(Object[][]::new);
1205 }
1206
1207 @DataProvider
1208 public Object[][] byteTernaryOpMaskProvider() {
1209 return BOOLEAN_MASK_GENERATORS.stream().
1210 flatMap(fm -> BYTE_GENERATOR_TRIPLES.stream().map(lfa -> {
1211 return Stream.concat(lfa.stream(), Stream.of(fm)).toArray();
1212 })).
1213 toArray(Object[][]::new);
1214 }
1215
1216 @DataProvider
1217 public Object[][] byteUnaryOpProvider() {
1218 return BYTE_GENERATORS.stream().
1219 map(f -> new Object[]{f}).
1220 toArray(Object[][]::new);
1221 }
1222
1223 @DataProvider
1224 public Object[][] byteUnaryOpMaskProvider() {
1225 return BOOLEAN_MASK_GENERATORS.stream().
1226 flatMap(fm -> BYTE_GENERATORS.stream().map(fa -> {
1227 return new Object[] {fa, fm};
1228 })).
1229 toArray(Object[][]::new);
1230 }
1231
1232 @DataProvider
1233 public Object[][] maskProvider() {
1234 return BOOLEAN_MASK_GENERATORS.stream().
1235 map(f -> new Object[]{f}).
1236 toArray(Object[][]::new);
1237 }
1238
1239 @DataProvider
1240 public Object[][] maskCompareOpProvider() {
1241 return BOOLEAN_MASK_COMPARE_GENERATOR_PAIRS.stream().map(List::toArray).
1242 toArray(Object[][]::new);
1243 }
1244
1245 @DataProvider
1246 public Object[][] shuffleProvider() {
1247 return INT_SHUFFLE_GENERATORS.stream().
1248 map(f -> new Object[]{f}).
1249 toArray(Object[][]::new);
1250 }
1251
1252 @DataProvider
1253 public Object[][] shuffleCompareOpProvider() {
1254 return INT_SHUFFLE_COMPARE_GENERATOR_PAIRS.stream().map(List::toArray).
1255 toArray(Object[][]::new);
1256 }
1257
1258 @DataProvider
1259 public Object[][] byteUnaryOpShuffleProvider() {
1260 return INT_SHUFFLE_GENERATORS.stream().
1261 flatMap(fs -> BYTE_GENERATORS.stream().map(fa -> {
1262 return new Object[] {fa, fs};
1263 })).
1264 toArray(Object[][]::new);
1265 }
1266
1267 @DataProvider
1268 public Object[][] byteUnaryOpShuffleMaskProvider() {
1269 return BOOLEAN_MASK_GENERATORS.stream().
1270 flatMap(fm -> INT_SHUFFLE_GENERATORS.stream().
1271 flatMap(fs -> BYTE_GENERATORS.stream().map(fa -> {
1272 return new Object[] {fa, fs, fm};
1273 }))).
1274 toArray(Object[][]::new);
1275 }
1276
1277 static final List<BiFunction<Integer,Integer,byte[]>> BYTE_SHUFFLE_GENERATORS = List.of(
1278 withToStringBi("shuffle[random]", (Integer l, Integer m) -> {
1279 byte[] a = new byte[l];
1280 int upper = Math.min(Byte.MAX_VALUE + 1, m);
1281 for (int i = 0; i < 1; i++) {
1282 a[i] = (byte)RAND.nextInt(upper);
1283 }
1284 return a;
1285 })
1286 );
1287
1288 @DataProvider
1289 public Object[][] byteUnaryOpSelectFromProvider() {
1290 return BYTE_SHUFFLE_GENERATORS.stream().
1291 flatMap(fs -> BYTE_GENERATORS.stream().map(fa -> {
1292 return new Object[] {fa, fs};
1293 })).
1294 toArray(Object[][]::new);
1295 }
1296
1297 @DataProvider
1298 public Object[][] byteUnaryOpSelectFromMaskProvider() {
1299 return BOOLEAN_MASK_GENERATORS.stream().
1300 flatMap(fm -> BYTE_SHUFFLE_GENERATORS.stream().
1301 flatMap(fs -> BYTE_GENERATORS.stream().map(fa -> {
1302 return new Object[] {fa, fs, fm};
1303 }))).
1304 toArray(Object[][]::new);
1305 }
1306
1307 static final List<IntFunction<byte[]>> BYTE_COMPARE_GENERATORS = List.of(
1308 withToString("byte[i]", (int s) -> {
1309 return fill(s * BUFFER_REPS,
1310 i -> (byte)i);
1311 }),
1312 withToString("byte[i - length / 2]", (int s) -> {
1313 return fill(s * BUFFER_REPS,
1314 i -> (byte)(i - (s * BUFFER_REPS / 2)));
1315 }),
1316 withToString("byte[i + 1]", (int s) -> {
1317 return fill(s * BUFFER_REPS,
1318 i -> (byte)(i + 1));
1319 }),
1320 withToString("byte[i - 2]", (int s) -> {
1321 return fill(s * BUFFER_REPS,
1322 i -> (byte)(i - 2));
1323 }),
1324 withToString("byte[zigZag(i)]", (int s) -> {
1325 return fill(s * BUFFER_REPS,
1326 i -> i%3 == 0 ? (byte)i : (i%3 == 1 ? (byte)(i + 1) : (byte)(i - 2)));
1327 }),
1328 withToString("byte[cornerCaseValue(i)]", (int s) -> {
1329 return fill(s * BUFFER_REPS,
1330 i -> cornerCaseValue(i));
1331 })
1332 );
1333
1334 static final List<List<IntFunction<byte[]>>> BYTE_TEST_GENERATOR_ARGS =
1335 BYTE_COMPARE_GENERATORS.stream().
1336 map(fa -> List.of(fa)).
1337 collect(Collectors.toList());
1338
1339 @DataProvider
1340 public Object[][] byteTestOpProvider() {
1341 return BYTE_TEST_GENERATOR_ARGS.stream().map(List::toArray).
1342 toArray(Object[][]::new);
1343 }
1344
1345 @DataProvider
1346 public Object[][] byteTestOpMaskProvider() {
1347 return BOOLEAN_MASK_GENERATORS.stream().
1348 flatMap(fm -> BYTE_TEST_GENERATOR_ARGS.stream().map(lfa -> {
1349 return Stream.concat(lfa.stream(), Stream.of(fm)).toArray();
1350 })).
1351 toArray(Object[][]::new);
1352 }
1353
1354 static final List<List<IntFunction<byte[]>>> BYTE_COMPARE_GENERATOR_PAIRS =
1355 BYTE_COMPARE_GENERATORS.stream().
1356 flatMap(fa -> BYTE_COMPARE_GENERATORS.stream().map(fb -> List.of(fa, fb))).
1357 collect(Collectors.toList());
1358
1359 @DataProvider
1360 public Object[][] byteCompareOpProvider() {
1361 return BYTE_COMPARE_GENERATOR_PAIRS.stream().map(List::toArray).
1362 toArray(Object[][]::new);
1363 }
1364
1365 @DataProvider
1366 public Object[][] byteCompareOpMaskProvider() {
1367 return BOOLEAN_MASK_GENERATORS.stream().
1368 flatMap(fm -> BYTE_COMPARE_GENERATOR_PAIRS.stream().map(lfa -> {
1369 return Stream.concat(lfa.stream(), Stream.of(fm)).toArray();
1370 })).
1371 toArray(Object[][]::new);
1372 }
1373
1374 interface ToByteF {
1375 byte apply(int i);
1376 }
1377
1378 static byte[] fill(int s , ToByteF f) {
1379 return fill(new byte[s], f);
1380 }
1381
1382 static byte[] fill(byte[] a, ToByteF f) {
1383 for (int i = 0; i < a.length; i++) {
1384 a[i] = f.apply(i);
1385 }
1386 return a;
1387 }
1388
1389 static byte cornerCaseValue(int i) {
1390 switch(i % 5) {
1391 case 0:
1392 return Byte.MAX_VALUE;
1393 case 1:
1394 return Byte.MIN_VALUE;
1395 case 2:
1396 return Byte.MIN_VALUE;
1397 case 3:
1398 return Byte.MAX_VALUE;
1399 default:
1400 return (byte)0;
1401 }
1402 }
1403
1404 static final IntFunction<byte[]> fr = (vl) -> {
1405 int length = BUFFER_REPS * vl;
1406 return new byte[length];
1407 };
1408
1409 static final IntFunction<boolean[]> fmr = (vl) -> {
1410 int length = BUFFER_REPS * vl;
1411 return new boolean[length];
1412 };
1413
1414 static final IntFunction<long[]> lfr = (vl) -> {
1415 int length = BUFFER_REPS * vl;
1416 return new long[length];
1417 };
1418
1419 static void replaceZero(byte[] a, byte v) {
1420 for (int i = 0; i < a.length; i++) {
1421 if (a[i] == 0) {
1422 a[i] = v;
1423 }
1424 }
1425 }
1426
1427 static void replaceZero(byte[] a, boolean[] mask, byte v) {
1428 for (int i = 0; i < a.length; i++) {
1429 if (mask[i % mask.length] && a[i] == 0) {
1430 a[i] = v;
1431 }
1432 }
1433 }
1434
1435 static byte ROL_scalar(byte a, byte b) {
1436 return (byte)(((((byte)a) & 0xFF) << (b & 7)) | ((((byte)a) & 0xFF) >>> (8 - (b & 7))));
1437 }
1438
1439 static byte ROR_scalar(byte a, byte b) {
1440 return (byte)(((((byte)a) & 0xFF) >>> (b & 7)) | ((((byte)a) & 0xFF) << (8 - (b & 7))));
1441 }
1442
1443 static byte TRAILING_ZEROS_COUNT_scalar(byte a) {
1444 return (byte) (a != 0 ? Integer.numberOfTrailingZeros(a) : 8);
1445 }
1446
1447 static byte LEADING_ZEROS_COUNT_scalar(byte a) {
1448 return (byte) (a >= 0 ? Integer.numberOfLeadingZeros(a) - 24 : 0);
1449 }
1450
1451 static byte REVERSE_scalar(byte a) {
1452 byte b = (byte) ROL_scalar(a, (byte) 4);
1453 b = (byte) (((b & 0x55) << 1) | ((b & 0xAA) >>> 1));
1454 b = (byte) (((b & 0x33) << 2) | ((b & 0xCC) >>> 2));
1455 return b;
1456 }
1457
1458 static boolean eq(byte a, byte b) {
1459 return a == b;
1460 }
1461
1462 static boolean neq(byte a, byte b) {
1463 return a != b;
1464 }
1465
1466 static boolean lt(byte a, byte b) {
1467 return a < b;
1468 }
1469
1470 static boolean le(byte a, byte b) {
1471 return a <= b;
1472 }
1473
1474 static boolean gt(byte a, byte b) {
1475 return a > b;
1476 }
1477
1478 static boolean ge(byte a, byte b) {
1479 return a >= b;
1480 }
1481
1482 static boolean ult(byte a, byte b) {
1483 return Byte.compareUnsigned(a, b) < 0;
1484 }
1485
1486 static boolean ule(byte a, byte b) {
1487 return Byte.compareUnsigned(a, b) <= 0;
1488 }
1489
1490 static boolean ugt(byte a, byte b) {
1491 return Byte.compareUnsigned(a, b) > 0;
1492 }
1493
1494 static boolean uge(byte a, byte b) {
1495 return Byte.compareUnsigned(a, b) >= 0;
1496 }
1497
1498 static byte firstNonZero(byte a, byte b) {
1499 return Byte.compare(a, (byte) 0) != 0 ? a : b;
1500 }
1501
1502 @Test
1503 static void smokeTest1() {
1504 ByteVector three = ByteVector.broadcast(SPECIES, (byte)-3);
1505 ByteVector three2 = (ByteVector) SPECIES.broadcast(-3);
1506 assert(three.eq(three2).allTrue());
1507 ByteVector three3 = three2.broadcast(1).broadcast(-3);
1508 assert(three.eq(three3).allTrue());
1509 int scale = 2;
1510 Class<?> ETYPE = byte.class;
1511 if (ETYPE == double.class || ETYPE == long.class)
1512 scale = 1000000;
1513 else if (ETYPE == byte.class && SPECIES.length() >= 64)
1514 scale = 1;
1515 ByteVector higher = three.addIndex(scale);
1516 VectorMask<Byte> m = three.compare(VectorOperators.LE, higher);
1517 assert(m.allTrue());
1518 m = higher.min((byte)-1).test(VectorOperators.IS_NEGATIVE);
1519 assert(m.allTrue());
1520 byte max = higher.reduceLanes(VectorOperators.MAX);
1521 assert(max == -3 + scale * (SPECIES.length()-1));
1522 }
1523
1524 private static byte[]
1525 bothToArray(ByteVector a, ByteVector b) {
1526 byte[] r = new byte[a.length() + b.length()];
1527 a.intoArray(r, 0);
1528 b.intoArray(r, a.length());
1529 return r;
1530 }
1531
1532 @Test
1533 static void smokeTest2() {
1534 // Do some zipping and shuffling.
1535 ByteVector io = (ByteVector) SPECIES.broadcast(0).addIndex(1);
1536 ByteVector io2 = (ByteVector) VectorShuffle.iota(SPECIES,0,1,false).toVector();
1537 Assert.assertEquals(io, io2);
1538 ByteVector a = io.add((byte)1); //[1,2]
1539 ByteVector b = a.neg(); //[-1,-2]
1540 byte[] abValues = bothToArray(a,b); //[1,2,-1,-2]
1541 VectorShuffle<Byte> zip0 = VectorShuffle.makeZip(SPECIES, 0);
1542 VectorShuffle<Byte> zip1 = VectorShuffle.makeZip(SPECIES, 1);
1543 ByteVector zab0 = a.rearrange(zip0,b); //[1,-1]
1544 ByteVector zab1 = a.rearrange(zip1,b); //[2,-2]
1545 byte[] zabValues = bothToArray(zab0, zab1); //[1,-1,2,-2]
1546 // manually zip
1547 byte[] manual = new byte[zabValues.length];
1548 for (int i = 0; i < manual.length; i += 2) {
1549 manual[i+0] = abValues[i/2];
1550 manual[i+1] = abValues[a.length() + i/2];
1551 }
1552 Assert.assertEquals(Arrays.toString(zabValues), Arrays.toString(manual));
1553 VectorShuffle<Byte> unz0 = VectorShuffle.makeUnzip(SPECIES, 0);
1554 VectorShuffle<Byte> unz1 = VectorShuffle.makeUnzip(SPECIES, 1);
1555 ByteVector uab0 = zab0.rearrange(unz0,zab1);
1556 ByteVector uab1 = zab0.rearrange(unz1,zab1);
1557 byte[] abValues1 = bothToArray(uab0, uab1);
1558 Assert.assertEquals(Arrays.toString(abValues), Arrays.toString(abValues1));
1559 }
1560
1561 static void iotaShuffle() {
1562 ByteVector io = (ByteVector) SPECIES.broadcast(0).addIndex(1);
1563 ByteVector io2 = (ByteVector) VectorShuffle.iota(SPECIES, 0 , 1, false).toVector();
1564 Assert.assertEquals(io, io2);
1565 }
1566
1567 @Test
1568 // Test all shuffle related operations.
1569 static void shuffleTest() {
1570 // To test backend instructions, make sure that C2 is used.
1571 for (int loop = 0; loop < INVOC_COUNT * INVOC_COUNT; loop++) {
1572 iotaShuffle();
1573 }
1574 }
1575
1576 @Test
1577 void viewAsIntegeralLanesTest() {
1578 Vector<?> asIntegral = SPECIES.zero().viewAsIntegralLanes();
1579 Assert.assertEquals(asIntegral.species(), SPECIES);
1580 }
1581
1582 @Test(expectedExceptions = UnsupportedOperationException.class)
1583 void viewAsFloatingLanesTest() {
1584 SPECIES.zero().viewAsFloatingLanes();
1585 }
1586
1587 @Test
1588 // Test div by 0.
1589 static void bitwiseDivByZeroSmokeTest() {
1590 try {
1591 ByteVector a = (ByteVector) SPECIES.broadcast(0).addIndex(1);
1592 ByteVector b = (ByteVector) SPECIES.broadcast(0);
1593 a.div(b);
1594 Assert.fail();
1595 } catch (ArithmeticException e) {
1596 }
1597
1598 try {
1599 ByteVector a = (ByteVector) SPECIES.broadcast(0).addIndex(1);
1600 ByteVector b = (ByteVector) SPECIES.broadcast(0);
1601 VectorMask<Byte> m = a.lt((byte) 1);
1602 a.div(b, m);
1603 Assert.fail();
1604 } catch (ArithmeticException e) {
1605 }
1606 }
1607
1608 static byte ADD(byte a, byte b) {
1609 return (byte)(a + b);
1610 }
1611
1612 @Test(dataProvider = "byteBinaryOpProvider")
1613 static void ADDByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
1614 byte[] a = fa.apply(SPECIES.length());
1615 byte[] b = fb.apply(SPECIES.length());
1616 byte[] r = fr.apply(SPECIES.length());
1617
1618 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1619 for (int i = 0; i < a.length; i += SPECIES.length()) {
1620 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1621 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1622 av.lanewise(VectorOperators.ADD, bv).intoArray(r, i);
1623 }
1624 }
1625
1626 assertArraysEquals(r, a, b, ByteMaxVectorTests::ADD);
1627 }
1628
1629 static byte add(byte a, byte b) {
1630 return (byte)(a + b);
1631 }
1632
1633 @Test(dataProvider = "byteBinaryOpProvider")
1634 static void addByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
1635 byte[] a = fa.apply(SPECIES.length());
1636 byte[] b = fb.apply(SPECIES.length());
1637 byte[] r = fr.apply(SPECIES.length());
1638
1639 for (int i = 0; i < a.length; i += SPECIES.length()) {
1640 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1641 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1642 av.add(bv).intoArray(r, i);
1643 }
1644
1645 assertArraysEquals(r, a, b, ByteMaxVectorTests::add);
1646 }
1647
1648 @Test(dataProvider = "byteBinaryOpMaskProvider")
1649 static void ADDByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
1650 IntFunction<boolean[]> fm) {
1651 byte[] a = fa.apply(SPECIES.length());
1652 byte[] b = fb.apply(SPECIES.length());
1653 byte[] r = fr.apply(SPECIES.length());
1654 boolean[] mask = fm.apply(SPECIES.length());
1655 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1656
1657 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1658 for (int i = 0; i < a.length; i += SPECIES.length()) {
1659 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1660 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1661 av.lanewise(VectorOperators.ADD, bv, vmask).intoArray(r, i);
1662 }
1663 }
1664
1665 assertArraysEquals(r, a, b, mask, ByteMaxVectorTests::ADD);
1666 }
1667
1668 @Test(dataProvider = "byteBinaryOpMaskProvider")
1669 static void addByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
1670 IntFunction<boolean[]> fm) {
1671 byte[] a = fa.apply(SPECIES.length());
1672 byte[] b = fb.apply(SPECIES.length());
1673 byte[] r = fr.apply(SPECIES.length());
1674 boolean[] mask = fm.apply(SPECIES.length());
1675 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1676
1677 for (int i = 0; i < a.length; i += SPECIES.length()) {
1678 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1679 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1680 av.add(bv, vmask).intoArray(r, i);
1681 }
1682
1683 assertArraysEquals(r, a, b, mask, ByteMaxVectorTests::add);
1684 }
1685
1686 static byte SUB(byte a, byte b) {
1687 return (byte)(a - b);
1688 }
1689
1690 @Test(dataProvider = "byteBinaryOpProvider")
1691 static void SUBByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
1692 byte[] a = fa.apply(SPECIES.length());
1693 byte[] b = fb.apply(SPECIES.length());
1694 byte[] r = fr.apply(SPECIES.length());
1695
1696 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1697 for (int i = 0; i < a.length; i += SPECIES.length()) {
1698 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1699 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1700 av.lanewise(VectorOperators.SUB, bv).intoArray(r, i);
1701 }
1702 }
1703
1704 assertArraysEquals(r, a, b, ByteMaxVectorTests::SUB);
1705 }
1706
1707 static byte sub(byte a, byte b) {
1708 return (byte)(a - b);
1709 }
1710
1711 @Test(dataProvider = "byteBinaryOpProvider")
1712 static void subByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
1713 byte[] a = fa.apply(SPECIES.length());
1714 byte[] b = fb.apply(SPECIES.length());
1715 byte[] r = fr.apply(SPECIES.length());
1716
1717 for (int i = 0; i < a.length; i += SPECIES.length()) {
1718 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1719 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1720 av.sub(bv).intoArray(r, i);
1721 }
1722
1723 assertArraysEquals(r, a, b, ByteMaxVectorTests::sub);
1724 }
1725
1726 @Test(dataProvider = "byteBinaryOpMaskProvider")
1727 static void SUBByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
1728 IntFunction<boolean[]> fm) {
1729 byte[] a = fa.apply(SPECIES.length());
1730 byte[] b = fb.apply(SPECIES.length());
1731 byte[] r = fr.apply(SPECIES.length());
1732 boolean[] mask = fm.apply(SPECIES.length());
1733 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1734
1735 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1736 for (int i = 0; i < a.length; i += SPECIES.length()) {
1737 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1738 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1739 av.lanewise(VectorOperators.SUB, bv, vmask).intoArray(r, i);
1740 }
1741 }
1742
1743 assertArraysEquals(r, a, b, mask, ByteMaxVectorTests::SUB);
1744 }
1745
1746 @Test(dataProvider = "byteBinaryOpMaskProvider")
1747 static void subByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
1748 IntFunction<boolean[]> fm) {
1749 byte[] a = fa.apply(SPECIES.length());
1750 byte[] b = fb.apply(SPECIES.length());
1751 byte[] r = fr.apply(SPECIES.length());
1752 boolean[] mask = fm.apply(SPECIES.length());
1753 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1754
1755 for (int i = 0; i < a.length; i += SPECIES.length()) {
1756 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1757 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1758 av.sub(bv, vmask).intoArray(r, i);
1759 }
1760
1761 assertArraysEquals(r, a, b, mask, ByteMaxVectorTests::sub);
1762 }
1763
1764 static byte MUL(byte a, byte b) {
1765 return (byte)(a * b);
1766 }
1767
1768 @Test(dataProvider = "byteBinaryOpProvider")
1769 static void MULByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
1770 byte[] a = fa.apply(SPECIES.length());
1771 byte[] b = fb.apply(SPECIES.length());
1772 byte[] r = fr.apply(SPECIES.length());
1773
1774 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1775 for (int i = 0; i < a.length; i += SPECIES.length()) {
1776 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1777 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1778 av.lanewise(VectorOperators.MUL, bv).intoArray(r, i);
1779 }
1780 }
1781
1782 assertArraysEquals(r, a, b, ByteMaxVectorTests::MUL);
1783 }
1784
1785 static byte mul(byte a, byte b) {
1786 return (byte)(a * b);
1787 }
1788
1789 @Test(dataProvider = "byteBinaryOpProvider")
1790 static void mulByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
1791 byte[] a = fa.apply(SPECIES.length());
1792 byte[] b = fb.apply(SPECIES.length());
1793 byte[] r = fr.apply(SPECIES.length());
1794
1795 for (int i = 0; i < a.length; i += SPECIES.length()) {
1796 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1797 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1798 av.mul(bv).intoArray(r, i);
1799 }
1800
1801 assertArraysEquals(r, a, b, ByteMaxVectorTests::mul);
1802 }
1803
1804 @Test(dataProvider = "byteBinaryOpMaskProvider")
1805 static void MULByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
1806 IntFunction<boolean[]> fm) {
1807 byte[] a = fa.apply(SPECIES.length());
1808 byte[] b = fb.apply(SPECIES.length());
1809 byte[] r = fr.apply(SPECIES.length());
1810 boolean[] mask = fm.apply(SPECIES.length());
1811 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1812
1813 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1814 for (int i = 0; i < a.length; i += SPECIES.length()) {
1815 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1816 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1817 av.lanewise(VectorOperators.MUL, bv, vmask).intoArray(r, i);
1818 }
1819 }
1820
1821 assertArraysEquals(r, a, b, mask, ByteMaxVectorTests::MUL);
1822 }
1823
1824 @Test(dataProvider = "byteBinaryOpMaskProvider")
1825 static void mulByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
1826 IntFunction<boolean[]> fm) {
1827 byte[] a = fa.apply(SPECIES.length());
1828 byte[] b = fb.apply(SPECIES.length());
1829 byte[] r = fr.apply(SPECIES.length());
1830 boolean[] mask = fm.apply(SPECIES.length());
1831 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1832
1833 for (int i = 0; i < a.length; i += SPECIES.length()) {
1834 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1835 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1836 av.mul(bv, vmask).intoArray(r, i);
1837 }
1838
1839 assertArraysEquals(r, a, b, mask, ByteMaxVectorTests::mul);
1840 }
1841
1842 static byte DIV(byte a, byte b) {
1843 return (byte)(a / b);
1844 }
1845
1846 @Test(dataProvider = "byteBinaryOpProvider")
1847 static void DIVByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
1848 byte[] a = fa.apply(SPECIES.length());
1849 byte[] b = fb.apply(SPECIES.length());
1850 byte[] r = fr.apply(SPECIES.length());
1851
1852 replaceZero(b, (byte) 1);
1853
1854 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1855 for (int i = 0; i < a.length; i += SPECIES.length()) {
1856 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1857 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1858 av.lanewise(VectorOperators.DIV, bv).intoArray(r, i);
1859 }
1860 }
1861
1862 assertArraysEquals(r, a, b, ByteMaxVectorTests::DIV);
1863 }
1864
1865 static byte div(byte a, byte b) {
1866 return (byte)(a / b);
1867 }
1868
1869 @Test(dataProvider = "byteBinaryOpProvider")
1870 static void divByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
1871 byte[] a = fa.apply(SPECIES.length());
1872 byte[] b = fb.apply(SPECIES.length());
1873 byte[] r = fr.apply(SPECIES.length());
1874
1875 replaceZero(b, (byte) 1);
1876
1877 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1878 for (int i = 0; i < a.length; i += SPECIES.length()) {
1879 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1880 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1881 av.div(bv).intoArray(r, i);
1882 }
1883 }
1884
1885 assertArraysEquals(r, a, b, ByteMaxVectorTests::div);
1886 }
1887
1888 @Test(dataProvider = "byteBinaryOpMaskProvider")
1889 static void DIVByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
1890 IntFunction<boolean[]> fm) {
1891 byte[] a = fa.apply(SPECIES.length());
1892 byte[] b = fb.apply(SPECIES.length());
1893 byte[] r = fr.apply(SPECIES.length());
1894 boolean[] mask = fm.apply(SPECIES.length());
1895 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1896
1897 replaceZero(b, mask, (byte) 1);
1898
1899 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1900 for (int i = 0; i < a.length; i += SPECIES.length()) {
1901 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1902 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1903 av.lanewise(VectorOperators.DIV, bv, vmask).intoArray(r, i);
1904 }
1905 }
1906
1907 assertArraysEquals(r, a, b, mask, ByteMaxVectorTests::DIV);
1908 }
1909
1910 @Test(dataProvider = "byteBinaryOpMaskProvider")
1911 static void divByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
1912 IntFunction<boolean[]> fm) {
1913 byte[] a = fa.apply(SPECIES.length());
1914 byte[] b = fb.apply(SPECIES.length());
1915 byte[] r = fr.apply(SPECIES.length());
1916 boolean[] mask = fm.apply(SPECIES.length());
1917 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1918
1919 replaceZero(b, mask, (byte) 1);
1920
1921 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1922 for (int i = 0; i < a.length; i += SPECIES.length()) {
1923 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1924 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1925 av.div(bv, vmask).intoArray(r, i);
1926 }
1927 }
1928
1929 assertArraysEquals(r, a, b, mask, ByteMaxVectorTests::div);
1930 }
1931
1932 static byte FIRST_NONZERO(byte a, byte b) {
1933 return (byte)((a)!=0?a:b);
1934 }
1935
1936 @Test(dataProvider = "byteBinaryOpProvider")
1937 static void FIRST_NONZEROByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
1938 byte[] a = fa.apply(SPECIES.length());
1939 byte[] b = fb.apply(SPECIES.length());
1940 byte[] r = fr.apply(SPECIES.length());
1941
1942 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1943 for (int i = 0; i < a.length; i += SPECIES.length()) {
1944 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1945 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1946 av.lanewise(VectorOperators.FIRST_NONZERO, bv).intoArray(r, i);
1947 }
1948 }
1949
1950 assertArraysEquals(r, a, b, ByteMaxVectorTests::FIRST_NONZERO);
1951 }
1952
1953 @Test(dataProvider = "byteBinaryOpMaskProvider")
1954 static void FIRST_NONZEROByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
1955 IntFunction<boolean[]> fm) {
1956 byte[] a = fa.apply(SPECIES.length());
1957 byte[] b = fb.apply(SPECIES.length());
1958 byte[] r = fr.apply(SPECIES.length());
1959 boolean[] mask = fm.apply(SPECIES.length());
1960 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
1961
1962 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1963 for (int i = 0; i < a.length; i += SPECIES.length()) {
1964 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1965 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1966 av.lanewise(VectorOperators.FIRST_NONZERO, bv, vmask).intoArray(r, i);
1967 }
1968 }
1969
1970 assertArraysEquals(r, a, b, mask, ByteMaxVectorTests::FIRST_NONZERO);
1971 }
1972
1973 static byte AND(byte a, byte b) {
1974 return (byte)(a & b);
1975 }
1976
1977 @Test(dataProvider = "byteBinaryOpProvider")
1978 static void ANDByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
1979 byte[] a = fa.apply(SPECIES.length());
1980 byte[] b = fb.apply(SPECIES.length());
1981 byte[] r = fr.apply(SPECIES.length());
1982
1983 for (int ic = 0; ic < INVOC_COUNT; ic++) {
1984 for (int i = 0; i < a.length; i += SPECIES.length()) {
1985 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
1986 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
1987 av.lanewise(VectorOperators.AND, bv).intoArray(r, i);
1988 }
1989 }
1990
1991 assertArraysEquals(r, a, b, ByteMaxVectorTests::AND);
1992 }
1993
1994 static byte and(byte a, byte b) {
1995 return (byte)(a & b);
1996 }
1997
1998 @Test(dataProvider = "byteBinaryOpProvider")
1999 static void andByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
2000 byte[] a = fa.apply(SPECIES.length());
2001 byte[] b = fb.apply(SPECIES.length());
2002 byte[] r = fr.apply(SPECIES.length());
2003
2004 for (int i = 0; i < a.length; i += SPECIES.length()) {
2005 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2006 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
2007 av.and(bv).intoArray(r, i);
2008 }
2009
2010 assertArraysEquals(r, a, b, ByteMaxVectorTests::and);
2011 }
2012
2013 @Test(dataProvider = "byteBinaryOpMaskProvider")
2014 static void ANDByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
2015 IntFunction<boolean[]> fm) {
2016 byte[] a = fa.apply(SPECIES.length());
2017 byte[] b = fb.apply(SPECIES.length());
2018 byte[] r = fr.apply(SPECIES.length());
2019 boolean[] mask = fm.apply(SPECIES.length());
2020 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2021
2022 for (int ic = 0; ic < INVOC_COUNT; ic++) {
2023 for (int i = 0; i < a.length; i += SPECIES.length()) {
2024 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2025 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
2026 av.lanewise(VectorOperators.AND, bv, vmask).intoArray(r, i);
2027 }
2028 }
2029
2030 assertArraysEquals(r, a, b, mask, ByteMaxVectorTests::AND);
2031 }
2032
2033 static byte AND_NOT(byte a, byte b) {
2034 return (byte)(a & ~b);
2035 }
2036
2037 @Test(dataProvider = "byteBinaryOpProvider")
2038 static void AND_NOTByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
2039 byte[] a = fa.apply(SPECIES.length());
2040 byte[] b = fb.apply(SPECIES.length());
2041 byte[] r = fr.apply(SPECIES.length());
2042
2043 for (int ic = 0; ic < INVOC_COUNT; ic++) {
2044 for (int i = 0; i < a.length; i += SPECIES.length()) {
2045 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2046 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
2047 av.lanewise(VectorOperators.AND_NOT, bv).intoArray(r, i);
2048 }
2049 }
2050
2051 assertArraysEquals(r, a, b, ByteMaxVectorTests::AND_NOT);
2052 }
2053
2054 @Test(dataProvider = "byteBinaryOpMaskProvider")
2055 static void AND_NOTByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
2056 IntFunction<boolean[]> fm) {
2057 byte[] a = fa.apply(SPECIES.length());
2058 byte[] b = fb.apply(SPECIES.length());
2059 byte[] r = fr.apply(SPECIES.length());
2060 boolean[] mask = fm.apply(SPECIES.length());
2061 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2062
2063 for (int ic = 0; ic < INVOC_COUNT; ic++) {
2064 for (int i = 0; i < a.length; i += SPECIES.length()) {
2065 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2066 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
2067 av.lanewise(VectorOperators.AND_NOT, bv, vmask).intoArray(r, i);
2068 }
2069 }
2070
2071 assertArraysEquals(r, a, b, mask, ByteMaxVectorTests::AND_NOT);
2072 }
2073
2074 static byte OR(byte a, byte b) {
2075 return (byte)(a | b);
2076 }
2077
2078 @Test(dataProvider = "byteBinaryOpProvider")
2079 static void ORByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
2080 byte[] a = fa.apply(SPECIES.length());
2081 byte[] b = fb.apply(SPECIES.length());
2082 byte[] r = fr.apply(SPECIES.length());
2083
2084 for (int ic = 0; ic < INVOC_COUNT; ic++) {
2085 for (int i = 0; i < a.length; i += SPECIES.length()) {
2086 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2087 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
2088 av.lanewise(VectorOperators.OR, bv).intoArray(r, i);
2089 }
2090 }
2091
2092 assertArraysEquals(r, a, b, ByteMaxVectorTests::OR);
2093 }
2094
2095 static byte or(byte a, byte b) {
2096 return (byte)(a | b);
2097 }
2098
2099 @Test(dataProvider = "byteBinaryOpProvider")
2100 static void orByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
2101 byte[] a = fa.apply(SPECIES.length());
2102 byte[] b = fb.apply(SPECIES.length());
2103 byte[] r = fr.apply(SPECIES.length());
2104
2105 for (int i = 0; i < a.length; i += SPECIES.length()) {
2106 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2107 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
2108 av.or(bv).intoArray(r, i);
2109 }
2110
2111 assertArraysEquals(r, a, b, ByteMaxVectorTests::or);
2112 }
2113
2114 @Test(dataProvider = "byteBinaryOpMaskProvider")
2115 static void ORByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
2116 IntFunction<boolean[]> fm) {
2117 byte[] a = fa.apply(SPECIES.length());
2118 byte[] b = fb.apply(SPECIES.length());
2119 byte[] r = fr.apply(SPECIES.length());
2120 boolean[] mask = fm.apply(SPECIES.length());
2121 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2122
2123 for (int ic = 0; ic < INVOC_COUNT; ic++) {
2124 for (int i = 0; i < a.length; i += SPECIES.length()) {
2125 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2126 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
2127 av.lanewise(VectorOperators.OR, bv, vmask).intoArray(r, i);
2128 }
2129 }
2130
2131 assertArraysEquals(r, a, b, mask, ByteMaxVectorTests::OR);
2132 }
2133
2134 static byte XOR(byte a, byte b) {
2135 return (byte)(a ^ b);
2136 }
2137
2138 @Test(dataProvider = "byteBinaryOpProvider")
2139 static void XORByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
2140 byte[] a = fa.apply(SPECIES.length());
2141 byte[] b = fb.apply(SPECIES.length());
2142 byte[] r = fr.apply(SPECIES.length());
2143
2144 for (int ic = 0; ic < INVOC_COUNT; ic++) {
2145 for (int i = 0; i < a.length; i += SPECIES.length()) {
2146 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2147 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
2148 av.lanewise(VectorOperators.XOR, bv).intoArray(r, i);
2149 }
2150 }
2151
2152 assertArraysEquals(r, a, b, ByteMaxVectorTests::XOR);
2153 }
2154
2155 @Test(dataProvider = "byteBinaryOpMaskProvider")
2156 static void XORByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
2157 IntFunction<boolean[]> fm) {
2158 byte[] a = fa.apply(SPECIES.length());
2159 byte[] b = fb.apply(SPECIES.length());
2160 byte[] r = fr.apply(SPECIES.length());
2161 boolean[] mask = fm.apply(SPECIES.length());
2162 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2163
2164 for (int ic = 0; ic < INVOC_COUNT; ic++) {
2165 for (int i = 0; i < a.length; i += SPECIES.length()) {
2166 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2167 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
2168 av.lanewise(VectorOperators.XOR, bv, vmask).intoArray(r, i);
2169 }
2170 }
2171
2172 assertArraysEquals(r, a, b, mask, ByteMaxVectorTests::XOR);
2173 }
2174
2175 @Test(dataProvider = "byteBinaryOpProvider")
2176 static void addByteMaxVectorTestsBroadcastSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
2177 byte[] a = fa.apply(SPECIES.length());
2178 byte[] b = fb.apply(SPECIES.length());
2179 byte[] r = fr.apply(SPECIES.length());
2180
2181 for (int i = 0; i < a.length; i += SPECIES.length()) {
2182 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2183 av.add(b[i]).intoArray(r, i);
2184 }
2185
2186 assertBroadcastArraysEquals(r, a, b, ByteMaxVectorTests::add);
2187 }
2188
2189 @Test(dataProvider = "byteBinaryOpMaskProvider")
2190 static void addByteMaxVectorTestsBroadcastMaskedSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
2191 IntFunction<boolean[]> fm) {
2192 byte[] a = fa.apply(SPECIES.length());
2193 byte[] b = fb.apply(SPECIES.length());
2194 byte[] r = fr.apply(SPECIES.length());
2195 boolean[] mask = fm.apply(SPECIES.length());
2196 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2197
2198 for (int i = 0; i < a.length; i += SPECIES.length()) {
2199 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2200 av.add(b[i], vmask).intoArray(r, i);
2201 }
2202
2203 assertBroadcastArraysEquals(r, a, b, mask, ByteMaxVectorTests::add);
2204 }
2205
2206 @Test(dataProvider = "byteBinaryOpProvider")
2207 static void subByteMaxVectorTestsBroadcastSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
2208 byte[] a = fa.apply(SPECIES.length());
2209 byte[] b = fb.apply(SPECIES.length());
2210 byte[] r = fr.apply(SPECIES.length());
2211
2212 for (int i = 0; i < a.length; i += SPECIES.length()) {
2213 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2214 av.sub(b[i]).intoArray(r, i);
2215 }
2216
2217 assertBroadcastArraysEquals(r, a, b, ByteMaxVectorTests::sub);
2218 }
2219
2220 @Test(dataProvider = "byteBinaryOpMaskProvider")
2221 static void subByteMaxVectorTestsBroadcastMaskedSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
2222 IntFunction<boolean[]> fm) {
2223 byte[] a = fa.apply(SPECIES.length());
2224 byte[] b = fb.apply(SPECIES.length());
2225 byte[] r = fr.apply(SPECIES.length());
2226 boolean[] mask = fm.apply(SPECIES.length());
2227 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2228
2229 for (int i = 0; i < a.length; i += SPECIES.length()) {
2230 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2231 av.sub(b[i], vmask).intoArray(r, i);
2232 }
2233
2234 assertBroadcastArraysEquals(r, a, b, mask, ByteMaxVectorTests::sub);
2235 }
2236
2237 @Test(dataProvider = "byteBinaryOpProvider")
2238 static void mulByteMaxVectorTestsBroadcastSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
2239 byte[] a = fa.apply(SPECIES.length());
2240 byte[] b = fb.apply(SPECIES.length());
2241 byte[] r = fr.apply(SPECIES.length());
2242
2243 for (int i = 0; i < a.length; i += SPECIES.length()) {
2244 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2245 av.mul(b[i]).intoArray(r, i);
2246 }
2247
2248 assertBroadcastArraysEquals(r, a, b, ByteMaxVectorTests::mul);
2249 }
2250
2251 @Test(dataProvider = "byteBinaryOpMaskProvider")
2252 static void mulByteMaxVectorTestsBroadcastMaskedSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
2253 IntFunction<boolean[]> fm) {
2254 byte[] a = fa.apply(SPECIES.length());
2255 byte[] b = fb.apply(SPECIES.length());
2256 byte[] r = fr.apply(SPECIES.length());
2257 boolean[] mask = fm.apply(SPECIES.length());
2258 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2259
2260 for (int i = 0; i < a.length; i += SPECIES.length()) {
2261 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2262 av.mul(b[i], vmask).intoArray(r, i);
2263 }
2264
2265 assertBroadcastArraysEquals(r, a, b, mask, ByteMaxVectorTests::mul);
2266 }
2267
2268 @Test(dataProvider = "byteBinaryOpProvider")
2269 static void divByteMaxVectorTestsBroadcastSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
2270 byte[] a = fa.apply(SPECIES.length());
2271 byte[] b = fb.apply(SPECIES.length());
2272 byte[] r = fr.apply(SPECIES.length());
2273
2274 replaceZero(b, (byte) 1);
2275
2276 for (int i = 0; i < a.length; i += SPECIES.length()) {
2277 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2278 av.div(b[i]).intoArray(r, i);
2279 }
2280
2281 assertBroadcastArraysEquals(r, a, b, ByteMaxVectorTests::div);
2282 }
2283
2284 @Test(dataProvider = "byteBinaryOpMaskProvider")
2285 static void divByteMaxVectorTestsBroadcastMaskedSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
2286 IntFunction<boolean[]> fm) {
2287 byte[] a = fa.apply(SPECIES.length());
2288 byte[] b = fb.apply(SPECIES.length());
2289 byte[] r = fr.apply(SPECIES.length());
2290 boolean[] mask = fm.apply(SPECIES.length());
2291 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2292
2293 replaceZero(b, (byte) 1);
2294
2295 for (int i = 0; i < a.length; i += SPECIES.length()) {
2296 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2297 av.div(b[i], vmask).intoArray(r, i);
2298 }
2299
2300 assertBroadcastArraysEquals(r, a, b, mask, ByteMaxVectorTests::div);
2301 }
2302
2303 @Test(dataProvider = "byteBinaryOpProvider")
2304 static void ORByteMaxVectorTestsBroadcastSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
2305 byte[] a = fa.apply(SPECIES.length());
2306 byte[] b = fb.apply(SPECIES.length());
2307 byte[] r = fr.apply(SPECIES.length());
2308
2309 for (int i = 0; i < a.length; i += SPECIES.length()) {
2310 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2311 av.lanewise(VectorOperators.OR, b[i]).intoArray(r, i);
2312 }
2313
2314 assertBroadcastArraysEquals(r, a, b, ByteMaxVectorTests::OR);
2315 }
2316
2317 @Test(dataProvider = "byteBinaryOpProvider")
2318 static void orByteMaxVectorTestsBroadcastSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
2319 byte[] a = fa.apply(SPECIES.length());
2320 byte[] b = fb.apply(SPECIES.length());
2321 byte[] r = fr.apply(SPECIES.length());
2322
2323 for (int i = 0; i < a.length; i += SPECIES.length()) {
2324 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2325 av.or(b[i]).intoArray(r, i);
2326 }
2327
2328 assertBroadcastArraysEquals(r, a, b, ByteMaxVectorTests::or);
2329 }
2330
2331 @Test(dataProvider = "byteBinaryOpMaskProvider")
2332 static void ORByteMaxVectorTestsBroadcastMaskedSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
2333 IntFunction<boolean[]> fm) {
2334 byte[] a = fa.apply(SPECIES.length());
2335 byte[] b = fb.apply(SPECIES.length());
2336 byte[] r = fr.apply(SPECIES.length());
2337 boolean[] mask = fm.apply(SPECIES.length());
2338 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2339
2340 for (int i = 0; i < a.length; i += SPECIES.length()) {
2341 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2342 av.lanewise(VectorOperators.OR, b[i], vmask).intoArray(r, i);
2343 }
2344
2345 assertBroadcastArraysEquals(r, a, b, mask, ByteMaxVectorTests::OR);
2346 }
2347
2348 @Test(dataProvider = "byteBinaryOpProvider")
2349 static void ANDByteMaxVectorTestsBroadcastSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
2350 byte[] a = fa.apply(SPECIES.length());
2351 byte[] b = fb.apply(SPECIES.length());
2352 byte[] r = fr.apply(SPECIES.length());
2353
2354 for (int i = 0; i < a.length; i += SPECIES.length()) {
2355 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2356 av.lanewise(VectorOperators.AND, b[i]).intoArray(r, i);
2357 }
2358
2359 assertBroadcastArraysEquals(r, a, b, ByteMaxVectorTests::AND);
2360 }
2361
2362 @Test(dataProvider = "byteBinaryOpProvider")
2363 static void andByteMaxVectorTestsBroadcastSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
2364 byte[] a = fa.apply(SPECIES.length());
2365 byte[] b = fb.apply(SPECIES.length());
2366 byte[] r = fr.apply(SPECIES.length());
2367
2368 for (int i = 0; i < a.length; i += SPECIES.length()) {
2369 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2370 av.and(b[i]).intoArray(r, i);
2371 }
2372
2373 assertBroadcastArraysEquals(r, a, b, ByteMaxVectorTests::and);
2374 }
2375
2376 @Test(dataProvider = "byteBinaryOpMaskProvider")
2377 static void ANDByteMaxVectorTestsBroadcastMaskedSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
2378 IntFunction<boolean[]> fm) {
2379 byte[] a = fa.apply(SPECIES.length());
2380 byte[] b = fb.apply(SPECIES.length());
2381 byte[] r = fr.apply(SPECIES.length());
2382 boolean[] mask = fm.apply(SPECIES.length());
2383 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2384
2385 for (int i = 0; i < a.length; i += SPECIES.length()) {
2386 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2387 av.lanewise(VectorOperators.AND, b[i], vmask).intoArray(r, i);
2388 }
2389
2390 assertBroadcastArraysEquals(r, a, b, mask, ByteMaxVectorTests::AND);
2391 }
2392
2393 @Test(dataProvider = "byteBinaryOpProvider")
2394 static void ORByteMaxVectorTestsBroadcastLongSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
2395 byte[] a = fa.apply(SPECIES.length());
2396 byte[] b = fb.apply(SPECIES.length());
2397 byte[] r = fr.apply(SPECIES.length());
2398
2399 for (int i = 0; i < a.length; i += SPECIES.length()) {
2400 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2401 av.lanewise(VectorOperators.OR, (long)b[i]).intoArray(r, i);
2402 }
2403
2404 assertBroadcastLongArraysEquals(r, a, b, ByteMaxVectorTests::OR);
2405 }
2406
2407 @Test(dataProvider = "byteBinaryOpMaskProvider")
2408 static void ORByteMaxVectorTestsBroadcastMaskedLongSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
2409 IntFunction<boolean[]> fm) {
2410 byte[] a = fa.apply(SPECIES.length());
2411 byte[] b = fb.apply(SPECIES.length());
2412 byte[] r = fr.apply(SPECIES.length());
2413 boolean[] mask = fm.apply(SPECIES.length());
2414 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2415
2416 for (int i = 0; i < a.length; i += SPECIES.length()) {
2417 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2418 av.lanewise(VectorOperators.OR, (long)b[i], vmask).intoArray(r, i);
2419 }
2420
2421 assertBroadcastLongArraysEquals(r, a, b, mask, ByteMaxVectorTests::OR);
2422 }
2423
2424 @Test(dataProvider = "byteBinaryOpProvider")
2425 static void ADDByteMaxVectorTestsBroadcastLongSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
2426 byte[] a = fa.apply(SPECIES.length());
2427 byte[] b = fb.apply(SPECIES.length());
2428 byte[] r = fr.apply(SPECIES.length());
2429
2430 for (int i = 0; i < a.length; i += SPECIES.length()) {
2431 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2432 av.lanewise(VectorOperators.ADD, (long)b[i]).intoArray(r, i);
2433 }
2434
2435 assertBroadcastLongArraysEquals(r, a, b, ByteMaxVectorTests::ADD);
2436 }
2437
2438 @Test(dataProvider = "byteBinaryOpMaskProvider")
2439 static void ADDByteMaxVectorTestsBroadcastMaskedLongSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
2440 IntFunction<boolean[]> fm) {
2441 byte[] a = fa.apply(SPECIES.length());
2442 byte[] b = fb.apply(SPECIES.length());
2443 byte[] r = fr.apply(SPECIES.length());
2444 boolean[] mask = fm.apply(SPECIES.length());
2445 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2446
2447 for (int i = 0; i < a.length; i += SPECIES.length()) {
2448 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2449 av.lanewise(VectorOperators.ADD, (long)b[i], vmask).intoArray(r, i);
2450 }
2451
2452 assertBroadcastLongArraysEquals(r, a, b, mask, ByteMaxVectorTests::ADD);
2453 }
2454
2455 static byte LSHL(byte a, byte b) {
2456 return (byte)((a << (b & 0x7)));
2457 }
2458
2459 @Test(dataProvider = "byteBinaryOpProvider")
2460 static void LSHLByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
2461 byte[] a = fa.apply(SPECIES.length());
2462 byte[] b = fb.apply(SPECIES.length());
2463 byte[] r = fr.apply(SPECIES.length());
2464
2465 for (int ic = 0; ic < INVOC_COUNT; ic++) {
2466 for (int i = 0; i < a.length; i += SPECIES.length()) {
2467 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2468 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
2469 av.lanewise(VectorOperators.LSHL, bv).intoArray(r, i);
2470 }
2471 }
2472
2473 assertArraysEquals(r, a, b, ByteMaxVectorTests::LSHL);
2474 }
2475
2476 @Test(dataProvider = "byteBinaryOpMaskProvider")
2477 static void LSHLByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
2478 IntFunction<boolean[]> fm) {
2479 byte[] a = fa.apply(SPECIES.length());
2480 byte[] b = fb.apply(SPECIES.length());
2481 byte[] r = fr.apply(SPECIES.length());
2482 boolean[] mask = fm.apply(SPECIES.length());
2483 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2484
2485 for (int ic = 0; ic < INVOC_COUNT; ic++) {
2486 for (int i = 0; i < a.length; i += SPECIES.length()) {
2487 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2488 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
2489 av.lanewise(VectorOperators.LSHL, bv, vmask).intoArray(r, i);
2490 }
2491 }
2492
2493 assertArraysEquals(r, a, b, mask, ByteMaxVectorTests::LSHL);
2494 }
2495
2496 static byte ASHR(byte a, byte b) {
2497 return (byte)((a >> (b & 0x7)));
2498 }
2499
2500 @Test(dataProvider = "byteBinaryOpProvider")
2501 static void ASHRByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
2502 byte[] a = fa.apply(SPECIES.length());
2503 byte[] b = fb.apply(SPECIES.length());
2504 byte[] r = fr.apply(SPECIES.length());
2505
2506 for (int ic = 0; ic < INVOC_COUNT; ic++) {
2507 for (int i = 0; i < a.length; i += SPECIES.length()) {
2508 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2509 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
2510 av.lanewise(VectorOperators.ASHR, bv).intoArray(r, i);
2511 }
2512 }
2513
2514 assertArraysEquals(r, a, b, ByteMaxVectorTests::ASHR);
2515 }
2516
2517 @Test(dataProvider = "byteBinaryOpMaskProvider")
2518 static void ASHRByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
2519 IntFunction<boolean[]> fm) {
2520 byte[] a = fa.apply(SPECIES.length());
2521 byte[] b = fb.apply(SPECIES.length());
2522 byte[] r = fr.apply(SPECIES.length());
2523 boolean[] mask = fm.apply(SPECIES.length());
2524 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2525
2526 for (int ic = 0; ic < INVOC_COUNT; ic++) {
2527 for (int i = 0; i < a.length; i += SPECIES.length()) {
2528 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2529 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
2530 av.lanewise(VectorOperators.ASHR, bv, vmask).intoArray(r, i);
2531 }
2532 }
2533
2534 assertArraysEquals(r, a, b, mask, ByteMaxVectorTests::ASHR);
2535 }
2536
2537 static byte LSHR(byte a, byte b) {
2538 return (byte)(((a & 0xFF) >>> (b & 0x7)));
2539 }
2540
2541 @Test(dataProvider = "byteBinaryOpProvider")
2542 static void LSHRByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
2543 byte[] a = fa.apply(SPECIES.length());
2544 byte[] b = fb.apply(SPECIES.length());
2545 byte[] r = fr.apply(SPECIES.length());
2546
2547 for (int ic = 0; ic < INVOC_COUNT; ic++) {
2548 for (int i = 0; i < a.length; i += SPECIES.length()) {
2549 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2550 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
2551 av.lanewise(VectorOperators.LSHR, bv).intoArray(r, i);
2552 }
2553 }
2554
2555 assertArraysEquals(r, a, b, ByteMaxVectorTests::LSHR);
2556 }
2557
2558 @Test(dataProvider = "byteBinaryOpMaskProvider")
2559 static void LSHRByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
2560 IntFunction<boolean[]> fm) {
2561 byte[] a = fa.apply(SPECIES.length());
2562 byte[] b = fb.apply(SPECIES.length());
2563 byte[] r = fr.apply(SPECIES.length());
2564 boolean[] mask = fm.apply(SPECIES.length());
2565 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2566
2567 for (int ic = 0; ic < INVOC_COUNT; ic++) {
2568 for (int i = 0; i < a.length; i += SPECIES.length()) {
2569 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2570 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
2571 av.lanewise(VectorOperators.LSHR, bv, vmask).intoArray(r, i);
2572 }
2573 }
2574
2575 assertArraysEquals(r, a, b, mask, ByteMaxVectorTests::LSHR);
2576 }
2577
2578 static byte LSHL_unary(byte a, byte b) {
2579 return (byte)((a << (b & 7)));
2580 }
2581
2582 @Test(dataProvider = "byteBinaryOpProvider")
2583 static void LSHLByteMaxVectorTestsScalarShift(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
2584 byte[] a = fa.apply(SPECIES.length());
2585 byte[] b = fb.apply(SPECIES.length());
2586 byte[] r = fr.apply(SPECIES.length());
2587
2588 for (int ic = 0; ic < INVOC_COUNT; ic++) {
2589 for (int i = 0; i < a.length; i += SPECIES.length()) {
2590 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2591 av.lanewise(VectorOperators.LSHL, (int)b[i]).intoArray(r, i);
2592 }
2593 }
2594
2595 assertShiftArraysEquals(r, a, b, ByteMaxVectorTests::LSHL_unary);
2596 }
2597
2598 @Test(dataProvider = "byteBinaryOpMaskProvider")
2599 static void LSHLByteMaxVectorTestsScalarShiftMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
2600 IntFunction<boolean[]> fm) {
2601 byte[] a = fa.apply(SPECIES.length());
2602 byte[] b = fb.apply(SPECIES.length());
2603 byte[] r = fr.apply(SPECIES.length());
2604 boolean[] mask = fm.apply(SPECIES.length());
2605 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2606
2607 for (int ic = 0; ic < INVOC_COUNT; ic++) {
2608 for (int i = 0; i < a.length; i += SPECIES.length()) {
2609 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2610 av.lanewise(VectorOperators.LSHL, (int)b[i], vmask).intoArray(r, i);
2611 }
2612 }
2613
2614 assertShiftArraysEquals(r, a, b, mask, ByteMaxVectorTests::LSHL_unary);
2615 }
2616
2617 static byte LSHR_unary(byte a, byte b) {
2618 return (byte)(((a & 0xFF) >>> (b & 7)));
2619 }
2620
2621 @Test(dataProvider = "byteBinaryOpProvider")
2622 static void LSHRByteMaxVectorTestsScalarShift(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
2623 byte[] a = fa.apply(SPECIES.length());
2624 byte[] b = fb.apply(SPECIES.length());
2625 byte[] r = fr.apply(SPECIES.length());
2626
2627 for (int ic = 0; ic < INVOC_COUNT; ic++) {
2628 for (int i = 0; i < a.length; i += SPECIES.length()) {
2629 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2630 av.lanewise(VectorOperators.LSHR, (int)b[i]).intoArray(r, i);
2631 }
2632 }
2633
2634 assertShiftArraysEquals(r, a, b, ByteMaxVectorTests::LSHR_unary);
2635 }
2636
2637 @Test(dataProvider = "byteBinaryOpMaskProvider")
2638 static void LSHRByteMaxVectorTestsScalarShiftMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
2639 IntFunction<boolean[]> fm) {
2640 byte[] a = fa.apply(SPECIES.length());
2641 byte[] b = fb.apply(SPECIES.length());
2642 byte[] r = fr.apply(SPECIES.length());
2643 boolean[] mask = fm.apply(SPECIES.length());
2644 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2645
2646 for (int ic = 0; ic < INVOC_COUNT; ic++) {
2647 for (int i = 0; i < a.length; i += SPECIES.length()) {
2648 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2649 av.lanewise(VectorOperators.LSHR, (int)b[i], vmask).intoArray(r, i);
2650 }
2651 }
2652
2653 assertShiftArraysEquals(r, a, b, mask, ByteMaxVectorTests::LSHR_unary);
2654 }
2655
2656 static byte ASHR_unary(byte a, byte b) {
2657 return (byte)((a >> (b & 7)));
2658 }
2659
2660 @Test(dataProvider = "byteBinaryOpProvider")
2661 static void ASHRByteMaxVectorTestsScalarShift(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
2662 byte[] a = fa.apply(SPECIES.length());
2663 byte[] b = fb.apply(SPECIES.length());
2664 byte[] r = fr.apply(SPECIES.length());
2665
2666 for (int ic = 0; ic < INVOC_COUNT; ic++) {
2667 for (int i = 0; i < a.length; i += SPECIES.length()) {
2668 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2669 av.lanewise(VectorOperators.ASHR, (int)b[i]).intoArray(r, i);
2670 }
2671 }
2672
2673 assertShiftArraysEquals(r, a, b, ByteMaxVectorTests::ASHR_unary);
2674 }
2675
2676 @Test(dataProvider = "byteBinaryOpMaskProvider")
2677 static void ASHRByteMaxVectorTestsScalarShiftMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
2678 IntFunction<boolean[]> fm) {
2679 byte[] a = fa.apply(SPECIES.length());
2680 byte[] b = fb.apply(SPECIES.length());
2681 byte[] r = fr.apply(SPECIES.length());
2682 boolean[] mask = fm.apply(SPECIES.length());
2683 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2684
2685 for (int ic = 0; ic < INVOC_COUNT; ic++) {
2686 for (int i = 0; i < a.length; i += SPECIES.length()) {
2687 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2688 av.lanewise(VectorOperators.ASHR, (int)b[i], vmask).intoArray(r, i);
2689 }
2690 }
2691
2692 assertShiftArraysEquals(r, a, b, mask, ByteMaxVectorTests::ASHR_unary);
2693 }
2694
2695 static byte ROR(byte a, byte b) {
2696 return (byte)(ROR_scalar(a,b));
2697 }
2698
2699 @Test(dataProvider = "byteBinaryOpProvider")
2700 static void RORByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
2701 byte[] a = fa.apply(SPECIES.length());
2702 byte[] b = fb.apply(SPECIES.length());
2703 byte[] r = fr.apply(SPECIES.length());
2704
2705 for (int ic = 0; ic < INVOC_COUNT; ic++) {
2706 for (int i = 0; i < a.length; i += SPECIES.length()) {
2707 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2708 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
2709 av.lanewise(VectorOperators.ROR, bv).intoArray(r, i);
2710 }
2711 }
2712
2713 assertArraysEquals(r, a, b, ByteMaxVectorTests::ROR);
2714 }
2715
2716 @Test(dataProvider = "byteBinaryOpMaskProvider")
2717 static void RORByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
2718 IntFunction<boolean[]> fm) {
2719 byte[] a = fa.apply(SPECIES.length());
2720 byte[] b = fb.apply(SPECIES.length());
2721 byte[] r = fr.apply(SPECIES.length());
2722 boolean[] mask = fm.apply(SPECIES.length());
2723 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2724
2725 for (int ic = 0; ic < INVOC_COUNT; ic++) {
2726 for (int i = 0; i < a.length; i += SPECIES.length()) {
2727 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2728 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
2729 av.lanewise(VectorOperators.ROR, bv, vmask).intoArray(r, i);
2730 }
2731 }
2732
2733 assertArraysEquals(r, a, b, mask, ByteMaxVectorTests::ROR);
2734 }
2735
2736 static byte ROL(byte a, byte b) {
2737 return (byte)(ROL_scalar(a,b));
2738 }
2739
2740 @Test(dataProvider = "byteBinaryOpProvider")
2741 static void ROLByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
2742 byte[] a = fa.apply(SPECIES.length());
2743 byte[] b = fb.apply(SPECIES.length());
2744 byte[] r = fr.apply(SPECIES.length());
2745
2746 for (int ic = 0; ic < INVOC_COUNT; ic++) {
2747 for (int i = 0; i < a.length; i += SPECIES.length()) {
2748 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2749 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
2750 av.lanewise(VectorOperators.ROL, bv).intoArray(r, i);
2751 }
2752 }
2753
2754 assertArraysEquals(r, a, b, ByteMaxVectorTests::ROL);
2755 }
2756
2757 @Test(dataProvider = "byteBinaryOpMaskProvider")
2758 static void ROLByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
2759 IntFunction<boolean[]> fm) {
2760 byte[] a = fa.apply(SPECIES.length());
2761 byte[] b = fb.apply(SPECIES.length());
2762 byte[] r = fr.apply(SPECIES.length());
2763 boolean[] mask = fm.apply(SPECIES.length());
2764 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2765
2766 for (int ic = 0; ic < INVOC_COUNT; ic++) {
2767 for (int i = 0; i < a.length; i += SPECIES.length()) {
2768 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2769 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
2770 av.lanewise(VectorOperators.ROL, bv, vmask).intoArray(r, i);
2771 }
2772 }
2773
2774 assertArraysEquals(r, a, b, mask, ByteMaxVectorTests::ROL);
2775 }
2776
2777 static byte ROR_unary(byte a, byte b) {
2778 return (byte)(ROR_scalar(a, b));
2779 }
2780
2781 @Test(dataProvider = "byteBinaryOpProvider")
2782 static void RORByteMaxVectorTestsScalarShift(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
2783 byte[] a = fa.apply(SPECIES.length());
2784 byte[] b = fb.apply(SPECIES.length());
2785 byte[] r = fr.apply(SPECIES.length());
2786
2787 for (int ic = 0; ic < INVOC_COUNT; ic++) {
2788 for (int i = 0; i < a.length; i += SPECIES.length()) {
2789 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2790 av.lanewise(VectorOperators.ROR, (int)b[i]).intoArray(r, i);
2791 }
2792 }
2793
2794 assertShiftArraysEquals(r, a, b, ByteMaxVectorTests::ROR_unary);
2795 }
2796
2797 @Test(dataProvider = "byteBinaryOpMaskProvider")
2798 static void RORByteMaxVectorTestsScalarShiftMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
2799 IntFunction<boolean[]> fm) {
2800 byte[] a = fa.apply(SPECIES.length());
2801 byte[] b = fb.apply(SPECIES.length());
2802 byte[] r = fr.apply(SPECIES.length());
2803 boolean[] mask = fm.apply(SPECIES.length());
2804 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2805
2806 for (int ic = 0; ic < INVOC_COUNT; ic++) {
2807 for (int i = 0; i < a.length; i += SPECIES.length()) {
2808 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2809 av.lanewise(VectorOperators.ROR, (int)b[i], vmask).intoArray(r, i);
2810 }
2811 }
2812
2813 assertShiftArraysEquals(r, a, b, mask, ByteMaxVectorTests::ROR_unary);
2814 }
2815
2816 static byte ROL_unary(byte a, byte b) {
2817 return (byte)(ROL_scalar(a, b));
2818 }
2819
2820 @Test(dataProvider = "byteBinaryOpProvider")
2821 static void ROLByteMaxVectorTestsScalarShift(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
2822 byte[] a = fa.apply(SPECIES.length());
2823 byte[] b = fb.apply(SPECIES.length());
2824 byte[] r = fr.apply(SPECIES.length());
2825
2826 for (int ic = 0; ic < INVOC_COUNT; ic++) {
2827 for (int i = 0; i < a.length; i += SPECIES.length()) {
2828 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2829 av.lanewise(VectorOperators.ROL, (int)b[i]).intoArray(r, i);
2830 }
2831 }
2832
2833 assertShiftArraysEquals(r, a, b, ByteMaxVectorTests::ROL_unary);
2834 }
2835
2836 @Test(dataProvider = "byteBinaryOpMaskProvider")
2837 static void ROLByteMaxVectorTestsScalarShiftMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
2838 IntFunction<boolean[]> fm) {
2839 byte[] a = fa.apply(SPECIES.length());
2840 byte[] b = fb.apply(SPECIES.length());
2841 byte[] r = fr.apply(SPECIES.length());
2842 boolean[] mask = fm.apply(SPECIES.length());
2843 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2844
2845 for (int ic = 0; ic < INVOC_COUNT; ic++) {
2846 for (int i = 0; i < a.length; i += SPECIES.length()) {
2847 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2848 av.lanewise(VectorOperators.ROL, (int)b[i], vmask).intoArray(r, i);
2849 }
2850 }
2851
2852 assertShiftArraysEquals(r, a, b, mask, ByteMaxVectorTests::ROL_unary);
2853 }
2854 static byte LSHR_binary_const(byte a) {
2855 return (byte)(((a & 0xFF) >>> CONST_SHIFT));
2856 }
2857
2858 @Test(dataProvider = "byteUnaryOpProvider")
2859 static void LSHRByteMaxVectorTestsScalarShiftConst(IntFunction<byte[]> fa) {
2860 byte[] a = fa.apply(SPECIES.length());
2861 byte[] r = fr.apply(SPECIES.length());
2862
2863 for (int ic = 0; ic < INVOC_COUNT; ic++) {
2864 for (int i = 0; i < a.length; i += SPECIES.length()) {
2865 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2866 av.lanewise(VectorOperators.LSHR, CONST_SHIFT).intoArray(r, i);
2867 }
2868 }
2869
2870 assertShiftConstEquals(r, a, ByteMaxVectorTests::LSHR_binary_const);
2871 }
2872
2873 @Test(dataProvider = "byteUnaryOpMaskProvider")
2874 static void LSHRByteMaxVectorTestsScalarShiftMaskedConst(IntFunction<byte[]> fa,
2875 IntFunction<boolean[]> fm) {
2876 byte[] a = fa.apply(SPECIES.length());
2877 byte[] r = fr.apply(SPECIES.length());
2878 boolean[] mask = fm.apply(SPECIES.length());
2879 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2880
2881 for (int ic = 0; ic < INVOC_COUNT; ic++) {
2882 for (int i = 0; i < a.length; i += SPECIES.length()) {
2883 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2884 av.lanewise(VectorOperators.LSHR, CONST_SHIFT, vmask).intoArray(r, i);
2885 }
2886 }
2887
2888 assertShiftConstEquals(r, a, mask, ByteMaxVectorTests::LSHR_binary_const);
2889 }
2890
2891 static byte LSHL_binary_const(byte a) {
2892 return (byte)((a << CONST_SHIFT));
2893 }
2894
2895 @Test(dataProvider = "byteUnaryOpProvider")
2896 static void LSHLByteMaxVectorTestsScalarShiftConst(IntFunction<byte[]> fa) {
2897 byte[] a = fa.apply(SPECIES.length());
2898 byte[] r = fr.apply(SPECIES.length());
2899
2900 for (int ic = 0; ic < INVOC_COUNT; ic++) {
2901 for (int i = 0; i < a.length; i += SPECIES.length()) {
2902 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2903 av.lanewise(VectorOperators.LSHL, CONST_SHIFT).intoArray(r, i);
2904 }
2905 }
2906
2907 assertShiftConstEquals(r, a, ByteMaxVectorTests::LSHL_binary_const);
2908 }
2909
2910 @Test(dataProvider = "byteUnaryOpMaskProvider")
2911 static void LSHLByteMaxVectorTestsScalarShiftMaskedConst(IntFunction<byte[]> fa,
2912 IntFunction<boolean[]> fm) {
2913 byte[] a = fa.apply(SPECIES.length());
2914 byte[] r = fr.apply(SPECIES.length());
2915 boolean[] mask = fm.apply(SPECIES.length());
2916 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2917
2918 for (int ic = 0; ic < INVOC_COUNT; ic++) {
2919 for (int i = 0; i < a.length; i += SPECIES.length()) {
2920 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2921 av.lanewise(VectorOperators.LSHL, CONST_SHIFT, vmask).intoArray(r, i);
2922 }
2923 }
2924
2925 assertShiftConstEquals(r, a, mask, ByteMaxVectorTests::LSHL_binary_const);
2926 }
2927
2928 static byte ASHR_binary_const(byte a) {
2929 return (byte)((a >> CONST_SHIFT));
2930 }
2931
2932 @Test(dataProvider = "byteUnaryOpProvider")
2933 static void ASHRByteMaxVectorTestsScalarShiftConst(IntFunction<byte[]> fa) {
2934 byte[] a = fa.apply(SPECIES.length());
2935 byte[] r = fr.apply(SPECIES.length());
2936
2937 for (int ic = 0; ic < INVOC_COUNT; ic++) {
2938 for (int i = 0; i < a.length; i += SPECIES.length()) {
2939 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2940 av.lanewise(VectorOperators.ASHR, CONST_SHIFT).intoArray(r, i);
2941 }
2942 }
2943
2944 assertShiftConstEquals(r, a, ByteMaxVectorTests::ASHR_binary_const);
2945 }
2946
2947 @Test(dataProvider = "byteUnaryOpMaskProvider")
2948 static void ASHRByteMaxVectorTestsScalarShiftMaskedConst(IntFunction<byte[]> fa,
2949 IntFunction<boolean[]> fm) {
2950 byte[] a = fa.apply(SPECIES.length());
2951 byte[] r = fr.apply(SPECIES.length());
2952 boolean[] mask = fm.apply(SPECIES.length());
2953 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2954
2955 for (int ic = 0; ic < INVOC_COUNT; ic++) {
2956 for (int i = 0; i < a.length; i += SPECIES.length()) {
2957 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2958 av.lanewise(VectorOperators.ASHR, CONST_SHIFT, vmask).intoArray(r, i);
2959 }
2960 }
2961
2962 assertShiftConstEquals(r, a, mask, ByteMaxVectorTests::ASHR_binary_const);
2963 }
2964
2965 static byte ROR_binary_const(byte a) {
2966 return (byte)(ROR_scalar(a, CONST_SHIFT));
2967 }
2968
2969 @Test(dataProvider = "byteUnaryOpProvider")
2970 static void RORByteMaxVectorTestsScalarShiftConst(IntFunction<byte[]> fa) {
2971 byte[] a = fa.apply(SPECIES.length());
2972 byte[] r = fr.apply(SPECIES.length());
2973
2974 for (int ic = 0; ic < INVOC_COUNT; ic++) {
2975 for (int i = 0; i < a.length; i += SPECIES.length()) {
2976 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2977 av.lanewise(VectorOperators.ROR, CONST_SHIFT).intoArray(r, i);
2978 }
2979 }
2980
2981 assertShiftConstEquals(r, a, ByteMaxVectorTests::ROR_binary_const);
2982 }
2983
2984 @Test(dataProvider = "byteUnaryOpMaskProvider")
2985 static void RORByteMaxVectorTestsScalarShiftMaskedConst(IntFunction<byte[]> fa,
2986 IntFunction<boolean[]> fm) {
2987 byte[] a = fa.apply(SPECIES.length());
2988 byte[] r = fr.apply(SPECIES.length());
2989 boolean[] mask = fm.apply(SPECIES.length());
2990 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2991
2992 for (int ic = 0; ic < INVOC_COUNT; ic++) {
2993 for (int i = 0; i < a.length; i += SPECIES.length()) {
2994 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
2995 av.lanewise(VectorOperators.ROR, CONST_SHIFT, vmask).intoArray(r, i);
2996 }
2997 }
2998
2999 assertShiftConstEquals(r, a, mask, ByteMaxVectorTests::ROR_binary_const);
3000 }
3001
3002 static byte ROL_binary_const(byte a) {
3003 return (byte)(ROL_scalar(a, CONST_SHIFT));
3004 }
3005
3006 @Test(dataProvider = "byteUnaryOpProvider")
3007 static void ROLByteMaxVectorTestsScalarShiftConst(IntFunction<byte[]> fa) {
3008 byte[] a = fa.apply(SPECIES.length());
3009 byte[] r = fr.apply(SPECIES.length());
3010
3011 for (int ic = 0; ic < INVOC_COUNT; ic++) {
3012 for (int i = 0; i < a.length; i += SPECIES.length()) {
3013 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3014 av.lanewise(VectorOperators.ROL, CONST_SHIFT).intoArray(r, i);
3015 }
3016 }
3017
3018 assertShiftConstEquals(r, a, ByteMaxVectorTests::ROL_binary_const);
3019 }
3020
3021 @Test(dataProvider = "byteUnaryOpMaskProvider")
3022 static void ROLByteMaxVectorTestsScalarShiftMaskedConst(IntFunction<byte[]> fa,
3023 IntFunction<boolean[]> fm) {
3024 byte[] a = fa.apply(SPECIES.length());
3025 byte[] r = fr.apply(SPECIES.length());
3026 boolean[] mask = fm.apply(SPECIES.length());
3027 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3028
3029 for (int ic = 0; ic < INVOC_COUNT; ic++) {
3030 for (int i = 0; i < a.length; i += SPECIES.length()) {
3031 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3032 av.lanewise(VectorOperators.ROL, CONST_SHIFT, vmask).intoArray(r, i);
3033 }
3034 }
3035
3036 assertShiftConstEquals(r, a, mask, ByteMaxVectorTests::ROL_binary_const);
3037 }
3038
3039
3040 static ByteVector bv_MIN = ByteVector.broadcast(SPECIES, (byte)10);
3041
3042 @Test(dataProvider = "byteUnaryOpProvider")
3043 static void MINByteMaxVectorTestsWithMemOp(IntFunction<byte[]> fa) {
3044 byte[] a = fa.apply(SPECIES.length());
3045 byte[] r = fr.apply(SPECIES.length());
3046
3047 for (int ic = 0; ic < INVOC_COUNT; ic++) {
3048 for (int i = 0; i < a.length; i += SPECIES.length()) {
3049 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3050 av.lanewise(VectorOperators.MIN, bv_MIN).intoArray(r, i);
3051 }
3052 }
3053
3054 assertArraysEquals(r, a, (byte)10, ByteMaxVectorTests::MIN);
3055 }
3056
3057 static ByteVector bv_min = ByteVector.broadcast(SPECIES, (byte)10);
3058
3059 @Test(dataProvider = "byteUnaryOpProvider")
3060 static void minByteMaxVectorTestsWithMemOp(IntFunction<byte[]> fa) {
3061 byte[] a = fa.apply(SPECIES.length());
3062 byte[] r = fr.apply(SPECIES.length());
3063
3064 for (int ic = 0; ic < INVOC_COUNT; ic++) {
3065 for (int i = 0; i < a.length; i += SPECIES.length()) {
3066 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3067 av.min(bv_min).intoArray(r, i);
3068 }
3069 }
3070
3071 assertArraysEquals(r, a, (byte)10, ByteMaxVectorTests::min);
3072 }
3073
3074 static ByteVector bv_MIN_M = ByteVector.broadcast(SPECIES, (byte)10);
3075
3076 @Test(dataProvider = "byteUnaryOpMaskProvider")
3077 static void MINByteMaxVectorTestsMaskedWithMemOp(IntFunction<byte[]> fa, IntFunction<boolean[]> fm) {
3078 byte[] a = fa.apply(SPECIES.length());
3079 byte[] r = fr.apply(SPECIES.length());
3080 boolean[] mask = fm.apply(SPECIES.length());
3081 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3082
3083 for (int ic = 0; ic < INVOC_COUNT; ic++) {
3084 for (int i = 0; i < a.length; i += SPECIES.length()) {
3085 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3086 av.lanewise(VectorOperators.MIN, bv_MIN_M, vmask).intoArray(r, i);
3087 }
3088 }
3089
3090 assertArraysEquals(r, a, (byte)10, mask, ByteMaxVectorTests::MIN);
3091 }
3092
3093 static ByteVector bv_MAX = ByteVector.broadcast(SPECIES, (byte)10);
3094
3095 @Test(dataProvider = "byteUnaryOpProvider")
3096 static void MAXByteMaxVectorTestsWithMemOp(IntFunction<byte[]> fa) {
3097 byte[] a = fa.apply(SPECIES.length());
3098 byte[] r = fr.apply(SPECIES.length());
3099
3100 for (int ic = 0; ic < INVOC_COUNT; ic++) {
3101 for (int i = 0; i < a.length; i += SPECIES.length()) {
3102 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3103 av.lanewise(VectorOperators.MAX, bv_MAX).intoArray(r, i);
3104 }
3105 }
3106
3107 assertArraysEquals(r, a, (byte)10, ByteMaxVectorTests::MAX);
3108 }
3109
3110 static ByteVector bv_max = ByteVector.broadcast(SPECIES, (byte)10);
3111
3112 @Test(dataProvider = "byteUnaryOpProvider")
3113 static void maxByteMaxVectorTestsWithMemOp(IntFunction<byte[]> fa) {
3114 byte[] a = fa.apply(SPECIES.length());
3115 byte[] r = fr.apply(SPECIES.length());
3116
3117 for (int ic = 0; ic < INVOC_COUNT; ic++) {
3118 for (int i = 0; i < a.length; i += SPECIES.length()) {
3119 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3120 av.max(bv_max).intoArray(r, i);
3121 }
3122 }
3123
3124 assertArraysEquals(r, a, (byte)10, ByteMaxVectorTests::max);
3125 }
3126
3127 static ByteVector bv_MAX_M = ByteVector.broadcast(SPECIES, (byte)10);
3128
3129 @Test(dataProvider = "byteUnaryOpMaskProvider")
3130 static void MAXByteMaxVectorTestsMaskedWithMemOp(IntFunction<byte[]> fa, IntFunction<boolean[]> fm) {
3131 byte[] a = fa.apply(SPECIES.length());
3132 byte[] r = fr.apply(SPECIES.length());
3133 boolean[] mask = fm.apply(SPECIES.length());
3134 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3135
3136 for (int ic = 0; ic < INVOC_COUNT; ic++) {
3137 for (int i = 0; i < a.length; i += SPECIES.length()) {
3138 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3139 av.lanewise(VectorOperators.MAX, bv_MAX_M, vmask).intoArray(r, i);
3140 }
3141 }
3142
3143 assertArraysEquals(r, a, (byte)10, mask, ByteMaxVectorTests::MAX);
3144 }
3145
3146 static byte MIN(byte a, byte b) {
3147 return (byte)(Math.min(a, b));
3148 }
3149
3150 @Test(dataProvider = "byteBinaryOpProvider")
3151 static void MINByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
3152 byte[] a = fa.apply(SPECIES.length());
3153 byte[] b = fb.apply(SPECIES.length());
3154 byte[] r = fr.apply(SPECIES.length());
3155
3156 for (int ic = 0; ic < INVOC_COUNT; ic++) {
3157 for (int i = 0; i < a.length; i += SPECIES.length()) {
3158 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3159 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
3160 av.lanewise(VectorOperators.MIN, bv).intoArray(r, i);
3161 }
3162 }
3163
3164 assertArraysEquals(r, a, b, ByteMaxVectorTests::MIN);
3165 }
3166
3167 static byte min(byte a, byte b) {
3168 return (byte)(Math.min(a, b));
3169 }
3170
3171 @Test(dataProvider = "byteBinaryOpProvider")
3172 static void minByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
3173 byte[] a = fa.apply(SPECIES.length());
3174 byte[] b = fb.apply(SPECIES.length());
3175 byte[] r = fr.apply(SPECIES.length());
3176
3177 for (int i = 0; i < a.length; i += SPECIES.length()) {
3178 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3179 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
3180 av.min(bv).intoArray(r, i);
3181 }
3182
3183 assertArraysEquals(r, a, b, ByteMaxVectorTests::min);
3184 }
3185
3186 static byte MAX(byte a, byte b) {
3187 return (byte)(Math.max(a, b));
3188 }
3189
3190 @Test(dataProvider = "byteBinaryOpProvider")
3191 static void MAXByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
3192 byte[] a = fa.apply(SPECIES.length());
3193 byte[] b = fb.apply(SPECIES.length());
3194 byte[] r = fr.apply(SPECIES.length());
3195
3196 for (int ic = 0; ic < INVOC_COUNT; ic++) {
3197 for (int i = 0; i < a.length; i += SPECIES.length()) {
3198 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3199 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
3200 av.lanewise(VectorOperators.MAX, bv).intoArray(r, i);
3201 }
3202 }
3203
3204 assertArraysEquals(r, a, b, ByteMaxVectorTests::MAX);
3205 }
3206
3207 static byte max(byte a, byte b) {
3208 return (byte)(Math.max(a, b));
3209 }
3210
3211 @Test(dataProvider = "byteBinaryOpProvider")
3212 static void maxByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
3213 byte[] a = fa.apply(SPECIES.length());
3214 byte[] b = fb.apply(SPECIES.length());
3215 byte[] r = fr.apply(SPECIES.length());
3216
3217 for (int i = 0; i < a.length; i += SPECIES.length()) {
3218 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3219 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
3220 av.max(bv).intoArray(r, i);
3221 }
3222
3223 assertArraysEquals(r, a, b, ByteMaxVectorTests::max);
3224 }
3225
3226 static byte UMIN(byte a, byte b) {
3227 return (byte)(VectorMath.minUnsigned(a, b));
3228 }
3229
3230 @Test(dataProvider = "byteBinaryOpProvider")
3231 static void UMINByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
3232 byte[] a = fa.apply(SPECIES.length());
3233 byte[] b = fb.apply(SPECIES.length());
3234 byte[] r = fr.apply(SPECIES.length());
3235
3236 for (int ic = 0; ic < INVOC_COUNT; ic++) {
3237 for (int i = 0; i < a.length; i += SPECIES.length()) {
3238 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3239 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
3240 av.lanewise(VectorOperators.UMIN, bv).intoArray(r, i);
3241 }
3242 }
3243
3244 assertArraysEquals(r, a, b, ByteMaxVectorTests::UMIN);
3245 }
3246
3247 @Test(dataProvider = "byteBinaryOpMaskProvider")
3248 static void UMINByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
3249 IntFunction<boolean[]> fm) {
3250 byte[] a = fa.apply(SPECIES.length());
3251 byte[] b = fb.apply(SPECIES.length());
3252 byte[] r = fr.apply(SPECIES.length());
3253 boolean[] mask = fm.apply(SPECIES.length());
3254 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3255
3256 for (int ic = 0; ic < INVOC_COUNT; ic++) {
3257 for (int i = 0; i < a.length; i += SPECIES.length()) {
3258 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3259 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
3260 av.lanewise(VectorOperators.UMIN, bv, vmask).intoArray(r, i);
3261 }
3262 }
3263
3264 assertArraysEquals(r, a, b, mask, ByteMaxVectorTests::UMIN);
3265 }
3266
3267 static byte UMAX(byte a, byte b) {
3268 return (byte)(VectorMath.maxUnsigned(a, b));
3269 }
3270
3271 @Test(dataProvider = "byteBinaryOpProvider")
3272 static void UMAXByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
3273 byte[] a = fa.apply(SPECIES.length());
3274 byte[] b = fb.apply(SPECIES.length());
3275 byte[] r = fr.apply(SPECIES.length());
3276
3277 for (int ic = 0; ic < INVOC_COUNT; ic++) {
3278 for (int i = 0; i < a.length; i += SPECIES.length()) {
3279 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3280 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
3281 av.lanewise(VectorOperators.UMAX, bv).intoArray(r, i);
3282 }
3283 }
3284
3285 assertArraysEquals(r, a, b, ByteMaxVectorTests::UMAX);
3286 }
3287
3288 @Test(dataProvider = "byteBinaryOpMaskProvider")
3289 static void UMAXByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
3290 IntFunction<boolean[]> fm) {
3291 byte[] a = fa.apply(SPECIES.length());
3292 byte[] b = fb.apply(SPECIES.length());
3293 byte[] r = fr.apply(SPECIES.length());
3294 boolean[] mask = fm.apply(SPECIES.length());
3295 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3296
3297 for (int ic = 0; ic < INVOC_COUNT; ic++) {
3298 for (int i = 0; i < a.length; i += SPECIES.length()) {
3299 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3300 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
3301 av.lanewise(VectorOperators.UMAX, bv, vmask).intoArray(r, i);
3302 }
3303 }
3304
3305 assertArraysEquals(r, a, b, mask, ByteMaxVectorTests::UMAX);
3306 }
3307
3308 static byte SADD(byte a, byte b) {
3309 return (byte)(VectorMath.addSaturating(a, b));
3310 }
3311
3312 @Test(dataProvider = "byteSaturatingBinaryOpProvider")
3313 static void SADDByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
3314 byte[] a = fa.apply(SPECIES.length());
3315 byte[] b = fb.apply(SPECIES.length());
3316 byte[] r = fr.apply(SPECIES.length());
3317
3318 for (int ic = 0; ic < INVOC_COUNT; ic++) {
3319 for (int i = 0; i < a.length; i += SPECIES.length()) {
3320 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3321 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
3322 av.lanewise(VectorOperators.SADD, bv).intoArray(r, i);
3323 }
3324 }
3325
3326 assertArraysEquals(r, a, b, ByteMaxVectorTests::SADD);
3327 }
3328
3329 @Test(dataProvider = "byteSaturatingBinaryOpMaskProvider")
3330 static void SADDByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
3331 IntFunction<boolean[]> fm) {
3332 byte[] a = fa.apply(SPECIES.length());
3333 byte[] b = fb.apply(SPECIES.length());
3334 byte[] r = fr.apply(SPECIES.length());
3335 boolean[] mask = fm.apply(SPECIES.length());
3336 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3337
3338 for (int ic = 0; ic < INVOC_COUNT; ic++) {
3339 for (int i = 0; i < a.length; i += SPECIES.length()) {
3340 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3341 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
3342 av.lanewise(VectorOperators.SADD, bv, vmask).intoArray(r, i);
3343 }
3344 }
3345
3346 assertArraysEquals(r, a, b, mask, ByteMaxVectorTests::SADD);
3347 }
3348
3349 static byte SSUB(byte a, byte b) {
3350 return (byte)(VectorMath.subSaturating(a, b));
3351 }
3352
3353 @Test(dataProvider = "byteSaturatingBinaryOpProvider")
3354 static void SSUBByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
3355 byte[] a = fa.apply(SPECIES.length());
3356 byte[] b = fb.apply(SPECIES.length());
3357 byte[] r = fr.apply(SPECIES.length());
3358
3359 for (int ic = 0; ic < INVOC_COUNT; ic++) {
3360 for (int i = 0; i < a.length; i += SPECIES.length()) {
3361 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3362 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
3363 av.lanewise(VectorOperators.SSUB, bv).intoArray(r, i);
3364 }
3365 }
3366
3367 assertArraysEquals(r, a, b, ByteMaxVectorTests::SSUB);
3368 }
3369
3370 @Test(dataProvider = "byteSaturatingBinaryOpMaskProvider")
3371 static void SSUBByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
3372 IntFunction<boolean[]> fm) {
3373 byte[] a = fa.apply(SPECIES.length());
3374 byte[] b = fb.apply(SPECIES.length());
3375 byte[] r = fr.apply(SPECIES.length());
3376 boolean[] mask = fm.apply(SPECIES.length());
3377 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3378
3379 for (int ic = 0; ic < INVOC_COUNT; ic++) {
3380 for (int i = 0; i < a.length; i += SPECIES.length()) {
3381 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3382 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
3383 av.lanewise(VectorOperators.SSUB, bv, vmask).intoArray(r, i);
3384 }
3385 }
3386
3387 assertArraysEquals(r, a, b, mask, ByteMaxVectorTests::SSUB);
3388 }
3389
3390 static byte SUADD(byte a, byte b) {
3391 return (byte)(VectorMath.addSaturatingUnsigned(a, b));
3392 }
3393
3394 @Test(dataProvider = "byteSaturatingBinaryOpProvider")
3395 static void SUADDByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
3396 byte[] a = fa.apply(SPECIES.length());
3397 byte[] b = fb.apply(SPECIES.length());
3398 byte[] r = fr.apply(SPECIES.length());
3399
3400 for (int ic = 0; ic < INVOC_COUNT; ic++) {
3401 for (int i = 0; i < a.length; i += SPECIES.length()) {
3402 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3403 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
3404 av.lanewise(VectorOperators.SUADD, bv).intoArray(r, i);
3405 }
3406 }
3407
3408 assertArraysEquals(r, a, b, ByteMaxVectorTests::SUADD);
3409 }
3410
3411 @Test(dataProvider = "byteSaturatingBinaryOpMaskProvider")
3412 static void SUADDByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
3413 IntFunction<boolean[]> fm) {
3414 byte[] a = fa.apply(SPECIES.length());
3415 byte[] b = fb.apply(SPECIES.length());
3416 byte[] r = fr.apply(SPECIES.length());
3417 boolean[] mask = fm.apply(SPECIES.length());
3418 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3419
3420 for (int ic = 0; ic < INVOC_COUNT; ic++) {
3421 for (int i = 0; i < a.length; i += SPECIES.length()) {
3422 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3423 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
3424 av.lanewise(VectorOperators.SUADD, bv, vmask).intoArray(r, i);
3425 }
3426 }
3427
3428 assertArraysEquals(r, a, b, mask, ByteMaxVectorTests::SUADD);
3429 }
3430
3431 static byte SUSUB(byte a, byte b) {
3432 return (byte)(VectorMath.subSaturatingUnsigned(a, b));
3433 }
3434
3435 @Test(dataProvider = "byteSaturatingBinaryOpProvider")
3436 static void SUSUBByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
3437 byte[] a = fa.apply(SPECIES.length());
3438 byte[] b = fb.apply(SPECIES.length());
3439 byte[] r = fr.apply(SPECIES.length());
3440
3441 for (int ic = 0; ic < INVOC_COUNT; ic++) {
3442 for (int i = 0; i < a.length; i += SPECIES.length()) {
3443 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3444 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
3445 av.lanewise(VectorOperators.SUSUB, bv).intoArray(r, i);
3446 }
3447 }
3448
3449 assertArraysEquals(r, a, b, ByteMaxVectorTests::SUSUB);
3450 }
3451
3452 @Test(dataProvider = "byteSaturatingBinaryOpMaskProvider")
3453 static void SUSUBByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
3454 IntFunction<boolean[]> fm) {
3455 byte[] a = fa.apply(SPECIES.length());
3456 byte[] b = fb.apply(SPECIES.length());
3457 byte[] r = fr.apply(SPECIES.length());
3458 boolean[] mask = fm.apply(SPECIES.length());
3459 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3460
3461 for (int ic = 0; ic < INVOC_COUNT; ic++) {
3462 for (int i = 0; i < a.length; i += SPECIES.length()) {
3463 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3464 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
3465 av.lanewise(VectorOperators.SUSUB, bv, vmask).intoArray(r, i);
3466 }
3467 }
3468
3469 assertArraysEquals(r, a, b, mask, ByteMaxVectorTests::SUSUB);
3470 }
3471
3472 @Test(dataProvider = "byteBinaryOpProvider")
3473 static void MINByteMaxVectorTestsBroadcastSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
3474 byte[] a = fa.apply(SPECIES.length());
3475 byte[] b = fb.apply(SPECIES.length());
3476 byte[] r = fr.apply(SPECIES.length());
3477
3478 for (int i = 0; i < a.length; i += SPECIES.length()) {
3479 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3480 av.lanewise(VectorOperators.MIN, b[i]).intoArray(r, i);
3481 }
3482
3483 assertBroadcastArraysEquals(r, a, b, ByteMaxVectorTests::MIN);
3484 }
3485
3486 @Test(dataProvider = "byteBinaryOpProvider")
3487 static void minByteMaxVectorTestsBroadcastSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
3488 byte[] a = fa.apply(SPECIES.length());
3489 byte[] b = fb.apply(SPECIES.length());
3490 byte[] r = fr.apply(SPECIES.length());
3491
3492 for (int i = 0; i < a.length; i += SPECIES.length()) {
3493 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3494 av.min(b[i]).intoArray(r, i);
3495 }
3496
3497 assertBroadcastArraysEquals(r, a, b, ByteMaxVectorTests::min);
3498 }
3499
3500 @Test(dataProvider = "byteBinaryOpProvider")
3501 static void MAXByteMaxVectorTestsBroadcastSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
3502 byte[] a = fa.apply(SPECIES.length());
3503 byte[] b = fb.apply(SPECIES.length());
3504 byte[] r = fr.apply(SPECIES.length());
3505
3506 for (int i = 0; i < a.length; i += SPECIES.length()) {
3507 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3508 av.lanewise(VectorOperators.MAX, b[i]).intoArray(r, i);
3509 }
3510
3511 assertBroadcastArraysEquals(r, a, b, ByteMaxVectorTests::MAX);
3512 }
3513
3514 @Test(dataProvider = "byteBinaryOpProvider")
3515 static void maxByteMaxVectorTestsBroadcastSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
3516 byte[] a = fa.apply(SPECIES.length());
3517 byte[] b = fb.apply(SPECIES.length());
3518 byte[] r = fr.apply(SPECIES.length());
3519
3520 for (int i = 0; i < a.length; i += SPECIES.length()) {
3521 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3522 av.max(b[i]).intoArray(r, i);
3523 }
3524
3525 assertBroadcastArraysEquals(r, a, b, ByteMaxVectorTests::max);
3526 }
3527 @Test(dataProvider = "byteSaturatingBinaryOpAssocProvider")
3528 static void SUADDAssocByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb, IntFunction<byte[]> fc) {
3529 byte[] a = fa.apply(SPECIES.length());
3530 byte[] b = fb.apply(SPECIES.length());
3531 byte[] c = fc.apply(SPECIES.length());
3532 byte[] rl = fr.apply(SPECIES.length());
3533 byte[] rr = fr.apply(SPECIES.length());
3534
3535 for (int ic = 0; ic < INVOC_COUNT; ic++) {
3536 for (int i = 0; i < a.length; i += SPECIES.length()) {
3537 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3538 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
3539 ByteVector cv = ByteVector.fromArray(SPECIES, c, i);
3540 av.lanewise(VectorOperators.SUADD, bv).lanewise(VectorOperators.SUADD, cv).intoArray(rl, i);
3541 av.lanewise(VectorOperators.SUADD, bv.lanewise(VectorOperators.SUADD, cv)).intoArray(rr, i);
3542 }
3543 }
3544
3545 assertArraysEqualsAssociative(rl, rr, a, b, c, ByteMaxVectorTests::SUADD);
3546 }
3547
3548 @Test(dataProvider = "byteSaturatingBinaryOpAssocMaskProvider")
3549 static void SUADDAssocByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
3550 IntFunction<byte[]> fc, IntFunction<boolean[]> fm) {
3551 byte[] a = fa.apply(SPECIES.length());
3552 byte[] b = fb.apply(SPECIES.length());
3553 byte[] c = fc.apply(SPECIES.length());
3554 boolean[] mask = fm.apply(SPECIES.length());
3555 byte[] rl = fr.apply(SPECIES.length());
3556 byte[] rr = fr.apply(SPECIES.length());
3557
3558 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3559
3560 for (int ic = 0; ic < INVOC_COUNT; ic++) {
3561 for (int i = 0; i < a.length; i += SPECIES.length()) {
3562 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3563 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
3564 ByteVector cv = ByteVector.fromArray(SPECIES, c, i);
3565 av.lanewise(VectorOperators.SUADD, bv, vmask).lanewise(VectorOperators.SUADD, cv, vmask).intoArray(rl, i);
3566 av.lanewise(VectorOperators.SUADD, bv.lanewise(VectorOperators.SUADD, cv, vmask), vmask).intoArray(rr, i);
3567 }
3568 }
3569
3570 assertArraysEqualsAssociative(rl, rr, a, b, c, mask, ByteMaxVectorTests::SUADD);
3571 }
3572
3573 static byte ANDReduce(byte[] a, int idx) {
3574 byte res = -1;
3575 for (int i = idx; i < (idx + SPECIES.length()); i++) {
3576 res &= a[i];
3577 }
3578
3579 return res;
3580 }
3581
3582 static byte ANDReduceAll(byte[] a) {
3583 byte res = -1;
3584 for (int i = 0; i < a.length; i += SPECIES.length()) {
3585 res &= ANDReduce(a, i);
3586 }
3587
3588 return res;
3589 }
3590
3591 @Test(dataProvider = "byteUnaryOpProvider")
3592 static void ANDReduceByteMaxVectorTests(IntFunction<byte[]> fa) {
3593 byte[] a = fa.apply(SPECIES.length());
3594 byte[] r = fr.apply(SPECIES.length());
3595 byte ra = -1;
3596
3597 for (int ic = 0; ic < INVOC_COUNT; ic++) {
3598 for (int i = 0; i < a.length; i += SPECIES.length()) {
3599 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3600 r[i] = av.reduceLanes(VectorOperators.AND);
3601 }
3602 }
3603
3604 for (int ic = 0; ic < INVOC_COUNT; ic++) {
3605 ra = -1;
3606 for (int i = 0; i < a.length; i += SPECIES.length()) {
3607 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3608 ra &= av.reduceLanes(VectorOperators.AND);
3609 }
3610 }
3611
3612 assertReductionArraysEquals(r, ra, a,
3613 ByteMaxVectorTests::ANDReduce, ByteMaxVectorTests::ANDReduceAll);
3614 }
3615
3616 static byte ANDReduceMasked(byte[] a, int idx, boolean[] mask) {
3617 byte res = -1;
3618 for (int i = idx; i < (idx + SPECIES.length()); i++) {
3619 if (mask[i % SPECIES.length()])
3620 res &= a[i];
3621 }
3622
3623 return res;
3624 }
3625
3626 static byte ANDReduceAllMasked(byte[] a, boolean[] mask) {
3627 byte res = -1;
3628 for (int i = 0; i < a.length; i += SPECIES.length()) {
3629 res &= ANDReduceMasked(a, i, mask);
3630 }
3631
3632 return res;
3633 }
3634
3635 @Test(dataProvider = "byteUnaryOpMaskProvider")
3636 static void ANDReduceByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<boolean[]> fm) {
3637 byte[] a = fa.apply(SPECIES.length());
3638 byte[] r = fr.apply(SPECIES.length());
3639 boolean[] mask = fm.apply(SPECIES.length());
3640 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3641 byte ra = -1;
3642
3643 for (int ic = 0; ic < INVOC_COUNT; ic++) {
3644 for (int i = 0; i < a.length; i += SPECIES.length()) {
3645 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3646 r[i] = av.reduceLanes(VectorOperators.AND, vmask);
3647 }
3648 }
3649
3650 for (int ic = 0; ic < INVOC_COUNT; ic++) {
3651 ra = -1;
3652 for (int i = 0; i < a.length; i += SPECIES.length()) {
3653 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3654 ra &= av.reduceLanes(VectorOperators.AND, vmask);
3655 }
3656 }
3657
3658 assertReductionArraysEqualsMasked(r, ra, a, mask,
3659 ByteMaxVectorTests::ANDReduceMasked, ByteMaxVectorTests::ANDReduceAllMasked);
3660 }
3661
3662 static byte ORReduce(byte[] a, int idx) {
3663 byte res = 0;
3664 for (int i = idx; i < (idx + SPECIES.length()); i++) {
3665 res |= a[i];
3666 }
3667
3668 return res;
3669 }
3670
3671 static byte ORReduceAll(byte[] a) {
3672 byte res = 0;
3673 for (int i = 0; i < a.length; i += SPECIES.length()) {
3674 res |= ORReduce(a, i);
3675 }
3676
3677 return res;
3678 }
3679
3680 @Test(dataProvider = "byteUnaryOpProvider")
3681 static void ORReduceByteMaxVectorTests(IntFunction<byte[]> fa) {
3682 byte[] a = fa.apply(SPECIES.length());
3683 byte[] r = fr.apply(SPECIES.length());
3684 byte ra = 0;
3685
3686 for (int ic = 0; ic < INVOC_COUNT; ic++) {
3687 for (int i = 0; i < a.length; i += SPECIES.length()) {
3688 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3689 r[i] = av.reduceLanes(VectorOperators.OR);
3690 }
3691 }
3692
3693 for (int ic = 0; ic < INVOC_COUNT; ic++) {
3694 ra = 0;
3695 for (int i = 0; i < a.length; i += SPECIES.length()) {
3696 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3697 ra |= av.reduceLanes(VectorOperators.OR);
3698 }
3699 }
3700
3701 assertReductionArraysEquals(r, ra, a,
3702 ByteMaxVectorTests::ORReduce, ByteMaxVectorTests::ORReduceAll);
3703 }
3704
3705 static byte ORReduceMasked(byte[] a, int idx, boolean[] mask) {
3706 byte res = 0;
3707 for (int i = idx; i < (idx + SPECIES.length()); i++) {
3708 if (mask[i % SPECIES.length()])
3709 res |= a[i];
3710 }
3711
3712 return res;
3713 }
3714
3715 static byte ORReduceAllMasked(byte[] a, boolean[] mask) {
3716 byte res = 0;
3717 for (int i = 0; i < a.length; i += SPECIES.length()) {
3718 res |= ORReduceMasked(a, i, mask);
3719 }
3720
3721 return res;
3722 }
3723
3724 @Test(dataProvider = "byteUnaryOpMaskProvider")
3725 static void ORReduceByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<boolean[]> fm) {
3726 byte[] a = fa.apply(SPECIES.length());
3727 byte[] r = fr.apply(SPECIES.length());
3728 boolean[] mask = fm.apply(SPECIES.length());
3729 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3730 byte ra = 0;
3731
3732 for (int ic = 0; ic < INVOC_COUNT; ic++) {
3733 for (int i = 0; i < a.length; i += SPECIES.length()) {
3734 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3735 r[i] = av.reduceLanes(VectorOperators.OR, vmask);
3736 }
3737 }
3738
3739 for (int ic = 0; ic < INVOC_COUNT; ic++) {
3740 ra = 0;
3741 for (int i = 0; i < a.length; i += SPECIES.length()) {
3742 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3743 ra |= av.reduceLanes(VectorOperators.OR, vmask);
3744 }
3745 }
3746
3747 assertReductionArraysEqualsMasked(r, ra, a, mask,
3748 ByteMaxVectorTests::ORReduceMasked, ByteMaxVectorTests::ORReduceAllMasked);
3749 }
3750
3751 static byte XORReduce(byte[] a, int idx) {
3752 byte res = 0;
3753 for (int i = idx; i < (idx + SPECIES.length()); i++) {
3754 res ^= a[i];
3755 }
3756
3757 return res;
3758 }
3759
3760 static byte XORReduceAll(byte[] a) {
3761 byte res = 0;
3762 for (int i = 0; i < a.length; i += SPECIES.length()) {
3763 res ^= XORReduce(a, i);
3764 }
3765
3766 return res;
3767 }
3768
3769 @Test(dataProvider = "byteUnaryOpProvider")
3770 static void XORReduceByteMaxVectorTests(IntFunction<byte[]> fa) {
3771 byte[] a = fa.apply(SPECIES.length());
3772 byte[] r = fr.apply(SPECIES.length());
3773 byte ra = 0;
3774
3775 for (int ic = 0; ic < INVOC_COUNT; ic++) {
3776 for (int i = 0; i < a.length; i += SPECIES.length()) {
3777 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3778 r[i] = av.reduceLanes(VectorOperators.XOR);
3779 }
3780 }
3781
3782 for (int ic = 0; ic < INVOC_COUNT; ic++) {
3783 ra = 0;
3784 for (int i = 0; i < a.length; i += SPECIES.length()) {
3785 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3786 ra ^= av.reduceLanes(VectorOperators.XOR);
3787 }
3788 }
3789
3790 assertReductionArraysEquals(r, ra, a,
3791 ByteMaxVectorTests::XORReduce, ByteMaxVectorTests::XORReduceAll);
3792 }
3793
3794 static byte XORReduceMasked(byte[] a, int idx, boolean[] mask) {
3795 byte res = 0;
3796 for (int i = idx; i < (idx + SPECIES.length()); i++) {
3797 if (mask[i % SPECIES.length()])
3798 res ^= a[i];
3799 }
3800
3801 return res;
3802 }
3803
3804 static byte XORReduceAllMasked(byte[] a, boolean[] mask) {
3805 byte res = 0;
3806 for (int i = 0; i < a.length; i += SPECIES.length()) {
3807 res ^= XORReduceMasked(a, i, mask);
3808 }
3809
3810 return res;
3811 }
3812
3813 @Test(dataProvider = "byteUnaryOpMaskProvider")
3814 static void XORReduceByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<boolean[]> fm) {
3815 byte[] a = fa.apply(SPECIES.length());
3816 byte[] r = fr.apply(SPECIES.length());
3817 boolean[] mask = fm.apply(SPECIES.length());
3818 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3819 byte ra = 0;
3820
3821 for (int ic = 0; ic < INVOC_COUNT; ic++) {
3822 for (int i = 0; i < a.length; i += SPECIES.length()) {
3823 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3824 r[i] = av.reduceLanes(VectorOperators.XOR, vmask);
3825 }
3826 }
3827
3828 for (int ic = 0; ic < INVOC_COUNT; ic++) {
3829 ra = 0;
3830 for (int i = 0; i < a.length; i += SPECIES.length()) {
3831 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3832 ra ^= av.reduceLanes(VectorOperators.XOR, vmask);
3833 }
3834 }
3835
3836 assertReductionArraysEqualsMasked(r, ra, a, mask,
3837 ByteMaxVectorTests::XORReduceMasked, ByteMaxVectorTests::XORReduceAllMasked);
3838 }
3839
3840 static byte ADDReduce(byte[] a, int idx) {
3841 byte res = 0;
3842 for (int i = idx; i < (idx + SPECIES.length()); i++) {
3843 res += a[i];
3844 }
3845
3846 return res;
3847 }
3848
3849 static byte ADDReduceAll(byte[] a) {
3850 byte res = 0;
3851 for (int i = 0; i < a.length; i += SPECIES.length()) {
3852 res += ADDReduce(a, i);
3853 }
3854
3855 return res;
3856 }
3857
3858 @Test(dataProvider = "byteUnaryOpProvider")
3859 static void ADDReduceByteMaxVectorTests(IntFunction<byte[]> fa) {
3860 byte[] a = fa.apply(SPECIES.length());
3861 byte[] r = fr.apply(SPECIES.length());
3862 byte ra = 0;
3863
3864 for (int ic = 0; ic < INVOC_COUNT; ic++) {
3865 for (int i = 0; i < a.length; i += SPECIES.length()) {
3866 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3867 r[i] = av.reduceLanes(VectorOperators.ADD);
3868 }
3869 }
3870
3871 for (int ic = 0; ic < INVOC_COUNT; ic++) {
3872 ra = 0;
3873 for (int i = 0; i < a.length; i += SPECIES.length()) {
3874 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3875 ra += av.reduceLanes(VectorOperators.ADD);
3876 }
3877 }
3878
3879 assertReductionArraysEquals(r, ra, a,
3880 ByteMaxVectorTests::ADDReduce, ByteMaxVectorTests::ADDReduceAll);
3881 }
3882
3883 static byte ADDReduceMasked(byte[] a, int idx, boolean[] mask) {
3884 byte res = 0;
3885 for (int i = idx; i < (idx + SPECIES.length()); i++) {
3886 if (mask[i % SPECIES.length()])
3887 res += a[i];
3888 }
3889
3890 return res;
3891 }
3892
3893 static byte ADDReduceAllMasked(byte[] a, boolean[] mask) {
3894 byte res = 0;
3895 for (int i = 0; i < a.length; i += SPECIES.length()) {
3896 res += ADDReduceMasked(a, i, mask);
3897 }
3898
3899 return res;
3900 }
3901
3902 @Test(dataProvider = "byteUnaryOpMaskProvider")
3903 static void ADDReduceByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<boolean[]> fm) {
3904 byte[] a = fa.apply(SPECIES.length());
3905 byte[] r = fr.apply(SPECIES.length());
3906 boolean[] mask = fm.apply(SPECIES.length());
3907 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3908 byte ra = 0;
3909
3910 for (int ic = 0; ic < INVOC_COUNT; ic++) {
3911 for (int i = 0; i < a.length; i += SPECIES.length()) {
3912 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3913 r[i] = av.reduceLanes(VectorOperators.ADD, vmask);
3914 }
3915 }
3916
3917 for (int ic = 0; ic < INVOC_COUNT; ic++) {
3918 ra = 0;
3919 for (int i = 0; i < a.length; i += SPECIES.length()) {
3920 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3921 ra += av.reduceLanes(VectorOperators.ADD, vmask);
3922 }
3923 }
3924
3925 assertReductionArraysEqualsMasked(r, ra, a, mask,
3926 ByteMaxVectorTests::ADDReduceMasked, ByteMaxVectorTests::ADDReduceAllMasked);
3927 }
3928
3929 static byte MULReduce(byte[] a, int idx) {
3930 byte res = 1;
3931 for (int i = idx; i < (idx + SPECIES.length()); i++) {
3932 res *= a[i];
3933 }
3934
3935 return res;
3936 }
3937
3938 static byte MULReduceAll(byte[] a) {
3939 byte res = 1;
3940 for (int i = 0; i < a.length; i += SPECIES.length()) {
3941 res *= MULReduce(a, i);
3942 }
3943
3944 return res;
3945 }
3946
3947 @Test(dataProvider = "byteUnaryOpProvider")
3948 static void MULReduceByteMaxVectorTests(IntFunction<byte[]> fa) {
3949 byte[] a = fa.apply(SPECIES.length());
3950 byte[] r = fr.apply(SPECIES.length());
3951 byte ra = 1;
3952
3953 for (int ic = 0; ic < INVOC_COUNT; ic++) {
3954 for (int i = 0; i < a.length; i += SPECIES.length()) {
3955 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3956 r[i] = av.reduceLanes(VectorOperators.MUL);
3957 }
3958 }
3959
3960 for (int ic = 0; ic < INVOC_COUNT; ic++) {
3961 ra = 1;
3962 for (int i = 0; i < a.length; i += SPECIES.length()) {
3963 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3964 ra *= av.reduceLanes(VectorOperators.MUL);
3965 }
3966 }
3967
3968 assertReductionArraysEquals(r, ra, a,
3969 ByteMaxVectorTests::MULReduce, ByteMaxVectorTests::MULReduceAll);
3970 }
3971
3972 static byte MULReduceMasked(byte[] a, int idx, boolean[] mask) {
3973 byte res = 1;
3974 for (int i = idx; i < (idx + SPECIES.length()); i++) {
3975 if (mask[i % SPECIES.length()])
3976 res *= a[i];
3977 }
3978
3979 return res;
3980 }
3981
3982 static byte MULReduceAllMasked(byte[] a, boolean[] mask) {
3983 byte res = 1;
3984 for (int i = 0; i < a.length; i += SPECIES.length()) {
3985 res *= MULReduceMasked(a, i, mask);
3986 }
3987
3988 return res;
3989 }
3990
3991 @Test(dataProvider = "byteUnaryOpMaskProvider")
3992 static void MULReduceByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<boolean[]> fm) {
3993 byte[] a = fa.apply(SPECIES.length());
3994 byte[] r = fr.apply(SPECIES.length());
3995 boolean[] mask = fm.apply(SPECIES.length());
3996 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3997 byte ra = 1;
3998
3999 for (int ic = 0; ic < INVOC_COUNT; ic++) {
4000 for (int i = 0; i < a.length; i += SPECIES.length()) {
4001 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
4002 r[i] = av.reduceLanes(VectorOperators.MUL, vmask);
4003 }
4004 }
4005
4006 for (int ic = 0; ic < INVOC_COUNT; ic++) {
4007 ra = 1;
4008 for (int i = 0; i < a.length; i += SPECIES.length()) {
4009 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
4010 ra *= av.reduceLanes(VectorOperators.MUL, vmask);
4011 }
4012 }
4013
4014 assertReductionArraysEqualsMasked(r, ra, a, mask,
4015 ByteMaxVectorTests::MULReduceMasked, ByteMaxVectorTests::MULReduceAllMasked);
4016 }
4017
4018 static byte MINReduce(byte[] a, int idx) {
4019 byte res = Byte.MAX_VALUE;
4020 for (int i = idx; i < (idx + SPECIES.length()); i++) {
4021 res = (byte) Math.min(res, a[i]);
4022 }
4023
4024 return res;
4025 }
4026
4027 static byte MINReduceAll(byte[] a) {
4028 byte res = Byte.MAX_VALUE;
4029 for (int i = 0; i < a.length; i += SPECIES.length()) {
4030 res = (byte) Math.min(res, MINReduce(a, i));
4031 }
4032
4033 return res;
4034 }
4035
4036 @Test(dataProvider = "byteUnaryOpProvider")
4037 static void MINReduceByteMaxVectorTests(IntFunction<byte[]> fa) {
4038 byte[] a = fa.apply(SPECIES.length());
4039 byte[] r = fr.apply(SPECIES.length());
4040 byte ra = Byte.MAX_VALUE;
4041
4042 for (int ic = 0; ic < INVOC_COUNT; ic++) {
4043 for (int i = 0; i < a.length; i += SPECIES.length()) {
4044 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
4045 r[i] = av.reduceLanes(VectorOperators.MIN);
4046 }
4047 }
4048
4049 for (int ic = 0; ic < INVOC_COUNT; ic++) {
4050 ra = Byte.MAX_VALUE;
4051 for (int i = 0; i < a.length; i += SPECIES.length()) {
4052 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
4053 ra = (byte) Math.min(ra, av.reduceLanes(VectorOperators.MIN));
4054 }
4055 }
4056
4057 assertReductionArraysEquals(r, ra, a,
4058 ByteMaxVectorTests::MINReduce, ByteMaxVectorTests::MINReduceAll);
4059 }
4060
4061 static byte MINReduceMasked(byte[] a, int idx, boolean[] mask) {
4062 byte res = Byte.MAX_VALUE;
4063 for (int i = idx; i < (idx + SPECIES.length()); i++) {
4064 if (mask[i % SPECIES.length()])
4065 res = (byte) Math.min(res, a[i]);
4066 }
4067
4068 return res;
4069 }
4070
4071 static byte MINReduceAllMasked(byte[] a, boolean[] mask) {
4072 byte res = Byte.MAX_VALUE;
4073 for (int i = 0; i < a.length; i += SPECIES.length()) {
4074 res = (byte) Math.min(res, MINReduceMasked(a, i, mask));
4075 }
4076
4077 return res;
4078 }
4079
4080 @Test(dataProvider = "byteUnaryOpMaskProvider")
4081 static void MINReduceByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<boolean[]> fm) {
4082 byte[] a = fa.apply(SPECIES.length());
4083 byte[] r = fr.apply(SPECIES.length());
4084 boolean[] mask = fm.apply(SPECIES.length());
4085 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
4086 byte ra = Byte.MAX_VALUE;
4087
4088 for (int ic = 0; ic < INVOC_COUNT; ic++) {
4089 for (int i = 0; i < a.length; i += SPECIES.length()) {
4090 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
4091 r[i] = av.reduceLanes(VectorOperators.MIN, vmask);
4092 }
4093 }
4094
4095 for (int ic = 0; ic < INVOC_COUNT; ic++) {
4096 ra = Byte.MAX_VALUE;
4097 for (int i = 0; i < a.length; i += SPECIES.length()) {
4098 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
4099 ra = (byte) Math.min(ra, av.reduceLanes(VectorOperators.MIN, vmask));
4100 }
4101 }
4102
4103 assertReductionArraysEqualsMasked(r, ra, a, mask,
4104 ByteMaxVectorTests::MINReduceMasked, ByteMaxVectorTests::MINReduceAllMasked);
4105 }
4106
4107 static byte MAXReduce(byte[] a, int idx) {
4108 byte res = Byte.MIN_VALUE;
4109 for (int i = idx; i < (idx + SPECIES.length()); i++) {
4110 res = (byte) Math.max(res, a[i]);
4111 }
4112
4113 return res;
4114 }
4115
4116 static byte MAXReduceAll(byte[] a) {
4117 byte res = Byte.MIN_VALUE;
4118 for (int i = 0; i < a.length; i += SPECIES.length()) {
4119 res = (byte) Math.max(res, MAXReduce(a, i));
4120 }
4121
4122 return res;
4123 }
4124
4125 @Test(dataProvider = "byteUnaryOpProvider")
4126 static void MAXReduceByteMaxVectorTests(IntFunction<byte[]> fa) {
4127 byte[] a = fa.apply(SPECIES.length());
4128 byte[] r = fr.apply(SPECIES.length());
4129 byte ra = Byte.MIN_VALUE;
4130
4131 for (int ic = 0; ic < INVOC_COUNT; ic++) {
4132 for (int i = 0; i < a.length; i += SPECIES.length()) {
4133 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
4134 r[i] = av.reduceLanes(VectorOperators.MAX);
4135 }
4136 }
4137
4138 for (int ic = 0; ic < INVOC_COUNT; ic++) {
4139 ra = Byte.MIN_VALUE;
4140 for (int i = 0; i < a.length; i += SPECIES.length()) {
4141 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
4142 ra = (byte) Math.max(ra, av.reduceLanes(VectorOperators.MAX));
4143 }
4144 }
4145
4146 assertReductionArraysEquals(r, ra, a,
4147 ByteMaxVectorTests::MAXReduce, ByteMaxVectorTests::MAXReduceAll);
4148 }
4149
4150 static byte MAXReduceMasked(byte[] a, int idx, boolean[] mask) {
4151 byte res = Byte.MIN_VALUE;
4152 for (int i = idx; i < (idx + SPECIES.length()); i++) {
4153 if (mask[i % SPECIES.length()])
4154 res = (byte) Math.max(res, a[i]);
4155 }
4156
4157 return res;
4158 }
4159
4160 static byte MAXReduceAllMasked(byte[] a, boolean[] mask) {
4161 byte res = Byte.MIN_VALUE;
4162 for (int i = 0; i < a.length; i += SPECIES.length()) {
4163 res = (byte) Math.max(res, MAXReduceMasked(a, i, mask));
4164 }
4165
4166 return res;
4167 }
4168
4169 @Test(dataProvider = "byteUnaryOpMaskProvider")
4170 static void MAXReduceByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<boolean[]> fm) {
4171 byte[] a = fa.apply(SPECIES.length());
4172 byte[] r = fr.apply(SPECIES.length());
4173 boolean[] mask = fm.apply(SPECIES.length());
4174 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
4175 byte ra = Byte.MIN_VALUE;
4176
4177 for (int ic = 0; ic < INVOC_COUNT; ic++) {
4178 for (int i = 0; i < a.length; i += SPECIES.length()) {
4179 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
4180 r[i] = av.reduceLanes(VectorOperators.MAX, vmask);
4181 }
4182 }
4183
4184 for (int ic = 0; ic < INVOC_COUNT; ic++) {
4185 ra = Byte.MIN_VALUE;
4186 for (int i = 0; i < a.length; i += SPECIES.length()) {
4187 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
4188 ra = (byte) Math.max(ra, av.reduceLanes(VectorOperators.MAX, vmask));
4189 }
4190 }
4191
4192 assertReductionArraysEqualsMasked(r, ra, a, mask,
4193 ByteMaxVectorTests::MAXReduceMasked, ByteMaxVectorTests::MAXReduceAllMasked);
4194 }
4195
4196 static byte UMINReduce(byte[] a, int idx) {
4197 byte res = Byte.MAX_VALUE;
4198 for (int i = idx; i < (idx + SPECIES.length()); i++) {
4199 res = (byte) VectorMath.minUnsigned(res, a[i]);
4200 }
4201
4202 return res;
4203 }
4204
4205 static byte UMINReduceAll(byte[] a) {
4206 byte res = Byte.MAX_VALUE;
4207 for (int i = 0; i < a.length; i += SPECIES.length()) {
4208 res = (byte) VectorMath.minUnsigned(res, UMINReduce(a, i));
4209 }
4210
4211 return res;
4212 }
4213
4214 @Test(dataProvider = "byteUnaryOpProvider")
4215 static void UMINReduceByteMaxVectorTests(IntFunction<byte[]> fa) {
4216 byte[] a = fa.apply(SPECIES.length());
4217 byte[] r = fr.apply(SPECIES.length());
4218 byte ra = Byte.MAX_VALUE;
4219
4220 for (int ic = 0; ic < INVOC_COUNT; ic++) {
4221 for (int i = 0; i < a.length; i += SPECIES.length()) {
4222 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
4223 r[i] = av.reduceLanes(VectorOperators.UMIN);
4224 }
4225 }
4226
4227 for (int ic = 0; ic < INVOC_COUNT; ic++) {
4228 ra = Byte.MAX_VALUE;
4229 for (int i = 0; i < a.length; i += SPECIES.length()) {
4230 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
4231 ra = (byte) VectorMath.minUnsigned(ra, av.reduceLanes(VectorOperators.UMIN));
4232 }
4233 }
4234
4235 assertReductionArraysEquals(r, ra, a,
4236 ByteMaxVectorTests::UMINReduce, ByteMaxVectorTests::UMINReduceAll);
4237 }
4238
4239 static byte UMINReduceMasked(byte[] a, int idx, boolean[] mask) {
4240 byte res = Byte.MAX_VALUE;
4241 for (int i = idx; i < (idx + SPECIES.length()); i++) {
4242 if (mask[i % SPECIES.length()])
4243 res = (byte) VectorMath.minUnsigned(res, a[i]);
4244 }
4245
4246 return res;
4247 }
4248
4249 static byte UMINReduceAllMasked(byte[] a, boolean[] mask) {
4250 byte res = Byte.MAX_VALUE;
4251 for (int i = 0; i < a.length; i += SPECIES.length()) {
4252 res = (byte) VectorMath.minUnsigned(res, UMINReduceMasked(a, i, mask));
4253 }
4254
4255 return res;
4256 }
4257
4258 @Test(dataProvider = "byteUnaryOpMaskProvider")
4259 static void UMINReduceByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<boolean[]> fm) {
4260 byte[] a = fa.apply(SPECIES.length());
4261 byte[] r = fr.apply(SPECIES.length());
4262 boolean[] mask = fm.apply(SPECIES.length());
4263 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
4264 byte ra = Byte.MAX_VALUE;
4265
4266 for (int ic = 0; ic < INVOC_COUNT; ic++) {
4267 for (int i = 0; i < a.length; i += SPECIES.length()) {
4268 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
4269 r[i] = av.reduceLanes(VectorOperators.UMIN, vmask);
4270 }
4271 }
4272
4273 for (int ic = 0; ic < INVOC_COUNT; ic++) {
4274 ra = Byte.MAX_VALUE;
4275 for (int i = 0; i < a.length; i += SPECIES.length()) {
4276 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
4277 ra = (byte) VectorMath.minUnsigned(ra, av.reduceLanes(VectorOperators.UMIN, vmask));
4278 }
4279 }
4280
4281 assertReductionArraysEqualsMasked(r, ra, a, mask,
4282 ByteMaxVectorTests::UMINReduceMasked, ByteMaxVectorTests::UMINReduceAllMasked);
4283 }
4284
4285 static byte UMAXReduce(byte[] a, int idx) {
4286 byte res = Byte.MIN_VALUE;
4287 for (int i = idx; i < (idx + SPECIES.length()); i++) {
4288 res = (byte) VectorMath.maxUnsigned(res, a[i]);
4289 }
4290
4291 return res;
4292 }
4293
4294 static byte UMAXReduceAll(byte[] a) {
4295 byte res = Byte.MIN_VALUE;
4296 for (int i = 0; i < a.length; i += SPECIES.length()) {
4297 res = (byte) VectorMath.maxUnsigned(res, UMAXReduce(a, i));
4298 }
4299
4300 return res;
4301 }
4302
4303 @Test(dataProvider = "byteUnaryOpProvider")
4304 static void UMAXReduceByteMaxVectorTests(IntFunction<byte[]> fa) {
4305 byte[] a = fa.apply(SPECIES.length());
4306 byte[] r = fr.apply(SPECIES.length());
4307 byte ra = Byte.MIN_VALUE;
4308
4309 for (int ic = 0; ic < INVOC_COUNT; ic++) {
4310 for (int i = 0; i < a.length; i += SPECIES.length()) {
4311 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
4312 r[i] = av.reduceLanes(VectorOperators.UMAX);
4313 }
4314 }
4315
4316 for (int ic = 0; ic < INVOC_COUNT; ic++) {
4317 ra = Byte.MIN_VALUE;
4318 for (int i = 0; i < a.length; i += SPECIES.length()) {
4319 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
4320 ra = (byte) VectorMath.maxUnsigned(ra, av.reduceLanes(VectorOperators.UMAX));
4321 }
4322 }
4323
4324 assertReductionArraysEquals(r, ra, a,
4325 ByteMaxVectorTests::UMAXReduce, ByteMaxVectorTests::UMAXReduceAll);
4326 }
4327
4328 static byte UMAXReduceMasked(byte[] a, int idx, boolean[] mask) {
4329 byte res = Byte.MIN_VALUE;
4330 for (int i = idx; i < (idx + SPECIES.length()); i++) {
4331 if (mask[i % SPECIES.length()])
4332 res = (byte) VectorMath.maxUnsigned(res, a[i]);
4333 }
4334
4335 return res;
4336 }
4337
4338 static byte UMAXReduceAllMasked(byte[] a, boolean[] mask) {
4339 byte res = Byte.MIN_VALUE;
4340 for (int i = 0; i < a.length; i += SPECIES.length()) {
4341 res = (byte) VectorMath.maxUnsigned(res, UMAXReduceMasked(a, i, mask));
4342 }
4343
4344 return res;
4345 }
4346
4347 @Test(dataProvider = "byteUnaryOpMaskProvider")
4348 static void UMAXReduceByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<boolean[]> fm) {
4349 byte[] a = fa.apply(SPECIES.length());
4350 byte[] r = fr.apply(SPECIES.length());
4351 boolean[] mask = fm.apply(SPECIES.length());
4352 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
4353 byte ra = Byte.MIN_VALUE;
4354
4355 for (int ic = 0; ic < INVOC_COUNT; ic++) {
4356 for (int i = 0; i < a.length; i += SPECIES.length()) {
4357 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
4358 r[i] = av.reduceLanes(VectorOperators.UMAX, vmask);
4359 }
4360 }
4361
4362 for (int ic = 0; ic < INVOC_COUNT; ic++) {
4363 ra = Byte.MIN_VALUE;
4364 for (int i = 0; i < a.length; i += SPECIES.length()) {
4365 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
4366 ra = (byte) VectorMath.maxUnsigned(ra, av.reduceLanes(VectorOperators.UMAX, vmask));
4367 }
4368 }
4369
4370 assertReductionArraysEqualsMasked(r, ra, a, mask,
4371 ByteMaxVectorTests::UMAXReduceMasked, ByteMaxVectorTests::UMAXReduceAllMasked);
4372 }
4373
4374 static byte FIRST_NONZEROReduce(byte[] a, int idx) {
4375 byte res = (byte) 0;
4376 for (int i = idx; i < (idx + SPECIES.length()); i++) {
4377 res = firstNonZero(res, a[i]);
4378 }
4379
4380 return res;
4381 }
4382
4383 static byte FIRST_NONZEROReduceAll(byte[] a) {
4384 byte res = (byte) 0;
4385 for (int i = 0; i < a.length; i += SPECIES.length()) {
4386 res = firstNonZero(res, FIRST_NONZEROReduce(a, i));
4387 }
4388
4389 return res;
4390 }
4391
4392 @Test(dataProvider = "byteUnaryOpProvider")
4393 static void FIRST_NONZEROReduceByteMaxVectorTests(IntFunction<byte[]> fa) {
4394 byte[] a = fa.apply(SPECIES.length());
4395 byte[] r = fr.apply(SPECIES.length());
4396 byte ra = (byte) 0;
4397
4398 for (int ic = 0; ic < INVOC_COUNT; ic++) {
4399 for (int i = 0; i < a.length; i += SPECIES.length()) {
4400 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
4401 r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO);
4402 }
4403 }
4404
4405 for (int ic = 0; ic < INVOC_COUNT; ic++) {
4406 ra = (byte) 0;
4407 for (int i = 0; i < a.length; i += SPECIES.length()) {
4408 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
4409 ra = firstNonZero(ra, av.reduceLanes(VectorOperators.FIRST_NONZERO));
4410 }
4411 }
4412
4413 assertReductionArraysEquals(r, ra, a,
4414 ByteMaxVectorTests::FIRST_NONZEROReduce, ByteMaxVectorTests::FIRST_NONZEROReduceAll);
4415 }
4416
4417 static byte FIRST_NONZEROReduceMasked(byte[] a, int idx, boolean[] mask) {
4418 byte res = (byte) 0;
4419 for (int i = idx; i < (idx + SPECIES.length()); i++) {
4420 if (mask[i % SPECIES.length()])
4421 res = firstNonZero(res, a[i]);
4422 }
4423
4424 return res;
4425 }
4426
4427 static byte FIRST_NONZEROReduceAllMasked(byte[] a, boolean[] mask) {
4428 byte res = (byte) 0;
4429 for (int i = 0; i < a.length; i += SPECIES.length()) {
4430 res = firstNonZero(res, FIRST_NONZEROReduceMasked(a, i, mask));
4431 }
4432
4433 return res;
4434 }
4435
4436 @Test(dataProvider = "byteUnaryOpMaskProvider")
4437 static void FIRST_NONZEROReduceByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<boolean[]> fm) {
4438 byte[] a = fa.apply(SPECIES.length());
4439 byte[] r = fr.apply(SPECIES.length());
4440 boolean[] mask = fm.apply(SPECIES.length());
4441 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
4442 byte ra = (byte) 0;
4443
4444 for (int ic = 0; ic < INVOC_COUNT; ic++) {
4445 for (int i = 0; i < a.length; i += SPECIES.length()) {
4446 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
4447 r[i] = av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask);
4448 }
4449 }
4450
4451 for (int ic = 0; ic < INVOC_COUNT; ic++) {
4452 ra = (byte) 0;
4453 for (int i = 0; i < a.length; i += SPECIES.length()) {
4454 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
4455 ra = firstNonZero(ra, av.reduceLanes(VectorOperators.FIRST_NONZERO, vmask));
4456 }
4457 }
4458
4459 assertReductionArraysEqualsMasked(r, ra, a, mask,
4460 ByteMaxVectorTests::FIRST_NONZEROReduceMasked, ByteMaxVectorTests::FIRST_NONZEROReduceAllMasked);
4461 }
4462
4463 static boolean anyTrue(boolean[] a, int idx) {
4464 boolean res = false;
4465 for (int i = idx; i < (idx + SPECIES.length()); i++) {
4466 res |= a[i];
4467 }
4468
4469 return res;
4470 }
4471
4472 @Test(dataProvider = "boolUnaryOpProvider")
4473 static void anyTrueByteMaxVectorTests(IntFunction<boolean[]> fm) {
4474 boolean[] mask = fm.apply(SPECIES.length());
4475 boolean[] r = fmr.apply(SPECIES.length());
4476
4477 for (int ic = 0; ic < INVOC_COUNT; ic++) {
4478 for (int i = 0; i < mask.length; i += SPECIES.length()) {
4479 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, i);
4480 r[i] = vmask.anyTrue();
4481 }
4482 }
4483
4484 assertReductionBoolArraysEquals(r, mask, ByteMaxVectorTests::anyTrue);
4485 }
4486
4487 static boolean allTrue(boolean[] a, int idx) {
4488 boolean res = true;
4489 for (int i = idx; i < (idx + SPECIES.length()); i++) {
4490 res &= a[i];
4491 }
4492
4493 return res;
4494 }
4495
4496 @Test(dataProvider = "boolUnaryOpProvider")
4497 static void allTrueByteMaxVectorTests(IntFunction<boolean[]> fm) {
4498 boolean[] mask = fm.apply(SPECIES.length());
4499 boolean[] r = fmr.apply(SPECIES.length());
4500
4501 for (int ic = 0; ic < INVOC_COUNT; ic++) {
4502 for (int i = 0; i < mask.length; i += SPECIES.length()) {
4503 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, i);
4504 r[i] = vmask.allTrue();
4505 }
4506 }
4507
4508 assertReductionBoolArraysEquals(r, mask, ByteMaxVectorTests::allTrue);
4509 }
4510
4511 static byte SUADDReduce(byte[] a, int idx) {
4512 byte res = 0;
4513 for (int i = idx; i < (idx + SPECIES.length()); i++) {
4514 res = (byte) VectorMath.addSaturatingUnsigned(res, a[i]);
4515 }
4516
4517 return res;
4518 }
4519
4520 static byte SUADDReduceAll(byte[] a) {
4521 byte res = 0;
4522 for (int i = 0; i < a.length; i += SPECIES.length()) {
4523 res = (byte) VectorMath.addSaturatingUnsigned(res, SUADDReduce(a, i));
4524 }
4525
4526 return res;
4527 }
4528
4529 @Test(dataProvider = "byteSaturatingUnaryOpProvider")
4530 static void SUADDReduceByteMaxVectorTests(IntFunction<byte[]> fa) {
4531 byte[] a = fa.apply(SPECIES.length());
4532 byte[] r = fr.apply(SPECIES.length());
4533 byte ra = 0;
4534
4535 for (int ic = 0; ic < INVOC_COUNT; ic++) {
4536 for (int i = 0; i < a.length; i += SPECIES.length()) {
4537 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
4538 r[i] = av.reduceLanes(VectorOperators.SUADD);
4539 }
4540 }
4541
4542 for (int ic = 0; ic < INVOC_COUNT; ic++) {
4543 ra = 0;
4544 for (int i = 0; i < a.length; i += SPECIES.length()) {
4545 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
4546 ra = (byte) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD));
4547 }
4548 }
4549
4550 assertReductionArraysEquals(r, ra, a,
4551 ByteMaxVectorTests::SUADDReduce, ByteMaxVectorTests::SUADDReduceAll);
4552 }
4553
4554 static byte SUADDReduceMasked(byte[] a, int idx, boolean[] mask) {
4555 byte res = 0;
4556 for (int i = idx; i < (idx + SPECIES.length()); i++) {
4557 if (mask[i % SPECIES.length()])
4558 res = (byte) VectorMath.addSaturatingUnsigned(res, a[i]);
4559 }
4560
4561 return res;
4562 }
4563
4564 static byte SUADDReduceAllMasked(byte[] a, boolean[] mask) {
4565 byte res = 0;
4566 for (int i = 0; i < a.length; i += SPECIES.length()) {
4567 res = (byte) VectorMath.addSaturatingUnsigned(res, SUADDReduceMasked(a, i, mask));
4568 }
4569
4570 return res;
4571 }
4572 @Test(dataProvider = "byteSaturatingUnaryOpMaskProvider")
4573 static void SUADDReduceByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<boolean[]> fm) {
4574 byte[] a = fa.apply(SPECIES.length());
4575 byte[] r = fr.apply(SPECIES.length());
4576 boolean[] mask = fm.apply(SPECIES.length());
4577 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
4578 byte ra = 0;
4579
4580 for (int ic = 0; ic < INVOC_COUNT; ic++) {
4581 for (int i = 0; i < a.length; i += SPECIES.length()) {
4582 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
4583 r[i] = av.reduceLanes(VectorOperators.SUADD, vmask);
4584 }
4585 }
4586
4587 for (int ic = 0; ic < INVOC_COUNT; ic++) {
4588 ra = 0;
4589 for (int i = 0; i < a.length; i += SPECIES.length()) {
4590 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
4591 ra = (byte) VectorMath.addSaturatingUnsigned(ra, av.reduceLanes(VectorOperators.SUADD, vmask));
4592 }
4593 }
4594
4595 assertReductionArraysEqualsMasked(r, ra, a, mask,
4596 ByteMaxVectorTests::SUADDReduceMasked, ByteMaxVectorTests::SUADDReduceAllMasked);
4597 }
4598
4599 @Test(dataProvider = "byteBinaryOpProvider")
4600 static void withByteMaxVectorTests(IntFunction<byte []> fa, IntFunction<byte []> fb) {
4601 byte[] a = fa.apply(SPECIES.length());
4602 byte[] b = fb.apply(SPECIES.length());
4603 byte[] r = fr.apply(SPECIES.length());
4604
4605 for (int ic = 0; ic < INVOC_COUNT; ic++) {
4606 for (int i = 0, j = 0; i < a.length; i += SPECIES.length()) {
4607 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
4608 av.withLane(j, b[i + j]).intoArray(r, i);
4609 a[i + j] = b[i + j];
4610 j = (j + 1) & (SPECIES.length() - 1);
4611 }
4612 }
4613
4614
4615 assertArraysStrictlyEquals(r, a);
4616 }
4617
4618 static boolean testIS_DEFAULT(byte a) {
4619 return bits(a)==0;
4620 }
4621
4622 @Test(dataProvider = "byteTestOpProvider")
4623 static void IS_DEFAULTByteMaxVectorTests(IntFunction<byte[]> fa) {
4624 byte[] a = fa.apply(SPECIES.length());
4625
4626 for (int ic = 0; ic < INVOC_COUNT; ic++) {
4627 for (int i = 0; i < a.length; i += SPECIES.length()) {
4628 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
4629 VectorMask<Byte> mv = av.test(VectorOperators.IS_DEFAULT);
4630
4631 // Check results as part of computation.
4632 for (int j = 0; j < SPECIES.length(); j++) {
4633 Assert.assertEquals(mv.laneIsSet(j), testIS_DEFAULT(a[i + j]));
4634 }
4635 }
4636 }
4637 }
4638
4639 @Test(dataProvider = "byteTestOpMaskProvider")
4640 static void IS_DEFAULTMaskedByteMaxVectorTests(IntFunction<byte[]> fa,
4641 IntFunction<boolean[]> fm) {
4642 byte[] a = fa.apply(SPECIES.length());
4643 boolean[] mask = fm.apply(SPECIES.length());
4644 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
4645
4646 for (int ic = 0; ic < INVOC_COUNT; ic++) {
4647 for (int i = 0; i < a.length; i += SPECIES.length()) {
4648 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
4649 VectorMask<Byte> mv = av.test(VectorOperators.IS_DEFAULT, vmask);
4650
4651 // Check results as part of computation.
4652 for (int j = 0; j < SPECIES.length(); j++) {
4653 Assert.assertEquals(mv.laneIsSet(j), vmask.laneIsSet(j) && testIS_DEFAULT(a[i + j]));
4654 }
4655 }
4656 }
4657 }
4658
4659 static boolean testIS_NEGATIVE(byte a) {
4660 return bits(a)<0;
4661 }
4662
4663 @Test(dataProvider = "byteTestOpProvider")
4664 static void IS_NEGATIVEByteMaxVectorTests(IntFunction<byte[]> fa) {
4665 byte[] a = fa.apply(SPECIES.length());
4666
4667 for (int ic = 0; ic < INVOC_COUNT; ic++) {
4668 for (int i = 0; i < a.length; i += SPECIES.length()) {
4669 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
4670 VectorMask<Byte> mv = av.test(VectorOperators.IS_NEGATIVE);
4671
4672 // Check results as part of computation.
4673 for (int j = 0; j < SPECIES.length(); j++) {
4674 Assert.assertEquals(mv.laneIsSet(j), testIS_NEGATIVE(a[i + j]));
4675 }
4676 }
4677 }
4678 }
4679
4680 @Test(dataProvider = "byteTestOpMaskProvider")
4681 static void IS_NEGATIVEMaskedByteMaxVectorTests(IntFunction<byte[]> fa,
4682 IntFunction<boolean[]> fm) {
4683 byte[] a = fa.apply(SPECIES.length());
4684 boolean[] mask = fm.apply(SPECIES.length());
4685 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
4686
4687 for (int ic = 0; ic < INVOC_COUNT; ic++) {
4688 for (int i = 0; i < a.length; i += SPECIES.length()) {
4689 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
4690 VectorMask<Byte> mv = av.test(VectorOperators.IS_NEGATIVE, vmask);
4691
4692 // Check results as part of computation.
4693 for (int j = 0; j < SPECIES.length(); j++) {
4694 Assert.assertEquals(mv.laneIsSet(j), vmask.laneIsSet(j) && testIS_NEGATIVE(a[i + j]));
4695 }
4696 }
4697 }
4698 }
4699
4700 @Test(dataProvider = "byteCompareOpProvider")
4701 static void LTByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
4702 byte[] a = fa.apply(SPECIES.length());
4703 byte[] b = fb.apply(SPECIES.length());
4704
4705 for (int ic = 0; ic < INVOC_COUNT; ic++) {
4706 for (int i = 0; i < a.length; i += SPECIES.length()) {
4707 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
4708 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
4709 VectorMask<Byte> mv = av.compare(VectorOperators.LT, bv);
4710
4711 // Check results as part of computation.
4712 for (int j = 0; j < SPECIES.length(); j++) {
4713 Assert.assertEquals(mv.laneIsSet(j), lt(a[i + j], b[i + j]));
4714 }
4715 }
4716 }
4717 }
4718
4719 @Test(dataProvider = "byteCompareOpProvider")
4720 static void ltByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
4721 byte[] a = fa.apply(SPECIES.length());
4722 byte[] b = fb.apply(SPECIES.length());
4723
4724 for (int ic = 0; ic < INVOC_COUNT; ic++) {
4725 for (int i = 0; i < a.length; i += SPECIES.length()) {
4726 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
4727 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
4728 VectorMask<Byte> mv = av.lt(bv);
4729
4730 // Check results as part of computation.
4731 for (int j = 0; j < SPECIES.length(); j++) {
4732 Assert.assertEquals(mv.laneIsSet(j), lt(a[i + j], b[i + j]));
4733 }
4734 }
4735 }
4736 }
4737
4738 @Test(dataProvider = "byteCompareOpMaskProvider")
4739 static void LTByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
4740 IntFunction<boolean[]> fm) {
4741 byte[] a = fa.apply(SPECIES.length());
4742 byte[] b = fb.apply(SPECIES.length());
4743 boolean[] mask = fm.apply(SPECIES.length());
4744
4745 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
4746
4747 for (int ic = 0; ic < INVOC_COUNT; ic++) {
4748 for (int i = 0; i < a.length; i += SPECIES.length()) {
4749 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
4750 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
4751 VectorMask<Byte> mv = av.compare(VectorOperators.LT, bv, vmask);
4752
4753 // Check results as part of computation.
4754 for (int j = 0; j < SPECIES.length(); j++) {
4755 Assert.assertEquals(mv.laneIsSet(j), mask[j] && lt(a[i + j], b[i + j]));
4756 }
4757 }
4758 }
4759 }
4760
4761 @Test(dataProvider = "byteCompareOpProvider")
4762 static void GTByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
4763 byte[] a = fa.apply(SPECIES.length());
4764 byte[] b = fb.apply(SPECIES.length());
4765
4766 for (int ic = 0; ic < INVOC_COUNT; ic++) {
4767 for (int i = 0; i < a.length; i += SPECIES.length()) {
4768 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
4769 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
4770 VectorMask<Byte> mv = av.compare(VectorOperators.GT, bv);
4771
4772 // Check results as part of computation.
4773 for (int j = 0; j < SPECIES.length(); j++) {
4774 Assert.assertEquals(mv.laneIsSet(j), gt(a[i + j], b[i + j]));
4775 }
4776 }
4777 }
4778 }
4779
4780 @Test(dataProvider = "byteCompareOpMaskProvider")
4781 static void GTByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
4782 IntFunction<boolean[]> fm) {
4783 byte[] a = fa.apply(SPECIES.length());
4784 byte[] b = fb.apply(SPECIES.length());
4785 boolean[] mask = fm.apply(SPECIES.length());
4786
4787 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
4788
4789 for (int ic = 0; ic < INVOC_COUNT; ic++) {
4790 for (int i = 0; i < a.length; i += SPECIES.length()) {
4791 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
4792 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
4793 VectorMask<Byte> mv = av.compare(VectorOperators.GT, bv, vmask);
4794
4795 // Check results as part of computation.
4796 for (int j = 0; j < SPECIES.length(); j++) {
4797 Assert.assertEquals(mv.laneIsSet(j), mask[j] && gt(a[i + j], b[i + j]));
4798 }
4799 }
4800 }
4801 }
4802
4803 @Test(dataProvider = "byteCompareOpProvider")
4804 static void EQByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
4805 byte[] a = fa.apply(SPECIES.length());
4806 byte[] b = fb.apply(SPECIES.length());
4807
4808 for (int ic = 0; ic < INVOC_COUNT; ic++) {
4809 for (int i = 0; i < a.length; i += SPECIES.length()) {
4810 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
4811 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
4812 VectorMask<Byte> mv = av.compare(VectorOperators.EQ, bv);
4813
4814 // Check results as part of computation.
4815 for (int j = 0; j < SPECIES.length(); j++) {
4816 Assert.assertEquals(mv.laneIsSet(j), eq(a[i + j], b[i + j]));
4817 }
4818 }
4819 }
4820 }
4821
4822 @Test(dataProvider = "byteCompareOpProvider")
4823 static void eqByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
4824 byte[] a = fa.apply(SPECIES.length());
4825 byte[] b = fb.apply(SPECIES.length());
4826
4827 for (int ic = 0; ic < INVOC_COUNT; ic++) {
4828 for (int i = 0; i < a.length; i += SPECIES.length()) {
4829 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
4830 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
4831 VectorMask<Byte> mv = av.eq(bv);
4832
4833 // Check results as part of computation.
4834 for (int j = 0; j < SPECIES.length(); j++) {
4835 Assert.assertEquals(mv.laneIsSet(j), eq(a[i + j], b[i + j]));
4836 }
4837 }
4838 }
4839 }
4840
4841 @Test(dataProvider = "byteCompareOpMaskProvider")
4842 static void EQByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
4843 IntFunction<boolean[]> fm) {
4844 byte[] a = fa.apply(SPECIES.length());
4845 byte[] b = fb.apply(SPECIES.length());
4846 boolean[] mask = fm.apply(SPECIES.length());
4847
4848 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
4849
4850 for (int ic = 0; ic < INVOC_COUNT; ic++) {
4851 for (int i = 0; i < a.length; i += SPECIES.length()) {
4852 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
4853 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
4854 VectorMask<Byte> mv = av.compare(VectorOperators.EQ, bv, vmask);
4855
4856 // Check results as part of computation.
4857 for (int j = 0; j < SPECIES.length(); j++) {
4858 Assert.assertEquals(mv.laneIsSet(j), mask[j] && eq(a[i + j], b[i + j]));
4859 }
4860 }
4861 }
4862 }
4863
4864 @Test(dataProvider = "byteCompareOpProvider")
4865 static void NEByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
4866 byte[] a = fa.apply(SPECIES.length());
4867 byte[] b = fb.apply(SPECIES.length());
4868
4869 for (int ic = 0; ic < INVOC_COUNT; ic++) {
4870 for (int i = 0; i < a.length; i += SPECIES.length()) {
4871 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
4872 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
4873 VectorMask<Byte> mv = av.compare(VectorOperators.NE, bv);
4874
4875 // Check results as part of computation.
4876 for (int j = 0; j < SPECIES.length(); j++) {
4877 Assert.assertEquals(mv.laneIsSet(j), neq(a[i + j], b[i + j]));
4878 }
4879 }
4880 }
4881 }
4882
4883 @Test(dataProvider = "byteCompareOpMaskProvider")
4884 static void NEByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
4885 IntFunction<boolean[]> fm) {
4886 byte[] a = fa.apply(SPECIES.length());
4887 byte[] b = fb.apply(SPECIES.length());
4888 boolean[] mask = fm.apply(SPECIES.length());
4889
4890 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
4891
4892 for (int ic = 0; ic < INVOC_COUNT; ic++) {
4893 for (int i = 0; i < a.length; i += SPECIES.length()) {
4894 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
4895 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
4896 VectorMask<Byte> mv = av.compare(VectorOperators.NE, bv, vmask);
4897
4898 // Check results as part of computation.
4899 for (int j = 0; j < SPECIES.length(); j++) {
4900 Assert.assertEquals(mv.laneIsSet(j), mask[j] && neq(a[i + j], b[i + j]));
4901 }
4902 }
4903 }
4904 }
4905
4906 @Test(dataProvider = "byteCompareOpProvider")
4907 static void LEByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
4908 byte[] a = fa.apply(SPECIES.length());
4909 byte[] b = fb.apply(SPECIES.length());
4910
4911 for (int ic = 0; ic < INVOC_COUNT; ic++) {
4912 for (int i = 0; i < a.length; i += SPECIES.length()) {
4913 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
4914 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
4915 VectorMask<Byte> mv = av.compare(VectorOperators.LE, bv);
4916
4917 // Check results as part of computation.
4918 for (int j = 0; j < SPECIES.length(); j++) {
4919 Assert.assertEquals(mv.laneIsSet(j), le(a[i + j], b[i + j]));
4920 }
4921 }
4922 }
4923 }
4924
4925 @Test(dataProvider = "byteCompareOpMaskProvider")
4926 static void LEByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
4927 IntFunction<boolean[]> fm) {
4928 byte[] a = fa.apply(SPECIES.length());
4929 byte[] b = fb.apply(SPECIES.length());
4930 boolean[] mask = fm.apply(SPECIES.length());
4931
4932 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
4933
4934 for (int ic = 0; ic < INVOC_COUNT; ic++) {
4935 for (int i = 0; i < a.length; i += SPECIES.length()) {
4936 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
4937 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
4938 VectorMask<Byte> mv = av.compare(VectorOperators.LE, bv, vmask);
4939
4940 // Check results as part of computation.
4941 for (int j = 0; j < SPECIES.length(); j++) {
4942 Assert.assertEquals(mv.laneIsSet(j), mask[j] && le(a[i + j], b[i + j]));
4943 }
4944 }
4945 }
4946 }
4947
4948 @Test(dataProvider = "byteCompareOpProvider")
4949 static void GEByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
4950 byte[] a = fa.apply(SPECIES.length());
4951 byte[] b = fb.apply(SPECIES.length());
4952
4953 for (int ic = 0; ic < INVOC_COUNT; ic++) {
4954 for (int i = 0; i < a.length; i += SPECIES.length()) {
4955 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
4956 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
4957 VectorMask<Byte> mv = av.compare(VectorOperators.GE, bv);
4958
4959 // Check results as part of computation.
4960 for (int j = 0; j < SPECIES.length(); j++) {
4961 Assert.assertEquals(mv.laneIsSet(j), ge(a[i + j], b[i + j]));
4962 }
4963 }
4964 }
4965 }
4966
4967 @Test(dataProvider = "byteCompareOpMaskProvider")
4968 static void GEByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
4969 IntFunction<boolean[]> fm) {
4970 byte[] a = fa.apply(SPECIES.length());
4971 byte[] b = fb.apply(SPECIES.length());
4972 boolean[] mask = fm.apply(SPECIES.length());
4973
4974 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
4975
4976 for (int ic = 0; ic < INVOC_COUNT; ic++) {
4977 for (int i = 0; i < a.length; i += SPECIES.length()) {
4978 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
4979 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
4980 VectorMask<Byte> mv = av.compare(VectorOperators.GE, bv, vmask);
4981
4982 // Check results as part of computation.
4983 for (int j = 0; j < SPECIES.length(); j++) {
4984 Assert.assertEquals(mv.laneIsSet(j), mask[j] && ge(a[i + j], b[i + j]));
4985 }
4986 }
4987 }
4988 }
4989
4990 @Test(dataProvider = "byteCompareOpProvider")
4991 static void ULTByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
4992 byte[] a = fa.apply(SPECIES.length());
4993 byte[] b = fb.apply(SPECIES.length());
4994
4995 for (int ic = 0; ic < INVOC_COUNT; ic++) {
4996 for (int i = 0; i < a.length; i += SPECIES.length()) {
4997 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
4998 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
4999 VectorMask<Byte> mv = av.compare(VectorOperators.ULT, bv);
5000
5001 // Check results as part of computation.
5002 for (int j = 0; j < SPECIES.length(); j++) {
5003 Assert.assertEquals(mv.laneIsSet(j), ult(a[i + j], b[i + j]));
5004 }
5005 }
5006 }
5007 }
5008
5009 @Test(dataProvider = "byteCompareOpMaskProvider")
5010 static void ULTByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
5011 IntFunction<boolean[]> fm) {
5012 byte[] a = fa.apply(SPECIES.length());
5013 byte[] b = fb.apply(SPECIES.length());
5014 boolean[] mask = fm.apply(SPECIES.length());
5015
5016 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
5017
5018 for (int ic = 0; ic < INVOC_COUNT; ic++) {
5019 for (int i = 0; i < a.length; i += SPECIES.length()) {
5020 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
5021 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
5022 VectorMask<Byte> mv = av.compare(VectorOperators.ULT, bv, vmask);
5023
5024 // Check results as part of computation.
5025 for (int j = 0; j < SPECIES.length(); j++) {
5026 Assert.assertEquals(mv.laneIsSet(j), mask[j] && ult(a[i + j], b[i + j]));
5027 }
5028 }
5029 }
5030 }
5031
5032 @Test(dataProvider = "byteCompareOpProvider")
5033 static void UGTByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
5034 byte[] a = fa.apply(SPECIES.length());
5035 byte[] b = fb.apply(SPECIES.length());
5036
5037 for (int ic = 0; ic < INVOC_COUNT; ic++) {
5038 for (int i = 0; i < a.length; i += SPECIES.length()) {
5039 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
5040 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
5041 VectorMask<Byte> mv = av.compare(VectorOperators.UGT, bv);
5042
5043 // Check results as part of computation.
5044 for (int j = 0; j < SPECIES.length(); j++) {
5045 Assert.assertEquals(mv.laneIsSet(j), ugt(a[i + j], b[i + j]));
5046 }
5047 }
5048 }
5049 }
5050
5051 @Test(dataProvider = "byteCompareOpMaskProvider")
5052 static void UGTByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
5053 IntFunction<boolean[]> fm) {
5054 byte[] a = fa.apply(SPECIES.length());
5055 byte[] b = fb.apply(SPECIES.length());
5056 boolean[] mask = fm.apply(SPECIES.length());
5057
5058 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
5059
5060 for (int ic = 0; ic < INVOC_COUNT; ic++) {
5061 for (int i = 0; i < a.length; i += SPECIES.length()) {
5062 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
5063 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
5064 VectorMask<Byte> mv = av.compare(VectorOperators.UGT, bv, vmask);
5065
5066 // Check results as part of computation.
5067 for (int j = 0; j < SPECIES.length(); j++) {
5068 Assert.assertEquals(mv.laneIsSet(j), mask[j] && ugt(a[i + j], b[i + j]));
5069 }
5070 }
5071 }
5072 }
5073
5074 @Test(dataProvider = "byteCompareOpProvider")
5075 static void ULEByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
5076 byte[] a = fa.apply(SPECIES.length());
5077 byte[] b = fb.apply(SPECIES.length());
5078
5079 for (int ic = 0; ic < INVOC_COUNT; ic++) {
5080 for (int i = 0; i < a.length; i += SPECIES.length()) {
5081 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
5082 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
5083 VectorMask<Byte> mv = av.compare(VectorOperators.ULE, bv);
5084
5085 // Check results as part of computation.
5086 for (int j = 0; j < SPECIES.length(); j++) {
5087 Assert.assertEquals(mv.laneIsSet(j), ule(a[i + j], b[i + j]));
5088 }
5089 }
5090 }
5091 }
5092
5093 @Test(dataProvider = "byteCompareOpMaskProvider")
5094 static void ULEByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
5095 IntFunction<boolean[]> fm) {
5096 byte[] a = fa.apply(SPECIES.length());
5097 byte[] b = fb.apply(SPECIES.length());
5098 boolean[] mask = fm.apply(SPECIES.length());
5099
5100 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
5101
5102 for (int ic = 0; ic < INVOC_COUNT; ic++) {
5103 for (int i = 0; i < a.length; i += SPECIES.length()) {
5104 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
5105 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
5106 VectorMask<Byte> mv = av.compare(VectorOperators.ULE, bv, vmask);
5107
5108 // Check results as part of computation.
5109 for (int j = 0; j < SPECIES.length(); j++) {
5110 Assert.assertEquals(mv.laneIsSet(j), mask[j] && ule(a[i + j], b[i + j]));
5111 }
5112 }
5113 }
5114 }
5115
5116 @Test(dataProvider = "byteCompareOpProvider")
5117 static void UGEByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
5118 byte[] a = fa.apply(SPECIES.length());
5119 byte[] b = fb.apply(SPECIES.length());
5120
5121 for (int ic = 0; ic < INVOC_COUNT; ic++) {
5122 for (int i = 0; i < a.length; i += SPECIES.length()) {
5123 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
5124 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
5125 VectorMask<Byte> mv = av.compare(VectorOperators.UGE, bv);
5126
5127 // Check results as part of computation.
5128 for (int j = 0; j < SPECIES.length(); j++) {
5129 Assert.assertEquals(mv.laneIsSet(j), uge(a[i + j], b[i + j]));
5130 }
5131 }
5132 }
5133 }
5134
5135 @Test(dataProvider = "byteCompareOpMaskProvider")
5136 static void UGEByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
5137 IntFunction<boolean[]> fm) {
5138 byte[] a = fa.apply(SPECIES.length());
5139 byte[] b = fb.apply(SPECIES.length());
5140 boolean[] mask = fm.apply(SPECIES.length());
5141
5142 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
5143
5144 for (int ic = 0; ic < INVOC_COUNT; ic++) {
5145 for (int i = 0; i < a.length; i += SPECIES.length()) {
5146 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
5147 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
5148 VectorMask<Byte> mv = av.compare(VectorOperators.UGE, bv, vmask);
5149
5150 // Check results as part of computation.
5151 for (int j = 0; j < SPECIES.length(); j++) {
5152 Assert.assertEquals(mv.laneIsSet(j), mask[j] && uge(a[i + j], b[i + j]));
5153 }
5154 }
5155 }
5156 }
5157
5158 @Test(dataProvider = "byteCompareOpProvider")
5159 static void LTByteMaxVectorTestsBroadcastSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
5160 byte[] a = fa.apply(SPECIES.length());
5161 byte[] b = fb.apply(SPECIES.length());
5162
5163 for (int i = 0; i < a.length; i += SPECIES.length()) {
5164 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
5165 VectorMask<Byte> mv = av.compare(VectorOperators.LT, b[i]);
5166
5167 // Check results as part of computation.
5168 for (int j = 0; j < SPECIES.length(); j++) {
5169 Assert.assertEquals(mv.laneIsSet(j), a[i + j] < b[i]);
5170 }
5171 }
5172 }
5173
5174 @Test(dataProvider = "byteCompareOpMaskProvider")
5175 static void LTByteMaxVectorTestsBroadcastMaskedSmokeTest(IntFunction<byte[]> fa,
5176 IntFunction<byte[]> fb, IntFunction<boolean[]> fm) {
5177 byte[] a = fa.apply(SPECIES.length());
5178 byte[] b = fb.apply(SPECIES.length());
5179 boolean[] mask = fm.apply(SPECIES.length());
5180
5181 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
5182
5183 for (int i = 0; i < a.length; i += SPECIES.length()) {
5184 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
5185 VectorMask<Byte> mv = av.compare(VectorOperators.LT, b[i], vmask);
5186
5187 // Check results as part of computation.
5188 for (int j = 0; j < SPECIES.length(); j++) {
5189 Assert.assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] < b[i]));
5190 }
5191 }
5192 }
5193
5194 @Test(dataProvider = "byteCompareOpProvider")
5195 static void LTByteMaxVectorTestsBroadcastLongSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
5196 byte[] a = fa.apply(SPECIES.length());
5197 byte[] b = fb.apply(SPECIES.length());
5198
5199 for (int i = 0; i < a.length; i += SPECIES.length()) {
5200 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
5201 VectorMask<Byte> mv = av.compare(VectorOperators.LT, (long)b[i]);
5202
5203 // Check results as part of computation.
5204 for (int j = 0; j < SPECIES.length(); j++) {
5205 Assert.assertEquals(mv.laneIsSet(j), a[i + j] < (byte)((long)b[i]));
5206 }
5207 }
5208 }
5209
5210 @Test(dataProvider = "byteCompareOpMaskProvider")
5211 static void LTByteMaxVectorTestsBroadcastLongMaskedSmokeTest(IntFunction<byte[]> fa,
5212 IntFunction<byte[]> fb, IntFunction<boolean[]> fm) {
5213 byte[] a = fa.apply(SPECIES.length());
5214 byte[] b = fb.apply(SPECIES.length());
5215 boolean[] mask = fm.apply(SPECIES.length());
5216
5217 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
5218
5219 for (int i = 0; i < a.length; i += SPECIES.length()) {
5220 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
5221 VectorMask<Byte> mv = av.compare(VectorOperators.LT, (long)b[i], vmask);
5222
5223 // Check results as part of computation.
5224 for (int j = 0; j < SPECIES.length(); j++) {
5225 Assert.assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] < (byte)((long)b[i])));
5226 }
5227 }
5228 }
5229
5230 @Test(dataProvider = "byteCompareOpProvider")
5231 static void EQByteMaxVectorTestsBroadcastSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
5232 byte[] a = fa.apply(SPECIES.length());
5233 byte[] b = fb.apply(SPECIES.length());
5234
5235 for (int i = 0; i < a.length; i += SPECIES.length()) {
5236 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
5237 VectorMask<Byte> mv = av.compare(VectorOperators.EQ, b[i]);
5238
5239 // Check results as part of computation.
5240 for (int j = 0; j < SPECIES.length(); j++) {
5241 Assert.assertEquals(mv.laneIsSet(j), a[i + j] == b[i]);
5242 }
5243 }
5244 }
5245
5246 @Test(dataProvider = "byteCompareOpMaskProvider")
5247 static void EQByteMaxVectorTestsBroadcastMaskedSmokeTest(IntFunction<byte[]> fa,
5248 IntFunction<byte[]> fb, IntFunction<boolean[]> fm) {
5249 byte[] a = fa.apply(SPECIES.length());
5250 byte[] b = fb.apply(SPECIES.length());
5251 boolean[] mask = fm.apply(SPECIES.length());
5252
5253 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
5254
5255 for (int i = 0; i < a.length; i += SPECIES.length()) {
5256 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
5257 VectorMask<Byte> mv = av.compare(VectorOperators.EQ, b[i], vmask);
5258
5259 // Check results as part of computation.
5260 for (int j = 0; j < SPECIES.length(); j++) {
5261 Assert.assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] == b[i]));
5262 }
5263 }
5264 }
5265
5266 @Test(dataProvider = "byteCompareOpProvider")
5267 static void EQByteMaxVectorTestsBroadcastLongSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
5268 byte[] a = fa.apply(SPECIES.length());
5269 byte[] b = fb.apply(SPECIES.length());
5270
5271 for (int i = 0; i < a.length; i += SPECIES.length()) {
5272 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
5273 VectorMask<Byte> mv = av.compare(VectorOperators.EQ, (long)b[i]);
5274
5275 // Check results as part of computation.
5276 for (int j = 0; j < SPECIES.length(); j++) {
5277 Assert.assertEquals(mv.laneIsSet(j), a[i + j] == (byte)((long)b[i]));
5278 }
5279 }
5280 }
5281
5282 @Test(dataProvider = "byteCompareOpMaskProvider")
5283 static void EQByteMaxVectorTestsBroadcastLongMaskedSmokeTest(IntFunction<byte[]> fa,
5284 IntFunction<byte[]> fb, IntFunction<boolean[]> fm) {
5285 byte[] a = fa.apply(SPECIES.length());
5286 byte[] b = fb.apply(SPECIES.length());
5287 boolean[] mask = fm.apply(SPECIES.length());
5288
5289 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
5290
5291 for (int i = 0; i < a.length; i += SPECIES.length()) {
5292 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
5293 VectorMask<Byte> mv = av.compare(VectorOperators.EQ, (long)b[i], vmask);
5294
5295 // Check results as part of computation.
5296 for (int j = 0; j < SPECIES.length(); j++) {
5297 Assert.assertEquals(mv.laneIsSet(j), mask[j] && (a[i + j] == (byte)((long)b[i])));
5298 }
5299 }
5300 }
5301
5302 static byte blend(byte a, byte b, boolean mask) {
5303 return mask ? b : a;
5304 }
5305
5306 @Test(dataProvider = "byteBinaryOpMaskProvider")
5307 static void blendByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
5308 IntFunction<boolean[]> fm) {
5309 byte[] a = fa.apply(SPECIES.length());
5310 byte[] b = fb.apply(SPECIES.length());
5311 byte[] r = fr.apply(SPECIES.length());
5312 boolean[] mask = fm.apply(SPECIES.length());
5313 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
5314
5315 for (int ic = 0; ic < INVOC_COUNT; ic++) {
5316 for (int i = 0; i < a.length; i += SPECIES.length()) {
5317 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
5318 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
5319 av.blend(bv, vmask).intoArray(r, i);
5320 }
5321 }
5322
5323 assertArraysEquals(r, a, b, mask, ByteMaxVectorTests::blend);
5324 }
5325
5326 @Test(dataProvider = "byteUnaryOpShuffleProvider")
5327 static void RearrangeByteMaxVectorTests(IntFunction<byte[]> fa,
5328 BiFunction<Integer,Integer,int[]> fs) {
5329 byte[] a = fa.apply(SPECIES.length());
5330 int[] order = fs.apply(a.length, SPECIES.length());
5331 byte[] r = fr.apply(SPECIES.length());
5332
5333 for (int ic = 0; ic < INVOC_COUNT; ic++) {
5334 for (int i = 0; i < a.length; i += SPECIES.length()) {
5335 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
5336 av.rearrange(VectorShuffle.fromArray(SPECIES, order, i)).intoArray(r, i);
5337 }
5338 }
5339
5340 assertRearrangeArraysEquals(r, a, order, SPECIES.length());
5341 }
5342
5343 @Test(dataProvider = "byteUnaryOpShuffleMaskProvider")
5344 static void RearrangeByteMaxVectorTestsMaskedSmokeTest(IntFunction<byte[]> fa,
5345 BiFunction<Integer,Integer,int[]> fs,
5346 IntFunction<boolean[]> fm) {
5347 byte[] a = fa.apply(SPECIES.length());
5348 int[] order = fs.apply(a.length, SPECIES.length());
5349 byte[] r = fr.apply(SPECIES.length());
5350 boolean[] mask = fm.apply(SPECIES.length());
5351 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
5352
5353 for (int i = 0; i < a.length; i += SPECIES.length()) {
5354 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
5355 av.rearrange(VectorShuffle.fromArray(SPECIES, order, i), vmask).intoArray(r, i);
5356 }
5357
5358 assertRearrangeArraysEquals(r, a, order, mask, SPECIES.length());
5359 }
5360
5361 @Test(dataProvider = "byteUnaryOpMaskProvider")
5362 static void compressByteMaxVectorTests(IntFunction<byte[]> fa,
5363 IntFunction<boolean[]> fm) {
5364 byte[] a = fa.apply(SPECIES.length());
5365 byte[] r = fr.apply(SPECIES.length());
5366 boolean[] mask = fm.apply(SPECIES.length());
5367 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
5368
5369 for (int ic = 0; ic < INVOC_COUNT; ic++) {
5370 for (int i = 0; i < a.length; i += SPECIES.length()) {
5371 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
5372 av.compress(vmask).intoArray(r, i);
5373 }
5374 }
5375
5376 assertcompressArraysEquals(r, a, mask, SPECIES.length());
5377 }
5378
5379 @Test(dataProvider = "byteUnaryOpMaskProvider")
5380 static void expandByteMaxVectorTests(IntFunction<byte[]> fa,
5381 IntFunction<boolean[]> fm) {
5382 byte[] a = fa.apply(SPECIES.length());
5383 byte[] r = fr.apply(SPECIES.length());
5384 boolean[] mask = fm.apply(SPECIES.length());
5385 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
5386
5387 for (int ic = 0; ic < INVOC_COUNT; ic++) {
5388 for (int i = 0; i < a.length; i += SPECIES.length()) {
5389 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
5390 av.expand(vmask).intoArray(r, i);
5391 }
5392 }
5393
5394 assertexpandArraysEquals(r, a, mask, SPECIES.length());
5395 }
5396
5397 @Test(dataProvider = "byteUnaryOpProvider")
5398 static void getByteMaxVectorTests(IntFunction<byte[]> fa) {
5399 byte[] a = fa.apply(SPECIES.length());
5400 byte[] r = fr.apply(SPECIES.length());
5401
5402 for (int ic = 0; ic < INVOC_COUNT; ic++) {
5403 for (int i = 0; i < a.length; i += SPECIES.length()) {
5404 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
5405 int num_lanes = SPECIES.length();
5406 // Manually unroll because full unroll happens after intrinsification.
5407 // Unroll is needed because get intrinsic requires for index to be a known constant.
5408 if (num_lanes == 1) {
5409 r[i]=av.lane(0);
5410 } else if (num_lanes == 2) {
5411 r[i]=av.lane(0);
5412 r[i+1]=av.lane(1);
5413 } else if (num_lanes == 4) {
5414 r[i]=av.lane(0);
5415 r[i+1]=av.lane(1);
5416 r[i+2]=av.lane(2);
5417 r[i+3]=av.lane(3);
5418 } else if (num_lanes == 8) {
5419 r[i]=av.lane(0);
5420 r[i+1]=av.lane(1);
5421 r[i+2]=av.lane(2);
5422 r[i+3]=av.lane(3);
5423 r[i+4]=av.lane(4);
5424 r[i+5]=av.lane(5);
5425 r[i+6]=av.lane(6);
5426 r[i+7]=av.lane(7);
5427 } else if (num_lanes == 16) {
5428 r[i]=av.lane(0);
5429 r[i+1]=av.lane(1);
5430 r[i+2]=av.lane(2);
5431 r[i+3]=av.lane(3);
5432 r[i+4]=av.lane(4);
5433 r[i+5]=av.lane(5);
5434 r[i+6]=av.lane(6);
5435 r[i+7]=av.lane(7);
5436 r[i+8]=av.lane(8);
5437 r[i+9]=av.lane(9);
5438 r[i+10]=av.lane(10);
5439 r[i+11]=av.lane(11);
5440 r[i+12]=av.lane(12);
5441 r[i+13]=av.lane(13);
5442 r[i+14]=av.lane(14);
5443 r[i+15]=av.lane(15);
5444 } else if (num_lanes == 32) {
5445 r[i]=av.lane(0);
5446 r[i+1]=av.lane(1);
5447 r[i+2]=av.lane(2);
5448 r[i+3]=av.lane(3);
5449 r[i+4]=av.lane(4);
5450 r[i+5]=av.lane(5);
5451 r[i+6]=av.lane(6);
5452 r[i+7]=av.lane(7);
5453 r[i+8]=av.lane(8);
5454 r[i+9]=av.lane(9);
5455 r[i+10]=av.lane(10);
5456 r[i+11]=av.lane(11);
5457 r[i+12]=av.lane(12);
5458 r[i+13]=av.lane(13);
5459 r[i+14]=av.lane(14);
5460 r[i+15]=av.lane(15);
5461 r[i+16]=av.lane(16);
5462 r[i+17]=av.lane(17);
5463 r[i+18]=av.lane(18);
5464 r[i+19]=av.lane(19);
5465 r[i+20]=av.lane(20);
5466 r[i+21]=av.lane(21);
5467 r[i+22]=av.lane(22);
5468 r[i+23]=av.lane(23);
5469 r[i+24]=av.lane(24);
5470 r[i+25]=av.lane(25);
5471 r[i+26]=av.lane(26);
5472 r[i+27]=av.lane(27);
5473 r[i+28]=av.lane(28);
5474 r[i+29]=av.lane(29);
5475 r[i+30]=av.lane(30);
5476 r[i+31]=av.lane(31);
5477 } else if (num_lanes == 64) {
5478 r[i]=av.lane(0);
5479 r[i+1]=av.lane(1);
5480 r[i+2]=av.lane(2);
5481 r[i+3]=av.lane(3);
5482 r[i+4]=av.lane(4);
5483 r[i+5]=av.lane(5);
5484 r[i+6]=av.lane(6);
5485 r[i+7]=av.lane(7);
5486 r[i+8]=av.lane(8);
5487 r[i+9]=av.lane(9);
5488 r[i+10]=av.lane(10);
5489 r[i+11]=av.lane(11);
5490 r[i+12]=av.lane(12);
5491 r[i+13]=av.lane(13);
5492 r[i+14]=av.lane(14);
5493 r[i+15]=av.lane(15);
5494 r[i+16]=av.lane(16);
5495 r[i+17]=av.lane(17);
5496 r[i+18]=av.lane(18);
5497 r[i+19]=av.lane(19);
5498 r[i+20]=av.lane(20);
5499 r[i+21]=av.lane(21);
5500 r[i+22]=av.lane(22);
5501 r[i+23]=av.lane(23);
5502 r[i+24]=av.lane(24);
5503 r[i+25]=av.lane(25);
5504 r[i+26]=av.lane(26);
5505 r[i+27]=av.lane(27);
5506 r[i+28]=av.lane(28);
5507 r[i+29]=av.lane(29);
5508 r[i+30]=av.lane(30);
5509 r[i+31]=av.lane(31);
5510 r[i+32]=av.lane(32);
5511 r[i+33]=av.lane(33);
5512 r[i+34]=av.lane(34);
5513 r[i+35]=av.lane(35);
5514 r[i+36]=av.lane(36);
5515 r[i+37]=av.lane(37);
5516 r[i+38]=av.lane(38);
5517 r[i+39]=av.lane(39);
5518 r[i+40]=av.lane(40);
5519 r[i+41]=av.lane(41);
5520 r[i+42]=av.lane(42);
5521 r[i+43]=av.lane(43);
5522 r[i+44]=av.lane(44);
5523 r[i+45]=av.lane(45);
5524 r[i+46]=av.lane(46);
5525 r[i+47]=av.lane(47);
5526 r[i+48]=av.lane(48);
5527 r[i+49]=av.lane(49);
5528 r[i+50]=av.lane(50);
5529 r[i+51]=av.lane(51);
5530 r[i+52]=av.lane(52);
5531 r[i+53]=av.lane(53);
5532 r[i+54]=av.lane(54);
5533 r[i+55]=av.lane(55);
5534 r[i+56]=av.lane(56);
5535 r[i+57]=av.lane(57);
5536 r[i+58]=av.lane(58);
5537 r[i+59]=av.lane(59);
5538 r[i+60]=av.lane(60);
5539 r[i+61]=av.lane(61);
5540 r[i+62]=av.lane(62);
5541 r[i+63]=av.lane(63);
5542 } else {
5543 for (int j = 0; j < SPECIES.length(); j++) {
5544 r[i+j]=av.lane(j);
5545 }
5546 }
5547 }
5548 }
5549
5550 assertArraysStrictlyEquals(r, a);
5551 }
5552
5553 @Test(dataProvider = "byteUnaryOpProvider")
5554 static void BroadcastByteMaxVectorTests(IntFunction<byte[]> fa) {
5555 byte[] a = fa.apply(SPECIES.length());
5556 byte[] r = new byte[a.length];
5557
5558 for (int ic = 0; ic < INVOC_COUNT; ic++) {
5559 for (int i = 0; i < a.length; i += SPECIES.length()) {
5560 ByteVector.broadcast(SPECIES, a[i]).intoArray(r, i);
5561 }
5562 }
5563
5564 assertBroadcastArraysEquals(r, a);
5565 }
5566
5567 @Test(dataProvider = "byteUnaryOpProvider")
5568 static void ZeroByteMaxVectorTests(IntFunction<byte[]> fa) {
5569 byte[] a = fa.apply(SPECIES.length());
5570 byte[] r = new byte[a.length];
5571
5572 for (int ic = 0; ic < INVOC_COUNT; ic++) {
5573 for (int i = 0; i < a.length; i += SPECIES.length()) {
5574 ByteVector.zero(SPECIES).intoArray(a, i);
5575 }
5576 }
5577
5578 Assert.assertEquals(a, r);
5579 }
5580
5581 static byte[] sliceUnary(byte[] a, int origin, int idx) {
5582 byte[] res = new byte[SPECIES.length()];
5583 for (int i = 0; i < SPECIES.length(); i++){
5584 if(i+origin < SPECIES.length())
5585 res[i] = a[idx+i+origin];
5586 else
5587 res[i] = (byte)0;
5588 }
5589 return res;
5590 }
5591
5592 @Test(dataProvider = "byteUnaryOpProvider")
5593 static void sliceUnaryByteMaxVectorTests(IntFunction<byte[]> fa) {
5594 byte[] a = fa.apply(SPECIES.length());
5595 byte[] r = new byte[a.length];
5596 int origin = RAND.nextInt(SPECIES.length());
5597 for (int ic = 0; ic < INVOC_COUNT; ic++) {
5598 for (int i = 0; i < a.length; i += SPECIES.length()) {
5599 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
5600 av.slice(origin).intoArray(r, i);
5601 }
5602 }
5603
5604 assertArraysEquals(r, a, origin, ByteMaxVectorTests::sliceUnary);
5605 }
5606
5607 static byte[] sliceBinary(byte[] a, byte[] b, int origin, int idx) {
5608 byte[] res = new byte[SPECIES.length()];
5609 for (int i = 0, j = 0; i < SPECIES.length(); i++){
5610 if(i+origin < SPECIES.length())
5611 res[i] = a[idx+i+origin];
5612 else {
5613 res[i] = b[idx+j];
5614 j++;
5615 }
5616 }
5617 return res;
5618 }
5619
5620 @Test(dataProvider = "byteBinaryOpProvider")
5621 static void sliceBinaryByteMaxVectorTestsBinary(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
5622 byte[] a = fa.apply(SPECIES.length());
5623 byte[] b = fb.apply(SPECIES.length());
5624 byte[] r = new byte[a.length];
5625 int origin = RAND.nextInt(SPECIES.length());
5626 for (int ic = 0; ic < INVOC_COUNT; ic++) {
5627 for (int i = 0; i < a.length; i += SPECIES.length()) {
5628 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
5629 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
5630 av.slice(origin, bv).intoArray(r, i);
5631 }
5632 }
5633
5634 assertArraysEquals(r, a, b, origin, ByteMaxVectorTests::sliceBinary);
5635 }
5636
5637 static byte[] slice(byte[] a, byte[] b, int origin, boolean[] mask, int idx) {
5638 byte[] res = new byte[SPECIES.length()];
5639 for (int i = 0, j = 0; i < SPECIES.length(); i++){
5640 if(i+origin < SPECIES.length())
5641 res[i] = mask[i] ? a[idx+i+origin] : (byte)0;
5642 else {
5643 res[i] = mask[i] ? b[idx+j] : (byte)0;
5644 j++;
5645 }
5646 }
5647 return res;
5648 }
5649
5650 @Test(dataProvider = "byteBinaryOpMaskProvider")
5651 static void sliceByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
5652 IntFunction<boolean[]> fm) {
5653 byte[] a = fa.apply(SPECIES.length());
5654 byte[] b = fb.apply(SPECIES.length());
5655 boolean[] mask = fm.apply(SPECIES.length());
5656 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
5657
5658 byte[] r = new byte[a.length];
5659 int origin = RAND.nextInt(SPECIES.length());
5660 for (int ic = 0; ic < INVOC_COUNT; ic++) {
5661 for (int i = 0; i < a.length; i += SPECIES.length()) {
5662 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
5663 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
5664 av.slice(origin, bv, vmask).intoArray(r, i);
5665 }
5666 }
5667
5668 assertArraysEquals(r, a, b, origin, mask, ByteMaxVectorTests::slice);
5669 }
5670
5671 static byte[] unsliceUnary(byte[] a, int origin, int idx) {
5672 byte[] res = new byte[SPECIES.length()];
5673 for (int i = 0, j = 0; i < SPECIES.length(); i++){
5674 if(i < origin)
5675 res[i] = (byte)0;
5676 else {
5677 res[i] = a[idx+j];
5678 j++;
5679 }
5680 }
5681 return res;
5682 }
5683
5684 @Test(dataProvider = "byteUnaryOpProvider")
5685 static void unsliceUnaryByteMaxVectorTests(IntFunction<byte[]> fa) {
5686 byte[] a = fa.apply(SPECIES.length());
5687 byte[] r = new byte[a.length];
5688 int origin = RAND.nextInt(SPECIES.length());
5689 for (int ic = 0; ic < INVOC_COUNT; ic++) {
5690 for (int i = 0; i < a.length; i += SPECIES.length()) {
5691 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
5692 av.unslice(origin).intoArray(r, i);
5693 }
5694 }
5695
5696 assertArraysEquals(r, a, origin, ByteMaxVectorTests::unsliceUnary);
5697 }
5698
5699 static byte[] unsliceBinary(byte[] a, byte[] b, int origin, int part, int idx) {
5700 byte[] res = new byte[SPECIES.length()];
5701 for (int i = 0, j = 0; i < SPECIES.length(); i++){
5702 if (part == 0) {
5703 if (i < origin)
5704 res[i] = b[idx+i];
5705 else {
5706 res[i] = a[idx+j];
5707 j++;
5708 }
5709 } else if (part == 1) {
5710 if (i < origin)
5711 res[i] = a[idx+SPECIES.length()-origin+i];
5712 else {
5713 res[i] = b[idx+origin+j];
5714 j++;
5715 }
5716 }
5717 }
5718 return res;
5719 }
5720
5721 @Test(dataProvider = "byteBinaryOpProvider")
5722 static void unsliceBinaryByteMaxVectorTestsBinary(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
5723 byte[] a = fa.apply(SPECIES.length());
5724 byte[] b = fb.apply(SPECIES.length());
5725 byte[] r = new byte[a.length];
5726 int origin = RAND.nextInt(SPECIES.length());
5727 int part = RAND.nextInt(2);
5728 for (int ic = 0; ic < INVOC_COUNT; ic++) {
5729 for (int i = 0; i < a.length; i += SPECIES.length()) {
5730 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
5731 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
5732 av.unslice(origin, bv, part).intoArray(r, i);
5733 }
5734 }
5735
5736 assertArraysEquals(r, a, b, origin, part, ByteMaxVectorTests::unsliceBinary);
5737 }
5738
5739 static byte[] unslice(byte[] a, byte[] b, int origin, int part, boolean[] mask, int idx) {
5740 byte[] res = new byte[SPECIES.length()];
5741 for (int i = 0, j = 0; i < SPECIES.length(); i++){
5742 if(i+origin < SPECIES.length())
5743 res[i] = b[idx+i+origin];
5744 else {
5745 res[i] = b[idx+j];
5746 j++;
5747 }
5748 }
5749 for (int i = 0; i < SPECIES.length(); i++){
5750 res[i] = mask[i] ? a[idx+i] : res[i];
5751 }
5752 byte[] res1 = new byte[SPECIES.length()];
5753 if (part == 0) {
5754 for (int i = 0, j = 0; i < SPECIES.length(); i++){
5755 if (i < origin)
5756 res1[i] = b[idx+i];
5757 else {
5758 res1[i] = res[j];
5759 j++;
5760 }
5761 }
5762 } else if (part == 1) {
5763 for (int i = 0, j = 0; i < SPECIES.length(); i++){
5764 if (i < origin)
5765 res1[i] = res[SPECIES.length()-origin+i];
5766 else {
5767 res1[i] = b[idx+origin+j];
5768 j++;
5769 }
5770 }
5771 }
5772 return res1;
5773 }
5774
5775 @Test(dataProvider = "byteBinaryOpMaskProvider")
5776 static void unsliceByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
5777 IntFunction<boolean[]> fm) {
5778 byte[] a = fa.apply(SPECIES.length());
5779 byte[] b = fb.apply(SPECIES.length());
5780 boolean[] mask = fm.apply(SPECIES.length());
5781 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
5782 byte[] r = new byte[a.length];
5783 int origin = RAND.nextInt(SPECIES.length());
5784 int part = RAND.nextInt(2);
5785 for (int ic = 0; ic < INVOC_COUNT; ic++) {
5786 for (int i = 0; i < a.length; i += SPECIES.length()) {
5787 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
5788 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
5789 av.unslice(origin, bv, part, vmask).intoArray(r, i);
5790 }
5791 }
5792
5793 assertArraysEquals(r, a, b, origin, part, mask, ByteMaxVectorTests::unslice);
5794 }
5795
5796 static byte BITWISE_BLEND(byte a, byte b, byte c) {
5797 return (byte)((a&~(c))|(b&c));
5798 }
5799
5800 static byte bitwiseBlend(byte a, byte b, byte c) {
5801 return (byte)((a&~(c))|(b&c));
5802 }
5803
5804 @Test(dataProvider = "byteTernaryOpProvider")
5805 static void BITWISE_BLENDByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb, IntFunction<byte[]> fc) {
5806 byte[] a = fa.apply(SPECIES.length());
5807 byte[] b = fb.apply(SPECIES.length());
5808 byte[] c = fc.apply(SPECIES.length());
5809 byte[] r = fr.apply(SPECIES.length());
5810
5811 for (int ic = 0; ic < INVOC_COUNT; ic++) {
5812 for (int i = 0; i < a.length; i += SPECIES.length()) {
5813 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
5814 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
5815 ByteVector cv = ByteVector.fromArray(SPECIES, c, i);
5816 av.lanewise(VectorOperators.BITWISE_BLEND, bv, cv).intoArray(r, i);
5817 }
5818 }
5819
5820 assertArraysEquals(r, a, b, c, ByteMaxVectorTests::BITWISE_BLEND);
5821 }
5822
5823 @Test(dataProvider = "byteTernaryOpProvider")
5824 static void bitwiseBlendByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb, IntFunction<byte[]> fc) {
5825 byte[] a = fa.apply(SPECIES.length());
5826 byte[] b = fb.apply(SPECIES.length());
5827 byte[] c = fc.apply(SPECIES.length());
5828 byte[] r = fr.apply(SPECIES.length());
5829
5830 for (int i = 0; i < a.length; i += SPECIES.length()) {
5831 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
5832 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
5833 ByteVector cv = ByteVector.fromArray(SPECIES, c, i);
5834 av.bitwiseBlend(bv, cv).intoArray(r, i);
5835 }
5836
5837 assertArraysEquals(r, a, b, c, ByteMaxVectorTests::bitwiseBlend);
5838 }
5839
5840 @Test(dataProvider = "byteTernaryOpMaskProvider")
5841 static void BITWISE_BLENDByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
5842 IntFunction<byte[]> fc, IntFunction<boolean[]> fm) {
5843 byte[] a = fa.apply(SPECIES.length());
5844 byte[] b = fb.apply(SPECIES.length());
5845 byte[] c = fc.apply(SPECIES.length());
5846 byte[] r = fr.apply(SPECIES.length());
5847 boolean[] mask = fm.apply(SPECIES.length());
5848 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
5849
5850 for (int ic = 0; ic < INVOC_COUNT; ic++) {
5851 for (int i = 0; i < a.length; i += SPECIES.length()) {
5852 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
5853 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
5854 ByteVector cv = ByteVector.fromArray(SPECIES, c, i);
5855 av.lanewise(VectorOperators.BITWISE_BLEND, bv, cv, vmask).intoArray(r, i);
5856 }
5857 }
5858
5859 assertArraysEquals(r, a, b, c, mask, ByteMaxVectorTests::BITWISE_BLEND);
5860 }
5861
5862 @Test(dataProvider = "byteTernaryOpProvider")
5863 static void BITWISE_BLENDByteMaxVectorTestsBroadcastSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb, IntFunction<byte[]> fc) {
5864 byte[] a = fa.apply(SPECIES.length());
5865 byte[] b = fb.apply(SPECIES.length());
5866 byte[] c = fc.apply(SPECIES.length());
5867 byte[] r = fr.apply(SPECIES.length());
5868
5869 for (int i = 0; i < a.length; i += SPECIES.length()) {
5870 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
5871 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
5872 av.lanewise(VectorOperators.BITWISE_BLEND, bv, c[i]).intoArray(r, i);
5873 }
5874 assertBroadcastArraysEquals(r, a, b, c, ByteMaxVectorTests::BITWISE_BLEND);
5875 }
5876
5877 @Test(dataProvider = "byteTernaryOpProvider")
5878 static void BITWISE_BLENDByteMaxVectorTestsAltBroadcastSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb, IntFunction<byte[]> fc) {
5879 byte[] a = fa.apply(SPECIES.length());
5880 byte[] b = fb.apply(SPECIES.length());
5881 byte[] c = fc.apply(SPECIES.length());
5882 byte[] r = fr.apply(SPECIES.length());
5883
5884 for (int i = 0; i < a.length; i += SPECIES.length()) {
5885 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
5886 ByteVector cv = ByteVector.fromArray(SPECIES, c, i);
5887 av.lanewise(VectorOperators.BITWISE_BLEND, b[i], cv).intoArray(r, i);
5888 }
5889 assertAltBroadcastArraysEquals(r, a, b, c, ByteMaxVectorTests::BITWISE_BLEND);
5890 }
5891
5892 @Test(dataProvider = "byteTernaryOpProvider")
5893 static void bitwiseBlendByteMaxVectorTestsBroadcastSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb, IntFunction<byte[]> fc) {
5894 byte[] a = fa.apply(SPECIES.length());
5895 byte[] b = fb.apply(SPECIES.length());
5896 byte[] c = fc.apply(SPECIES.length());
5897 byte[] r = fr.apply(SPECIES.length());
5898
5899 for (int i = 0; i < a.length; i += SPECIES.length()) {
5900 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
5901 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
5902 av.bitwiseBlend(bv, c[i]).intoArray(r, i);
5903 }
5904 assertBroadcastArraysEquals(r, a, b, c, ByteMaxVectorTests::bitwiseBlend);
5905 }
5906
5907 @Test(dataProvider = "byteTernaryOpProvider")
5908 static void bitwiseBlendByteMaxVectorTestsAltBroadcastSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb, IntFunction<byte[]> fc) {
5909 byte[] a = fa.apply(SPECIES.length());
5910 byte[] b = fb.apply(SPECIES.length());
5911 byte[] c = fc.apply(SPECIES.length());
5912 byte[] r = fr.apply(SPECIES.length());
5913
5914 for (int i = 0; i < a.length; i += SPECIES.length()) {
5915 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
5916 ByteVector cv = ByteVector.fromArray(SPECIES, c, i);
5917 av.bitwiseBlend(b[i], cv).intoArray(r, i);
5918 }
5919 assertAltBroadcastArraysEquals(r, a, b, c, ByteMaxVectorTests::bitwiseBlend);
5920 }
5921
5922 @Test(dataProvider = "byteTernaryOpMaskProvider")
5923 static void BITWISE_BLENDByteMaxVectorTestsBroadcastMaskedSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
5924 IntFunction<byte[]> fc, IntFunction<boolean[]> fm) {
5925 byte[] a = fa.apply(SPECIES.length());
5926 byte[] b = fb.apply(SPECIES.length());
5927 byte[] c = fc.apply(SPECIES.length());
5928 byte[] r = fr.apply(SPECIES.length());
5929 boolean[] mask = fm.apply(SPECIES.length());
5930 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
5931
5932 for (int i = 0; i < a.length; i += SPECIES.length()) {
5933 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
5934 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
5935 av.lanewise(VectorOperators.BITWISE_BLEND, bv, c[i], vmask).intoArray(r, i);
5936 }
5937
5938 assertBroadcastArraysEquals(r, a, b, c, mask, ByteMaxVectorTests::BITWISE_BLEND);
5939 }
5940
5941 @Test(dataProvider = "byteTernaryOpMaskProvider")
5942 static void BITWISE_BLENDByteMaxVectorTestsAltBroadcastMaskedSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
5943 IntFunction<byte[]> fc, IntFunction<boolean[]> fm) {
5944 byte[] a = fa.apply(SPECIES.length());
5945 byte[] b = fb.apply(SPECIES.length());
5946 byte[] c = fc.apply(SPECIES.length());
5947 byte[] r = fr.apply(SPECIES.length());
5948 boolean[] mask = fm.apply(SPECIES.length());
5949 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
5950
5951 for (int i = 0; i < a.length; i += SPECIES.length()) {
5952 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
5953 ByteVector cv = ByteVector.fromArray(SPECIES, c, i);
5954 av.lanewise(VectorOperators.BITWISE_BLEND, b[i], cv, vmask).intoArray(r, i);
5955 }
5956
5957 assertAltBroadcastArraysEquals(r, a, b, c, mask, ByteMaxVectorTests::BITWISE_BLEND);
5958 }
5959
5960 @Test(dataProvider = "byteTernaryOpProvider")
5961 static void BITWISE_BLENDByteMaxVectorTestsDoubleBroadcastSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb, IntFunction<byte[]> fc) {
5962 byte[] a = fa.apply(SPECIES.length());
5963 byte[] b = fb.apply(SPECIES.length());
5964 byte[] c = fc.apply(SPECIES.length());
5965 byte[] r = fr.apply(SPECIES.length());
5966
5967 for (int i = 0; i < a.length; i += SPECIES.length()) {
5968 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
5969 av.lanewise(VectorOperators.BITWISE_BLEND, b[i], c[i]).intoArray(r, i);
5970 }
5971
5972 assertDoubleBroadcastArraysEquals(r, a, b, c, ByteMaxVectorTests::BITWISE_BLEND);
5973 }
5974
5975 @Test(dataProvider = "byteTernaryOpProvider")
5976 static void bitwiseBlendByteMaxVectorTestsDoubleBroadcastSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb, IntFunction<byte[]> fc) {
5977 byte[] a = fa.apply(SPECIES.length());
5978 byte[] b = fb.apply(SPECIES.length());
5979 byte[] c = fc.apply(SPECIES.length());
5980 byte[] r = fr.apply(SPECIES.length());
5981
5982 for (int i = 0; i < a.length; i += SPECIES.length()) {
5983 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
5984 av.bitwiseBlend(b[i], c[i]).intoArray(r, i);
5985 }
5986
5987 assertDoubleBroadcastArraysEquals(r, a, b, c, ByteMaxVectorTests::bitwiseBlend);
5988 }
5989
5990 @Test(dataProvider = "byteTernaryOpMaskProvider")
5991 static void BITWISE_BLENDByteMaxVectorTestsDoubleBroadcastMaskedSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
5992 IntFunction<byte[]> fc, IntFunction<boolean[]> fm) {
5993 byte[] a = fa.apply(SPECIES.length());
5994 byte[] b = fb.apply(SPECIES.length());
5995 byte[] c = fc.apply(SPECIES.length());
5996 byte[] r = fr.apply(SPECIES.length());
5997 boolean[] mask = fm.apply(SPECIES.length());
5998 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
5999
6000 for (int i = 0; i < a.length; i += SPECIES.length()) {
6001 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
6002 av.lanewise(VectorOperators.BITWISE_BLEND, b[i], c[i], vmask).intoArray(r, i);
6003 }
6004
6005 assertDoubleBroadcastArraysEquals(r, a, b, c, mask, ByteMaxVectorTests::BITWISE_BLEND);
6006 }
6007
6008 static byte NEG(byte a) {
6009 return (byte)(-((byte)a));
6010 }
6011
6012 static byte neg(byte a) {
6013 return (byte)(-((byte)a));
6014 }
6015
6016 @Test(dataProvider = "byteUnaryOpProvider")
6017 static void NEGByteMaxVectorTests(IntFunction<byte[]> fa) {
6018 byte[] a = fa.apply(SPECIES.length());
6019 byte[] r = fr.apply(SPECIES.length());
6020
6021 for (int ic = 0; ic < INVOC_COUNT; ic++) {
6022 for (int i = 0; i < a.length; i += SPECIES.length()) {
6023 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
6024 av.lanewise(VectorOperators.NEG).intoArray(r, i);
6025 }
6026 }
6027
6028 assertArraysEquals(r, a, ByteMaxVectorTests::NEG);
6029 }
6030
6031 @Test(dataProvider = "byteUnaryOpProvider")
6032 static void negByteMaxVectorTests(IntFunction<byte[]> fa) {
6033 byte[] a = fa.apply(SPECIES.length());
6034 byte[] r = fr.apply(SPECIES.length());
6035
6036 for (int ic = 0; ic < INVOC_COUNT; ic++) {
6037 for (int i = 0; i < a.length; i += SPECIES.length()) {
6038 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
6039 av.neg().intoArray(r, i);
6040 }
6041 }
6042
6043 assertArraysEquals(r, a, ByteMaxVectorTests::neg);
6044 }
6045
6046 @Test(dataProvider = "byteUnaryOpMaskProvider")
6047 static void NEGMaskedByteMaxVectorTests(IntFunction<byte[]> fa,
6048 IntFunction<boolean[]> fm) {
6049 byte[] a = fa.apply(SPECIES.length());
6050 byte[] r = fr.apply(SPECIES.length());
6051 boolean[] mask = fm.apply(SPECIES.length());
6052 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
6053
6054 for (int ic = 0; ic < INVOC_COUNT; ic++) {
6055 for (int i = 0; i < a.length; i += SPECIES.length()) {
6056 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
6057 av.lanewise(VectorOperators.NEG, vmask).intoArray(r, i);
6058 }
6059 }
6060
6061 assertArraysEquals(r, a, mask, ByteMaxVectorTests::NEG);
6062 }
6063
6064 static byte ABS(byte a) {
6065 return (byte)(Math.abs((byte)a));
6066 }
6067
6068 static byte abs(byte a) {
6069 return (byte)(Math.abs((byte)a));
6070 }
6071
6072 @Test(dataProvider = "byteUnaryOpProvider")
6073 static void ABSByteMaxVectorTests(IntFunction<byte[]> fa) {
6074 byte[] a = fa.apply(SPECIES.length());
6075 byte[] r = fr.apply(SPECIES.length());
6076
6077 for (int ic = 0; ic < INVOC_COUNT; ic++) {
6078 for (int i = 0; i < a.length; i += SPECIES.length()) {
6079 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
6080 av.lanewise(VectorOperators.ABS).intoArray(r, i);
6081 }
6082 }
6083
6084 assertArraysEquals(r, a, ByteMaxVectorTests::ABS);
6085 }
6086
6087 @Test(dataProvider = "byteUnaryOpProvider")
6088 static void absByteMaxVectorTests(IntFunction<byte[]> fa) {
6089 byte[] a = fa.apply(SPECIES.length());
6090 byte[] r = fr.apply(SPECIES.length());
6091
6092 for (int ic = 0; ic < INVOC_COUNT; ic++) {
6093 for (int i = 0; i < a.length; i += SPECIES.length()) {
6094 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
6095 av.abs().intoArray(r, i);
6096 }
6097 }
6098
6099 assertArraysEquals(r, a, ByteMaxVectorTests::abs);
6100 }
6101
6102 @Test(dataProvider = "byteUnaryOpMaskProvider")
6103 static void ABSMaskedByteMaxVectorTests(IntFunction<byte[]> fa,
6104 IntFunction<boolean[]> fm) {
6105 byte[] a = fa.apply(SPECIES.length());
6106 byte[] r = fr.apply(SPECIES.length());
6107 boolean[] mask = fm.apply(SPECIES.length());
6108 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
6109
6110 for (int ic = 0; ic < INVOC_COUNT; ic++) {
6111 for (int i = 0; i < a.length; i += SPECIES.length()) {
6112 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
6113 av.lanewise(VectorOperators.ABS, vmask).intoArray(r, i);
6114 }
6115 }
6116
6117 assertArraysEquals(r, a, mask, ByteMaxVectorTests::ABS);
6118 }
6119
6120 static byte NOT(byte a) {
6121 return (byte)(~((byte)a));
6122 }
6123
6124 static byte not(byte a) {
6125 return (byte)(~((byte)a));
6126 }
6127
6128 @Test(dataProvider = "byteUnaryOpProvider")
6129 static void NOTByteMaxVectorTests(IntFunction<byte[]> fa) {
6130 byte[] a = fa.apply(SPECIES.length());
6131 byte[] r = fr.apply(SPECIES.length());
6132
6133 for (int ic = 0; ic < INVOC_COUNT; ic++) {
6134 for (int i = 0; i < a.length; i += SPECIES.length()) {
6135 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
6136 av.lanewise(VectorOperators.NOT).intoArray(r, i);
6137 }
6138 }
6139
6140 assertArraysEquals(r, a, ByteMaxVectorTests::NOT);
6141 }
6142
6143 @Test(dataProvider = "byteUnaryOpProvider")
6144 static void notByteMaxVectorTests(IntFunction<byte[]> fa) {
6145 byte[] a = fa.apply(SPECIES.length());
6146 byte[] r = fr.apply(SPECIES.length());
6147
6148 for (int ic = 0; ic < INVOC_COUNT; ic++) {
6149 for (int i = 0; i < a.length; i += SPECIES.length()) {
6150 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
6151 av.not().intoArray(r, i);
6152 }
6153 }
6154
6155 assertArraysEquals(r, a, ByteMaxVectorTests::not);
6156 }
6157
6158 @Test(dataProvider = "byteUnaryOpMaskProvider")
6159 static void NOTMaskedByteMaxVectorTests(IntFunction<byte[]> fa,
6160 IntFunction<boolean[]> fm) {
6161 byte[] a = fa.apply(SPECIES.length());
6162 byte[] r = fr.apply(SPECIES.length());
6163 boolean[] mask = fm.apply(SPECIES.length());
6164 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
6165
6166 for (int ic = 0; ic < INVOC_COUNT; ic++) {
6167 for (int i = 0; i < a.length; i += SPECIES.length()) {
6168 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
6169 av.lanewise(VectorOperators.NOT, vmask).intoArray(r, i);
6170 }
6171 }
6172
6173 assertArraysEquals(r, a, mask, ByteMaxVectorTests::NOT);
6174 }
6175
6176 static byte ZOMO(byte a) {
6177 return (byte)((a==0?0:-1));
6178 }
6179
6180 @Test(dataProvider = "byteUnaryOpProvider")
6181 static void ZOMOByteMaxVectorTests(IntFunction<byte[]> fa) {
6182 byte[] a = fa.apply(SPECIES.length());
6183 byte[] r = fr.apply(SPECIES.length());
6184
6185 for (int ic = 0; ic < INVOC_COUNT; ic++) {
6186 for (int i = 0; i < a.length; i += SPECIES.length()) {
6187 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
6188 av.lanewise(VectorOperators.ZOMO).intoArray(r, i);
6189 }
6190 }
6191
6192 assertArraysEquals(r, a, ByteMaxVectorTests::ZOMO);
6193 }
6194
6195 @Test(dataProvider = "byteUnaryOpMaskProvider")
6196 static void ZOMOMaskedByteMaxVectorTests(IntFunction<byte[]> fa,
6197 IntFunction<boolean[]> fm) {
6198 byte[] a = fa.apply(SPECIES.length());
6199 byte[] r = fr.apply(SPECIES.length());
6200 boolean[] mask = fm.apply(SPECIES.length());
6201 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
6202
6203 for (int ic = 0; ic < INVOC_COUNT; ic++) {
6204 for (int i = 0; i < a.length; i += SPECIES.length()) {
6205 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
6206 av.lanewise(VectorOperators.ZOMO, vmask).intoArray(r, i);
6207 }
6208 }
6209
6210 assertArraysEquals(r, a, mask, ByteMaxVectorTests::ZOMO);
6211 }
6212
6213 static byte BIT_COUNT(byte a) {
6214 return (byte)(Integer.bitCount((int)a & 0xFF));
6215 }
6216
6217 @Test(dataProvider = "byteUnaryOpProvider")
6218 static void BIT_COUNTByteMaxVectorTests(IntFunction<byte[]> fa) {
6219 byte[] a = fa.apply(SPECIES.length());
6220 byte[] r = fr.apply(SPECIES.length());
6221
6222 for (int ic = 0; ic < INVOC_COUNT; ic++) {
6223 for (int i = 0; i < a.length; i += SPECIES.length()) {
6224 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
6225 av.lanewise(VectorOperators.BIT_COUNT).intoArray(r, i);
6226 }
6227 }
6228
6229 assertArraysEquals(r, a, ByteMaxVectorTests::BIT_COUNT);
6230 }
6231
6232 @Test(dataProvider = "byteUnaryOpMaskProvider")
6233 static void BIT_COUNTMaskedByteMaxVectorTests(IntFunction<byte[]> fa,
6234 IntFunction<boolean[]> fm) {
6235 byte[] a = fa.apply(SPECIES.length());
6236 byte[] r = fr.apply(SPECIES.length());
6237 boolean[] mask = fm.apply(SPECIES.length());
6238 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
6239
6240 for (int ic = 0; ic < INVOC_COUNT; ic++) {
6241 for (int i = 0; i < a.length; i += SPECIES.length()) {
6242 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
6243 av.lanewise(VectorOperators.BIT_COUNT, vmask).intoArray(r, i);
6244 }
6245 }
6246
6247 assertArraysEquals(r, a, mask, ByteMaxVectorTests::BIT_COUNT);
6248 }
6249
6250 static byte TRAILING_ZEROS_COUNT(byte a) {
6251 return (byte)(TRAILING_ZEROS_COUNT_scalar(a));
6252 }
6253
6254 @Test(dataProvider = "byteUnaryOpProvider")
6255 static void TRAILING_ZEROS_COUNTByteMaxVectorTests(IntFunction<byte[]> fa) {
6256 byte[] a = fa.apply(SPECIES.length());
6257 byte[] r = fr.apply(SPECIES.length());
6258
6259 for (int ic = 0; ic < INVOC_COUNT; ic++) {
6260 for (int i = 0; i < a.length; i += SPECIES.length()) {
6261 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
6262 av.lanewise(VectorOperators.TRAILING_ZEROS_COUNT).intoArray(r, i);
6263 }
6264 }
6265
6266 assertArraysEquals(r, a, ByteMaxVectorTests::TRAILING_ZEROS_COUNT);
6267 }
6268
6269 @Test(dataProvider = "byteUnaryOpMaskProvider")
6270 static void TRAILING_ZEROS_COUNTMaskedByteMaxVectorTests(IntFunction<byte[]> fa,
6271 IntFunction<boolean[]> fm) {
6272 byte[] a = fa.apply(SPECIES.length());
6273 byte[] r = fr.apply(SPECIES.length());
6274 boolean[] mask = fm.apply(SPECIES.length());
6275 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
6276
6277 for (int ic = 0; ic < INVOC_COUNT; ic++) {
6278 for (int i = 0; i < a.length; i += SPECIES.length()) {
6279 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
6280 av.lanewise(VectorOperators.TRAILING_ZEROS_COUNT, vmask).intoArray(r, i);
6281 }
6282 }
6283
6284 assertArraysEquals(r, a, mask, ByteMaxVectorTests::TRAILING_ZEROS_COUNT);
6285 }
6286
6287 static byte LEADING_ZEROS_COUNT(byte a) {
6288 return (byte)(LEADING_ZEROS_COUNT_scalar(a));
6289 }
6290
6291 @Test(dataProvider = "byteUnaryOpProvider")
6292 static void LEADING_ZEROS_COUNTByteMaxVectorTests(IntFunction<byte[]> fa) {
6293 byte[] a = fa.apply(SPECIES.length());
6294 byte[] r = fr.apply(SPECIES.length());
6295
6296 for (int ic = 0; ic < INVOC_COUNT; ic++) {
6297 for (int i = 0; i < a.length; i += SPECIES.length()) {
6298 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
6299 av.lanewise(VectorOperators.LEADING_ZEROS_COUNT).intoArray(r, i);
6300 }
6301 }
6302
6303 assertArraysEquals(r, a, ByteMaxVectorTests::LEADING_ZEROS_COUNT);
6304 }
6305
6306 @Test(dataProvider = "byteUnaryOpMaskProvider")
6307 static void LEADING_ZEROS_COUNTMaskedByteMaxVectorTests(IntFunction<byte[]> fa,
6308 IntFunction<boolean[]> fm) {
6309 byte[] a = fa.apply(SPECIES.length());
6310 byte[] r = fr.apply(SPECIES.length());
6311 boolean[] mask = fm.apply(SPECIES.length());
6312 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
6313
6314 for (int ic = 0; ic < INVOC_COUNT; ic++) {
6315 for (int i = 0; i < a.length; i += SPECIES.length()) {
6316 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
6317 av.lanewise(VectorOperators.LEADING_ZEROS_COUNT, vmask).intoArray(r, i);
6318 }
6319 }
6320
6321 assertArraysEquals(r, a, mask, ByteMaxVectorTests::LEADING_ZEROS_COUNT);
6322 }
6323
6324 static byte REVERSE(byte a) {
6325 return (byte)(REVERSE_scalar(a));
6326 }
6327
6328 @Test(dataProvider = "byteUnaryOpProvider")
6329 static void REVERSEByteMaxVectorTests(IntFunction<byte[]> fa) {
6330 byte[] a = fa.apply(SPECIES.length());
6331 byte[] r = fr.apply(SPECIES.length());
6332
6333 for (int ic = 0; ic < INVOC_COUNT; ic++) {
6334 for (int i = 0; i < a.length; i += SPECIES.length()) {
6335 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
6336 av.lanewise(VectorOperators.REVERSE).intoArray(r, i);
6337 }
6338 }
6339
6340 assertArraysEquals(r, a, ByteMaxVectorTests::REVERSE);
6341 }
6342
6343 @Test(dataProvider = "byteUnaryOpMaskProvider")
6344 static void REVERSEMaskedByteMaxVectorTests(IntFunction<byte[]> fa,
6345 IntFunction<boolean[]> fm) {
6346 byte[] a = fa.apply(SPECIES.length());
6347 byte[] r = fr.apply(SPECIES.length());
6348 boolean[] mask = fm.apply(SPECIES.length());
6349 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
6350
6351 for (int ic = 0; ic < INVOC_COUNT; ic++) {
6352 for (int i = 0; i < a.length; i += SPECIES.length()) {
6353 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
6354 av.lanewise(VectorOperators.REVERSE, vmask).intoArray(r, i);
6355 }
6356 }
6357
6358 assertArraysEquals(r, a, mask, ByteMaxVectorTests::REVERSE);
6359 }
6360
6361 static byte REVERSE_BYTES(byte a) {
6362 return (byte)(a);
6363 }
6364
6365 @Test(dataProvider = "byteUnaryOpProvider")
6366 static void REVERSE_BYTESByteMaxVectorTests(IntFunction<byte[]> fa) {
6367 byte[] a = fa.apply(SPECIES.length());
6368 byte[] r = fr.apply(SPECIES.length());
6369
6370 for (int ic = 0; ic < INVOC_COUNT; ic++) {
6371 for (int i = 0; i < a.length; i += SPECIES.length()) {
6372 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
6373 av.lanewise(VectorOperators.REVERSE_BYTES).intoArray(r, i);
6374 }
6375 }
6376
6377 assertArraysEquals(r, a, ByteMaxVectorTests::REVERSE_BYTES);
6378 }
6379
6380 @Test(dataProvider = "byteUnaryOpMaskProvider")
6381 static void REVERSE_BYTESMaskedByteMaxVectorTests(IntFunction<byte[]> fa,
6382 IntFunction<boolean[]> fm) {
6383 byte[] a = fa.apply(SPECIES.length());
6384 byte[] r = fr.apply(SPECIES.length());
6385 boolean[] mask = fm.apply(SPECIES.length());
6386 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
6387
6388 for (int ic = 0; ic < INVOC_COUNT; ic++) {
6389 for (int i = 0; i < a.length; i += SPECIES.length()) {
6390 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
6391 av.lanewise(VectorOperators.REVERSE_BYTES, vmask).intoArray(r, i);
6392 }
6393 }
6394
6395 assertArraysEquals(r, a, mask, ByteMaxVectorTests::REVERSE_BYTES);
6396 }
6397
6398 @Test(dataProvider = "byteCompareOpProvider")
6399 static void ltByteMaxVectorTestsBroadcastSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
6400 byte[] a = fa.apply(SPECIES.length());
6401 byte[] b = fb.apply(SPECIES.length());
6402
6403 for (int i = 0; i < a.length; i += SPECIES.length()) {
6404 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
6405 VectorMask<Byte> mv = av.lt(b[i]);
6406
6407 // Check results as part of computation.
6408 for (int j = 0; j < SPECIES.length(); j++) {
6409 Assert.assertEquals(mv.laneIsSet(j), a[i + j] < b[i]);
6410 }
6411 }
6412 }
6413
6414 @Test(dataProvider = "byteCompareOpProvider")
6415 static void eqByteMaxVectorTestsBroadcastMaskedSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
6416 byte[] a = fa.apply(SPECIES.length());
6417 byte[] b = fb.apply(SPECIES.length());
6418
6419 for (int i = 0; i < a.length; i += SPECIES.length()) {
6420 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
6421 VectorMask<Byte> mv = av.eq(b[i]);
6422
6423 // Check results as part of computation.
6424 for (int j = 0; j < SPECIES.length(); j++) {
6425 Assert.assertEquals(mv.laneIsSet(j), a[i + j] == b[i]);
6426 }
6427 }
6428 }
6429
6430 @Test(dataProvider = "byteUnaryOpProvider")
6431 static void toIntArrayByteMaxVectorTestsSmokeTest(IntFunction<byte[]> fa) {
6432 byte[] a = fa.apply(SPECIES.length());
6433
6434 for (int i = 0; i < a.length; i += SPECIES.length()) {
6435 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
6436 int[] r = av.toIntArray();
6437 assertArraysEquals(r, a, i);
6438 }
6439 }
6440
6441 @Test(dataProvider = "byteUnaryOpProvider")
6442 static void toLongArrayByteMaxVectorTestsSmokeTest(IntFunction<byte[]> fa) {
6443 byte[] a = fa.apply(SPECIES.length());
6444
6445 for (int i = 0; i < a.length; i += SPECIES.length()) {
6446 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
6447 long[] r = av.toLongArray();
6448 assertArraysEquals(r, a, i);
6449 }
6450 }
6451
6452 @Test(dataProvider = "byteUnaryOpProvider")
6453 static void toDoubleArrayByteMaxVectorTestsSmokeTest(IntFunction<byte[]> fa) {
6454 byte[] a = fa.apply(SPECIES.length());
6455
6456 for (int i = 0; i < a.length; i += SPECIES.length()) {
6457 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
6458 double[] r = av.toDoubleArray();
6459 assertArraysEquals(r, a, i);
6460 }
6461 }
6462
6463 @Test(dataProvider = "byteUnaryOpProvider")
6464 static void toStringByteMaxVectorTestsSmokeTest(IntFunction<byte[]> fa) {
6465 byte[] a = fa.apply(SPECIES.length());
6466
6467 for (int i = 0; i < a.length; i += SPECIES.length()) {
6468 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
6469 String str = av.toString();
6470
6471 byte subarr[] = Arrays.copyOfRange(a, i, i + SPECIES.length());
6472 Assert.assertTrue(str.equals(Arrays.toString(subarr)), "at index " + i + ", string should be = " + Arrays.toString(subarr) + ", but is = " + str);
6473 }
6474 }
6475
6476 @Test(dataProvider = "byteUnaryOpProvider")
6477 static void hashCodeByteMaxVectorTestsSmokeTest(IntFunction<byte[]> fa) {
6478 byte[] a = fa.apply(SPECIES.length());
6479
6480 for (int i = 0; i < a.length; i += SPECIES.length()) {
6481 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
6482 int hash = av.hashCode();
6483
6484 byte subarr[] = Arrays.copyOfRange(a, i, i + SPECIES.length());
6485 int expectedHash = Objects.hash(SPECIES, Arrays.hashCode(subarr));
6486 Assert.assertTrue(hash == expectedHash, "at index " + i + ", hash should be = " + expectedHash + ", but is = " + hash);
6487 }
6488 }
6489
6490 @Test(dataProvider = "byteUnaryOpProvider")
6491 static void reinterpretAsBytesByteMaxVectorTestsSmokeTest(IntFunction<byte[]> fa) {
6492 byte[] a = fa.apply(SPECIES.length());
6493 byte[] r = new byte[a.length];
6494
6495 for (int i = 0; i < a.length; i += SPECIES.length()) {
6496 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
6497 av.reinterpretAsBytes().intoArray(r, i);
6498 }
6499 assertArraysEquals(r, a, 0);
6500 }
6501
6502 static long ADDReduceLong(byte[] a, int idx) {
6503 byte res = 0;
6504 for (int i = idx; i < (idx + SPECIES.length()); i++) {
6505 res += a[i];
6506 }
6507
6508 return (long)res;
6509 }
6510
6511 static long ADDReduceAllLong(byte[] a) {
6512 long res = 0;
6513 for (int i = 0; i < a.length; i += SPECIES.length()) {
6514 res += ADDReduceLong(a, i);
6515 }
6516
6517 return res;
6518 }
6519
6520 @Test(dataProvider = "byteUnaryOpProvider")
6521 static void ADDReduceLongByteMaxVectorTests(IntFunction<byte[]> fa) {
6522 byte[] a = fa.apply(SPECIES.length());
6523 long[] r = lfr.apply(SPECIES.length());
6524 long ra = 0;
6525
6526 for (int i = 0; i < a.length; i += SPECIES.length()) {
6527 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
6528 r[i] = av.reduceLanesToLong(VectorOperators.ADD);
6529 }
6530
6531 ra = 0;
6532 for (int i = 0; i < a.length; i ++) {
6533 ra += r[i];
6534 }
6535
6536 assertReductionLongArraysEquals(r, ra, a,
6537 ByteMaxVectorTests::ADDReduceLong, ByteMaxVectorTests::ADDReduceAllLong);
6538 }
6539
6540 static long ADDReduceLongMasked(byte[] a, int idx, boolean[] mask) {
6541 byte res = 0;
6542 for (int i = idx; i < (idx + SPECIES.length()); i++) {
6543 if(mask[i % SPECIES.length()])
6544 res += a[i];
6545 }
6546
6547 return (long)res;
6548 }
6549
6550 static long ADDReduceAllLongMasked(byte[] a, boolean[] mask) {
6551 long res = 0;
6552 for (int i = 0; i < a.length; i += SPECIES.length()) {
6553 res += ADDReduceLongMasked(a, i, mask);
6554 }
6555
6556 return res;
6557 }
6558
6559 @Test(dataProvider = "byteUnaryOpMaskProvider")
6560 static void ADDReduceLongByteMaxVectorTestsMasked(IntFunction<byte[]> fa, IntFunction<boolean[]> fm) {
6561 byte[] a = fa.apply(SPECIES.length());
6562 long[] r = lfr.apply(SPECIES.length());
6563 boolean[] mask = fm.apply(SPECIES.length());
6564 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
6565 long ra = 0;
6566
6567 for (int i = 0; i < a.length; i += SPECIES.length()) {
6568 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
6569 r[i] = av.reduceLanesToLong(VectorOperators.ADD, vmask);
6570 }
6571
6572 ra = 0;
6573 for (int i = 0; i < a.length; i ++) {
6574 ra += r[i];
6575 }
6576
6577 assertReductionLongArraysEqualsMasked(r, ra, a, mask,
6578 ByteMaxVectorTests::ADDReduceLongMasked, ByteMaxVectorTests::ADDReduceAllLongMasked);
6579 }
6580
6581 @Test(dataProvider = "byteUnaryOpProvider")
6582 static void BroadcastLongByteMaxVectorTestsSmokeTest(IntFunction<byte[]> fa) {
6583 byte[] a = fa.apply(SPECIES.length());
6584 byte[] r = new byte[a.length];
6585
6586 for (int i = 0; i < a.length; i += SPECIES.length()) {
6587 ByteVector.broadcast(SPECIES, (long)a[i]).intoArray(r, i);
6588 }
6589 assertBroadcastArraysEquals(r, a);
6590 }
6591
6592 @Test(dataProvider = "byteBinaryOpMaskProvider")
6593 static void blendByteMaxVectorTestsBroadcastLongSmokeTest(IntFunction<byte[]> fa, IntFunction<byte[]> fb,
6594 IntFunction<boolean[]> fm) {
6595 byte[] a = fa.apply(SPECIES.length());
6596 byte[] b = fb.apply(SPECIES.length());
6597 byte[] r = fr.apply(SPECIES.length());
6598 boolean[] mask = fm.apply(SPECIES.length());
6599 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
6600
6601 for (int ic = 0; ic < INVOC_COUNT; ic++) {
6602 for (int i = 0; i < a.length; i += SPECIES.length()) {
6603 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
6604 av.blend((long)b[i], vmask).intoArray(r, i);
6605 }
6606 }
6607 assertBroadcastLongArraysEquals(r, a, b, mask, ByteMaxVectorTests::blend);
6608 }
6609
6610
6611 @Test(dataProvider = "byteUnaryOpSelectFromProvider")
6612 static void SelectFromByteMaxVectorTests(IntFunction<byte[]> fa,
6613 BiFunction<Integer,Integer,byte[]> fs) {
6614 byte[] a = fa.apply(SPECIES.length());
6615 byte[] order = fs.apply(a.length, SPECIES.length());
6616 byte[] r = fr.apply(SPECIES.length());
6617
6618 for (int i = 0; i < a.length; i += SPECIES.length()) {
6619 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
6620 ByteVector bv = ByteVector.fromArray(SPECIES, order, i);
6621 bv.selectFrom(av).intoArray(r, i);
6622 }
6623
6624 assertSelectFromArraysEquals(r, a, order, SPECIES.length());
6625 }
6626
6627 @Test(dataProvider = "byteSelectFromTwoVectorOpProvider")
6628 static void SelectFromTwoVectorByteMaxVectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb, IntFunction<byte[]> fc) {
6629 byte[] a = fa.apply(SPECIES.length());
6630 byte[] b = fb.apply(SPECIES.length());
6631 byte[] idx = fc.apply(SPECIES.length());
6632 byte[] r = fr.apply(SPECIES.length());
6633
6634 for (int ic = 0; ic < INVOC_COUNT; ic++) {
6635 for (int i = 0; i < idx.length; i += SPECIES.length()) {
6636 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
6637 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
6638 ByteVector idxv = ByteVector.fromArray(SPECIES, idx, i);
6639 idxv.selectFrom(av, bv).intoArray(r, i);
6640 }
6641 }
6642 assertSelectFromTwoVectorEquals(r, idx, a, b, SPECIES.length());
6643 }
6644
6645 @Test(dataProvider = "byteUnaryOpSelectFromMaskProvider")
6646 static void SelectFromByteMaxVectorTestsMaskedSmokeTest(IntFunction<byte[]> fa,
6647 BiFunction<Integer,Integer,byte[]> fs,
6648 IntFunction<boolean[]> fm) {
6649 byte[] a = fa.apply(SPECIES.length());
6650 byte[] order = fs.apply(a.length, SPECIES.length());
6651 byte[] r = fr.apply(SPECIES.length());
6652 boolean[] mask = fm.apply(SPECIES.length());
6653 VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
6654
6655 for (int i = 0; i < a.length; i += SPECIES.length()) {
6656 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
6657 ByteVector bv = ByteVector.fromArray(SPECIES, order, i);
6658 bv.selectFrom(av, vmask).intoArray(r, i);
6659 }
6660
6661 assertSelectFromArraysEquals(r, a, order, mask, SPECIES.length());
6662 }
6663
6664 @Test(dataProvider = "shuffleProvider")
6665 static void shuffleMiscellaneousByteMaxVectorTestsSmokeTest(BiFunction<Integer,Integer,int[]> fs) {
6666 int[] a = fs.apply(SPECIES.length() * BUFFER_REPS, SPECIES.length());
6667
6668 for (int i = 0; i < a.length; i += SPECIES.length()) {
6669 var shuffle = VectorShuffle.fromArray(SPECIES, a, i);
6670 int hash = shuffle.hashCode();
6671 int length = shuffle.length();
6672
6673 int subarr[] = Arrays.copyOfRange(a, i, i + SPECIES.length());
6674 int expectedHash = Objects.hash(SPECIES, Arrays.hashCode(subarr));
6675 Assert.assertTrue(hash == expectedHash, "at index " + i + ", hash should be = " + expectedHash + ", but is = " + hash);
6676 Assert.assertEquals(length, SPECIES.length());
6677 }
6678 }
6679
6680 @Test(dataProvider = "shuffleProvider")
6681 static void shuffleToStringByteMaxVectorTestsSmokeTest(BiFunction<Integer,Integer,int[]> fs) {
6682 int[] a = fs.apply(SPECIES.length() * BUFFER_REPS, SPECIES.length());
6683
6684 for (int i = 0; i < a.length; i += SPECIES.length()) {
6685 var shuffle = VectorShuffle.fromArray(SPECIES, a, i);
6686 String str = shuffle.toString();
6687
6688 int subarr[] = Arrays.copyOfRange(a, i, i + SPECIES.length());
6689 Assert.assertTrue(str.equals("Shuffle" + Arrays.toString(subarr)), "at index " +
6690 i + ", string should be = " + Arrays.toString(subarr) + ", but is = " + str);
6691 }
6692 }
6693
6694 @Test(dataProvider = "shuffleCompareOpProvider")
6695 static void shuffleEqualsByteMaxVectorTestsSmokeTest(BiFunction<Integer,Integer,int[]> fa, BiFunction<Integer,Integer,int[]> fb) {
6696 int[] a = fa.apply(SPECIES.length() * BUFFER_REPS, SPECIES.length());
6697 int[] b = fb.apply(SPECIES.length() * BUFFER_REPS, SPECIES.length());
6698
6699 for (int i = 0; i < a.length; i += SPECIES.length()) {
6700 var av = VectorShuffle.fromArray(SPECIES, a, i);
6701 var bv = VectorShuffle.fromArray(SPECIES, b, i);
6702 boolean eq = av.equals(bv);
6703 int to = i + SPECIES.length();
6704 Assert.assertEquals(eq, Arrays.equals(a, i, to, b, i, to));
6705 }
6706 }
6707
6708 @Test(dataProvider = "maskCompareOpProvider")
6709 static void maskEqualsByteMaxVectorTestsSmokeTest(IntFunction<boolean[]> fa, IntFunction<boolean[]> fb) {
6710 boolean[] a = fa.apply(SPECIES.length());
6711 boolean[] b = fb.apply(SPECIES.length());
6712
6713 for (int i = 0; i < a.length; i += SPECIES.length()) {
6714 var av = SPECIES.loadMask(a, i);
6715 var bv = SPECIES.loadMask(b, i);
6716 boolean equals = av.equals(bv);
6717 int to = i + SPECIES.length();
6718 Assert.assertEquals(equals, Arrays.equals(a, i, to, b, i, to));
6719 }
6720 }
6721
6722 static boolean band(boolean a, boolean b) {
6723 return a & b;
6724 }
6725
6726 @Test(dataProvider = "maskCompareOpProvider")
6727 static void maskAndByteMaxVectorTestsSmokeTest(IntFunction<boolean[]> fa, IntFunction<boolean[]> fb) {
6728 boolean[] a = fa.apply(SPECIES.length());
6729 boolean[] b = fb.apply(SPECIES.length());
6730 boolean[] r = new boolean[a.length];
6731
6732 for (int i = 0; i < a.length; i += SPECIES.length()) {
6733 var av = SPECIES.loadMask(a, i);
6734 var bv = SPECIES.loadMask(b, i);
6735 var cv = av.and(bv);
6736 cv.intoArray(r, i);
6737 }
6738 assertArraysEquals(r, a, b, ByteMaxVectorTests::band);
6739 }
6740
6741 static boolean bor(boolean a, boolean b) {
6742 return a | b;
6743 }
6744
6745 @Test(dataProvider = "maskCompareOpProvider")
6746 static void maskOrByteMaxVectorTestsSmokeTest(IntFunction<boolean[]> fa, IntFunction<boolean[]> fb) {
6747 boolean[] a = fa.apply(SPECIES.length());
6748 boolean[] b = fb.apply(SPECIES.length());
6749 boolean[] r = new boolean[a.length];
6750
6751 for (int i = 0; i < a.length; i += SPECIES.length()) {
6752 var av = SPECIES.loadMask(a, i);
6753 var bv = SPECIES.loadMask(b, i);
6754 var cv = av.or(bv);
6755 cv.intoArray(r, i);
6756 }
6757 assertArraysEquals(r, a, b, ByteMaxVectorTests::bor);
6758 }
6759
6760 static boolean bxor(boolean a, boolean b) {
6761 return a != b;
6762 }
6763
6764 @Test(dataProvider = "maskCompareOpProvider")
6765 static void maskXorByteMaxVectorTestsSmokeTest(IntFunction<boolean[]> fa, IntFunction<boolean[]> fb) {
6766 boolean[] a = fa.apply(SPECIES.length());
6767 boolean[] b = fb.apply(SPECIES.length());
6768 boolean[] r = new boolean[a.length];
6769
6770 for (int i = 0; i < a.length; i += SPECIES.length()) {
6771 var av = SPECIES.loadMask(a, i);
6772 var bv = SPECIES.loadMask(b, i);
6773 var cv = av.xor(bv);
6774 cv.intoArray(r, i);
6775 }
6776 assertArraysEquals(r, a, b, ByteMaxVectorTests::bxor);
6777 }
6778
6779 static boolean bandNot(boolean a, boolean b) {
6780 return a & !b;
6781 }
6782
6783 @Test(dataProvider = "maskCompareOpProvider")
6784 static void maskAndNotByteMaxVectorTestsSmokeTest(IntFunction<boolean[]> fa, IntFunction<boolean[]> fb) {
6785 boolean[] a = fa.apply(SPECIES.length());
6786 boolean[] b = fb.apply(SPECIES.length());
6787 boolean[] r = new boolean[a.length];
6788
6789 for (int i = 0; i < a.length; i += SPECIES.length()) {
6790 var av = SPECIES.loadMask(a, i);
6791 var bv = SPECIES.loadMask(b, i);
6792 var cv = av.andNot(bv);
6793 cv.intoArray(r, i);
6794 }
6795 assertArraysEquals(r, a, b, ByteMaxVectorTests::bandNot);
6796 }
6797
6798 static boolean beq(boolean a, boolean b) {
6799 return (a == b);
6800 }
6801
6802 @Test(dataProvider = "maskCompareOpProvider")
6803 static void maskEqByteMaxVectorTestsSmokeTest(IntFunction<boolean[]> fa, IntFunction<boolean[]> fb) {
6804 boolean[] a = fa.apply(SPECIES.length());
6805 boolean[] b = fb.apply(SPECIES.length());
6806 boolean[] r = new boolean[a.length];
6807
6808 for (int i = 0; i < a.length; i += SPECIES.length()) {
6809 var av = SPECIES.loadMask(a, i);
6810 var bv = SPECIES.loadMask(b, i);
6811 var cv = av.eq(bv);
6812 cv.intoArray(r, i);
6813 }
6814 assertArraysEquals(r, a, b, ByteMaxVectorTests::beq);
6815 }
6816
6817 @Test(dataProvider = "maskProvider")
6818 static void maskHashCodeByteMaxVectorTestsSmokeTest(IntFunction<boolean[]> fa) {
6819 boolean[] a = fa.apply(SPECIES.length());
6820
6821 for (int i = 0; i < a.length; i += SPECIES.length()) {
6822 var vmask = SPECIES.loadMask(a, i);
6823 int hash = vmask.hashCode();
6824
6825 boolean subarr[] = Arrays.copyOfRange(a, i, i + SPECIES.length());
6826 int expectedHash = Objects.hash(SPECIES, Arrays.hashCode(subarr));
6827 Assert.assertTrue(hash == expectedHash, "at index " + i + ", hash should be = " + expectedHash + ", but is = " + hash);
6828 }
6829 }
6830
6831 static int maskTrueCount(boolean[] a, int idx) {
6832 int trueCount = 0;
6833 for (int i = idx; i < idx + SPECIES.length(); i++) {
6834 trueCount += a[i] ? 1 : 0;
6835 }
6836 return trueCount;
6837 }
6838
6839 @Test(dataProvider = "maskProvider")
6840 static void maskTrueCountByteMaxVectorTestsSmokeTest(IntFunction<boolean[]> fa) {
6841 boolean[] a = fa.apply(SPECIES.length());
6842 int[] r = new int[a.length];
6843
6844 for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) {
6845 for (int i = 0; i < a.length; i += SPECIES.length()) {
6846 var vmask = SPECIES.loadMask(a, i);
6847 r[i] = vmask.trueCount();
6848 }
6849 }
6850
6851 assertMaskReductionArraysEquals(r, a, ByteMaxVectorTests::maskTrueCount);
6852 }
6853
6854 static int maskLastTrue(boolean[] a, int idx) {
6855 int i = idx + SPECIES.length() - 1;
6856 for (; i >= idx; i--) {
6857 if (a[i]) {
6858 break;
6859 }
6860 }
6861 return i - idx;
6862 }
6863
6864 @Test(dataProvider = "maskProvider")
6865 static void maskLastTrueByteMaxVectorTestsSmokeTest(IntFunction<boolean[]> fa) {
6866 boolean[] a = fa.apply(SPECIES.length());
6867 int[] r = new int[a.length];
6868
6869 for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) {
6870 for (int i = 0; i < a.length; i += SPECIES.length()) {
6871 var vmask = SPECIES.loadMask(a, i);
6872 r[i] = vmask.lastTrue();
6873 }
6874 }
6875
6876 assertMaskReductionArraysEquals(r, a, ByteMaxVectorTests::maskLastTrue);
6877 }
6878
6879 static int maskFirstTrue(boolean[] a, int idx) {
6880 int i = idx;
6881 for (; i < idx + SPECIES.length(); i++) {
6882 if (a[i]) {
6883 break;
6884 }
6885 }
6886 return i - idx;
6887 }
6888
6889 @Test(dataProvider = "maskProvider")
6890 static void maskFirstTrueByteMaxVectorTestsSmokeTest(IntFunction<boolean[]> fa) {
6891 boolean[] a = fa.apply(SPECIES.length());
6892 int[] r = new int[a.length];
6893
6894 for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) {
6895 for (int i = 0; i < a.length; i += SPECIES.length()) {
6896 var vmask = SPECIES.loadMask(a, i);
6897 r[i] = vmask.firstTrue();
6898 }
6899 }
6900
6901 assertMaskReductionArraysEquals(r, a, ByteMaxVectorTests::maskFirstTrue);
6902 }
6903
6904 @Test(dataProvider = "maskProvider")
6905 static void maskCompressByteMaxVectorTestsSmokeTest(IntFunction<boolean[]> fa) {
6906 int trueCount = 0;
6907 boolean[] a = fa.apply(SPECIES.length());
6908
6909 for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) {
6910 for (int i = 0; i < a.length; i += SPECIES.length()) {
6911 var vmask = SPECIES.loadMask(a, i);
6912 trueCount = vmask.trueCount();
6913 var rmask = vmask.compress();
6914 for (int j = 0; j < SPECIES.length(); j++) {
6915 Assert.assertEquals(rmask.laneIsSet(j), j < trueCount);
6916 }
6917 }
6918 }
6919 }
6920
6921
6922 @DataProvider
6923 public static Object[][] offsetProvider() {
6924 return new Object[][]{
6925 {0},
6926 {-1},
6927 {+1},
6928 {+2},
6929 {-2},
6930 };
6931 }
6932
6933 @Test(dataProvider = "offsetProvider")
6934 static void indexInRangeByteMaxVectorTestsSmokeTest(int offset) {
6935 int limit = SPECIES.length() * BUFFER_REPS;
6936 for (int i = 0; i < limit; i += SPECIES.length()) {
6937 var actualMask = SPECIES.indexInRange(i + offset, limit);
6938 var expectedMask = SPECIES.maskAll(true).indexInRange(i + offset, limit);
6939 assert(actualMask.equals(expectedMask));
6940 for (int j = 0; j < SPECIES.length(); j++) {
6941 int index = i + j + offset;
6942 Assert.assertEquals(actualMask.laneIsSet(j), index >= 0 && index < limit);
6943 }
6944 }
6945 }
6946
6947 @Test(dataProvider = "offsetProvider")
6948 static void indexInRangeLongByteMaxVectorTestsSmokeTest(int offset) {
6949 long limit = SPECIES.length() * BUFFER_REPS;
6950 for (long i = 0; i < limit; i += SPECIES.length()) {
6951 var actualMask = SPECIES.indexInRange(i + offset, limit);
6952 var expectedMask = SPECIES.maskAll(true).indexInRange(i + offset, limit);
6953 assert(actualMask.equals(expectedMask));
6954 for (int j = 0; j < SPECIES.length(); j++) {
6955 long index = i + j + offset;
6956 Assert.assertEquals(actualMask.laneIsSet(j), index >= 0 && index < limit);
6957 }
6958 }
6959 }
6960
6961 @DataProvider
6962 public static Object[][] lengthProvider() {
6963 return new Object[][]{
6964 {0},
6965 {1},
6966 {32},
6967 {37},
6968 {1024},
6969 {1024+1},
6970 {1024+5},
6971 };
6972 }
6973
6974 @Test(dataProvider = "lengthProvider")
6975 static void loopBoundByteMaxVectorTestsSmokeTest(int length) {
6976 int actualLoopBound = SPECIES.loopBound(length);
6977 int expectedLoopBound = length - Math.floorMod(length, SPECIES.length());
6978 Assert.assertEquals(actualLoopBound, expectedLoopBound);
6979 }
6980
6981 @Test(dataProvider = "lengthProvider")
6982 static void loopBoundLongByteMaxVectorTestsSmokeTest(int _length) {
6983 long length = _length;
6984 long actualLoopBound = SPECIES.loopBound(length);
6985 long expectedLoopBound = length - Math.floorMod(length, SPECIES.length());
6986 Assert.assertEquals(actualLoopBound, expectedLoopBound);
6987 }
6988
6989 @Test
6990 static void ElementSizeByteMaxVectorTestsSmokeTest() {
6991 ByteVector av = ByteVector.zero(SPECIES);
6992 int elsize = av.elementSize();
6993 Assert.assertEquals(elsize, Byte.SIZE);
6994 }
6995
6996 @Test
6997 static void VectorShapeByteMaxVectorTestsSmokeTest() {
6998 ByteVector av = ByteVector.zero(SPECIES);
6999 VectorShape vsh = av.shape();
7000 assert(vsh.equals(VectorShape.S_Max_BIT));
7001 }
7002
7003 @Test
7004 static void ShapeWithLanesByteMaxVectorTestsSmokeTest() {
7005 ByteVector av = ByteVector.zero(SPECIES);
7006 VectorShape vsh = av.shape();
7007 VectorSpecies species = vsh.withLanes(byte.class);
7008 assert(species.equals(SPECIES));
7009 }
7010
7011 @Test
7012 static void ElementTypeByteMaxVectorTestsSmokeTest() {
7013 ByteVector av = ByteVector.zero(SPECIES);
7014 assert(av.species().elementType() == byte.class);
7015 }
7016
7017 @Test
7018 static void SpeciesElementSizeByteMaxVectorTestsSmokeTest() {
7019 ByteVector av = ByteVector.zero(SPECIES);
7020 assert(av.species().elementSize() == Byte.SIZE);
7021 }
7022
7023 @Test
7024 static void VectorTypeByteMaxVectorTestsSmokeTest() {
7025 ByteVector av = ByteVector.zero(SPECIES);
7026 assert(av.species().vectorType() == av.getClass());
7027 }
7028
7029 @Test
7030 static void WithLanesByteMaxVectorTestsSmokeTest() {
7031 ByteVector av = ByteVector.zero(SPECIES);
7032 VectorSpecies species = av.species().withLanes(byte.class);
7033 assert(species.equals(SPECIES));
7034 }
7035
7036 @Test
7037 static void WithShapeByteMaxVectorTestsSmokeTest() {
7038 ByteVector av = ByteVector.zero(SPECIES);
7039 VectorShape vsh = av.shape();
7040 VectorSpecies species = av.species().withShape(vsh);
7041 assert(species.equals(SPECIES));
7042 }
7043
7044 @Test
7045 static void MaskAllTrueByteMaxVectorTestsSmokeTest() {
7046 for (int ic = 0; ic < INVOC_COUNT; ic++) {
7047 Assert.assertEquals(SPECIES.maskAll(true).toLong(), -1L >>> (64 - SPECIES.length()));
7048 }
7049 }
7050 }