RFR: 8338021: Support saturating vector operators in VectorAPI [v3]

Andrey Turbanov aturbanov at openjdk.org
Sat Aug 17 17:28:56 UTC 2024


On Wed, 14 Aug 2024 04:59:23 GMT, Jatin Bhateja <jbhateja at openjdk.org> wrote:

>> Hi All,
>> 
>> As per the discussion on panama-dev mailing list[1], patch adds the support following new vector operators.
>> 
>> 
>>      . SUADD   : Saturating unsigned addition.
>>      . SADD    : Saturating signed addition. 
>>      . SUSUB   : Saturating unsigned subtraction.
>>      . SSUB    : Saturating signed subtraction.
>>      . UMAX    : Unsigned max
>>      . UMIN    : Unsigned min.
>>      
>> 
>> New vector operators are applicable to only integral types since their values wraparound in over/underflowing scenarios after setting appropriate status flags. For floating point types, as per IEEE 754 specs there are multiple schemes to handler underflow, one of them is gradual underflow which transitions the value to subnormal range. Similarly, overflow implicitly saturates the floating-point value to an Infinite value.
>> 
>> As the name suggests, these are saturating operations, i.e. the result of the computation is strictly capped by lower and upper bounds of the result type and is not wrapped around in underflowing or overflowing scenarios.
>> 
>> Summary of changes:
>> - Java side implementation of new vector operators.
>> - Add new scalar saturating APIs for each of the above saturating vector operator in corresponding primitive box classes, fallback implementation of vector operators is based over it.
>> - C2 compiler IR and inline expander changes.
>> - Optimized x86 backend implementation for new vector operators and their predicated counterparts.
>> - Extends existing VectorAPI Jtreg test suite to cover new operations.
>> 
>> Kindly review and share your feedback.
>> 
>> Best Regards,
>> PS: Intrinsification and auto-vectorization of new core-lib API will be addressed separately in a follow-up patch.
>> 
>> [1] https://mail.openjdk.org/pipermail/panama-dev/2024-May/020408.html
>
> Jatin Bhateja has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Review comments resolutions

src/java.base/share/classes/java/lang/Byte.java line 81:

> 79:      * A constant holding polarity(sign) mask used by saturating operations.
> 80:      */
> 81:     public static final byte POLARITY_MASK_BYTE  = (byte)(1 << 7);

Suggestion:

    public static final byte POLARITY_MASK_BYTE = (byte)(1 << 7);

src/java.base/share/classes/java/lang/Byte.java line 672:

> 670:         byte res = (byte)(a + b);
> 671:         boolean overflow = Byte.compareUnsigned(res, (byte)(a | b)) < 0;
> 672:         if (overflow)  {

Suggestion:

        if (overflow) {

src/java.base/share/classes/java/lang/Long.java line 93:

> 91:      * A constant holding polarity(sign) mask used by saturating operations.
> 92:      */
> 93:     public static final long POLARITY_MASK_LONG  = 1L << 63;

Suggestion:

    public static final long POLARITY_MASK_LONG = 1L << 63;

src/java.base/share/classes/java/lang/Long.java line 2033:

> 2031:         long res = a + b;
> 2032:         boolean overflow = Long.compareUnsigned(res, (a | b)) < 0;
> 2033:         if (overflow)  {

Suggestion:

        if (overflow) {

src/java.base/share/classes/java/lang/Short.java line 707:

> 705:         short res = (short)(a + b);
> 706:         boolean overflow = Short.compareUnsigned(res, (short)(a | b)) < 0;
> 707:         if (overflow)  {

Suggestion:

        if (overflow) {

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/20507#discussion_r1720807587
PR Review Comment: https://git.openjdk.org/jdk/pull/20507#discussion_r1720807612
PR Review Comment: https://git.openjdk.org/jdk/pull/20507#discussion_r1720807574
PR Review Comment: https://git.openjdk.org/jdk/pull/20507#discussion_r1720807513
PR Review Comment: https://git.openjdk.org/jdk/pull/20507#discussion_r1720807466


More information about the core-libs-dev mailing list