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