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