RFR: 8284932: [Vector API] Incorrect implementation of LSHR operator for negative byte/short elements

Jie Fu jiefu at openjdk.java.net
Sun Apr 17 23:09:31 UTC 2022


On Sun, 17 Apr 2022 17:25:57 GMT, Quan Anh Mai <duke at openjdk.java.net> wrote:

> Hi,
> 
> The `>>>` operator is not defined for subword types, what the code in line 28 does vs what it is supposed to do are different, which is more likely the bug here. An unsigned shift should operate on subword types the same as it does on word and double-word types, which is to zero extend the value before shifting it rightwards.
> 
> Another argument would be that an unsigned shift operates on the unsigned types, and the signed cast exposes this misunderstanding regarding the operation.
> 
> Thanks.

Thanks @merykitty for your comments.

What I show in this PR is the typical translation of a Java scalar program to Vector API code.
Obviously, the implementation is wrong for negative bytes/shorts according to the description of the Vecotor API doc.

As a general programming language, Java does support the usage of `>>>` for negative bytes/shorts.
Will you use this Vector API to optimize a Java lib which doesn't know the actual input at all?
For a given shift_cnt, why not produce the same result for Vector API just as what is done for scalar `>>>`?

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

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


More information about the core-libs-dev mailing list