- java.lang.Object
-
- jdk.incubator.vector.VectorShuffle<E>
-
- Type Parameters:
E
- the boxed element type of this mask
public abstract class VectorShuffle<E> extends Object
AVectorShuffle
represents an ordered immutable sequence ofint
values. A VectorShuffle can be used with a shuffle accepting vector operation to control the rearrangement of lane elements of input vectorsThe number of values in the sequence is referred to as the shuffle
length
. The length also corresponds to the number of shuffle lanes. The lane element at lane indexN
(from0
, inclusive, to length, exclusive) corresponds to theN + 1
'th value in the sequence. A VectorShuffle and Vector of the same element type and shape have the same number of lanes.A VectorShuffle describes how a lane element of a vector may cross lanes from its lane index,
i
say, to another lane index whose value is the shuffle's lane element at lane indexi
. VectorShuffle lane elements will be in the range of0
(inclusive) to the shuffle length (exclusive), and therefore cannot induce out of bounds errors when used with vectors operations and vectors of the same length.
-
-
Method Summary
Modifier and Type Method Description abstract <F> VectorShuffle<F>
cast(VectorSpecies<F> species)
Converts this shuffle to a shuffle of the given species of element typeF
.static <E> VectorShuffle<E>
fromArray(VectorSpecies<E> species, int[] ixs, int offset)
Loads a shuffle from anint
array starting at an offset.static <E> VectorShuffle<E>
fromValues(VectorSpecies<E> species, int... ixs)
Returns a shuffle where each lane element is set to a givenint
value logically AND'ed by the species length minus one.abstract void
intoArray(int[] a, int offset)
Stores this shuffle into anint
array starting at offset.int
lane(int i)
Gets theint
lane element at lane indexi
int
length()
Returns the number of shuffle lanes (the length).abstract VectorShuffle<E>
rearrange(VectorShuffle<E> s)
Rearranges the lane elements of this shuffle selecting lane indexes controlled by another shuffle.static <E> VectorShuffle<E>
shuffle(VectorSpecies<E> species, IntUnaryOperator f)
Returns a shuffle of mapped indexes where each lane element is the result of applying a mapping function to the corresponding lane index.static <E> VectorShuffle<E>
shuffleIota(VectorSpecies<E> species)
Returns a shuffle where each lane element is the value of its corresponding lane index.static <E> VectorShuffle<E>
shuffleIota(VectorSpecies<E> species, int start)
Returns a shuffle with lane elements set to sequentialint
values starting fromstart
.static <E> VectorShuffle<E>
shuffleOffset(VectorSpecies<E> species, int start)
Returns a shuffle with lane elements set to sequentialint
values starting fromstart
and looping around species length.abstract VectorSpecies<E>
species()
Returns the species of this shuffle.abstract int[]
toArray()
Returns anint
array containing the lane elements of this shuffle.abstract Vector<E>
toVector()
Converts this shuffle into a vector, creating a vector from shuffle lane elements (int values) cast to the vector element type.
-
-
-
Method Detail
-
species
public abstract VectorSpecies<E> species()
Returns the species of this shuffle.- Returns:
- the species of this shuffle
-
length
public int length()
Returns the number of shuffle lanes (the length).- Returns:
- the number of shuffle lanes
-
cast
public abstract <F> VectorShuffle<F> cast(VectorSpecies<F> species)
Converts this shuffle to a shuffle of the given species of element typeF
.For each shuffle lane, where
N
is the lane index, the shuffle element at indexN
is placed, unmodified, into the resulting shuffle at indexN
.- Type Parameters:
F
- the boxed element type of the species- Parameters:
species
- species of desired shuffle- Returns:
- a shuffle converted by shape and element type
- Throws:
IllegalArgumentException
- if this shuffle length and the species length differ
-
shuffle
public static <E> VectorShuffle<E> shuffle(VectorSpecies<E> species, IntUnaryOperator f)
Returns a shuffle of mapped indexes where each lane element is the result of applying a mapping function to the corresponding lane index.Care should be taken to ensure VectorShuffle values produced from this method are consumed as constants to ensure optimal generation of code. For example, values held in static final fields or values held in loop constant local variables.
This method behaves as if a shuffle is created from an array of mapped indexes as follows:
int[] a = new int[species.length()]; for (int i = 0; i < a.length; i++) { a[i] = f.applyAsInt(i); } return VectorShuffle.fromValues(a);
- Parameters:
species
- shuffle speciesf
- the lane index mapping function- Returns:
- a shuffle of mapped indexes
- See Also:
Vector.shuffle(IntUnaryOperator)
-
shuffleIota
public static <E> VectorShuffle<E> shuffleIota(VectorSpecies<E> species)
Returns a shuffle where each lane element is the value of its corresponding lane index.This method behaves as if a shuffle is created from an identity index mapping function as follows:
return VectorShuffle.shuffle(i -> i);
- Parameters:
species
- shuffle species- Returns:
- a shuffle of lane indexes
- See Also:
Vector.shuffleIota()
-
shuffleIota
public static <E> VectorShuffle<E> shuffleIota(VectorSpecies<E> species, int start)
Returns a shuffle with lane elements set to sequentialint
values starting fromstart
.This method behaves as if a shuffle is created from an identity index mapping function as follows:
return VectorShuffle.shuffle(i -> i + start);
- Parameters:
species
- shuffle speciesstart
- starting value of sequence- Returns:
- a shuffle of lane indexes
- See Also:
Vector.shuffleIota(int)
-
shuffleOffset
public static <E> VectorShuffle<E> shuffleOffset(VectorSpecies<E> species, int start)
Returns a shuffle with lane elements set to sequentialint
values starting fromstart
and looping around species length.This method behaves as if a shuffle is created from an identity index mapping function as follows:
return VectorShuffle.shuffle(i -> (i + start) & (species.length() - 1));
- Parameters:
species
- shuffle speciesstart
- starting value of sequence- Returns:
- a shuffle of lane indexes
- See Also:
Vector.shuffleOffset(int)
-
fromValues
public static <E> VectorShuffle<E> fromValues(VectorSpecies<E> species, int... ixs)
Returns a shuffle where each lane element is set to a givenint
value logically AND'ed by the species length minus one.For each shuffle lane, where
N
is the shuffle lane index, the theint
value at indexN
logically AND'ed byspecies.length() - 1
is placed into the resulting shuffle at lane indexN
.- Parameters:
species
- shuffle speciesixs
- the givenint
values- Returns:
- a shuffle where each lane element is set to a given
int
value - Throws:
IndexOutOfBoundsException
- if the number of int values is< species.length()
- See Also:
Vector.shuffleFromValues(int...)
-
fromArray
public static <E> VectorShuffle<E> fromArray(VectorSpecies<E> species, int[] ixs, int offset)
Loads a shuffle from anint
array starting at an offset.For each shuffle lane, where
N
is the shuffle lane index, the array element at indexi + N
logically AND'ed byspecies.length() - 1
is placed into the resulting shuffle at lane indexN
.- Parameters:
species
- shuffle speciesixs
- theint
arrayoffset
- the offset into the array- Returns:
- a shuffle loaded from the
int
array - Throws:
IndexOutOfBoundsException
- ifoffset < 0
, oroffset > ixs.length - species.length()
- See Also:
Vector.shuffleFromArray(int[], int)
-
toArray
public abstract int[] toArray()
Returns anint
array containing the lane elements of this shuffle.This method behaves as if it
intoArray(int[], int)
stores} this shuffle into an allocated array and returns that array as follows:int[] a = new int[this.length()]; VectorShuffle.intoArray(a, 0); return a;
- Returns:
- an array containing the the lane elements of this vector
-
intoArray
public abstract void intoArray(int[] a, int offset)
Stores this shuffle into anint
array starting at offset.For each shuffle lane, where
N
is the shuffle lane index, the lane element at indexN
is stored into the array at indexi + N
.- Parameters:
a
- the arrayoffset
- the offset into the array- Throws:
IndexOutOfBoundsException
- ifi < 0
, oroffset > a.length - this.length()
-
toVector
public abstract Vector<E> toVector()
Converts this shuffle into a vector, creating a vector from shuffle lane elements (int values) cast to the vector element type.This method behaves as if it returns the result of creating a vector given an
int
array obtained from this shuffle's lane elements, as follows:int[] sa = this.toArray(); $type$[] va = new $type$[a.length]; for (int i = 0; i < a.length; i++) { va[i] = ($type$) sa[i]; } return IntVector.fromArray(va, 0);
- Returns:
- a vector representation of this shuffle
-
lane
public int lane(int i)
Gets theint
lane element at lane indexi
- Parameters:
i
- the lane index- Returns:
- the
int
lane element at lane indexi
-
rearrange
public abstract VectorShuffle<E> rearrange(VectorShuffle<E> s)
Rearranges the lane elements of this shuffle selecting lane indexes controlled by another shuffle.For each lane of the specified shuffle, at lane index
N
with lane elementI
, the lane element atI
from this shuffle is selected and placed into the resulting shuffle atN
.- Parameters:
s
- the shuffle controlling lane index selection- Returns:
- the rearrangement of the lane elements of this shuffle
-
-