From 4df7856a931e710c96d2804d428869df7759f337 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 14 Dec 2024 17:16:09 -0800 Subject: [PATCH] Make the frnd function round according to the C 'round' spec I don't know if this is correct as I don't have access to the ARC V3 specification, but if GCC is correct and QEMU is wrong, then the fdrnd (and fsrnd) functions are supposed to round with ties rounding away from zero, just like the C round and roundf functions. Signed-off-by: Keith Packard --- target/arc/fpu-helper-v3.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/target/arc/fpu-helper-v3.c b/target/arc/fpu-helper-v3.c index 233abefab2b..ebfdcc3f2b5 100644 --- a/target/arc/fpu-helper-v3.c +++ b/target/arc/fpu-helper-v3.c @@ -173,13 +173,35 @@ CONVERSION_HELPERS(fuint2s, uint32_to_float32) CONVERSION_HELPERS(fs2uint, float32_to_uint32) CONVERSION_HELPERS(fs2uint_rz, float32_to_uint32_round_to_zero) -CONVERSION_HELPERS(fdrnd, float64_round_to_int) -CONVERSION_HELPERS(fsrnd, float32_round_to_int) - CONVERSION_HELPERS(fdsqrt, float64_sqrt) CONVERSION_HELPERS(fssqrt, float32_sqrt) CONVERSION_HELPERS(fhsqrt, float16_sqrt) +/* Soft fpu helper for round_to_int with rounding away mode */ +#define CONVERSION_HELPERS_RA(NAME, FLT_HELPER) \ +uint64_t helper_##NAME(CPUARCState *env, uint64_t src) \ +{ \ + FloatRoundMode saved_rounding_mode; \ + bool saved_flush_zero; \ + \ + saved_flush_zero = get_flush_to_zero(&env->fp_status); \ + saved_rounding_mode = get_float_rounding_mode(&env->fp_status); \ + \ + set_flush_to_zero(true, &env->fp_status); \ + set_float_rounding_mode(float_round_ties_away, &env->fp_status); \ + \ + uint64_t ret = FLT_HELPER(src, &env->fp_status); \ + \ + set_flush_to_zero(saved_flush_zero, &env->fp_status); \ + set_float_rounding_mode(saved_rounding_mode, &env->fp_status); \ + \ + check_fpu_raise_exception(env); \ + return ret; \ +} + +CONVERSION_HELPERS_RA(fdrnd, float64_round_to_int) +CONVERSION_HELPERS_RA(fsrnd, float32_round_to_int) + /* Soft fpu helper for round_to_int with rounding to zero mode */ #define CONVERSION_HELPERS_RZ(NAME, FLT_HELPER) \ uint64_t helper_##NAME(CPUARCState *env, uint64_t src) \