From nobody Thu Apr 25 23:30:55 2024 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; 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 1502401307494524.5348284261286; Thu, 10 Aug 2017 14:41:47 -0700 (PDT) Received: from localhost ([::1]:55421 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dfvD4-0001ru-QY for importer@patchew.org; Thu, 10 Aug 2017 17:41:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44292) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dfvCL-0001a3-0j for qemu-devel@nongnu.org; Thu, 10 Aug 2017 17:40:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dfvCH-0007rP-Dl for qemu-devel@nongnu.org; Thu, 10 Aug 2017 17:40:57 -0400 Received: from relay1.mentorg.com ([192.94.38.131]:37194) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dfvCH-0007qk-7L for qemu-devel@nongnu.org; Thu, 10 Aug 2017 17:40:53 -0400 Received: from nat-ies.mentorg.com ([192.94.31.2] helo=svr-ies-mbx-01.mgc.mentorg.com) by relay1.mentorg.com with esmtp id 1dfvCC-0004gn-Sq from joseph_myers@mentor.com ; Thu, 10 Aug 2017 14:40:49 -0700 Received: from digraph.polyomino.org.uk (137.202.0.87) by svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) with Microsoft SMTP Server (TLS) id 15.0.1263.5; Thu, 10 Aug 2017 22:40:46 +0100 Received: from jsm28 (helo=localhost) by digraph.polyomino.org.uk with local-esmtp (Exim 4.86_2) (envelope-from ) id 1dfvC5-0003Pw-AY; Thu, 10 Aug 2017 21:40:41 +0000 Date: Thu, 10 Aug 2017 21:40:41 +0000 From: Joseph Myers X-X-Sender: jsm28@digraph.polyomino.org.uk To: , , , Message-ID: User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 X-Originating-IP: [137.202.0.87] X-ClientProxiedBy: svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) To svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) X-detected-operating-system: by eggs.gnu.org: Windows NT kernel [generic] [fuzzy] X-Received-From: 192.94.38.131 Subject: [Qemu-devel] [PATCH] 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 --- diff --git a/target/i386/ops_sse.h b/target/i386/ops_sse.h index 16509d0..9f1b351 100644 --- a/target/i386/ops_sse.h +++ b/target/i386/ops_sse.h @@ -2037,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 Joseph S. Myers joseph@codesourcery.com