1 /*
  2  * Copyright (c) 2017, 2022, 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.  Oracle designates this
  8  * particular file as subject to the "Classpath" exception as provided
  9  * by Oracle in the LICENSE file that accompanied this code.
 10  *
 11  * This code is distributed in the hope that it will be useful, but WITHOUT
 12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 14  * version 2 for more details (a copy is included in the LICENSE file that
 15  * accompanied this code).
 16  *
 17  * You should have received a copy of the GNU General Public License version
 18  * 2 along with this work; if not, write to the Free Software Foundation,
 19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 20  *
 21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 22  * or visit www.oracle.com if you need additional information or have any
 23  * questions.
 24  */
 25 package jdk.incubator.vector;
 26 
 27 import java.util.Arrays;
 28 import java.util.Objects;
 29 import java.util.function.IntUnaryOperator;
 30 
 31 import jdk.incubator.foreign.MemorySegment;
 32 import jdk.internal.vm.annotation.ForceInline;
 33 import jdk.internal.vm.vector.VectorSupport;
 34 
 35 import static jdk.internal.vm.vector.VectorSupport.*;
 36 
 37 import static jdk.incubator.vector.VectorOperators.*;
 38 
 39 // -- This file was mechanically generated: Do not edit! -- //
 40 
 41 @SuppressWarnings("cast")  // warning: redundant cast
 42 final class Byte128Vector extends ByteVector {
 43     static final ByteSpecies VSPECIES =
 44         (ByteSpecies) ByteVector.SPECIES_128;
 45 
 46     static final VectorShape VSHAPE =
 47         VSPECIES.vectorShape();
 48 
 49     static final Class<Byte128Vector> VCLASS = Byte128Vector.class;
 50 
 51     static final int VSIZE = VSPECIES.vectorBitSize();
 52 
 53     static final int VLENGTH = VSPECIES.laneCount(); // used by the JVM
 54 
 55     static final Class<Byte> ETYPE = byte.class; // used by the JVM
 56 
 57     Byte128Vector(byte[] v) {
 58         super(v);
 59     }
 60 
 61     // For compatibility as Byte128Vector::new,
 62     // stored into species.vectorFactory.
 63     Byte128Vector(Object v) {
 64         this((byte[]) v);
 65     }
 66 
 67     static final Byte128Vector ZERO = new Byte128Vector(new byte[VLENGTH]);
 68     static final Byte128Vector IOTA = new Byte128Vector(VSPECIES.iotaArray());
 69 
 70     static {
 71         // Warm up a few species caches.
 72         // If we do this too much we will
 73         // get NPEs from bootstrap circularity.
 74         VSPECIES.dummyVector();
 75         VSPECIES.withLanes(LaneType.BYTE);
 76     }
 77 
 78     // Specialized extractors
 79 
 80     @ForceInline
 81     final @Override
 82     public ByteSpecies vspecies() {
 83         // ISSUE:  This should probably be a @Stable
 84         // field inside AbstractVector, rather than
 85         // a megamorphic method.
 86         return VSPECIES;
 87     }
 88 
 89     @ForceInline
 90     @Override
 91     public final Class<Byte> elementType() { return byte.class; }
 92 
 93     @ForceInline
 94     @Override
 95     public final int elementSize() { return Byte.SIZE; }
 96 
 97     @ForceInline
 98     @Override
 99     public final VectorShape shape() { return VSHAPE; }
100 
101     @ForceInline
102     @Override
103     public final int length() { return VLENGTH; }
104 
105     @ForceInline
106     @Override
107     public final int bitSize() { return VSIZE; }
108 
109     @ForceInline
110     @Override
111     public final int byteSize() { return VSIZE / Byte.SIZE; }
112 
113     /*package-private*/
114     @ForceInline
115     final @Override
116     byte[] vec() {
117         return (byte[])getPayload();
118     }
119 
120     // Virtualized constructors
121 
122     @Override
123     @ForceInline
124     public final Byte128Vector broadcast(byte e) {
125         return (Byte128Vector) super.broadcastTemplate(e);  // specialize
126     }
127 
128     @Override
129     @ForceInline
130     public final Byte128Vector broadcast(long e) {
131         return (Byte128Vector) super.broadcastTemplate(e);  // specialize
132     }
133 
134     @Override
135     @ForceInline
136     Byte128Mask maskFromArray(boolean[] bits) {
137         return new Byte128Mask(bits);
138     }
139 
140     @Override
141     @ForceInline
142     Byte128Shuffle iotaShuffle() { return Byte128Shuffle.IOTA; }
143 
144     @ForceInline
145     Byte128Shuffle iotaShuffle(int start, int step, boolean wrap) {
146       if (wrap) {
147         return (Byte128Shuffle)VectorSupport.shuffleIota(ETYPE, Byte128Shuffle.class, VSPECIES, VLENGTH, start, step, 1,
148                 (l, lstart, lstep, s) -> s.shuffleFromOp(i -> (VectorIntrinsics.wrapToRange(i*lstep + lstart, l))));
149       } else {
150         return (Byte128Shuffle)VectorSupport.shuffleIota(ETYPE, Byte128Shuffle.class, VSPECIES, VLENGTH, start, step, 0,
151                 (l, lstart, lstep, s) -> s.shuffleFromOp(i -> (i*lstep + lstart)));
152       }
153     }
154 
155     @Override
156     @ForceInline
157     Byte128Shuffle shuffleFromBytes(byte[] reorder) { return new Byte128Shuffle(reorder); }
158 
159     @Override
160     @ForceInline
161     Byte128Shuffle shuffleFromArray(int[] indexes, int i) { return new Byte128Shuffle(indexes, i); }
162 
163     @Override
164     @ForceInline
165     Byte128Shuffle shuffleFromOp(IntUnaryOperator fn) { return new Byte128Shuffle(fn); }
166 
167     // Make a vector of the same species but the given elements:
168     @ForceInline
169     final @Override
170     Byte128Vector vectorFactory(byte[] vec) {
171         return new Byte128Vector(vec);
172     }
173 
174     @ForceInline
175     final @Override
176     Byte128Vector asByteVectorRaw() {
177         return (Byte128Vector) super.asByteVectorRawTemplate();  // specialize
178     }
179 
180     @ForceInline
181     final @Override
182     AbstractVector<?> asVectorRaw(LaneType laneType) {
183         return super.asVectorRawTemplate(laneType);  // specialize
184     }
185 
186     // Unary operator
187 
188     @ForceInline
189     final @Override
190     Byte128Vector uOp(FUnOp f) {
191         return (Byte128Vector) super.uOpTemplate(f);  // specialize
192     }
193 
194     @ForceInline
195     final @Override
196     Byte128Vector uOp(VectorMask<Byte> m, FUnOp f) {
197         return (Byte128Vector)
198             super.uOpTemplate((Byte128Mask)m, f);  // specialize
199     }
200 
201     // Binary operator
202 
203     @ForceInline
204     final @Override
205     Byte128Vector bOp(Vector<Byte> v, FBinOp f) {
206         return (Byte128Vector) super.bOpTemplate((Byte128Vector)v, f);  // specialize
207     }
208 
209     @ForceInline
210     final @Override
211     Byte128Vector bOp(Vector<Byte> v,
212                      VectorMask<Byte> m, FBinOp f) {
213         return (Byte128Vector)
214             super.bOpTemplate((Byte128Vector)v, (Byte128Mask)m,
215                               f);  // specialize
216     }
217 
218     // Ternary operator
219 
220     @ForceInline
221     final @Override
222     Byte128Vector tOp(Vector<Byte> v1, Vector<Byte> v2, FTriOp f) {
223         return (Byte128Vector)
224             super.tOpTemplate((Byte128Vector)v1, (Byte128Vector)v2,
225                               f);  // specialize
226     }
227 
228     @ForceInline
229     final @Override
230     Byte128Vector tOp(Vector<Byte> v1, Vector<Byte> v2,
231                      VectorMask<Byte> m, FTriOp f) {
232         return (Byte128Vector)
233             super.tOpTemplate((Byte128Vector)v1, (Byte128Vector)v2,
234                               (Byte128Mask)m, f);  // specialize
235     }
236 
237     @ForceInline
238     final @Override
239     byte rOp(byte v, VectorMask<Byte> m, FBinOp f) {
240         return super.rOpTemplate(v, m, f);  // specialize
241     }
242 
243     @Override
244     @ForceInline
245     public final <F>
246     Vector<F> convertShape(VectorOperators.Conversion<Byte,F> conv,
247                            VectorSpecies<F> rsp, int part) {
248         return super.convertShapeTemplate(conv, rsp, part);  // specialize
249     }
250 
251     @Override
252     @ForceInline
253     public final <F>
254     Vector<F> reinterpretShape(VectorSpecies<F> toSpecies, int part) {
255         return super.reinterpretShapeTemplate(toSpecies, part);  // specialize
256     }
257 
258     // Specialized algebraic operations:
259 
260     // The following definition forces a specialized version of this
261     // crucial method into the v-table of this class.  A call to add()
262     // will inline to a call to lanewise(ADD,), at which point the JIT
263     // intrinsic will have the opcode of ADD, plus all the metadata
264     // for this particular class, enabling it to generate precise
265     // code.
266     //
267     // There is probably no benefit to the JIT to specialize the
268     // masked or broadcast versions of the lanewise method.
269 
270     @Override
271     @ForceInline
272     public Byte128Vector lanewise(Unary op) {
273         return (Byte128Vector) super.lanewiseTemplate(op);  // specialize
274     }
275 
276     @Override
277     @ForceInline
278     public Byte128Vector lanewise(Unary op, VectorMask<Byte> m) {
279         return (Byte128Vector) super.lanewiseTemplate(op, Byte128Mask.class, (Byte128Mask) m);  // specialize
280     }
281 
282     @Override
283     @ForceInline
284     public Byte128Vector lanewise(Binary op, Vector<Byte> v) {
285         return (Byte128Vector) super.lanewiseTemplate(op, v);  // specialize
286     }
287 
288     @Override
289     @ForceInline
290     public Byte128Vector lanewise(Binary op, Vector<Byte> v, VectorMask<Byte> m) {
291         return (Byte128Vector) super.lanewiseTemplate(op, Byte128Mask.class, v, (Byte128Mask) m);  // specialize
292     }
293 
294     /*package-private*/
295     @Override
296     @ForceInline Byte128Vector
297     lanewiseShift(VectorOperators.Binary op, int e) {
298         return (Byte128Vector) super.lanewiseShiftTemplate(op, e);  // specialize
299     }
300 
301     /*package-private*/
302     @Override
303     @ForceInline Byte128Vector
304     lanewiseShift(VectorOperators.Binary op, int e, VectorMask<Byte> m) {
305         return (Byte128Vector) super.lanewiseShiftTemplate(op, Byte128Mask.class, e, (Byte128Mask) m);  // specialize
306     }
307 
308     /*package-private*/
309     @Override
310     @ForceInline
311     public final
312     Byte128Vector
313     lanewise(Ternary op, Vector<Byte> v1, Vector<Byte> v2) {
314         return (Byte128Vector) super.lanewiseTemplate(op, v1, v2);  // specialize
315     }
316 
317     @Override
318     @ForceInline
319     public final
320     Byte128Vector
321     lanewise(Ternary op, Vector<Byte> v1, Vector<Byte> v2, VectorMask<Byte> m) {
322         return (Byte128Vector) super.lanewiseTemplate(op, Byte128Mask.class, v1, v2, (Byte128Mask) m);  // specialize
323     }
324 
325     @Override
326     @ForceInline
327     public final
328     Byte128Vector addIndex(int scale) {
329         return (Byte128Vector) super.addIndexTemplate(scale);  // specialize
330     }
331 
332     // Type specific horizontal reductions
333 
334     @Override
335     @ForceInline
336     public final byte reduceLanes(VectorOperators.Associative op) {
337         return super.reduceLanesTemplate(op);  // specialized
338     }
339 
340     @Override
341     @ForceInline
342     public final byte reduceLanes(VectorOperators.Associative op,
343                                     VectorMask<Byte> m) {
344         return super.reduceLanesTemplate(op, Byte128Mask.class, (Byte128Mask) m);  // specialized
345     }
346 
347     @Override
348     @ForceInline
349     public final long reduceLanesToLong(VectorOperators.Associative op) {
350         return (long) super.reduceLanesTemplate(op);  // specialized
351     }
352 
353     @Override
354     @ForceInline
355     public final long reduceLanesToLong(VectorOperators.Associative op,
356                                         VectorMask<Byte> m) {
357         return (long) super.reduceLanesTemplate(op, Byte128Mask.class, (Byte128Mask) m);  // specialized
358     }
359 
360     @ForceInline
361     public VectorShuffle<Byte> toShuffle() {
362         return super.toShuffleTemplate(Byte128Shuffle.class); // specialize
363     }
364 
365     // Specialized unary testing
366 
367     @Override
368     @ForceInline
369     public final Byte128Mask test(Test op) {
370         return super.testTemplate(Byte128Mask.class, op);  // specialize
371     }
372 
373     @Override
374     @ForceInline
375     public final Byte128Mask test(Test op, VectorMask<Byte> m) {
376         return super.testTemplate(Byte128Mask.class, op, (Byte128Mask) m);  // specialize
377     }
378 
379     // Specialized comparisons
380 
381     @Override
382     @ForceInline
383     public final Byte128Mask compare(Comparison op, Vector<Byte> v) {
384         return super.compareTemplate(Byte128Mask.class, op, v);  // specialize
385     }
386 
387     @Override
388     @ForceInline
389     public final Byte128Mask compare(Comparison op, byte s) {
390         return super.compareTemplate(Byte128Mask.class, op, s);  // specialize
391     }
392 
393     @Override
394     @ForceInline
395     public final Byte128Mask compare(Comparison op, long s) {
396         return super.compareTemplate(Byte128Mask.class, op, s);  // specialize
397     }
398 
399     @Override
400     @ForceInline
401     public final Byte128Mask compare(Comparison op, Vector<Byte> v, VectorMask<Byte> m) {
402         return super.compareTemplate(Byte128Mask.class, op, v, (Byte128Mask) m);
403     }
404 
405 
406     @Override
407     @ForceInline
408     public Byte128Vector blend(Vector<Byte> v, VectorMask<Byte> m) {
409         return (Byte128Vector)
410             super.blendTemplate(Byte128Mask.class,
411                                 (Byte128Vector) v,
412                                 (Byte128Mask) m);  // specialize
413     }
414 
415     @Override
416     @ForceInline
417     public Byte128Vector slice(int origin, Vector<Byte> v) {
418         return (Byte128Vector) super.sliceTemplate(origin, v);  // specialize
419     }
420 
421     @Override
422     @ForceInline
423     public Byte128Vector slice(int origin) {
424         return (Byte128Vector) super.sliceTemplate(origin);  // specialize
425     }
426 
427     @Override
428     @ForceInline
429     public Byte128Vector unslice(int origin, Vector<Byte> w, int part) {
430         return (Byte128Vector) super.unsliceTemplate(origin, w, part);  // specialize
431     }
432 
433     @Override
434     @ForceInline
435     public Byte128Vector unslice(int origin, Vector<Byte> w, int part, VectorMask<Byte> m) {
436         return (Byte128Vector)
437             super.unsliceTemplate(Byte128Mask.class,
438                                   origin, w, part,
439                                   (Byte128Mask) m);  // specialize
440     }
441 
442     @Override
443     @ForceInline
444     public Byte128Vector unslice(int origin) {
445         return (Byte128Vector) super.unsliceTemplate(origin);  // specialize
446     }
447 
448     @Override
449     @ForceInline
450     public Byte128Vector rearrange(VectorShuffle<Byte> s) {
451         return (Byte128Vector)
452             super.rearrangeTemplate(Byte128Shuffle.class,
453                                     (Byte128Shuffle) s);  // specialize
454     }
455 
456     @Override
457     @ForceInline
458     public Byte128Vector rearrange(VectorShuffle<Byte> shuffle,
459                                   VectorMask<Byte> m) {
460         return (Byte128Vector)
461             super.rearrangeTemplate(Byte128Shuffle.class,
462                                     Byte128Mask.class,
463                                     (Byte128Shuffle) shuffle,
464                                     (Byte128Mask) m);  // specialize
465     }
466 
467     @Override
468     @ForceInline
469     public Byte128Vector rearrange(VectorShuffle<Byte> s,
470                                   Vector<Byte> v) {
471         return (Byte128Vector)
472             super.rearrangeTemplate(Byte128Shuffle.class,
473                                     (Byte128Shuffle) s,
474                                     (Byte128Vector) v);  // specialize
475     }
476 
477     @Override
478     @ForceInline
479     public Byte128Vector compress(VectorMask<Byte> m) {
480         return (Byte128Vector)
481             super.compressTemplate(Byte128Mask.class,
482                                    (Byte128Mask) m);  // specialize
483     }
484 
485     @Override
486     @ForceInline
487     public Byte128Vector expand(VectorMask<Byte> m) {
488         return (Byte128Vector)
489             super.expandTemplate(Byte128Mask.class,
490                                    (Byte128Mask) m);  // specialize
491     }
492 
493     @Override
494     @ForceInline
495     public Byte128Vector selectFrom(Vector<Byte> v) {
496         return (Byte128Vector)
497             super.selectFromTemplate((Byte128Vector) v);  // specialize
498     }
499 
500     @Override
501     @ForceInline
502     public Byte128Vector selectFrom(Vector<Byte> v,
503                                    VectorMask<Byte> m) {
504         return (Byte128Vector)
505             super.selectFromTemplate((Byte128Vector) v,
506                                      (Byte128Mask) m);  // specialize
507     }
508 
509 
510     @ForceInline
511     @Override
512     public byte lane(int i) {
513         switch(i) {
514             case 0: return laneHelper(0);
515             case 1: return laneHelper(1);
516             case 2: return laneHelper(2);
517             case 3: return laneHelper(3);
518             case 4: return laneHelper(4);
519             case 5: return laneHelper(5);
520             case 6: return laneHelper(6);
521             case 7: return laneHelper(7);
522             case 8: return laneHelper(8);
523             case 9: return laneHelper(9);
524             case 10: return laneHelper(10);
525             case 11: return laneHelper(11);
526             case 12: return laneHelper(12);
527             case 13: return laneHelper(13);
528             case 14: return laneHelper(14);
529             case 15: return laneHelper(15);
530             default: throw new IllegalArgumentException("Index " + i + " must be zero or positive, and less than " + VLENGTH);
531         }
532     }
533 
534     public byte laneHelper(int i) {
535         return (byte) VectorSupport.extract(
536                                 VCLASS, ETYPE, VLENGTH,
537                                 this, i,
538                                 (vec, ix) -> {
539                                     byte[] vecarr = vec.vec();
540                                     return (long)vecarr[ix];
541                                 });
542     }
543 
544     @ForceInline
545     @Override
546     public Byte128Vector withLane(int i, byte e) {
547         switch (i) {
548             case 0: return withLaneHelper(0, e);
549             case 1: return withLaneHelper(1, e);
550             case 2: return withLaneHelper(2, e);
551             case 3: return withLaneHelper(3, e);
552             case 4: return withLaneHelper(4, e);
553             case 5: return withLaneHelper(5, e);
554             case 6: return withLaneHelper(6, e);
555             case 7: return withLaneHelper(7, e);
556             case 8: return withLaneHelper(8, e);
557             case 9: return withLaneHelper(9, e);
558             case 10: return withLaneHelper(10, e);
559             case 11: return withLaneHelper(11, e);
560             case 12: return withLaneHelper(12, e);
561             case 13: return withLaneHelper(13, e);
562             case 14: return withLaneHelper(14, e);
563             case 15: return withLaneHelper(15, e);
564             default: throw new IllegalArgumentException("Index " + i + " must be zero or positive, and less than " + VLENGTH);
565         }
566     }
567 
568     public Byte128Vector withLaneHelper(int i, byte e) {
569         return VectorSupport.insert(
570                                 VCLASS, ETYPE, VLENGTH,
571                                 this, i, (long)e,
572                                 (v, ix, bits) -> {
573                                     byte[] res = v.vec().clone();
574                                     res[ix] = (byte)bits;
575                                     return v.vectorFactory(res);
576                                 });
577     }
578 
579     // Mask
580 
581     static final class Byte128Mask extends AbstractMask<Byte> {
582         static final int VLENGTH = VSPECIES.laneCount();    // used by the JVM
583         static final Class<Byte> ETYPE = byte.class; // used by the JVM
584 
585         Byte128Mask(boolean[] bits) {
586             this(bits, 0);
587         }
588 
589         Byte128Mask(boolean[] bits, int offset) {
590             super(prepare(bits, offset));
591         }
592 
593         Byte128Mask(boolean val) {
594             super(prepare(val));
595         }
596 
597         private static boolean[] prepare(boolean[] bits, int offset) {
598             boolean[] newBits = new boolean[VSPECIES.laneCount()];
599             for (int i = 0; i < newBits.length; i++) {
600                 newBits[i] = bits[offset + i];
601             }
602             return newBits;
603         }
604 
605         private static boolean[] prepare(boolean val) {
606             boolean[] bits = new boolean[VSPECIES.laneCount()];
607             Arrays.fill(bits, val);
608             return bits;
609         }
610 
611         @ForceInline
612         final @Override
613         public ByteSpecies vspecies() {
614             // ISSUE:  This should probably be a @Stable
615             // field inside AbstractMask, rather than
616             // a megamorphic method.
617             return VSPECIES;
618         }
619 
620         @ForceInline
621         boolean[] getBits() {
622             return (boolean[])getPayload();
623         }
624 
625         @Override
626         Byte128Mask uOp(MUnOp f) {
627             boolean[] res = new boolean[vspecies().laneCount()];
628             boolean[] bits = getBits();
629             for (int i = 0; i < res.length; i++) {
630                 res[i] = f.apply(i, bits[i]);
631             }
632             return new Byte128Mask(res);
633         }
634 
635         @Override
636         Byte128Mask bOp(VectorMask<Byte> m, MBinOp f) {
637             boolean[] res = new boolean[vspecies().laneCount()];
638             boolean[] bits = getBits();
639             boolean[] mbits = ((Byte128Mask)m).getBits();
640             for (int i = 0; i < res.length; i++) {
641                 res[i] = f.apply(i, bits[i], mbits[i]);
642             }
643             return new Byte128Mask(res);
644         }
645 
646         @ForceInline
647         @Override
648         public final
649         Byte128Vector toVector() {
650             return (Byte128Vector) super.toVectorTemplate();  // specialize
651         }
652 
653         /**
654          * Helper function for lane-wise mask conversions.
655          * This function kicks in after intrinsic failure.
656          */
657         @ForceInline
658         private final <E>
659         VectorMask<E> defaultMaskCast(AbstractSpecies<E> dsp) {
660             if (length() != dsp.laneCount())
661                 throw new IllegalArgumentException("VectorMask length and species length differ");
662             boolean[] maskArray = toArray();
663             return  dsp.maskFactory(maskArray).check(dsp);
664         }
665 
666         @Override
667         @ForceInline
668         public <E> VectorMask<E> cast(VectorSpecies<E> dsp) {
669             AbstractSpecies<E> species = (AbstractSpecies<E>) dsp;
670             if (length() != species.laneCount())
671                 throw new IllegalArgumentException("VectorMask length and species length differ");
672 
673             return VectorSupport.convert(VectorSupport.VECTOR_OP_CAST,
674                 this.getClass(), ETYPE, VLENGTH,
675                 species.maskType(), species.elementType(), VLENGTH,
676                 this, species,
677                 (m, s) -> s.maskFactory(m.toArray()).check(s));
678         }
679 
680         @Override
681         @ForceInline
682         public Byte128Mask eq(VectorMask<Byte> mask) {
683             Objects.requireNonNull(mask);
684             Byte128Mask m = (Byte128Mask)mask;
685             return xor(m.not());
686         }
687 
688         // Unary operations
689 
690         @Override
691         @ForceInline
692         public Byte128Mask not() {
693             return xor(maskAll(true));
694         }
695 
696         @Override
697         @ForceInline
698         public Byte128Mask compress() {
699             return (Byte128Mask)VectorSupport.comExpOp(VectorSupport.VECTOR_OP_MASK_COMPRESS,
700                 Byte128Vector.class, Byte128Mask.class, ETYPE, VLENGTH, null, this,
701                 (v1, m1) -> VSPECIES.iota().compare(VectorOperators.LT, m1.trueCount()));
702         }
703 
704 
705         // Binary operations
706 
707         @Override
708         @ForceInline
709         public Byte128Mask and(VectorMask<Byte> mask) {
710             Objects.requireNonNull(mask);
711             Byte128Mask m = (Byte128Mask)mask;
712             return VectorSupport.binaryOp(VECTOR_OP_AND, Byte128Mask.class, null, byte.class, VLENGTH,
713                                           this, m, null,
714                                           (m1, m2, vm) -> m1.bOp(m2, (i, a, b) -> a & b));
715         }
716 
717         @Override
718         @ForceInline
719         public Byte128Mask or(VectorMask<Byte> mask) {
720             Objects.requireNonNull(mask);
721             Byte128Mask m = (Byte128Mask)mask;
722             return VectorSupport.binaryOp(VECTOR_OP_OR, Byte128Mask.class, null, byte.class, VLENGTH,
723                                           this, m, null,
724                                           (m1, m2, vm) -> m1.bOp(m2, (i, a, b) -> a | b));
725         }
726 
727         @ForceInline
728         /* package-private */
729         Byte128Mask xor(VectorMask<Byte> mask) {
730             Objects.requireNonNull(mask);
731             Byte128Mask m = (Byte128Mask)mask;
732             return VectorSupport.binaryOp(VECTOR_OP_XOR, Byte128Mask.class, null, byte.class, VLENGTH,
733                                           this, m, null,
734                                           (m1, m2, vm) -> m1.bOp(m2, (i, a, b) -> a ^ b));
735         }
736 
737         // Mask Query operations
738 
739         @Override
740         @ForceInline
741         public int trueCount() {
742             return (int) VectorSupport.maskReductionCoerced(VECTOR_OP_MASK_TRUECOUNT, Byte128Mask.class, byte.class, VLENGTH, this,
743                                                       (m) -> trueCountHelper(m.getBits()));
744         }
745 
746         @Override
747         @ForceInline
748         public int firstTrue() {
749             return (int) VectorSupport.maskReductionCoerced(VECTOR_OP_MASK_FIRSTTRUE, Byte128Mask.class, byte.class, VLENGTH, this,
750                                                       (m) -> firstTrueHelper(m.getBits()));
751         }
752 
753         @Override
754         @ForceInline
755         public int lastTrue() {
756             return (int) VectorSupport.maskReductionCoerced(VECTOR_OP_MASK_LASTTRUE, Byte128Mask.class, byte.class, VLENGTH, this,
757                                                       (m) -> lastTrueHelper(m.getBits()));
758         }
759 
760         @Override
761         @ForceInline
762         public long toLong() {
763             if (length() > Long.SIZE) {
764                 throw new UnsupportedOperationException("too many lanes for one long");
765             }
766             return VectorSupport.maskReductionCoerced(VECTOR_OP_MASK_TOLONG, Byte128Mask.class, byte.class, VLENGTH, this,
767                                                       (m) -> toLongHelper(m.getBits()));
768         }
769 
770         // Reductions
771 
772         @Override
773         @ForceInline
774         public boolean anyTrue() {
775             return VectorSupport.test(BT_ne, Byte128Mask.class, byte.class, VLENGTH,
776                                          this, vspecies().maskAll(true),
777                                          (m, __) -> anyTrueHelper(((Byte128Mask)m).getBits()));
778         }
779 
780         @Override
781         @ForceInline
782         public boolean allTrue() {
783             return VectorSupport.test(BT_overflow, Byte128Mask.class, byte.class, VLENGTH,
784                                          this, vspecies().maskAll(true),
785                                          (m, __) -> allTrueHelper(((Byte128Mask)m).getBits()));
786         }
787 
788         @ForceInline
789         /*package-private*/
790         static Byte128Mask maskAll(boolean bit) {
791             return VectorSupport.fromBitsCoerced(Byte128Mask.class, byte.class, VLENGTH,
792                                                  (bit ? -1 : 0), MODE_BROADCAST, null,
793                                                  (v, __) -> (v != 0 ? TRUE_MASK : FALSE_MASK));
794         }
795         private static final Byte128Mask  TRUE_MASK = new Byte128Mask(true);
796         private static final Byte128Mask FALSE_MASK = new Byte128Mask(false);
797 
798     }
799 
800     // Shuffle
801 
802     static final class Byte128Shuffle extends AbstractShuffle<Byte> {
803         static final int VLENGTH = VSPECIES.laneCount();    // used by the JVM
804         static final Class<Byte> ETYPE = byte.class; // used by the JVM
805 
806         Byte128Shuffle(byte[] reorder) {
807             super(VLENGTH, reorder);
808         }
809 
810         public Byte128Shuffle(int[] reorder) {
811             super(VLENGTH, reorder);
812         }
813 
814         public Byte128Shuffle(int[] reorder, int i) {
815             super(VLENGTH, reorder, i);
816         }
817 
818         public Byte128Shuffle(IntUnaryOperator fn) {
819             super(VLENGTH, fn);
820         }
821 
822         @Override
823         public ByteSpecies vspecies() {
824             return VSPECIES;
825         }
826 
827         static {
828             // There must be enough bits in the shuffle lanes to encode
829             // VLENGTH valid indexes and VLENGTH exceptional ones.
830             assert(VLENGTH < Byte.MAX_VALUE);
831             assert(Byte.MIN_VALUE <= -VLENGTH);
832         }
833         static final Byte128Shuffle IOTA = new Byte128Shuffle(IDENTITY);
834 
835         @Override
836         @ForceInline
837         public Byte128Vector toVector() {
838             return VectorSupport.shuffleToVector(VCLASS, ETYPE, Byte128Shuffle.class, this, VLENGTH,
839                                                     (s) -> ((Byte128Vector)(((AbstractShuffle<Byte>)(s)).toVectorTemplate())));
840         }
841 
842         @Override
843         @ForceInline
844         public <F> VectorShuffle<F> cast(VectorSpecies<F> s) {
845             AbstractSpecies<F> species = (AbstractSpecies<F>) s;
846             if (length() != species.laneCount())
847                 throw new IllegalArgumentException("VectorShuffle length and species length differ");
848             int[] shuffleArray = toArray();
849             return s.shuffleFromArray(shuffleArray, 0).check(s);
850         }
851 
852         @ForceInline
853         @Override
854         public Byte128Shuffle rearrange(VectorShuffle<Byte> shuffle) {
855             Byte128Shuffle s = (Byte128Shuffle) shuffle;
856             byte[] reorder1 = reorder();
857             byte[] reorder2 = s.reorder();
858             byte[] r = new byte[reorder1.length];
859             for (int i = 0; i < reorder1.length; i++) {
860                 int ssi = reorder2[i];
861                 r[i] = reorder1[ssi];  // throws on exceptional index
862             }
863             return new Byte128Shuffle(r);
864         }
865     }
866 
867     // ================================================
868 
869     // Specialized low-level memory operations.
870 
871     @ForceInline
872     @Override
873     final
874     ByteVector fromArray0(byte[] a, int offset) {
875         return super.fromArray0Template(a, offset);  // specialize
876     }
877 
878     @ForceInline
879     @Override
880     final
881     ByteVector fromArray0(byte[] a, int offset, VectorMask<Byte> m) {
882         return super.fromArray0Template(Byte128Mask.class, a, offset, (Byte128Mask) m);  // specialize
883     }
884 
885 
886 
887     @ForceInline
888     @Override
889     final
890     ByteVector fromBooleanArray0(boolean[] a, int offset) {
891         return super.fromBooleanArray0Template(a, offset);  // specialize
892     }
893 
894     @ForceInline
895     @Override
896     final
897     ByteVector fromBooleanArray0(boolean[] a, int offset, VectorMask<Byte> m) {
898         return super.fromBooleanArray0Template(Byte128Mask.class, a, offset, (Byte128Mask) m);  // specialize
899     }
900 
901     @ForceInline
902     @Override
903     final
904     ByteVector fromMemorySegment0(MemorySegment ms, long offset) {
905         return super.fromMemorySegment0Template(ms, offset);  // specialize
906     }
907 
908     @ForceInline
909     @Override
910     final
911     ByteVector fromMemorySegment0(MemorySegment ms, long offset, VectorMask<Byte> m) {
912         return super.fromMemorySegment0Template(Byte128Mask.class, ms, offset, (Byte128Mask) m);  // specialize
913     }
914 
915     @ForceInline
916     @Override
917     final
918     void intoArray0(byte[] a, int offset) {
919         super.intoArray0Template(a, offset);  // specialize
920     }
921 
922     @ForceInline
923     @Override
924     final
925     void intoArray0(byte[] a, int offset, VectorMask<Byte> m) {
926         super.intoArray0Template(Byte128Mask.class, a, offset, (Byte128Mask) m);
927     }
928 
929 
930     @ForceInline
931     @Override
932     final
933     void intoBooleanArray0(boolean[] a, int offset, VectorMask<Byte> m) {
934         super.intoBooleanArray0Template(Byte128Mask.class, a, offset, (Byte128Mask) m);
935     }
936 
937     @ForceInline
938     @Override
939     final
940     void intoMemorySegment0(MemorySegment ms, long offset, VectorMask<Byte> m) {
941         super.intoMemorySegment0Template(Byte128Mask.class, ms, offset, (Byte128Mask) m);
942     }
943 
944 
945     // End of specialized low-level memory operations.
946 
947     // ================================================
948 
949 }