File: TestMaskedMacroLogicVector.java

package info (click to toggle)
openjdk-25 25.0.1%2B8-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 825,408 kB
  • sloc: java: 5,585,680; cpp: 1,333,948; xml: 1,321,242; ansic: 488,034; asm: 404,003; objc: 21,088; sh: 15,106; javascript: 13,265; python: 8,319; makefile: 2,518; perl: 357; awk: 351; pascal: 103; exp: 83; sed: 72; jsp: 24
file content (847 lines) | stat: -rw-r--r-- 32,824 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
/*
 * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 */

/**
 * @test
 * @bug 8273322
 * @key randomness
 * @summary Enhance macro logic optimization for masked logic operations.
 * @modules jdk.incubator.vector
 * @requires vm.compiler2.enabled
 * @requires os.simpleArch == "x64"
 * @library /test/lib /
 * @run driver compiler.vectorapi.TestMaskedMacroLogicVector
 */

package compiler.vectorapi;

import java.util.concurrent.Callable;
import compiler.lib.ir_framework.*;
import jdk.test.lib.Utils;
import java.util.Random;

import jdk.incubator.vector.*;

public class TestMaskedMacroLogicVector {
    boolean [] br;
    boolean [] ba;
    boolean [] bb;

    short [] sr;
    char  [] ca;
    char  [] cb;

    int [] r;
    int [] a;
    int [] b;
    int [] c;
    int [] d;
    int [] e;
    int [] f;

    long [] rl;
    long [] al;
    long [] bl;
    long [] cl;

    boolean [] mask;

    static boolean booleanFunc1(boolean a, boolean b) {
        return a & b;
    }

    @Test
    @IR(applyIf = {"UseAVX", "3"}, counts = {IRNode.MACRO_LOGIC_V, " > 0 "})
    public void testSubWordBoolean(boolean[] r, boolean[] a, boolean[] b) {
        for (int i = 0; i < r.length; i++) {
            r[i] = booleanFunc1(a[i], b[i]);
        }
    }
    public void verifySubWordBoolean(boolean[] r, boolean[] a, boolean[] b) {
        for (int i = 0; i < r.length; i++) {
            boolean expected = booleanFunc1(a[i], b[i]);
            if (r[i] != expected) {
                throw new AssertionError(
                        String.format("at #%d: r=%b, expected = %b = booleanFunc1(%b,%b)",
                                      i, r[i], expected, a[i], b[i]));
            }
        }
    }


    static short charFunc1(char a, char b) {
        return (short)((a & b) & 1);
    }

    @Test
    @IR(applyIf = {"UseAVX", "3"}, counts = {IRNode.MACRO_LOGIC_V, " > 0 "})
    public void testSubWordChar(short[] r, char[] a, char[] b) {
        for (int i = 0; i < r.length; i++) {
            r[i] = charFunc1(a[i], b[i]);
        }
    }
    public void verifySubWordChar(short[] r, char[] a, char[] b) {
        for (int i = 0; i < r.length; i++) {
            short expected = charFunc1(a[i], b[i]);
            if (r[i] != expected) {
                throw new AssertionError(
                        String.format("testSubWordChar: at #%d: r=%d, expected = %d = booleanFunc1(%d,%d)",
                                      i, r[i], expected, (int)a[i], (int)b[i]));
            }
        }
    }

    // Case 1): Unmasked expression tree.
    //        P_LOP
    //   L_LOP     R_LOP

    static int intFunc1(int a, int b, int c) {
        return (a & b) ^ (a & c);
    }

    @ForceInline
    public void testInt1Kernel(VectorSpecies SPECIES, int [] r, int [] a, int [] b, int [] c) {
        for (int i = 0; i < SPECIES.loopBound(r.length); i += SPECIES.length()) {
            IntVector va = IntVector.fromArray(SPECIES, a, i);
            IntVector vb = IntVector.fromArray(SPECIES, b, i);
            IntVector vc = IntVector.fromArray(SPECIES, c, i);
            va.lanewise(VectorOperators.AND, vc)
            .lanewise(VectorOperators.XOR, va.lanewise(VectorOperators.AND, vb))
            .intoArray(r, i);
        }
    }

    @Test
    @IR(applyIf = {"UseAVX", "3"}, counts = {IRNode.MACRO_LOGIC_V, " > 0 "})
    public void testInt1_Int128(int[] r, int[] a, int[] b, int[] c) {
        testInt1Kernel(IntVector.SPECIES_128, r, a, b, c);
    }

    @Test
    @IR(applyIf = {"UseAVX", "3"}, counts = {IRNode.MACRO_LOGIC_V, " > 0 "})
    public void testInt1_Int256(int[] r, int[] a, int[] b, int[] c) {
        testInt1Kernel(IntVector.SPECIES_256, r, a, b, c);
    }

