Patchwork fpu/softfloat.c: Remove pointless shift of always-zero value

login
register
mail settings
Submitter Peter Maydell
Date Sept. 24, 2012, 4:28 p.m.
Message ID <1348504115-13203-1-git-send-email-peter.maydell@linaro.org>
Download mbox | patch
Permalink /patch/186485/
State New
Headers show

Comments

Peter Maydell - Sept. 24, 2012, 4:28 p.m.
In float16_to_float32, when returning an infinity, just pass zero
as the mantissa argument to packFloat32(), rather than shifting
a value which we know must be zero.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
Spotted by the clang static analyzer. This brings this code into line with
the other float-to-float conversion functions and was probably a harmless
cut-n-paste error from the normal-return codepath.

 fpu/softfloat.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Richard Henderson - Sept. 24, 2012, 4:43 p.m.
On 2012-09-24 09:28, Peter Maydell wrote:
> In float16_to_float32, when returning an infinity, just pass zero
> as the mantissa argument to packFloat32(), rather than shifting
> a value which we know must be zero.
> 
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>

Reviewed-by: Richard Henderson <rth@twiddle.net>


r~
Aurelien Jarno - Sept. 24, 2012, 5:23 p.m.
On Mon, Sep 24, 2012 at 05:28:35PM +0100, Peter Maydell wrote:
> In float16_to_float32, when returning an infinity, just pass zero
> as the mantissa argument to packFloat32(), rather than shifting
> a value which we know must be zero.
> 
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
> Spotted by the clang static analyzer. This brings this code into line with
> the other float-to-float conversion functions and was probably a harmless
> cut-n-paste error from the normal-return codepath.
> 
>  fpu/softfloat.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fpu/softfloat.c b/fpu/softfloat.c
> index b29256a..01a28ca 100644
> --- a/fpu/softfloat.c
> +++ b/fpu/softfloat.c
> @@ -3007,7 +3007,7 @@ float32 float16_to_float32(float16 a, flag ieee STATUS_PARAM)
>          if (aSig) {
>              return commonNaNToFloat32(float16ToCommonNaN(a STATUS_VAR) STATUS_VAR);
>          }
> -        return packFloat32(aSign, 0xff, aSig << 13);
> +        return packFloat32(aSign, 0xff, 0);
>      }
>      if (aExp == 0) {
>          int8 shiftCount;
> -- 
> 1.7.9.5

Good catch!

Reviewed-by: Aurelien Jarno <aurelien@aurel32.net>
Aurelien Jarno - Oct. 1, 2012, 8:12 p.m.
On Mon, Sep 24, 2012 at 05:28:35PM +0100, Peter Maydell wrote:
> In float16_to_float32, when returning an infinity, just pass zero
> as the mantissa argument to packFloat32(), rather than shifting
> a value which we know must be zero.
> 
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
> Spotted by the clang static analyzer. This brings this code into line with
> the other float-to-float conversion functions and was probably a harmless
> cut-n-paste error from the normal-return codepath.
> 
>  fpu/softfloat.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fpu/softfloat.c b/fpu/softfloat.c
> index b29256a..01a28ca 100644
> --- a/fpu/softfloat.c
> +++ b/fpu/softfloat.c
> @@ -3007,7 +3007,7 @@ float32 float16_to_float32(float16 a, flag ieee STATUS_PARAM)
>          if (aSig) {
>              return commonNaNToFloat32(float16ToCommonNaN(a STATUS_VAR) STATUS_VAR);
>          }
> -        return packFloat32(aSign, 0xff, aSig << 13);
> +        return packFloat32(aSign, 0xff, 0);
>      }
>      if (aExp == 0) {
>          int8 shiftCount;

Thanks, applied.

Patch

diff --git a/fpu/softfloat.c b/fpu/softfloat.c
index b29256a..01a28ca 100644
--- a/fpu/softfloat.c
+++ b/fpu/softfloat.c
@@ -3007,7 +3007,7 @@  float32 float16_to_float32(float16 a, flag ieee STATUS_PARAM)
         if (aSig) {
             return commonNaNToFloat32(float16ToCommonNaN(a STATUS_VAR) STATUS_VAR);
         }
-        return packFloat32(aSign, 0xff, aSig << 13);
+        return packFloat32(aSign, 0xff, 0);
     }
     if (aExp == 0) {
         int8 shiftCount;