fpu/softfloat: Silent 'bitwise negation of a boolean expression' warning
PATCH v2 1/1 fpu/softfloat: Silent 'bitwise negation of a boolean expression' warning
When building with clang version 10.0.0-4ubuntu1, we get:
CC lm32-softmmu/fpu/softfloat.o
fpu/softfloat.c:3365:13: error: bitwise negation of a boolean expression; did you mean logical negation? [-Werror,-Wbool-operation]
absZ &= ~ ( ( ( roundBits ^ 0x40 ) == 0 ) & roundNearestEven );
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ fpu/softfloat.c:3423:18: error: bitwise negation of a boolean expression; did you mean logical negation? [-Werror,-Wbool-operation]
absZ0 &= ~ ( ( (uint64_t) ( absZ1<<1 ) == 0 ) & roundNearestEven );
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ fpu/softfloat.c:3483:18: error: bitwise negation of a boolean expression; did you mean logical negation? [-Werror,-Wbool-operation]
absZ0 &= ~(((uint64_t)(absZ1<<1) == 0) & roundNearestEven);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ fpu/softfloat.c:3606:13: error: bitwise negation of a boolean expression; did you mean logical negation? [-Werror,-Wbool-operation]
zSig &= ~ ( ( ( roundBits ^ 0x40 ) == 0 ) & roundNearestEven );
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ fpu/softfloat.c:3760:13: error: bitwise negation of a boolean expression; did you mean logical negation? [-Werror,-Wbool-operation]
zSig &= ~ ( ( ( roundBits ^ 0x200 ) == 0 ) & roundNearestEven );
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ fpu/softfloat.c:3987:21: error: bitwise negation of a boolean expression; did you mean logical negation? [-Werror,-Wbool-operation]
~ ( ( (uint64_t) ( zSig1<<1 ) == 0 ) & roundNearestEven );
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ fpu/softfloat.c:4003:22: error: bitwise negation of a boolean expression; did you mean logical negation? [-Werror,-Wbool-operation]
zSig0 &= ~ ( ( (uint64_t) ( zSig1<<1 ) == 0 ) & roundNearestEven );
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ fpu/softfloat.c:4273:18: error: bitwise negation of a boolean expression; did you mean logical negation? [-Werror,-Wbool-operation]
zSig1 &= ~ ( ( zSig2 + zSig2 == 0 ) & roundNearestEven );
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Fix by rewriting the fishy bitwise AND of two bools as an int.
---
v2: Resend without the Cc: "Toni Wilen <[email protected]>" tag
--- fpu/softfloat.c | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-)
fpu/softfloat.c +24 -9
@@ -3362,7 +3362,9 @@ static int32_t roundAndPackInt32(bool zSign, uint64_t absZ, } roundBits = absZ &0x7F ; absZ = ( absZ + roundIncrement )>>7 ; - absZ &= ~ ( ( ( roundBits ^0x40 ) ==0 ) & roundNearestEven ); +if (((roundBits ^0x40 ) ==0 ) && roundNearestEven) { + absZ &= ~1 ; + } z = absZ;if ( zSign ) z = - z;if ( ( absZ>>32 ) || ( z && ( ( z <0 ) ^ zSign ) ) ) {
@@ -3420,7 +3422,9 @@ static int64_t roundAndPackInt64(bool zSign, uint64_t absZ0, uint64_t absZ1,if ( increment ) { ++absZ0;if ( absZ0 ==0 ) goto overflow; - absZ0 &= ~ ( ( (uint64_t ) ( absZ1<<1 ) ==0 ) & roundNearestEven ); +if (((absZ1 <<1 ) ==0 ) && roundNearestEven) { + absZ0 &= ~1 ; + } } z = absZ0;if ( zSign ) z = - z;
@@ -3480,7 +3484,9 @@ static int64_t roundAndPackUint64(bool zSign, uint64_t absZ0,float_raise (float_flag_invalid, status);return UINT64_MAX ; } - absZ0 &= ~(((uint64_t )(absZ1<<1 ) ==0 ) & roundNearestEven); +if (((absZ1 <<1 ) ==0 ) && roundNearestEven) { + absZ0 &= ~1 ; + } }if (zSign && absZ0) {
@@ -3603,7 +3609,9 @@ static float32 roundAndPackFloat32(bool zSign, int zExp, uint32_t zSig, status->float_exception_flags |= float_flag_inexact; } zSig = ( zSig + roundIncrement )>>7 ; - zSig &= ~ ( ( ( roundBits ^0x40 ) ==0 ) & roundNearestEven ); +if (((roundBits ^0x40 ) ==0 ) && roundNearestEven) { + zSig &= ~1 ; + }if ( zSig ==0 ) zExp =0 ;return packFloat32 ( zSign, zExp, zSig );
@@ -3757,7 +3765,9 @@ static float64 roundAndPackFloat64(bool zSign, int zExp, uint64_t zSig, status->float_exception_flags |= float_flag_inexact; } zSig = ( zSig + roundIncrement )>>10 ; - zSig &= ~ ( ( ( roundBits ^0x200 ) ==0 ) & roundNearestEven ); +if (((roundBits ^0x200 ) ==0 ) && roundNearestEven) { + zSig &= ~1 ; + }if ( zSig ==0 ) zExp =0 ;return packFloat64 ( zSign, zExp, zSig );
@@ -3983,8 +3993,9 @@ floatx80 roundAndPackFloatx80(int8_t roundingPrecision, bool zSign, }if ( increment ) { ++zSig0; - zSig0 &= - ~ ( ( (uint64_t ) ( zSig1<<1 ) ==0 ) & roundNearestEven ); +if (((zSig1 <<1 ) ==0 ) && roundNearestEven) { + zSig0 &= ~1 ; + }if ( (int64_t ) zSig0 <0 ) zExp =1 ; }return packFloatx80 ( zSign, zExp, zSig0 );
@@ -4000,7 +4011,9 @@ floatx80 roundAndPackFloatx80(int8_t roundingPrecision, bool zSign, zSig0 =UINT64_C (0x8000000000000000 ); }else { - zSig0 &= ~ ( ( (uint64_t ) ( zSig1<<1 ) ==0 ) & roundNearestEven ); +if (((zSig1 <<1 ) ==0 ) && roundNearestEven) { + zSig0 &= ~1 ; + } } }else {
@@ -4270,7 +4283,9 @@ static float128 roundAndPackFloat128(bool zSign, int32_t zExp, }if ( increment ) {add128 ( zSig0, zSig1,0 ,1 , &zSig0, &zSig1 ); - zSig1 &= ~ ( ( zSig2 + zSig2 ==0 ) & roundNearestEven ); +if ((zSig2 + zSig2 ==0 ) && roundNearestEven) { + zSig1 &= ~1 ; + } }else {if ( ( zSig0 | zSig1 ) ==0 ) zExp =0 ;
Signature · 1 line
2.21.3
Quoted 51 lines · Philippe Mathieu-Daudé
When building with clang version 10.0.0-4ubuntu1, we get:
CC
lm32-softmmu/fpu/softfloat.o
fpu/softfloat.c:3365:13: error: bitwise negation of a boolean expression; did you mean logical negation? [-Werror,-Wbool-operation]absZ &= ~ ( ( ( roundBits ^ 0x40 ) == 0 ) & roundNearestEven ); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fpu/softfloat.c:3423:18: error: bitwise negation of a boolean expression; did you mean logical negation? [-Werror,-Wbool-operation]absZ0 &= ~ ( ( (uint64_t) ( absZ1<<1 ) == 0 ) & roundNearestEven ); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fpu/softfloat.c:3483:18: error: bitwise negation of a boolean expression; did you mean logical negation? [-Werror,-Wbool-operation]absZ0 &= ~(((uint64_t)(absZ1<<1) == 0) & roundNearestEven); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fpu/softfloat.c:3606:13: error: bitwise negation of a boolean expression; did you mean logical negation? [-Werror,-Wbool-operation]zSig &= ~ ( ( ( roundBits ^ 0x40 ) == 0 ) & roundNearestEven ); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fpu/softfloat.c:3760:13: error: bitwise negation of a boolean expression; did you mean logical negation? [-Werror,-Wbool-operation]zSig &= ~ ( ( ( roundBits ^ 0x200 ) == 0 ) & roundNearestEven ); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fpu/softfloat.c:3987:21: error: bitwise negation of a boolean expression; did you mean logical negation? [-Werror,-Wbool-operation]~ ( ( (uint64_t) ( zSig1<<1 ) == 0 ) & roundNearestEven ); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fpu/softfloat.c:4003:22: error: bitwise negation of a boolean expression; did you mean logical negation? [-Werror,-Wbool-operation]zSig0 &= ~ ( ( (uint64_t) ( zSig1<<1 ) == 0 ) & roundNearestEven ); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fpu/softfloat.c:4273:18: error: bitwise negation of a boolean expression; did you mean logical negation? [-Werror,-Wbool-operation]zSig1 &= ~ ( ( zSig2 + zSig2 == 0 ) & roundNearestEven ); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Fix by rewriting the fishy bitwise AND of two bools as an int.
Suggested-by Eric Blake <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
v2: Resend without the Cc: "Toni Wilen <[email protected]>" tag--- fpu/softfloat.c | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-)fpu/softfloat.c +0
-0
fpu/softfloat.c static int32_t roundAndPackInt32(bool zSign, uint64_t absZ, · line 3367
Quoted 7 lines
fpu/softfloat.c +3
-1@@ -3362,7 +3362,9 @@ static int32_t roundAndPackInt32(bool zSign, uint64_t absZ, } roundBits = absZ &0x7F ; absZ = ( absZ + roundIncrement )>>7 ; - absZ &= ~ ( ( ( roundBits ^0x40 ) ==0 ) & roundNearestEven ); +if (((roundBits ^0x40 ) ==0 ) && roundNearestEven) { + absZ &= ~1 ; + }
You could get rid of some more parentheses now:
if ((roundBits ^ 0x40) == 0 && roundNearestEven)
... also in the other hunks.
Anyway:
Quoted 62 lines · Thomas Huth
Quoted 51 lines · Philippe Mathieu-Daudé
When building with clang version 10.0.0-4ubuntu1, we get:
CC
lm32-softmmu/fpu/softfloat.o
fpu/softfloat.c:3365:13: error: bitwise negation of a boolean expression; did you mean logical negation? [-Werror,-Wbool-operation]absZ &= ~ ( ( ( roundBits ^ 0x40 ) == 0 ) & roundNearestEven ); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fpu/softfloat.c:3423:18: error: bitwise negation of a boolean expression; did you mean logical negation? [-Werror,-Wbool-operation]absZ0 &= ~ ( ( (uint64_t) ( absZ1<<1 ) == 0 ) & roundNearestEven ); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fpu/softfloat.c:3483:18: error: bitwise negation of a boolean expression; did you mean logical negation? [-Werror,-Wbool-operation]absZ0 &= ~(((uint64_t)(absZ1<<1) == 0) & roundNearestEven); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fpu/softfloat.c:3606:13: error: bitwise negation of a boolean expression; did you mean logical negation? [-Werror,-Wbool-operation]zSig &= ~ ( ( ( roundBits ^ 0x40 ) == 0 ) & roundNearestEven ); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fpu/softfloat.c:3760:13: error: bitwise negation of a boolean expression; did you mean logical negation? [-Werror,-Wbool-operation]zSig &= ~ ( ( ( roundBits ^ 0x200 ) == 0 ) & roundNearestEven ); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fpu/softfloat.c:3987:21: error: bitwise negation of a boolean expression; did you mean logical negation? [-Werror,-Wbool-operation]~ ( ( (uint64_t) ( zSig1<<1 ) == 0 ) & roundNearestEven ); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fpu/softfloat.c:4003:22: error: bitwise negation of a boolean expression; did you mean logical negation? [-Werror,-Wbool-operation]zSig0 &= ~ ( ( (uint64_t) ( zSig1<<1 ) == 0 ) & roundNearestEven ); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fpu/softfloat.c:4273:18: error: bitwise negation of a boolean expression; did you mean logical negation? [-Werror,-Wbool-operation]zSig1 &= ~ ( ( zSig2 + zSig2 == 0 ) & roundNearestEven ); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Fix by rewriting the fishy bitwise AND of two bools as an int.
Suggested-by Eric Blake <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
v2: Resend without the Cc: "Toni Wilen <[email protected]>" tag--- fpu/softfloat.c | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-)fpu/softfloat.c +0
-0fpu/softfloat.c static int32_t roundAndPackInt32(bool zSign, uint64_t absZ, · line 3367
Quoted 7 lines
fpu/softfloat.c +3
-1@@ -3362,7 +3362,9 @@ static int32_t roundAndPackInt32(bool zSign, uint64_t absZ, } roundBits = absZ &0x7F ; absZ = ( absZ + roundIncrement )>>7 ; - absZ &= ~ ( ( ( roundBits ^0x40 ) ==0 ) & roundNearestEven ); +if (((roundBits ^0x40 ) ==0 ) && roundNearestEven) { + absZ &= ~1 ; + }You could get rid of some more parentheses now:
Quoted 3 lines
if ((roundBits ^ 0x40) == 0 && roundNearestEven)... also in the other hunks.
I first wrote
if (!(roundBits ^ 0x40) && roundNearestEven)
But then thought this would diverge from Eric suggestion, so I kept what he wrote (which is a bit closer to the style of rest of this file).
Quoted 4 lines
Anyway:
Reviewed-by Thomas Huth <[email protected]>
Thanks!
Eric Blake
Reviewed-byQuoted 3 lines · Philippe Mathieu-Daudé
Quoted 2 lines · Thomas Huth
Quoted 1 line · Philippe Mathieu-Daudé
When building with clang version 10.0.0-4ubuntu1, we get:
In the subject, I'd suggest s/Silent/Silence/
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
CC
lm32-softmmu/fpu/softfloat.o
fpu/softfloat.c:3365:13: error: bitwise negation of a boolean expression; did you mean logical negation? [-Werror,-Wbool-operation]absZ &= ~ ( ( ( roundBits ^ 0x40 ) == 0 ) & roundNearestEven ); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~fpu/softfloat.c:3423:18: error: bitwise negation of a boolean expression; did you mean logical negation? [-Werror,-Wbool-operation] absZ0 &= ~ ( ( (uint64_t) ( absZ1<<1 ) == 0 ) & roundNearestEven ); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Also, do you need to list all errors, or will just one or two representative errors be sufficient?
Quoted 22 lines
Quoted 22 lines
Quoted 10 lines
Fix by rewriting the fishy bitwise AND of two bools as an int.
Suggested-by Eric Blake <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
+++
b/fpu/softfloat.cfpu/softfloat.c static int32_t roundAndPackInt32(bool zSign, uint64_t absZ, · line 3367
Quoted 7 lines
fpu/softfloat.c +3
-1@@ -3362,7 +3362,9 @@ static int32_t roundAndPackInt32(bool zSign, uint64_t absZ, } roundBits = absZ &0x7F ; absZ = ( absZ + roundIncrement )>>7 ; - absZ &= ~ ( ( ( roundBits ^0x40 ) ==0 ) & roundNearestEven ); +if (((roundBits ^0x40 ) ==0 ) && roundNearestEven) { + absZ &= ~1 ; + }You could get rid of some more parentheses now:
if ((roundBits ^ 0x40) == 0 && roundNearestEven)
Quoted 8 lines
Quoted 1 line
... also in the other hunks.
I first wrote
if (!(roundBits ^ 0x40) && roundNearestEven)But then thought this would diverge from Eric suggestion, so I kept what he wrote (which is a bit closer to the style of rest of this file).
I don't mind the patch as-is for minimizing churn and matching existing style, but I also would not be opposed if you wanted to elide unnecessary ().
Quoted 8 lines
Quoted 5 lines
Anyway:
Reviewed-by Thomas Huth <[email protected]>Thanks!
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
Quoted 6 lines · Eric Blake
Quoted 3 lines · Philippe Mathieu-Daudé
Quoted 2 lines · Thomas Huth
Quoted 1 line · Philippe Mathieu-Daudé
When building with clang version 10.0.0-4ubuntu1, we get:
In the subject, I'd suggest s/Silent/Silence/
Don't fit... 73 chars :S I'll use 'Avoid' (or 'Remove'?) instead.
Quoted 16 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
CC
lm32-softmmu/fpu/softfloat.ofpu/softfloat.c:3365:13: error: bitwise negation of a boolean expression; did you mean logical negation? [-Werror,-Wbool-operation] absZ &= ~ ( ( ( roundBits ^0x40) == 0 ) & roundNearestEven ); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
fpu/softfloat.c:3423:18: error: bitwise negation of a boolean expression; did you mean logical negation? [-Werror,-Wbool-operation] absZ0 &= ~ ( ( (uint64_t) ( absZ1<<1 ) == 0 ) & roundNearestEven );
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Quoted 2 lines
Also, do you need to list all errors, or will just one or two representative errors be sufficient?
Fair :)
Quoted 28 lines
Quoted 28 lines
Quoted 22 lines
Quoted 11 lines
Fix by rewriting the fishy bitwise AND of two bools as an int.
Suggested-by Eric Blake <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
+++
b/fpu/softfloat.cfpu/softfloat.c static int32_t roundAndPackInt32(bool zSign, · line 3368
Quoted 8 lines
fpu/softfloat.c +3
-1@@ -3362,7 +3362,9 @@ static int32_t roundAndPackInt32(bool zSign,uint64_t absZ, } roundBits = absZ & 0x7F; absZ = ( absZ + roundIncrement )>>7; - absZ &= ~ ( ( ( roundBits ^ 0x40 ) == 0 ) & roundNearestEven ); + if (((roundBits ^ 0x40) == 0) && roundNearestEven) { + absZ &= ~1; + }You could get rid of some more parentheses now:
Quoted 3 lines
if ((roundBits ^
0x40) == 0 && roundNearestEven)... also in the other hunks.
I first wrote
Quoted 8 lines
Quoted 4 lines
if (!(roundBits ^
0x40) && roundNearestEven)But then thought this would diverge from Eric suggestion, so I kept what he wrote (which is a bit closer to the style of rest of this file).
I don't mind the patch as-is for minimizing churn and matching existing style, but I also would not be opposed if you wanted to elide unnecessary ().
OK, thanks for the review!
Quoted 12 lines
Quoted 9 lines
Quoted 6 lines
Anyway:
Reviewed-by Thomas Huth <[email protected]>Thanks!
Reviewed-by Eric Blake <[email protected]>