    @Test
    @IR(applyIf = {"UseAVX", "3"}, counts = {IRNode.MACRO_LOGIC_V, " > 0 "})
    public void testInt1_Int512(int[] r, int[] a, int[] b, int[] c) {
        testInt1Kernel(IntVector.SPECIES_512, r, a, b, c);
    }

    public void verifyInt1(int[] r, int[] a, int[] b, int[] c) {
        for (int i = 0; i < r.length; i++) {
            int expected = intFunc1(a[i], b[i], c[i]);
            if (r[i] != expected) {
                throw new AssertionError(String.format("testInt1: at #%d: r=%d, expected = %d = intFunc1(%d,%d,%d)",
                                                       i, r[i], expected, a[i], b[i], c[i]));
            }
        }
    }

    // Case 2): Only right child is masked.
    //        P_LOP
    //   L_LOP    R_LOP(mask)

    static int intFunc2(int a, int b, int c, boolean mask) {
        return (a & b) ^ (mask == true ? a & c : a);
    }

    @ForceInline
    public void testInt2Kernel(VectorSpecies SPECIES, int[] r, int[] a, int[] b, int[] c, boolean [] mask) {
        for (int i = 0; i < SPECIES.loopBound(r.length); i += SPECIES.length()) {
            VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask , i);
            IntVector va = IntVector.fromArray(SPECIES, a, i);
            IntVector vb = IntVector.fromArray(SPECIES, b, i);
            IntVector vc = IntVector.fromArray(SPECIES, c, i);
            va.lanewise(VectorOperators.AND, vb)
            .lanewise(VectorOperators.XOR,
                      va.lanewise(VectorOperators.AND, vc, vmask))
           .intoArray(r, i);
        }
    }

    @Test
    @IR(applyIf = {"UseAVX", "3"}, counts = {IRNode.MACRO_LOGIC_V, " > 0 "})
    public void testInt2_Int128(int[] r, int[] a, int[] b, int[] c, boolean [] mask) {
        testInt2Kernel(IntVector.SPECIES_128, r, a, b, c, mask);
    }
    @Test
    @IR(applyIf = {"UseAVX", "3"}, counts = {IRNode.MACRO_LOGIC_V, " > 0 "})
    public void testInt2_Int256(int[] r, int[] a, int[] b, int[] c, boolean [] mask) {
        testInt2Kernel(IntVector.SPECIES_256, r, a, b, c, mask);
    }
    @Test
    @IR(applyIf = {"UseAVX", "3"}, counts = {IRNode.MACRO_LOGIC_V, " > 0 "})
    public void testInt2_Int512(int[] r, int[] a, int[] b, int[] c, boolean [] mask) {
        testInt2Kernel(IntVector.SPECIES_512, r, a, b, c, mask);
    }

    public void verifyInt2(int[] r, int[] a, int[] b, int[] c, boolean [] mask) {
        for (int i = 0; i < r.length; i++) {
            int expected = intFunc2(a[i], b[i], c[i], mask[i]);
            if (r[i] != expected) {
                throw new AssertionError(String.format("testInt2: at #%d: r=%d, expected = %d = intFunc2(%d,%d,%d,%b)",
                                                       i, r[i], expected, a[i], b[i], c[i], mask[i]));
            }
        }
    }

    // Case 3): Only left child is masked.
    //             P_LOP
    //   L_LOP(mask)    R_LOP

    static int intFunc3(int a, int b, int c, boolean mask) {
        return (mask == true ? a & b : a) ^ (a & c);
    }

    @ForceInline
    public void testInt3Kernel(VectorSpecies SPECIES, int[] r, int[] a, int[] b, int[] c, boolean [] mask) {
        for (int i = 0; i < SPECIES.loopBound(r.length); i += SPECIES.length()) {
            VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask , i);
            IntVector va = IntVector.fromArray(SPECIES, a, i);
            IntVector vb = IntVector.fromArray(SPECIES, b, i);
            IntVector vc = IntVector.fromArray(SPECIES, c, i);
            va.lanewise(VectorOperators.AND, vb, vmask)
            .lanewise(VectorOperators.XOR,
                      va.lanewise(VectorOperators.AND, vc))
           .intoArray(r, i);
        }
    }

    @Test
    @IR(applyIf = {"UseAVX", "3"}, counts = {IRNode.MACRO_LOGIC_V, " > 0 "})
    public void testInt3_Int128(int[] r, int[] a, int[] b, int[] c, boolean [] mask) {
        testInt3Kernel(IntVector.SPECIES_128, r, a, b, c, mask);
    }
    @Test
    @IR(applyIf = {"UseAVX", "3"}, counts = {IRNode.MACRO_LOGIC_V, " > 0 "})
    public void testInt3_Int256(int[] r, int[] a, int[] b, int[] c, boolean [] mask) {
        testInt3Kernel(IntVector.SPECIES_256, r, a, b, c, mask);
    }
    @Test
    @IR(applyIf = {"UseAVX", "3"}, counts = {IRNode.MACRO_LOGIC_V, " > 0 "})
    public void testInt3_Int512(int[] r, int[] a, int[] b, int[] c, boolean [] mask) {
        testInt3Kernel(IntVector.SPECIES_512, r, a, b, c, mask);
    }


    @ForceInline
    public void verifyInt3(int[] r, int[] a, int[] b, int[] c, boolean [] mask) {
        for (int i = 0; i < r.length; i++) {
            int expected = intFunc3(a[i], b[i], c[i], mask[i]);
            if (r[i] != expected) {
                throw new AssertionError(String.format("testInt3: at #%d: r=%d, expected = %d = intFunc3(%d,%d,%d,%b)",
                                                       i, r[i], expected, a[i], b[i], c[i], mask[i]));
            }
        }
    }

    // Case 4): Both child nodes are masked.
    //             P_LOP
    //   L_LOP(mask)    R_LOP(mask)

    static int intFunc4(int a, int b, int c, boolean mask) {
        return (mask == true ? b & a : b) ^ (mask == true ? c & a : c);
    }

    @ForceInline
    public void testInt4Kernel(VectorSpecies SPECIES, int[] r, int[] a, int[] b, int[] c, boolean [] mask) {
        for (int i = 0; i < SPECIES.loopBound(r.length); i += SPECIES.length()) {
            VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask , i);
            IntVector va = IntVector.fromArray(SPECIES, a, i);
            IntVector vb = IntVector.fromArray(SPECIES, b, i);
            IntVector vc = IntVector.fromArray(SPECIES, c, i);
            vb.lanewise(VectorOperators.AND, va, vmask)
            .lanewise(VectorOperators.XOR,
                      vc.lanewise(VectorOperators.AND, va, vmask))
           .intoArray(r, i);
        }
    }

    @Test
    @IR(applyIfAnd = {"UseAVX", "3", "UseSSE", " > 3 "},
        counts = {IRNode.AND_VI, IRNode.VECTOR_SIZE_4, " > 0 ",
                  IRNode.XOR_VI, IRNode.VECTOR_SIZE_4, " > 0 "})
    public void testInt4_Int128(int[] r, int[] a, int[] b, int[] c, boolean [] mask) {
        testInt4Kernel(IntVector.SPECIES_128, r, a, b, c, mask);
    }
    @Test
    @IR(applyIfAnd = {"UseAVX", "3", "UseSSE", " > 3 "},
        counts = {IRNode.AND_VI, IRNode.VECTOR_SIZE_8, " > 0 ",
                  IRNode.XOR_VI, IRNode.VECTOR_SIZE_8, " > 0 "})
    public void testInt4_Int256(int[] r, int[] a, int[] b, int[] c, boolean [] mask) {
        testInt4Kernel(IntVector.SPECIES_256, r, a, b, c, mask);
    }
    @Test
    @IR(applyIfAnd = {"UseAVX", "3", "UseSSE", " > 3 "},
        counts = {IRNode.AND_VI, IRNode.VECTOR_SIZE_16, " > 0 ",
                  IRNode.XOR_VI, IRNode.VECTOR_SIZE_16, " > 0 "})
    public void testInt4_Int512(int[] r, int[] a, int[] b, int[] c, boolean [] mask) {
        testInt4Kernel(IntVector.SPECIES_512, r, a, b, c, mask);
    }

    public void verifyInt4(int[] r, int[] a, int[] b, int[] c, boolean [] mask) {
        for (int i = 0; i < r.length; i++) {
            int expected = intFunc4(a[i], b[i], c[i], mask[i]);
            if (r[i] != expected) {
                throw new AssertionError(String.format("testInt4: at #%d: r=%d, expected = %d = intFunc4(%d,%d,%d,%b)",
                                                       i, r[i], expected, a[i], b[i], c[i], mask[i]));
            }
        }
    }

    // Case 5): Parent is masked with unmasked child expressions.
    //        P_LOP(mask)
    //   L_LOP     R_LOP

    static int intFunc5(int a, int b, int c, boolean mask) {
        return mask == true ? ((a & b) ^ (a & c)) : (a & b);
    }

    @ForceInline
    public void testInt5Kernel(VectorSpecies SPECIES, int[] r, int[] a, int[] b, int[] c, boolean [] mask) {
        for (int i = 0; i < SPECIES.loopBound(r.length); i += SPECIES.length()) {
            VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask , i);
            IntVector va = IntVector.fromArray(SPECIES, a, i);
            IntVector vb = IntVector.fromArray(SPECIES, b, i);
            IntVector vc = IntVector.fromArray(SPECIES, c, i);
            va.lanewise(VectorOperators.AND, vb)
            .lanewise(VectorOperators.XOR,
                      va.lanewise(VectorOperators.AND, vc), vmask)
           .intoArray(r, i);
        }
    }

    @Test
    @IR(applyIf = {"UseAVX", "3"}, counts = {IRNode.MACRO_LOGIC_V, " > 0 "})
    public void testInt5_Int128(int[] r, int[] a, int[] b, int[] c, boolean [] mask) {
        testInt5Kernel(IntVector.SPECIES_128, r, a, b, c, mask);
    }
    @Test
    @IR(applyIf = {"UseAVX", "3"}, counts = {IRNode.MACRO_LOGIC_V, " > 0 "})
    public void testInt5_Int256(int[] r, int[] a, int[] b, int[] c, boolean [] mask) {
        testInt5Kernel(IntVector.SPECIES_256, r, a, b, c, mask);
    }
    @Test
    @IR(applyIf = {"UseAVX", "3"}, counts = {IRNode.MACRO_LOGIC_V, " > 0 "})
    public void testInt5_Int512(int[] r, int[] a, int[] b, int[] c, boolean [] mask) {
        testInt5Kernel(IntVector.SPECIES_512, r, a, b, c, mask);
    }

    @ForceInline
    public void verifyInt5(int[] r, int[] a, int[] b, int[] c, boolean [] mask) {
        for (int i = 0; i < r.length; i++) {
            int expected = intFunc5(a[i], b[i], c[i], mask[i]);
            if (r[i] != expected) {
                throw new AssertionError(String.format("testInt5: at #%d: r=%d, expected = %d = intFunc5(%d,%d,%d,%b)",
                                                       i, r[i], expected, a[i], b[i], c[i], mask[i]));
            }
        }
    }

    // Case 6): Parent and right child are masked.
    //        P_LOP(mask)
    //   L_LOP     R_LOP(mask)

    static int intFunc6(int a, int b, int c, boolean mask) {
        return mask == true ? ((a & b) ^ (mask == true ? a & c : a)) : (a & b);
    }

    @ForceInline
    public void testInt6Kernel(VectorSpecies SPECIES, int[] r, int[] a, int[] b, int[] c, boolean [] mask) {
        for (int i = 0; i < SPECIES.loopBound(r.length); i += SPECIES.length()) {
            VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask , i);
            IntVector va = IntVector.fromArray(SPECIES, a, i);
            IntVector vb = IntVector.fromArray(SPECIES, b, i);
            IntVector vc = IntVector.fromArray(SPECIES, c, i);
            va.lanewise(VectorOperators.AND, vb)
            .lanewise(VectorOperators.XOR,
                      va.lanewise(VectorOperators.AND, vc, vmask), vmask)
           .intoArray(r, i);
        }
    }
    @Test
    @IR(applyIf = {"UseAVX", "3"}, counts = {IRNode.MACRO_LOGIC_V, " > 0 "})
    public void testInt6_Int128(int[] r, int[] a, int[] b, int[] c, boolean [] mask) {
        testInt6Kernel(IntVector.SPECIES_128, r, a, b, c, mask);
    }
    @Test
    @IR(applyIf = {"UseAVX", "3"}, counts = {IRNode.MACRO_LOGIC_V, " > 0 "})
    public void testInt6_Int256(int[] r, int[] a, int[] b, int[] c, boolean [] mask) {
        testInt6Kernel(IntVector.SPECIES_256, r, a, b, c, mask);
    }
    @Test
    @IR(applyIf = {"UseAVX", "3"}, counts = {IRNode.MACRO_LOGIC_V, " > 0 "})
    public void testInt6_Int512(int[] r, int[] a, int[] b, int[] c, boolean [] mask) {
        testInt6Kernel(IntVector.SPECIES_512, r, a, b, c, mask);
    }


    public void verifyInt6(int[] r, int[] a, int[] b, int[] c, boolean [] mask) {
        for (int i = 0; i < r.length; i++) {
            int expected = intFunc6(a[i], b[i], c[i], mask[i]);
            if (r[i] != expected) {
                throw new AssertionError(String.format("testInt6: at #%d: r=%d, expected = %d = intFunc6(%d,%d,%d,%b)",
                                                       i, r[i], expected, a[i], b[i], c[i], mask[i]));
            }
        }
    }

    // Case 7): Parent and left child are masked.
    //            P_LOP(mask)
    //   L_LOP(mask)       R_LOP

    static int intFunc7(int a, int b, int c, boolean mask) {
        return mask == true ? ((mask == true ? a & b : a) ^ (a & c)) : a;
    }

    @ForceInline
    public void testInt7Kernel(VectorSpecies SPECIES, int[] r, int[] a, int[] b, int[] c, boolean [] mask) {
        for (int i = 0; i < SPECIES.loopBound(r.length); i += SPECIES.length()) {
            VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask , i);
            IntVector va = IntVector.fromArray(SPECIES, a, i);
            IntVector vb = IntVector.fromArray(SPECIES, b, i);
            IntVector vc = IntVector.fromArray(SPECIES, c, i);
            va.lanewise(VectorOperators.AND, vb, vmask)
            .lanewise(VectorOperators.XOR,
                      va.lanewise(VectorOperators.AND, vc), vmask)
           .intoArray(r, i);
        }
    }

    @Test
    @IR(applyIf = {"UseAVX", "3"}, counts = {IRNode.MACRO_LOGIC_V, " > 0 "})
    public void testInt7_Int128(int[] r, int[] a, int[] b, int[] c, boolean [] mask) {
        testInt7Kernel(IntVector.SPECIES_128, r, a, b, c, mask);
    }
    @Test
    @IR(applyIf = {"UseAVX", "3"}, counts = {IRNode.MACRO_LOGIC_V, " > 0 "})
    public void testInt7_Int256(int[] r, int[] a, int[] b, int[] c, boolean [] mask) {
        testInt7Kernel(IntVector.SPECIES_256, r, a, b, c, mask);
    }
    @Test
    @IR(applyIf = {"UseAVX", "3"}, counts = {IRNode.MACRO_LOGIC_V, " > 0 "})
    public void testInt7_Int512(int[] r, int[] a, int[] b, int[] c, boolean [] mask) {
        testInt7Kernel(IntVector.SPECIES_512, r, a, b, c, mask);
    }

    public void verifyInt7(int[] r, int[] a, int[] b, int[] c, boolean [] mask) {
        for (int i = 0; i < r.length; i++) {
            int expected = intFunc7(a[i], b[i], c[i], mask[i]);
            if (r[i] != expected) {
                throw new AssertionError(String.format("testInt7: at #%d: r=%d, expected = %d = intFunc7(%d,%d,%d,%b)",
                                                       i, r[i], expected, a[i], b[i], c[i], mask[i]));
            }
        }
    }

    // Case 8): Parent and both child expressions are masked.
    //            P_LOP(mask)
    //   L_LOP(mask)       R_LOP (mask)

    static int intFunc8(int a, int b, int c, boolean mask) {
        return mask == true ? ((mask == true ? b & a : b) ^ (mask == true ? c & a  : c)) : b;
    }

    @ForceInline
    public void testInt8Kernel(VectorSpecies SPECIES, int[] r, int[] a, int[] b, int[] c, boolean [] mask) {
        for (int i = 0; i < SPECIES.loopBound(r.length); i += SPECIES.length()) {
            VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask , i);
            IntVector va = IntVector.fromArray(SPECIES, a, i);
            IntVector vb = IntVector.fromArray(SPECIES, b, i);
            IntVector vc = IntVector.fromArray(SPECIES, c, i);
            vb.lanewise(VectorOperators.AND, va, vmask)
            .lanewise(VectorOperators.XOR,
                      vc.lanewise(VectorOperators.AND, va, vmask), vmask)
           .intoArray(r, i);
        }
    }

    @Test
    @IR(applyIf = {"UseAVX", "3"}, counts = {IRNode.MACRO_LOGIC_V, " > 0 "})
    public void testInt8_Int128(int[] r, int[] a, int[] b, int[] c, boolean [] mask) {
        testInt8Kernel(IntVector.SPECIES_128, r, a, b, c, mask);
    }
    @Test
    @IR(applyIf = {"UseAVX", "3"}, counts = {IRNode.MACRO_LOGIC_V, " > 0 "})
    public void testInt8_Int256(int[] r, int[] a, int[] b, int[] c, boolean [] mask) {
        testInt8Kernel(IntVector.SPECIES_256, r, a, b, c, mask);
    }
    @Test
    @IR(applyIf = {"UseAVX", "3"}, counts = {IRNode.MACRO_LOGIC_V, " > 0 "})
    public void testInt8_Int512(int[] r, int[] a, int[] b, int[] c, boolean [] mask) {
        testInt8Kernel(IntVector.SPECIES_512, r, a, b, c, mask);
    }

    public void verifyInt8(int[] r, int[] a, int[] b, int[] c, boolean [] mask) {
        for (int i = 0; i < r.length; i++) {
            int expected = intFunc8(a[i], b[i], c[i], mask[i]);
            if (r[i] != expected) {
                throw new AssertionError(String.format("testInt8: at #%d: r=%d, expected = %d = intFunc8(%d,%d,%d,%b)",
                                                       i, r[i], expected, a[i], b[i], c[i], mask[i]));
            }
        }
    }


    // ===================================================== //

    static long longFunc(long a, long b, long c) {
        long v1 = (a & b) ^ (a & c) ^ (b & c);
        long v2 = (~a & b) | (~b & c) | (~c & a);
        return v1 & v2;
    }

    @ForceInline
    public void testLongKernel(VectorSpecies SPECIES, long[] r, long[] a, long[] b, long[] c) {
        for (int i = 0; i < SPECIES.loopBound(r.length); i  +=  SPECIES.length()) {
            LongVector va = LongVector.fromArray(SPECIES, a, i);
            LongVector vb = LongVector.fromArray(SPECIES, b, i);
            LongVector vc = LongVector.fromArray(SPECIES, c, i);

            va.lanewise(VectorOperators.AND, vb)
            .lanewise(VectorOperators.XOR, va.lanewise(VectorOperators.AND, vc))
            .lanewise(VectorOperators.XOR, vb.lanewise(VectorOperators.AND, vc))
            .lanewise(VectorOperators.AND,
                       va.lanewise(VectorOperators.NOT).lanewise(VectorOperators.AND, vb)
                      .lanewise(VectorOperators.OR, vb.lanewise(VectorOperators.NOT).lanewise(VectorOperators.AND, vc))
                      .lanewise(VectorOperators.OR, vc.lanewise(VectorOperators.NOT).lanewise(VectorOperators.AND, va)))
            .intoArray(r, i);
        }
    }

    @Test
    @IR(applyIf = {"UseAVX", "3"}, counts = {IRNode.MACRO_LOGIC_V, " > 0 "})
    public void testLong_Long256(long[] r, long[] a, long[] b, long[] c) {
        testLongKernel(LongVector.SPECIES_256, r, a, b, c);
    }
    @Test
    @IR(applyIf = {"UseAVX", "3"}, counts = {IRNode.MACRO_LOGIC_V, " > 0 "})
    public void testLong_Long512(long[] r, long[] a, long[] b, long[] c) {
        testLongKernel(LongVector.SPECIES_512, r, a, b, c);
    }

    public void verifyLong(long[] r, long[] a, long[] b, long[] c) {
        for (int i = 0; i < r.length; i++) {
            long expected = longFunc(a[i], b[i], c[i]);
            if (r[i] != expected) {
                throw new AssertionError(
                        String.format("testLong: at #%d: r=%d, expected = %d = longFunc(%d,%d,%d)",
                                      i, r[i], expected, a[i], b[i], c[i]));
            }
        }
    }

    // ===================================================== //

    private static final Random R = Utils.getRandomInstance();

    static boolean[] fillBooleanRandom(Callable<boolean[]> factory) {
        try {
            boolean[] arr = factory.call();
            for (int i = 0; i < arr.length; i++) {
                arr[i] = R.nextBoolean();
            }
            return arr;
        } catch (Exception e) {
            throw new InternalError(e);
        }
    }
    static char[] fillCharRandom(Callable<char[]> factory) {
        try {
            char[] arr = factory.call();
            for (int i = 0; i < arr.length; i++) {
                arr[i] = (char)R.nextInt();
            }
            return arr;
        } catch (Exception e) {
            throw new InternalError(e);
        }
    }
    static int[] fillIntRandom(Callable<int[]> factory) {
        try {
            int[] arr = factory.call();
            for (int i = 0; i < arr.length; i++) {
                arr[i] = R.nextInt();
            }
            return arr;
        } catch (Exception e) {
            throw new InternalError(e);
        }
    }
    static long[] fillLongRandom(Callable<long[]> factory) {
        try {
            long[] arr = factory.call();
            for (int i = 0; i < arr.length; i++) {
                arr[i] = R.nextLong();
            }
            return arr;
        } catch (Exception e) {
            throw new InternalError(e);
        }
    }

    // ===================================================== //

    static final int SIZE = 512;

    @Run(test = {"testInt4_Int128"}, mode = RunMode.STANDALONE)
    public void kernel_testInt4_Int128() {
        for (int i = 0; i < 10000; i++) {
            testInt4_Int128(r, a, b, c, mask);
            verifyInt4(r, a, b, c, mask);
        }
    }
    @Run(test = {"testInt4_Int256"}, mode = RunMode.STANDALONE)
    public void kernel_testInt4_Int256() {
        for (int i = 0; i < 10000; i++) {
            testInt4_Int256(r, a, b, c, mask);
            verifyInt4(r, a, b, c, mask);
        }
    }
    @Run(test = {"testInt4_Int512"}, mode = RunMode.STANDALONE)
    public void kernel_testInt4_Int512() {
        for (int i = 0; i < 10000; i++) {
            testInt4_Int512(r, a, b, c, mask);
            verifyInt4(r, a, b, c, mask);
        }
    }

    @Run(test = {"testSubWordBoolean"}, mode = RunMode.STANDALONE)
    public void kernel_test_SubWordBoolean() {
        for (int i = 0; i < 10000; i++) {
            testSubWordBoolean(br, ba, bb);
            verifySubWordBoolean(br, ba, bb);
        }
    }

    @Run(test = {"testSubWordChar"}, mode = RunMode.STANDALONE)
    public void kernel_test_SubWordChar() {
        for (int i = 0; i < 10000; i++) {
            testSubWordChar(sr, ca, cb);
            verifySubWordChar(sr, ca, cb);
        }
    }

    @Run(test = {"testInt1_Int128"}, mode = RunMode.STANDALONE)
    public void kernel_testInt1_Int128() {
        for (int i = 0; i < 10000; i++) {
            testInt1_Int128(r, a, b, c);
            verifyInt1(r, a, b, c);
        }
    }
    @Run(test = {"testInt1_Int256"}, mode = RunMode.STANDALONE)
    public void kernel_testInt1_Int256() {
        for (int i = 0; i < 10000; i++) {
            testInt1_Int256(r, a, b, c);
            verifyInt1(r, a, b, c);
        }
    }
    @Run(test = {"testInt1_Int512"}, mode = RunMode.STANDALONE)
    public void kernel_testInt1_Int512() {
        for (int i = 0; i < 10000; i++) {
            testInt1_Int512(r, a, b, c);
            verifyInt1(r, a, b, c);
        }
    }

    @Run(test = {"testInt2_Int128"}, mode = RunMode.STANDALONE)
    public void kernel_testInt2_Int128() {
        for (int i = 0; i < 10000; i++) {
            testInt2_Int128(r, a, b, c, mask);
            verifyInt2(r, a, b, c, mask);
        }
    }
    @Run(test = {"testInt2_Int256"}, mode = RunMode.STANDALONE)
    public void kernel_testInt2_Int256() {
        for (int i = 0; i < 10000; i++) {
            testInt2_Int256(r, a, b, c, mask);
            verifyInt2(r, a, b, c, mask);
        }
    }
    @Run(test = {"testInt2_Int512"}, mode = RunMode.STANDALONE)
    public void kernel_testInt2_Int512() {
        for (int i = 0; i < 10000; i++) {
            testInt2_Int512(r, a, b, c, mask);
            verifyInt2(r, a, b, c, mask);
        }
    }

    @Run(test = {"testInt3_Int128"}, mode = RunMode.STANDALONE)
    public void kernel_testInt3_Int128() {
        for (int i = 0; i < 10000; i++) {
            testInt3_Int128(r, a, b, c, mask);
            verifyInt3(r, a, b, c, mask);
        }
    }
    @Run(test = {"testInt3_Int256"}, mode = RunMode.STANDALONE)
    public void kernel_testInt3_Int256() {
        for (int i = 0; i < 10000; i++) {
            testInt3_Int256(r, a, b, c, mask);
            verifyInt3(r, a, b, c, mask);
        }
    }
    @Run(test = {"testInt3_Int512"}, mode = RunMode.STANDALONE)
    public void kernel_testInt3_Int512() {
        for (int i = 0; i < 10000; i++) {
            testInt3_Int512(r, a, b, c, mask);
            verifyInt3(r, a, b, c, mask);
        }
    }

    @Run(test = {"testInt5_Int128"}, mode = RunMode.STANDALONE)
    public void kernel_testInt5_128() {
        for (int i = 0; i < 10000; i++) {
            testInt5_Int128(r, a, b, c, mask);
            verifyInt5(r, a, b, c, mask);
        }
    }
    @Run(test = {"testInt5_Int256"}, mode = RunMode.STANDALONE)
    public void kernel_testInt5_256() {
        for (int i = 0; i < 10000; i++) {
            testInt5_Int256(r, a, b, c, mask);
            verifyInt5(r, a, b, c, mask);
        }
    }
    @Run(test = {"testInt5_Int512"}, mode = RunMode.STANDALONE)
    public void kernel_testInt5_Int512() {
        for (int i = 0; i < 10000; i++) {
            testInt5_Int512(r, a, b, c, mask);
            verifyInt5(r, a, b, c, mask);
        }
    }

    @Run(test = {"testInt6_Int128"}, mode = RunMode.STANDALONE)
    public void kernel_testInt6_Int128() {
        for (int i = 0; i < 10000; i++) {
            testInt6_Int128(r, a, b, c, mask);
            verifyInt6(r, a, b, c, mask);
        }
    }
    @Run(test = {"testInt6_Int256"}, mode = RunMode.STANDALONE)
    public void kernel_testInt6_Int256() {
        for (int i = 0; i < 10000; i++) {
            testInt6_Int256(r, a, b, c, mask);
            verifyInt6(r, a, b, c, mask);
        }
    }
    @Run(test = {"testInt6_Int512"}, mode = RunMode.STANDALONE)
    public void kernel_testInt6_Int512() {
        for (int i = 0; i < 10000; i++) {
            testInt6_Int512(r, a, b, c, mask);
            verifyInt6(r, a, b, c, mask);
        }
    }

    @Run(test = {"testInt7_Int128"}, mode = RunMode.STANDALONE)
    public void kernel_testInt7_Int128() {
        for (int i = 0; i < 10000; i++) {
            testInt7_Int128(r, a, b, c, mask);
            verifyInt7(r, a, b, c, mask);
        }
    }
    @Run(test = {"testInt7_Int256"}, mode = RunMode.STANDALONE)
    public void kernel_testInt7_Int256() {
        for (int i = 0; i < 10000; i++) {
            testInt7_Int256(r, a, b, c, mask);
            verifyInt7(r, a, b, c, mask);
        }
    }
    @Run(test = {"testInt7_Int512"}, mode = RunMode.STANDALONE)
    public void kernel_testInt7_Int512() {
        for (int i = 0; i < 10000; i++) {
            testInt7_Int512(r, a, b, c, mask);
            verifyInt7(r, a, b, c, mask);
        }
    }

    @Run(test = {"testInt8_Int128"}, mode = RunMode.STANDALONE)
    public void kernel_testInt8_Int128() {
        for (int i = 0; i < 10000; i++) {
            testInt8_Int128(r, a, b, c, mask);
            verifyInt8(r, a, b, c, mask);
        }
    }
    @Run(test = {"testInt8_Int256"}, mode = RunMode.STANDALONE)
    public void kernel_testInt8_Int256() {
        for (int i = 0; i < 10000; i++) {
            testInt8_Int256(r, a, b, c, mask);
            verifyInt8(r, a, b, c, mask);
        }
    }
    @Run(test = {"testInt8_Int512"}, mode = RunMode.STANDALONE)
    public void kernel_testInt8_Int512() {
        for (int i = 0; i < 10000; i++) {
            testInt8_Int512(r, a, b, c, mask);
            verifyInt8(r, a, b, c, mask);
        }
    }

    @Run(test = {"testLong_Long256"}, mode = RunMode.STANDALONE)
    public void kernel_testLong_Long256() {
        for (int i = 0; i < 10000; i++) {
            testLong_Long256(rl, al, bl, cl);
            verifyLong(rl, al, bl, cl);
        }
    }
    @Run(test = {"testLong_Long512"}, mode = RunMode.STANDALONE)
    public void kernel_testLong_Long512() {
        for (int i = 0; i < 10000; i++) {
            testLong_Long512(rl, al, bl, cl);
            verifyLong(rl, al, bl, cl);
        }
    }

    public TestMaskedMacroLogicVector() {
        br = new boolean[SIZE];
        ba = fillBooleanRandom((()-> new boolean[SIZE]));
        bb = fillBooleanRandom((()-> new boolean[SIZE]));

        sr = new short[SIZE];
        ca = fillCharRandom((()-> new char[SIZE]));
        cb = fillCharRandom((()-> new char[SIZE]));

        r = new int[SIZE];
        a = fillIntRandom(()-> new int[SIZE]);
        b = fillIntRandom(()-> new int[SIZE]);
        c = fillIntRandom(()-> new int[SIZE]);
        d = fillIntRandom(()-> new int[SIZE]);
        e = fillIntRandom(()-> new int[SIZE]);
        f = fillIntRandom(()-> new int[SIZE]);

        rl = new long[SIZE];
        al = fillLongRandom(() -> new long[SIZE]);
        bl = fillLongRandom(() -> new long[SIZE]);
        cl = fillLongRandom(() -> new long[SIZE]);

        mask = fillBooleanRandom((()-> new boolean[SIZE]));
    }

    public static void main(String[] args) {
        TestFramework.runWithFlags("-XX:-TieredCompilation",
                                   "-XX:UseAVX=3",
                                   "--add-modules=jdk.incubator.vector",
                                   "-XX:CompileThresholdScaling=0.3");
    }
}