RFR: 8276151: AArch64: Incorrect result for double to int vector conversion

Andrew Haley aph at openjdk.java.net
Thu Nov 4 09:25:09 UTC 2021


On Thu, 4 Nov 2021 07:19:55 GMT, Ningsheng Jian <njian at openjdk.org> wrote:

> Current NEON vector double to integer conversion generates code to convert double to long first and then narrow to integer, which does not follow Java language spec [1], and will get incorrect results for double values larger than Integer.MAX_VALUE or less than Integer.MIN_VALUE. For those too large/small values, result should be the largest/smallest representable value of type int, but converting to long and then narrowing to int will get different results.
> 
> There's no direct double to int vector conversion NEON instruction, so we simply do it with scalar conversion.
> 
> Also update compiler/vectorapi test cases to cover some corner cases.
> 
> [1] https://docs.oracle.com/javase/specs/jls/se17/html/jls-5.html#jls-5.1.3

src/hotspot/cpu/aarch64/aarch64_neon.ad line 518:

> 516:   ins_encode %{
> 517:     __ ins(as_FloatRegister($dst$$reg), __ D, as_FloatRegister($src$$reg), 0, 1);
> 518:     // Converting from double to int directly follows Java specification.

Suggestion:

    // We can't use fcvtzs(vector, integer) here because we need saturation arithmetic. See JDK-8276151.

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

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


More information about the hotspot-compiler-dev mailing list