Skip to content

Commit

Permalink
fpu: Bound increment for scalbn
Browse files Browse the repository at this point in the history
Without bounding the increment, we can overflow exp either here
in scalbn_decomposed or when adding the bias in round_canonical.
This can result in e.g. underflowing to 0 instead of overflowing
to infinity.

The old softfloat code did bound the increment.

Signed-off-by: Richard Henderson <[email protected]>
Reviewed-by: Peter Maydell <[email protected]>
Reviewed-by: Alex Bennée <[email protected]>
Tested-by: Alex Bennée <[email protected]>
Signed-off-by: Peter Maydell <[email protected]>
  • Loading branch information
rth7680 authored and pm215 committed Apr 17, 2018
1 parent 1b2503f commit ce8d408
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions fpu/softfloat.c
Original file line number Diff line number Diff line change
Expand Up @@ -1878,6 +1878,12 @@ static FloatParts scalbn_decomposed(FloatParts a, int n, float_status *s)
return return_nan(a, s);
}
if (a.cls == float_class_normal) {
/* The largest float type (even though not supported by FloatParts)
* is float128, which has a 15 bit exponent. Bounding N to 16 bits
* still allows rounding to infinity, without allowing overflow
* within the int32_t that backs FloatParts.exp.
*/
n = MIN(MAX(n, -0x10000), 0x10000);
a.exp += n;
}
return a;
Expand Down

0 comments on commit ce8d408

Please sign in to comment.