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