target-i386: fix pcmpxstrx equal-ordered (strstr) mode
PATCH 1/1 target-i386: fix pcmpxstrx equal-ordered (strstr) mode
In this mode, referring an invalid element of the source forces the result to false (table 4-7, last column) but referring an invalid element of the destination forces the result to true, so the outer loop should still be run even if some elements of the destination will be invalid. They will be culled in the inner loop, which correctly bounds "i" to validd.
This fix tst_strstr in glibc 2.17.
--- target-i386/ops_sse.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target-i386/ops_sse.h +1 -1
@@ -2037,7 +2037,7 @@ static inline unsigned pcmpxstrx(CPUX86State *env, Reg *d, Reg *s, }break ;case 3 : -for (j = valids - validd; j >=0 ; j--) { +for (j = valids; j >=0 ; j--) { res <<=1 ; v =1 ;for (i =MIN (upper - j, validd); i >=0 ; i--) {
Signature · 1 line
2.5.0
Quoted 22 lines · Paolo Bonzini
In this mode, referring an invalid element of the source forces the result to false (table 4-7, last column) but referring an invalid element of the destination forces the result to true, so the outer loop should still be run even if some elements of the destination will be invalid. They will be culled in the inner loop, which correctly bounds "i" to validd.
This fix
tst_strstrin glibc 2.17.Reported-by Florian Weimer <[email protected]>Cc Richard Henderson <[email protected]>Cc Eduardo Habkost <[email protected]>Signed-off-by Paolo Bonzini <[email protected]>--- target-i386/ops_sse.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)target-i386/ops_sse.h +0
-0
target-i386/ops_sse.h static inline unsigned pcmpxstrx(CPUX86State *env, Reg *d, Reg *s, · line 2043
Quoted 8 lines
target-i386/ops_sse.h +1
-1@@ -2037,7 +2037,7 @@ static inline unsigned pcmpxstrx(CPUX86State *env, Reg *d, Reg *s, }break ;case 3 : -for (j = valids - validd; j >=0 ; j--) { +for (j = valids; j >=0 ; j--) { res <<=1 ; v =1 ;for (i =MIN (upper - j, validd); i >=0 ; i--) {
I don't see how the bounding is properly done. In particular,
Quoted 1 line
v &= (pcmp_val(s, ctrl, i + j) == pcmp_val(d, ctrl, i));
We're bounding j by valids, but accessing i+j?
I think this would be a lot simpler if we simply followed the pseudocode in table 4-3, doing overrideIfDataInvalid after comparison.
r~
Quoted 35 lines · Richard Henderson
Quoted 30 lines · Paolo Bonzini
In this mode, referring an invalid element of the source forces the result to false (table 4-7, last column) but referring an invalid element of the destination forces the result to true, so the outer loop should still be run even if some elements of the destination will be invalid. They will be culled in the inner loop, which correctly bounds "i" to validd.
This fix
tst_strstrin glibc 2.17.Reported-by Florian Weimer <[email protected]>Cc Richard Henderson <[email protected]>Cc Eduardo Habkost <[email protected]>Signed-off-by Paolo Bonzini <[email protected]>--- target-i386/ops_sse.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)target-i386/ops_sse.h +1
-1@@ -2037,7 +2037,7 @@ static inline unsigned pcmpxstrx(CPUX86State *env, Reg *d, Reg *s, }break ;case 3 : -for (j = valids - validd; j >=0 ; j--) { +for (j = valids; j >=0 ; j--) { res <<=1 ; v =1 ;Quoted 1 line
for (i = MIN(upper - j, validd); i >= 0; i--) {I don't see how the bounding is properly done. In particular,
Quoted 3 lines
Quoted 1 line
v &= (pcmp_val(s, ctrl, i + j) == pcmp_val(d, ctrl, i));We're bounding j by valids, but accessing i+j?
You're absolutely right, the second loop also needs s/upper/valids/.
Paolo