From: Ilya Leoshkevich Date: Tue, 10 Feb 2026 21:39:01 +0000 (+0100) Subject: target/s390x: Extract s390_get_bfp_rounding_mode() X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f5682b9deef3d572bbe780e04857166b77870718;p=thirdparty%2Fqemu.git target/s390x: Extract s390_get_bfp_rounding_mode() For DIVIDE TO INTEGER it will be helpful to pass final-quotient rounding mode around explicitly rather than setting it in fpu_status implicitly. To facilitate this, extract a function for converting the mask to the rounding mode. Reviewed-by: Richard Henderson Reviewed-by: Thomas Huth Signed-off-by: Ilya Leoshkevich Message-ID: <20260210214044.1174699-3-iii@linux.ibm.com> Signed-off-by: Thomas Huth --- diff --git a/target/s390x/tcg/fpu_helper.c b/target/s390x/tcg/fpu_helper.c index 1ba43715ac..7a3ff501a4 100644 --- a/target/s390x/tcg/fpu_helper.c +++ b/target/s390x/tcg/fpu_helper.c @@ -56,6 +56,35 @@ uint8_t s390_softfloat_exc_to_ieee(unsigned int exc) return s390_exc; } +static int s390_get_bfp_rounding_mode(CPUS390XState *env, int m3) +{ + switch (m3) { + case 0: + /* current mode */ + return env->fpu_status.float_rounding_mode; + case 1: + /* round to nearest with ties away from 0 */ + return float_round_ties_away; + case 3: + /* round to prepare for shorter precision */ + return float_round_to_odd; + case 4: + /* round to nearest with ties to even */ + return float_round_nearest_even; + case 5: + /* round to zero */ + return float_round_to_zero; + case 6: + /* round to +inf */ + return float_round_up; + case 7: + /* round to -inf */ + return float_round_down; + default: + g_assert_not_reached(); + } +} + /* Should be called after any operation that may raise IEEE exceptions. */ static void handle_exceptions(CPUS390XState *env, bool XxC, uintptr_t retaddr) { @@ -416,37 +445,8 @@ int s390_swap_bfp_rounding_mode(CPUS390XState *env, int m3) { int ret = env->fpu_status.float_rounding_mode; - switch (m3) { - case 0: - /* current mode */ - break; - case 1: - /* round to nearest with ties away from 0 */ - set_float_rounding_mode(float_round_ties_away, &env->fpu_status); - break; - case 3: - /* round to prepare for shorter precision */ - set_float_rounding_mode(float_round_to_odd, &env->fpu_status); - break; - case 4: - /* round to nearest with ties to even */ - set_float_rounding_mode(float_round_nearest_even, &env->fpu_status); - break; - case 5: - /* round to zero */ - set_float_rounding_mode(float_round_to_zero, &env->fpu_status); - break; - case 6: - /* round to +inf */ - set_float_rounding_mode(float_round_up, &env->fpu_status); - break; - case 7: - /* round to -inf */ - set_float_rounding_mode(float_round_down, &env->fpu_status); - break; - default: - g_assert_not_reached(); - } + set_float_rounding_mode(s390_get_bfp_rounding_mode(env, m3), + &env->fpu_status); return ret; }