1 /*
  2  * Copyright (c) 2017, 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.  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.nio.ByteBuffer;
 28 import java.util.Arrays;
 29 import java.util.Objects;
 30 import java.util.function.IntUnaryOperator;
 31 
 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 Byte512Vector extends ByteVector {
 43     static final ByteSpecies VSPECIES =
 44         (ByteSpecies) ByteVector.SPECIES_512;
 45 
 46     static final VectorShape VSHAPE =
 47         VSPECIES.vectorShape();
 48 
 49     static final Class<Byte512Vector> VCLASS = Byte512Vector.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     Byte512Vector(byte[] v) {
 58         super(v);
 59     }
 60 
 61     // For compatibility as Byte512Vector::new,
 62     // stored into species.vectorFactory.
 63     Byte512Vector(Object v) {
 64         this((byte[]) v);
 65     }
 66 
 67     static final Byte512Vector ZERO = new Byte512Vector(new byte[VLENGTH]);
 68     static final Byte512Vector IOTA = new Byte512Vector(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 Byte512Vector broadcast(byte e) {
125         return (Byte512Vector) super.broadcastTemplate(e);  // specialize
126     }
127 
128     @Override
129     @ForceInline
130     public final Byte512Vector broadcast(long e) {
131         return (Byte512Vector) super.broadcastTemplate(e);  // specialize
132     }
133 
134     @Override
135     @ForceInline
136     Byte512Mask maskFromArray(boolean[] bits) {
137         return new Byte512Mask(bits);
138     }
139 
140     @Override
141     @ForceInline
142     Byte512Shuffle iotaShuffle() { return Byte512Shuffle.IOTA; }
143 
144     @ForceInline
145     Byte512Shuffle iotaShuffle(int start, int step, boolean wrap) {
146       if (wrap) {
147         return (Byte512Shuffle)VectorSupport.shuffleIota(ETYPE, Byte512Shuffle.class, VSPECIES, VLENGTH, start, step, 1,
148                 (l, lstart, lstep, s) -> s.shuffleFromOp(i -> (VectorIntrinsics.wrapToRange(i*lstep + lstart, l))));
149       } else {
150         return (Byte512Shuffle)VectorSupport.shuffleIota(ETYPE, Byte512Shuffle.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     Byte512Shuffle shuffleFromBytes(byte[] reorder) { return new Byte512Shuffle(reorder); }
158 
159     @Override
160     @ForceInline
161     Byte512Shuffle shuffleFromArray(int[] indexes, int i) { return new Byte512Shuffle(indexes, i); }
162 
163     @Override
164     @ForceInline
165     Byte512Shuffle shuffleFromOp(IntUnaryOperator fn) { return new Byte512Shuffle(fn); }
166 
167     // Make a vector of the same species but the given elements:
168     @ForceInline
169     final @Override
170     Byte512Vector vectorFactory(byte[] vec) {
171         return new Byte512Vector(vec);
172     }
173 
174     @ForceInline
175     final @Override
176     Byte512Vector asByteVectorRaw() {
177         return (Byte512Vector) 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     Byte512Vector uOp(FUnOp f) {
191         return (Byte512Vector) super.uOpTemplate(f);  // specialize
192     }
193 
194     @ForceInline
195     final @Override
196     Byte512Vector uOp(VectorMask<Byte> m, FUnOp f) {
197         return (Byte512Vector)
198             super.uOpTemplate((Byte512Mask)m, f);  // specialize
199     }
200 
201     // Binary operator
202 
203     @ForceInline
204     final @Override
205     Byte512Vector bOp(Vector<Byte> v, FBinOp f) {
206         return (Byte512Vector) super.bOpTemplate((Byte512Vector)v, f);  // specialize
207     }
208 
209     @ForceInline
210     final @Override
211     Byte512Vector bOp(Vector<Byte> v,
212                      VectorMask<Byte> m, FBinOp f) {
213         return (Byte512Vector)
214             super.bOpTemplate((Byte512Vector)v, (Byte512Mask)m,
215                               f);  // specialize
216     }
217 
218     // Ternary operator
219 
220     @ForceInline
221     final @Override
222     Byte512Vector tOp(Vector<Byte> v1, Vector<Byte> v2, FTriOp f) {
223         return (Byte512Vector)
224             super.tOpTemplate((Byte512Vector)v1, (Byte512Vector)v2,
225                               f);  // specialize
226     }
227 
228     @ForceInline
229     final @Override
230     Byte512Vector tOp(Vector<Byte> v1, Vector<Byte> v2,
231                      VectorMask<Byte> m, FTriOp f) {
232         return (Byte512Vector)
233             super.tOpTemplate((Byte512Vector)v1, (Byte512Vector)v2,
234                               (Byte512Mask)m, f);  // specialize
235     }
236 
237     @ForceInline
238     final @Override
239     byte rOp(byte v, FBinOp f) {
240         return super.rOpTemplate(v, 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 Byte512Vector lanewise(Unary op) {
273         return (Byte512Vector) super.lanewiseTemplate(op);  // specialize
274     }
275 
276     @Override
277     @ForceInline
278     public Byte512Vector lanewise(Binary op, Vector<Byte> v) {
279         return (Byte512Vector) super.lanewiseTemplate(op, v);  // specialize
280     }
281 
282     /*package-private*/
283     @Override
284     @ForceInline Byte512Vector
285     lanewiseShift(VectorOperators.Binary op, int e) {
286         return (Byte512Vector) super.lanewiseShiftTemplate(op, e);  // specialize
287     }
288 
289     /*package-private*/
290     @Override
291     @ForceInline
292     public final
293     Byte512Vector
294     lanewise(VectorOperators.Ternary op, Vector<Byte> v1, Vector<Byte> v2) {
295         return (Byte512Vector) super.lanewiseTemplate(op, v1, v2);  // specialize
296     }
297 
298     @Override
299     @ForceInline
300     public final
301     Byte512Vector addIndex(int scale) {
302         return (Byte512Vector) super.addIndexTemplate(scale);  // specialize
303     }
304 
305     // Type specific horizontal reductions
306 
307     @Override
308     @ForceInline
309     public final byte reduceLanes(VectorOperators.Associative op) {
310         return super.reduceLanesTemplate(op);  // specialized
311     }
312 
313     @Override
314     @ForceInline
315     public final byte reduceLanes(VectorOperators.Associative op,
316                                     VectorMask<Byte> m) {
317         return super.reduceLanesTemplate(op, m);  // specialized
318     }
319 
320     @Override
321     @ForceInline
322     public final long reduceLanesToLong(VectorOperators.Associative op) {
323         return (long) super.reduceLanesTemplate(op);  // specialized
324     }
325 
326     @Override
327     @ForceInline
328     public final long reduceLanesToLong(VectorOperators.Associative op,
329                                         VectorMask<Byte> m) {
330         return (long) super.reduceLanesTemplate(op, m);  // specialized
331     }
332 
333     @ForceInline
334     public VectorShuffle<Byte> toShuffle() {
335         return super.toShuffleTemplate(Byte512Shuffle.class); // specialize
336     }
337 
338     // Specialized unary testing
339 
340     @Override
341     @ForceInline
342     public final Byte512Mask test(Test op) {
343         return super.testTemplate(Byte512Mask.class, op);  // specialize
344     }
345 
346     // Specialized comparisons
347 
348     @Override
349     @ForceInline
350     public final Byte512Mask compare(Comparison op, Vector<Byte> v) {
351         return super.compareTemplate(Byte512Mask.class, op, v);  // specialize
352     }
353 
354     @Override
355     @ForceInline
356     public final Byte512Mask compare(Comparison op, byte s) {
357         return super.compareTemplate(Byte512Mask.class, op, s);  // specialize
358     }
359 
360     @Override
361     @ForceInline
362     public final Byte512Mask compare(Comparison op, long s) {
363         return super.compareTemplate(Byte512Mask.class, op, s);  // specialize
364     }
365 
366     @Override
367     @ForceInline
368     public Byte512Vector blend(Vector<Byte> v, VectorMask<Byte> m) {
369         return (Byte512Vector)
370             super.blendTemplate(Byte512Mask.class,
371                                 (Byte512Vector) v,
372                                 (Byte512Mask) m);  // specialize
373     }
374 
375     @Override
376     @ForceInline
377     public Byte512Vector slice(int origin, Vector<Byte> v) {
378         return (Byte512Vector) super.sliceTemplate(origin, v);  // specialize
379     }
380 
381     @Override
382     @ForceInline
383     public Byte512Vector slice(int origin) {
384         return (Byte512Vector) super.sliceTemplate(origin);  // specialize
385     }
386 
387     @Override
388     @ForceInline
389     public Byte512Vector unslice(int origin, Vector<Byte> w, int part) {
390         return (Byte512Vector) super.unsliceTemplate(origin, w, part);  // specialize
391     }
392 
393     @Override
394     @ForceInline
395     public Byte512Vector unslice(int origin, Vector<Byte> w, int part, VectorMask<Byte> m) {
396         return (Byte512Vector)
397             super.unsliceTemplate(Byte512Mask.class,
398                                   origin, w, part,
399                                   (Byte512Mask) m);  // specialize
400     }
401 
402     @Override
403     @ForceInline
404     public Byte512Vector unslice(int origin) {
405         return (Byte512Vector) super.unsliceTemplate(origin);  // specialize
406     }
407 
408     @Override
409     @ForceInline
410     public Byte512Vector rearrange(VectorShuffle<Byte> s) {
411         return (Byte512Vector)
412             super.rearrangeTemplate(Byte512Shuffle.class,
413                                     (Byte512Shuffle) s);  // specialize
414     }
415 
416     @Override
417     @ForceInline
418     public Byte512Vector rearrange(VectorShuffle<Byte> shuffle,
419                                   VectorMask<Byte> m) {
420         return (Byte512Vector)
421             super.rearrangeTemplate(Byte512Shuffle.class,
422                                     (Byte512Shuffle) shuffle,
423                                     (Byte512Mask) m);  // specialize
424     }
425 
426     @Override
427     @ForceInline
428     public Byte512Vector rearrange(VectorShuffle<Byte> s,
429                                   Vector<Byte> v) {
430         return (Byte512Vector)
431             super.rearrangeTemplate(Byte512Shuffle.class,
432                                     (Byte512Shuffle) s,
433                                     (Byte512Vector) v);  // specialize
434     }
435 
436     @Override
437     @ForceInline
438     public Byte512Vector selectFrom(Vector<Byte> v) {
439         return (Byte512Vector)
440             super.selectFromTemplate((Byte512Vector) v);  // specialize
441     }
442 
443     @Override
444     @ForceInline
445     public Byte512Vector selectFrom(Vector<Byte> v,
446                                    VectorMask<Byte> m) {
447         return (Byte512Vector)
448             super.selectFromTemplate((Byte512Vector) v,
449                                      (Byte512Mask) m);  // specialize
450     }
451 
452 
453     @ForceInline
454     @Override
455     public byte lane(int i) {
456         switch(i) {
457             case 0: return laneHelper(0);
458             case 1: return laneHelper(1);
459             case 2: return laneHelper(2);
460             case 3: return laneHelper(3);
461             case 4: return laneHelper(4);
462             case 5: return laneHelper(5);
463             case 6: return laneHelper(6);
464             case 7: return laneHelper(7);
465             case 8: return laneHelper(8);
466             case 9: return laneHelper(9);
467             case 10: return laneHelper(10);
468             case 11: return laneHelper(11);
469             case 12: return laneHelper(12);
470             case 13: return laneHelper(13);
471             case 14: return laneHelper(14);
472             case 15: return laneHelper(15);
473             case 16: return laneHelper(16);
474             case 17: return laneHelper(17);
475             case 18: return laneHelper(18);
476             case 19: return laneHelper(19);
477             case 20: return laneHelper(20);
478             case 21: return laneHelper(21);
479             case 22: return laneHelper(22);
480             case 23: return laneHelper(23);
481             case 24: return laneHelper(24);
482             case 25: return laneHelper(25);
483             case 26: return laneHelper(26);
484             case 27: return laneHelper(27);
485             case 28: return laneHelper(28);
486             case 29: return laneHelper(29);
487             case 30: return laneHelper(30);
488             case 31: return laneHelper(31);
489             case 32: return laneHelper(32);
490             case 33: return laneHelper(33);
491             case 34: return laneHelper(34);
492             case 35: return laneHelper(35);
493             case 36: return laneHelper(36);
494             case 37: return laneHelper(37);
495             case 38: return laneHelper(38);
496             case 39: return laneHelper(39);
497             case 40: return laneHelper(40);
498             case 41: return laneHelper(41);
499             case 42: return laneHelper(42);
500             case 43: return laneHelper(43);
501             case 44: return laneHelper(44);
502             case 45: return laneHelper(45);
503             case 46: return laneHelper(46);
504             case 47: return laneHelper(47);
505             case 48: return laneHelper(48);
506             case 49: return laneHelper(49);
507             case 50: return laneHelper(50);
508             case 51: return laneHelper(51);
509             case 52: return laneHelper(52);
510             case 53: return laneHelper(53);
511             case 54: return laneHelper(54);
512             case 55: return laneHelper(55);
513             case 56: return laneHelper(56);
514             case 57: return laneHelper(57);
515             case 58: return laneHelper(58);
516             case 59: return laneHelper(59);
517             case 60: return laneHelper(60);
518             case 61: return laneHelper(61);
519             case 62: return laneHelper(62);
520             case 63: return laneHelper(63);
521             default: throw new IllegalArgumentException("Index " + i + " must be zero or positive, and less than " + VLENGTH);
522         }
523     }
524 
525     public byte laneHelper(int i) {
526         return (byte) VectorSupport.extract(
527                                 VCLASS, ETYPE, VLENGTH,
528                                 this, i,
529                                 (vec, ix) -> {
530                                     byte[] vecarr = vec.vec();
531                                     return (long)vecarr[ix];
532                                 });
533     }
534 
535     @ForceInline
536     @Override
537     public Byte512Vector withLane(int i, byte e) {
538         switch (i) {
539             case 0: return withLaneHelper(0, e);
540             case 1: return withLaneHelper(1, e);
541             case 2: return withLaneHelper(2, e);
542             case 3: return withLaneHelper(3, e);
543             case 4: return withLaneHelper(4, e);
544             case 5: return withLaneHelper(5, e);
545             case 6: return withLaneHelper(6, e);
546             case 7: return withLaneHelper(7, e);
547             case 8: return withLaneHelper(8, e);
548             case 9: return withLaneHelper(9, e);
549             case 10: return withLaneHelper(10, e);
550             case 11: return withLaneHelper(11, e);
551             case 12: return withLaneHelper(12, e);
552             case 13: return withLaneHelper(13, e);
553             case 14: return withLaneHelper(14, e);
554             case 15: return withLaneHelper(15, e);
555             case 16: return withLaneHelper(16, e);
556             case 17: return withLaneHelper(17, e);
557             case 18: return withLaneHelper(18, e);
558             case 19: return withLaneHelper(19, e);
559             case 20: return withLaneHelper(20, e);
560             case 21: return withLaneHelper(21, e);
561             case 22: return withLaneHelper(22, e);
562             case 23: return withLaneHelper(23, e);
563             case 24: return withLaneHelper(24, e);
564             case 25: return withLaneHelper(25, e);
565             case 26: return withLaneHelper(26, e);
566             case 27: return withLaneHelper(27, e);
567             case 28: return withLaneHelper(28, e);
568             case 29: return withLaneHelper(29, e);
569             case 30: return withLaneHelper(30, e);
570             case 31: return withLaneHelper(31, e);
571             case 32: return withLaneHelper(32, e);
572             case 33: return withLaneHelper(33, e);
573             case 34: return withLaneHelper(34, e);
574             case 35: return withLaneHelper(35, e);
575             case 36: return withLaneHelper(36, e);
576             case 37: return withLaneHelper(37, e);
577             case 38: return withLaneHelper(38, e);
578             case 39: return withLaneHelper(39, e);
579             case 40: return withLaneHelper(40, e);
580             case 41: return withLaneHelper(41, e);
581             case 42: return withLaneHelper(42, e);
582             case 43: return withLaneHelper(43, e);
583             case 44: return withLaneHelper(44, e);
584             case 45: return withLaneHelper(45, e);
585             case 46: return withLaneHelper(46, e);
586             case 47: return withLaneHelper(47, e);
587             case 48: return withLaneHelper(48, e);
588             case 49: return withLaneHelper(49, e);
589             case 50: return withLaneHelper(50, e);
590             case 51: return withLaneHelper(51, e);
591             case 52: return withLaneHelper(52, e);
592             case 53: return withLaneHelper(53, e);
593             case 54: return withLaneHelper(54, e);
594             case 55: return withLaneHelper(55, e);
595             case 56: return withLaneHelper(56, e);
596             case 57: return withLaneHelper(57, e);
597             case 58: return withLaneHelper(58, e);
598             case 59: return withLaneHelper(59, e);
599             case 60: return withLaneHelper(60, e);
600             case 61: return withLaneHelper(61, e);
601             case 62: return withLaneHelper(62, e);
602             case 63: return withLaneHelper(63, e);
603             default: throw new IllegalArgumentException("Index " + i + " must be zero or positive, and less than " + VLENGTH);
604         }
605     }
606 
607     public Byte512Vector withLaneHelper(int i, byte e) {
608         return VectorSupport.insert(
609                                 VCLASS, ETYPE, VLENGTH,
610                                 this, i, (long)e,
611                                 (v, ix, bits) -> {
612                                     byte[] res = v.vec().clone();
613                                     res[ix] = (byte)bits;
614                                     return v.vectorFactory(res);
615                                 });
616     }
617 
618     // Mask
619 
620     static final class Byte512Mask extends AbstractMask<Byte> {
621         static final int VLENGTH = VSPECIES.laneCount();    // used by the JVM
622         static final Class<Byte> ETYPE = byte.class; // used by the JVM
623 
624         Byte512Mask(boolean[] bits) {
625             this(bits, 0);
626         }
627 
628         Byte512Mask(boolean[] bits, int offset) {
629             super(prepare(bits, offset));
630         }
631 
632         Byte512Mask(boolean val) {
633             super(prepare(val));
634         }
635 
636         private static boolean[] prepare(boolean[] bits, int offset) {
637             boolean[] newBits = new boolean[VSPECIES.laneCount()];
638             for (int i = 0; i < newBits.length; i++) {
639                 newBits[i] = bits[offset + i];
640             }
641             return newBits;
642         }
643 
644         private static boolean[] prepare(boolean val) {
645             boolean[] bits = new boolean[VSPECIES.laneCount()];
646             Arrays.fill(bits, val);
647             return bits;
648         }
649 
650         @ForceInline
651         final @Override
652         public ByteSpecies vspecies() {
653             // ISSUE:  This should probably be a @Stable
654             // field inside AbstractMask, rather than
655             // a megamorphic method.
656             return VSPECIES;
657         }
658 
659         @ForceInline
660         boolean[] getBits() {
661             return (boolean[])getPayload();
662         }
663 
664         @Override
665         Byte512Mask uOp(MUnOp f) {
666             boolean[] res = new boolean[vspecies().laneCount()];
667             boolean[] bits = getBits();
668             for (int i = 0; i < res.length; i++) {
669                 res[i] = f.apply(i, bits[i]);
670             }
671             return new Byte512Mask(res);
672         }
673 
674         @Override
675         Byte512Mask bOp(VectorMask<Byte> m, MBinOp f) {
676             boolean[] res = new boolean[vspecies().laneCount()];
677             boolean[] bits = getBits();
678             boolean[] mbits = ((Byte512Mask)m).getBits();
679             for (int i = 0; i < res.length; i++) {
680                 res[i] = f.apply(i, bits[i], mbits[i]);
681             }
682             return new Byte512Mask(res);
683         }
684 
685         @ForceInline
686         @Override
687         public final
688         Byte512Vector toVector() {
689             return (Byte512Vector) super.toVectorTemplate();  // specialize
690         }
691 
692         /**
693          * Helper function for lane-wise mask conversions.
694          * This function kicks in after intrinsic failure.
695          */
696         @ForceInline
697         private final <E>
698         VectorMask<E> defaultMaskCast(AbstractSpecies<E> dsp) {
699             if (length() != dsp.laneCount())
700                 throw new IllegalArgumentException("VectorMask length and species length differ");
701             boolean[] maskArray = toArray();
702             return  dsp.maskFactory(maskArray).check(dsp);
703         }
704 
705         @Override
706         @ForceInline
707         public <E> VectorMask<E> cast(VectorSpecies<E> dsp) {
708             AbstractSpecies<E> species = (AbstractSpecies<E>) dsp;
709             if (length() != species.laneCount())
710                 throw new IllegalArgumentException("VectorMask length and species length differ");
711             if (VSIZE == species.vectorBitSize()) {
712                 Class<?> dtype = species.elementType();
713                 Class<?> dmtype = species.maskType();
714                 return VectorSupport.convert(VectorSupport.VECTOR_OP_REINTERPRET,
715                     this.getClass(), ETYPE, VLENGTH,
716                     dmtype, dtype, VLENGTH,
717                     this, species,
718                     Byte512Mask::defaultMaskCast);
719             }
720             return this.defaultMaskCast(species);
721         }
722 
723         @Override
724         @ForceInline
725         public Byte512Mask eq(VectorMask<Byte> mask) {
726             Objects.requireNonNull(mask);
727             Byte512Mask m = (Byte512Mask)mask;
728             return xor(m.not());
729         }
730 
731         // Unary operations
732 
733         @Override
734         @ForceInline
735         public Byte512Mask not() {
736             return xor(maskAll(true));
737         }
738 
739         // Binary operations
740 
741         @Override
742         @ForceInline
743         public Byte512Mask and(VectorMask<Byte> mask) {
744             Objects.requireNonNull(mask);
745             Byte512Mask m = (Byte512Mask)mask;
746             return VectorSupport.binaryOp(VECTOR_OP_AND, Byte512Mask.class, byte.class, VLENGTH,
747                                              this, m,
748                                              (m1, m2) -> m1.bOp(m2, (i, a, b) -> a & b));
749         }
750 
751         @Override
752         @ForceInline
753         public Byte512Mask or(VectorMask<Byte> mask) {
754             Objects.requireNonNull(mask);
755             Byte512Mask m = (Byte512Mask)mask;
756             return VectorSupport.binaryOp(VECTOR_OP_OR, Byte512Mask.class, byte.class, VLENGTH,
757                                              this, m,
758                                              (m1, m2) -> m1.bOp(m2, (i, a, b) -> a | b));
759         }
760 
761         @ForceInline
762         /* package-private */
763         Byte512Mask xor(VectorMask<Byte> mask) {
764             Objects.requireNonNull(mask);
765             Byte512Mask m = (Byte512Mask)mask;
766             return VectorSupport.binaryOp(VECTOR_OP_XOR, Byte512Mask.class, byte.class, VLENGTH,
767                                           this, m,
768                                           (m1, m2) -> m1.bOp(m2, (i, a, b) -> a ^ b));
769         }
770 
771         // Mask Query operations
772 
773         @Override
774         @ForceInline
775         public int trueCount() {
776             return VectorSupport.maskReductionCoerced(VECTOR_OP_MASK_TRUECOUNT, Byte512Mask.class, byte.class, VLENGTH, this,
777                                                       (m) -> trueCountHelper(((Byte512Mask)m).getBits()));
778         }
779 
780         @Override
781         @ForceInline
782         public int firstTrue() {
783             return VectorSupport.maskReductionCoerced(VECTOR_OP_MASK_FIRSTTRUE, Byte512Mask.class, byte.class, VLENGTH, this,
784                                                       (m) -> firstTrueHelper(((Byte512Mask)m).getBits()));
785         }
786 
787         @Override
788         @ForceInline
789         public int lastTrue() {
790             return VectorSupport.maskReductionCoerced(VECTOR_OP_MASK_LASTTRUE, Byte512Mask.class, byte.class, VLENGTH, this,
791                                                       (m) -> lastTrueHelper(((Byte512Mask)m).getBits()));
792         }
793 
794         // Reductions
795 
796         @Override
797         @ForceInline
798         public boolean anyTrue() {
799             return VectorSupport.test(BT_ne, Byte512Mask.class, byte.class, VLENGTH,
800                                          this, vspecies().maskAll(true),
801                                          (m, __) -> anyTrueHelper(((Byte512Mask)m).getBits()));
802         }
803 
804         @Override
805         @ForceInline
806         public boolean allTrue() {
807             return VectorSupport.test(BT_overflow, Byte512Mask.class, byte.class, VLENGTH,
808                                          this, vspecies().maskAll(true),
809                                          (m, __) -> allTrueHelper(((Byte512Mask)m).getBits()));
810         }
811 
812         @ForceInline
813         /*package-private*/
814         static Byte512Mask maskAll(boolean bit) {
815             return VectorSupport.broadcastCoerced(Byte512Mask.class, byte.class, VLENGTH,
816                                                   (bit ? -1 : 0), null,
817                                                   (v, __) -> (v != 0 ? TRUE_MASK : FALSE_MASK));
818         }
819         private static final Byte512Mask  TRUE_MASK = new Byte512Mask(true);
820         private static final Byte512Mask FALSE_MASK = new Byte512Mask(false);
821 
822     }
823 
824     // Shuffle
825 
826     static final class Byte512Shuffle extends AbstractShuffle<Byte> {
827         static final int VLENGTH = VSPECIES.laneCount();    // used by the JVM
828         static final Class<Byte> ETYPE = byte.class; // used by the JVM
829 
830         Byte512Shuffle(byte[] reorder) {
831             super(VLENGTH, reorder);
832         }
833 
834         public Byte512Shuffle(int[] reorder) {
835             super(VLENGTH, reorder);
836         }
837 
838         public Byte512Shuffle(int[] reorder, int i) {
839             super(VLENGTH, reorder, i);
840         }
841 
842         public Byte512Shuffle(IntUnaryOperator fn) {
843             super(VLENGTH, fn);
844         }
845 
846         @Override
847         public ByteSpecies vspecies() {
848             return VSPECIES;
849         }
850 
851         static {
852             // There must be enough bits in the shuffle lanes to encode
853             // VLENGTH valid indexes and VLENGTH exceptional ones.
854             assert(VLENGTH < Byte.MAX_VALUE);
855             assert(Byte.MIN_VALUE <= -VLENGTH);
856         }
857         static final Byte512Shuffle IOTA = new Byte512Shuffle(IDENTITY);
858 
859         @Override
860         @ForceInline
861         public Byte512Vector toVector() {
862             return VectorSupport.shuffleToVector(VCLASS, ETYPE, Byte512Shuffle.class, this, VLENGTH,
863                                                     (s) -> ((Byte512Vector)(((AbstractShuffle<Byte>)(s)).toVectorTemplate())));
864         }
865 
866         @Override
867         @ForceInline
868         public <F> VectorShuffle<F> cast(VectorSpecies<F> s) {
869             AbstractSpecies<F> species = (AbstractSpecies<F>) s;
870             if (length() != species.laneCount())
871                 throw new IllegalArgumentException("VectorShuffle length and species length differ");
872             int[] shuffleArray = toArray();
873             return s.shuffleFromArray(shuffleArray, 0).check(s);
874         }
875 
876         @ForceInline
877         @Override
878         public Byte512Shuffle rearrange(VectorShuffle<Byte> shuffle) {
879             Byte512Shuffle s = (Byte512Shuffle) shuffle;
880             byte[] reorder1 = reorder();
881             byte[] reorder2 = s.reorder();
882             byte[] r = new byte[reorder1.length];
883             for (int i = 0; i < reorder1.length; i++) {
884                 int ssi = reorder2[i];
885                 r[i] = reorder1[ssi];  // throws on exceptional index
886             }
887             return new Byte512Shuffle(r);
888         }
889     }
890 
891     // ================================================
892 
893     // Specialized low-level memory operations.
894 
895     @ForceInline
896     @Override
897     final
898     ByteVector fromArray0(byte[] a, int offset) {
899         return super.fromArray0Template(a, offset);  // specialize
900     }
901 
902 
903     @ForceInline
904     @Override
905     final
906     ByteVector fromBooleanArray0(boolean[] a, int offset) {
907         return super.fromBooleanArray0Template(a, offset);  // specialize
908     }
909 
910     @ForceInline
911     @Override
912     final
913     ByteVector fromByteArray0(byte[] a, int offset) {
914         return super.fromByteArray0Template(a, offset);  // specialize
915     }
916 
917     @ForceInline
918     @Override
919     final
920     ByteVector fromByteBuffer0(ByteBuffer bb, int offset) {
921         return super.fromByteBuffer0Template(bb, offset);  // specialize
922     }
923 
924     @ForceInline
925     @Override
926     final
927     void intoArray0(byte[] a, int offset) {
928         super.intoArray0Template(a, offset);  // specialize
929     }
930 
931     @ForceInline
932     @Override
933     final
934     void intoByteArray0(byte[] a, int offset) {
935         super.intoByteArray0Template(a, offset);  // specialize
936     }
937 
938     // End of specialized low-level memory operations.
939 
940     // ================================================
941 
942 }