@samitouri / QOSamiQemu / commits / 3d952d7cb5

fpu: Introduce parts64_round_to_fmt

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>

Richard Henderson committed Apr 25, 2026 at 22:15 UTC 3d952d7cb57752a1b6a2a7d3a06c1265c72b6da4
2 files changed +22 -3
fpu/softfloat.c
+19 -3
@@ -1396,6 +1396,24 @@ float64 float64_round_pack_canonical(FloatParts64 *p, float_status *s)
1396 return pack_raw64(p, &float64_params);
1397 }
1398
1399 +/*
1400 + * Round to Fmt while remaining canonicalized.
1401 + */
1402 +FloatParts64 parts64_round_to_fmt(const FloatParts64 *p, float_status *s,
1403 + const FloatFmt *fmt)
1404 +{
1405 + FloatParts64 r = *p;
1406 +
1407 + parts64_uncanon(&r, s, fmt, false);
1408 + /*
1409 + * We normally expect uncanon to be followed by pack_raw,
1410 + * so we don't actually crop the bits. Do so now.
1411 + */
1412 + r.frac &= MAKE_64BIT_MASK(0, fmt->frac_size);
1413 + parts64_canonicalize(&r, s, fmt);
1414 + return r;
1415 +}
1416 +
1417 static float64 float64r32_pack_raw(FloatParts64 *p)
1418 {
1419 /*
@@ -5176,10 +5194,8 @@ static void parts_s390_divide_to_integer(FloatParts64 *a, FloatParts64 *b,
5194 /* Round remainder to the target format */
5195 *r = *r_precise;
5196 status->float_exception_flags = 0;
5179 - parts64_uncanon(r, status, fmt, false);
5197 + *r = parts64_round_to_fmt(r, status, fmt);
5198 r_flags = status->float_exception_flags;
5181 - r->frac &= (1ULL << fmt->frac_size) - 1;
5182 - parts64_canonicalize(r, status, fmt);
5199
5200 /* POp table "Results: DIVIDE TO INTEGER (Part 2 of 2)" */
5201 if (is_q_smallish) {
include/fpu/softfloat-parts.h
+3
@@ -196,4 +196,7 @@ FloatParts128 parts128_round_to_int(const FloatParts128 *a,
196 int scale, float_status *s,
197 const FloatFmt *fmt);
198
199 +FloatParts64 parts64_round_to_fmt(const FloatParts64 *p, float_status *s,
200 + const FloatFmt *fmt);
201 +
202 #endif