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 avoided in the inner loop, which
correctly bounds "i" to validd, but they will still contribute to a
positive outcome of the search.

This fixes tst_strstr in glibc 2.17.

Backports commit 54c54f8b56047d3c2420e1ae06a6a8890c220ac4 from qemu
This commit is contained in:
Paolo Bonzini 2018-02-17 14:56:39 -05:00 committed by Lioncash
parent 9c26efb406
commit 2e6770c643
No known key found for this signature in database
GPG key ID: 4E3C3CC1031BA9C7

View file

@ -2037,10 +2037,10 @@ static inline unsigned pcmpxstrx(CPUX86State *env, Reg *d, Reg *s,
} }
break; break;
case 3: case 3:
for (j = valids - validd; j >= 0; j--) { for (j = valids; j >= 0; j--) {
res <<= 1; res <<= 1;
v = 1; v = 1;
for (i = MIN(upper - j, validd); i >= 0; i--) { for (i = MIN(valids - j, validd); i >= 0; i--) {
v &= (pcmp_val(s, ctrl, i + j) == pcmp_val(d, ctrl, i)); v &= (pcmp_val(s, ctrl, i + j) == pcmp_val(d, ctrl, i));
} }
res |= v; res |= v;