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