From nobody Mon Feb 9 16:47:12 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1505824309152820.5275836861174; Tue, 19 Sep 2017 05:31:49 -0700 (PDT) Received: from localhost ([::1]:42571 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1duHgq-00058f-Af for importer@patchew.org; Tue, 19 Sep 2017 08:31:48 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59620) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1duHez-0003gV-9Q for qemu-devel@nongnu.org; Tue, 19 Sep 2017 08:29:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1duHev-0005Am-6b for qemu-devel@nongnu.org; Tue, 19 Sep 2017 08:29:53 -0400 Received: from mail-wr0-x241.google.com ([2a00:1450:400c:c0c::241]:36436) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1duHev-0005AS-0T for qemu-devel@nongnu.org; Tue, 19 Sep 2017 08:29:49 -0400 Received: by mail-wr0-x241.google.com with SMTP id g50so2140839wra.3 for ; Tue, 19 Sep 2017 05:29:48 -0700 (PDT) Received: from 640k.lan (dynamic-adsl-78-12-246-117.clienti.tiscali.it. [78.12.246.117]) by smtp.gmail.com with ESMTPSA id k18sm1292878wmd.22.2017.09.19.05.29.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Sep 2017 05:29:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=vAqTN1ZKHBBzcgX6glvzSDO0Y0MbFf3zePy5hVOXcp0=; b=Dg5u7WCAqrGGIwLErrTuF8mSACRFvC/uZNknWgS4l6s3VvU/aNsblqGNOJfZ6HPErX qdDk93kudpwBWnpxdAzgtiKHaliYpN1g30xskJc2EfOiJQttdO0cLCDV43nfNJFs5kzT glMuXedFl6f6g+Mm+5axHMzPBvvjwyWy6qmYkZIXsV4OF/P44SgYcADuvWYz+pWt3dnX R8j6T2uSLj+SQSOPvNyLrFRJ/5JAfpfgfnzi/7rFW0qXDxDv5yNlzfoBLSV+7ZJEo6Pk hfQalxv8B7JWjLorSbz9eazLrIfYTVZubq2Cc4WW2zJ+elyRM8YX/+zyf0+BQkBKIX7b xykA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=vAqTN1ZKHBBzcgX6glvzSDO0Y0MbFf3zePy5hVOXcp0=; b=Wt2ri6dchAE/Dw54hKHleUaTKdtNAChP+1QsRrXPGdBNZYOCqpgXdLpCthsEafgcCm MlzhMpT+efiOe0sXRlLrxxzmQ2cosiA8QAtn9JOOfL6xa3QwdL0nxbAVl3+yYOPSo+qk koWfgvCJ4vJv9xfoNi1eErFTbrSc4VtdOKDzaN+5U4KDjwuPOhLZ+KRVcm0NwWi5yNCF 2AYfZIej7N7eO05ZCDaSreM/WhZzq5aFxEQs+AnhV84hhSzSD2v41YJ0cRjI3/onN7wP d8Yj0fJB7lSW0LDNGFPYl0wPmRZg9mR9vUb/pHg4kQLxalFCGzDfxYZtNAx3ID7xx6Zk r0Aw== X-Gm-Message-State: AHPjjUjmyvS8n0PTgf8n7Hx6JDCjEXkYd9Xs/mMWUfqp/ax8W0YAmKeN b3bHR5PbY4FXUzMMQW+x+FMYmz7R X-Google-Smtp-Source: AOwi7QDhS4Jn+UA9J5LVhqLKkxN6RIOhZPzB1yLU6U5euFWgaWzg4f9e3hEeU9vKh289G3bxLyddMA== X-Received: by 10.223.178.193 with SMTP id g59mr1391182wrd.0.1505824187732; Tue, 19 Sep 2017 05:29:47 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Tue, 19 Sep 2017 14:28:53 +0200 Message-Id: <1505824179-21541-5-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1505824179-21541-1-git-send-email-pbonzini@redhat.com> References: <1505824179-21541-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::241 Subject: [Qemu-devel] [PULL 04/50] target/i386: fix pcmpxstrx substring search X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Joseph Myers Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Joseph Myers One of the cases of the SSE4.2 pcmpestri / pcmpestrm / pcmpistri / pcmpistrm instructions does a substring search. The implementation of this case in the pcmpxstrx helper is incorrect. The operation in this case is a search for a string (argument d to the helper) in another string (argument s to the helper); if a copy of d at a particular position would run off the end of s, the resulting output bit should be 0 whether or not the strings match in the region where they overlap, but the QEMU implementation was wrongly comparing only up to the point where s ends and counting it as a match if an initial segment of d matched a terminal segment of s. Here, "run off the end of s" means that some byte of d would overlap some byte outside of s; thus, if d has zero length, it is considered to match everywhere, including after the end of s. This patch fixes the implementation to correspond with the proper instruction semantics. This fixes four gcc test failures in my GCC 6-based testing. Signed-off-by: Joseph Myers Message-Id: Signed-off-by: Paolo Bonzini --- target/i386/ops_sse.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/target/i386/ops_sse.h b/target/i386/ops_sse.h index 05b1701..9f1b351 100644 --- a/target/i386/ops_sse.h +++ b/target/i386/ops_sse.h @@ -2040,10 +2040,14 @@ static inline unsigned pcmpxstrx(CPUX86State *env, = Reg *d, Reg *s, } break; case 3: - for (j =3D valids; j >=3D 0; j--) { + if (validd =3D=3D -1) { + res =3D (2 << upper) - 1; + break; + } + for (j =3D valids - validd; j >=3D 0; j--) { res <<=3D 1; v =3D 1; - for (i =3D MIN(valids - j, validd); i >=3D 0; i--) { + for (i =3D validd; i >=3D 0; i--) { v &=3D (pcmp_val(s, ctrl, i + j) =3D=3D pcmp_val(d, ctrl, = i)); } res |=3D v; --=20 1.8.3.1