APIdia Launch Partner
Top Description Constructors Methods
jdk.incubator.vector

public abstract sealed Class VectorMask<E>

extends VectorSupport.VectorMask<E>
permits AbstractMask<E>
Class Inheritance
Known Direct Subclasses
jdk.incubator.vector.AbstractMask
Annotations
@SuppressWarnings:exports
Type Parameters
<E>
the boxed version of ETYPE, the element type of a vector
Imports
jdk.internal.misc.Unsafe, jdk.internal.vm.annotation.ForceInline, jdk.internal.vm.vector.VectorSupport, java.util.Arrays, .Objects

A VectorMask represents an ordered immutable sequence of boolean values.

A VectorMask and Vector of the same element type (ETYPE) and shape have the same number of lanes, and are therefore compatible (specifically, their vector species are compatible).

Some vector operations accept (compatible) masks to control the selection and operation of lane elements of input vectors.

The number of values in the sequence is referred to as the VectorMask length. The length also corresponds to the number of VectorMask lanes. The lane element at lane index N (from 0, inclusive, to length, exclusive) corresponds to the N + 1'th value in the sequence.

A lane is said to be set if the lane element is true, otherwise a lane is said to be unset if the lane element is false.

VectorMask declares a limited set of unary, binary and reduction operations.

Value-based classes and identity operations

VectorMask, along with Vector, is a value-based class. With VectorMask, identity-sensitive operations such as == may yield unpredictable results, or reduced performance. Oddly enough, v.equals(w) is likely to be faster than v==w, since equals is not an identity sensitive method. (Neither is toString nor hashCode.) Also, vector mask objects can be stored in locals and parameters and as static final constants, but storing them in other Java fields or in array elements, while semantically valid, may incur performance penalties.

Constructor Summary

AccessConstructor and Description
pack-priv
VectorMask(boolean[] bits)

Method Summary

Modifier and TypeMethod and Description
public abstract boolean

Returns:

true if all the mask lanes are set, otherwise false.
allTrue
()

Returns true if all the mask lanes are set.

public abstract VectorMask<E>

Returns:

the result of logically conjoining the two input masks
and
(VectorMask<E>
the second input mask
m
)

Computes the logical intersection (as a&b;) between this mask and a second input mask.

public abstract VectorMask<E>

Returns:

the result of logically subtracting the second mask from this mask
andNot
(VectorMask<E>
the second input mask
m
)

Logically subtracts a second input mask from this mask (as a&~b).

public abstract boolean

Returns:

true if any of the mask lanes are set, otherwise false.
anyTrue
()

Returns true if any of the mask lanes are set.

public abstract <
the boxed element type of the species
F
>
VectorMask<F>

Returns:

a mask converted by shape and element type
cast
(VectorSpecies<F>
vector species for the desired mask
species
)

Converts this mask to a mask of the given species of element type F.

public abstract <
the boxed element type of the required lane type
F
>
VectorMask<F>

Returns:

the same mask
check
(Class<F>
the required lane type
elementType
)

Checks that this mask applies to vectors with the given element type, and returns this mask unchanged.

public abstract <
the boxed element type of the required species
F
>
VectorMask<F>

Returns:

the same mask
check
(VectorSpecies<F>
vector species required for this mask
species
)

Checks that this mask has the given species, and returns this mask unchanged.

pack-priv abstract <
the boxed element type of the required species
F
>
VectorMask<F>

Returns:

the same mask
check
(Class<? extends VectorMask<F>>
the class required for this mask
maskClass
,
Vector<F>
its species required for this mask
vector
)

Checks that this mask has the same class with the given mask class, and it has the same species with given vector's species, and returns this mask unchanged.

public abstract VectorMask<E>

Returns:

the compressed mask of this mask
compress
()

Compresses set lanes from this mask.

public abstract VectorMask<E>

Returns:

a mask showing where the two input masks were equal
eq
(VectorMask<E>
the input mask
m
)

Determines logical equivalence of this mask to a second input mask (as boolean a==b or a^~b).

public final boolean

Returns:

whether this vector is identical to some other object
equals
(Object obj)

Overrides java.lang.Object.equals.

Indicates whether this mask is identical to some other object.

public abstract int

Returns:

the index of the first mask lane that is set, or VLENGTH
firstTrue
()

Returns the index of the first mask lane that is set.

public static <
the boxed element type
E
>
VectorMask<E>

Returns:

the mask loaded from the boolean array
fromArray
(VectorSpecies<E>
vector species for the desired mask
species
,
boolean[]
the boolean array
bits
,
int
the offset into the array
offset
)

