MIPS: math-emu: do not use bools for arithmetic
RFC PATCH 1/1 MIPS: math-emu: do not use bools for arithmetic
GCC-7 complains about a boolean value being used with an arithmetic AND:
arch/mips/math-emu/cp1emu.c: In function 'cop1Emulate':arch/mips/math-emu/cp1emu.c:838:14: warning: '~' on a boolean expression [-Wbool-operation]
fpr = (x) & ~(cop1_64bit(xcp) == 0); \
^arch/mips/math-emu/cp1emu.c:1068:3: note: in expansion of macro 'DITOREG'
DITOREG(dval, MIPSInst_RT(ir));
^~~~~~~arch/mips/math-emu/cp1emu.c:838:14: note: did you mean to use logical not?
fpr = (x) & ~(cop1_64bit(xcp) == 0); \
Fix this by testing the bool and returning an int. This also shrinks the size of the file object file by 312 bytes:
text data bss dec hex filename
11432 0 0 11432 2ca8 cp1emu.o-alt 11120 0 0 11120 2b70 cp1emu.o
---
I'm unsure whether the patch is really correct, due to the unexpected binary size reduction. I do not have a hardfloat mips32 userland at hand therefore I'd appreciate it if someone could test it!
Thanks!
arch/mips/math-emu/cp1emu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/mips/math-emu/cp1emu.c +2 -2
@@ -830,12 +830,12 @@ do { \ } while (0)#define DIFROMREG (di, x) \ - ((di) = get_fpr64(&ctx->fpr[(x) & ~(cop1_64bit(xcp) == 0)], 0)) + ((di) = get_fpr64(&ctx->fpr[(x) & ~(cop1_64bit(xcp) == 0 ? 1 : 0)], 0))#define DITOREG (di, x) \ do { \ unsigned fpr, i; \ - fpr = (x) & ~(cop1_64bit(xcp) == 0); \ + fpr = (x) & ~(cop1_64bit(xcp) == 0 ? 1 : 0); \ set_fpr64(&ctx->fpr[fpr], 0, di); \ for (i = 1; i < ARRAY_SIZE(ctx->fpr[x].val64); i++) \ set_fpr64(&ctx->fpr[fpr], i, 0); \
Signature · 1 line
2.13.1
Quoted 3 lines · Manuel Lauss
I'm unsure whether the patch is really correct, due to the unexpected binary size reduction. I do not have a hardfloat mips32 userland at hand therefore I'd appreciate it if someone could test it!
What exactly are you unsure about? Double operations using odd register
indices in the 32-bit FPR mode are architecturally unpredictable. Is this what concerns you?
arch/mips/math-emu/cp1emu.c do { \ · line 833
Quoted 10 lines
arch/mips/math-emu/cp1emu.c +1
-1@@ -830,12 +830,12 @@ do { \ }while (0 ) #define DIFROMREG(di, x) \ - ((di) =get_fpr64 (&ctx->fpr[(x) & ~(cop1_64bit (xcp) ==0 )],0 )) + ((di) =get_fpr64 (&ctx->fpr[(x) & ~(cop1_64bit (xcp) ==0 ?1 :0 )],0 ))
Umm, I find the expression somewhat hard to follow. How about:
((di) = get_fpr64(&ctx->fpr[(x) & ~(cop1_64bit(xcp) ^ 1))
?
arch/mips/math-emu/cp1emu.c do { \ · line 838
Quoted 5 lines
arch/mips/math-emu/cp1emu.c +1
-1#define DITOREG (di, x) \ do { \ unsigned fpr, i; \ - fpr = (x) & ~(cop1_64bit(xcp) == 0); \ + fpr = (x) & ~(cop1_64bit(xcp) == 0 ? 1 : 0); \
Likewise:
fpr = (x) & ~(cop1_64bit(xcp) ^ 1); \
?
Maciej
Quoted 9 lines · Maciej W. Rozycki
Quoted 3 lines · Manuel Lauss
I'm unsure whether the patch is really correct, due to the unexpected binary size reduction. I do not have a hardfloat mips32 userland at hand therefore I'd appreciate it if someone could test it!
What exactly are you unsure about? Double operations using odd register
indices in the 32-bit FPR mode are architecturally unpredictable. Is this what concerns you?
I was not able to find a definition for get_fpr by grepping the tree for it, so I wasn't
sure whether only the LSB or all mattered.
Manuel
Quoted 7 lines · Manuel Lauss
Quoted 3 lines
What exactly are you unsure about? Double operations using odd register
indices in the 32-bit FPR mode are architecturally unpredictable. Is this what concerns you?I was not able to find a definition for
get_fprby grepping the tree for it, so I wasn't
sure whether only the LSB or all mattered.
It's in arch/mips/include/asm/processor.h; see BUILD_FPR_ACCESS.
Maciej