From nobody Wed Apr 9 01:11:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1734253631; cv=none; d=zohomail.com; s=zohoarc; b=Y5oUAGCUIfR9dh20FAX+J2HJ8io9u87AB5rP2VgEKeZlYZvbBwv9wB1V/QICj6GckKqIBvdMF+TGsMg+DrfDQ8ETbS++IvLYrY3de32ujvAlX1uPLUQOuiSdKLAKNtQDv89JoCPqHQtGRa3uJotWzYY7hRd4kYoOVFgdH2i21iY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1734253631; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=/dGFERRWFUpZlIsQTMSnLpRN54/m8liDcvkRPsprq7k=; b=fXVI29RMZjUSu+8ywwpLhhQttLQKYxSP573w4W/DRaMbp59s+FwJdYG1MUCCu+dgcTDY5pCbLoTD7J5UWrCVqEnapcqkV6BFxmRy54AkNlQsQcmOlBju0YTwrxY0WqsQdXlaBP99PUAA1qSji7BAgeANJt8TYvdB2EJ4stayw+8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1734253631176768.0832016877963; Sun, 15 Dec 2024 01:07:11 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tMka3-0004SG-J8; Sun, 15 Dec 2024 04:06:27 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tMka1-0004Rk-Dc for qemu-devel@nongnu.org; Sun, 15 Dec 2024 04:06:25 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tMkZy-0006wR-Pl for qemu-devel@nongnu.org; Sun, 15 Dec 2024 04:06:25 -0500 Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-637-Ht9I7XYAOqKQNCZ1s1RtGQ-1; Sun, 15 Dec 2024 04:06:20 -0500 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4361d4e8359so6339175e9.3 for ; Sun, 15 Dec 2024 01:06:20 -0800 (PST) Received: from [192.168.10.3] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43625706c82sm103757765e9.35.2024.12.15.01.06.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Dec 2024 01:06:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734253582; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/dGFERRWFUpZlIsQTMSnLpRN54/m8liDcvkRPsprq7k=; b=hZTJ396JI+t1G1Z0w0UWPV+kXyXGl2QgIvhU/5AOkOuVsCS05OFeLFnl6xrrkdefFDns9G o6HI620Z5vt+hj+liuXxwKePpO5WCr8b/OKcNsvFaraMI4ROYuD9lgegshO4WBBcFa6w5C 8JPx8CN7BAu8wZ3R21qzmSFbI1A4ELg= X-MC-Unique: Ht9I7XYAOqKQNCZ1s1RtGQ-1 X-Mimecast-MFC-AGG-ID: Ht9I7XYAOqKQNCZ1s1RtGQ X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734253578; x=1734858378; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/dGFERRWFUpZlIsQTMSnLpRN54/m8liDcvkRPsprq7k=; b=DFvpHXpKfkE6tMmgmmPpWQavGLlyuHwWAlMIzIjPhMFNQ4z2wcPaTd8Nj7IiuJUms5 QqyHQosRoec8AVdm038M+BkAFZXfIP+xIDv7dIr/78ax2K/JeC6Vh25AM1Fon0cv6Ku0 omMk+xGU83NFeJdWWpl1bPr1GFjq7TaaB2RP/JLy7ciA8124u/GREdPJhTdWc0BlYKFY 0WeHO3p3W4vu7T8eSPwe+8ZSvlf60QppSEyFwkp2WGTU1Eym4iiB1Ts9sP9nEnNGEn4Z pYYIk6ZXpwfQuWhHUpjtWCIegLH52eKD3Ugs4RSvXTzp5RW/fZ9LZSmsoQ5lWaHk/MVo tNgA== X-Gm-Message-State: AOJu0YyT+Y08G4uDHnqguLL2kbUUxBPESrMO44f7Bom/vgBpCSo5I7h0 fTsRfIZ5xFDV9xTP7hKf/n8dcyUBCN+zav5+PQ3Xx8FwWUbSEMO7K2fhJJbcVNtvPI1ydrM8szO IGXwGQK6p+ZqZAPbcagG77Xv4mOK+sWCfz8Kt/1i/vXJuGI0Oxt3EiTaZvBwLJqhHHC7wnSn1Kc 9QRqDgVHThwNLKwu+atl3omAn7TlJJyj0ewNN0 X-Gm-Gg: ASbGnctqzqgcsS4azQfZsWGPC728O/p4aXSAERrVvW6AU6ldA9aQ1NWx8by2cJ4mZPu Q+FLcLhFR+NmRZtSUa2Gius0lzV/SDzZAhZRnDWe3214xr0M4Eg9bkdTx7uME7munB7j8h4qBFA Rp6BFjncYGEAfQEOXW8hpd+W/YwknxTIKCpgVha0V25SUKIoTt1Xi0Vd5mz3fDLWinS7dXNMKHM c0WwSuTrAYedjTeC2X3xCTgBGDYAODTvIKv+9XULlf5qEUVsudTmBShFgg= X-Received: by 2002:a05:600c:b95:b0:431:44f6:566f with SMTP id 5b1f17b1804b1-4362aa3acf9mr81406155e9.13.1734253578461; Sun, 15 Dec 2024 01:06:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IHpOtXrJ8muv+pnGwrgPQCn6Yb59VbQ2DNB6/Qc9t+r2Lb44jBmGDyLo9nCZqDjud7SytvMfw== X-Received: by 2002:a05:600c:b95:b0:431:44f6:566f with SMTP id 5b1f17b1804b1-4362aa3acf9mr81405835e9.13.1734253578104; Sun, 15 Dec 2024 01:06:18 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: richard.henderson@linaro.org Subject: [PATCH 01/13] target/i386: inline gen_jcc into sole caller Date: Sun, 15 Dec 2024 10:06:00 +0100 Message-ID: <20241215090613.89588-2-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241215090613.89588-1-pbonzini@redhat.com> References: <20241215090613.89588-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.292, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1734253634438116600 Content-Type: text/plain; charset="utf-8" The code of gen_Jcc is very similar to gen_LOOP* and gen_JCXZ, but this is hidden by gen_jcc. Signed-off-by: Paolo Bonzini Reviewed-by: Richard Henderson --- target/i386/tcg/translate.c | 8 -------- target/i386/tcg/emit.c.inc | 6 +++++- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index 5d729e68c98..298842d46b6 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -1846,14 +1846,6 @@ static void gen_conditional_jump_labels(DisasContext= *s, target_long diff, gen_jmp_rel(s, s->dflag, diff, 0); } =20 -static void gen_jcc(DisasContext *s, int b, int diff) -{ - TCGLabel *l1 =3D gen_new_label(); - - gen_jcc1(s, b, l1); - gen_conditional_jump_labels(s, diff, NULL, l1); -} - static void gen_cmovcc1(DisasContext *s, int b, TCGv dest, TCGv src) { CCPrepare cc =3D gen_prepare_cc(s, b, NULL); diff --git a/target/i386/tcg/emit.c.inc b/target/i386/tcg/emit.c.inc index 785ff63f2ac..8d18407facf 100644 --- a/target/i386/tcg/emit.c.inc +++ b/target/i386/tcg/emit.c.inc @@ -2276,8 +2276,12 @@ static void gen_IRET(DisasContext *s, X86DecodedInsn= *decode) =20 static void gen_Jcc(DisasContext *s, X86DecodedInsn *decode) { + TCGLabel *taken =3D gen_new_label(); + gen_bnd_jmp(s); - gen_jcc(s, decode->b & 0xf, decode->immediate); + gen_jcc1(s, decode->b & 0xf, taken); + gen_conditional_jump_labels(s, decode->immediate, NULL, taken); + } =20 static void gen_JCXZ(DisasContext *s, X86DecodedInsn *decode) --=20 2.47.1 From nobody Wed Apr 9 01:11:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1734253688504950.1054483128305; Sun, 15 Dec 2024 01:08:08 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tMkaD-0004W8-Hq; Sun, 15 Dec 2024 04:06:37 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tMka4-0004Sy-To for qemu-devel@nongnu.org; Sun, 15 Dec 2024 04:06:30 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tMka3-0006wy-6S for qemu-devel@nongnu.org; Sun, 15 Dec 2024 04:06:28 -0500 Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-120-aVYUh56fNbC2qZgn8qwjaw-1; Sun, 15 Dec 2024 04:06:23 -0500 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-43627bb20b5so22286545e9.1 for ; Sun, 15 Dec 2024 01:06:23 -0800 (PST) Received: from [192.168.10.3] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-436362b6841sm48046295e9.28.2024.12.15.01.06.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Dec 2024 01:06:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734253585; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=I/9GAD92u+pnNvpDHvZE6faR5pj8MJQ9gNr1CMb/few=; b=cqv+SSN4rvOftyHZgdba8U/1Dh2KJ3aVM9u/ZZY8rAo6jaa1tQjZEij5+xJ0bvFTjf09ga WR6XbCEq7/UG36m8n3fwPxC6LTA0eB/cZdjVEMs4oTYFGjURpq69k3nUUPOeunklLoMyHm S6SCIx8gyHyPH29VcAoiHURiIldc6zU= X-MC-Unique: aVYUh56fNbC2qZgn8qwjaw-1 X-Mimecast-MFC-AGG-ID: aVYUh56fNbC2qZgn8qwjaw X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734253581; x=1734858381; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=I/9GAD92u+pnNvpDHvZE6faR5pj8MJQ9gNr1CMb/few=; b=ZtWg0iMLXmH7dRiNgmJQ2W/vh6uFkjp93H71zIJmdoFZYpxywdpb+MFvv+T3cTZzDa B+a5oO0KnCL8kPBYTIT/n6RL56g8GmbxtxUTHEOVvaeKW8UMIyvO8pV8yXZT4SIylfjW wa6SCwvBMLhT5nKij8Uk7jK4l6Ya8fCpo+ZFTgNzevQGc/bK3jjoWwHK6Z4RY1USKUZD K560QhYCX9IHo9ACCgoCLHxFVJcbJyE3zxdmQ0pYX5IWL0N7khBIGp/hZxpZInhmt9Wt t0PSJvYNvjKmhf2+y89Ph5L5vwgKRlhU8uDtKfe6XosMotivE9/VsEoEAwMT5mWkoFsr lThA== X-Gm-Message-State: AOJu0Yx9JolFzOjXeReS5bHGPgzj9KKgkwynTmmMmrvGwz1E+sfs64K0 pttyIuL0lM0BfcD3SZ72QvOEZ3d+Q+UFBbWFNo7Gi2ETFY+It3QbhRTySfIGDDQXwGhFIjtDzqE esCJTe/b/2palhHgbWXjgX8hUxR38wmXJkQDgSIgXraMLVCWxuWbYcZgzHlbtKspKAMtc5nBpeD nvrCsNktkkc87JCklQ6GspZ8Lq5aoTKV7hhg/T X-Gm-Gg: ASbGncsi2hfpJ/46KDuzxbleZFHv9AqTu/W0FtVSBklDiUTlp7luHFK+P8/u2WxQfoh fUIyZDnfLBLk3KhVwXf66BEP4Nz4DQaUOwiB+rhXHoswHt/T2AQ1l1Wdqru8X4J3BCp1soxzv9e eJpMV8GR/raolGyJbKZuXZHfrjipei0rWm/nrlcNmqSPQh8O7NW9rhkW+ugXjAUurImu9dSN5E0 A7Vi8QTnfYABivCJPRuORjSdmQAyk2B4qwgHbn8+vIng0/0sHIskVQBMS0= X-Received: by 2002:a05:600c:c11:b0:431:93d8:e1a1 with SMTP id 5b1f17b1804b1-4362aaa8cfemr73916815e9.27.1734253581279; Sun, 15 Dec 2024 01:06:21 -0800 (PST) X-Google-Smtp-Source: AGHT+IHUoODYly/7cDX3sVJr7w75qJhLu0P/ojvrYjucCC4sH3SlFfJTO+KxQcfP3P6/bMg5BveOiQ== X-Received: by 2002:a05:600c:c11:b0:431:93d8:e1a1 with SMTP id 5b1f17b1804b1-4362aaa8cfemr73916465e9.27.1734253580802; Sun, 15 Dec 2024 01:06:20 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: richard.henderson@linaro.org Subject: [PATCH 02/13] target/i386: remove trailing 1 from gen_{j, cmov, set}cc1 Date: Sun, 15 Dec 2024 10:06:01 +0100 Message-ID: <20241215090613.89588-3-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241215090613.89588-1-pbonzini@redhat.com> References: <20241215090613.89588-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.292, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1734253689623116600 Content-Type: text/plain; charset="utf-8" This is not needed anymore now that gen_jcc has been eliminated (merged into the similarly-named gen_Jcc, where the uppercase letter gives away that it is an emission function). Signed-off-by: Paolo Bonzini Reviewed-by: Richard Henderson --- target/i386/tcg/translate.c | 14 +++++++------- target/i386/tcg/emit.c.inc | 10 +++++----- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index 298842d46b6..99e989d4b22 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -1147,7 +1147,7 @@ static CCPrepare gen_prepare_cc(DisasContext *s, int = b, TCGv reg) return cc; } =20 -static void gen_setcc1(DisasContext *s, int b, TCGv reg) +static void gen_setcc(DisasContext *s, int b, TCGv reg) { CCPrepare cc =3D gen_prepare_cc(s, b, reg); =20 @@ -1169,12 +1169,12 @@ static void gen_setcc1(DisasContext *s, int b, TCGv= reg) =20 static inline void gen_compute_eflags_c(DisasContext *s, TCGv reg) { - gen_setcc1(s, JCC_B << 1, reg); + gen_setcc(s, JCC_B << 1, reg); } =20 /* generate a conditional jump to label 'l1' according to jump opcode value 'b'. In the fast case, T0 is guaranteed not to be used. */ -static inline void gen_jcc1_noeob(DisasContext *s, int b, TCGLabel *l1) +static inline void gen_jcc_noeob(DisasContext *s, int b, TCGLabel *l1) { CCPrepare cc =3D gen_prepare_cc(s, b, NULL); =20 @@ -1189,7 +1189,7 @@ static inline void gen_jcc1_noeob(DisasContext *s, in= t b, TCGLabel *l1) value 'b'. In the fast case, T0 is guaranteed not to be used. One or both of the branches will call gen_jmp_rel, so ensure cc_op is clean. */ -static inline void gen_jcc1(DisasContext *s, int b, TCGLabel *l1) +static inline void gen_jcc(DisasContext *s, int b, TCGLabel *l1) { CCPrepare cc =3D gen_prepare_cc(s, b, NULL); =20 @@ -1336,7 +1336,7 @@ static void gen_repz_nz(DisasContext *s, MemOp ot, l2 =3D gen_jz_ecx_string(s); fn(s, ot); gen_op_add_reg_im(s, s->aflag, R_ECX, -1); - gen_jcc1(s, (JCC_Z << 1) | (nz ^ 1), l2); + gen_jcc(s, (JCC_Z << 1) | (nz ^ 1), l2); if (s->repz_opt) { gen_op_jz_ecx(s, l2); } @@ -1846,7 +1846,7 @@ static void gen_conditional_jump_labels(DisasContext = *s, target_long diff, gen_jmp_rel(s, s->dflag, diff, 0); } =20 -static void gen_cmovcc1(DisasContext *s, int b, TCGv dest, TCGv src) +static void gen_cmovcc(DisasContext *s, int b, TCGv dest, TCGv src) { CCPrepare cc =3D gen_prepare_cc(s, b, NULL); =20 @@ -2855,7 +2855,7 @@ static void gen_x87(DisasContext *s, X86DecodedInsn *= decode) } op1 =3D fcmov_cc[op & 3] | (((op >> 3) & 1) ^ 1); l1 =3D gen_new_label(); - gen_jcc1_noeob(s, op1, l1); + gen_jcc_noeob(s, op1, l1); gen_helper_fmov_ST0_STN(tcg_env, tcg_constant_i32(opreg)); gen_set_label(l1); diff --git a/target/i386/tcg/emit.c.inc b/target/i386/tcg/emit.c.inc index 8d18407facf..a05ba019026 100644 --- a/target/i386/tcg/emit.c.inc +++ b/target/i386/tcg/emit.c.inc @@ -1613,7 +1613,7 @@ static void gen_CMC(DisasContext *s, X86DecodedInsn *= decode) =20 static void gen_CMOVcc(DisasContext *s, X86DecodedInsn *decode) { - gen_cmovcc1(s, decode->b & 0xf, s->T0, s->T1); + gen_cmovcc(s, decode->b & 0xf, s->T0, s->T1); } =20 static void gen_CMPccXADD(DisasContext *s, X86DecodedInsn *decode) @@ -2279,7 +2279,7 @@ static void gen_Jcc(DisasContext *s, X86DecodedInsn *= decode) TCGLabel *taken =3D gen_new_label(); =20 gen_bnd_jmp(s); - gen_jcc1(s, decode->b & 0xf, taken); + gen_jcc(s, decode->b & 0xf, taken); gen_conditional_jump_labels(s, decode->immediate, NULL, taken); =20 } @@ -2431,7 +2431,7 @@ static void gen_LOOPE(DisasContext *s, X86DecodedInsn= *decode) gen_update_cc_op(s); gen_op_add_reg_im(s, s->aflag, R_ECX, -1); gen_op_jz_ecx(s, not_taken); - gen_jcc1(s, (JCC_Z << 1), taken); /* jz taken */ + gen_jcc(s, (JCC_Z << 1), taken); /* jz taken */ gen_conditional_jump_labels(s, decode->immediate, not_taken, taken); } =20 @@ -2443,7 +2443,7 @@ static void gen_LOOPNE(DisasContext *s, X86DecodedIns= n *decode) gen_update_cc_op(s); gen_op_add_reg_im(s, s->aflag, R_ECX, -1); gen_op_jz_ecx(s, not_taken); - gen_jcc1(s, (JCC_Z << 1) | 1, taken); /* jnz taken */ + gen_jcc(s, (JCC_Z << 1) | 1, taken); /* jnz taken */ gen_conditional_jump_labels(s, decode->immediate, not_taken, taken); } =20 @@ -3868,7 +3868,7 @@ static void gen_SCAS(DisasContext *s, X86DecodedInsn = *decode) =20 static void gen_SETcc(DisasContext *s, X86DecodedInsn *decode) { - gen_setcc1(s, decode->b & 0xf, s->T0); + gen_setcc(s, decode->b & 0xf, s->T0); } =20 static void gen_SFENCE(DisasContext *s, X86DecodedInsn *decode) --=20 2.47.1 From nobody Wed Apr 9 01:11:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1734253729; cv=none; d=zohomail.com; s=zohoarc; b=HpT3cpl4vY5fe3GMNRKwH1ARkdRnsQbV6eW8LlJtMvjXieOU7h5XI6J8yiPoLpVD6KZZ5LdtY08yTaSgek+EbKi8+S9wjzEe0LOTTqg7YpmY3BZOivz9vb9nXLCeGKnlFpgY4ZBYyym3b2SGYCRA44nh/n0wibfMCmKTOw0nsc0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1734253729; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ukTF0xScWnwWrNf37BS8Dvw3/BbLdE6czijwzXoGkA0=; b=IY3KNEktlrSiiAbyUWf5zC0pIHsrhEfx5MlDtxO2Z66Or6fKkTnJqYYHI2uYdPIpivjlrHcZCk5lrs9CI/3/gBXW3VT4mHtWM2fG9byu3Z7P1GwhNNZf3YNbL0WL8xT7bGgJEfqrqjMbwbc6x+/a3lWjeQOYU8NU4NxdyG1Sa98= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1734253729502417.56565810110646; Sun, 15 Dec 2024 01:08:49 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tMkaA-0004Uy-GK; Sun, 15 Dec 2024 04:06:34 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tMka6-0004Tx-NK for qemu-devel@nongnu.org; Sun, 15 Dec 2024 04:06:31 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tMka5-0006xG-9q for qemu-devel@nongnu.org; Sun, 15 Dec 2024 04:06:30 -0500 Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-589-0zbCm8A8MbCGKU4nIVwoZw-1; Sun, 15 Dec 2024 04:06:26 -0500 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-385f0829430so2144036f8f.1 for ; Sun, 15 Dec 2024 01:06:25 -0800 (PST) Received: from [192.168.10.3] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-388c8016275sm4678765f8f.24.2024.12.15.01.06.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Dec 2024 01:06:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734253588; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ukTF0xScWnwWrNf37BS8Dvw3/BbLdE6czijwzXoGkA0=; b=S0h+nIzYfulDje8D4ljl9qYOqcNFgtjghucMpEkylEz9QjHXrbaHRBxzRNILZfO9sqnosd M00TdWQ5EkbeI5tP91dVurxeWJREbHwQnnwoThGXMXlKQuD2+OsqUsgBKs0lXX3UDDfcz7 oF6eUZ9Ljoaez4TfXCFHEg1eglsSh14= X-MC-Unique: 0zbCm8A8MbCGKU4nIVwoZw-1 X-Mimecast-MFC-AGG-ID: 0zbCm8A8MbCGKU4nIVwoZw X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734253584; x=1734858384; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ukTF0xScWnwWrNf37BS8Dvw3/BbLdE6czijwzXoGkA0=; b=mTJEzzn048u+WQoMr15BwoLah+KvFeD/VV6Xa8Zh3WQw0KENucuUvY1O2Bcn6oS/OA Xv+8/nMNOXfsjo8XQ3toemmBkir9vu5o+4QCOlsJrC0Ftm7lD+WsN0LrAk+vaNhSwihd 9g/lBX+5Po26vQD/hxAAN6vxqPMYhLKGT2FtrgGyaMu3bOK1E3tbTiCkyObEbfzH1bQU ImZnGg10dlgX/L0xT/Rx/VvC7wCAGJiMHgK7Ce2vLNKat8aBlKYqAF5k0+0EJf/22j98 LiK6533LZItSat92j5sTNewateqEulQvrYaEFNMsuqRc34TH3zFLasMnjjUtROadReJN E09A== X-Gm-Message-State: AOJu0Yx7jbnOERtg/rdfxePViopr6Psv3iQjcPl9c3L6qBJxyK0Ou7fj MigvGpDX8sDaXcrid2NAowrplPsyOpCed7bgjAU1UGI3Q8GlKzASbP7P1ZB90V8KMuPfc/ep9j8 yprbu4H9DgnkON/4ws1K5b1a9hkYLxyYv2a4DUy8KN4e4NwkFguXclel7McE/iHPvdgSRCrN0NY ULCyajIikoxX4wJFl4teWgwLOXct9+8r6evQZK X-Gm-Gg: ASbGncvxGH9cqUGwO1uHTSQM4BYWxzbWmsNFPbZyMEfovfsuj6kJVYMY1SHan/g9ubZ xZm7iFi4tWV/iXsT3Z8hX1Rn+ep40lCxqfSREH7j/WQBhTay6k07gDheW5gAkY3SXXWzxwuDhbi VIKHH3XnAujJn7efh3f/AADU8asnJ9tcTEX2SW7eDWaG78P+WEnNCzHv1grABcB/zH1LC4aYpRX GAQ86sf4MwelnnPRgLeNxPLYt/iZzpZLxPRZjKtAQYYZO4P5hKZS8n4k4w= X-Received: by 2002:a05:6000:4028:b0:385:e2d5:cdf2 with SMTP id ffacd0b85a97d-38880ad9012mr7274926f8f.19.1734253584228; Sun, 15 Dec 2024 01:06:24 -0800 (PST) X-Google-Smtp-Source: AGHT+IHHAN2oz3cKZJNmOxqBXHzhiMft+Hoq67j4HogMJMuTdek6KGOLUEpTOXmQovdQXS+PSJyUnQ== X-Received: by 2002:a05:6000:4028:b0:385:e2d5:cdf2 with SMTP id ffacd0b85a97d-38880ad9012mr7274895f8f.19.1734253583745; Sun, 15 Dec 2024 01:06:23 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: richard.henderson@linaro.org Subject: [PATCH 03/13] target/i386: unify REP and REPZ/REPNZ generation Date: Sun, 15 Dec 2024 10:06:02 +0100 Message-ID: <20241215090613.89588-4-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241215090613.89588-1-pbonzini@redhat.com> References: <20241215090613.89588-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.292, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1734253731625116600 Content-Type: text/plain; charset="utf-8" It only differs in a single call to gen_jcc, so use a "bool" argument to distinguish the two cases; do not duplicate code. Signed-off-by: Paolo Bonzini Reviewed-by: Richard Henderson --- target/i386/tcg/translate.c | 39 +++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index 99e989d4b22..8bf6aa1fcf6 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -1309,14 +1309,18 @@ static void gen_outs(DisasContext *s, MemOp ot) gen_bpt_io(s, s->tmp2_i32, ot); } =20 -/* Generate jumps to current or next instruction */ -static void gen_repz(DisasContext *s, MemOp ot, - void (*fn)(DisasContext *s, MemOp ot)) +static void do_gen_rep(DisasContext *s, MemOp ot, + void (*fn)(DisasContext *s, MemOp ot), + bool is_repz_nz) { TCGLabel *l2; l2 =3D gen_jz_ecx_string(s); fn(s, ot); gen_op_add_reg_im(s, s->aflag, R_ECX, -1); + if (is_repz_nz) { + int nz =3D (s->prefix & PREFIX_REPNZ) ? 1 : 0; + gen_jcc(s, (JCC_Z << 1) | (nz ^ 1), l2); + } /* * A loop would cause two single step exceptions if ECX =3D 1 * before rep string_insn @@ -1324,28 +1328,25 @@ static void gen_repz(DisasContext *s, MemOp ot, if (s->repz_opt) { gen_op_jz_ecx(s, l2); } + /* + * For CMPS/SCAS there is no need to set CC_OP_DYNAMIC: only one itera= tion + * is done at a time, so the translation block ends unconditionally af= ter + * this instruction and there is no control flow junction. + */ gen_jmp_rel_csize(s, -cur_insn_len(s), 0); } =20 +static void gen_repz(DisasContext *s, MemOp ot, + void (*fn)(DisasContext *s, MemOp ot)) + +{ + do_gen_rep(s, ot, fn, false); +} + static void gen_repz_nz(DisasContext *s, MemOp ot, void (*fn)(DisasContext *s, MemOp ot)) { - TCGLabel *l2; - int nz =3D (s->prefix & PREFIX_REPNZ) ? 1 : 0; - - l2 =3D gen_jz_ecx_string(s); - fn(s, ot); - gen_op_add_reg_im(s, s->aflag, R_ECX, -1); - gen_jcc(s, (JCC_Z << 1) | (nz ^ 1), l2); - if (s->repz_opt) { - gen_op_jz_ecx(s, l2); - } - /* - * Only one iteration is done at a time, so the translation - * block ends unconditionally after this instruction and there - * is no control flow junction - no need to set CC_OP_DYNAMIC. - */ - gen_jmp_rel_csize(s, -cur_insn_len(s), 0); + do_gen_rep(s, ot, fn, true); } =20 static void gen_helper_fp_arith_ST0_FT0(int op) --=20 2.47.1 From nobody Wed Apr 9 01:11:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1734253638; cv=none; d=zohomail.com; s=zohoarc; b=FH+xIr4ApYD+xSYw+YGii5Y1umtvRJX8BGTQuMmqMqa4MSW8mqdqZLAWv2AKTjR+HaQ6S3n6l9pzJB0Gbajx1XU9RFdc9XFF4IQlsWs26W3n8uJcvW9qQJTXJRLzkALT6Dmvoiqug3Zni+8FeBiEO4mL5Vs5knHxyDh6ru+KiV0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1734253638; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=MWGGAB5XdcB3pXdVxuTkeezPYKORB6/K7AYCSGtJfhg=; b=WD0L0DyzRh9o10xDbNTrcRxK50S0uYwRL0+Edy4qGGUnnvkDmg88riG0cwEJFPbUJrTenXuoJE1Z9wii2k3M5uEBIlvRU086d9M+QdaP9346eLnTK3l9pEc8iUu8xSNBLLfXazXy0+pUqS7ZqHEXIkLBmxfQwpMsmayOQEUvdgI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1734253638181773.3045018486587; Sun, 15 Dec 2024 01:07:18 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tMkaD-0004WH-QO; Sun, 15 Dec 2024 04:06:37 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tMkaA-0004VI-Kj for qemu-devel@nongnu.org; Sun, 15 Dec 2024 04:06:34 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tMka9-0006xm-0U for qemu-devel@nongnu.org; Sun, 15 Dec 2024 04:06:34 -0500 Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-592-UZwQwHsvNUSFCDEtU5SRfg-1; Sun, 15 Dec 2024 04:06:30 -0500 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4362552ce62so16871455e9.0 for ; Sun, 15 Dec 2024 01:06:30 -0800 (PST) Received: from [192.168.10.3] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4361ec97d13sm83866495e9.1.2024.12.15.01.06.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Dec 2024 01:06:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734253591; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MWGGAB5XdcB3pXdVxuTkeezPYKORB6/K7AYCSGtJfhg=; b=cFgKsDnQPeg4cwvQ/2OBq91zm/HHTeXohAw55N8sKylPd+106qQ3p+E2ddCiWtqDRSza5D vmEyaPWgCGtt4aAzGxhyr/6T1OiTS6BM58GY7gIB96oo+0ZwFC6fu41JtYkJqAkrHbfX2X vWNFHBXePcryR8OPOO82pTsk2rI3VCU= X-MC-Unique: UZwQwHsvNUSFCDEtU5SRfg-1 X-Mimecast-MFC-AGG-ID: UZwQwHsvNUSFCDEtU5SRfg X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734253587; x=1734858387; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MWGGAB5XdcB3pXdVxuTkeezPYKORB6/K7AYCSGtJfhg=; b=UsgbLQDfYmijbroetfo3W2JZA68w9fqDvh9JCzYiYWMaswd+ciCVR6uP5r7/FzWC4e 39wNAHwJrryEAz9BWShYZOP894/ze15XnXAS2G670hDQMaSNSDKlEkz2quFuddC/Q0GI kA5NWxy/pKQIJQBw9GUpgj4tFs4z2BjtZzGcnILDZDt1vGgAGaWWW3UP0sNqZLuUDygG qvO8yOrhw+lugV4zl64L1BHS8DdR1ZoZnLWrHxt0yZS8zlNtLIRQyf5YVMsXNTk74PFR Xh1v26NBlLLse16TKeW4JVvvOzVuKsvpYsmqL3x4BY8oQzpe8/Z/OTQCaFeVIJTJftiI lP0w== X-Gm-Message-State: AOJu0YyAcW2gwj2LAu5/7fG4S52kL2mdfXcflbN8QZApEAEHXN4jv/V1 wBYRxQghmm9iOpK+F/S0Udiz60WGscRCVD5AcNJdycDbj2wxQ6PW47OfzwkMvMTvS2wXKupQYt3 GPQxsEPHed1h0z/PbJiFdi6Z2q8kZL3cWmRust9o3bgqwtOi7fdxG26BMUKji1R03dDfKYQW0lJ DaoTyHZLVNaFSyBpewEqy1ksFTBp93G5z7JdoQ X-Gm-Gg: ASbGncvu729yz+2RIGPvyTkE+49ppF7obdRmU+e32WNz8KPkOWVVV4ErumRW10bK3VE UPkFJFva9ug4wylYw89O2a33uOQfXZDCJIg8QDomIl1aRladroHsec0rQv53VcoBUFy68e65N1L mGzjrsPKCFSLC8etkLhBKjuKrlJSeNRESr6sFntxwnfQkLVHBok5uOMISXa63CcP3TnDZqVe6OP GgSmDspYIfcyG4KK6ym+MVD/nZJZfWy6og5m8FHs0viSQnY5CxJ/D10xGE= X-Received: by 2002:a7b:cb89:0:b0:434:f609:1af7 with SMTP id 5b1f17b1804b1-4362aa1b8b7mr70035375e9.4.1734253587525; Sun, 15 Dec 2024 01:06:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IGcAGny48HTP4vXyDylRpMDew+hC6I3hTf1IlYLkzKABiVKleioHELcWDkBG9kmvwEEBwqHtQ== X-Received: by 2002:a7b:cb89:0:b0:434:f609:1af7 with SMTP id 5b1f17b1804b1-4362aa1b8b7mr70035105e9.4.1734253587098; Sun, 15 Dec 2024 01:06:27 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: richard.henderson@linaro.org Subject: [PATCH 04/13] target/i386: unify choice between single and repeated string instructions Date: Sun, 15 Dec 2024 10:06:03 +0100 Message-ID: <20241215090613.89588-5-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241215090613.89588-1-pbonzini@redhat.com> References: <20241215090613.89588-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.292, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1734253639351116600 Content-Type: text/plain; charset="utf-8" The same "if" is present in all generator functions for string instructions. Push it inside gen_repz() and gen_repz_nz() instead. Signed-off-by: Paolo Bonzini --- target/i386/tcg/translate.c | 12 +++++++++-- target/i386/tcg/emit.c.inc | 42 +++++++------------------------------ 2 files changed, 17 insertions(+), 37 deletions(-) diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index 8bf6aa1fcf6..63a39d9f15a 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -1340,13 +1340,21 @@ static void gen_repz(DisasContext *s, MemOp ot, void (*fn)(DisasContext *s, MemOp ot)) =20 { - do_gen_rep(s, ot, fn, false); + if (s->prefix & (PREFIX_REPZ | PREFIX_REPNZ)) { + do_gen_rep(s, ot, fn, false); + } else { + fn(s, ot); + } } =20 static void gen_repz_nz(DisasContext *s, MemOp ot, void (*fn)(DisasContext *s, MemOp ot)) { - do_gen_rep(s, ot, fn, true); + if (s->prefix & (PREFIX_REPZ | PREFIX_REPNZ)) { + do_gen_rep(s, ot, fn, true); + } else { + fn(s, ot); + } } =20 static void gen_helper_fp_arith_ST0_FT0(int op) diff --git a/target/i386/tcg/emit.c.inc b/target/i386/tcg/emit.c.inc index a05ba019026..c346bf53c5f 100644 --- a/target/i386/tcg/emit.c.inc +++ b/target/i386/tcg/emit.c.inc @@ -1722,11 +1722,7 @@ static void gen_CMPccXADD(DisasContext *s, X86Decode= dInsn *decode) static void gen_CMPS(DisasContext *s, X86DecodedInsn *decode) { MemOp ot =3D decode->op[2].ot; - if (s->prefix & (PREFIX_REPZ | PREFIX_REPNZ)) { - gen_repz_nz(s, ot, gen_cmps); - } else { - gen_cmps(s, ot); - } + gen_repz_nz(s, ot, gen_cmps); } =20 static void gen_CMPXCHG(DisasContext *s, X86DecodedInsn *decode) @@ -2217,11 +2213,7 @@ static void gen_INS(DisasContext *s, X86DecodedInsn = *decode) } =20 translator_io_start(&s->base); - if (s->prefix & (PREFIX_REPZ | PREFIX_REPNZ)) { - gen_repz(s, ot, gen_ins); - } else { - gen_ins(s, ot); - } + gen_repz(s, ot, gen_ins); } =20 static void gen_INSERTQ_i(DisasContext *s, X86DecodedInsn *decode) @@ -2406,11 +2398,7 @@ static void gen_LGS(DisasContext *s, X86DecodedInsn = *decode) static void gen_LODS(DisasContext *s, X86DecodedInsn *decode) { MemOp ot =3D decode->op[1].ot; - if (s->prefix & (PREFIX_REPZ | PREFIX_REPNZ)) { - gen_repz(s, ot, gen_lods); - } else { - gen_lods(s, ot); - } + gen_repz(s, ot, gen_lods); } =20 static void gen_LOOP(DisasContext *s, X86DecodedInsn *decode) @@ -2608,11 +2596,7 @@ static void gen_MOVq_dq(DisasContext *s, X86DecodedI= nsn *decode) static void gen_MOVS(DisasContext *s, X86DecodedInsn *decode) { MemOp ot =3D decode->op[2].ot; - if (s->prefix & (PREFIX_REPZ | PREFIX_REPNZ)) { - gen_repz(s, ot, gen_movs); - } else { - gen_movs(s, ot); - } + gen_repz(s, ot, gen_movs); } =20 static void gen_MUL(DisasContext *s, X86DecodedInsn *decode) @@ -2774,11 +2758,7 @@ static void gen_OUTS(DisasContext *s, X86DecodedInsn= *decode) } =20 translator_io_start(&s->base); - if (s->prefix & (PREFIX_REPZ | PREFIX_REPNZ)) { - gen_repz(s, ot, gen_outs); - } else { - gen_outs(s, ot); - } + gen_repz(s, ot, gen_outs); } =20 static void gen_PALIGNR(DisasContext *s, X86DecodedInsn *decode) @@ -3859,11 +3839,7 @@ static void gen_SBB(DisasContext *s, X86DecodedInsn = *decode) static void gen_SCAS(DisasContext *s, X86DecodedInsn *decode) { MemOp ot =3D decode->op[2].ot; - if (s->prefix & (PREFIX_REPZ | PREFIX_REPNZ)) { - gen_repz_nz(s, ot, gen_scas); - } else { - gen_scas(s, ot); - } + gen_repz_nz(s, ot, gen_scas); } =20 static void gen_SETcc(DisasContext *s, X86DecodedInsn *decode) @@ -4069,11 +4045,7 @@ static void gen_STMXCSR(DisasContext *s, X86DecodedI= nsn *decode) static void gen_STOS(DisasContext *s, X86DecodedInsn *decode) { MemOp ot =3D decode->op[1].ot; - if (s->prefix & (PREFIX_REPZ | PREFIX_REPNZ)) { - gen_repz(s, ot, gen_stos); - } else { - gen_stos(s, ot); - } + gen_repz(s, ot, gen_stos); } =20 static void gen_SUB(DisasContext *s, X86DecodedInsn *decode) --=20 2.47.1 From nobody Wed Apr 9 01:11:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1734253700; cv=none; d=zohomail.com; s=zohoarc; b=YcqYH/FQN03seFh9S8YXzdf5NVn5jDALliWyTEIF3R88wf3/FBYXKRA//zQSlRW04nwr7Idsq/OkofJNHGgLZvgWZlj1a4Zg8FXT4Nm7x8USIXFIJRMM8/P6zFS2273WjpVaa4K9HWtb/8Dg9ZjuXf06JJ4ERGb89HjWJKtWW6A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1734253700; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Dafbs10xKmoTxtWUtvU8S+9K7XsF2B4JhpZ07ZD6dXY=; b=Ncmf/ItsIsgTaYWZ3TMPgg5JRZUSGgaFdzTDybKPQvcp3aK8bgMUngWtN4n6CmkxZPOYuCTJcyY/0qS/hLnTiD4SIGHcSXuz0Lu2TBWdzJqMy0UQq8+z61J4eu5wlt+3ckPQ+bpbBQecgRtTy4sq6EuOB7h96NjJrFnyayVK7gk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1734253700498682.3129555940345; Sun, 15 Dec 2024 01:08:20 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tMkaH-0004X9-T2; Sun, 15 Dec 2024 04:06:41 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tMkaD-0004WF-Hy for qemu-devel@nongnu.org; Sun, 15 Dec 2024 04:06:37 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tMkaB-0006y3-Tz for qemu-devel@nongnu.org; Sun, 15 Dec 2024 04:06:37 -0500 Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-515-ckfCmBejMeqgN3rEE8NQSA-1; Sun, 15 Dec 2024 04:06:33 -0500 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-3878ad4bf8cso1918126f8f.1 for ; Sun, 15 Dec 2024 01:06:33 -0800 (PST) Received: from [192.168.10.3] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-388c80602a1sm4695991f8f.97.2024.12.15.01.06.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Dec 2024 01:06:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734253594; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Dafbs10xKmoTxtWUtvU8S+9K7XsF2B4JhpZ07ZD6dXY=; b=AQOrrpV55OSwGrT2KjGzsjtvs6ZxV5MEC8rGr/dkRA/DjkgiV+Kdw1WAUhc43HBn+bLHxW sKFdszGLb851A3qcqXla8aDTrApmPkjUXNuGelxDdSYHD7sceKATKQhc8xd4FuUPQxxffy WpBOo9TvpYx23GtPF7IHJEtRBcAvnII= X-MC-Unique: ckfCmBejMeqgN3rEE8NQSA-1 X-Mimecast-MFC-AGG-ID: ckfCmBejMeqgN3rEE8NQSA X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734253591; x=1734858391; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Dafbs10xKmoTxtWUtvU8S+9K7XsF2B4JhpZ07ZD6dXY=; b=rqwGJTuGeKi3g0NBf/Ja7W7HdjMhjIMEDPlcovcc1J3q+Pfm72MmnM94yl0JNn38Bg iT2BWWoZcX+TOWJLtZDBOFGfbgE9uvKC0WC/yVu9dpFE7tcYyIiGG7RYZhoc+vrRiPHn Xlz4pPqUayg47UX4zEgN48AcKtKq/CBi1Za59le7zFSUr+r6RfB+2Zurj3/sGmv+JXn9 RZZupop5so7hVKuFYvp2R/o976hb441RnKz96taT8OdyEMANlIigHucpdSXUI6m7W2h5 a6KBWxUu9AkEhAU4jG3pAeguX24cj+Na6f05P2aUB2hAwKOXEiMhVY+v07JPEhpqGGlS 8LPg== X-Gm-Message-State: AOJu0YylUUlCaF+h2bEJs4k2QF46EBD+JJdPGZ+tyymmf5pIu5ow29C1 x4k1M48Uz0tvF1JQV4aXmSCUPBId2MAIm5MDCgr3gcUH/Ryi73lDe5Rfi0VoWlTOnvykysicaUp nKk2Z4mvKmm2fJE4sG+wOVuEXAYq738svivM/jidPKDAKuSittXdq00Nkvc6GuYH0M1ukKZbpd4 /48oBl18uu0WtS+ejxCf4R+VCRKIl4na41RLyB X-Gm-Gg: ASbGncuq70vnOWZvhla01y2URM0nsnBiZBQI5anHw6GbKV3Miay+OoLL2Jnw/qXQVwq UDsObJD2U7Ot61PlD9oFcVPxAt2pZ9nSVxYlZmjoai3bebdu53g5UFgs4OaLVibtzZGOPZo/XVK mNi45Q9eJ4Ijgyi94y27KQcItAnV1MvQvZ3Yq+AfcvzRDRR7H5Z37hOVqAAXihbjMDMjmBjCcx+ 5evAZdfrMEpzmvQoncaveEDoGyxwguxy1NahlemplD/giajdopRS0R1LxA= X-Received: by 2002:a05:6000:4b1b:b0:385:dedb:a156 with SMTP id ffacd0b85a97d-38880af1254mr7564526f8f.6.1734253590910; Sun, 15 Dec 2024 01:06:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IGAAtuyechW2rSVsAkbBjZvvBUMuQKGDwGU5oAA6RJetN8vKCWSSb9todVJ0OSDiEce0V9oyw== X-Received: by 2002:a05:6000:4b1b:b0:385:dedb:a156 with SMTP id ffacd0b85a97d-38880af1254mr7564488f8f.6.1734253590433; Sun, 15 Dec 2024 01:06:30 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: richard.henderson@linaro.org Subject: [PATCH 05/13] target/i386: reorganize ops emitted by do_gen_rep, drop repz_opt Date: Sun, 15 Dec 2024 10:06:04 +0100 Message-ID: <20241215090613.89588-6-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241215090613.89588-1-pbonzini@redhat.com> References: <20241215090613.89588-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.292, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1734253701499116600 Content-Type: text/plain; charset="utf-8" The condition for optimizing repeat instruction is more or less the opposite of what you imagine: almost always the string instruction was _not_ optimized and optimizing the loop relied on goto_tb. This is obviously not great for performance, due to the cost of the exit-to-main-loop check, but also wrong. In fact, after expanding dc->jmp_opt and simplifying "!!x" to "x", the condition for looping used to be: ((cflags & CF_NO_GOTO_TB) || (flags & (HF_RF_MASK | HF_TF_MASK | HF_INHIBIT_IRQ_MASK))) && !(cflags = & CF_USE_ICOUNT) In other words, setting aside RF (it requires special handling for REP instructions and it was completely missing), repeat instruction were being optimized if TF or inhibit IRQ flags were set. This is certainly wrong for TF, because string instructions trap after every execution, and probably for interrupt shadow too. Get rid of repz_opt completely. The next patches will reintroduce the optimization, applying it in the common case instead of the unlikely and wrong one. While at it, place the CX/ECX/RCX=3D0 case is at the end of the function, which saves a label and is clearer when reading the generated ops. For clarity, mark the cc_op explicitly as DYNAMIC even if at the end of the translation block; the cc_op can come from either the previous instruction or the string instruction, and currently we rely on a gen_update_cc_op() that is hidden in the bowels of gen_jcc() to spill cc_op and mark it clean. Signed-off-by: Paolo Bonzini Reviewed-by: Richard Henderson --- target/i386/tcg/translate.c | 60 ++++++++----------------------------- 1 file changed, 13 insertions(+), 47 deletions(-) diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index 63a39d9f15a..3732d05d5f5 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -112,7 +112,6 @@ typedef struct DisasContext { #endif bool vex_w; /* used by AVX even on 32-bit processors */ bool jmp_opt; /* use direct block chaining for direct jumps */ - bool repz_opt; /* optimize jumps within repz instructions */ bool cc_op_dirty; =20 CCOp cc_op; /* current CC operation */ @@ -1205,23 +1204,6 @@ static inline void gen_jcc(DisasContext *s, int b, T= CGLabel *l1) } } =20 -/* XXX: does not work with gdbstub "ice" single step - not a - serious problem. The caller can jump to the returned label - to stop the REP but, if the flags have changed, it has to call - gen_update_cc_op before doing so. */ -static TCGLabel *gen_jz_ecx_string(DisasContext *s) -{ - TCGLabel *l1 =3D gen_new_label(); - TCGLabel *l2 =3D gen_new_label(); - - gen_update_cc_op(s); - gen_op_jnz_ecx(s, l1); - gen_set_label(l2); - gen_jmp_rel_csize(s, 0, 1); - gen_set_label(l1); - return l2; -} - static void gen_stos(DisasContext *s, MemOp ot) { gen_string_movl_A0_EDI(s); @@ -1313,27 +1295,25 @@ static void do_gen_rep(DisasContext *s, MemOp ot, void (*fn)(DisasContext *s, MemOp ot), bool is_repz_nz) { - TCGLabel *l2; - l2 =3D gen_jz_ecx_string(s); + TCGLabel *done =3D gen_new_label(); + + gen_update_cc_op(s); + gen_op_jz_ecx(s, done); + fn(s, ot); gen_op_add_reg_im(s, s->aflag, R_ECX, -1); if (is_repz_nz) { int nz =3D (s->prefix & PREFIX_REPNZ) ? 1 : 0; - gen_jcc(s, (JCC_Z << 1) | (nz ^ 1), l2); + gen_jcc(s, (JCC_Z << 1) | (nz ^ 1), done); } - /* - * A loop would cause two single step exceptions if ECX =3D 1 - * before rep string_insn - */ - if (s->repz_opt) { - gen_op_jz_ecx(s, l2); - } - /* - * For CMPS/SCAS there is no need to set CC_OP_DYNAMIC: only one itera= tion - * is done at a time, so the translation block ends unconditionally af= ter - * this instruction and there is no control flow junction. - */ + + /* Go to the main loop but reenter the same instruction. */ gen_jmp_rel_csize(s, -cur_insn_len(s), 0); + + /* CX/ECX/RCX is zero, or REPZ/REPNZ broke the repetition. */ + gen_set_label(done); + set_cc_op(s, CC_OP_DYNAMIC); + gen_jmp_rel_csize(s, 0, 1); } =20 static void gen_repz(DisasContext *s, MemOp ot, @@ -3664,20 +3644,6 @@ static void i386_tr_init_disas_context(DisasContextB= ase *dcbase, CPUState *cpu) dc->cpuid_xsave_features =3D env->features[FEAT_XSAVE]; dc->jmp_opt =3D !((cflags & CF_NO_GOTO_TB) || (flags & (HF_RF_MASK | HF_TF_MASK | HF_INHIBIT_IRQ_MAS= K))); - /* - * If jmp_opt, we want to handle each string instruction individually. - * For icount also disable repz optimization so that each iteration - * is accounted separately. - * - * FIXME: this is messy; it makes REP string instructions a lot less - * efficient than they should be and it gets in the way of correct - * handling of RF (interrupts or traps arriving after any iteration - * of a repeated string instruction but the last should set RF to 1). - * Perhaps it would be more efficient if REP string instructions were - * always at the beginning of the TB, or even their own TB? That - * would even allow accounting up to 64k iterations at once for icount. - */ - dc->repz_opt =3D !dc->jmp_opt && !(cflags & CF_USE_ICOUNT); =20 dc->T0 =3D tcg_temp_new(); dc->T1 =3D tcg_temp_new(); --=20 2.47.1 From nobody Wed Apr 9 01:11:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1734253631; cv=none; d=zohomail.com; s=zohoarc; b=C/DfETnwUbSjVH7ee+81LWAI4ePp5fIpw8bRdgfJohd3p0R9q2MsZqM8/4vy8+N7A2rBw1kYI3qTIzQftSdo6lcA56iAjE7cbXsOkFnKfhTUdwO8LsTl/zadUH6WFn3kLXq7KgXI9ex1ynBT5XlFXt8mcawH+NSdrIfvaKH4rPc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1734253631; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=T4DOvj8ea+R+4uCgyE0WisdYjtGttU2oS4PXE8TXzoY=; b=VwXmJub8OfSfafYVwbmOMHMxpdcCSfrlb4zs8XyvuArfYM8nFb+D+YT+sqrjueuiDaW4Ey/maW7btbIdJqY9IKpIBhZYy3STsKzKuKSupl5oMshYhF+NdJttFnF791oczhSRlIV8HSEaeKYNu6cUZpYzB6P3YHp6UG8T8IXmisk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1734253631555919.141000399981; Sun, 15 Dec 2024 01:07:11 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tMkaL-0004Yr-VC; Sun, 15 Dec 2024 04:06:45 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tMkaJ-0004YP-Nb for qemu-devel@nongnu.org; Sun, 15 Dec 2024 04:06:44 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tMkaI-0006yZ-0C for qemu-devel@nongnu.org; Sun, 15 Dec 2024 04:06:43 -0500 Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-523-lQB2gfseO9uiscaMScozzQ-1; Sun, 15 Dec 2024 04:06:36 -0500 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4361ac8b25fso17281115e9.2 for ; Sun, 15 Dec 2024 01:06:36 -0800 (PST) Received: from [192.168.10.3] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4362559ed8dsm106580625e9.23.2024.12.15.01.06.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Dec 2024 01:06:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734253600; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=T4DOvj8ea+R+4uCgyE0WisdYjtGttU2oS4PXE8TXzoY=; b=OcjNxbPzix2yBBoXvmkYFSOK0BVWw9DJxzVub9MRSnYM7NESbTSHPdSuRkKYmEwREjCHpU r7L0q8FLK7fhFuOA1GP9XSr9PFo5BvxcOb9U7iMaTxUDn6hBSStsqSzOxXSO1+FULwvJZ3 /aL95aaeO+/dEkqJ3DrfoSxO8Ef8dhU= X-MC-Unique: lQB2gfseO9uiscaMScozzQ-1 X-Mimecast-MFC-AGG-ID: lQB2gfseO9uiscaMScozzQ X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734253594; x=1734858394; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=T4DOvj8ea+R+4uCgyE0WisdYjtGttU2oS4PXE8TXzoY=; b=HVbS5uFwCV2lbEq208fxjiNPm/amTAiGzmWvlRcaa+wyBtg7JfSzPEVWOXDM8lPoSN yI9y319Qj0pdZx4JGVQkM7tk42BkCk1zl56SojnXIP14l6jVZM8snKaZj+/DWYuavVSB brTEIOaer51a9ZsCg70NilMOK0RKo1t4Y6RMQ8PfW6FNC8n9yd+8zLmFKRLt/LOdQMlp aVfSKkEts9egjImBkNLaxUuOjWypGRjEvsHMjj007pnQY7jncUZDVh7NXwh15x80yP9S +B9nxh1YKo1uFrTRhcc1rzIJBqADP45qq0Y+nEKl3Yyinap9ZzVUfe3cD+q/G9LaWDXa 7ALg== X-Gm-Message-State: AOJu0Yzfg0ASLjdHuR5UnL99qjdqa+3GiWwDXGPInym+GEYA9H70oIJh ogP64yNuNj2p/IHL2Ye0bMfw7KQVpV+WJpkD3e+diqjdIv8eheC6rsruopq6fQAeAZp7cKHLmMV 3Z1H6slsziBeAfvzfIFfToWLT12Nk5nBlOo8Nv6+1YMJwzGwOSbltRugeeRFKO8FCaVaGnfypoP AeoZRYWBfmBE9Cz3XQPdl5jBEOl5lhNTtlaOoR X-Gm-Gg: ASbGncudvHSVPPk/ZiVmQ2pUO8Msr8YaVs+b74BgXX2FPYx1NF7ubUf4DywRSx0al3T RBvq4RETdHfXOfGglQ4uAoKUik5vc1ag8Oxhxn+S/WdBucXa0Y8crWEBe9CjjD+3E0Aax9gIHBm tGENJHt2hD/TS5Nfav7iqBJJ0My+uJbCuO3ng8epBybclOZt94ByIJ9Qd1TwBOFLQYf0CqWLTCa kNUIAgOMFr+/CwvShzzG62Z1OoOyYf4xDbhoKfpq09eDPiC93ft1jNY7/k= X-Received: by 2002:a05:600c:1c07:b0:434:9fac:b158 with SMTP id 5b1f17b1804b1-4362aa34e8amr66686565e9.1.1734253593983; Sun, 15 Dec 2024 01:06:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IGc17yO0imPYbv18wiVlrvIXjcZ5jDUNimWVX4Jej1xi0CXP5bbcyUl6dfRb6WIqymS+yt1bg== X-Received: by 2002:a05:600c:1c07:b0:434:9fac:b158 with SMTP id 5b1f17b1804b1-4362aa34e8amr66686255e9.1.1734253593497; Sun, 15 Dec 2024 01:06:33 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: richard.henderson@linaro.org Subject: [PATCH 06/13] target/i386: tcg: move gen_set/reset_* earlier in the file Date: Sun, 15 Dec 2024 10:06:05 +0100 Message-ID: <20241215090613.89588-7-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241215090613.89588-1-pbonzini@redhat.com> References: <20241215090613.89588-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.292, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1734253634532116600 Content-Type: text/plain; charset="utf-8" Allow using them in the code that translates REP/REPZ, without forward declarations. Signed-off-by: Paolo Bonzini Reviewed-by: Richard Henderson --- target/i386/tcg/translate.c | 80 ++++++++++++++++++------------------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index 3732d05d5f5..0fe7ed4ec8d 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -724,6 +724,46 @@ static inline void gen_op_jnz_ecx(DisasContext *s, TCG= Label *label1) gen_op_j_ecx(s, TCG_COND_NE, label1); } =20 +static void gen_set_hflag(DisasContext *s, uint32_t mask) +{ + if ((s->flags & mask) =3D=3D 0) { + TCGv_i32 t =3D tcg_temp_new_i32(); + tcg_gen_ld_i32(t, tcg_env, offsetof(CPUX86State, hflags)); + tcg_gen_ori_i32(t, t, mask); + tcg_gen_st_i32(t, tcg_env, offsetof(CPUX86State, hflags)); + s->flags |=3D mask; + } +} + +static void gen_reset_hflag(DisasContext *s, uint32_t mask) +{ + if (s->flags & mask) { + TCGv_i32 t =3D tcg_temp_new_i32(); + tcg_gen_ld_i32(t, tcg_env, offsetof(CPUX86State, hflags)); + tcg_gen_andi_i32(t, t, ~mask); + tcg_gen_st_i32(t, tcg_env, offsetof(CPUX86State, hflags)); + s->flags &=3D ~mask; + } +} + +static void gen_set_eflags(DisasContext *s, target_ulong mask) +{ + TCGv t =3D tcg_temp_new(); + + tcg_gen_ld_tl(t, tcg_env, offsetof(CPUX86State, eflags)); + tcg_gen_ori_tl(t, t, mask); + tcg_gen_st_tl(t, tcg_env, offsetof(CPUX86State, eflags)); +} + +static void gen_reset_eflags(DisasContext *s, target_ulong mask) +{ + TCGv t =3D tcg_temp_new(); + + tcg_gen_ld_tl(t, tcg_env, offsetof(CPUX86State, eflags)); + tcg_gen_andi_tl(t, t, ~mask); + tcg_gen_st_tl(t, tcg_env, offsetof(CPUX86State, eflags)); +} + static void gen_helper_in_func(MemOp ot, TCGv v, TCGv_i32 n) { switch (ot) { @@ -2083,46 +2123,6 @@ static void gen_interrupt(DisasContext *s, uint8_t i= ntno) s->base.is_jmp =3D DISAS_NORETURN; } =20 -static void gen_set_hflag(DisasContext *s, uint32_t mask) -{ - if ((s->flags & mask) =3D=3D 0) { - TCGv_i32 t =3D tcg_temp_new_i32(); - tcg_gen_ld_i32(t, tcg_env, offsetof(CPUX86State, hflags)); - tcg_gen_ori_i32(t, t, mask); - tcg_gen_st_i32(t, tcg_env, offsetof(CPUX86State, hflags)); - s->flags |=3D mask; - } -} - -static void gen_reset_hflag(DisasContext *s, uint32_t mask) -{ - if (s->flags & mask) { - TCGv_i32 t =3D tcg_temp_new_i32(); - tcg_gen_ld_i32(t, tcg_env, offsetof(CPUX86State, hflags)); - tcg_gen_andi_i32(t, t, ~mask); - tcg_gen_st_i32(t, tcg_env, offsetof(CPUX86State, hflags)); - s->flags &=3D ~mask; - } -} - -static void gen_set_eflags(DisasContext *s, target_ulong mask) -{ - TCGv t =3D tcg_temp_new(); - - tcg_gen_ld_tl(t, tcg_env, offsetof(CPUX86State, eflags)); - tcg_gen_ori_tl(t, t, mask); - tcg_gen_st_tl(t, tcg_env, offsetof(CPUX86State, eflags)); -} - -static void gen_reset_eflags(DisasContext *s, target_ulong mask) -{ - TCGv t =3D tcg_temp_new(); - - tcg_gen_ld_tl(t, tcg_env, offsetof(CPUX86State, eflags)); - tcg_gen_andi_tl(t, t, ~mask); - tcg_gen_st_tl(t, tcg_env, offsetof(CPUX86State, eflags)); -} - /* Clear BND registers during legacy branches. */ static void gen_bnd_jmp(DisasContext *s) { --=20 2.47.1 From nobody Wed Apr 9 01:11:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1734253670; cv=none; d=zohomail.com; s=zohoarc; b=OGCT7yZJLIKspOpk4XYnKTxkGZm+kJXUEbQXt0RIU2BXoV2m1Y78m9L9neQLUAuH1lJkDoFeSK36OtW1mBnznNGMfBeE2wG3vDxeDUd4NtSZYE2c88hCKACkqw5s8/g9/WhpwskwwKAUl8lkf7kNCVP5HiXp6aMFBq76jHi9uKk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1734253670; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=UWAQn2YIR8aOSzjOe8Hz8zbe/CVb70iaUdD4Q/NtuH8=; b=jwCxWqpifwiwUlEGu7xidzS+VtMi7jzg0MD3SYmgFycssd4QY9KZ9m4S5I78na0L2r4thI94a2qKQoOrbv2mCVd3RsO2DTbP+jqeKIO9XRsi0x+fgtDQf8sRBuo/ViFg1FAvXsxIMEs/740rqQTlWevU2FZVIsJcEM7ihKKWJjw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1734253670746819.6831700525378; Sun, 15 Dec 2024 01:07:50 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tMkaJ-0004YM-Gf; Sun, 15 Dec 2024 04:06:43 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tMkaI-0004Xl-6w for qemu-devel@nongnu.org; Sun, 15 Dec 2024 04:06:42 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tMkaG-0006yS-Mr for qemu-devel@nongnu.org; Sun, 15 Dec 2024 04:06:41 -0500 Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-121-zysN8m5ENCqqylujJAy83w-1; Sun, 15 Dec 2024 04:06:38 -0500 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-385e27c5949so1867104f8f.3 for ; Sun, 15 Dec 2024 01:06:38 -0800 (PST) Received: from [192.168.10.3] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-388c8060582sm4640063f8f.93.2024.12.15.01.06.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Dec 2024 01:06:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734253600; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UWAQn2YIR8aOSzjOe8Hz8zbe/CVb70iaUdD4Q/NtuH8=; b=PlHxwHNPZd6T9khewmyrnakfKV1Wv+at38aPZJX0qegBrTgH4mN/K5Hit3GPTUsW6ZYebj dzbbkjAYdq9Sdwq7imjaRVJ+S4bTRafwRTIjZWZOThsaMB5I0WJOXFHf8s+WBOWbCCp6I9 QpHTylPudMCp1BW+bKF7Y6Uu/RTJ31g= X-MC-Unique: zysN8m5ENCqqylujJAy83w-1 X-Mimecast-MFC-AGG-ID: zysN8m5ENCqqylujJAy83w X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734253597; x=1734858397; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UWAQn2YIR8aOSzjOe8Hz8zbe/CVb70iaUdD4Q/NtuH8=; b=iL6KNMNxrFjUSSNixUL5M80cCMFf1SokHCchGXWkdZJfjXfWlnrzo+EBInDH+TmCNW FuoWLLWuknxtYN55954BkP8oSxXCJCLNdtRQqFsUSgzkAqjaOJL9WIggE0NUHz/D7fsS 42wgpGk0ciE8GmPmtXKHAA+Pp7GM0NGGnkKOVRznVGjK7GTzoGPEKjKsx93e6B/FOtq4 36VdaCIwvEfcIe9fvBg3+56pDqm8pt8nGE8PXax7p9PBfHHq2z/j3ePoDsmgtzuugMXX hIOCV75v2cTbkOMs6utc8wTtRcmUfF+HSw5ijFukOaUjO9DxfPURpM1hwlzdQNrcBw0b jG4A== X-Gm-Message-State: AOJu0Yx8Frys+sJT2u7KUQT9ugLnYW4oYiOHgIsXBhp0NiEN/le3DzAb bbUa34OfKxXv+PU6uMLsa0tydcr/K99O4YSI6KqlOJEToG6zPxtTJrJ3nVmAu/y+GnxcmtiWcd3 CNBVoVcwrmaoggszXH4FLv/JGLup2G5yMYQaD01Rgz+Vvi/iubB3BIS+ay7TGZHRXvBoxNjHJhm ZxO4EkmH1S/6I7XLP9zakYm49zM7Y2Zs2jWgMf X-Gm-Gg: ASbGncv5oqCZidY7GLA7Mm31wAZvH91P8NhUJEmLw7phJkzsQflDHe9UfzH2n/rrZCU 3lw9lcyDxRmGHoSJckFX5YPPhuIebQ3oDWFBkI1FU9BvV/e7ut32r/ELZHWaS7/CJ3FRdojGnTr xJksWzGe0DxQzgDV/lspRlwFemzNjXq/EnUHJLZNvVgbsV6c0QWs1Ry3KGXuJVQ0s5epmCVr/Fq 4fbGTSID/NG5hW6BN1P1PXxN03kFHpSs8HaeChPFeMWDHsgLhWZlFXSvis= X-Received: by 2002:a05:6000:4b1b:b0:385:dedb:a156 with SMTP id ffacd0b85a97d-38880af1254mr7564887f8f.6.1734253596922; Sun, 15 Dec 2024 01:06:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IGX6l3+aqpqjQSxhFK/ZDIZ2Hw65I/cdyie38iZj2RGSUVR8c8FNnBvqtQWbj57Fu3/nhBqpw== X-Received: by 2002:a05:6000:4b1b:b0:385:dedb:a156 with SMTP id ffacd0b85a97d-38880af1254mr7564860f8f.6.1734253596437; Sun, 15 Dec 2024 01:06:36 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: richard.henderson@linaro.org Subject: [PATCH 07/13] target/i386: fix RF handling for string instructions Date: Sun, 15 Dec 2024 10:06:06 +0100 Message-ID: <20241215090613.89588-8-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241215090613.89588-1-pbonzini@redhat.com> References: <20241215090613.89588-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.292, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1734253671357116600 Content-Type: text/plain; charset="utf-8" RF must be set on traps and interrupts from a string instruction, except if they occur after the last iteration. Ensure it is set before giving the main loop a chance to execute. Signed-off-by: Paolo Bonzini Reviewed-by: Richard Henderson --- target/i386/tcg/translate.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index 0fe7ed4ec8d..4ff0ccf71cb 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -1336,6 +1336,14 @@ static void do_gen_rep(DisasContext *s, MemOp ot, bool is_repz_nz) { TCGLabel *done =3D gen_new_label(); + bool had_rf =3D s->flags & HF_RF_MASK; + + /* + * Even if EFLAGS.RF was set on entry (such as if we're on the second = or + * later iteration and an exception or interrupt happened), force gen_= eob() + * not to clear the flag. We do that ourselves after the last iterati= on. + */ + s->flags &=3D ~HF_RF_MASK; =20 gen_update_cc_op(s); gen_op_jz_ecx(s, done); @@ -1347,12 +1355,24 @@ static void do_gen_rep(DisasContext *s, MemOp ot, gen_jcc(s, (JCC_Z << 1) | (nz ^ 1), done); } =20 + /* + * Traps or interrupts set RF_MASK if they happen after any iteration + * but the last. Set it here before giving the main loop a chance to + * execute. (For faults, seg_helper.c sets the flag as usual). + */ + if (!had_rf) { + gen_set_eflags(s, RF_MASK); + } + /* Go to the main loop but reenter the same instruction. */ gen_jmp_rel_csize(s, -cur_insn_len(s), 0); =20 /* CX/ECX/RCX is zero, or REPZ/REPNZ broke the repetition. */ gen_set_label(done); set_cc_op(s, CC_OP_DYNAMIC); + if (had_rf) { + gen_reset_eflags(s, RF_MASK); + } gen_jmp_rel_csize(s, 0, 1); } =20 @@ -2157,7 +2177,7 @@ gen_eob(DisasContext *s, int mode) gen_set_hflag(s, HF_INHIBIT_IRQ_MASK); } =20 - if (s->base.tb->flags & HF_RF_MASK) { + if (s->flags & HF_RF_MASK) { gen_reset_eflags(s, RF_MASK); } if (mode =3D=3D DISAS_EOB_RECHECK_TF) { --=20 2.47.1 From nobody Wed Apr 9 01:11:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1734253733; cv=none; d=zohomail.com; s=zohoarc; b=UDKBalMLrKfuVpZAjUiWeSxJOl2m3efZD7xBzVuvrs2U7/yAbVcTPuthzhGyhXLHMpc4kmWHW9xqM2xN5vhwhAqZbMTQLGbOhpqILHMy2RHLUISs1p6RrsrLS2CxsDXGrGuPcXmtDHHPcAhOppmR1v5X3qvYEVL+WAtzarGemmQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1734253733; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=OyQ9wLbCKDjV+T8LPYPoAogaZ9aobQT720NgGO1dskY=; b=VHeLULxL79OgIRg4hd1AvHcSqTw5bdhJDo4FxZapVVh9VHNkqa4BGCu9y2G0J9oIxKjSzuFZYwnl6ZjE0hKso6kXCrPvyLeXLvrqfca1R9OBGwsyV2ZnKivKsR3whTlT02GY9ktFMBdEDC6Fj456w+MkhsBfdfsQxxktfaspK0k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1734253733458419.2110151133877; Sun, 15 Dec 2024 01:08:53 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tMkaM-0004ZE-JF; Sun, 15 Dec 2024 04:06:46 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tMkaL-0004Yd-4x for qemu-devel@nongnu.org; Sun, 15 Dec 2024 04:06:45 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tMkaJ-0006yq-GW for qemu-devel@nongnu.org; Sun, 15 Dec 2024 04:06:44 -0500 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-630-2KNboUw-PR--IDjg476Y2g-1; Sun, 15 Dec 2024 04:06:41 -0500 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-436228ebc5eso345425e9.3 for ; Sun, 15 Dec 2024 01:06:40 -0800 (PST) Received: from [192.168.10.3] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-436255531b1sm106296625e9.2.2024.12.15.01.06.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Dec 2024 01:06:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734253602; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OyQ9wLbCKDjV+T8LPYPoAogaZ9aobQT720NgGO1dskY=; b=O/uXSGAHbif23rhze7e/ZQxQww8XsPuB4nsqbpSptcN0IKBrY17I5trTGpFX4Et1UkCdXY TfQwOENm6uLJj/JB/Zset72kECySws11l6P4O4Bp9s4dmVXVldrJGmqh8y6B36ZduANCyR fXLUEvCBYgkOmoM/fBBx0eSxnB4ebPw= X-MC-Unique: 2KNboUw-PR--IDjg476Y2g-1 X-Mimecast-MFC-AGG-ID: 2KNboUw-PR--IDjg476Y2g X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734253599; x=1734858399; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OyQ9wLbCKDjV+T8LPYPoAogaZ9aobQT720NgGO1dskY=; b=Z1DKw44bcrLbrX1FchkTc4jc7JsyYZthpXhOuNX+n3B9NaGNuwTSjJUGTgfsBSHTN4 4AiivCqmwKePPD09Bc3O7v6yczzj5ZyRI0iD/oj7BG3Ql/bW/A+EcHkxHBR90B+taPuw LhYVSBp8LnX0tSUIQ9Mrq4R4CEO2dymDLchjeoCWhSkegzBSW3EU6LhQgoR6rqjKS5+r kKNiZW8PYd2uMeU6Y3v7xaNz5INxEP2cfF7xeYAwok1ljj4aLVNrOESeWlfDLXIg3yuA YJJwzcB0qq9cbVTZ6eFJlBbqCVMi54YJcn9KrakidOQvo+sWhais/hOxRZck0lS3pii8 6EFg== X-Gm-Message-State: AOJu0YyFXwry+feK/u1BEQxIRd3XQ9w+XkrXpURT/bnEVeckXEXsQU1N iod4vmxPvn1K8d2/MqW9t9bsoOWMekdwEUDwEDRqAr/wFgB4/bo/sKQQv3sGURpku8NIh20wLnj JkdrVYGExVN6Xegjcvdx84XQ9ktrEu3QMyT2w6ui/lwPm+9NDxYSECTyT9c7gxxDG2e6tu7sSa6 EMoCQRTW1TbdEaatWPwAjpxttk8ayuIAhcSx3X X-Gm-Gg: ASbGncvqUCBwp3M+4g+HCop/qkmnKP8l24WygozvB6iA4/o+X9eq9OXbhWp/jp8PLvM kc5tn8btTR4z6IxVXiXJ9zkWeXnZVSsPwwZpmii07L2UyNbkYRM+/G8puXBvVUKyMfcT1PoyLD0 KMCJfi36ERpMlR8Z/FtcVCYIoAB7ImfLi5W0bfd2hII4b4/KIWhRRg7m5Hyz2eFLBmxNFcgjxZm RWSKsu+T3M+wLF5LNYtUlTHpUA3+fWpYrlLA05thGFSlEZGCn6hv7k4jBU= X-Received: by 2002:a05:600c:1e87:b0:436:2923:d23a with SMTP id 5b1f17b1804b1-4362aaaacdemr67798715e9.33.1734253599047; Sun, 15 Dec 2024 01:06:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IEY6XxQ1kkFUAQYQchIxSuLl6sJEOV/OkesHZY8hxwQkH9d9IWdxbWI4eM49e+N9LO5rrofOA== X-Received: by 2002:a05:600c:1e87:b0:436:2923:d23a with SMTP id 5b1f17b1804b1-4362aaaacdemr67798335e9.33.1734253598557; Sun, 15 Dec 2024 01:06:38 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: richard.henderson@linaro.org Subject: [PATCH 08/13] target/i386: make cc_op handling more explicit for repeated string instructions. Date: Sun, 15 Dec 2024 10:06:07 +0100 Message-ID: <20241215090613.89588-9-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241215090613.89588-1-pbonzini@redhat.com> References: <20241215090613.89588-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.292, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1734253735509116600 Content-Type: text/plain; charset="utf-8" Since the cost of gen_update_cc_op() must be paid anyway, it's easier to place them manually and not rely on spilling that is buried under multiple levels of function calls. And since cc_op will have been spilled at the point of a fault, just make the whole insn CC_OP_DYNAMIC. Once repz_opt is reintroduced, a fault could happen either before or after the first execution of CMPS/SCAS, and CC_OP_DYNAMIC sidesteps the complicated matter of what x86_restore_state_to_opc would do. Signed-off-by: Paolo Bonzini --- target/i386/tcg/translate.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index 4ff0ccf71cb..4b53a47000e 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -1345,14 +1345,29 @@ static void do_gen_rep(DisasContext *s, MemOp ot, */ s->flags &=3D ~HF_RF_MASK; =20 + /* + * For CMPS/SCAS, the CC_OP after a memory fault could come from either + * the previous instruction or the string instruction; but because we + * arrange to keep CC_OP up to date all the time, just mark the whole + * insn as CC_OP_DYNAMIC. + * + * It's not a problem to do this even for instructions that do not + * modify the flags, so do it unconditionally. + */ gen_update_cc_op(s); + tcg_set_insn_start_param(s->base.insn_start, 1, CC_OP_DYNAMIC); + + /* Any iteration at all? */ gen_op_jz_ecx(s, done); =20 fn(s, ot); gen_op_add_reg_im(s, s->aflag, R_ECX, -1); + gen_update_cc_op(s); + + /* Leave if REP condition fails. */ if (is_repz_nz) { int nz =3D (s->prefix & PREFIX_REPNZ) ? 1 : 0; - gen_jcc(s, (JCC_Z << 1) | (nz ^ 1), done); + gen_jcc_noeob(s, (JCC_Z << 1) | (nz ^ 1), done); } =20 /* --=20 2.47.1 From nobody Wed Apr 9 01:11:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1734253688; cv=none; d=zohomail.com; s=zohoarc; b=PF6mOeBhSrfi9lzvJmU7KG/50d9P6e8Fh3kl98kk9HttYWO3tz09nl9FopL/YKJp2tyWfTcgVE00lRXHIDyqXPyjzapbK7MCXWdcqR5ndV4KG95XNSTsm5lQLnnXC98VtGNB6vkZvQQhyXrHDHFC7kknbqusRfrf9WqpmbYRvbk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1734253688; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ln+83d/zkp6fFGfT0f7BeAfE0lUk0lgGm7eEEbWaZJc=; b=U82TtxVANH3R3N1zj1U7MYT8l1/iY6SEjYEBi/QKOO+s/HyvPDh8zRk1L7G/izwY+kKDcQINPMzAGjb8xFHEoOJVVRoGJPMJnTcEwj0Buz9xFyC8SxnMV3ClAzLJIn9R5BjgkCNOyHC3JzCQKZN/y7G/N8Yi2N5AsiLcjCGvg5I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1734253688596942.1053724222231; Sun, 15 Dec 2024 01:08:08 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tMkaS-0004cK-4b; Sun, 15 Dec 2024 04:06:52 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tMkaQ-0004bU-KD for qemu-devel@nongnu.org; Sun, 15 Dec 2024 04:06:50 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tMkaP-0006zD-3z for qemu-devel@nongnu.org; Sun, 15 Dec 2024 04:06:50 -0500 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-38-f4I0jET3OJKWjSqSJn4A6Q-1; Sun, 15 Dec 2024 04:06:44 -0500 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-4361ac8b25fso17281315e9.2 for ; Sun, 15 Dec 2024 01:06:44 -0800 (PST) Received: from [192.168.10.3] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-436257177c5sm103082705e9.43.2024.12.15.01.06.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Dec 2024 01:06:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734253607; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ln+83d/zkp6fFGfT0f7BeAfE0lUk0lgGm7eEEbWaZJc=; b=PISNlKUeGpEHRv/faO5ntE8GfYWB+1FG+ZroZz6HwXZ43JBtzjGItzQHvkVY3m7fSowfHB 5XvqmJznYovMRoHSrkj3ivmQOEtTv500PK5xQOOo/IZOtzm4mmLceMDFrMJuPYRBDADO7O TdaSPt+hfvQAgOErlOtznNoOaJjZGGw= X-MC-Unique: f4I0jET3OJKWjSqSJn4A6Q-1 X-Mimecast-MFC-AGG-ID: f4I0jET3OJKWjSqSJn4A6Q X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734253602; x=1734858402; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ln+83d/zkp6fFGfT0f7BeAfE0lUk0lgGm7eEEbWaZJc=; b=j87zspTes1E0a0UzaZKlbEcKrCzUgfWzXejEgrIQ4NaFIdi9+In895AxeaaQ0RhRwo gAhhyi1wUghuNGrWrsWXbI4rj6YouC0Vy92jxplnsqiPtx6GNFlFke8dqpGOpKFUwrf0 1MLE/PZabw9/9KhljN9setepOS/OWvX5I7zkGWHDrO4Yl7o2WlMxx2r2iQ5GFYbm2Fbf vD4y2eITuVK5VXrnNVYRWSv2bse0itkQrC0c0WM4OPK10+C5S133qEuywLghJUk7YOU0 9N1Z6Z/s9jOHVhgN3jcdNGEOtDfYLUpn2D+Jw+eYfxQRIH1LstRq3jdw0mZIkoGfP8iF rFIQ== X-Gm-Message-State: AOJu0YwfBAKH6RHVAkBEdQQw9n0Dk9K7DF3NYpAsyy3tLJrsP2uNjwd9 Atz5v05vO8ryCAbtfpBMJkbPoNtJmX6MOzWManTKKIgypRFqMKP1Ubvi7sxSVy5R6MsSkX99Wu5 Pe+cdoi8oSs3LW/mQy/iri2KUW2NIUx0jGG8PIrMUMBx0OaWQKcrcxpYy7E7qQlxUac+OxiU+w9 mAucrtAaYT3Z7LZt8SL7jMDxLX+Mrbh4ue41XB X-Gm-Gg: ASbGnctnpJrjQkwgfhiBmxU5e+A1E9A/c6S4QdHRLlYewO/3fsNgfvOa3JxWdNHOTov j8RT+BpG2/xw+3OXNyrv6cr3RYE4SgRyL6iFnNX1f08kQQyFJ0LA7OJzMWNvUvDJRrVLyKGn3JW xQf71JCipZVpNmtkFppGRuBZ2YDfKifrB97kCRFyUHdNUirdVvDh4n3cUt79NFhyXZUyDx+eXnV UXOqvCKWSPE/E9yeINhMytJQOxvklcat5R/L/028jc4/KgWnMDp8BzxU9w= X-Received: by 2002:a05:600c:3491:b0:435:b064:7dce with SMTP id 5b1f17b1804b1-4362aa66f9fmr83696035e9.18.1734253602131; Sun, 15 Dec 2024 01:06:42 -0800 (PST) X-Google-Smtp-Source: AGHT+IGFJ5BR7dc4oAYyQreVT3zYJuA/hsO/26W/PF8wDJ8c/kNRR2uejhec11Q8ymUB3ibKDc279g== X-Received: by 2002:a05:600c:3491:b0:435:b064:7dce with SMTP id 5b1f17b1804b1-4362aa66f9fmr83695755e9.18.1734253601681; Sun, 15 Dec 2024 01:06:41 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: richard.henderson@linaro.org Subject: [PATCH 09/13] target/i386: do not use gen_op_jz_ecx for repeated string operations Date: Sun, 15 Dec 2024 10:06:08 +0100 Message-ID: <20241215090613.89588-10-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241215090613.89588-1-pbonzini@redhat.com> References: <20241215090613.89588-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.292, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1734253689655116600 Content-Type: text/plain; charset="utf-8" Explicitly generate a TSTEQ branch (which is optimized to NE x,0 if possibl= e). This does not make much sense yet, but later we will add more checks and so= me will use a temporary to check on the decremented value of CX/ECX/RCX; it wi= ll be clearer for all checks to share the same logic using TSTEQ(reg, cx_mask). Signed-off-by: Paolo Bonzini Reviewed-by: Richard Henderson --- target/i386/tcg/translate.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index 4b53a47000e..8ef938372d5 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -1336,6 +1336,7 @@ static void do_gen_rep(DisasContext *s, MemOp ot, bool is_repz_nz) { TCGLabel *done =3D gen_new_label(); + target_ulong cx_mask =3D MAKE_64BIT_MASK(0, 8 << s->aflag); bool had_rf =3D s->flags & HF_RF_MASK; =20 /* @@ -1358,7 +1359,7 @@ static void do_gen_rep(DisasContext *s, MemOp ot, tcg_set_insn_start_param(s->base.insn_start, 1, CC_OP_DYNAMIC); =20 /* Any iteration at all? */ - gen_op_jz_ecx(s, done); + tcg_gen_brcondi_tl(TCG_COND_TSTEQ, cpu_regs[R_ECX], cx_mask, done); =20 fn(s, ot); gen_op_add_reg_im(s, s->aflag, R_ECX, -1); --=20 2.47.1 From nobody Wed Apr 9 01:11:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1734253703; cv=none; d=zohomail.com; s=zohoarc; b=Nu6OpF+OBF2nK2TYZ3jmMWXeDVCyv+y6OjIDbEk7DJAIgRWEz519e67CGUl0fNX79S5Q++SAItm4PJIhf4pRnsu60vGCLcw8SKkcVBCJJTfYCu7l14qCaNEMTebF8kx7uk0CulyWp3vYYRsRD/AHkOkl6xizMuRfXvW2+1eXxH0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1734253703; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Idh6F+CCHPC1QXuT+CtjsxuMJk4UDaP68th/7PYeY34=; b=dDobExa4+AxA0Rn+SHTCkaLp6V4+r7gt8BzFX9Uojq8/1HYpGQrPCXZK6fblWIR7ZU4rwt4tmB9fF4J0hW0AzEM/5CLNysaRkkpF9jHmDIyMybEgTKqCdB7ua178gbl1I92g0lwfqZz3AEEJ+5zQg+ga50o5rN9wIFTuJwq1hHY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1734253703166747.4475737057063; Sun, 15 Dec 2024 01:08:23 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tMkaU-0004dR-Gj; Sun, 15 Dec 2024 04:06:54 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tMkaR-0004cC-PM for qemu-devel@nongnu.org; Sun, 15 Dec 2024 04:06:51 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tMkaP-0006zF-8g for qemu-devel@nongnu.org; Sun, 15 Dec 2024 04:06:51 -0500 Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-139-X-mO8gnnMf-3Rv43afx5lw-1; Sun, 15 Dec 2024 04:06:47 -0500 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-4361ecebc5bso345515e9.1 for ; Sun, 15 Dec 2024 01:06:47 -0800 (PST) Received: from [192.168.10.3] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4361e322328sm119831855e9.0.2024.12.15.01.06.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Dec 2024 01:06:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734253608; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Idh6F+CCHPC1QXuT+CtjsxuMJk4UDaP68th/7PYeY34=; b=ao+cfuo1liSmCN8aYlV6FYO5LKLSq46H8VIo+mTUph4ObbRfccLQvK7pwVxS0US8iBwA61 mpNwCuCLhcdgORokEWgwP625xPWU7Hun35J2PjZH5Q0GKZ+Oi8gbsN3nSb6p6WoycpJKJm 5cGrqndiz+kfIApBtOHeBxSIFx6VBOk= X-MC-Unique: X-mO8gnnMf-3Rv43afx5lw-1 X-Mimecast-MFC-AGG-ID: X-mO8gnnMf-3Rv43afx5lw X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734253605; x=1734858405; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Idh6F+CCHPC1QXuT+CtjsxuMJk4UDaP68th/7PYeY34=; b=hTZ66idSwkKB/End6951pvJY7L3H25Nxm1I/XLshGn5+i0lUxjySKDTiLJ8TJ6+tmo NYgUBXXFhFP+FJJKLpxbda/dTCOa4b6ZP2ilM+50rs8PQWR2CpqimNbC2h8BtEDrl2JG eca3GnVQ4wTx/I2sZpDTp1ny/Gdh9jmf5456QXV+aiG34071l8zLiqoZ7fV+V/XpsEkW nJT/Rwj/yuR3OJ5nZOk9q2c2TLP5JDeQv25+YAgCRErCnV3Pq4L+jh38GUk3mysPDLji /I3le17FdbuHeqj9DW7OxHsVt4UfTjsgkwTDhmxT2lkQb3C2wMcaktDgs13edvhNMt3w JLeg== X-Gm-Message-State: AOJu0YzN78CWcFRgn33KmOTjdlTI3pSdhXJx5/QJJaCGm/JRSpHDb84L gUA/DjnpPEHh19izgA43P4hQsdbxJA1CDdgqN2H1KMibUo3nlpLkKgDK5hSiG4BpiLT+tAc621c xSatGWpervCL0dRh6a9efNbyIIVAFgRQnhgjKFzeROdkTxIpUNKQZaQ3W5KgJAKERBHOOICHAuY M1Ht5F1bC4r41oFIAsPrrHWejh1/xcXDsmw29t X-Gm-Gg: ASbGncs2/kDEB4s9kEi7SYEbrkKeIHthGEhy2vdgD9emnUdXAP2QsrKcKE0sOskIwSU bGUzIwHw+mrw/2BD5mRrsEGRbUEokBf+2cHapCQ7A/3u8MVTm6iWwQJ+DTa6VoCpc+irZR4UTmz be4PXnHDTK4mIkHbW98+Vv7797VrS4ardLg4Mtu2dU5UiK/IIm+sBHgHBx2mCF6fVYvs35Iu++i 5zwYfxLQ2/z75B//1V8G08F8t6KaJ8plrIyB4n/nbBz1o3A1zXOt+oBEFA= X-Received: by 2002:a05:600c:384a:b0:434:a239:d2fe with SMTP id 5b1f17b1804b1-4362aaa89e0mr62916755e9.28.1734253604921; Sun, 15 Dec 2024 01:06:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IGysfcTt60NSxVu+C2YzakB8y+tIeDM8pyUczW8CaTsHFWSR1u70gKVQoOhcglW463CCq2Xjw== X-Received: by 2002:a05:600c:384a:b0:434:a239:d2fe with SMTP id 5b1f17b1804b1-4362aaa89e0mr62916555e9.28.1734253604506; Sun, 15 Dec 2024 01:06:44 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: richard.henderson@linaro.org Subject: [PATCH 10/13] target/i386: optimize CX handling in repeated string operations Date: Sun, 15 Dec 2024 10:06:09 +0100 Message-ID: <20241215090613.89588-11-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241215090613.89588-1-pbonzini@redhat.com> References: <20241215090613.89588-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.292, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1734253703425116600 Content-Type: text/plain; charset="utf-8" In a repeated string operation, CX/ECX will be decremented until it is 0 but never underflow. Use this observation to avoid a deposit or zero-extend operation if the address size of the operation is smaller than MO_TL. As in the previous patch, the patch is structured to include some preparatory work for subsequent changes. In particular, introducing cx_next prepares for when ECX will be decremented *before* calling fn(s, ot), and therefore cannot yet be written back to cpu_regs. Signed-off-by: Paolo Bonzini Reviewed-by: Richard Henderson --- target/i386/tcg/translate.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index 8ef938372d5..2ea8a418612 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -1337,6 +1337,7 @@ static void do_gen_rep(DisasContext *s, MemOp ot, { TCGLabel *done =3D gen_new_label(); target_ulong cx_mask =3D MAKE_64BIT_MASK(0, 8 << s->aflag); + TCGv cx_next =3D tcg_temp_new(); bool had_rf =3D s->flags & HF_RF_MASK; =20 /* @@ -1362,7 +1363,19 @@ static void do_gen_rep(DisasContext *s, MemOp ot, tcg_gen_brcondi_tl(TCG_COND_TSTEQ, cpu_regs[R_ECX], cx_mask, done); =20 fn(s, ot); - gen_op_add_reg_im(s, s->aflag, R_ECX, -1); + + tcg_gen_subi_tl(cx_next, cpu_regs[R_ECX], 1); + + /* + * Write back cx_next to CX/ECX/RCX. There can be no carry, so zero + * extend if needed but do not do expensive deposit operations. + */ +#ifdef TARGET_X86_64 + if (s->aflag =3D=3D MO_32) { + tcg_gen_ext32u_tl(cx_next, cx_next); + } +#endif + tcg_gen_mov_tl(cpu_regs[R_ECX], cx_next); gen_update_cc_op(s); =20 /* Leave if REP condition fails. */ --=20 2.47.1 From nobody Wed Apr 9 01:11:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1734253662; cv=none; d=zohomail.com; s=zohoarc; b=KJlFfzXfOh8uivEu+gEotRU0qb9eM2Sp0dIOnfyOUsVBCm98RD5/vx9aFnFaIGxM2H/z3kEW7QViwOdAv5eytX+vXo62BJQSqTG5aOzO1s7fXUO7gla7ysVUukHT9iZ+XryZoHYtCsg1UnH9MONNcBG5GBO9OHb+K0gDVnd9Mfk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1734253662; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=acGgMB4ZUdKs37fWXnZnKDTObj/dNL285Lmn4GAtSdY=; b=bjnE0YvkN964//iw+X6iRcSUuHw9Og8rVnATmo9g2J5DfYp6D/vHc2zxSCDSll9ceEzLOh4xAmobmbK9DSKEZ3Wiw0wsiVy9d34bIkd8jVzO2Xhc8U0kIx3M3wx+IphfH3taSBZeN8vYqO/hqQXJi3XExIXTx/1rPFEcN/zmU/I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1734253662567659.6253959618251; Sun, 15 Dec 2024 01:07:42 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tMkaV-0004eE-MB; Sun, 15 Dec 2024 04:06:55 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tMkaU-0004dn-PV for qemu-devel@nongnu.org; Sun, 15 Dec 2024 04:06:54 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tMkaT-0006zY-6E for qemu-devel@nongnu.org; Sun, 15 Dec 2024 04:06:54 -0500 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-663-o2un7vbGNLC61w5WYgSFxA-1; Sun, 15 Dec 2024 04:06:50 -0500 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-43582d49dacso27609815e9.2 for ; Sun, 15 Dec 2024 01:06:50 -0800 (PST) Received: from [192.168.10.3] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-388c805d489sm4767112f8f.88.2024.12.15.01.06.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Dec 2024 01:06:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734253611; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=acGgMB4ZUdKs37fWXnZnKDTObj/dNL285Lmn4GAtSdY=; b=LlpphGMKIxiMQ7cXYoT0m3idjCowk7Z70ZPCAldQKZFQEtVPpQwuDTG5n0geAri7n0oil8 dn5wMsXiTEnczXphnCqO8nYxdshnOIFDrelIhuQXEpzf4qLyR1DOdVr4v0k4d9mKZAmbSS ZgwM2btFutmPLhPiHU/TkQQ/CnLQyfw= X-MC-Unique: o2un7vbGNLC61w5WYgSFxA-1 X-Mimecast-MFC-AGG-ID: o2un7vbGNLC61w5WYgSFxA X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734253608; x=1734858408; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=acGgMB4ZUdKs37fWXnZnKDTObj/dNL285Lmn4GAtSdY=; b=Q9KSHEYbIcSYZ9V08RHIllz4TBrn3TmihDU6K6G19J4MmgHClmRXeFvfEop/9xoKjI zrNXC6PKa0MLDbOmaM/pyvqfTZkbbRxSkhJHi1j8jmF+TkGLUVj2/aOs2gK7qwCRNM9S 1Tz6ZmcPrDXq8hOFnxAfG7wWvJfK2L45EvMS0ZdXk+BWCAg9oPzDz1X1RvolG3dHGWJh 5bPJ/0UB/2QSfJGpPG0QFNLzm0yl3/A1MsDKjFROEW335yRAQIYQuYLfCgeqYGGitKsy 9wa2xmajxRtuhb/6A7UhLUmpBJwWtEA6qkCs2vfB8hdLPN6Mm25TkQCF0Pae0qQ24bnZ TFtA== X-Gm-Message-State: AOJu0YxKA+wtgPgzXisdnvowdu+xv9qHiiJP67Wn5TDkG1Yt2f8iGq5A PMRlpCnVDuoLvykq8QUXVfHzEJVxRam4TuNMdLgIUCXlWPMNaXwdoU0mtxayOOjCCNbCpu72pnz b9eHd4iQmgWuqSbRmCJdFUSndWXRM3GXLbnIdYew6wAD9hcTbzjilMDebF/0yMafJlMmlVLqL2z 1o7QQEQt4Uxlbjtnznyxn5RolqDX33tLjAmXZI X-Gm-Gg: ASbGncsLpNWo7Il+OqSngq5EAN0bw9HaiAdCnNX5jOfRqs9Y4ImiR1WK0BMONhDsj4r lteZdXRmXMa/hxUv5N9XdvZ6fJTqZ0Xrz/W0k9OyzVocQgmbNZ+Aymwsedo2JnnYEL7GkuGe5m+ ++DmUonBFLTPzcAzqa3y8h9O/Qk2r1U0oIdB/UYiZ03Y88zA10SsJh9ILVnN/aYHx6hc+kgqtS2 Z8bJSIJFGd4+qCL1WFWJswGYNFdXyg/tmmsX9mdxfZ5TYVWsxVHOrKfBXc= X-Received: by 2002:a5d:59a6:0:b0:385:e5d8:3ec2 with SMTP id ffacd0b85a97d-38880ada81amr5975211f8f.28.1734253607979; Sun, 15 Dec 2024 01:06:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IG8dLJJHHNe/eEwhUHzLWm75h30pKMYt44IkH6wsgF6P8LfDHX6+SSXRUw2OpQWUOXhLhwp4w== X-Received: by 2002:a5d:59a6:0:b0:385:e5d8:3ec2 with SMTP id ffacd0b85a97d-38880ada81amr5975187f8f.28.1734253607439; Sun, 15 Dec 2024 01:06:47 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: richard.henderson@linaro.org Subject: [PATCH 11/13] target/i386: execute multiple REP/REPZ iterations without leaving TB Date: Sun, 15 Dec 2024 10:06:10 +0100 Message-ID: <20241215090613.89588-12-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241215090613.89588-1-pbonzini@redhat.com> References: <20241215090613.89588-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.292, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1734253663385116600 Content-Type: text/plain; charset="utf-8" Use a TCG loop so that it is not necessary to go through the setup steps of REP and through the I/O check on every iteration. Interestingly, this is not a particularly effective optimization on its own, though it avoids the cost of correct RF emulation that was added in the previous patch. The main benefit lies in allowing the hoisting of loop invariants outside the loop, which will happen separately. The loop exits when the low 16 bits of CX/ECX/RCX are zero (so generally speaking the string operation runs in 65536 iteration batches) to give the main loop an opportunity to pick up interrupts. Signed-off-by: Paolo Bonzini Reviewed-by: Richard Henderson --- target/i386/tcg/translate.c | 55 +++++++++++++++++++++++++++++++++---- 1 file changed, 49 insertions(+), 6 deletions(-) diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index 2ea8a418612..e0f9f7748bc 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -1331,13 +1331,28 @@ static void gen_outs(DisasContext *s, MemOp ot) gen_bpt_io(s, s->tmp2_i32, ot); } =20 +#define REP_MAX 65535 + static void do_gen_rep(DisasContext *s, MemOp ot, void (*fn)(DisasContext *s, MemOp ot), bool is_repz_nz) { + TCGLabel *last =3D gen_new_label(); + TCGLabel *loop =3D gen_new_label(); TCGLabel *done =3D gen_new_label(); + target_ulong cx_mask =3D MAKE_64BIT_MASK(0, 8 << s->aflag); TCGv cx_next =3D tcg_temp_new(); + + /* + * Check if we must translate a single iteration only. Normally, HF_R= F_MASK + * would also limit translation blocks to one instruction, so that gen= _eob + * can reset the flag; here however RF is set throughout the repetitio= n, so + * we can plow through until CX/ECX/RCX is zero. + */ + bool can_loop =3D + (!(tb_cflags(s->base.tb) & (CF_USE_ICOUNT | CF_SINGLE_STEP)) + && !(s->flags & (HF_TF_MASK | HF_INHIBIT_IRQ_MASK))); bool had_rf =3D s->flags & HF_RF_MASK; =20 /* @@ -1362,19 +1377,29 @@ static void do_gen_rep(DisasContext *s, MemOp ot, /* Any iteration at all? */ tcg_gen_brcondi_tl(TCG_COND_TSTEQ, cpu_regs[R_ECX], cx_mask, done); =20 - fn(s, ot); - - tcg_gen_subi_tl(cx_next, cpu_regs[R_ECX], 1); - /* - * Write back cx_next to CX/ECX/RCX. There can be no carry, so zero - * extend if needed but do not do expensive deposit operations. + * From now on we operate on the value of CX/ECX/RCX that will be writ= ten + * back, which is stored in cx_next. There can be no carry, so we can= zero + * extend here if needed and not do any expensive deposit operations l= ater. */ + tcg_gen_subi_tl(cx_next, cpu_regs[R_ECX], 1); #ifdef TARGET_X86_64 if (s->aflag =3D=3D MO_32) { tcg_gen_ext32u_tl(cx_next, cx_next); + cx_mask =3D ~0; } #endif + + /* + * The last iteration is handled outside the loop, so that cx_next + * can never underflow. + */ + if (can_loop) { + tcg_gen_brcondi_tl(TCG_COND_TSTEQ, cx_next, cx_mask, last); + } + + gen_set_label(loop); + fn(s, ot); tcg_gen_mov_tl(cpu_regs[R_ECX], cx_next); gen_update_cc_op(s); =20 @@ -1384,6 +1409,12 @@ static void do_gen_rep(DisasContext *s, MemOp ot, gen_jcc_noeob(s, (JCC_Z << 1) | (nz ^ 1), done); } =20 + if (can_loop) { + tcg_gen_subi_tl(cx_next, cpu_regs[R_ECX], 1); + tcg_gen_brcondi_tl(TCG_COND_TSTNE, cx_next, REP_MAX, loop); + tcg_gen_brcondi_tl(TCG_COND_TSTEQ, cx_next, cx_mask, last); + } + /* * Traps or interrupts set RF_MASK if they happen after any iteration * but the last. Set it here before giving the main loop a chance to @@ -1396,6 +1427,18 @@ static void do_gen_rep(DisasContext *s, MemOp ot, /* Go to the main loop but reenter the same instruction. */ gen_jmp_rel_csize(s, -cur_insn_len(s), 0); =20 + if (can_loop) { + /* + * The last iteration needs no conditional jump, even if is_repz_n= z, + * because the repeats are ending anyway. + */ + gen_set_label(last); + set_cc_op(s, CC_OP_DYNAMIC); + fn(s, ot); + tcg_gen_mov_tl(cpu_regs[R_ECX], cx_next); + gen_update_cc_op(s); + } + /* CX/ECX/RCX is zero, or REPZ/REPNZ broke the repetition. */ gen_set_label(done); set_cc_op(s, CC_OP_DYNAMIC); --=20 2.47.1 From nobody Wed Apr 9 01:11:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1734253691; cv=none; d=zohomail.com; s=zohoarc; b=kvKRrER4nRk1KXKAEoH0AXeJqBw1TFVKu6bNmVuOhNE/TyxB4jJfUvtFh9DKc49SmR0EBTWQPLOU+ADkDKw11OGFmvZN6GRWKDeS9jwYIC/GUawvzAaAgLR/N01VxSajUzNu2Eb3F0RqRfNobXhrLPn2KvCvL3A8gZGxMR6hzGw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1734253691; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=7qSvxAgvi/iO/49Wv7FHDDVXKQuBKeLKv7IQubFUeUk=; b=ag7RfKaD/VWroXACkxHY3Qc0WMm4/OWo86JyaeMPlwhsIoGtOKw+cT4ms5uDgTUmNvCtN+XLDAqd72upmeAyHyYzmbEdTum5oHWuAWCYTGyti32lA/6jMX83bNeJRVxpSSK0psvIVFhiTqm1fsGbCenWMflF4f4FGxlxgJMmx1Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17342536915121008.3956196816475; Sun, 15 Dec 2024 01:08:11 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tMkaZ-0004fm-7n; Sun, 15 Dec 2024 04:06:59 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tMkaY-0004fM-3a for qemu-devel@nongnu.org; Sun, 15 Dec 2024 04:06:58 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tMkaW-000704-Ct for qemu-devel@nongnu.org; Sun, 15 Dec 2024 04:06:57 -0500 Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-475-578W1KbUNH6t7WV7UQhyOA-1; Sun, 15 Dec 2024 04:06:52 -0500 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-4362f893bfaso10208085e9.1 for ; Sun, 15 Dec 2024 01:06:52 -0800 (PST) Received: from [192.168.10.3] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43625706c77sm103226235e9.34.2024.12.15.01.06.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Dec 2024 01:06:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734253614; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7qSvxAgvi/iO/49Wv7FHDDVXKQuBKeLKv7IQubFUeUk=; b=gFXoDpUUeIVUThe6xjT4KzzXSGjC5voAqPWEzxUgkfWnEN7rpOaWU1zFF+y3FC30b67a6C GIy0hF/fe7FJoUMVBX4oMtiiDrzeVAGvmeKrSEto6gdeYYEMYqBgAhEmAkEZ+W9eIXCikR DSdBlTSLGWMPQ3M2FzfyFw0Bo+wdkNI= X-MC-Unique: 578W1KbUNH6t7WV7UQhyOA-1 X-Mimecast-MFC-AGG-ID: 578W1KbUNH6t7WV7UQhyOA X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734253611; x=1734858411; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7qSvxAgvi/iO/49Wv7FHDDVXKQuBKeLKv7IQubFUeUk=; b=De6H4LQNUCHod+rzk1PurTaCMYzMNCa8wnWQQM2gHvX5vVjZ6KnQp+0UkhhPm9TR+l PatesYvoBQAnj0Dby6EkdRKrx5thnoqbqbRf7AjGwwxa81oc1b9zu49Hi1DQINpEazGK GsVuLdADpLyPRGCqQln8GF5/81C3p9Hmrl8aV0G98rpVHxKcCvUIA7uAeedYupRupEjE CHr+wMy2y0XsH99RbhhxoCtf1wS161YqLECcj+NaN77s1YbfCVIZOCZKYdebTkEdCjpE GEWZRDzfH4YMzLv/jyyZ+X8q2IAB4x6S/lCDnPRXBM69a3reQDfNAK0PkKG/KxB/zzuF Wl5w== X-Gm-Message-State: AOJu0YzqdjKbLqRUxe2cHsWyCmgl0yNausuM+L90ym4rwAMsi2Btbmtb s6FLQHMloSVzvXY6P1TuFI3SPRXoRPLFQGgr5IuZj53kPmR3JBkbN5UxHPTbr6ghHvHAYw9KLVh MbOoRFfAYe5f7NkKnjOKNAyU91+1EEKG9BIkIzk5gyH+gPtpznMy5D1S9ovw2GaTRUqrk1xi5LF ioQt1vIJjRumeRhmZspadmY0mEuObj7N3mEHdQ X-Gm-Gg: ASbGncvRymRu+pxjCS42Nq48qJlsIiz79Uv1Yy6/+73A57TiqTXNcbzP4k0QHWgT4IO MB033yYzBw69zMEDf1nBdQuCOuYUmC4N2FjFOcvIKgyF0EQ7aQclEiFnCI2zD06Z809Q6u1aKeh RmHUQ+MziglSlMmpPgoBtxkGCZwWDBNnS3qlx+v09nN3kmPxFgAkGAKMhU4LlqxkAAii1zWxrDi MRvoTyIac0lWIWCzULcuYMJ6jVFfQl7CXkQVNCx4aRUcSaPmEdspCby738= X-Received: by 2002:a05:600c:4709:b0:42c:de2f:da27 with SMTP id 5b1f17b1804b1-4362aa34d7bmr88880975e9.2.1734253610927; Sun, 15 Dec 2024 01:06:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IE4ISHZrDX6b/xTH4Cf1MN1fyCDJ8scktNcsSMm+1xq/ClLYGUh47DCl2pwO3OwW1MnylMEUw== X-Received: by 2002:a05:600c:4709:b0:42c:de2f:da27 with SMTP id 5b1f17b1804b1-4362aa34d7bmr88880625e9.2.1734253610500; Sun, 15 Dec 2024 01:06:50 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: richard.henderson@linaro.org Subject: [PATCH 12/13] target/i386: pull computation of string update value out of loop Date: Sun, 15 Dec 2024 10:06:11 +0100 Message-ID: <20241215090613.89588-13-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241215090613.89588-1-pbonzini@redhat.com> References: <20241215090613.89588-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.292, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1734253693351116600 Content-Type: text/plain; charset="utf-8" This is a common operation that is executed many times in rep movs or rep stos loops. It can improve performance by several percentage points. Signed-off-by: Paolo Bonzini --- target/i386/tcg/translate.c | 54 ++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index e0f9f7748bc..4b652cc23e1 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -831,16 +831,13 @@ static bool gen_check_io(DisasContext *s, MemOp ot, T= CGv_i32 port, #endif } =20 -static void gen_movs(DisasContext *s, MemOp ot) +static void gen_movs(DisasContext *s, MemOp ot, TCGv dshift) { - TCGv dshift; - gen_string_movl_A0_ESI(s); gen_op_ld_v(s, ot, s->T0, s->A0); gen_string_movl_A0_EDI(s); gen_op_st_v(s, ot, s->T0, s->A0); =20 - dshift =3D gen_compute_Dshift(s, ot); gen_op_add_reg(s, s->aflag, R_ESI, dshift); gen_op_add_reg(s, s->aflag, R_EDI, dshift); } @@ -1244,22 +1241,22 @@ static inline void gen_jcc(DisasContext *s, int b, = TCGLabel *l1) } } =20 -static void gen_stos(DisasContext *s, MemOp ot) +static void gen_stos(DisasContext *s, MemOp ot, TCGv dshift) { gen_string_movl_A0_EDI(s); gen_op_st_v(s, ot, s->T0, s->A0); - gen_op_add_reg(s, s->aflag, R_EDI, gen_compute_Dshift(s, ot)); + gen_op_add_reg(s, s->aflag, R_EDI, dshift); } =20 -static void gen_lods(DisasContext *s, MemOp ot) +static void gen_lods(DisasContext *s, MemOp ot, TCGv dshift) { gen_string_movl_A0_ESI(s); gen_op_ld_v(s, ot, s->T0, s->A0); gen_op_mov_reg_v(s, ot, R_EAX, s->T0); - gen_op_add_reg(s, s->aflag, R_ESI, gen_compute_Dshift(s, ot)); + gen_op_add_reg(s, s->aflag, R_ESI, dshift); } =20 -static void gen_scas(DisasContext *s, MemOp ot) +static void gen_scas(DisasContext *s, MemOp ot, TCGv dshift) { gen_string_movl_A0_EDI(s); gen_op_ld_v(s, ot, s->T1, s->A0); @@ -1268,13 +1265,11 @@ static void gen_scas(DisasContext *s, MemOp ot) tcg_gen_sub_tl(cpu_cc_dst, s->T0, s->T1); set_cc_op(s, CC_OP_SUBB + ot); =20 - gen_op_add_reg(s, s->aflag, R_EDI, gen_compute_Dshift(s, ot)); + gen_op_add_reg(s, s->aflag, R_EDI, dshift); } =20 -static void gen_cmps(DisasContext *s, MemOp ot) +static void gen_cmps(DisasContext *s, MemOp ot, TCGv dshift) { - TCGv dshift; - gen_string_movl_A0_EDI(s); gen_op_ld_v(s, ot, s->T1, s->A0); gen_string_movl_A0_ESI(s); @@ -1284,7 +1279,6 @@ static void gen_cmps(DisasContext *s, MemOp ot) tcg_gen_sub_tl(cpu_cc_dst, s->T0, s->T1); set_cc_op(s, CC_OP_SUBB + ot); =20 - dshift =3D gen_compute_Dshift(s, ot); gen_op_add_reg(s, s->aflag, R_ESI, dshift); gen_op_add_reg(s, s->aflag, R_EDI, dshift); } @@ -1303,7 +1297,7 @@ static void gen_bpt_io(DisasContext *s, TCGv_i32 t_po= rt, int ot) } } =20 -static void gen_ins(DisasContext *s, MemOp ot) +static void gen_ins(DisasContext *s, MemOp ot, TCGv dshift) { gen_string_movl_A0_EDI(s); /* Note: we must do this dummy write first to be restartable in @@ -1314,11 +1308,11 @@ static void gen_ins(DisasContext *s, MemOp ot) tcg_gen_andi_i32(s->tmp2_i32, s->tmp2_i32, 0xffff); gen_helper_in_func(ot, s->T0, s->tmp2_i32); gen_op_st_v(s, ot, s->T0, s->A0); - gen_op_add_reg(s, s->aflag, R_EDI, gen_compute_Dshift(s, ot)); + gen_op_add_reg(s, s->aflag, R_EDI, dshift); gen_bpt_io(s, s->tmp2_i32, ot); } =20 -static void gen_outs(DisasContext *s, MemOp ot) +static void gen_outs(DisasContext *s, MemOp ot, TCGv dshift) { gen_string_movl_A0_ESI(s); gen_op_ld_v(s, ot, s->T0, s->A0); @@ -1327,14 +1321,14 @@ static void gen_outs(DisasContext *s, MemOp ot) tcg_gen_andi_i32(s->tmp2_i32, s->tmp2_i32, 0xffff); tcg_gen_trunc_tl_i32(s->tmp3_i32, s->T0); gen_helper_out_func(ot, s->tmp2_i32, s->tmp3_i32); - gen_op_add_reg(s, s->aflag, R_ESI, gen_compute_Dshift(s, ot)); + gen_op_add_reg(s, s->aflag, R_ESI, dshift); gen_bpt_io(s, s->tmp2_i32, ot); } =20 #define REP_MAX 65535 =20 -static void do_gen_rep(DisasContext *s, MemOp ot, - void (*fn)(DisasContext *s, MemOp ot), +static void do_gen_rep(DisasContext *s, MemOp ot, TCGv dshift, + void (*fn)(DisasContext *s, MemOp ot, TCGv dshift), bool is_repz_nz) { TCGLabel *last =3D gen_new_label(); @@ -1399,7 +1393,7 @@ static void do_gen_rep(DisasContext *s, MemOp ot, } =20 gen_set_label(loop); - fn(s, ot); + fn(s, ot, dshift); tcg_gen_mov_tl(cpu_regs[R_ECX], cx_next); gen_update_cc_op(s); =20 @@ -1434,7 +1428,7 @@ static void do_gen_rep(DisasContext *s, MemOp ot, */ gen_set_label(last); set_cc_op(s, CC_OP_DYNAMIC); - fn(s, ot); + fn(s, ot, dshift); tcg_gen_mov_tl(cpu_regs[R_ECX], cx_next); gen_update_cc_op(s); } @@ -1449,23 +1443,27 @@ static void do_gen_rep(DisasContext *s, MemOp ot, } =20 static void gen_repz(DisasContext *s, MemOp ot, - void (*fn)(DisasContext *s, MemOp ot)) + void (*fn)(DisasContext *s, MemOp ot, TCGv dshift)) =20 { + TCGv dshift =3D gen_compute_Dshift(s, ot); + if (s->prefix & (PREFIX_REPZ | PREFIX_REPNZ)) { - do_gen_rep(s, ot, fn, false); + do_gen_rep(s, ot, dshift, fn, false); } else { - fn(s, ot); + fn(s, ot, dshift); } } =20 static void gen_repz_nz(DisasContext *s, MemOp ot, - void (*fn)(DisasContext *s, MemOp ot)) + void (*fn)(DisasContext *s, MemOp ot, TCGv dshift)) { + TCGv dshift =3D gen_compute_Dshift(s, ot); + if (s->prefix & (PREFIX_REPZ | PREFIX_REPNZ)) { - do_gen_rep(s, ot, fn, true); + do_gen_rep(s, ot, dshift, fn, true); } else { - fn(s, ot); + fn(s, ot, dshift); } } =20 --=20 2.47.1 From nobody Wed Apr 9 01:11:20 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1734253708; cv=none; d=zohomail.com; s=zohoarc; b=WNYVMQE/YypSCaJaI8iuWAu3nQBiEeMJx6kajtt//pFb0TwpU3BVIJvgHwRsDPxe9cOoBvexmRDub51pMM8VGBap+/PI+HZ9OpYLgVa8AqpdIHUNNuFHsXNaKeMPRT6bjl0n9ndy7aecnUhIJix0lXVwMimZR0bU1zxrfOIyA6o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1734253708; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=+7Q/7tH4enxnwW3OhOEz+YJTZLRmROVofkNsXBKXZhI=; b=cR1TKzPrudlAucgG/mrPWqjRYvkUHRp1INQoImFB3gOTT6/XBGGt+sX5P53GiHh1XI/8x6oRuKk4J/jD8V8C61RhDflEKE8cF9zn2oWHCvIxob7MzhZemggkkBsXgRrG0/x3+X/aZ0p/DiNaE81gYhVoYW+82IVUuJbmof3KgIg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1734253708070407.1800538853016; Sun, 15 Dec 2024 01:08:28 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tMkad-0004gR-PM; Sun, 15 Dec 2024 04:07:03 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tMkac-0004gA-3A for qemu-devel@nongnu.org; Sun, 15 Dec 2024 04:07:02 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tMkaa-00070L-PX for qemu-devel@nongnu.org; Sun, 15 Dec 2024 04:07:01 -0500 Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-58-26Vaq9NLNMCU3kJH_D8Ifw-1; Sun, 15 Dec 2024 04:06:55 -0500 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4361ecebc5bso345635e9.1 for ; Sun, 15 Dec 2024 01:06:55 -0800 (PST) Received: from [192.168.10.3] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43625553234sm105815575e9.3.2024.12.15.01.06.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Dec 2024 01:06:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734253617; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+7Q/7tH4enxnwW3OhOEz+YJTZLRmROVofkNsXBKXZhI=; b=L+/Ue0PXpGuNgljytng42cNOTd6hMga0/4IjsyBu4/fg1WMAOYspgUlK417ZTDK6xBUshe GgqxL2iEoNrR7MJgBC9VQQXcCuLLwy+S6k5sYLBQwVbl6qwDdiRaZpekF+EZW23no/rHeq 8TQMO31DMmK5WEGaozEuBX5uQS7Dj2I= X-MC-Unique: 26Vaq9NLNMCU3kJH_D8Ifw-1 X-Mimecast-MFC-AGG-ID: 26Vaq9NLNMCU3kJH_D8Ifw X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734253613; x=1734858413; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+7Q/7tH4enxnwW3OhOEz+YJTZLRmROVofkNsXBKXZhI=; b=GwLlw+skLZyHO8onAN5SM2nNl5HIDtwhldLnUsQtRGN/RDi9E9JSSrDBIaoOXK6s8J +2xeLFYPEe7Z1xY7qrcRDSXwUf2Ao+4lq7oxWNBC4mv4NNRyA314mmCAvooa1Q84o/De kUUUuQFCat/yMBuQxTm1ohoqJx/mGcC2y3GCdJteA/75URj5EyqJL27bLbpgYR31SG4/ KfmbySPeyM1xDoiMGmMnTaPYX1WcOw4sOPpjzLcdKGgA11lLkiVKr2D9ALFt52rUUg2I 9JiwjyBiiZnyXtDtYXVfQjIEVD6NFyXoF6T2r3aKp2BbHfj3ved0PeUf7t6bsa6cw5mG VPWA== X-Gm-Message-State: AOJu0Yx4tQwe+SlNLKxWOZc+G6FDd5USgvLHT4sa4m1NBqdGuJ7EJU3P LkAw1avYhVJfWs6MTbPmIvg5dvRFVREJ41xQutRoKSIh97NV7ubUKov6z8zgNP37JiL8Dftiq5M iU6eyIAt1zUc6w4rC3DrVhwnvtccILbVtVXtRinMnhL20rOJNB8oqzity/jLQsGWMYzzezfCQ6r //ShkYTG2DpdsxjX7thzw+wVhuDTjJuS2kHGPX X-Gm-Gg: ASbGncvKekOkogxaKIe+TBClxXA0+TYw6AiV1iowmcS7A+4J9S1blegYS4wnUFlbb/w DpjA9oyDbErGtDIPxPQ/PVn05OEeDzEezeNEze5Tt+0fkPOBjZDzkwVVduBRZjcxVnypBOh61qj wpaC1bRXjc03o7gpb4IOIHp4ROPuadrleKrFUM1SYW03Gi+Dtd8REuY/7aDVj/XQj1cxkBPNpMo kl02vV37Z0T47GYdpUyeHo2Ug1UHrL+6dus62VakGnk+rXN4cGy0M7jksM= X-Received: by 2002:a05:600c:1e0b:b0:434:feb1:adcf with SMTP id 5b1f17b1804b1-4362aa9d2afmr66978665e9.25.1734253613026; Sun, 15 Dec 2024 01:06:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IHKptYqJeAQcw0foSrC6OnVaqP26dUMYCfohyYkKVH+u0m3f7ySM+QiB6JZPiv6s6jwCia/Ww== X-Received: by 2002:a05:600c:1e0b:b0:434:feb1:adcf with SMTP id 5b1f17b1804b1-4362aa9d2afmr66978315e9.25.1734253612585; Sun, 15 Dec 2024 01:06:52 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: richard.henderson@linaro.org Subject: [PATCH 13/13] target/i386: avoid using s->tmp0 for add to implicit registers Date: Sun, 15 Dec 2024 10:06:12 +0100 Message-ID: <20241215090613.89588-14-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241215090613.89588-1-pbonzini@redhat.com> References: <20241215090613.89588-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.292, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1734253709377116600 Content-Type: text/plain; charset="utf-8" For updates to implicit registers (RCX in LOOP instructions, RSI or RDI in string instructions, or the stack pointer) do the add directly using the registers (with no temporary) if 32-bit or 64-bit, or use a temporary created for the occasion if 16-bit. This is more efficient and removes move instructions for the MO_TL case. Signed-off-by: Paolo Bonzini Reviewed-by: Richard Henderson --- target/i386/tcg/translate.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index 4b652cc23e1..8de506927b0 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -504,17 +504,24 @@ static inline void gen_op_jmp_v(DisasContext *s, TCGv= dest) s->pc_save =3D -1; } =20 +static inline void gen_op_add_reg(DisasContext *s, MemOp size, int reg, TC= Gv val) +{ + /* Using cpu_regs[reg] does not work for xH registers. */ + assert(size >=3D MO_16); + if (size =3D=3D MO_16) { + TCGv temp =3D tcg_temp_new(); + tcg_gen_add_tl(temp, cpu_regs[reg], val); + gen_op_mov_reg_v(s, size, reg, temp); + } else { + tcg_gen_add_tl(cpu_regs[reg], cpu_regs[reg], val); + tcg_gen_ext_tl(cpu_regs[reg], cpu_regs[reg], size); + } +} + static inline void gen_op_add_reg_im(DisasContext *s, MemOp size, int reg, int32_t val) { - tcg_gen_addi_tl(s->tmp0, cpu_regs[reg], val); - gen_op_mov_reg_v(s, size, reg, s->tmp0); -} - -static inline void gen_op_add_reg(DisasContext *s, MemOp size, int reg, TC= Gv val) -{ - tcg_gen_add_tl(s->tmp0, cpu_regs[reg], val); - gen_op_mov_reg_v(s, size, reg, s->tmp0); + gen_op_add_reg(s, size, reg, tcg_constant_tl(val)); } =20 static inline void gen_op_ld_v(DisasContext *s, int idx, TCGv t0, TCGv a0) --=20 2.47.1