On Wed, 20 May 2026 at 19:25, Richard Henderson
<[email protected]> wrote:
>
> The unique e4m3 nan encoding is SNaN for Arm.
>
> Signed-off-by: Richard Henderson <[email protected]>
> ---
>  target/arm/tcg/vfp_helper.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/target/arm/tcg/vfp_helper.c b/target/arm/tcg/vfp_helper.c
> index 8d3f6e3a2e..c10b085f08 100644
> --- a/target/arm/tcg/vfp_helper.c
> +++ b/target/arm/tcg/vfp_helper.c
> @@ -46,6 +46,7 @@ void arm_set_default_fp_behaviours(float_status *s)
>      set_float_3nan_prop_rule(float_3nan_prop_s_cab, s);
>      set_float_infzeronan_rule(float_infzeronan_dnan_if_qnan, s);
>      set_float_default_nan_pattern(0b01000000, s);
> +    set_float_e4m3_nan_is_snan(true, s);
>  }
>
>  /*
> @@ -67,6 +68,7 @@ void arm_set_ah_fp_behaviours(float_status *s)
>      set_float_infzeronan_rule(float_infzeronan_dnan_never |
>                                float_infzeronan_suppress_invalid, s);
>      set_float_default_nan_pattern(0b11000000, s);
> +    set_float_e4m3_nan_is_snan(true, s);
>  }
>
>  /* Convert host exception flags to vfp form.  */

These functions are supposed to set only the bits of the
FP config that change between AH=0 and AH=1; we call them
when FPCR.AH is toggled. Conveniently, up until now all
the FP config that remains the same across AH=0 and AH=1
has been the same as the default fpu config, so we haven't
needed a place to do "initialize float_status to the other
parts of what Arm uses", and arm_cpu_reset_hold has been
able to just call one or the other of these functions starting
from a zeroed-out fp_status, and then adjust the default
NaN mode and the ftz config for a few of the fp_status words.

So ideally we should set the e4m3_nan_is_snan elsewhere,
except that setting it on all 8 of our fp_status fields
is a bit tedious. Maybe something like:

/*
 * Fully initialize an fp_status to the usual Arm
 * behaviours. If you want the AH=1 choices you can
 * call arm_set_ah_fp_behaviours() afterwards.
 */
arm_init_fp_status(float_status *s);

and have the implementation be
   *s = (float_status){};
   arm_set_default_fp_behaviours(s);
   set_float_e4m3_nan_is_snan(true, s);
   /* We want 0 for all other settings */

?

Then reset can do
    for (int i = 0; i < FPST_COUNT; i++) {
        arm_init_fp_status(&env->vfp.fp_status[i]);
    }
    set_flush_to_zero(1, &env->vfp.fp_status[FPST_STD]);
    set_flush_inputs_to_zero(1, &env->vfp.fp_status[FPST_STD]);
    set_default_nan_mode(1, &env->vfp.fp_status[FPST_STD]);
    set_default_nan_mode(1, &env->vfp.fp_status[FPST_STD_F16]);
    set_default_nan_mode(1, &env->vfp.fp_status[FPST_ZA]);
    set_default_nan_mode(1, &env->vfp.fp_status[FPST_ZA_F16]);
    arm_set_ah_fp_behaviours(&env->vfp.fp_status[FPST_AH]);
    set_flush_to_zero(1, &env->vfp.fp_status[FPST_AH]);
    set_flush_inputs_to_zero(1, &env->vfp.fp_status[FPST_AH]);
    arm_set_ah_fp_behaviours(&env->vfp.fp_status[FPST_AH_F16]);

and the code we want to add for fp8 can init its local
fp_status by calling arm_init_fp_status.

thanks
-- PMM

Reply via email to