Species-agnostic shuffle
Vladimir Ivanov
vladimir.x.ivanov at oracle.com
Tue Jul 9 17:32:50 UTC 2024
Hi Martin,
What about loading indices as a Vector first (using
IntVector.fromArray()) and then converting it to VectorShuffle using
Vector.toShuffle()?
Best regards,
Vladimir Ivanov
On 7/9/24 09:59, Martin Traverso wrote:
> Hi,
>
> I've been experimenting with the Vector API in an attempt to port the
> XXH3 hashing algorithm to Java. One of the steps requires rearranging
> the elements of a vector by swapping adjacent values. I.e., (v0, v1, v2,
> v3, ...) -> (v1, v0, v3, v2, ...).
>
> One usability issue I'm running into is creating the VectorShuffle in a
> species-agnostic manner. The VectorShuffle.fromArray() expects a number
> of indices that matches *exactly* the length of the vector for the given
> species, so it's harder to create a shuffle that uses SPECIES_PREFERRED
> without additional logic to construct that array of indices dynamically.
>
> To illustrate, I need to do the following for each species:
>
> VectorShuffle.fromArray(LongVector.SPECIES_128, new int[] { 1, 0 }, 0)
> VectorShuffle.fromArray(LongVector.SPECIES_256, new int[] { 1, 0,
> 3, 2 }, 0)
> VectorShuffle.fromArray(LongVector.SPECIES_512, new int[] { 1, 0,
> 3, 2, 5, 4, 7, 6 }, 0)
>
> Of course, I could make something like this
>
> VectorShuffle.fromArray(LongVector.SPECIES_PREFERRED,
> makeIndexesFromTemplate(new int[] { 1, 0 }), 0)
>
> with my own custom "makeIndexesFromTemplate" function to create the
> array of indices of the appropriate length.
>
> Is there anything like that in the Vector APIs that I haven't been able
> to find? If not, would it make sense to add something like it, or allow
> VectorShuffle.fromXXX to derive such mapping?
>
> - Martin
>
More information about the panama-dev
mailing list