target-i386: fix pcmpxstrx equal-ordered (strstr) mode
authorPaolo Bonzini <pbonzini@redhat.com>
Mon, 12 Oct 2015 09:50:27 +0000 (11:50 +0200)
committerPaolo Bonzini <pbonzini@redhat.com>
Wed, 4 Nov 2015 14:02:30 +0000 (15:02 +0100)
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.

Reported-by: Florian Weimer <fweimer@redhat.com>
Cc: Richard Henderson <rth@twiddle.net>
Cc: Eduardo Habkost <ehabkost@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
target-i386/ops_sse.h

index 7aa693aee9d6d003f49049695b52b6c2ae7884ea..1780d1d791657432fce101191e8da3b87addab6f 100644 (file)
@@ -2037,10 +2037,10 @@ 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--) {
+            for (i = MIN(valids - j, validd); i >= 0; i--) {
                 v &= (pcmp_val(s, ctrl, i + j) == pcmp_val(d, ctrl, i));
             }
             res |= v;