Loads a mask from a boolean array starting at an offset.

public static <
the boxed element type
E
>
VectorMask<E>

Returns:

a mask where each lane is set or unset according to the bits in the given integer value
fromLong
(VectorSpecies<E>
vector species for the desired mask
species
,
long
the given mask bits, as a 64-bit signed integer
bits
)

Returns a mask where each lane is set or unset according to the bits in the given bitmask, starting with the least significant bit, and continuing up to the sign bit.

public static <
the boxed element type
E
>
VectorMask<E>

Returns:

a mask where each lane is set or unset according to the given boolean value
fromValues
(VectorSpecies<E>
vector species for the desired mask
species
,
boolean...
the given boolean values
bits
)

Returns a mask where each lane is set or unset according to given boolean values.

public final int

Returns:

a hash code value for this mask
hashCode
()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the mask, based on the mask bit settings and the vector species.

public abstract VectorMask<E>

Returns:

the original mask, with out-of-range lanes unset
indexInRange
(int
the starting index
offset
,
int
the upper-bound (exclusive) of index range
limit
)

Removes lanes numbered N from this mask where the adjusted index N+offset, is not in the range [0..limit-1].

public abstract VectorMask<E>

Returns:

the original mask, with out-of-range lanes unset
indexInRange
(long
the starting index
offset
,
long
the upper-bound (exclusive) of index range
limit
)

Removes lanes numbered N from this mask where the adjusted index N+offset, is not in the range [0..limit-1].

public abstract void
intoArray(boolean[]
the array, of type boolean[]
a
,
int
the offset into the array
offset
)

Stores this mask into a boolean array starting at offset.

public abstract boolean

Returns:

true if the lane at index i is set, otherwise false
laneIsSet
(int
the lane index
i
)

Tests if the lane at index i is set

public abstract int

Returns:

the index of the last mask lane that is set, or -1
lastTrue
()

Returns the index of the last mask lane that is set.

public final int

Returns:

the number of mask lanes
length
()

Returns the number of mask lanes.

public abstract VectorMask<E>

Returns:

the result of logically negating this mask
not
()

Logically negates this mask.

public abstract VectorMask<E>

Returns:

the result of logically disjoining the two input masks
or
(VectorMask<E>
the input mask
m
)

Computes the logical union (as a|b) of this mask and a second input mask.

public abstract boolean[]

Returns:

an array containing the lane elements of this vector
toArray
()

Returns an boolean array containing the lane elements of this mask.

public abstract long

Returns:

the lane elements of this mask packed into a long value.
toLong
()

Returns the lane elements of this mask packed into a long value for at most the first 64 lane elements.

public final String

Returns:

a string of the form "Mask[T.TT...]"
toString
()

Overrides java.lang.Object.toString.

Returns a string representation of this mask, of the form "Mask[T.TT...]", reporting the mask bit settings (as 'T' or '.' characters) in lane order.

public abstract Vector<E>

Returns:

a vector representation of this mask
toVector
()

Returns a vector representation of this mask, the lane bits of which are set or unset in correspondence to the mask bits.

public abstract int

Returns:

the number of mask lanes that are set.
trueCount
()

Returns the number of mask lanes that are set.

public abstract VectorSpecies<E>

Returns:

the vector species of this mask
vectorSpecies
()

Returns the vector species to which this mask applies.

public abstract VectorMask<E>

Returns:

the result of logically disjunctively disjoining the two input masks
xor
(VectorMask<E>
the input mask
m
)

Determines logical symmetric difference (as a^b) of this mask and a second input mask.

Constructor Detail

VectorMaskback to summary
pack-priv VectorMask(boolean[] bits)

Method Detail

allTrueback to summary
public abstract boolean allTrue()

Returns true if all the mask lanes are set.

Returns:boolean

true if all the mask lanes are set, otherwise false.

andback to summary
public abstract VectorMask<E> and(VectorMask<E> m)

Computes the logical intersection (as a&b) between this mask and a second input mask.

This is a lane-wise binary operation which applies the logical AND operation (&) to each corresponding pair of mask bits.

Parameters
m:VectorMask<E>

the second input mask

Returns:VectorMask<E>

the result of logically conjoining the two input masks

andNotback to summary
public abstract VectorMask<E> andNot(VectorMask<E> m)

Logically subtracts a second input mask from this mask (as a&~b).

This is a lane-wise binary operation which applies the logical ANDC operation (&~) to each corresponding pair of mask bits.

Parameters
m:VectorMask<E>

the second input mask

Returns:VectorMask<E>

