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