RFR: 8341260: Add Float16 to jdk.incubator.vector [v3]

Raffaello Giulietti rgiulietti at openjdk.org
Tue Oct 22 14:21:34 UTC 2024


On Mon, 21 Oct 2024 17:07:35 GMT, Joe Darcy <darcy at openjdk.org> wrote:

>> Port of Float16 from java.lang in the lworld+fp16 branch to jdk.incubabor.vector.
>
> Joe Darcy has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains seven additional commits since the last revision:
> 
>  - Add @since tag, respond to review feedback.
>  - Merge branch 'master' into JDK-8341260
>  - Remove comments for intrinsics per review feedback.
>  - Update with changes from lworld+fp16 Float16.
>  - Merge branch 'master' into JDK-8341260
>  - Add support for BigDecimal -> Float16 conversion.
>  - JDK-8341260: Add Float16 to jdk.incubator.vector

src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Float16.java line 471:

> 469: //                     }
> 470: //                 }
> 471: //             }

Suggestion:

             int scale = bd.scale();
             BigInteger unscaledValue = bd.unscaledValue();

             if (unscaledValue.abs().compareTo(BigInteger.valueOf(Long.MAX_VALUE)) <= 0) {
                 long intCompact = unscaledValue.longValue();
                 Float16 v = Float16.valueOf(intCompact);
                 if (scale == 0) {
                     return v;
                 }
                 /*
                  * The discussion for the double case also applies here. That is,
                  * the following test is precise for all long values, but here
                  * Long.MAX_VALUE is not an issue.
                  */
                 if (v.longValue() == intCompact) {
                     if (0 < scale && scale < FLOAT16_10_POW.length) {
                         return Float16.divide(v, FLOAT16_10_POW[scale]);
                     }
                     if (0 > scale && scale > -FLOAT16_10_POW.length) {
                         return Float16.multiply(v, FLOAT16_10_POW[-scale]);
                     }
                 }
             }

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

PR Review Comment: https://git.openjdk.org/jdk/pull/21574#discussion_r1810823357


More information about the core-libs-dev mailing list