fpu: Fix OCP FP8 E4M3 conversion issues
v2 cover fpu: Fix OCP FP8 E4M3 conversion issues
This series fix following issues related to OCP FP8 E4M3 conversion.
- Numeric overflow to E4M3 produces incorrect exponent values due to a missing local variable update after calling uncanon_e4m3_overflow.
- Converting infinity to E4M3 incorrectly raises OF|NX exception flags.
Changes in version 2:
- The “fpu: Simplify OCP FP8 E4M3 NaN classification in parts_canonicalize” patch has been removed. This change retains the flexibility to classify NaNs.
rnax
Max Chou (2):
fpu: Fix repacking issues in the uncanonical step for E4M3 overflow
fpu: Fix unexpected exception flags when converting infinity to OCP
E4M3
fpu/softfloat-parts.c.inc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
Signature · 1 line
2.52.0
PATCH v2 1/2 fpu: Fix repacking issues in the uncanonical step for E4M3 overflow
In the uncanonical step, the input FloatParts will be repacked to the target FloatFmt. This commit fixes following issues after calling uncanon_e4m3_overflow in the uncanon/uncanon_normal functions.
- Add the local exp update after calling uncanon_e4m3_overflow in the parts_uncanon_normal function.
- Add the fraction shift after calling uncanon_e4m3_overflow in the parts_uncanon function.
--- fpu/softfloat-parts.c.inc | 2 ++ 1 file changed, 2 insertions(+)
fpu/softfloat-parts.c.inc +2 -0
@@ -387,6 +387,7 @@ static void partsN(uncanon_normal)(FloatPartsN *p, float_status *s, case float_expmax_e4m3: if (exp > exp_max || p->frac_hi > E4M3_NORMAL_FRAC_MAX) { partsN(uncanon_e4m3_overflow)(p, s, fmt, overflow_norm); + exp = p->exp; } break;
@@ -496,6 +497,7 @@ static void partsN(uncanon)(FloatPartsN *p, float_status *s, break; case float_expmax_e4m3: partsN(uncanon_e4m3_overflow)(p, s, fmt, saturate); + frac_shr(p, fmt->frac_shift); break; case float_expmax_normal: default:
Signature · 1 line
2.52.0
PATCH v2 2/2 fpu: Fix unexpected exception flags when converting infinity to OCP E4M3
In reply to Max ChouInfinity is a special case distinct from numeric overflow:
- Numeric overflow: finite value exceeds format's max normal -> overflow|inexact
- Infinity conversion: input is already infinite -> no flags
This commit fixes the unexpect exception flags by relocating the float exception flag update flow to be outside the uncanon_e4m3_overflow. And raising the overflow|inexact for numeric overflow in uncanon_normal.
--- fpu/softfloat-parts.c.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fpu/softfloat-parts.c.inc +1 -1
@@ -277,7 +277,6 @@ static void partsN(uncanon_e4m3_overflow)(FloatPartsN *p, float_status *s, const FloatFmt *fmt, bool saturate) { assert(N == 64); - float_raise(float_flag_overflow | float_flag_inexact, s); if (saturate) { p->exp = fmt->exp_max; p->frac_hi = E4M3_NORMAL_FRAC_MAX;
@@ -388,6 +387,7 @@ static void partsN(uncanon_normal)(FloatPartsN *p, float_status *s, if (exp > exp_max || p->frac_hi > E4M3_NORMAL_FRAC_MAX) { partsN(uncanon_e4m3_overflow)(p, s, fmt, overflow_norm); exp = p->exp; + flags |= (float_flag_overflow | float_flag_inexact); } break;
Signature · 1 line
2.52.0
Alistair Francis
AppliedQuoted 11 lines · Max Chou
This series fix following issues related to OCP FP8 E4M3 conversion.
- Numeric overflow to E4M3 produces incorrect exponent values due to a missing local variable update after calling
uncanon_e4m3_overflow.
- Converting infinity to E4M3 incorrectly raises OF|NX exception flags.Changes in version 2:
- The “fpu: Simplify OCP FP8 E4M3 NaN classification in parts_canonicalize” patch has been removed. This change retains the flexibility to classify NaNs.
Quoted 6 lines
rnax
Max Chou (2):
fpu: Fix repacking issues in the uncanonical step for E4M3 overflow
fpu: Fix unexpected exception flags when converting infinity to OCPE4M3
Thanks!
Applied to riscv-to-apply.next
Alistair
Quoted 8 lines
fpu/softfloat-parts.c.inc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)--
2.52.0