the result of logically subtracting the second mask from this mask

anyTrueback to summary
public abstract boolean anyTrue()

Returns true if any of the mask lanes are set.

Returns:boolean

true if any of the mask lanes are set, otherwise false.

castback to summary
public abstract <F> VectorMask<F> cast(VectorSpecies<F> species)

Converts this mask to a mask of the given species of element type F. The species.length() must be equal to the mask length. The various mask lane bits are unmodified.

For each mask lane, where N is the lane index, if the mask lane at index N is set, then the mask lane at index N of the resulting mask is set, otherwise that mask lane is not set.

Parameters
<F>
the boxed element type of the species
species:VectorSpecies<F>

vector species for the desired mask

Returns:VectorMask<F>

a mask converted by shape and element type

Exceptions
IllegalArgumentException:
if this mask length and the species length differ
checkback to summary
public abstract <F> VectorMask<F> check(Class<F> elementType)

Checks that this mask applies to vectors with the given element type, and returns this mask unchanged. The effect is similar to this pseudocode: elementType == vectorSpecies().elementType() ? this : throw new ClassCastException().

Parameters
<F>
the boxed element type of the required lane type
elementType:Class<F>

the required lane type

Returns:VectorMask<F>

the same mask

Exceptions
ClassCastException:
if the element type is wrong
See Also
Vector#check(Class), VectorMask#check(VectorSpecies)
checkback to summary
public abstract <F> VectorMask<F> check(VectorSpecies<F> species)

Checks that this mask has the given species, and returns this mask unchanged. The effect is similar to this pseudocode: species == vectorSpecies() ? this : throw new ClassCastException().

Parameters
<F>
the boxed element type of the required species
species:VectorSpecies<F>

vector species required for this mask

Returns:VectorMask<F>

the same mask

Exceptions
ClassCastException:
if the species is wrong
See Also
Vector#check(Class), Vector#check(VectorSpecies)
checkback to summary
pack-priv abstract <F> VectorMask<F> check(Class<? extends VectorMask<F>> maskClass, Vector<F> vector)

Checks that this mask has the same class with the given mask class, and it has the same species with given vector's species, and returns this mask unchanged. The effect is similar to this pseudocode: getClass() == maskClass && vectorSpecies() == vector.species() ? this : throw new ClassCastException().

Parameters
<F>
the boxed element type of the required species
maskClass:Class<? extends VectorMask<F>>

the class required for this mask

vector:Vector<F>

its species required for this mask

Returns:VectorMask<F>

the same mask

Exceptions
ClassCastException:
if the species is wrong
compressback to summary
public abstract VectorMask<E> compress()

Compresses set lanes from this mask. Returns a mask which is a series of N set lanes followed by a series of unset lanes, where N is the true count of this mask.

Returns:VectorMask<E>

the compressed mask of this mask

Since
19
eqback to summary
public abstract VectorMask<E> eq(VectorMask<E> m)

Determines logical equivalence of this mask to a second input mask (as boolean a==b or a^~b).

This is a lane-wise binary operation tests each corresponding pair of mask bits for equality. It is also equivalent to the logical XNOR operation (^~) to each corresponding pair of mask bits.

Parameters
m:VectorMask<E>

the input mask

Returns:VectorMask<E>

a mask showing where the two input masks were equal

See Also
equals
equalsback to summary
public final boolean equals(Object obj)

Overrides java.lang.Object.equals.

Indicates whether this mask is identical to some other object. Two masks are identical only if they have the same species and same source indexes, in the same order.

Returns:boolean

whether this vector is identical to some other object

Annotations
@Override
See Also
eq
firstTrueback to summary
public abstract int firstTrue()

Returns the index of the first mask lane that is set. Returns VLENGTH if none of them are set.

Returns:int

the index of the first mask lane that is set, or VLENGTH

fromArrayback to summary
public static <E> VectorMask<E> fromArray(VectorSpecies<E> species, boolean[] bits, int offset)

Loads a mask from a boolean array starting at an offset.

For each mask lane, where N is the mask lane index, if the array element at index offset + N is true then the mask lane at index N is set, otherwise it is unset.

Parameters
<E>
the boxed element type
species:VectorSpecies<E>

vector species for the desired mask

bits:boolean[]

the boolean array

offset:int

the offset into the array

Returns:VectorMask<E>

the mask loaded from the boolean array

Annotations
@ForceInline
Exceptions
IndexOutOfBoundsException:
if offset < 0, or offset > bits.length - species.length()
See Also
fromLong(VectorSpecies, long), fromValues(VectorSpecies, boolean...)
fromLongback to summary
public static <E> VectorMask<E> fromLong(VectorSpecies<E> species, long bits)

