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 selectFrom(Vector<Byte> v) {
474         return (ByteMaxVector)
475             super.selectFromTemplate((ByteMaxVector) v);  // specialize
476     }
477 
478     @Override
479     @ForceInline
480     public ByteMaxVector selectFrom(Vector<Byte> v,
481                                    VectorMask<Byte> m) {
482         return (ByteMaxVector)
483             super.selectFromTemplate((ByteMaxVector) v,
484                                      (ByteMaxMask) m);  // specialize
485     }
486 
487 
488     @ForceInline
489     @Override
490     public byte lane(int i) {
491         if (i < 0 || i >= VLENGTH) {
492             throw new IllegalArgumentException("Index " + i + " must be zero or positive, and less than " + VLENGTH);
493         }
494         return laneHelper(i);
495     }
496 
497     public byte laneHelper(int i) {
498         return (byte) VectorSupport.extract(
499                                 VCLASS, ETYPE, VLENGTH,
500                                 this, i,
501                                 (vec, ix) -> {
502                                     byte[] vecarr = vec.vec();
503                                     return (long)vecarr[ix];
504                                 });
505     }
506 
507     @ForceInline
508     @Override
509     public ByteMaxVector withLane(int i, byte e) {
510         if (i < 0 || i >= VLENGTH) {
511             throw new IllegalArgumentException("Index " + i + " must be zero or positive, and less than " + VLENGTH);
512         }
513         return withLaneHelper(i, e);
514     }
515 
516     public ByteMaxVector withLaneHelper(int i, byte e) {
517         return VectorSupport.insert(
518                                 VCLASS, ETYPE, VLENGTH,
519                                 this, i, (long)e,
520                                 (v, ix, bits) -> {
521                                     byte[] res = v.vec().clone();
522                                     res[ix] = (byte)bits;
523                                     return v.vectorFactory(res);
524                                 });
525     }
526 
527     // Mask
528 
529     static final class ByteMaxMask extends AbstractMask<Byte> {
530         static final int VLENGTH = VSPECIES.laneCount();    // used by the JVM
531         static final Class<Byte> ETYPE = byte.class; // used by the JVM
532 
533         ByteMaxMask(boolean[] bits) {
534             this(bits, 0);
535         }
536 
537         ByteMaxMask(boolean[] bits, int offset) {
538             super(prepare(bits, offset));
539         }
540 
541         ByteMaxMask(boolean val) {
542             super(prepare(val));
543         }
544 
545         private static boolean[] prepare(boolean[] bits, int offset) {
546             boolean[] newBits = new boolean[VSPECIES.laneCount()];
547             for (int i = 0; i < newBits.length; i++) {
548                 newBits[i] = bits[offset + i];
549             }
550             return newBits;
551         }
552 
553         private static boolean[] prepare(boolean val) {
554             boolean[] bits = new boolean[VSPECIES.laneCount()];
555             Arrays.fill(bits, val);
556             return bits;
557         }
558 
559         @ForceInline
560         final @Override
561         public ByteSpecies vspecies() {
562             // ISSUE:  This should probably be a @Stable
563             // field inside AbstractMask, rather than
564             // a megamorphic method.
565             return VSPECIES;
566         }
567 
568         @ForceInline
569         boolean[] getBits() {
570             return (boolean[])getPayload();
571         }
572 
573         @Override
574         ByteMaxMask uOp(MUnOp f) {
575             boolean[] res = new boolean[vspecies().laneCount()];
576             boolean[] bits = getBits();
577             for (int i = 0; i < res.length; i++) {
578                 res[i] = f.apply(i, bits[i]);
579             }
580             return new ByteMaxMask(res);
581         }
582 
583         @Override
584         ByteMaxMask bOp(VectorMask<Byte> m, MBinOp f) {
585             boolean[] res = new boolean[vspecies().laneCount()];
586             boolean[] bits = getBits();
587             boolean[] mbits = ((ByteMaxMask)m).getBits();
588             for (int i = 0; i < res.length; i++) {
589                 res[i] = f.apply(i, bits[i], mbits[i]);
590             }
591             return new ByteMaxMask(res);
592         }
593 
594         @ForceInline
595         @Override
596         public final
597         ByteMaxVector toVector() {
598             return (ByteMaxVector) super.toVectorTemplate();  // specialize
599         }
600 
601         /**
602          * Helper function for lane-wise mask conversions.
603          * This function kicks in after intrinsic failure.
604          */
605         @ForceInline
606         private final <E>
607         VectorMask<E> defaultMaskCast(AbstractSpecies<E> dsp) {
608             if (length() != dsp.laneCount())
609                 throw new IllegalArgumentException("VectorMask length and species length differ");
610             boolean[] maskArray = toArray();
611             return  dsp.maskFactory(maskArray).check(dsp);
612         }
613 
614         @Override
615         @ForceInline
616         public <E> VectorMask<E> cast(VectorSpecies<E> dsp) {
617             AbstractSpecies<E> species = (AbstractSpecies<E>) dsp;
618             if (length() != species.laneCount())
619                 throw new IllegalArgumentException("VectorMask length and species length differ");
620 
621             return VectorSupport.convert(VectorSupport.VECTOR_OP_CAST,
622                 this.getClass(), ETYPE, VLENGTH,
623                 species.maskType(), species.elementType(), VLENGTH,
624                 this, species,
625                 (m, s) -> s.maskFactory(m.toArray()).check(s));
626         }
627 
628         @Override
629         @ForceInline
630         public ByteMaxMask eq(VectorMask<Byte> mask) {
631             Objects.requireNonNull(mask);
632             ByteMaxMask m = (ByteMaxMask)mask;
633             return xor(m.not());
634         }
635 
636         // Unary operations
637 
638         @Override
639         @ForceInline
640         public ByteMaxMask not() {
641             return xor(maskAll(true));
642         }
643 









644         // Binary operations
645 
646         @Override
647         @ForceInline
648         public ByteMaxMask and(VectorMask<Byte> mask) {
649             Objects.requireNonNull(mask);
650             ByteMaxMask m = (ByteMaxMask)mask;
651             return VectorSupport.binaryOp(VECTOR_OP_AND, ByteMaxMask.class, null, byte.class, VLENGTH,
652                                           this, m, null,
653                                           (m1, m2, vm) -> m1.bOp(m2, (i, a, b) -> a & b));
654         }
655 
656         @Override
657         @ForceInline
658         public ByteMaxMask or(VectorMask<Byte> mask) {
659             Objects.requireNonNull(mask);
660             ByteMaxMask m = (ByteMaxMask)mask;
661             return VectorSupport.binaryOp(VECTOR_OP_OR, ByteMaxMask.class, null, byte.class, VLENGTH,
662                                           this, m, null,
663                                           (m1, m2, vm) -> m1.bOp(m2, (i, a, b) -> a | b));
664         }
665 
666         @ForceInline
667         /* package-private */
668         ByteMaxMask xor(VectorMask<Byte> mask) {
669             Objects.requireNonNull(mask);
670             ByteMaxMask m = (ByteMaxMask)mask;
671             return VectorSupport.binaryOp(VECTOR_OP_XOR, ByteMaxMask.class, null, byte.class, VLENGTH,
672                                           this, m, null,
673                                           (m1, m2, vm) -> m1.bOp(m2, (i, a, b) -> a ^ b));
674         }
675 
676         // Mask Query operations
677 
678         @Override
679         @ForceInline
680         public int trueCount() {
681             return (int) VectorSupport.maskReductionCoerced(VECTOR_OP_MASK_TRUECOUNT, ByteMaxMask.class, byte.class, VLENGTH, this,
682                                                       (m) -> trueCountHelper(m.getBits()));
683         }
684 
685         @Override
686         @ForceInline
687         public int firstTrue() {
688             return (int) VectorSupport.maskReductionCoerced(VECTOR_OP_MASK_FIRSTTRUE, ByteMaxMask.class, byte.class, VLENGTH, this,
689                                                       (m) -> firstTrueHelper(m.getBits()));
690         }
691 
692         @Override
693         @ForceInline
694         public int lastTrue() {
695             return (int) VectorSupport.maskReductionCoerced(VECTOR_OP_MASK_LASTTRUE, ByteMaxMask.class, byte.class, VLENGTH, this,
696                                                       (m) -> lastTrueHelper(m.getBits()));
697         }
698 
699         @Override
700         @ForceInline
701         public long toLong() {
702             if (length() > Long.SIZE) {
703                 throw new UnsupportedOperationException("too many lanes for one long");
704             }
705             return VectorSupport.maskReductionCoerced(VECTOR_OP_MASK_TOLONG, ByteMaxMask.class, byte.class, VLENGTH, this,
706                                                       (m) -> toLongHelper(m.getBits()));
707         }
708 
709         // Reductions
710 
711         @Override
712         @ForceInline
713         public boolean anyTrue() {
714             return VectorSupport.test(BT_ne, ByteMaxMask.class, byte.class, VLENGTH,
715                                          this, vspecies().maskAll(true),
716                                          (m, __) -> anyTrueHelper(((ByteMaxMask)m).getBits()));
717         }
718 
719         @Override
720         @ForceInline
721         public boolean allTrue() {
722             return VectorSupport.test(BT_overflow, ByteMaxMask.class, byte.class, VLENGTH,
723                                          this, vspecies().maskAll(true),
724                                          (m, __) -> allTrueHelper(((ByteMaxMask)m).getBits()));
725         }
726 
727         @ForceInline
728         /*package-private*/
729         static ByteMaxMask maskAll(boolean bit) {
730             return VectorSupport.broadcastCoerced(ByteMaxMask.class, byte.class, VLENGTH,
731                                                   (bit ? -1 : 0), null,
732                                                   (v, __) -> (v != 0 ? TRUE_MASK : FALSE_MASK));
733         }
734         private static final ByteMaxMask  TRUE_MASK = new ByteMaxMask(true);
735         private static final ByteMaxMask FALSE_MASK = new ByteMaxMask(false);
736 
737     }
738 
739     // Shuffle
740 
741     static final class ByteMaxShuffle extends AbstractShuffle<Byte> {
742         static final int VLENGTH = VSPECIES.laneCount();    // used by the JVM
743         static final Class<Byte> ETYPE = byte.class; // used by the JVM
744 
745         ByteMaxShuffle(byte[] reorder) {
746             super(VLENGTH, reorder);
747         }
748 
749         public ByteMaxShuffle(int[] reorder) {
750             super(VLENGTH, reorder);
751         }
752 
753         public ByteMaxShuffle(int[] reorder, int i) {
754             super(VLENGTH, reorder, i);
755         }
756 
757         public ByteMaxShuffle(IntUnaryOperator fn) {
758             super(VLENGTH, fn);
759         }
760 
761         @Override
762         public ByteSpecies vspecies() {
763             return VSPECIES;
764         }
765 
766         static {
767             // There must be enough bits in the shuffle lanes to encode
768             // VLENGTH valid indexes and VLENGTH exceptional ones.
769             assert(VLENGTH < Byte.MAX_VALUE);
770             assert(Byte.MIN_VALUE <= -VLENGTH);
771         }
772         static final ByteMaxShuffle IOTA = new ByteMaxShuffle(IDENTITY);
773 
774         @Override
775         @ForceInline
776         public ByteMaxVector toVector() {
777             return VectorSupport.shuffleToVector(VCLASS, ETYPE, ByteMaxShuffle.class, this, VLENGTH,
778                                                     (s) -> ((ByteMaxVector)(((AbstractShuffle<Byte>)(s)).toVectorTemplate())));
779         }
780 
781         @Override
782         @ForceInline
783         public <F> VectorShuffle<F> cast(VectorSpecies<F> s) {
784             AbstractSpecies<F> species = (AbstractSpecies<F>) s;
785             if (length() != species.laneCount())
786                 throw new IllegalArgumentException("VectorShuffle length and species length differ");
787             int[] shuffleArray = toArray();
788             return s.shuffleFromArray(shuffleArray, 0).check(s);
789         }
790 
791         @ForceInline
792         @Override
793         public ByteMaxShuffle rearrange(VectorShuffle<Byte> shuffle) {
794             ByteMaxShuffle s = (ByteMaxShuffle) shuffle;
795             byte[] reorder1 = reorder();
796             byte[] reorder2 = s.reorder();
797             byte[] r = new byte[reorder1.length];
798             for (int i = 0; i < reorder1.length; i++) {
799                 int ssi = reorder2[i];
800                 r[i] = reorder1[ssi];  // throws on exceptional index
801             }
802             return new ByteMaxShuffle(r);
803         }
804     }
805 
806     // ================================================
807 
808     // Specialized low-level memory operations.
809 
810     @ForceInline
811     @Override
812     final
813     ByteVector fromArray0(byte[] a, int offset) {
814         return super.fromArray0Template(a, offset);  // specialize
815     }
816 
817     @ForceInline
818     @Override
819     final
820     ByteVector fromArray0(byte[] a, int offset, VectorMask<Byte> m) {
821         return super.fromArray0Template(ByteMaxMask.class, a, offset, (ByteMaxMask) m);  // specialize
822     }
823 
824 
825 
826     @ForceInline
827     @Override
828     final
829     ByteVector fromBooleanArray0(boolean[] a, int offset) {
830         return super.fromBooleanArray0Template(a, offset);  // specialize
831     }
832 
833     @ForceInline
834     @Override
835     final
836     ByteVector fromBooleanArray0(boolean[] a, int offset, VectorMask<Byte> m) {
837         return super.fromBooleanArray0Template(ByteMaxMask.class, a, offset, (ByteMaxMask) m);  // specialize
838     }
839 
840     @ForceInline
841     @Override
842     final
843     ByteVector fromByteArray0(byte[] a, int offset) {
844         return super.fromByteArray0Template(a, offset);  // specialize
845     }
846 
847     @ForceInline
848     @Override
849     final
850     ByteVector fromByteArray0(byte[] a, int offset, VectorMask<Byte> m) {
851         return super.fromByteArray0Template(ByteMaxMask.class, a, offset, (ByteMaxMask) m);  // specialize
852     }
853 
854     @ForceInline
855     @Override
856     final
857     ByteVector fromByteBuffer0(ByteBuffer bb, int offset) {
858         return super.fromByteBuffer0Template(bb, offset);  // specialize
859     }
860 
861     @ForceInline
862     @Override
863     final
864     ByteVector fromByteBuffer0(ByteBuffer bb, int offset, VectorMask<Byte> m) {
865         return super.fromByteBuffer0Template(ByteMaxMask.class, bb, offset, (ByteMaxMask) m);  // specialize
866     }
867 
868     @ForceInline
869     @Override
870     final
871     void intoArray0(byte[] a, int offset) {
872         super.intoArray0Template(a, offset);  // specialize
873     }
874 
875     @ForceInline
876     @Override
877     final
878     void intoArray0(byte[] a, int offset, VectorMask<Byte> m) {
879         super.intoArray0Template(ByteMaxMask.class, a, offset, (ByteMaxMask) m);
880     }
881 
882 
883     @ForceInline
884     @Override
885     final
886     void intoBooleanArray0(boolean[] a, int offset, VectorMask<Byte> m) {
887         super.intoBooleanArray0Template(ByteMaxMask.class, a, offset, (ByteMaxMask) m);
888     }
889 
890     @ForceInline
891     @Override
892     final
893     void intoByteArray0(byte[] a, int offset) {
894         super.intoByteArray0Template(a, offset);  // specialize
895     }
896 
897     @ForceInline
898     @Override
899     final
900     void intoByteArray0(byte[] a, int offset, VectorMask<Byte> m) {
901         super.intoByteArray0Template(ByteMaxMask.class, a, offset, (ByteMaxMask) m);  // specialize
902     }
903 
904     @ForceInline
905     @Override
906     final
907     void intoByteBuffer0(ByteBuffer bb, int offset, VectorMask<Byte> m) {
908         super.intoByteBuffer0Template(ByteMaxMask.class, bb, offset, (ByteMaxMask) m);
909     }
910 
911 
912     // End of specialized low-level memory operations.
913 
914     // ================================================
915 
916 }
--- EOF ---