@samitouri / QOSamiQemu / commits / 2c2e54428b

fpu: Add overflow_raises_invalid to FloatFmt

ARM Alt HP raises different exceptions on overflow than is standard for IEEE when saturating a value. Add a flag to control this effect. Reviewed-by: Chao Liu <chao.liu.zevorn@gmail.com> Signed-off-by: Max Chou <max.chou@sifive.com> [rth: Split out of a larger patch] Signed-off-by: Richard Henderson <richard.henderson@linaro.org>

Max Chou committed Feb 5, 2026 at 15:37 UTC 2c2e54428b3e4c4921e4c83ccc8b43b1ff7158d0
2 files changed +8 -2
fpu/softfloat-parts.c.inc
+3 -1
@@ -348,7 +348,9 @@ static void partsN(uncanon_normal)(FloatPartsN *p, float_status *s,
348 case float_expmax_normal:
349 if (unlikely(exp > exp_max)) {
350 /* Overflow. Return the maximum normal. */
351 - flags = float_flag_invalid;
351 + flags = (fmt->overflow_raises_invalid
352 + ? float_flag_invalid
353 + : float_flag_overflow | float_flag_inexact);
354 exp = exp_max;
355 frac_allones(p);
356 p->frac_lo &= ~round_mask;
fpu/softfloat.c
+5 -1
@@ -542,7 +542,9 @@ typedef enum __attribute__((__packed__)) {
542 * The following optional modifiers are available:
543 * exp_max_kind: affects how exp == exp_max is interpreted
544 * has_explicit_bit: has an explicit integer bit; this affects whether
545 - * the float_status floatx80_behaviour handling applies
545 + * the float_status floatx80_behaviour handling applies
546 + * overflow_raises_invalid: for float_expmax_normal, raise invalid
547 + * instead of overflow.
548 */
549 typedef struct {
550 int exp_size;
@@ -553,6 +555,7 @@ typedef struct {
555 int frac_shift;
556 FloatFmtExpMaxKind exp_max_kind;
557 bool has_explicit_bit;
558 + bool overflow_raises_invalid;
559 uint64_t round_mask;
560 } FloatFmt;
561
@@ -576,6 +579,7 @@ static const FloatFmt float16_params = {
579 static const FloatFmt float16_params_ahp = {
580 FLOAT_PARAMS(5, 10),
581 .exp_max_kind = float_expmax_normal,
582 + .overflow_raises_invalid = true,
583 };
584
585 static const FloatFmt bfloat16_params = {