Returns a mask where each lane is set or unset according to the bits in the given bitmask, starting with the least significant bit, and continuing up to the sign bit.

For each mask lane, where N is the mask lane index, if the expression (bits>>min(63,N))&1 is non-zero, then the mask lane at index N is set, otherwise it is unset.

If the given species has fewer than 64 lanes, the high 64-VLENGTH bits of the bit-mask are ignored. If the given species has more than 64 lanes, the sign bit is replicated into lane 64 and beyond.

Parameters
<E>
the boxed element type
species:VectorSpecies<E>

vector species for the desired mask

bits:long

the given mask bits, as a 64-bit signed integer

Returns:VectorMask<E>

a mask where each lane is set or unset according to the bits in the given integer value

Annotations
@ForceInline
See Also
fromValues(VectorSpecies, boolean...), fromArray(VectorSpecies, boolean[], int)
fromValuesback to summary
public static <E> VectorMask<E> fromValues(VectorSpecies<E> species, boolean... bits)

Returns a mask where each lane is set or unset according to given boolean values.

For each mask lane, where N is the mask lane index, if the given boolean value at index N is true then the mask lane at index N is set, otherwise it is unset.

The given species must have a number of lanes that is compatible with the given array.

Parameters
<E>
the boxed element type
species:VectorSpecies<E>

vector species for the desired mask

bits:boolean[]

the given boolean values

Returns:VectorMask<E>

a mask where each lane is set or unset according to the given boolean value

Annotations
@ForceInline
Exceptions
IllegalArgumentException:
if bits.length != species.length()
See Also
fromLong(VectorSpecies, long), fromArray(VectorSpecies, boolean[], int)
hashCodeback to summary
public final int hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the mask, based on the mask bit settings and the vector species.

Returns:int

a hash code value for this mask

Annotations
@Override
indexInRangeback to summary
public abstract VectorMask<E> indexInRange(int offset, int limit)

Removes lanes numbered N from this mask where the adjusted index N+offset, is not in the range [0..limit-1].

In all cases the series of set and unset lanes is assigned as if by using infinite precision or VLENGTH-saturating additions or subtractions, without overflow or wrap-around.

API Note

This method performs a SIMD emulation of the check performed by Objects#checkIndex(int, int), on the index numbers in the range [offset..offset+VLENGTH-1]. If an exception is desired, the resulting mask can be compared with the original mask; if they are not equal, then at least one lane was out of range, and exception processing can be performed.

A mask which is a series of N set lanes followed by a series of unset lanes can be obtained by calling allTrue.indexInRange(0, N), where allTrue is a mask of all true bits. A mask of N1 unset lanes followed by N2 set lanes can be obtained by calling allTrue.indexInRange(-N1, N2).

Parameters
offset:int

the starting index

limit:int

the upper-bound (exclusive) of index range

Returns:VectorMask<E>

the original mask, with out-of-range lanes unset

See Also
VectorSpecies#indexInRange(int, int)
indexInRangeback to summary
public abstract VectorMask<E> indexInRange(long offset, long limit)

Removes lanes numbered N from this mask where the adjusted index N+offset, is not in the range [0..limit-1].

In all cases the series of set and unset lanes is assigned as if by using infinite precision or VLENGTH-saturating additions or subtractions, without overflow or wrap-around.

API Note

This method performs a SIMD emulation of the check performed by Objects#checkIndex(long, long), on the index numbers in the range [offset..offset+VLENGTH-1]. If an exception is desired, the resulting mask can be compared with the original mask; if they are not equal, then at least one lane was out of range, and exception processing can be performed.

A mask which is a series of N set lanes followed by a series of unset lanes can be obtained by calling allTrue.indexInRange(0, N), where allTrue is a mask of all true bits. A mask of N1 unset lanes followed by N2 set lanes can be obtained by calling allTrue.indexInRange(-N1, N2).

Parameters
offset:long

the starting index

limit:long

the upper-bound (exclusive) of index range

Returns:VectorMask<E>

the original mask, with out-of-range lanes unset

Since
19
See Also
VectorSpecies#indexInRange(long, long)
intoArrayback to summary
public abstract void intoArray(boolean[] a, int offset)

Stores this mask into a boolean array starting at offset.

For each mask lane, where N is the mask lane index, the lane element at index N is stored into the array element a[offset+N].

Parameters
a:boolean[]

the array, of type boolean[]

offset:int

the offset into the array

