RFR: 8283307: Vectorize unsigned shift right on signed subword types

Jie Fu jiefu at openjdk.java.net
Fri Apr 8 08:34:42 UTC 2022


On Fri, 8 Apr 2022 08:19:34 GMT, Fei Gao <fgao at openjdk.org> wrote:

>> src/hotspot/share/opto/superword.cpp line 2027:
>> 
>>> 2025:       }
>>> 2026:     } else {
>>> 2027:       // Vector unsigned right shift for signed subword types behaves differently
>> 
>> Can you make it to be more clear about the difference?
>
> In any Java arithmetic operation, operands of small integer types (boolean, byte, char & short) should be promoted to int first. For example, for negative short values, after sign-extension to int, the value should be like:
> ![image](https://user-images.githubusercontent.com/39403138/162386713-13c8cc1d-3075-4680-8170-dcbac19abd0a.png)
> In java spec, unsigned right shift on the promoted value is to shift data right and fill the higher bits with zero-extension. We may find that when shift amount is less than 16, the lower-16 bit value is right shift with one-extension, like:
> ![image](https://user-images.githubusercontent.com/39403138/162389373-9b178d03-d259-4cac-8c3a-669892380ca6.png)
> As vector elements of small types don't have upper bits of int, vector unsigned right shift on short elements is to fill lower bits with 0 directly like:
> ![image](https://user-images.githubusercontent.com/39403138/162390101-d1b53d2f-54be-48d5-9210-11d71c3f9145.png)
> In this way, the result of vector unsigned right shift is different from the result of scalar unsigned right shift for signed subword types.

> In any Java arithmetic operation, operands of small integer types (boolean, byte, char & short) should be promoted to int first. For example, for negative short value, after sign-extension to int, the value should be like: ![image](https://user-images.githubusercontent.com/39403138/162386713-13c8cc1d-3075-4680-8170-dcbac19abd0a.png) In java spec, unsigned right shift on the promoted value is to shift data right and fill the higher bits with zero-extension. We may find that when shift amount is less than 16, the lower-16 bit value is right shift with one-extension, like: ![image](https://user-images.githubusercontent.com/39403138/162389373-9b178d03-d259-4cac-8c3a-669892380ca6.png) As vector elements of small types don't have upper bits of int, vector unsigned right shift on short elements is to fill lower bits with 0 directly like: ![image](https://user-images.githubusercontent.com/39403138/162390101-d1b53d2f-54be-48d5-9210-11d71c3f9145.png) In this way, the result of vector unsigne
 d right shift is different from the result of scalar unsigned right shift for signed subword types.

Got it.
Thanks for your kind explanation.

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

PR: https://git.openjdk.java.net/jdk/pull/7979


More information about the hotspot-compiler-dev mailing list