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