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