RFR: 8284992: Fix misleading Vector API doc for LSHR operator
Paul Sandoz
psandoz at openjdk.java.net
Wed Apr 20 00:50:24 UTC 2022
On Tue, 19 Apr 2022 08:41:50 GMT, Jie Fu <jiefu at openjdk.org> wrote:
> Hi all,
>
> The Current Vector API doc for `LSHR` is
>
> Produce a>>>(n&(ESIZE*8-1)). Integral only.
>
>
> This is misleading which may lead to bugs for Java developers.
> This is because for negative byte/short elements, the results computed by `LSHR` will be different from that of `>>>`.
> For more details, please see https://github.com/openjdk/jdk/pull/8276#issue-1206391831 .
>
> After the patch, the doc for `LSHR` is
>
> Produce zero-extended right shift of a by (n&(ESIZE*8-1)) bits. Integral only.
>
>
> Thanks.
> Best regards,
> Jie
The intended pattern for the operator tokens is to present a short symbolic description using Java operators and common methods. It would be good to try and keep with this pattern, and clarify for the extra cases. Here's what i had in mind:
/** Produce {@code a>>>(n&(ESIZE*8-1))}. Integral only.
* <p>
* For operand types {@code byte} and {@code short} the operation behaves as if the operand is first implicitly widened
* to an {@code int} value with {@code (a & ((1 << ESIZE) - 1))} the result of which is then applied as the operand to this
* operation, the result of the operation is then narrowed from {@code int} to the operand type using an explicit cast.
*/
public static final /*bitwise*/ Binary LSHR;
-------------
PR: https://git.openjdk.java.net/jdk/pull/8291
More information about the core-libs-dev
mailing list