Skip to content

Commit 3d113af

Browse files
committed
8369051: More small Float16 refactorings
Reviewed-by: rgiulietti
1 parent 5fccabf commit 3d113af

File tree

1 file changed

+6
-5
lines changed
  • src/jdk.incubator.vector/share/classes/jdk/incubator/vector

1 file changed

+6
-5
lines changed

src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Float16.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import static jdk.incubator.vector.Float16Consts.SIGN_BIT_MASK;
3535
import static jdk.incubator.vector.Float16Consts.EXP_BIT_MASK;
3636
import static jdk.incubator.vector.Float16Consts.SIGNIF_BIT_MASK;
37+
import static jdk.incubator.vector.Float16Consts.MAG_BIT_MASK;
3738

3839
import static java.lang.Float.float16ToFloat;
3940
import static java.lang.Float.floatToFloat16;
@@ -396,7 +397,7 @@ public static Float16 valueOf(double d) {
396397
}
397398
long f_signif_bits = doppel & 0x000f_ffff_ffff_ffffL | msb;
398399

399-
int PRECISION_DIFF = Double.PRECISION - PRECISION; // 42
400+
final int PRECISION_DIFF = Double.PRECISION - PRECISION; // 42
400401
// Significand bits as if using rounding to zero (truncation).
401402
short signif_bits = (short)(f_signif_bits >> (PRECISION_DIFF + expdelta));
402403

@@ -774,7 +775,7 @@ public static boolean isInfinite(Float16 f16) {
774775
* @see Double#isFinite(double)
775776
*/
776777
public static boolean isFinite(Float16 f16) {
777-
return (float16ToRawShortBits(f16) & (EXP_BIT_MASK | SIGNIF_BIT_MASK)) <=
778+
return (float16ToRawShortBits(f16) & MAG_BIT_MASK) <=
778779
float16ToRawShortBits(MAX_VALUE);
779780
}
780781

@@ -1093,7 +1094,7 @@ public static Float16 min(Float16 a, Float16 b) {
10931094
* 2) performing the operation in the wider format
10941095
* 3) converting the result from 2) to the narrower format
10951096
*
1096-
* For example, this property hold between the formats used for the
1097+
* For example, this property holds between the formats used for the
10971098
* float and double types. Therefore, the following is a valid
10981099
* implementation of a float addition:
10991100
*
@@ -1477,7 +1478,7 @@ public static Float16 negate(Float16 f16) {
14771478
// operation. Therefore, in this case do _not_ use the float
14781479
// unary minus as an implementation as that is not guaranteed
14791480
// to flip the sign bit of a NaN.
1480-
return shortBitsToFloat16((short)(f16.value ^ (short)0x0000_8000));
1481+
return shortBitsToFloat16((short)(f16.value ^ SIGN_BIT_MASK));
14811482
}
14821483

14831484
/**
@@ -1495,7 +1496,7 @@ public static Float16 negate(Float16 f16) {
14951496
public static Float16 abs(Float16 f16) {
14961497
// Zero out sign bit. Per IEE 754-2019 section 5.5.1, abs is a
14971498
// bit-level operation and not a logical operation.
1498-
return shortBitsToFloat16((short)(f16.value & (short)0x0000_7FFF));
1499+
return shortBitsToFloat16((short)(f16.value & MAG_BIT_MASK));
14991500
}
15001501

15011502
/**

0 commit comments

Comments
 (0)