< prev index next >

src/jdk.incubator.vector/share/classes/jdk/incubator/vector/VectorMask.java

Print this page

193      * @param species vector species for the desired mask
194      * @param bits the {@code boolean} array
195      * @param offset the offset into the array
196      * @param <E> the boxed element type
197      * @return the mask loaded from the {@code boolean} array
198      * @throws IndexOutOfBoundsException if {@code offset < 0}, or
199      * {@code offset > bits.length - species.length()}
200      * @see #fromLong(VectorSpecies, long)
201      * @see #fromValues(VectorSpecies, boolean...)
202      */
203     @ForceInline
204     public static <E> VectorMask<E> fromArray(VectorSpecies<E> species, boolean[] bits, int offset) {
205         AbstractSpecies<E> vsp = (AbstractSpecies<E>) species;
206         int laneCount = vsp.laneCount();
207         offset = VectorIntrinsics.checkFromIndexSize(offset, laneCount, bits.length);
208         return VectorSupport.load(
209                 vsp.maskType(), vsp.elementType(), laneCount,
210                 bits, (long) offset + Unsafe.ARRAY_BOOLEAN_BASE_OFFSET,
211                 bits, offset, vsp,
212                 (c, idx, s)
213                   -> s.opm(n -> c[idx + n]));
214     }
215 
216     /**
217      * Returns a mask where each lane is set or unset according to
218      * the bits in the given bitmask, starting with the least
219      * significant bit, and continuing up to the sign bit.
220      * <p>
221      * For each mask lane, where {@code N} is the mask lane index,
222      * if the expression {@code (bits>>min(63,N))&1} is non-zero,
223      * then the mask lane at index {@code N} is set, otherwise it is unset.
224      * <p>
225      * If the given species has fewer than 64 lanes, the high
226      * {@code 64-VLENGTH} bits of the bit-mask are ignored.
227      * If the given species has more than 64 lanes, the sign
228      * bit is replicated into lane 64 and beyond.
229      *
230      * @param species vector species for the desired mask
231      * @param bits the given mask bits, as a 64-bit signed integer
232      * @param <E> the boxed element type
233      * @return a mask where each lane is set or unset according to

454      * {@link Objects#checkIndex(int,int)}, on the index numbers in
455      * the range {@code [offset..offset+VLENGTH-1]}.  If an exception
456      * is desired, the resulting mask can be compared with the
457      * original mask; if they are not equal, then at least one lane
458      * was out of range, and exception processing can be performed.
459      *
460      * <p> A mask which is a series of {@code N} set lanes followed by
461      * a series of unset lanes can be obtained by calling
462      * {@code allTrue.indexInRange(0, N)}, where {@code allTrue} is a
463      * mask of all true bits.  A mask of {@code N1} unset lanes
464      * followed by {@code N2} set lanes can be obtained by calling
465      * {@code allTrue.indexInRange(-N1, N2)}.
466      *
467      * @param offset the starting index
468      * @param limit the upper-bound (exclusive) of index range
469      * @return the original mask, with out-of-range lanes unset
470      * @see VectorSpecies#indexInRange(int, int)
471      */
472     public abstract VectorMask<E> indexInRange(int offset, int limit);
473 

































474     /**
475      * Returns a vector representation of this mask, the
476      * lane bits of which are set or unset in correspondence
477      * to the mask bits.
478      *
479      * For each mask lane, where {@code N} is the mask lane index, if
480      * the mask lane is set at {@code N} then the specific non-default
481      * value {@code -1} is placed into the resulting vector at lane
482      * index {@code N}.  Otherwise the default element value {@code 0}
483      * is placed into the resulting vector at lane index {@code N}.
484      *
485      * Whether the element type ({@code ETYPE}) of this mask is
486      * floating point or integral, the lane value, as selected by the
487      * mask, will be one of the two arithmetic values {@code 0} or
488      * {@code -1}.  For every {@code ETYPE} the most significant bit
489      * of the vector lane is set if and only if the mask lane is set.
490      * In addition, for integral types, <em>all</em> lane bits are set
491      * in lanes where the mask is set.
492      *
493      * <p> The vector returned is the same as would be computed by

604             if (this.vectorSpecies().equals(that.vectorSpecies())) {
605                 @SuppressWarnings("unchecked")
606                 VectorMask<E> that2 = (VectorMask<E>) that;
607                 return this.eq(that2).allTrue();
608             }
609         }
610         return false;
611     }
612 
613     /**
614      * Returns a hash code value for the mask,
615      * based on the mask bit settings and the vector species.
616      *
617      * @return  a hash code value for this mask
618      */
619     @Override
620     public final int hashCode() {
621         return Objects.hash(vectorSpecies(), Arrays.hashCode(toArray()));
622     }
623 












