Skip to contentSkip to conversation

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

PATCH Applied Peter Maydell 3 participants 4 messages Sep 24, 2012 – Oct 1, 2012

lore
Share & tools
lore
#0 lore raw

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

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.

---
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(-)
fpu/softfloat.c +1 -1
index b29256a..01a28ca 100644
@@ -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;
Signature · 1 line
1.7.9.5
Reviewed-by on v1 1/1
#2 lore raw
In reply to Peter Maydell
Quoted 28 lines · Peter Maydell

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.

---
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(-)
fpu/softfloat.c +1 -1
index b29256a..01a28ca 100644
@@ -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;
Signature · 1 line
1.7.9.5

Good catch!

Signature · 2 lines
Aurelien Jarno                          GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net
#3 lore raw
In reply to Peter Maydell
Quoted 18 lines · Peter Maydell

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.

---
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(-)
fpu/softfloat.c +0 -0
index b29256a..01a28ca 100644

fpu/softfloat.c float32 float16_to_float32(float16 a, flag ieee STATUS_PARAM) · line 3013

Quoted 8 lines
fpu/softfloat.c +1 -1
@@ -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.

Signature · 2 lines
Aurelien Jarno                          GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net