Exceptions
IndexOutOfBoundsException:
if offset < 0 or offset > a.length - this.length()
laneIsSetback to summary
public abstract boolean laneIsSet(int i)

Tests if the lane at index i is set

Parameters
i:int

the lane index

Returns:boolean

true if the lane at index i is set, otherwise false

Exceptions
IndexOutOfBoundsException:
if the index is out of range (< 0 || >= length())
lastTrueback to summary
public abstract int lastTrue()

Returns the index of the last mask lane that is set. Returns -1 if none of them are set.

Returns:int

the index of the last mask lane that is set, or -1

lengthback to summary
public final int length()

Returns the number of mask lanes. This mask applies to vectors of the same number of lanes, and the same species.

Returns:int

the number of mask lanes

Annotations
@ForceInline
notback to summary
public abstract VectorMask<E> not()

Logically negates this mask.

This is a lane-wise binary operation which applies the logical NOT operation (~) to each mask bit.

Returns:VectorMask<E>

the result of logically negating this mask

orback to summary
public abstract VectorMask<E> or(VectorMask<E> m)

Computes the logical union (as a|b) of this mask and a second input mask.

This is a lane-wise binary operation which applies the logical OR operation (|) to each corresponding pair of mask bits.

Parameters
m:VectorMask<E>

the input mask

Returns:VectorMask<E>

the result of logically disjoining the two input masks

toArrayback to summary
public abstract boolean[] toArray()

Returns an boolean array containing the lane elements of this mask.

This method behaves as if it stores this mask into an allocated array (using intoArray(boolean[], int)) and returns that array as follows:

boolean[] a = new boolean[this.length()];
this.intoArray(a, 0);
return a;
Returns:boolean[]

an array containing the lane elements of this vector

toLongback to summary
public abstract long toLong()

Returns the lane elements of this mask packed into a long value for at most the first 64 lane elements.

The lane elements are packed in the order of least significant bit to most significant bit. For each mask lane where N is the mask lane index, if the mask lane is set then the Nth bit is set to one in the resulting long value, otherwise the Nth bit is set to zero. The mask must have no more than 64 lanes.

Returns:long

the lane elements of this mask packed into a long value.

Exceptions
UnsupportedOperationException:
if there are more than 64 lanes in this mask
toStringback to summary
public final String toString()

Overrides java.lang.Object.toString.

Returns a string representation of this mask, of the form "Mask[T.TT...]", reporting the mask bit settings (as 'T' or '.' characters) in lane order.

Returns:String

a string of the form "Mask[T.TT...]"

Annotations
@Override
toVectorback to summary
public abstract Vector<E> toVector()

Returns a vector representation of this mask, the lane bits of which are set or unset in correspondence to the mask bits. For each mask lane, where N is the mask lane index, if the mask lane is set at N then the specific non-default value -1 is placed into the resulting vector at lane index N. Otherwise, the default element value 0 is placed into the resulting vector at lane index N. Whether the element type (ETYPE) of this mask is floating point or integral, the lane value, as selected by the mask, will be one of the two arithmetic values 0 or -1. For every ETYPE the most significant bit of the vector lane is set if and only if the mask lane is set. In addition, for integral types, all lane bits are set in lanes where the mask is set.

The vector returned is the same as would be computed by ZERO.blend(MINUS_ONE, this), where ZERO and MINUS_ONE are vectors which replicate the default ETYPE value and the ETYPE value representing -1, respectively.

API Note

For the sake of static type checking, users may wish to check the resulting vector against the expected integral lane type or species. If the mask is for a float-point species, then the resulting vector will have the same shape and lane size, but an integral type. If the mask is for an integral species, the resulting vector will be of exactly that species.

Returns:Vector<E>

a vector representation of this mask

See Also
Vector#check(Class), Vector#check(VectorSpecies)
trueCountback to summary
public abstract int trueCount()

Returns the number of mask lanes that are set.

Returns:int

the number of mask lanes that are set.

vectorSpeciesback to summary
public abstract VectorSpecies<E> vectorSpecies()

Returns the vector species to which this mask applies. This mask applies to vectors of the same species, and the same number of lanes.

Returns:VectorSpecies<E>

the vector species of this mask

xorback to summary
public abstract VectorMask<E> xor(VectorMask<E> m)

Determines logical symmetric difference (as a^b) of this mask and a second input mask.

This is a lane-wise binary operation which applies the logical XOR operation (^) to each corresponding pair of mask bits.

Parameters
m:VectorMask<E>

the input mask

Returns:VectorMask<E>

the result of logically disjunctively disjoining the two input masks