624     // ==== JROSE NAME CHANGES ====
625 
626     // TYPE CHANGED
627     // * toVector() return type is Vector<?> not Vector<E>
628     // ADDED
629     // * indexInRange(int,int,int) (SIMD range check, no overflow)
630     // * fromLong(VectorSpecies, long) (inverse of toLong)
631     // * check(VectorSpecies) (static type-safety check)
632     // * toString(), equals(Object), hashCode() (documented)
633     // * added <E> (not <?>) to toVector
634 
635 }

193      * @param species vector species for the desired mask
194      * @param bits the {@code boolean} array
195      * @param offset the offset into the array
196      * @param <E> the boxed element type
197      * @return the mask loaded from the {@code boolean} array
198      * @throws IndexOutOfBoundsException if {@code offset < 0}, or
199      * {@code offset > bits.length - species.length()}
200      * @see #fromLong(VectorSpecies, long)
201      * @see #fromValues(VectorSpecies, boolean...)
202      */
203     @ForceInline
204     public static <E> VectorMask<E> fromArray(VectorSpecies<E> species, boolean[] bits, int offset) {
205         AbstractSpecies<E> vsp = (AbstractSpecies<E>) species;
206         int laneCount = vsp.laneCount();
207         offset = VectorIntrinsics.checkFromIndexSize(offset, laneCount, bits.length);
208         return VectorSupport.load(
209                 vsp.maskType(), vsp.elementType(), laneCount,
210                 bits, (long) offset + Unsafe.ARRAY_BOOLEAN_BASE_OFFSET,
211                 bits, offset, vsp,
212                 (c, idx, s)
213                   -> s.opm(n -> c[((int )idx) + n]));
214     }
215 
216     /**
217      * Returns a mask where each lane is set or unset according to
218      * the bits in the given bitmask, starting with the least
219      * significant bit, and continuing up to the sign bit.
220      * <p>
221      * For each mask lane, where {@code N} is the mask lane index,
222      * if the expression {@code (bits>>min(63,N))&1} is non-zero,
223      * then the mask lane at index {@code N} is set, otherwise it is unset.
224      * <p>
225      * If the given species has fewer than 64 lanes, the high
226      * {@code 64-VLENGTH} bits of the bit-mask are ignored.
227      * If the given species has more than 64 lanes, the sign
228      * bit is replicated into lane 64 and beyond.
229      *
230      * @param species vector species for the desired mask
231      * @param bits the given mask bits, as a 64-bit signed integer
232      * @param <E> the boxed element type
233      * @return a mask where each lane is set or unset according to

454      * {@link Objects#checkIndex(int,int)}, on the index numbers in
455      * the range {@code [offset..offset+VLENGTH-1]}.  If an exception
456      * is desired, the resulting mask can be compared with the
457      * original mask; if they are not equal, then at least one lane
458      * was out of range, and exception processing can be performed.
459      *
460      * <p> A mask which is a series of {@code N} set lanes followed by
461      * a series of unset lanes can be obtained by calling
462      * {@code allTrue.indexInRange(0, N)}, where {@code allTrue} is a
463      * mask of all true bits.  A mask of {@code N1} unset lanes
464      * followed by {@code N2} set lanes can be obtained by calling
465      * {@code allTrue.indexInRange(-N1, N2)}.
466      *
467      * @param offset the starting index
468      * @param limit the upper-bound (exclusive) of index range
469      * @return the original mask, with out-of-range lanes unset
470      * @see VectorSpecies#indexInRange(int, int)
471      */
472     public abstract VectorMask<E> indexInRange(int offset, int limit);
473 
474     /**
475      * Removes lanes numbered {@code N} from this mask where the
476      * adjusted index {@code N+offset}, is not in the range
477      * {@code [0..limit-1]}.
478      *
479      * <p> In all cases the series of set and unset lanes is assigned
480      * as if by using infinite precision or {@code VLENGTH-}saturating
481      * additions or subtractions, without overflow or wrap-around.
482      *
483      * @apiNote
484      *
485      * This method performs a SIMD emulation of the check performed by
486      * {@link Objects#checkIndex(long,long)}, on the index numbers in
487      * the range {@code [offset..offset+VLENGTH-1]}.  If an exception
488      * is desired, the resulting mask can be compared with the
489      * original mask; if they are not equal, then at least one lane
490      * was out of range, and exception processing can be performed.
491      *
492      * <p> A mask which is a series of {@code N} set lanes followed by
493      * a series of unset lanes can be obtained by calling
494      * {@code allTrue.indexInRange(0, N)}, where {@code allTrue} is a
495      * mask of all true bits.  A mask of {@code N1} unset lanes
496      * followed by {@code N2} set lanes can be obtained by calling
497      * {@code allTrue.indexInRange(-N1, N2)}.
498      *
499      * @param offset the starting index
500      * @param limit the upper-bound (exclusive) of index range
501      * @return the original mask, with out-of-range lanes unset
502      * @see VectorSpecies#indexInRange(long, long)
503      * @since 19
504      */
505     public abstract VectorMask<E> indexInRange(long offset, long limit);
506 
507     /**
508      * Returns a vector representation of this mask, the
509      * lane bits of which are set or unset in correspondence
510      * to the mask bits.
511      *
512      * For each mask lane, where {@code N} is the mask lane index, if
513      * the mask lane is set at {@code N} then the specific non-default
514      * value {@code -1} is placed into the resulting vector at lane
515      * index {@code N}.  Otherwise the default element value {@code 0}
516      * is placed into the resulting vector at lane index {@code N}.
517      *
518      * Whether the element type ({@code ETYPE}) of this mask is
519      * floating point or integral, the lane value, as selected by the
520      * mask, will be one of the two arithmetic values {@code 0} or
521      * {@code -1}.  For every {@code ETYPE} the most significant bit
522      * of the vector lane is set if and only if the mask lane is set.
523      * In addition, for integral types, <em>all</em> lane bits are set
524      * in lanes where the mask is set.
525      *
526      * <p> The vector returned is the same as would be computed by

637             if (this.vectorSpecies().equals(that.vectorSpecies())) {
638                 @SuppressWarnings("unchecked")
639                 VectorMask<E> that2 = (VectorMask<E>) that;
640                 return this.eq(that2).allTrue();
641             }
642         }
643         return false;
644     }
645 
646     /**
647      * Returns a hash code value for the mask,
648      * based on the mask bit settings and the vector species.
649      *
650      * @return  a hash code value for this mask
651      */
652     @Override
653     public final int hashCode() {
654         return Objects.hash(vectorSpecies(), Arrays.hashCode(toArray()));
655     }
656 
657     /**
658      * Compresses set lanes from this mask.
659      *
660      * Returns a mask which is a series of {@code N} set lanes
661      * followed by a series of unset lanes, where {@code N} is
662      * the true count of this mask.
663      *
664      * @return the compressed mask of this mask
665      * @since 19
666      */
667     public abstract VectorMask<E> compress();
668 
669     // ==== JROSE NAME CHANGES ====
670 
671     // TYPE CHANGED
672     // * toVector() return type is Vector<?> not Vector<E>
673     // ADDED
674     // * indexInRange(int,int,int) (SIMD range check, no overflow)
675     // * fromLong(VectorSpecies, long) (inverse of toLong)
676     // * check(VectorSpecies) (static type-safety check)
677     // * toString(), equals(Object), hashCode() (documented)
678     // * added <E> (not <?>) to toVector
679 
680 }
< prev index next >