target-mips: fix incorrect behaviour for INSV
PATCH 1/1 target-mips: fix incorrect behaviour for INSV
From: Petar Jovanovic <[email protected]>
Corner case for INSV instruction when size=32 has not been correctly implemented. The mask for size should be one bit wider, and preparing the filter variable should be aware of this case too.
The test for INSV has been extended to include the case that triggers the bug.
--- target-mips/dsp_helper.c | 4 ++-- tests/tcg/mips/mips32-dsp/insv.c | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-)
target-mips/dsp_helper.c +2 -2
@@ -2921,7 +2921,7 @@ target_ulong helper_##name(CPUMIPSState *env, target_ulong rs, \return rt; \ } \ \ - filter = ((int32_t )0x01 << size) -1 ; \ + filter = ((int64_t )0x01 << size) -1 ; \ filter = filter << pos; \ temprs = (rs << pos) & filter; \ temprt = rt & ~filter; \
@@ -2930,7 +2930,7 @@ target_ulong helper_##name(CPUMIPSState *env, target_ulong rs, \return (target_long )(ret_type )temp; \ } -BIT_INSV (insv,0x1F ,0x1F , int32_t); +BIT_INSV (insv,0x1F ,0x3F , int32_t);#ifdef TARGET_MIPS64 BIT_INSV (dinsv,0x7F ,0x3F , target_long);#endif
tests/tcg/mips/mips32-dsp/insv.c +13 -0
@@ -19,5 +19,18 @@ int main() );assert (rt == result); + dsp =0x1000 ; + rt =0xF0F0F0F0 ; + rs =0xA5A5A5A5 ; + result =0xA5A5A5A5 ; + + __asm + ("wrdsp %2\n\t" +"insv %0, %1\n\t" + :"+r" (rt) + :"r" (rs),"r" (dsp) + ); +assert (rt == result); +return 0 ; }
Signature · 1 line
1.7.9.5
Quoted 8 lines · Petar Jovanovic
From: Petar Jovanovic <[email protected]>
Corner case for INSV instruction when size=32 has not been correctly implemented. The mask for size should be one bit wider, and preparing the filter variable should be aware of this case too.
The test for INSV has been extended to include the case that triggers the bug.
This isn't really a good fit for a trivial patch. Cc'ing qemu-devel and mips "odd-fixes" maintainer instead.
Thanks!
/mjt
Quoted 52 lines
Signed-off-by Petar Jovanovic <[email protected]>--- target-mips/dsp_helper.c | 4 ++-- tests/tcg/mips/mips32-dsp/insv.c | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-)target-mips/dsp_helper.c +2
-2@@ -2921,7 +2921,7 @@ target_ulong helper_##name(CPUMIPSState *env, target_ulong rs, \return rt; \ } \ \ - filter = ((int32_t )0x01 << size) -1 ; \ + filter = ((int64_t )0x01 << size) -1 ; \ filter = filter << pos; \ temprs = (rs << pos) & filter; \ temprt = rt & ~filter; \@@ -2930,7 +2930,7 @@ target_ulong helper_##name(CPUMIPSState *env, target_ulong rs, \return (target_long )(ret_type )temp; \ } -BIT_INSV (insv,0x1F ,0x1F , int32_t); +BIT_INSV (insv,0x1F ,0x3F , int32_t);#ifdef TARGET_MIPS64 BIT_INSV (dinsv,0x7F ,0x3F , target_long);#endif tests/tcg/mips/mips32-dsp/insv.c +13
-0@@ -19,5 +19,18 @@ int main() );assert (rt == result); + dsp =0x1000 ; + rt =0xF0F0F0F0 ; + rs =0xA5A5A5A5 ; + result =0xA5A5A5A5 ; + + __asm + ("wrdsp %2\n\t" +"insv %0, %1\n\t" + :"+r" (rt) + :"r" (rs),"r" (dsp) + ); +assert (rt == result); +return 0 ; }
Quoted 6 lines · Petar Jovanovic
From: Petar Jovanovic <[email protected]>
Corner case for INSV instruction when size=32 has not been correctly implemented. The mask for size should be one bit wider, and preparing the filter variable should be aware of this case too.
Quoted 8 lines
The test for INSV has been extended to include the case that triggers the bug.
Signed-off-by Petar Jovanovic <[email protected]>--- target-mips/dsp_helper.c | 4 ++-- tests/tcg/mips/mips32-dsp/insv.c | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-)
Thanks for the patch. I have applied it, as it is correct and we are in the freeze period. However please find a few comments below that might need a follow-up patch.
target-mips/dsp_helper.c target_ulong helper_##name(CPUMIPSState *env, target_ulong rs, \ · line 2924
Quoted 10 lines
target-mips/dsp_helper.c +1
-1@@ -2921,7 +2921,7 @@ target_ulong helper_##name(CPUMIPSState *env, target_ulong rs, \return rt; \ } \ \ - filter = ((int32_t )0x01 << size) -1 ; \ + filter = ((int64_t )0x01 << size) -1 ; \
maybe using (1LL << size) would make the code easier to read.
target-mips/dsp_helper.c target_ulong helper_##name(CPUMIPSState *env, target_ulong rs, \ · line 2935
Quoted 11 lines
target-mips/dsp_helper.c +1
-1filter = filter << pos; \ temprs = (rs << pos) & filter; \ temprt = rt & ~filter; \@@ -2930,7 +2930,7 @@ target_ulong helper_##name(CPUMIPSState *env, target_ulong rs, \return (target_long )(ret_type )temp; \ } -BIT_INSV (insv,0x1F ,0x1F , int32_t); +BIT_INSV (insv,0x1F ,0x3F , int32_t);#ifdef TARGET_MIPS64 BIT_INSV (dinsv,0x7F ,0x3F , target_long);
This means that the sizefilter argument is constant, so it probably can be removed.
Quoted 28 lines
target-mips/dsp_helper.c +0
-0#endif tests/tcg/mips/mips32-dsp/insv.c +13
-0@@ -19,5 +19,18 @@ int main() );assert (rt == result); + dsp =0x1000 ; + rt =0xF0F0F0F0 ; + rs =0xA5A5A5A5 ; + result =0xA5A5A5A5 ; + + __asm + ("wrdsp %2\n\t" +"insv %0, %1\n\t" + :"+r" (rt) + :"r" (rs),"r" (dsp) + ); +assert (rt == result); +return 0 ; }Signature · 1 line
1.7.9.5
Signature · 2 lines
Aurelien Jarno GPG: 1024D/F1BCDB73 [email protected] http://www.aurel32.net