[PATCH v3 3/5] fpu: Restrict parts_round_to_int_normal to target precision

Ilya Leoshkevich posted 5 patches 1 week, 2 days ago
Maintainers: Aurelien Jarno <aurelien@aurel32.net>, Peter Maydell <peter.maydell@linaro.org>, "Alex Bennée" <alex.bennee@linaro.org>, Richard Henderson <richard.henderson@linaro.org>, Ilya Leoshkevich <iii@linux.ibm.com>, David Hildenbrand <david@kernel.org>, Thomas Huth <thuth@redhat.com>
There is a newer version of this series
[PATCH v3 3/5] fpu: Restrict parts_round_to_int_normal to target precision
Posted by Ilya Leoshkevich 1 week, 2 days ago
Currently parts_round_to_int_normal() assumes that its input has just
been unpacked and therefore doesn't expect non-zero fraction bits past
target precision.

The upcoming DIVIDE TO INTEGER use cases needs it to support
calculations on intermediate values that utilize all fraction bits,
while at the same time restricting the result's precision to frac_size.

Delete the "All integral" check, because even though really large
values are always integer, their low fraction bits still need to be
truncated. For the same reason, make sure rnd_mask covers at least
fraction bits past target precision.

Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
---
 fpu/softfloat-parts.c.inc | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/fpu/softfloat-parts.c.inc b/fpu/softfloat-parts.c.inc
index 5e0438fc0b7..93ed59626e5 100644
--- a/fpu/softfloat-parts.c.inc
+++ b/fpu/softfloat-parts.c.inc
@@ -1118,11 +1118,6 @@ static bool partsN(round_to_int_normal)(FloatPartsN *a, FloatRoundMode rmode,
         return true;
     }
 
-    if (a->exp >= frac_size) {
-        /* All integral */
-        return false;
-    }
-
     if (N > 64 && a->exp < N - 64) {
         /*
          * Rounding is not in the low word -- shift lsb to bit 2,
@@ -1133,7 +1128,7 @@ static bool partsN(round_to_int_normal)(FloatPartsN *a, FloatRoundMode rmode,
         frac_lsb = 1 << 2;
     } else {
         shift_adj = 0;
-        frac_lsb = DECOMPOSED_IMPLICIT_BIT >> (a->exp & 63);
+        frac_lsb = DECOMPOSED_IMPLICIT_BIT >> MIN(a->exp, frac_size);
     }
 
     frac_lsbm1 = frac_lsb >> 1;
-- 
2.52.0
Re: [PATCH v3 3/5] fpu: Restrict parts_round_to_int_normal to target precision
Posted by Richard Henderson 6 days, 1 hour ago
On 1/30/26 04:57, Ilya Leoshkevich wrote:
> Currently parts_round_to_int_normal() assumes that its input has just
> been unpacked and therefore doesn't expect non-zero fraction bits past
> target precision.
> 
> The upcoming DIVIDE TO INTEGER use cases needs it to support
> calculations on intermediate values that utilize all fraction bits,
> while at the same time restricting the result's precision to frac_size.
> 
> Delete the "All integral" check, because even though really large
> values are always integer, their low fraction bits still need to be
> truncated. For the same reason, make sure rnd_mask covers at least
> fraction bits past target precision.
> 
> Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
> ---
>   fpu/softfloat-parts.c.inc | 7 +------
>   1 file changed, 1 insertion(+), 6 deletions(-)
> 
> diff --git a/fpu/softfloat-parts.c.inc b/fpu/softfloat-parts.c.inc
> index 5e0438fc0b7..93ed59626e5 100644
> --- a/fpu/softfloat-parts.c.inc
> +++ b/fpu/softfloat-parts.c.inc
> @@ -1118,11 +1118,6 @@ static bool partsN(round_to_int_normal)(FloatPartsN *a, FloatRoundMode rmode,
>           return true;
>       }
>   
> -    if (a->exp >= frac_size) {
> -        /* All integral */
> -        return false;
> -    }
> -
>       if (N > 64 && a->exp < N - 64) {
>           /*
>            * Rounding is not in the low word -- shift lsb to bit 2,
> @@ -1133,7 +1128,7 @@ static bool partsN(round_to_int_normal)(FloatPartsN *a, FloatRoundMode rmode,
>           frac_lsb = 1 << 2;
>       } else {
>           shift_adj = 0;
> -        frac_lsb = DECOMPOSED_IMPLICIT_BIT >> (a->exp & 63);
> +        frac_lsb = DECOMPOSED_IMPLICIT_BIT >> MIN(a->exp, frac_size);
>       }
>   
>       frac_lsbm1 = frac_lsb >> 1;

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~