[vector] rearrange with implicit wrapping

Viswanathan, Sandhya sandhya.viswanathan at intel.com
Tue Apr 20 00:38:28 UTC 2021


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?

The underlying instructions (.e.g pshufb) uses the bit 8 (MSB) of the shuffle as a special case. 
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.

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://github.com/openjdk/panama-vector/compare/vectorIntrinsics...PaulSandoz:rearrange-wrap

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