[vector] rearrange with implicit wrapping

Paul Sandoz paul.sandoz at oracle.com
Tue Apr 20 01:33:14 UTC 2021



> On Apr 19, 2021, at 5:38 PM, Viswanathan, Sandhya <sandhya.viswanathan at intel.com> wrote:
> 
> Hi Paul,
> 
> I think we will need to do an explicit wrap (vector AND) either in Java or in the intrinsic.
> Doing it in Java in an optimized fashion could be tricky as we only have shuffle -> vector and not vice versa vector -> shuffle method (see wrapIndexes in AbstractShuffle.java).
> Does this ask for a package private vector->shuffle method, if not public?
> 

There is a Vector.toShuffle method, not currently optimized.

You do mean doing something like shuffle -> vector -> AND with species length - 1 -> shuffle -> input to rearrange? 
We could just passed in the result of Shuffle.wrapIndexes to rearrange? And optimize that method e.g. push down to the specializations or make an intrinsic?


> The underlying instructions (.e.g pshufb) uses the bit 8 (MSB) of the shuffle as a special case. 

Ah!

> When the MSB is set, the corresponding element is cleared and that is what you are observing.
> Let me know if you need me to handle it in the intrinsic.
> 

I think it may be worth exploring an intrinsic solution to help make the best decision. I am concerned rearrange is fragile with regards to the input shuffle.

Paul.

> Best Regards,
> Sandhya
> 
> 
> 
> -----Original Message-----
> From: Paul Sandoz <paul.sandoz at oracle.com> 
> Sent: Monday, April 19, 2021 4:56 PM
> To: panama-dev at openjdk.java.net' <panama-dev at openjdk.java.net>
> Cc: Viswanathan, Sandhya <sandhya.viswanathan at intel.com>
> Subject: [vector] rearrange with implicit wrapping 
> 
> Hi,
> 
> I have started work on support rearrange with implicit wrapping, where the rearrange methods accepting a boolean parameter, which if true implicitly wraps the given shuffle:
> 
>  https://urldefense.com/v3/__https://github.com/openjdk/panama-vector/compare/vectorIntrinsics...PaulSandoz:rearrange-wrap__;!!GqivPVa7Brio!Phx_uvFOKPbYKCBsgyNbCJdiVydvIKHnAHYZ_SEJmNY0vubu_agP80yn_4OTHjeLmQ$ 
> 
> This currently results in some test failures on x64 when it hits the intrinsics. I think there is some zeroing going in some cases.
> 
> Sandhya, I am unsure how the intrinsics behave, if they are all consistent, how they interrelate with shuffle, and how the Java implementation deviates.
> 
> The Java implementation was updated to consistently wrap: 
> 
> @ForceInline
> final
> <S extends VectorShuffle<Integer>>
> IntVector rearrangeTemplate(Class<S> shuffletype, S shuffle, boolean wrap) {
>    if (!wrap) {
>        shuffle.checkIndexes();
>    }
>    return VectorSupport.rearrangeOp(
>        getClass(), shuffletype, int.class, length(),
>        this, shuffle,
>        (v1, s_) -> v1.uOp((i, a) -> {
>            int ei = s_.laneSource(i);
>            return v1.lane(s_.wrapIndex(ei));
>        }));
> }
> 
> AFAICT rearrange is depending on the checks performed on the shuffle, otherwise the rearrange intrinsic fails to unbox it.
> 
> Paul.



More information about the panama-dev mailing list