From nobody Mon Nov 25 02:08:55 2024 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=1718877372; cv=none; d=zohomail.com; s=zohoarc; b=HTt1VUxECjp5JHJLJS1zjf2DJNE71jlplzB5P2bc1JtaNb8+ycAnczYWdxZWhZjtnNwlTeRyEIvByk7iZDlhwqYXSGHYTKBOFmBQErCTu5D7uPczFd3+MIjDniQEI6xWenx6VdAQ/3JcAHxf/LesEQaZqzxYTrl+drXOn/MFIJs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1718877372; h=Content-Type:Content-Transfer-Encoding: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:Cc; bh=mB6qUyfk7CEyOLtSYFq4HWKNU3wdVBe6UZgliSYNpcM=; b=W61it8O1utmZ3a8CTxklGUtMzrgtOxz1e4FMShOeCxKrxsfEvI+a1Fm44RBSoFmzzR6Bebq25xvWFJ2/vtx4Cn+lJZOmyMEZqYegcCkwS+RpE7oH7VRSfZqTC+0a8G6NhcugdU51sPykmq7tewbG5DYxR9N8IxcEl3hLFOwpCSA= 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 171887737223881.08328345029872; Thu, 20 Jun 2024 02:56:12 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sKEUy-0002G7-Uo; Thu, 20 Jun 2024 05:54:32 -0400 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 1sKEUx-0002Fa-3n for qemu-devel@nongnu.org; Thu, 20 Jun 2024 05:54:31 -0400 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 1sKEUv-0005Ry-DZ for qemu-devel@nongnu.org; Thu, 20 Jun 2024 05:54:30 -0400 Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-424-lZ-yi2FuPYiXyRW-L6XtbA-1; Thu, 20 Jun 2024 05:54:26 -0400 Received: by mail-ed1-f69.google.com with SMTP id 4fb4d7f45d1cf-57c6979daf7so341363a12.1 for ; Thu, 20 Jun 2024 02:54:26 -0700 (PDT) Received: from avogadro.local ([151.62.196.71]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-57cbb05b465sm8894650a12.18.2024.06.20.02.54.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 02:54:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718877268; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mB6qUyfk7CEyOLtSYFq4HWKNU3wdVBe6UZgliSYNpcM=; b=flk7wJ4DdHukX65+gtGU0VTHNuehc5k0M7yTLMo16DPJSq5tMpU653//ClZgv8eD149twI eHW4uCE3vjCkm/vvus8TM11LLuX5PLpP+c9xW3kzYW8z5fDxepu5GE3P+7bclv57orTLsR fFBFn2MKPbJPYJ36gOkMd9+dJEXm1h0= X-MC-Unique: lZ-yi2FuPYiXyRW-L6XtbA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718877264; x=1719482064; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mB6qUyfk7CEyOLtSYFq4HWKNU3wdVBe6UZgliSYNpcM=; b=rEuUf1E9RGpSJkxHA9H9VdjpspMt2zdiKRSDRqb29wyGqUMHEy4KvLb2lAGNIqT+5i cSBE1gLHlanjOleKORB/NligsVwexy6QfmyjjHhjxsNjcE5YAJfOiMw4YlJnahxdF1eC u+Z2HROZ7ERiZuaYE/YN8N89q9rVwuKmKSBz6rg9JY1b0F6O/s/8yb1LYG1DEnu8spJu 7uVrWK/swTKYGx5eSKDcl3dY9lFN1tw83fT5KzAuC/wRD0f1fCNwhSB94kBq9nWFxlTO OufPbbbNptcTR7uJEycs6+CL6nBtlrb4ON3wfmqfk7HXFlTRxkp62fnmc7q1/+Gx3AsL PuCw== X-Gm-Message-State: AOJu0YwBOWZ2bqfWCCxQ0bVLDFxsS1Kg0IhN4ie6QQwa8yw5ruEeqZbv qDaANyLApY8lYi/vw4+V3qqMB4/zj36Ehh0tqOsgo1NkTi5DINh4Jgp/6namQJzBUgG/wxld37l DINPcc4yH6ECMjSucoIbOX8KLEh6uNSR+9w85AHaKFGSKrC8Vx3yXoQtQE6T7o+fvQrD/vJeIFZ 4UpzlQBn+7QlvpYfdta1yMoDAvg7fbGKovHgdn X-Received: by 2002:a50:d6d7:0:b0:57c:5f74:d8ff with SMTP id 4fb4d7f45d1cf-57d07e750c8mr2960967a12.21.1718877264640; Thu, 20 Jun 2024 02:54:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGwrgvmp2sBwO+HqQd3L0vQhEO1A2g2UqS++YxTiAoqdUyr/irKL/XOyXhTgWvMCQ9iYqYXMw== X-Received: by 2002:a50:d6d7:0:b0:57c:5f74:d8ff with SMTP id 4fb4d7f45d1cf-57d07e750c8mr2960956a12.21.1718877264218; Thu, 20 Jun 2024 02:54:24 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 01/10] target/i386: use cpu_cc_dst for CC_OP_POPCNT Date: Thu, 20 Jun 2024 11:54:10 +0200 Message-ID: <20240620095419.386958-2-pbonzini@redhat.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240620095419.386958-1-pbonzini@redhat.com> References: <20240620095419.386958-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: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.144, 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: 1718877372770100001 Content-Type: text/plain; charset="utf-8" It is the only POPCNT that computes ZF from one of the cc_op_* registers, but it uses cpu_cc_src instead of cpu_cc_dst like the others. Do not make it the odd one off. Signed-off-by: Paolo Bonzini Reviewed-by: Richard Henderson --- target/i386/cpu.h | 2 +- target/i386/tcg/cc_helper.c | 2 +- target/i386/tcg/translate.c | 2 +- target/i386/tcg/emit.c.inc | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 7e2a9b56aea..f54cd93b3f9 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1332,7 +1332,7 @@ typedef enum { CC_OP_BMILGQ, =20 CC_OP_CLR, /* Z set, all other flags clear. */ - CC_OP_POPCNT, /* Z via CC_SRC, all other flags clear. */ + CC_OP_POPCNT, /* Z via CC_DST, all other flags clear. */ =20 CC_OP_NB, } CCOp; diff --git a/target/i386/tcg/cc_helper.c b/target/i386/tcg/cc_helper.c index f76e9cb8cfb..301ed954064 100644 --- a/target/i386/tcg/cc_helper.c +++ b/target/i386/tcg/cc_helper.c @@ -107,7 +107,7 @@ target_ulong helper_cc_compute_all(target_ulong dst, ta= rget_ulong src1, case CC_OP_CLR: return CC_Z | CC_P; case CC_OP_POPCNT: - return src1 ? 0 : CC_Z; + return dst ? 0 : CC_Z; =20 case CC_OP_MULB: return compute_all_mulb(dst, src1); diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index ad1819815ab..f32cda4e169 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -324,7 +324,7 @@ static const uint8_t cc_op_live[CC_OP_NB] =3D { [CC_OP_ADOX] =3D USES_CC_SRC | USES_CC_SRC2, [CC_OP_ADCOX] =3D USES_CC_DST | USES_CC_SRC | USES_CC_SRC2, [CC_OP_CLR] =3D 0, - [CC_OP_POPCNT] =3D USES_CC_SRC, + [CC_OP_POPCNT] =3D USES_CC_DST, }; =20 static void set_cc_op_1(DisasContext *s, CCOp op, bool dirty) diff --git a/target/i386/tcg/emit.c.inc b/target/i386/tcg/emit.c.inc index 11faa70b5e2..fc7477833bc 100644 --- a/target/i386/tcg/emit.c.inc +++ b/target/i386/tcg/emit.c.inc @@ -2804,10 +2804,10 @@ static void gen_POPA(DisasContext *s, X86DecodedIns= n *decode) =20 static void gen_POPCNT(DisasContext *s, X86DecodedInsn *decode) { - decode->cc_src =3D tcg_temp_new(); + decode->cc_dst =3D tcg_temp_new(); decode->cc_op =3D CC_OP_POPCNT; =20 - tcg_gen_mov_tl(decode->cc_src, s->T0); + tcg_gen_mov_tl(decode->cc_dst, s->T0); tcg_gen_ctpop_tl(s->T0, s->T0); } =20 --=20 2.45.2 From nobody Mon Nov 25 02:08:55 2024 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=1718877387; cv=none; d=zohomail.com; s=zohoarc; b=OCEyu2X/luHjQgjo5CpcEKbdAsQCgBgo1er5f0JctV6a6iDREK4s42ZcbvdzOcRxKjvzXoSQAFjEhJXzjQEsXFzumnpXsDy2prg1tv5I2M7Mj4VppGJwi2+fEX0BHU1vGosz1ZQ35rYXUFOEPDqONii5fEJO7biPNYbQPQyt7Lc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1718877387; h=Content-Type:Content-Transfer-Encoding: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:Cc; bh=La0Xgc4fXhE2dqcStb1IyrP1obFxek+qtw925qAODeo=; b=NoEWeeVc5gtQNqlUCwruGGydtqaXxsjuLgkFy+aGrlhvi6AUJsKLqWzTLP2+/S3KoNNlI9G4odITFk48MyNUSfZ7/EbiO0L5seFsoHeuyqKnqC0oEqUQgei0D5QbbwXwcnkBJQGti7BavjW4Gdhu5K+F/6jG3trM5sbh1qSlwbo= 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 1718877387923670.3554487693791; Thu, 20 Jun 2024 02:56:27 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sKEV6-0002Gp-E9; Thu, 20 Jun 2024 05:54:40 -0400 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 1sKEUz-0002GO-T0 for qemu-devel@nongnu.org; Thu, 20 Jun 2024 05:54:34 -0400 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 1sKEUy-0005SH-A7 for qemu-devel@nongnu.org; Thu, 20 Jun 2024 05:54:33 -0400 Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-613-8tHcPaGIMPyyc8Cu_MVO1A-1; Thu, 20 Jun 2024 05:54:29 -0400 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-a6efbb08949so27506666b.0 for ; Thu, 20 Jun 2024 02:54:28 -0700 (PDT) Received: from avogadro.local ([151.62.196.71]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a6f8cc20663sm297636966b.190.2024.06.20.02.54.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 02:54:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718877270; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=La0Xgc4fXhE2dqcStb1IyrP1obFxek+qtw925qAODeo=; b=J16EaIhU7fROjSW7lNAxw6f8cuJMU+j2ZE2mE/P6RDAmWKFoq1ORuc7hkEEowsYZRBWe0x ts/DEa6DISZZPkqTqv+KLhPL5SUyUKJgHK0/LKPukrAT2hi7+njP9TPX8uMVcbqNTULO9g QUt7GwsQk62rzUvNoHY3Z2G/NLct7z0= X-MC-Unique: 8tHcPaGIMPyyc8Cu_MVO1A-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718877267; x=1719482067; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=La0Xgc4fXhE2dqcStb1IyrP1obFxek+qtw925qAODeo=; b=YByiYPNjMdf1QrYYV1oRbQnrxjPT2khRPgXMqeb5ckiMXvl0vwA+lif9nbPgXnzQq7 BsDFM09Ox/QksvVRKs+skZcQ0gs+n5vbHuYcXtAfwVuuHXYJb25/abnRAI+/64e0HdNO UP1YZdP0kLSWlnGmLRcUaXxzFQvp+bLgX/WUNinSaXijpWfzm384sbTRBoYWc7Dx1MPT 27iWe3f7xV1LmT1cWmw9wTISOL0SOAskpb9Rdi9zLFDPwffu5fEIilr3Mnc3jkMw+WfX fefVcGL5oR2rOdZmA9TZX9MI1DID0TfLUICi06BhngubLLOm9rHM9kEKJnDimnJLyGW4 OybQ== X-Gm-Message-State: AOJu0YxnnXFts6d4RlttAtKkTVGaK8gZbYA53G/8/aYhya7mmA7rMhGp PMSR0q4y+1YVZQDxbh9Ox5VgXi1x6BbNOSQQCmQQ/IyvChwXOSD6APbP3rRT+syUd8RyYFZ1eSz il5+uSxREEKz0x+lE4nvhHPM1WGpee05pZXgoBCJcq3XTJ5XOVCgBK4DXjsIc8E5QySI8T8A2lK L73DnJ0r+jviTBHgJW5leNnpMxj/PFmpyXRaU+ X-Received: by 2002:a17:907:c713:b0:a6f:61c7:dead with SMTP id a640c23a62f3a-a6fab61398amr398709666b.17.1718877267087; Thu, 20 Jun 2024 02:54:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEr3KynHYAXEID1ikOd8o6kXYGfX+u9zYgoVOSH0PUwdB3yn1j/Uvc3Uci/PK1bQUVc1xmNcQ== X-Received: by 2002:a17:907:c713:b0:a6f:61c7:dead with SMTP id a640c23a62f3a-a6fab61398amr398707566b.17.1718877266735; Thu, 20 Jun 2024 02:54:26 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 02/10] target/i386: give CC_OP_POPCNT low bits corresponding to MO_TL Date: Thu, 20 Jun 2024 11:54:11 +0200 Message-ID: <20240620095419.386958-3-pbonzini@redhat.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240620095419.386958-1-pbonzini@redhat.com> References: <20240620095419.386958-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: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.144, 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: 1718877388669100001 Content-Type: text/plain; charset="utf-8" Handle it like the other arithmetic cc_ops. This simplifies a bit the implementation of bit test instructions. Signed-off-by: Paolo Bonzini Reviewed-by: Richard Henderson --- target/i386/cpu.h | 13 +++++++++++-- target/i386/tcg/translate.c | 3 +-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/target/i386/cpu.h b/target/i386/cpu.h index f54cd93b3f9..8504a7998fd 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1275,6 +1275,7 @@ typedef enum { CC_OP_ADCX, /* CC_DST =3D C, CC_SRC =3D rest. */ CC_OP_ADOX, /* CC_SRC2 =3D O, CC_SRC =3D rest. */ CC_OP_ADCOX, /* CC_DST =3D C, CC_SRC2 =3D O, CC_SRC =3D rest. */ + CC_OP_CLR, /* Z and P set, all other flags clear. */ =20 CC_OP_MULB, /* modify all flags, C, O =3D (CC_SRC !=3D 0) */ CC_OP_MULW, @@ -1331,8 +1332,16 @@ typedef enum { CC_OP_BMILGL, CC_OP_BMILGQ, =20 - CC_OP_CLR, /* Z set, all other flags clear. */ - CC_OP_POPCNT, /* Z via CC_DST, all other flags clear. */ + /* + * Note that only CC_OP_POPCNT (i.e. the one with MO_TL size) + * is used or implemented, because the translation needs + * to zero-extend CC_DST anyway. + */ + CC_OP_POPCNTB__, /* Z via CC_DST, all other flags clear. */ + CC_OP_POPCNTW__, + CC_OP_POPCNTL__, + CC_OP_POPCNTQ__, + CC_OP_POPCNT =3D sizeof(target_ulong) =3D=3D 8 ? CC_OP_POPCNTQ__ : CC_= OP_POPCNTL__, =20 CC_OP_NB, } CCOp; diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index f32cda4e169..934c514e64f 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -1019,8 +1019,6 @@ static CCPrepare gen_prepare_eflags_z(DisasContext *s= , TCGv reg) .imm =3D CC_Z }; case CC_OP_CLR: return (CCPrepare) { .cond =3D TCG_COND_ALWAYS }; - case CC_OP_POPCNT: - return (CCPrepare) { .cond =3D TCG_COND_EQ, .reg =3D cpu_cc_src }; default: { MemOp size =3D (s->cc_op - CC_OP_ADDB) & 3; @@ -3177,6 +3175,7 @@ static void disas_insn_old(DisasContext *s, CPUState = *cpu, int b) case CC_OP_SHLB ... CC_OP_SHLQ: case CC_OP_SARB ... CC_OP_SARQ: case CC_OP_BMILGB ... CC_OP_BMILGQ: + case CC_OP_POPCNT: /* Z was going to be computed from the non-zero status of CC_D= ST. We can get that same Z value (and the new C value) by leavi= ng CC_DST alone, setting CC_SRC, and using a CC_OP_SAR of the --=20 2.45.2 From nobody Mon Nov 25 02:08:55 2024 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=1718877343; cv=none; d=zohomail.com; s=zohoarc; b=h1MLfWL3OXC7aja7/M4g8QFhISBwU/GVCx0zhkIAg5aukpkBJxUocdW3ceCs0AxEmv5DfbGqgzvMeDLSU7fcpyX1qmfNDflTKTcfYlvkmF9ILtGlkdDbr5dNlRpIFp5ldJjlxKswqpsNO+rMKgpR955RGapgAjyv+vejKRGi3Hk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1718877343; h=Content-Type:Content-Transfer-Encoding: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:Cc; bh=qjWVlJ/40EL+HO7iRvCGlrSu0a02R43ccSAhG6j0fwE=; b=jR4rq97GsVmJwEXvPGEMj6Igyco9NXgRdj6Ay9jNXQQ0Ue+U8aw7Ftuv4O7Fj1Uj7+h+Fvpq2e/vGoxAuvPHXDA7rZ0kIYWycxYmQUK3YHZrSl/dwZhjD7zIChWfmfJiRx39cvW41XjpAWKAykVOqLvBWW+bQdO3AqnbkKMNPtY= 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 1718877343017972.0873586224117; Thu, 20 Jun 2024 02:55:43 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sKEV9-0002HY-3F; Thu, 20 Jun 2024 05:54:43 -0400 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 1sKEV6-0002H9-T1 for qemu-devel@nongnu.org; Thu, 20 Jun 2024 05:54:41 -0400 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 1sKEV4-0005Sg-56 for qemu-devel@nongnu.org; Thu, 20 Jun 2024 05:54:40 -0400 Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-132-RSm65izVOgu0zvp7QVA-SA-1; Thu, 20 Jun 2024 05:54:31 -0400 Received: by mail-ed1-f69.google.com with SMTP id 4fb4d7f45d1cf-57c5d26a27fso702322a12.1 for ; Thu, 20 Jun 2024 02:54:31 -0700 (PDT) Received: from avogadro.local ([151.62.196.71]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-57cbc4f5870sm8691652a12.4.2024.06.20.02.54.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 02:54:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718877275; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qjWVlJ/40EL+HO7iRvCGlrSu0a02R43ccSAhG6j0fwE=; b=GT+Rl8f0njJK+ad6SiiCXOjHuhpUtRy35B61HaE+E5v2ayB9rsiKz4h0FDT3nbKn3fRGDN y+fszyVCDwuRj6RD2Vp/fEc0Z9x+yNhq3DWVWYB2VOVqkZPASiI28G1em/uERFUomWZISi ZkE/SJDhyH2CMv9xICR0jceF1Mf7I30= X-MC-Unique: RSm65izVOgu0zvp7QVA-SA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718877270; x=1719482070; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qjWVlJ/40EL+HO7iRvCGlrSu0a02R43ccSAhG6j0fwE=; b=fCouPhFs+uxUvk7b3NsmAiB8kEp1qEgPPeom1qeDuRu+kGa8/9NSjAR/Tqf9QlDO/h ukOhRqAVEWBFh1JfGPQOmemax/aMWvgjXT5OZLx+ij6ezhQ4ifAuaB+JmQhiIKQcHowI lNKcfOkKWXt/g/cGE9lKJo1LsI9fBiOrpjCQFfFSYS2ZHlIqBAoP4sOj1yU8HxXqHrel dJxre8xo11kcibtOOItGMu+sbMz35hHwodJORwwWA+o4Q7KGgLZrEDd1OFVKycL+3t78 cm9M7deP8pN85sDmu+i34HKQL9iJiiBjHpPwUevvHBjsjHPogNn6/XxRZzqHdJUmeGXC qx7Q== X-Gm-Message-State: AOJu0YwqJyintXVsSn1CAZLJrd+ya5rdwnP7rsS2OTGYUVlCmDUYQr7c vNEwo/RnyRxE8aUucC2nrtk0GXNF7WF6kNsAc4S7O2dQHyPIc/bP1oDHKAWM0WSXqxzoYn2P1Fu 1cVLqWU7Gpfy8xZNYx0e+LXDAJgXwN/SuOHpipDkwvGJsff8kIQ90ORPjY91q0L23WRuPzkNme/ /pvyS5TM1z/tmFgDVTWGJbnPxB2zIHnyhBDki9 X-Received: by 2002:a50:9551:0:b0:57c:6a05:afd0 with SMTP id 4fb4d7f45d1cf-57d06ab20damr2864283a12.14.1718877269925; Thu, 20 Jun 2024 02:54:29 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFH3dOxl+c7UDai3H9X4hzWAk8O0KQd8f3CTNpLcWdpErf+r0C6/cBk+nQeSmcSCtvjVGx1aA== X-Received: by 2002:a50:9551:0:b0:57c:6a05:afd0 with SMTP id 4fb4d7f45d1cf-57d06ab20damr2864271a12.14.1718877269268; Thu, 20 Jun 2024 02:54:29 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 03/10] target/i386: convert bit test instructions to new decoder Date: Thu, 20 Jun 2024 11:54:12 +0200 Message-ID: <20240620095419.386958-4-pbonzini@redhat.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240620095419.386958-1-pbonzini@redhat.com> References: <20240620095419.386958-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: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.144, 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: 1718877344470100003 Content-Type: text/plain; charset="utf-8" Signed-off-by: Paolo Bonzini Reviewed-by: Richard Henderson --- target/i386/tcg/decode-new.h | 3 + target/i386/tcg/translate.c | 147 +----------------------------- target/i386/tcg/decode-new.c.inc | 40 ++++++--- target/i386/tcg/emit.c.inc | 149 ++++++++++++++++++++++++++++++- 4 files changed, 181 insertions(+), 158 deletions(-) diff --git a/target/i386/tcg/decode-new.h b/target/i386/tcg/decode-new.h index f9bf9a60411..e4cdf5e3c4f 100644 --- a/target/i386/tcg/decode-new.h +++ b/target/i386/tcg/decode-new.h @@ -190,6 +190,9 @@ typedef enum X86InsnSpecial { /* Always locked if it has a memory operand (XCHG) */ X86_SPECIAL_Locked, =20 + /* Like HasLock, but also operand 2 provides bit displacement into mem= ory. */ + X86_SPECIAL_BitTest, + /* Do not load effective address in s->A0 */ X86_SPECIAL_NoLoadEA, =20 diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index 934c514e64f..257110ac703 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -708,11 +708,6 @@ static TCGv gen_ext_tl(TCGv dst, TCGv src, MemOp size,= bool sign) return dst; } =20 -static void gen_exts(MemOp ot, TCGv reg) -{ - gen_ext_tl(reg, reg, ot, true); -} - static void gen_op_j_ecx(DisasContext *s, TCGCond cond, TCGLabel *label1) { TCGv tmp =3D gen_ext_tl(NULL, cpu_regs[R_ECX], s->aflag, false); @@ -2985,7 +2980,7 @@ static void disas_insn_old(DisasContext *s, CPUState = *cpu, int b) int prefixes =3D s->prefix; MemOp dflag =3D s->dflag; MemOp ot; - int modrm, reg, rm, mod, op, val; + int modrm, reg, rm, mod, op; =20 /* now check op code */ switch (b) { @@ -3051,146 +3046,6 @@ static void disas_insn_old(DisasContext *s, CPUStat= e *cpu, int b) } break; =20 - /************************/ - /* bit operations */ - case 0x1ba: /* bt/bts/btr/btc Gv, im */ - ot =3D dflag; - modrm =3D x86_ldub_code(env, s); - op =3D (modrm >> 3) & 7; - mod =3D (modrm >> 6) & 3; - rm =3D (modrm & 7) | REX_B(s); - if (mod !=3D 3) { - s->rip_offset =3D 1; - gen_lea_modrm(env, s, modrm); - if (!(s->prefix & PREFIX_LOCK)) { - gen_op_ld_v(s, ot, s->T0, s->A0); - } - } else { - gen_op_mov_v_reg(s, ot, s->T0, rm); - } - /* load shift */ - val =3D x86_ldub_code(env, s); - tcg_gen_movi_tl(s->T1, val); - if (op < 4) - goto unknown_op; - op -=3D 4; - goto bt_op; - case 0x1a3: /* bt Gv, Ev */ - op =3D 0; - goto do_btx; - case 0x1ab: /* bts */ - op =3D 1; - goto do_btx; - case 0x1b3: /* btr */ - op =3D 2; - goto do_btx; - case 0x1bb: /* btc */ - op =3D 3; - do_btx: - ot =3D dflag; - modrm =3D x86_ldub_code(env, s); - reg =3D ((modrm >> 3) & 7) | REX_R(s); - mod =3D (modrm >> 6) & 3; - rm =3D (modrm & 7) | REX_B(s); - gen_op_mov_v_reg(s, MO_32, s->T1, reg); - if (mod !=3D 3) { - AddressParts a =3D gen_lea_modrm_0(env, s, modrm); - /* specific case: we need to add a displacement */ - gen_exts(ot, s->T1); - tcg_gen_sari_tl(s->tmp0, s->T1, 3 + ot); - tcg_gen_shli_tl(s->tmp0, s->tmp0, ot); - tcg_gen_add_tl(s->A0, gen_lea_modrm_1(s, a, false), s->tmp0); - gen_lea_v_seg(s, s->A0, a.def_seg, s->override); - if (!(s->prefix & PREFIX_LOCK)) { - gen_op_ld_v(s, ot, s->T0, s->A0); - } - } else { - gen_op_mov_v_reg(s, ot, s->T0, rm); - } - bt_op: - tcg_gen_andi_tl(s->T1, s->T1, (1 << (3 + ot)) - 1); - tcg_gen_movi_tl(s->tmp0, 1); - tcg_gen_shl_tl(s->tmp0, s->tmp0, s->T1); - if (s->prefix & PREFIX_LOCK) { - switch (op) { - case 0: /* bt */ - /* Needs no atomic ops; we suppressed the normal - memory load for LOCK above so do it now. */ - gen_op_ld_v(s, ot, s->T0, s->A0); - break; - case 1: /* bts */ - tcg_gen_atomic_fetch_or_tl(s->T0, s->A0, s->tmp0, - s->mem_index, ot | MO_LE); - break; - case 2: /* btr */ - tcg_gen_not_tl(s->tmp0, s->tmp0); - tcg_gen_atomic_fetch_and_tl(s->T0, s->A0, s->tmp0, - s->mem_index, ot | MO_LE); - break; - default: - case 3: /* btc */ - tcg_gen_atomic_fetch_xor_tl(s->T0, s->A0, s->tmp0, - s->mem_index, ot | MO_LE); - break; - } - tcg_gen_shr_tl(s->tmp4, s->T0, s->T1); - } else { - tcg_gen_shr_tl(s->tmp4, s->T0, s->T1); - switch (op) { - case 0: /* bt */ - /* Data already loaded; nothing to do. */ - break; - case 1: /* bts */ - tcg_gen_or_tl(s->T0, s->T0, s->tmp0); - break; - case 2: /* btr */ - tcg_gen_andc_tl(s->T0, s->T0, s->tmp0); - break; - default: - case 3: /* btc */ - tcg_gen_xor_tl(s->T0, s->T0, s->tmp0); - break; - } - if (op !=3D 0) { - if (mod !=3D 3) { - gen_op_st_v(s, ot, s->T0, s->A0); - } else { - gen_op_mov_reg_v(s, ot, rm, s->T0); - } - } - } - - /* Delay all CC updates until after the store above. Note that - C is the result of the test, Z is unchanged, and the others - are all undefined. */ - switch (s->cc_op) { - case CC_OP_MULB ... CC_OP_MULQ: - case CC_OP_ADDB ... CC_OP_ADDQ: - case CC_OP_ADCB ... CC_OP_ADCQ: - case CC_OP_SUBB ... CC_OP_SUBQ: - case CC_OP_SBBB ... CC_OP_SBBQ: - case CC_OP_LOGICB ... CC_OP_LOGICQ: - case CC_OP_INCB ... CC_OP_INCQ: - case CC_OP_DECB ... CC_OP_DECQ: - case CC_OP_SHLB ... CC_OP_SHLQ: - case CC_OP_SARB ... CC_OP_SARQ: - case CC_OP_BMILGB ... CC_OP_BMILGQ: - case CC_OP_POPCNT: - /* Z was going to be computed from the non-zero status of CC_D= ST. - We can get that same Z value (and the new C value) by leavi= ng - CC_DST alone, setting CC_SRC, and using a CC_OP_SAR of the - same width. */ - tcg_gen_mov_tl(cpu_cc_src, s->tmp4); - set_cc_op(s, ((s->cc_op - CC_OP_MULB) & 3) + CC_OP_SARB); - break; - default: - /* Otherwise, generate EFLAGS and replace the C bit. */ - gen_compute_eflags(s); - tcg_gen_deposit_tl(cpu_cc_src, cpu_cc_src, s->tmp4, - ctz32(CC_C), 1); - break; - } - break; case 0x100: modrm =3D x86_ldub_code(env, s); mod =3D (modrm >> 6) & 3; diff --git a/target/i386/tcg/decode-new.c.inc b/target/i386/tcg/decode-new.= c.inc index 0d846c32c22..33ffcf092ec 100644 --- a/target/i386/tcg/decode-new.c.inc +++ b/target/i386/tcg/decode-new.c.inc @@ -205,6 +205,7 @@ #define sextT0 .special =3D X86_SPECIAL_SExtT0, #define zextT0 .special =3D X86_SPECIAL_ZExtT0, #define op0_Mw .special =3D X86_SPECIAL_Op0_Mw, +#define btEvGv .special =3D X86_SPECIAL_BitTest, =20 #define vex1 .vex_class =3D 1, #define vex1_rep3 .vex_class =3D 1, .vex_special =3D X86_VEX_REPScalar, @@ -269,6 +270,24 @@ static inline const X86OpEntry *decode_by_prefix(Disas= Context *s, const X86OpEnt } } =20 +static void decode_group8(DisasContext *s, CPUX86State *env, X86OpEntry *e= ntry, uint8_t *b) +{ + static const X86GenFunc group8_gen[8] =3D { + NULL, NULL, NULL, NULL, + gen_BT, gen_BTS, gen_BTR, gen_BTC, + }; + int op =3D (get_modrm(s, env) >> 3) & 7; + entry->gen =3D group8_gen[op]; + if (op =3D=3D 4) { + /* prevent writeback and LOCK for BT */ + entry->op1 =3D entry->op0; + entry->op0 =3D X86_TYPE_None; + entry->s0 =3D X86_SIZE_None; + } else { + entry->special =3D X86_SPECIAL_HasLock; + } +} + static void decode_group15(DisasContext *s, CPUX86State *env, X86OpEntry *= entry, uint8_t *b) { static const X86OpEntry group15_reg[8] =3D { @@ -1162,12 +1181,14 @@ static const X86OpEntry opcodes_0F[256] =3D { [0xa0] =3D X86_OP_ENTRYr(PUSH, FS, w), [0xa1] =3D X86_OP_ENTRYw(POP, FS, w), [0xa2] =3D X86_OP_ENTRY0(CPUID), + [0xa3] =3D X86_OP_ENTRYrr(BT, E,v, G,v, btEvGv), [0xa4] =3D X86_OP_ENTRY4(SHLD, E,v, 2op,v, G,v), [0xa5] =3D X86_OP_ENTRY3(SHLD, E,v, 2op,v, G,v), =20 [0xb0] =3D X86_OP_ENTRY2(CMPXCHG,E,b, G,b, lock), [0xb1] =3D X86_OP_ENTRY2(CMPXCHG,E,v, G,v, lock), [0xb2] =3D X86_OP_ENTRY3(LSS, G,v, EM,p, None, None), + [0xb3] =3D X86_OP_ENTRY2(BTR, E,v, G,v, btEvGv), [0xb4] =3D X86_OP_ENTRY3(LFS, G,v, EM,p, None, None), [0xb5] =3D X86_OP_ENTRY3(LGS, G,v, EM,p, None, None), [0xb6] =3D X86_OP_ENTRY3(MOV, G,v, E,b, None, None, zextT0), /* MOV= ZX */ @@ -1294,6 +1315,7 @@ static const X86OpEntry opcodes_0F[256] =3D { [0xa8] =3D X86_OP_ENTRYr(PUSH, GS, w), [0xa9] =3D X86_OP_ENTRYw(POP, GS, w), [0xaa] =3D X86_OP_ENTRY0(RSM, chk(smm) svm(RSM)), + [0xab] =3D X86_OP_ENTRY2(BTS, E,v, G,v, btEvGv), [0xac] =3D X86_OP_ENTRY4(SHRD, E,v, 2op,v, G,v), [0xad] =3D X86_OP_ENTRY3(SHRD, E,v, 2op,v, G,v), [0xae] =3D X86_OP_GROUP0(group15), @@ -1306,6 +1328,8 @@ static const X86OpEntry opcodes_0F[256] =3D { [0xb8] =3D X86_OP_GROUP0(0FB8), /* decoded as modrm, which is visible as a difference between page fau= lt and #UD */ [0xb9] =3D X86_OP_ENTRYr(UD, nop,v), /* UD1= */ + [0xba] =3D X86_OP_GROUP2(group8, E,v, I,b), + [0xbb] =3D X86_OP_ENTRY2(BTC, E,v, G,v, btEvGv), [0xbc] =3D X86_OP_GROUP0(0FBC), [0xbd] =3D X86_OP_GROUP0(0FBD), [0xbe] =3D X86_OP_ENTRY3(MOV, G,v, E,b, None, None, sextT0), /* MOV= SX */ @@ -2424,6 +2448,7 @@ static void disas_insn(DisasContext *s, CPUState *cpu) CPUX86State *env =3D cpu_env(cpu); X86DecodedInsn decode; X86DecodeFunc decode_func =3D decode_root; + bool accept_lock =3D false; uint8_t cc_live, b; =20 s->pc =3D s->base.pc_next; @@ -2597,10 +2622,6 @@ static void disas_insn(DisasContext *s, CPUState *cp= u) switch (b) { case 0x00 ... 0x01: /* mostly privileged instructions */ case 0x1a ... 0x1b: /* MPX */ - case 0xa3: /* bt */ - case 0xab: /* bts */ - case 0xb3: /* btr */ - case 0xba ... 0xbb: /* grp8, btc */ case 0xc7: /* grp9 */ disas_insn_old(s, cpu, b + 0x100); return; @@ -2662,9 +2683,10 @@ static void disas_insn(DisasContext *s, CPUState *cp= u) if (decode.op[0].has_ea) { s->prefix |=3D PREFIX_LOCK; } - decode.e.special =3D X86_SPECIAL_HasLock; /* fallthrough */ case X86_SPECIAL_HasLock: + case X86_SPECIAL_BitTest: + accept_lock =3D decode.op[0].has_ea; break; =20 case X86_SPECIAL_Op0_Rd: @@ -2706,10 +2728,8 @@ static void disas_insn(DisasContext *s, CPUState *cp= u) break; } =20 - if (s->prefix & PREFIX_LOCK) { - if (decode.e.special !=3D X86_SPECIAL_HasLock || !decode.op[0].has= _ea) { - goto illegal_op; - } + if ((s->prefix & PREFIX_LOCK) && !accept_lock) { + goto illegal_op; } =20 if (!validate_vex(s, &decode)) { @@ -2755,7 +2775,7 @@ static void disas_insn(DisasContext *s, CPUState *cpu) =20 if (decode.e.special !=3D X86_SPECIAL_NoLoadEA && (decode.op[0].has_ea || decode.op[1].has_ea || decode.op[2].has_ea= )) { - gen_load_ea(s, &decode.mem, decode.e.vex_class =3D=3D 12); + gen_load_ea(s, &decode); } if (s->prefix & PREFIX_LOCK) { gen_load(s, &decode, 2, s->T1); diff --git a/target/i386/tcg/emit.c.inc b/target/i386/tcg/emit.c.inc index fc7477833bc..a25dff0570c 100644 --- a/target/i386/tcg/emit.c.inc +++ b/target/i386/tcg/emit.c.inc @@ -73,9 +73,25 @@ static void gen_NM_exception(DisasContext *s) gen_exception(s, EXCP07_PREX); } =20 -static void gen_load_ea(DisasContext *s, AddressParts *mem, bool is_vsib) +static void gen_load_ea(DisasContext *s, X86DecodedInsn *decode) { - TCGv ea =3D gen_lea_modrm_1(s, *mem, is_vsib); + AddressParts *mem =3D &decode->mem; + TCGv ea; + + ea =3D gen_lea_modrm_1(s, *mem, decode->e.vex_class =3D=3D 12); + if (decode->e.special =3D=3D X86_SPECIAL_BitTest) { + MemOp ot =3D decode->op[1].ot; + int poslen =3D 8 << ot; + TCGv ofs =3D tcg_temp_new(); + + /* Extract memory displacement from T1. */ + assert(decode->op[2].unit =3D=3D X86_OP_INT); + tcg_gen_sextract_tl(ofs, s->T1, 3, poslen - 3); + tcg_gen_andi_tl(ofs, ofs, -1 << ot); + tcg_gen_add_tl(s->A0, ea, ofs); + ea =3D s->A0; + } + gen_lea_v_seg(s, ea, mem->def_seg, s->override); } =20 @@ -407,6 +423,32 @@ static void prepare_update3_cc(X86DecodedInsn *decode,= DisasContext *s, CCOp op, decode->cc_op =3D op; } =20 +/* Set up decode->cc_* to modify CF while keeping other flags unchanged. = */ +static void prepare_update_cf(X86DecodedInsn *decode, DisasContext *s, TCG= v cf) +{ + switch (s->cc_op) { + case CC_OP_ADOX: + case CC_OP_ADCOX: + decode->cc_src2 =3D cpu_cc_src2; + decode->cc_src =3D cpu_cc_src; + decode->cc_op =3D CC_OP_ADCOX; + break; + + case CC_OP_EFLAGS: + case CC_OP_ADCX: + decode->cc_src =3D cpu_cc_src; + decode->cc_op =3D CC_OP_ADCX; + break; + + default: + decode->cc_src =3D tcg_temp_new(); + gen_mov_eflags(s, decode->cc_src); + decode->cc_op =3D CC_OP_ADCX; + break; + } + decode->cc_dst =3D cf; +} + static void gen_store_sse(DisasContext *s, X86DecodedInsn *decode, int src= _ofs) { MemOp ot =3D decode->op[0].ot; @@ -1385,6 +1427,109 @@ static void gen_BSWAP(DisasContext *s, X86DecodedIn= sn *decode) tcg_gen_bswap32_tl(s->T0, s->T0, TCG_BSWAP_OZ); } =20 +static TCGv gen_bt_mask(DisasContext *s, X86DecodedInsn *decode) +{ + MemOp ot =3D decode->op[1].ot; + TCGv mask =3D tcg_temp_new(); + + tcg_gen_andi_tl(s->T1, s->T1, (8 << ot) - 1); + tcg_gen_shl_tl(mask, tcg_constant_tl(1), s->T1); + return mask; +} + +/* Expects truncated bit index in s->T1, 1 << s->T1 in MASK. */ +static void gen_bt_flags(DisasContext *s, X86DecodedInsn *decode, TCGv src= , TCGv mask) +{ + TCGv cf; + + /* + * C is the result of the test, Z is unchanged, and the others + * are all undefined. + */ + switch (s->cc_op) { + case CC_OP_DYNAMIC: + case CC_OP_CLR: + case CC_OP_EFLAGS: + case CC_OP_ADCX: + case CC_OP_ADOX: + case CC_OP_ADCOX: + /* Generate EFLAGS and replace the C bit. */ + cf =3D tcg_temp_new(); + tcg_gen_setcond_tl(TCG_COND_TSTNE, cf, src, mask); + prepare_update_cf(decode, s, cf); + break; + default: + /* + * Z was going to be computed from the non-zero status of CC_DST. + * We can get that same Z value (and the new C value) by leaving + * CC_DST alone, setting CC_SRC, and using a CC_OP_SAR of the + * same width. + */ + decode->cc_src =3D tcg_temp_new(); + decode->cc_dst =3D cpu_cc_dst; + decode->cc_op =3D ((s->cc_op - CC_OP_MULB) & 3) + CC_OP_SARB; + tcg_gen_shr_tl(decode->cc_src, src, s->T1); + break; + } +} + +static void gen_BT(DisasContext *s, X86DecodedInsn *decode) +{ + TCGv mask =3D gen_bt_mask(s, decode); + + gen_bt_flags(s, decode, s->T0, mask); +} + +static void gen_BTC(DisasContext *s, X86DecodedInsn *decode) +{ + MemOp ot =3D decode->op[0].ot; + TCGv old =3D tcg_temp_new(); + TCGv mask =3D gen_bt_mask(s, decode); + + if (s->prefix & PREFIX_LOCK) { + tcg_gen_atomic_fetch_xor_tl(old, s->A0, mask, s->mem_index, ot | M= O_LE); + } else { + tcg_gen_mov_tl(old, s->T0); + tcg_gen_xor_tl(s->T0, s->T0, mask); + } + + gen_bt_flags(s, decode, old, mask); +} + +static void gen_BTR(DisasContext *s, X86DecodedInsn *decode) +{ + MemOp ot =3D decode->op[0].ot; + TCGv old =3D tcg_temp_new(); + TCGv mask =3D gen_bt_mask(s, decode); + + if (s->prefix & PREFIX_LOCK) { + TCGv maskc =3D tcg_temp_new(); + tcg_gen_not_tl(maskc, mask); + tcg_gen_atomic_fetch_and_tl(old, s->A0, maskc, s->mem_index, ot | = MO_LE); + } else { + tcg_gen_mov_tl(old, s->T0); + tcg_gen_andc_tl(s->T0, s->T0, mask); + } + + gen_bt_flags(s, decode, old, mask); +} + +static void gen_BTS(DisasContext *s, X86DecodedInsn *decode) +{ + MemOp ot =3D decode->op[0].ot; + TCGv old =3D tcg_temp_new(); + TCGv mask =3D gen_bt_mask(s, decode); + + if (s->prefix & PREFIX_LOCK) { + tcg_gen_atomic_fetch_or_tl(old, s->A0, mask, s->mem_index, ot | MO= _LE); + } else { + tcg_gen_mov_tl(old, s->T0); + tcg_gen_or_tl(s->T0, s->T0, mask); + } + + gen_bt_flags(s, decode, old, mask); +} + static void gen_BZHI(DisasContext *s, X86DecodedInsn *decode) { MemOp ot =3D decode->op[0].ot; --=20 2.45.2 From nobody Mon Nov 25 02:08:55 2024 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=1718877395; cv=none; d=zohomail.com; s=zohoarc; b=f5NfLdgr83sV0DYt/dNagyL2LtLRO5heBhYzfcquF32rdTcRNlnZFOsPKqoZKwBXGVIxSLEaH5iK4/J191dwSbx9FNwEAKs6MF3jaoNGyyMa1icIjR1H1uNVUQpILvoorEt+yS7Y8UMygEkAEV7667Qq8celsSGAMRHMdK0mFHA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1718877395; h=Content-Type:Content-Transfer-Encoding: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:Cc; bh=KpqPUZHJaPcbpRvk9vYmCA3tW3K6p5mawsrXblCt/Jg=; b=T0//dfRptSoXERTJQgM5YicAlx9nY8TlJUhGA7mgoaGOKJT22PLnOsk+Ee1l1mu4mqqPLe1GKQ08pBA3OTKF1hW3cPu9/8rjW84QM3l0qQz2dyCrOb+JOaZsVLkDsouDPsdbhDWC7ZGRGKxubEcMGLDsKdmwtb8AXhHE+shsKh0= 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 1718877395387236.33949469772938; Thu, 20 Jun 2024 02:56:35 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sKEV7-0002HK-Kk; Thu, 20 Jun 2024 05:54:41 -0400 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 1sKEV6-0002Go-0E for qemu-devel@nongnu.org; Thu, 20 Jun 2024 05:54:40 -0400 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 1sKEV4-0005Sj-5A for qemu-devel@nongnu.org; Thu, 20 Jun 2024 05:54:39 -0400 Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-230-OtgRw4EhM5Chea4y37aKeQ-1; Thu, 20 Jun 2024 05:54:34 -0400 Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-a6f3f614e58so37533366b.0 for ; Thu, 20 Jun 2024 02:54:34 -0700 (PDT) Received: from avogadro.local ([151.62.196.71]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a6f56ecdd63sm749927766b.124.2024.06.20.02.54.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 02:54:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718877276; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KpqPUZHJaPcbpRvk9vYmCA3tW3K6p5mawsrXblCt/Jg=; b=K2jP4sNK+QilY1QGFXOlsjwYXSKRcmEidZehjaz8XCHHEu8DGChO0DK7psdw7lEMWR9Mds MjXBmDgaeeT/U/BUdCnjzKzpSlnn7qyFBqlBrchCYGe1t6h0WZsNMmgq2/gheNd+EKglql lPXnSgtdvK5BVCanhQ90kZFislb/Cms= X-MC-Unique: OtgRw4EhM5Chea4y37aKeQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718877273; x=1719482073; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KpqPUZHJaPcbpRvk9vYmCA3tW3K6p5mawsrXblCt/Jg=; b=RRIOg+hwAB9vmZvk1j/tvcIVJTxl7llgP0UvrduhuzlT9sNIaMwxh9qwcbGLP9EWIZ v68T6Z5/aLdAIp2Js5LsectTYhos1Xwt4AnahXBSXFkOyf9zPkul+HQp6WVpCWxfKXO6 1erQZAhNQKPUM5dG1f3npQK7irZN99yZzBAHc3DE/Tu0aApk1lmRBtPnGbYJoOdZULSF MATvAYeYAqqCo20oohLxs8iYo7WtIw1a3z941/MkfbvWM8knaQr2fQuq0555GEph9sxz QFUHtx0Eg0zpkK78u9+/9JMShX9ONuIxqc8cWL+BoR9CpG2TBtti3fq9DcHEhcBYYVc7 2NwA== X-Gm-Message-State: AOJu0YyL2f8tPjqCsTxLMigcwaxsa9YeunC+3eWqjNAH9CsSH9fHuU/M VCYiPy7j14rtGSa/oB89LuTGL/25stcP82UieXqYxRQxfltH32p98eGVjOyiOMAcWKVmmYNf00n rnJzfDsm5tHjVzjpQ9IxP6akvVnZ9ive4boLNPeWog31mAjL7FSRWEJGxsJgtwaGkfoFzCk6+Yx rbXEPY0rDiBOmn4OJt1OlgJq1cGMwcmUXu84ob X-Received: by 2002:a17:907:ca1b:b0:a63:49d3:e1c5 with SMTP id a640c23a62f3a-a6fab7d6a8emr274208966b.64.1718877272938; Thu, 20 Jun 2024 02:54:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHnPa8kWYdxzlFcIF8xzlOsiOrWS0SvnAB7KORyD1+Nq8cVMqjtwkBlgW+ZQYqQaSRggZdxAQ== X-Received: by 2002:a17:907:ca1b:b0:a63:49d3:e1c5 with SMTP id a640c23a62f3a-a6fab7d6a8emr274207566b.64.1718877272442; Thu, 20 Jun 2024 02:54:32 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 04/10] target/i386: try not to force EFLAGS computation for CC_OP_ADOX/ADCX Date: Thu, 20 Jun 2024 11:54:13 +0200 Message-ID: <20240620095419.386958-5-pbonzini@redhat.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240620095419.386958-1-pbonzini@redhat.com> References: <20240620095419.386958-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: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.144, 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: 1718877396609100001 Content-Type: text/plain; charset="utf-8" When computing the "other" flag (CF for CC_OP_ADOX, OF for CC_OP_ADCX), take into account that it is already in the right position of cpu_cc_src, just like for CC_OP_EFLAGS. There is no need to call gen_compute_eflags(). Signed-off-by: Paolo Bonzini Reviewed-by: Richard Henderson --- target/i386/tcg/translate.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index 257110ac703..08db40681fa 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -928,6 +928,7 @@ static CCPrepare gen_prepare_eflags_c(DisasContext *s, = TCGv reg) .no_setcond =3D true }; =20 case CC_OP_EFLAGS: + case CC_OP_ADOX: case CC_OP_SARB ... CC_OP_SARQ: /* CC_SRC & 1 */ return (CCPrepare) { .cond =3D TCG_COND_TSTNE, @@ -994,6 +995,9 @@ static CCPrepare gen_prepare_eflags_o(DisasContext *s, = TCGv reg) return (CCPrepare) { .cond =3D TCG_COND_NE, .reg =3D cpu_cc_src }; default: gen_compute_eflags(s); + /* fallthrough */ + case CC_OP_EFLAGS: + case CC_OP_ADCX: return (CCPrepare) { .cond =3D TCG_COND_TSTNE, .reg =3D cpu_cc_src, .imm =3D CC_O }; } --=20 2.45.2 From nobody Mon Nov 25 02:08:55 2024 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=1718877446; cv=none; d=zohomail.com; s=zohoarc; b=QEHt1aknfdcuf68AG7x0esDKok1P+9bo7V+998RtJUysGp1j0aSvRq4YS08IcuYYxnPNJFUhcc9pHPxZW3wENJUk9dc7kMf9g9achTJvOm/T7VCd+PL622ey/vKVK6qYp99jVBWpXUzMz9WTl9Pzx86uNFckCdLpc6voi2Xioc8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1718877446; h=Content-Type: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=OtBqhhd2Tl8yeJJhVmC0tA4DyBk4avu2gh8sHJfHAKM=; b=HQHw4rOUdGAlHwNPmJICe04nsZ/kbkKJTMVGkdqrAFxJ7Ie++pVXb6iPD4ZyF0/aJpcWGv+goVOXJDnvgqkmw+lFJL3pkj9ElRbJJWZpsoW6kuPBo6zbkflvtityZWKxQ9pukfytjQxKywyOJMRcFiXa96NXW9nUk+GQSV7y2E4= 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 1718877446556389.62534185776553; Thu, 20 Jun 2024 02:57:26 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sKEVD-0002MD-5T; Thu, 20 Jun 2024 05:54:47 -0400 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 1sKEVA-0002Jx-8E for qemu-devel@nongnu.org; Thu, 20 Jun 2024 05:54:44 -0400 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 1sKEV7-0005T8-B6 for qemu-devel@nongnu.org; Thu, 20 Jun 2024 05:54:43 -0400 Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-340-abPzeousNBytow8LN7Vnfw-1; Thu, 20 Jun 2024 05:54:38 -0400 Received: by mail-ed1-f70.google.com with SMTP id 4fb4d7f45d1cf-57cda58672eso369598a12.1 for ; Thu, 20 Jun 2024 02:54:37 -0700 (PDT) Received: from avogadro.local ([151.62.196.71]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-57d1e4e5348sm896969a12.80.2024.06.20.02.54.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 02:54:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718877280; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OtBqhhd2Tl8yeJJhVmC0tA4DyBk4avu2gh8sHJfHAKM=; b=NCk9aZXmdAIqsByTLN/nLnPSXtzQ1rFSc3z03yMODbTHyW/ID/37k1+gwTd0r6LOFOxkwg 1zjDI7i9Az7m4Mk15TJa3+K2ht6y4j9OC8/kaxgidCh3KK0CE9XdRT1ZBR/ny5/pebFQ1i 1oW/4fSfUWjbK3t3BXkMCJpnsdgQ4yE= X-MC-Unique: abPzeousNBytow8LN7Vnfw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718877276; x=1719482076; 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=OtBqhhd2Tl8yeJJhVmC0tA4DyBk4avu2gh8sHJfHAKM=; b=o2KEaf7ZUyTsPUQz6nfi2Oh/2BBgi9vWhCq7MMI0lUd/OWv0T30M6WlXn2nBIJAnf9 QTSKgePhfZBKRoLdtuiLZYHpJsKHsqJH62Lr5oEN5gb8oV/Na0feHepZ0L983FNfDU/G +toZslNbol3pW8/qlk/ZFNCZ+nA+ZeIswsfFLQwB0LB3vNYpRfuPJPsyWn50Nr5S6PM2 A730snelW35C3ojQg5Ai0wufpuU6OltDim9HIVTwW5PlcsZPAr7+S+Aje7AzyBWj3GU3 nhUCERAoJR3gkX244d6KU3WQul7h12teuW6ajc5BVqm/EHYWu0AoS67T5bgMvgffKn21 GhoA== X-Gm-Message-State: AOJu0YwwWXBD3y1v15Zgx3TTu/s+pUNy4rbvX1ZSnBlKkdIAC71rNiiG 0tY+/ooog2CxGIe7KuoXgLP0PK3jXJ3ATK0uPof4FC3rtb0cIJsTWt6FAwjpepG1wm2FOyt5Z/C lhpFNs2yaDxf2fTXiEieh2Ag5lN2Lv45Z1raX6PPuaH+2ebMh5qK6wpszPPIvijg1NwtFHrq2wP YCLbTlP8c6CIZ3s05bOm1N5ogxq7vVQFVsc9DE X-Received: by 2002:a50:cc93:0:b0:57c:c712:a3c7 with SMTP id 4fb4d7f45d1cf-57d07ee6e85mr2917823a12.36.1718877275767; Thu, 20 Jun 2024 02:54:35 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGZTVdp7EDyHKEdoVsQy5stamWPmbMxNbWR5yganNv2dmL6fPZ71scaEKw7rFG0SXHjfMgdLg== X-Received: by 2002:a50:cc93:0:b0:57c:c712:a3c7 with SMTP id 4fb4d7f45d1cf-57d07ee6e85mr2917805a12.36.1718877275106; Thu, 20 Jun 2024 02:54:35 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Richard Henderson Subject: [PATCH 05/10] target/i386: decode address before going back to translate.c Date: Thu, 20 Jun 2024 11:54:14 +0200 Message-ID: <20240620095419.386958-6-pbonzini@redhat.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240620095419.386958-1-pbonzini@redhat.com> References: <20240620095419.386958-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: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.144, 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: 1718877446919100001 Content-Type: text/plain; charset="utf-8" There are now relatively few unconverted opcodes in translate.c (there are 13 of them including 8 for x87), and all of them have the same format with a mod/rm byte and no immediate. A good next step is to remove the early bail out to disas_insn_x87/disas_insn_old, instead giving these legacy translator functions the same prototype as the other gen_* functions. To do this, the X86DecodeInsn can be passed down to the places that used to fetch address bytes from the instruction stream. To make sure that everything is done cleanly, the CPUX86State* argument is removed. As part of the unification, the gen_lea_modrm() name is now free, so rename gen_load_ea() to gen_lea_modrm(). This is as good a name and it makes the changes to translate.c easier to review. Reviewed-by: Richard Henderson Signed-off-by: Paolo Bonzini --- target/i386/tcg/decode-new.h | 14 ++- target/i386/tcg/translate.c | 152 +++++++++++++------------------ target/i386/tcg/decode-new.c.inc | 53 ++++++----- target/i386/tcg/emit.c.inc | 2 +- 4 files changed, 103 insertions(+), 118 deletions(-) diff --git a/target/i386/tcg/decode-new.h b/target/i386/tcg/decode-new.h index e4cdf5e3c4f..bebc77bd54b 100644 --- a/target/i386/tcg/decode-new.h +++ b/target/i386/tcg/decode-new.h @@ -264,12 +264,13 @@ typedef enum X86VEXSpecial { =20 typedef struct X86OpEntry X86OpEntry; typedef struct X86DecodedInsn X86DecodedInsn; +struct DisasContext; =20 /* Decode function for multibyte opcodes. */ -typedef void (*X86DecodeFunc)(DisasContext *s, CPUX86State *env, X86OpEntr= y *entry, uint8_t *b); +typedef void (*X86DecodeFunc)(struct DisasContext *s, CPUX86State *env, X8= 6OpEntry *entry, uint8_t *b); =20 /* Code generation function. */ -typedef void (*X86GenFunc)(DisasContext *s, X86DecodedInsn *decode); +typedef void (*X86GenFunc)(struct DisasContext *s, X86DecodedInsn *decode); =20 struct X86OpEntry { /* Based on the is_decode flags. */ @@ -316,6 +317,14 @@ typedef struct X86DecodedOp { }; } X86DecodedOp; =20 +typedef struct AddressParts { + int def_seg; + int base; + int index; + int scale; + target_long disp; +} AddressParts; + struct X86DecodedInsn { X86OpEntry e; X86DecodedOp op[3]; @@ -333,3 +342,4 @@ struct X86DecodedInsn { uint8_t b; }; =20 +static void gen_lea_modrm(struct DisasContext *s, X86DecodedInsn *decode); diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index 08db40681fa..1d845ff66bb 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -29,6 +29,7 @@ #include "exec/helper-proto.h" #include "exec/helper-gen.h" #include "helper-tcg.h" +#include "decode-new.h" =20 #include "exec/log.h" =20 @@ -1529,14 +1530,6 @@ static inline uint64_t x86_ldq_code(CPUX86State *env= , DisasContext *s) =20 /* Decompose an address. */ =20 -typedef struct AddressParts { - int def_seg; - int base; - int index; - int scale; - target_long disp; -} AddressParts; - static AddressParts gen_lea_modrm_0(CPUX86State *env, DisasContext *s, int modrm) { @@ -1695,24 +1688,11 @@ static TCGv gen_lea_modrm_1(DisasContext *s, Addres= sParts a, bool is_vsib) return ea; } =20 -static void gen_lea_modrm(CPUX86State *env, DisasContext *s, int modrm) -{ - AddressParts a =3D gen_lea_modrm_0(env, s, modrm); - TCGv ea =3D gen_lea_modrm_1(s, a, false); - gen_lea_v_seg(s, ea, a.def_seg, s->override); -} - -static void gen_nop_modrm(CPUX86State *env, DisasContext *s, int modrm) -{ - (void)gen_lea_modrm_0(env, s, modrm); -} - /* Used for BNDCL, BNDCU, BNDCN. */ -static void gen_bndck(CPUX86State *env, DisasContext *s, int modrm, +static void gen_bndck(DisasContext *s, X86DecodedInsn *decode, TCGCond cond, TCGv_i64 bndv) { - AddressParts a =3D gen_lea_modrm_0(env, s, modrm); - TCGv ea =3D gen_lea_modrm_1(s, a, false); + TCGv ea =3D gen_lea_modrm_1(s, decode->mem, false); =20 tcg_gen_extu_tl_i64(s->tmp1_i64, ea); if (!CODE64(s)) { @@ -1724,8 +1704,9 @@ static void gen_bndck(CPUX86State *env, DisasContext = *s, int modrm, } =20 /* generate modrm load of memory or register. */ -static void gen_ld_modrm(CPUX86State *env, DisasContext *s, int modrm, Mem= Op ot) +static void gen_ld_modrm(DisasContext *s, X86DecodedInsn *decode, MemOp ot) { + int modrm =3D s->modrm; int mod, rm; =20 mod =3D (modrm >> 6) & 3; @@ -1733,14 +1714,15 @@ static void gen_ld_modrm(CPUX86State *env, DisasCon= text *s, int modrm, MemOp ot) if (mod =3D=3D 3) { gen_op_mov_v_reg(s, ot, s->T0, rm); } else { - gen_lea_modrm(env, s, modrm); + gen_lea_modrm(s, decode); gen_op_ld_v(s, ot, s->T0, s->A0); } } =20 /* generate modrm store of memory or register. */ -static void gen_st_modrm(CPUX86State *env, DisasContext *s, int modrm, Mem= Op ot) +static void gen_st_modrm(DisasContext *s, X86DecodedInsn *decode, MemOp ot) { + int modrm =3D s->modrm; int mod, rm; =20 mod =3D (modrm >> 6) & 3; @@ -1748,7 +1730,7 @@ static void gen_st_modrm(CPUX86State *env, DisasConte= xt *s, int modrm, MemOp ot) if (mod =3D=3D 3) { gen_op_mov_reg_v(s, ot, rm, s->T0); } else { - gen_lea_modrm(env, s, modrm); + gen_lea_modrm(s, decode); gen_op_st_v(s, ot, s->T0, s->A0); } } @@ -2316,12 +2298,12 @@ static void gen_sty_env_A0(DisasContext *s, int off= set, bool align) tcg_gen_qemu_st_i128(t, s->tmp0, mem_index, mop); } =20 -static void gen_cmpxchg8b(DisasContext *s, CPUX86State *env, int modrm) +static void gen_cmpxchg8b(DisasContext *s, X86DecodedInsn *decode) { TCGv_i64 cmp, val, old; TCGv Z; =20 - gen_lea_modrm(env, s, modrm); + gen_lea_modrm(s, decode); =20 cmp =3D tcg_temp_new_i64(); val =3D tcg_temp_new_i64(); @@ -2370,13 +2352,13 @@ static void gen_cmpxchg8b(DisasContext *s, CPUX86St= ate *env, int modrm) } =20 #ifdef TARGET_X86_64 -static void gen_cmpxchg16b(DisasContext *s, CPUX86State *env, int modrm) +static void gen_cmpxchg16b(DisasContext *s, X86DecodedInsn *decode) { MemOp mop =3D MO_TE | MO_128 | MO_ALIGN; TCGv_i64 t0, t1; TCGv_i128 cmp, val; =20 - gen_lea_modrm(env, s, modrm); + gen_lea_modrm(s, decode); =20 cmp =3D tcg_temp_new_i128(); val =3D tcg_temp_new_i128(); @@ -2414,31 +2396,32 @@ static void gen_cmpxchg16b(DisasContext *s, CPUX86S= tate *env, int modrm) } #endif =20 -static bool disas_insn_x87(DisasContext *s, CPUState *cpu, int b) +#include "emit.c.inc" + +static void gen_x87(DisasContext *s, X86DecodedInsn *decode) { - CPUX86State *env =3D cpu_env(cpu); bool update_fip =3D true; - int modrm, mod, rm, op; + int b =3D decode->b; + int modrm =3D s->modrm; + int mod, rm, op; =20 if (s->flags & (HF_EM_MASK | HF_TS_MASK)) { /* if CR0.EM or CR0.TS are set, generate an FPU exception */ /* XXX: what to do if illegal op ? */ gen_exception(s, EXCP07_PREX); - return true; + return; } - modrm =3D x86_ldub_code(env, s); mod =3D (modrm >> 6) & 3; rm =3D modrm & 7; op =3D ((b & 7) << 3) | ((modrm >> 3) & 7); if (mod !=3D 3) { /* memory op */ - AddressParts a =3D gen_lea_modrm_0(env, s, modrm); - TCGv ea =3D gen_lea_modrm_1(s, a, false); + TCGv ea =3D gen_lea_modrm_1(s, decode->mem, false); TCGv last_addr =3D tcg_temp_new(); bool update_fdp =3D true; =20 tcg_gen_mov_tl(last_addr, ea); - gen_lea_v_seg(s, ea, a.def_seg, s->override); + gen_lea_v_seg(s, ea, decode->mem.def_seg, s->override); =20 switch (op) { case 0x00 ... 0x07: /* fxxxs */ @@ -2628,11 +2611,11 @@ static bool disas_insn_x87(DisasContext *s, CPUStat= e *cpu, int b) gen_helper_fpop(tcg_env); break; default: - return false; + goto illegal_op; } =20 if (update_fdp) { - int last_seg =3D s->override >=3D 0 ? s->override : a.def_seg; + int last_seg =3D s->override >=3D 0 ? s->override : decode->me= m.def_seg; =20 tcg_gen_ld_i32(s->tmp2_i32, tcg_env, offsetof(CPUX86State, @@ -2669,7 +2652,7 @@ static bool disas_insn_x87(DisasContext *s, CPUState = *cpu, int b) update_fip =3D false; break; default: - return false; + goto illegal_op; } break; case 0x0c: /* grp d9/4 */ @@ -2688,7 +2671,7 @@ static bool disas_insn_x87(DisasContext *s, CPUState = *cpu, int b) gen_helper_fxam_ST0(tcg_env); break; default: - return false; + goto illegal_op; } break; case 0x0d: /* grp d9/5 */ @@ -2723,7 +2706,7 @@ static bool disas_insn_x87(DisasContext *s, CPUState = *cpu, int b) gen_helper_fldz_ST0(tcg_env); break; default: - return false; + goto illegal_op; } } break; @@ -2825,7 +2808,7 @@ static bool disas_insn_x87(DisasContext *s, CPUState = *cpu, int b) gen_helper_fpop(tcg_env); break; default: - return false; + goto illegal_op; } break; case 0x1c: @@ -2845,7 +2828,7 @@ static bool disas_insn_x87(DisasContext *s, CPUState = *cpu, int b) case 4: /* fsetpm (287 only, just do nop here) */ break; default: - return false; + goto illegal_op; } break; case 0x1d: /* fucomi */ @@ -2897,7 +2880,7 @@ static bool disas_insn_x87(DisasContext *s, CPUState = *cpu, int b) gen_helper_fpop(tcg_env); break; default: - return false; + goto illegal_op; } break; case 0x38: /* ffreep sti, undocumented op */ @@ -2912,7 +2895,7 @@ static bool disas_insn_x87(DisasContext *s, CPUState = *cpu, int b) gen_op_mov_reg_v(s, MO_16, R_EAX, s->T0); break; default: - return false; + goto illegal_op; } break; case 0x3d: /* fucomip */ @@ -2959,7 +2942,7 @@ static bool disas_insn_x87(DisasContext *s, CPUState = *cpu, int b) } break; default: - return false; + goto illegal_op; } } =20 @@ -2971,25 +2954,24 @@ static bool disas_insn_x87(DisasContext *s, CPUStat= e *cpu, int b) tcg_gen_st_tl(eip_cur_tl(s), tcg_env, offsetof(CPUX86State, fpip)); } - return true; + return; =20 illegal_op: gen_illegal_opcode(s); - return true; } =20 -static void disas_insn_old(DisasContext *s, CPUState *cpu, int b) +static void gen_multi0F(DisasContext *s, X86DecodedInsn *decode) { - CPUX86State *env =3D cpu_env(cpu); int prefixes =3D s->prefix; MemOp dflag =3D s->dflag; + int b =3D decode->b + 0x100; + int modrm =3D s->modrm; MemOp ot; - int modrm, reg, rm, mod, op; + int reg, rm, mod, op; =20 /* now check op code */ switch (b) { case 0x1c7: /* cmpxchg8b */ - modrm =3D x86_ldub_code(env, s); mod =3D (modrm >> 6) & 3; switch ((modrm >> 3) & 7) { case 1: /* CMPXCHG8, CMPXCHG16 */ @@ -3001,14 +2983,14 @@ static void disas_insn_old(DisasContext *s, CPUStat= e *cpu, int b) if (!(s->cpuid_ext_features & CPUID_EXT_CX16)) { goto illegal_op; } - gen_cmpxchg16b(s, env, modrm); + gen_cmpxchg16b(s, decode); break; } #endif if (!(s->cpuid_features & CPUID_CX8)) { goto illegal_op; } - gen_cmpxchg8b(s, env, modrm); + gen_cmpxchg8b(s, decode); break; =20 case 7: /* RDSEED, RDPID with f3 prefix */ @@ -3051,7 +3033,6 @@ static void disas_insn_old(DisasContext *s, CPUState = *cpu, int b) break; =20 case 0x100: - modrm =3D x86_ldub_code(env, s); mod =3D (modrm >> 6) & 3; op =3D (modrm >> 3) & 7; switch(op) { @@ -3065,14 +3046,14 @@ static void disas_insn_old(DisasContext *s, CPUStat= e *cpu, int b) tcg_gen_ld32u_tl(s->T0, tcg_env, offsetof(CPUX86State, ldt.selector)); ot =3D mod =3D=3D 3 ? dflag : MO_16; - gen_st_modrm(env, s, modrm, ot); + gen_st_modrm(s, decode, ot); break; case 2: /* lldt */ if (!PE(s) || VM86(s)) goto illegal_op; if (check_cpl0(s)) { gen_svm_check_intercept(s, SVM_EXIT_LDTR_WRITE); - gen_ld_modrm(env, s, modrm, MO_16); + gen_ld_modrm(s, decode, MO_16); tcg_gen_trunc_tl_i32(s->tmp2_i32, s->T0); gen_helper_lldt(tcg_env, s->tmp2_i32); } @@ -3087,14 +3068,14 @@ static void disas_insn_old(DisasContext *s, CPUStat= e *cpu, int b) tcg_gen_ld32u_tl(s->T0, tcg_env, offsetof(CPUX86State, tr.selector)); ot =3D mod =3D=3D 3 ? dflag : MO_16; - gen_st_modrm(env, s, modrm, ot); + gen_st_modrm(s, decode, ot); break; case 3: /* ltr */ if (!PE(s) || VM86(s)) goto illegal_op; if (check_cpl0(s)) { gen_svm_check_intercept(s, SVM_EXIT_TR_WRITE); - gen_ld_modrm(env, s, modrm, MO_16); + gen_ld_modrm(s, decode, MO_16); tcg_gen_trunc_tl_i32(s->tmp2_i32, s->T0); gen_helper_ltr(tcg_env, s->tmp2_i32); } @@ -3103,7 +3084,7 @@ static void disas_insn_old(DisasContext *s, CPUState = *cpu, int b) case 5: /* verw */ if (!PE(s) || VM86(s)) goto illegal_op; - gen_ld_modrm(env, s, modrm, MO_16); + gen_ld_modrm(s, decode, MO_16); gen_update_cc_op(s); if (op =3D=3D 4) { gen_helper_verr(tcg_env, s->T0); @@ -3113,19 +3094,18 @@ static void disas_insn_old(DisasContext *s, CPUStat= e *cpu, int b) assume_cc_op(s, CC_OP_EFLAGS); break; default: - goto unknown_op; + goto illegal_op; } break; =20 case 0x101: - modrm =3D x86_ldub_code(env, s); switch (modrm) { CASE_MODRM_MEM_OP(0): /* sgdt */ if (s->flags & HF_UMIP_MASK && !check_cpl0(s)) { break; } gen_svm_check_intercept(s, SVM_EXIT_GDTR_READ); - gen_lea_modrm(env, s, modrm); + gen_lea_modrm(s, decode); tcg_gen_ld32u_tl(s->T0, tcg_env, offsetof(CPUX86State, gdt.limit)); gen_op_st_v(s, MO_16, s->T0, s->A0); @@ -3181,7 +3161,7 @@ static void disas_insn_old(DisasContext *s, CPUState = *cpu, int b) break; } gen_svm_check_intercept(s, SVM_EXIT_IDTR_READ); - gen_lea_modrm(env, s, modrm); + gen_lea_modrm(s, decode); tcg_gen_ld32u_tl(s->T0, tcg_env, offsetof(CPUX86State, idt.lim= it)); gen_op_st_v(s, MO_16, s->T0, s->A0); gen_add_A0_im(s, 2); @@ -3331,7 +3311,7 @@ static void disas_insn_old(DisasContext *s, CPUState = *cpu, int b) break; } gen_svm_check_intercept(s, SVM_EXIT_GDTR_WRITE); - gen_lea_modrm(env, s, modrm); + gen_lea_modrm(s, decode); gen_op_ld_v(s, MO_16, s->T1, s->A0); gen_add_A0_im(s, 2); gen_op_ld_v(s, CODE64(s) + MO_32, s->T0, s->A0); @@ -3347,7 +3327,7 @@ static void disas_insn_old(DisasContext *s, CPUState = *cpu, int b) break; } gen_svm_check_intercept(s, SVM_EXIT_IDTR_WRITE); - gen_lea_modrm(env, s, modrm); + gen_lea_modrm(s, decode); gen_op_ld_v(s, MO_16, s->T1, s->A0); gen_add_A0_im(s, 2); gen_op_ld_v(s, CODE64(s) + MO_32, s->T0, s->A0); @@ -3371,7 +3351,7 @@ static void disas_insn_old(DisasContext *s, CPUState = *cpu, int b) */ mod =3D (modrm >> 6) & 3; ot =3D (mod !=3D 3 ? MO_16 : s->dflag); - gen_st_modrm(env, s, modrm, ot); + gen_st_modrm(s, decode, ot); break; case 0xee: /* rdpkru */ if (s->prefix & (PREFIX_LOCK | PREFIX_DATA @@ -3398,7 +3378,7 @@ static void disas_insn_old(DisasContext *s, CPUState = *cpu, int b) break; } gen_svm_check_intercept(s, SVM_EXIT_WRITE_CR0); - gen_ld_modrm(env, s, modrm, MO_16); + gen_ld_modrm(s, decode, MO_16); /* * Only the 4 lower bits of CR0 are modified. * PE cannot be set to zero if already set to one. @@ -3416,7 +3396,7 @@ static void disas_insn_old(DisasContext *s, CPUState = *cpu, int b) break; } gen_svm_check_intercept(s, SVM_EXIT_INVLPG); - gen_lea_modrm(env, s, modrm); + gen_lea_modrm(s, decode); gen_helper_flush_page(tcg_env, s->A0); s->base.is_jmp =3D DISAS_EOB_NEXT; break; @@ -3449,12 +3429,11 @@ static void disas_insn_old(DisasContext *s, CPUStat= e *cpu, int b) break; =20 default: - goto unknown_op; + goto illegal_op; } break; =20 case 0x11a: - modrm =3D x86_ldub_code(env, s); if (s->flags & HF_MPX_EN_MASK) { mod =3D (modrm >> 6) & 3; reg =3D ((modrm >> 3) & 7) | REX_R(s); @@ -3465,7 +3444,7 @@ static void disas_insn_old(DisasContext *s, CPUState = *cpu, int b) || s->aflag =3D=3D MO_16) { goto illegal_op; } - gen_bndck(env, s, modrm, TCG_COND_LTU, cpu_bndl[reg]); + gen_bndck(s, decode, TCG_COND_LTU, cpu_bndl[reg]); } else if (prefixes & PREFIX_REPNZ) { /* bndcu */ if (reg >=3D 4 @@ -3475,7 +3454,7 @@ static void disas_insn_old(DisasContext *s, CPUState = *cpu, int b) } TCGv_i64 notu =3D tcg_temp_new_i64(); tcg_gen_not_i64(notu, cpu_bndu[reg]); - gen_bndck(env, s, modrm, TCG_COND_GTU, notu); + gen_bndck(s, decode, TCG_COND_GTU, notu); } else if (prefixes & PREFIX_DATA) { /* bndmov -- from reg/mem */ if (reg >=3D 4 || s->aflag =3D=3D MO_16) { @@ -3491,7 +3470,7 @@ static void disas_insn_old(DisasContext *s, CPUState = *cpu, int b) tcg_gen_mov_i64(cpu_bndu[reg], cpu_bndu[reg2]); } } else { - gen_lea_modrm(env, s, modrm); + gen_lea_modrm(s, decode); if (CODE64(s)) { tcg_gen_qemu_ld_i64(cpu_bndl[reg], s->A0, s->mem_index, MO_LEUQ); @@ -3510,7 +3489,7 @@ static void disas_insn_old(DisasContext *s, CPUState = *cpu, int b) } } else if (mod !=3D 3) { /* bndldx */ - AddressParts a =3D gen_lea_modrm_0(env, s, modrm); + AddressParts a =3D decode->mem; if (reg >=3D 4 || (prefixes & PREFIX_LOCK) || s->aflag =3D=3D MO_16 @@ -3540,10 +3519,8 @@ static void disas_insn_old(DisasContext *s, CPUState= *cpu, int b) gen_set_hflag(s, HF_MPX_IU_MASK); } } - gen_nop_modrm(env, s, modrm); break; case 0x11b: - modrm =3D x86_ldub_code(env, s); if (s->flags & HF_MPX_EN_MASK) { mod =3D (modrm >> 6) & 3; reg =3D ((modrm >> 3) & 7) | REX_R(s); @@ -3554,7 +3531,7 @@ static void disas_insn_old(DisasContext *s, CPUState = *cpu, int b) || s->aflag =3D=3D MO_16) { goto illegal_op; } - AddressParts a =3D gen_lea_modrm_0(env, s, modrm); + AddressParts a =3D decode->mem; if (a.base >=3D 0) { tcg_gen_extu_tl_i64(cpu_bndl[reg], cpu_regs[a.base]); if (!CODE64(s)) { @@ -3567,7 +3544,7 @@ static void disas_insn_old(DisasContext *s, CPUState = *cpu, int b) /* rip-relative generates #ud */ goto illegal_op; } - tcg_gen_not_tl(s->A0, gen_lea_modrm_1(s, a, false)); + tcg_gen_not_tl(s->A0, gen_lea_modrm_1(s, decode->mem, fals= e)); if (!CODE64(s)) { tcg_gen_ext32u_tl(s->A0, s->A0); } @@ -3582,7 +3559,7 @@ static void disas_insn_old(DisasContext *s, CPUState = *cpu, int b) || s->aflag =3D=3D MO_16) { goto illegal_op; } - gen_bndck(env, s, modrm, TCG_COND_GTU, cpu_bndu[reg]); + gen_bndck(s, decode, TCG_COND_GTU, cpu_bndu[reg]); } else if (prefixes & PREFIX_DATA) { /* bndmov -- to reg/mem */ if (reg >=3D 4 || s->aflag =3D=3D MO_16) { @@ -3598,7 +3575,7 @@ static void disas_insn_old(DisasContext *s, CPUState = *cpu, int b) tcg_gen_mov_i64(cpu_bndu[reg2], cpu_bndu[reg]); } } else { - gen_lea_modrm(env, s, modrm); + gen_lea_modrm(s, decode); if (CODE64(s)) { tcg_gen_qemu_st_i64(cpu_bndl[reg], s->A0, s->mem_index, MO_LEUQ); @@ -3615,7 +3592,7 @@ static void disas_insn_old(DisasContext *s, CPUState = *cpu, int b) } } else if (mod !=3D 3) { /* bndstx */ - AddressParts a =3D gen_lea_modrm_0(env, s, modrm); + AddressParts a =3D decode->mem; if (reg >=3D 4 || (prefixes & PREFIX_LOCK) || s->aflag =3D=3D MO_16 @@ -3642,7 +3619,6 @@ static void disas_insn_old(DisasContext *s, CPUState = *cpu, int b) } } } - gen_nop_modrm(env, s, modrm); break; default: g_assert_not_reached(); @@ -3651,12 +3627,8 @@ static void disas_insn_old(DisasContext *s, CPUState= *cpu, int b) illegal_op: gen_illegal_opcode(s); return; - unknown_op: - gen_unknown_opcode(env, s); } =20 -#include "decode-new.h" -#include "emit.c.inc" #include "decode-new.c.inc" =20 void tcg_x86_init(void) diff --git a/target/i386/tcg/decode-new.c.inc b/target/i386/tcg/decode-new.= c.inc index 33ffcf092ec..45f4aed4611 100644 --- a/target/i386/tcg/decode-new.c.inc +++ b/target/i386/tcg/decode-new.c.inc @@ -1092,6 +1092,8 @@ static void decode_MOV_CR_DR(DisasContext *s, CPUX86S= tate *env, X86OpEntry *entr } =20 static const X86OpEntry opcodes_0F[256] =3D { + [0x00] =3D X86_OP_ENTRY1(multi0F, nop,v, nolea), /*= unconverted */ + [0x01] =3D X86_OP_ENTRY1(multi0F, nop,v, nolea), /*= unconverted */ [0x02] =3D X86_OP_ENTRYwr(LAR, G,v, E,w, chk(prot)), [0x03] =3D X86_OP_ENTRYwr(LSL, G,v, E,w, chk(prot)), [0x05] =3D X86_OP_ENTRY0(SYSCALL, chk(o64_in= tel)), @@ -1201,6 +1203,7 @@ static const X86OpEntry opcodes_0F[256] =3D { [0xc4] =3D X86_OP_ENTRY4(PINSRW, V,dq,H,dq,E,w, vex5 mmx p_0= 0_66), [0xc5] =3D X86_OP_ENTRY3(PEXTRW, G,d, U,dq,I,b, vex5 mmx p_0= 0_66), [0xc6] =3D X86_OP_ENTRY4(VSHUF, V,x, H,x, W,x, vex4 p_00_66= ), + [0xc7] =3D X86_OP_ENTRY1(multi0F, nop,v, nolea), /* u= nconverted */ =20 [0xd0] =3D X86_OP_ENTRY3(VADDSUB, V,x, H,x, W,x, vex2 cpuid(S= SE3) p_66_f2), [0xd1] =3D X86_OP_ENTRY3(PSRLW_r, V,x, H,x, W,x, vex4 mmx avx= 2_256 p_00_66), @@ -1243,6 +1246,8 @@ static const X86OpEntry opcodes_0F[256] =3D { =20 [0x18] =3D X86_OP_ENTRY1(NOP, nop,v), /* prefetch/reserved NOP */ [0x19] =3D X86_OP_ENTRY1(NOP, nop,v), /* reserved NOP */ + [0x1a] =3D X86_OP_ENTRY1(multi0F, nop,v, nolea), /* unconverted MPX */ + [0x1b] =3D X86_OP_ENTRY1(multi0F, nop,v, nolea), /* unconverted MPX */ [0x1c] =3D X86_OP_ENTRY1(NOP, nop,v), /* reserved NOP */ [0x1d] =3D X86_OP_ENTRY1(NOP, nop,v), /* reserved NOP */ [0x1e] =3D X86_OP_ENTRY1(NOP, nop,v), /* reserved NOP */ @@ -1780,6 +1785,19 @@ static const X86OpEntry opcodes_root[256] =3D { [0xCE] =3D X86_OP_ENTRY0(INTO), [0xCF] =3D X86_OP_ENTRY0(IRET, chk(vm86_iopl) svm(IRET)), =20 + /* + * x87 is nolea because it needs the address without segment base, + * in order to store it in fdp. + */ + [0xD8] =3D X86_OP_ENTRY1(x87, nop,v, nolea), + [0xD9] =3D X86_OP_ENTRY1(x87, nop,v, nolea), + [0xDA] =3D X86_OP_ENTRY1(x87, nop,v, nolea), + [0xDB] =3D X86_OP_ENTRY1(x87, nop,v, nolea), + [0xDC] =3D X86_OP_ENTRY1(x87, nop,v, nolea), + [0xDD] =3D X86_OP_ENTRY1(x87, nop,v, nolea), + [0xDE] =3D X86_OP_ENTRY1(x87, nop,v, nolea), + [0xDF] =3D X86_OP_ENTRY1(x87, nop,v, nolea), + [0xE8] =3D X86_OP_ENTRYr(CALL, J,z_f64), [0xE9] =3D X86_OP_ENTRYr(JMP, J,z_f64), [0xEA] =3D X86_OP_ENTRYrr(JMPF, I_unsigned,p, I_unsigned,w, chk(i64)), @@ -2608,30 +2626,6 @@ static void disas_insn(DisasContext *s, CPUState *cp= u) } } =20 - /* Go back to old decoder for unconverted opcodes. */ - if (!(s->prefix & PREFIX_VEX)) { - if ((b & ~7) =3D=3D 0xd8) { - if (!disas_insn_x87(s, cpu, b)) { - goto unknown_op; - } - return; - } - - if (b =3D=3D 0x0f) { - b =3D x86_ldub_code(env, s); - switch (b) { - case 0x00 ... 0x01: /* mostly privileged instructions */ - case 0x1a ... 0x1b: /* MPX */ - case 0xc7: /* grp9 */ - disas_insn_old(s, cpu, b + 0x100); - return; - default: - decode_func =3D do_decode_0F; - break; - } - } - } - memset(&decode, 0, sizeof(decode)); decode.cc_op =3D -1; decode.b =3D b; @@ -2728,6 +2722,15 @@ static void disas_insn(DisasContext *s, CPUState *cp= u) break; } =20 + /* + * hack for old decoder: 0F C7 has both instructions that accept LOCK + * and instructions that don't, but also needs X86_SPECIAL_NoLoadEA. + * Keep this here until CMPXCHG8B/CMPXCHG16B is separated from the + * other unconverted opcodes. + */ + if (decode.e.gen =3D=3D gen_multi0F) { + accept_lock =3D true; + } if ((s->prefix & PREFIX_LOCK) && !accept_lock) { goto illegal_op; } @@ -2775,7 +2778,7 @@ static void disas_insn(DisasContext *s, CPUState *cpu) =20 if (decode.e.special !=3D X86_SPECIAL_NoLoadEA && (decode.op[0].has_ea || decode.op[1].has_ea || decode.op[2].has_ea= )) { - gen_load_ea(s, &decode); + gen_lea_modrm(s, &decode); } if (s->prefix & PREFIX_LOCK) { gen_load(s, &decode, 2, s->T1); diff --git a/target/i386/tcg/emit.c.inc b/target/i386/tcg/emit.c.inc index a25dff0570c..edadb51ae89 100644 --- a/target/i386/tcg/emit.c.inc +++ b/target/i386/tcg/emit.c.inc @@ -73,7 +73,7 @@ static void gen_NM_exception(DisasContext *s) gen_exception(s, EXCP07_PREX); } =20 -static void gen_load_ea(DisasContext *s, X86DecodedInsn *decode) +static void gen_lea_modrm(DisasContext *s, X86DecodedInsn *decode) { AddressParts *mem =3D &decode->mem; TCGv ea; --=20 2.45.2 From nobody Mon Nov 25 02:08:55 2024 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=1718877305; cv=none; d=zohomail.com; s=zohoarc; b=Q9Uhkkc/7lPLF9N4KR/LQlwW7mem+CSKIpPWckVw3zrXujPDXzm8CcAzk0U1qB23eHI0A0TrpYaYKx3OSlyki09UHV0I1Y4LlrRy5bmFpCDlv5dECFVvn448EoJR87CpX3v6SDDgcBCLzO0vONFec37ZQNOjynwPKHWxqr1c4kQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1718877305; h=Content-Type:Content-Transfer-Encoding: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:Cc; bh=8rswGNFf/ukyjmtPVH0ERdHbL1CuFDqep6ZesRYYRbQ=; b=SPoc+PfndidnGbtSy86/SyxAL42sa5TjiX0G9devZ8/OEOw41It+qBZ43oeM73du0/9bGAqzlHgfedxPx+OZERXrU1wvRgQ3Bd2PAdesIUoEdPJx8wuR06h6OFaxPfTfwq6e7Cf2a0FxZIILyGc6GPZmvJtaDpnpacVtDvixMCQ= 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 1718877305209424.21456966186054; Thu, 20 Jun 2024 02:55:05 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sKEVF-0002MU-GN; Thu, 20 Jun 2024 05:54:49 -0400 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 1sKEVB-0002L4-IC for qemu-devel@nongnu.org; Thu, 20 Jun 2024 05:54:45 -0400 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 1sKEV9-0005TN-AI for qemu-devel@nongnu.org; Thu, 20 Jun 2024 05:54:45 -0400 Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-544-uwZ09XRWNl2q-B2Q22O9cQ-1; Thu, 20 Jun 2024 05:54:40 -0400 Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-a6f99aca0f8so25462066b.1 for ; Thu, 20 Jun 2024 02:54:40 -0700 (PDT) Received: from avogadro.local ([151.62.196.71]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a6f56da32c3sm760237766b.13.2024.06.20.02.54.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 02:54:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718877282; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8rswGNFf/ukyjmtPVH0ERdHbL1CuFDqep6ZesRYYRbQ=; b=CToyfSiNaVUUlwEc6E28ngplB6Rm0geKjCTJNSDeuPUpiBXGVnwmPRkF1r8sCKLCQCvfyt DOxkE3DQMEUnUj+xVSgRMbTGwArn5HwVj0jSx4cPLxXhjsVu5HMpC2Dla22aXeEc3Kxu9w OKlxPNzDqS1Y8Cd3aJU5m6KLF6ohiQQ= X-MC-Unique: uwZ09XRWNl2q-B2Q22O9cQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718877279; x=1719482079; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8rswGNFf/ukyjmtPVH0ERdHbL1CuFDqep6ZesRYYRbQ=; b=RyX2P5MMrZak+vgWyF4mZqJvweCzYcIUNrKKAxWN4LNnXammJzqBIhXQhgiGq0LeOZ e2JNouvY7wecfRPipDsM0sJJzwD0QfGCg6vUlkjvheDKEFM3XHKa3/hehU6ho/Au8Wly 64d2jLE8hfbtwYMp3i7o/69GTGQKI8lBNoSCFLvOXOoxM6wtyWkfpa9HA/kimrBKhcHD /rCANwSpocSdrdo/nLdlNuYwrZp7sI/MGwjaf4T+VHtQb3s/WgBAXWBS97sMGT56MLaL n/cp+xq5pRFxKZ6wHj3FZlSAuBfDo7K0QMbPiiLNR/WJXwU5uI1ai2m38W3CbE12tGFQ AxxQ== X-Gm-Message-State: AOJu0Yws0Ag14Zgqy1Xddds+2JjNEqZa2+5lcXo38AoGiYREde4HM7vp UgafkCwRd0ukp0TgZpzH4pI4oHPetY1xDKSUOBzFuR85C9sz9Sc+G07gZ+E0dMVZzlndzxQf5Eq pQIJ0zlklK7HN0o5JPfg/WUIb6FKOMCM5GTaRbVlevVTc8GexULBmBD1V5L0brzglk5WJxgC98Y 2oyIcBgykJUnczbXMJ2rWn9bznqa4KC7Cm5T2o X-Received: by 2002:a17:907:c31c:b0:a6f:1378:1329 with SMTP id a640c23a62f3a-a6fab607142mr397046266b.4.1718877279206; Thu, 20 Jun 2024 02:54:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFjINDZ1u3OpTbtV7I5LfUycUXQPWNcfz8DGW/ZdJEW3oqNf7hCPcHD53IfoJjVtHmjijpDJQ== X-Received: by 2002:a17:907:c31c:b0:a6f:1378:1329 with SMTP id a640c23a62f3a-a6fab607142mr397043666b.4.1718877278640; Thu, 20 Jun 2024 02:54:38 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 06/10] target/i386: convert CMPXCHG8B/CMPXCHG16B to new decoder Date: Thu, 20 Jun 2024 11:54:15 +0200 Message-ID: <20240620095419.386958-7-pbonzini@redhat.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240620095419.386958-1-pbonzini@redhat.com> References: <20240620095419.386958-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: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.144, 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: 1718877305487100001 Content-Type: text/plain; charset="utf-8" This moves the last LOCK-enabled instructions to the new decoder. It is now possible to assume that PREFIX_LOCK gen_multi0F is called only after checki= ng that LOCK was not specified. The gen_cmpxchg8b and gen_cmpxchg16b functions even have the correct prototype already; the only thing that needs to be done is removing the gen_lea_modrm() call. Signed-off-by: Paolo Bonzini Reviewed-by: Richard Henderson --- target/i386/tcg/decode-new.h | 2 + target/i386/tcg/translate.c | 121 +------------------------------ target/i386/tcg/decode-new.c.inc | 34 ++++++--- target/i386/tcg/emit.c.inc | 96 ++++++++++++++++++++++++ 4 files changed, 124 insertions(+), 129 deletions(-) diff --git a/target/i386/tcg/decode-new.h b/target/i386/tcg/decode-new.h index bebc77bd54b..7f23d373ea7 100644 --- a/target/i386/tcg/decode-new.h +++ b/target/i386/tcg/decode-new.h @@ -114,6 +114,8 @@ typedef enum X86CPUIDFeature { X86_FEAT_CLWB, X86_FEAT_CMOV, X86_FEAT_CMPCCXADD, + X86_FEAT_CX8, + X86_FEAT_CX16, X86_FEAT_F16C, X86_FEAT_FMA, X86_FEAT_FSGSBASE, diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index 1d845ff66bb..c60f18c7482 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -2298,104 +2298,6 @@ static void gen_sty_env_A0(DisasContext *s, int off= set, bool align) tcg_gen_qemu_st_i128(t, s->tmp0, mem_index, mop); } =20 -static void gen_cmpxchg8b(DisasContext *s, X86DecodedInsn *decode) -{ - TCGv_i64 cmp, val, old; - TCGv Z; - - gen_lea_modrm(s, decode); - - cmp =3D tcg_temp_new_i64(); - val =3D tcg_temp_new_i64(); - old =3D tcg_temp_new_i64(); - - /* Construct the comparison values from the register pair. */ - tcg_gen_concat_tl_i64(cmp, cpu_regs[R_EAX], cpu_regs[R_EDX]); - tcg_gen_concat_tl_i64(val, cpu_regs[R_EBX], cpu_regs[R_ECX]); - - /* Only require atomic with LOCK; non-parallel handled in generator. */ - if (s->prefix & PREFIX_LOCK) { - tcg_gen_atomic_cmpxchg_i64(old, s->A0, cmp, val, s->mem_index, MO_= TEUQ); - } else { - tcg_gen_nonatomic_cmpxchg_i64(old, s->A0, cmp, val, - s->mem_index, MO_TEUQ); - } - - /* Set tmp0 to match the required value of Z. */ - tcg_gen_setcond_i64(TCG_COND_EQ, cmp, old, cmp); - Z =3D tcg_temp_new(); - tcg_gen_trunc_i64_tl(Z, cmp); - - /* - * Extract the result values for the register pair. - * For 32-bit, we may do this unconditionally, because on success (Z= =3D1), - * the old value matches the previous value in EDX:EAX. For x86_64, - * the store must be conditional, because we must leave the source - * registers unchanged on success, and zero-extend the writeback - * on failure (Z=3D0). - */ - if (TARGET_LONG_BITS =3D=3D 32) { - tcg_gen_extr_i64_tl(cpu_regs[R_EAX], cpu_regs[R_EDX], old); - } else { - TCGv zero =3D tcg_constant_tl(0); - - tcg_gen_extr_i64_tl(s->T0, s->T1, old); - tcg_gen_movcond_tl(TCG_COND_EQ, cpu_regs[R_EAX], Z, zero, - s->T0, cpu_regs[R_EAX]); - tcg_gen_movcond_tl(TCG_COND_EQ, cpu_regs[R_EDX], Z, zero, - s->T1, cpu_regs[R_EDX]); - } - - /* Update Z. */ - gen_compute_eflags(s); - tcg_gen_deposit_tl(cpu_cc_src, cpu_cc_src, Z, ctz32(CC_Z), 1); -} - -#ifdef TARGET_X86_64 -static void gen_cmpxchg16b(DisasContext *s, X86DecodedInsn *decode) -{ - MemOp mop =3D MO_TE | MO_128 | MO_ALIGN; - TCGv_i64 t0, t1; - TCGv_i128 cmp, val; - - gen_lea_modrm(s, decode); - - cmp =3D tcg_temp_new_i128(); - val =3D tcg_temp_new_i128(); - tcg_gen_concat_i64_i128(cmp, cpu_regs[R_EAX], cpu_regs[R_EDX]); - tcg_gen_concat_i64_i128(val, cpu_regs[R_EBX], cpu_regs[R_ECX]); - - /* Only require atomic with LOCK; non-parallel handled in generator. */ - if (s->prefix & PREFIX_LOCK) { - tcg_gen_atomic_cmpxchg_i128(val, s->A0, cmp, val, s->mem_index, mo= p); - } else { - tcg_gen_nonatomic_cmpxchg_i128(val, s->A0, cmp, val, s->mem_index,= mop); - } - - tcg_gen_extr_i128_i64(s->T0, s->T1, val); - - /* Determine success after the fact. */ - t0 =3D tcg_temp_new_i64(); - t1 =3D tcg_temp_new_i64(); - tcg_gen_xor_i64(t0, s->T0, cpu_regs[R_EAX]); - tcg_gen_xor_i64(t1, s->T1, cpu_regs[R_EDX]); - tcg_gen_or_i64(t0, t0, t1); - - /* Update Z. */ - gen_compute_eflags(s); - tcg_gen_setcondi_i64(TCG_COND_EQ, t0, t0, 0); - tcg_gen_deposit_tl(cpu_cc_src, cpu_cc_src, t0, ctz32(CC_Z), 1); - - /* - * Extract the result values for the register pair. We may do this - * unconditionally, because on success (Z=3D1), the old value matches - * the previous value in RDX:RAX. - */ - tcg_gen_mov_i64(cpu_regs[R_EAX], s->T0); - tcg_gen_mov_i64(cpu_regs[R_EDX], s->T1); -} -#endif - #include "emit.c.inc" =20 static void gen_x87(DisasContext *s, X86DecodedInsn *decode) @@ -2971,29 +2873,10 @@ static void gen_multi0F(DisasContext *s, X86Decoded= Insn *decode) =20 /* now check op code */ switch (b) { - case 0x1c7: /* cmpxchg8b */ + case 0x1c7: /* RDSEED, RDPID with f3 prefix */ mod =3D (modrm >> 6) & 3; switch ((modrm >> 3) & 7) { - case 1: /* CMPXCHG8, CMPXCHG16 */ - if (mod =3D=3D 3) { - goto illegal_op; - } -#ifdef TARGET_X86_64 - if (dflag =3D=3D MO_64) { - if (!(s->cpuid_ext_features & CPUID_EXT_CX16)) { - goto illegal_op; - } - gen_cmpxchg16b(s, decode); - break; - } -#endif - if (!(s->cpuid_features & CPUID_CX8)) { - goto illegal_op; - } - gen_cmpxchg8b(s, decode); - break; - - case 7: /* RDSEED, RDPID with f3 prefix */ + case 7: if (mod !=3D 3 || (s->prefix & (PREFIX_LOCK | PREFIX_REPNZ))) { goto illegal_op; diff --git a/target/i386/tcg/decode-new.c.inc b/target/i386/tcg/decode-new.= c.inc index 45f4aed4611..fa51aadfcf2 100644 --- a/target/i386/tcg/decode-new.c.inc +++ b/target/i386/tcg/decode-new.c.inc @@ -288,6 +288,25 @@ static void decode_group8(DisasContext *s, CPUX86State= *env, X86OpEntry *entry, } } =20 +static void decode_group9(DisasContext *s, CPUX86State *env, X86OpEntry *e= ntry, uint8_t *b) +{ + static const X86OpEntry group9_reg =3D + X86_OP_ENTRY0(multi0F); /* unconverted */ + static const X86OpEntry cmpxchg8b =3D + X86_OP_ENTRY1(CMPXCHG8B, M,q, lock p_00 cpuid(CX8)); + static const X86OpEntry cmpxchg16b =3D + X86_OP_ENTRY1(CMPXCHG16B, M,dq, lock p_00 cpuid(CX16)); + + int modrm =3D get_modrm(s, env); + int op =3D (modrm >> 3) & 7; + + if ((modrm >> 6) =3D=3D 3) { + *entry =3D group9_reg; + } else if (op =3D=3D 1) { + *entry =3D REX_W(s) ? cmpxchg16b : cmpxchg8b; + } +} + static void decode_group15(DisasContext *s, CPUX86State *env, X86OpEntry *= entry, uint8_t *b) { static const X86OpEntry group15_reg[8] =3D { @@ -1203,7 +1222,7 @@ static const X86OpEntry opcodes_0F[256] =3D { [0xc4] =3D X86_OP_ENTRY4(PINSRW, V,dq,H,dq,E,w, vex5 mmx p_0= 0_66), [0xc5] =3D X86_OP_ENTRY3(PEXTRW, G,d, U,dq,I,b, vex5 mmx p_0= 0_66), [0xc6] =3D X86_OP_ENTRY4(VSHUF, V,x, H,x, W,x, vex4 p_00_66= ), - [0xc7] =3D X86_OP_ENTRY1(multi0F, nop,v, nolea), /* u= nconverted */ + [0xc7] =3D X86_OP_GROUP0(group9), =20 [0xd0] =3D X86_OP_ENTRY3(VADDSUB, V,x, H,x, W,x, vex2 cpuid(S= SE3) p_66_f2), [0xd1] =3D X86_OP_ENTRY3(PSRLW_r, V,x, H,x, W,x, vex4 mmx avx= 2_256 p_00_66), @@ -2241,8 +2260,12 @@ static bool has_cpuid_feature(DisasContext *s, X86CP= UIDFeature cpuid) return (s->cpuid_features & CPUID_CMOV); case X86_FEAT_CLFLUSH: return (s->cpuid_features & CPUID_CLFLUSH); + case X86_FEAT_CX8: + return (s->cpuid_features & CPUID_CX8); case X86_FEAT_FXSR: return (s->cpuid_features & CPUID_FXSR); + case X86_FEAT_CX16: + return (s->cpuid_ext_features & CPUID_EXT_CX16); case X86_FEAT_F16C: return (s->cpuid_ext_features & CPUID_EXT_F16C); case X86_FEAT_FMA: @@ -2722,15 +2745,6 @@ static void disas_insn(DisasContext *s, CPUState *cp= u) break; } =20 - /* - * hack for old decoder: 0F C7 has both instructions that accept LOCK - * and instructions that don't, but also needs X86_SPECIAL_NoLoadEA. - * Keep this here until CMPXCHG8B/CMPXCHG16B is separated from the - * other unconverted opcodes. - */ - if (decode.e.gen =3D=3D gen_multi0F) { - accept_lock =3D true; - } if ((s->prefix & PREFIX_LOCK) && !accept_lock) { goto illegal_op; } diff --git a/target/i386/tcg/emit.c.inc b/target/i386/tcg/emit.c.inc index edadb51ae89..98f10ad8b4e 100644 --- a/target/i386/tcg/emit.c.inc +++ b/target/i386/tcg/emit.c.inc @@ -1782,6 +1782,102 @@ static void gen_CMPXCHG(DisasContext *s, X86Decoded= Insn *decode) decode->cc_op =3D CC_OP_SUBB + ot; } =20 +static void gen_CMPXCHG16B(DisasContext *s, X86DecodedInsn *decode) +{ +#ifdef TARGET_X86_64 + MemOp mop =3D MO_TE | MO_128 | MO_ALIGN; + TCGv_i64 t0, t1; + TCGv_i128 cmp, val; + + cmp =3D tcg_temp_new_i128(); + val =3D tcg_temp_new_i128(); + tcg_gen_concat_i64_i128(cmp, cpu_regs[R_EAX], cpu_regs[R_EDX]); + tcg_gen_concat_i64_i128(val, cpu_regs[R_EBX], cpu_regs[R_ECX]); + + /* Only require atomic with LOCK; non-parallel handled in generator. */ + if (s->prefix & PREFIX_LOCK) { + tcg_gen_atomic_cmpxchg_i128(val, s->A0, cmp, val, s->mem_index, mo= p); + } else { + tcg_gen_nonatomic_cmpxchg_i128(val, s->A0, cmp, val, s->mem_index,= mop); + } + + tcg_gen_extr_i128_i64(s->T0, s->T1, val); + + /* Determine success after the fact. */ + t0 =3D tcg_temp_new_i64(); + t1 =3D tcg_temp_new_i64(); + tcg_gen_xor_i64(t0, s->T0, cpu_regs[R_EAX]); + tcg_gen_xor_i64(t1, s->T1, cpu_regs[R_EDX]); + tcg_gen_or_i64(t0, t0, t1); + + /* Update Z. */ + gen_compute_eflags(s); + tcg_gen_setcondi_i64(TCG_COND_EQ, t0, t0, 0); + tcg_gen_deposit_tl(cpu_cc_src, cpu_cc_src, t0, ctz32(CC_Z), 1); + + /* + * Extract the result values for the register pair. We may do this + * unconditionally, because on success (Z=3D1), the old value matches + * the previous value in RDX:RAX. + */ + tcg_gen_mov_i64(cpu_regs[R_EAX], s->T0); + tcg_gen_mov_i64(cpu_regs[R_EDX], s->T1); +#else + abort(); +#endif +} + +static void gen_CMPXCHG8B(DisasContext *s, X86DecodedInsn *decode) +{ + TCGv_i64 cmp, val, old; + TCGv Z; + + cmp =3D tcg_temp_new_i64(); + val =3D tcg_temp_new_i64(); + old =3D tcg_temp_new_i64(); + + /* Construct the comparison values from the register pair. */ + tcg_gen_concat_tl_i64(cmp, cpu_regs[R_EAX], cpu_regs[R_EDX]); + tcg_gen_concat_tl_i64(val, cpu_regs[R_EBX], cpu_regs[R_ECX]); + + /* Only require atomic with LOCK; non-parallel handled in generator. */ + if (s->prefix & PREFIX_LOCK) { + tcg_gen_atomic_cmpxchg_i64(old, s->A0, cmp, val, s->mem_index, MO_= TEUQ); + } else { + tcg_gen_nonatomic_cmpxchg_i64(old, s->A0, cmp, val, + s->mem_index, MO_TEUQ); + } + + /* Set tmp0 to match the required value of Z. */ + tcg_gen_setcond_i64(TCG_COND_EQ, cmp, old, cmp); + Z =3D tcg_temp_new(); + tcg_gen_trunc_i64_tl(Z, cmp); + + /* + * Extract the result values for the register pair. + * For 32-bit, we may do this unconditionally, because on success (Z= =3D1), + * the old value matches the previous value in EDX:EAX. For x86_64, + * the store must be conditional, because we must leave the source + * registers unchanged on success, and zero-extend the writeback + * on failure (Z=3D0). + */ + if (TARGET_LONG_BITS =3D=3D 32) { + tcg_gen_extr_i64_tl(cpu_regs[R_EAX], cpu_regs[R_EDX], old); + } else { + TCGv zero =3D tcg_constant_tl(0); + + tcg_gen_extr_i64_tl(s->T0, s->T1, old); + tcg_gen_movcond_tl(TCG_COND_EQ, cpu_regs[R_EAX], Z, zero, + s->T0, cpu_regs[R_EAX]); + tcg_gen_movcond_tl(TCG_COND_EQ, cpu_regs[R_EDX], Z, zero, + s->T1, cpu_regs[R_EDX]); + } + + /* Update Z. */ + gen_compute_eflags(s); + tcg_gen_deposit_tl(cpu_cc_src, cpu_cc_src, Z, ctz32(CC_Z), 1); +} + static void gen_CPUID(DisasContext *s, X86DecodedInsn *decode) { gen_update_cc_op(s); --=20 2.45.2 From nobody Mon Nov 25 02:08:55 2024 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=1718877364; cv=none; d=zohomail.com; s=zohoarc; b=GDUqwn/Y1npZQdUtiQORtwvO4CiUviurGLm8h31nf15VGZKAR4TyuGDMjSSzfogKQG/1Cbf6m2t2FhwhNQwRL+qVuzfhmkddyu3YhpwDuL5535OdfFAPUKKqYSROCTMZMfIV74ansZ0XSTWDTVN18a9CrT8jf0z5jwQz7NxEnnE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1718877364; h=Content-Type: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=9XXSgEZfF/mgmRYz0quvK+Q6GbqXkOMqVfYjFVsm7Z8=; b=QIao6X3pf3pw5Xqm8R91FQvu0IbG51tH5roNV0EF5yxzXnX9FNdt7iT4GtH/T+LGsrtkfsQQixTl6EtOPDXRgwc/nFKdNbciSCePR7QDAYyWXADm2tph2EymAXo3uVnGazDAws3NtUbwRIlh6hZNC/zuzcFM/IdftntmJq9KoiI= 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 1718877364605136.28576800790188; Thu, 20 Jun 2024 02:56:04 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sKEVT-0002k7-SD; Thu, 20 Jun 2024 05:55:05 -0400 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 1sKEVJ-0002OO-T1 for qemu-devel@nongnu.org; Thu, 20 Jun 2024 05:54:54 -0400 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 1sKEVH-0005VY-FL for qemu-devel@nongnu.org; Thu, 20 Jun 2024 05:54:53 -0400 Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-394-HiETnE3uPDC0zqstn5-MNQ-1; Thu, 20 Jun 2024 05:54:43 -0400 Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-a6f8ebdf8a6so35175966b.0 for ; Thu, 20 Jun 2024 02:54:43 -0700 (PDT) Received: from avogadro.local ([151.62.196.71]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a6f9bbb08d6sm182920666b.3.2024.06.20.02.54.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 02:54:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718877290; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9XXSgEZfF/mgmRYz0quvK+Q6GbqXkOMqVfYjFVsm7Z8=; b=O7e1TyQ0PJbfz6Txx4FnALtlCFlgMLg+kNtxapZXbMTdYSzeARo7J8IglakYwZt6yQRF0D siX2s4wPet7ndcV5HbLsikGkQ0eKfWhq0fHxz5Igzt+WntH3Vb9h/ogjaaG5Xn3rGYIyrk wxFHHghNljegosbY9xtTi0Fg5Sg6CUQ= X-MC-Unique: HiETnE3uPDC0zqstn5-MNQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718877282; x=1719482082; 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=9XXSgEZfF/mgmRYz0quvK+Q6GbqXkOMqVfYjFVsm7Z8=; b=WLSW69onZzTeKPcynJKEnKj7ZROtSz1a37KiKMa8dXt5DWrB8MRsO8GGDfEE53azII i1sA+BqKhQ6NnnV+oj4Rnj7el89JZ08lK6TTIfzbfnDlBaCPbI883ithlmdUkoMcwoHC kjuCg/b16PIQQvMyd9GimDOKyOhQ6X7bXkWCHYA3AIXajsZd7PFfJP99ldD1r2YDiEET JA/iAqvIlEU52JJgTz6JdJ+pOLhnj1IZ6Va/s/eHjudTnvFyPb9ssyeh9p66rfDW82KH 7XmZy3DAAGimLtV5VqFmHosURJ1t6DeG6YvwmnQdH8twd63mINyxQaf+IcsYD4Z3murb Rghw== X-Gm-Message-State: AOJu0YwiT4JUb1YTX2kts3GOzTTqeYLZK6/eKTRw6VhxJveCof9VXspi kXC3/ytn0etp2rznMD7IJGXn2uRrihQXQbu4Ydb6WACdQhrqVTI/jC/BJqBnEWmWr7zQy4Rq9Wn JkqMzMrH3aD1h2IXOQbercy+UO/GbmCgQvbZswlh6+ttflVh02xlY+2WPOaJk41Ri5X/BkDSmtP 39eCJwggWeDpz0pia8/j5i9t2CcnJj864yZCE2 X-Received: by 2002:a17:907:6a13:b0:a6f:24fe:f2a7 with SMTP id a640c23a62f3a-a6fab6031e1mr286686166b.10.1718877281878; Thu, 20 Jun 2024 02:54:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFqXz4UgcktpibJ/v6PfNF6u7yqPSa6JSiZMXF44wNlG1iXI3yijP7uD6DZNi7HrkOuBDQI2g== X-Received: by 2002:a17:907:6a13:b0:a6f:24fe:f2a7 with SMTP id a640c23a62f3a-a6fab6031e1mr286684166b.10.1718877281232; Thu, 20 Jun 2024 02:54:41 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Richard Henderson Subject: [PATCH 07/10] target/i386: do not check PREFIX_LOCK in old-style decoder Date: Thu, 20 Jun 2024 11:54:16 +0200 Message-ID: <20240620095419.386958-8-pbonzini@redhat.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240620095419.386958-1-pbonzini@redhat.com> References: <20240620095419.386958-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: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.144, 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: 1718877366516100003 Content-Type: text/plain; charset="utf-8" It is already checked before getting there. Reviewed-by: Richard Henderson Signed-off-by: Paolo Bonzini --- target/i386/tcg/translate.c | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index c60f18c7482..501a1ef9313 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -2878,7 +2878,7 @@ static void gen_multi0F(DisasContext *s, X86DecodedIn= sn *decode) switch ((modrm >> 3) & 7) { case 7: if (mod !=3D 3 || - (s->prefix & (PREFIX_LOCK | PREFIX_REPNZ))) { + (s->prefix & PREFIX_REPNZ)) { goto illegal_op; } if (s->prefix & PREFIX_REPZ) { @@ -2898,7 +2898,7 @@ static void gen_multi0F(DisasContext *s, X86DecodedIn= sn *decode) =20 case 6: /* RDRAND */ if (mod !=3D 3 || - (s->prefix & (PREFIX_LOCK | PREFIX_REPZ | PREFIX_REPNZ)) || + (s->prefix & (PREFIX_REPZ | PREFIX_REPNZ)) || !(s->cpuid_ext_features & CPUID_EXT_RDRAND)) { goto illegal_op; } @@ -3058,8 +3058,7 @@ static void gen_multi0F(DisasContext *s, X86DecodedIn= sn *decode) =20 case 0xd0: /* xgetbv */ if ((s->cpuid_ext_features & CPUID_EXT_XSAVE) =3D=3D 0 - || (s->prefix & (PREFIX_LOCK | PREFIX_DATA - | PREFIX_REPZ | PREFIX_REPNZ))) { + || (s->prefix & (PREFIX_DATA | PREFIX_REPZ | PREFIX_REPNZ)= )) { goto illegal_op; } tcg_gen_trunc_tl_i32(s->tmp2_i32, cpu_regs[R_ECX]); @@ -3069,8 +3068,7 @@ static void gen_multi0F(DisasContext *s, X86DecodedIn= sn *decode) =20 case 0xd1: /* xsetbv */ if ((s->cpuid_ext_features & CPUID_EXT_XSAVE) =3D=3D 0 - || (s->prefix & (PREFIX_LOCK | PREFIX_DATA - | PREFIX_REPZ | PREFIX_REPNZ))) { + || (s->prefix & (PREFIX_DATA | PREFIX_REPZ | PREFIX_REPNZ)= )) { goto illegal_op; } gen_svm_check_intercept(s, SVM_EXIT_XSETBV); @@ -3237,8 +3235,7 @@ static void gen_multi0F(DisasContext *s, X86DecodedIn= sn *decode) gen_st_modrm(s, decode, ot); break; case 0xee: /* rdpkru */ - if (s->prefix & (PREFIX_LOCK | PREFIX_DATA - | PREFIX_REPZ | PREFIX_REPNZ)) { + if (s->prefix & (PREFIX_DATA | PREFIX_REPZ | PREFIX_REPNZ)) { goto illegal_op; } tcg_gen_trunc_tl_i32(s->tmp2_i32, cpu_regs[R_ECX]); @@ -3246,8 +3243,7 @@ static void gen_multi0F(DisasContext *s, X86DecodedIn= sn *decode) tcg_gen_extr_i64_tl(cpu_regs[R_EAX], cpu_regs[R_EDX], s->tmp1_= i64); break; case 0xef: /* wrpkru */ - if (s->prefix & (PREFIX_LOCK | PREFIX_DATA - | PREFIX_REPZ | PREFIX_REPNZ)) { + if (s->prefix & (PREFIX_DATA | PREFIX_REPZ | PREFIX_REPNZ)) { goto illegal_op; } tcg_gen_concat_tl_i64(s->tmp1_i64, cpu_regs[R_EAX], @@ -3323,7 +3319,6 @@ static void gen_multi0F(DisasContext *s, X86DecodedIn= sn *decode) if (prefixes & PREFIX_REPZ) { /* bndcl */ if (reg >=3D 4 - || (prefixes & PREFIX_LOCK) || s->aflag =3D=3D MO_16) { goto illegal_op; } @@ -3331,7 +3326,6 @@ static void gen_multi0F(DisasContext *s, X86DecodedIn= sn *decode) } else if (prefixes & PREFIX_REPNZ) { /* bndcu */ if (reg >=3D 4 - || (prefixes & PREFIX_LOCK) || s->aflag =3D=3D MO_16) { goto illegal_op; } @@ -3345,7 +3339,7 @@ static void gen_multi0F(DisasContext *s, X86DecodedIn= sn *decode) } if (mod =3D=3D 3) { int reg2 =3D (modrm & 7) | REX_B(s); - if (reg2 >=3D 4 || (prefixes & PREFIX_LOCK)) { + if (reg2 >=3D 4) { goto illegal_op; } if (s->flags & HF_MPX_IU_MASK) { @@ -3374,7 +3368,6 @@ static void gen_multi0F(DisasContext *s, X86DecodedIn= sn *decode) /* bndldx */ AddressParts a =3D decode->mem; if (reg >=3D 4 - || (prefixes & PREFIX_LOCK) || s->aflag =3D=3D MO_16 || a.base < -1) { goto illegal_op; @@ -3410,7 +3403,6 @@ static void gen_multi0F(DisasContext *s, X86DecodedIn= sn *decode) if (mod !=3D 3 && (prefixes & PREFIX_REPZ)) { /* bndmk */ if (reg >=3D 4 - || (prefixes & PREFIX_LOCK) || s->aflag =3D=3D MO_16) { goto illegal_op; } @@ -3438,7 +3430,6 @@ static void gen_multi0F(DisasContext *s, X86DecodedIn= sn *decode) } else if (prefixes & PREFIX_REPNZ) { /* bndcn */ if (reg >=3D 4 - || (prefixes & PREFIX_LOCK) || s->aflag =3D=3D MO_16) { goto illegal_op; } @@ -3450,7 +3441,7 @@ static void gen_multi0F(DisasContext *s, X86DecodedIn= sn *decode) } if (mod =3D=3D 3) { int reg2 =3D (modrm & 7) | REX_B(s); - if (reg2 >=3D 4 || (prefixes & PREFIX_LOCK)) { + if (reg2 >=3D 4) { goto illegal_op; } if (s->flags & HF_MPX_IU_MASK) { @@ -3477,7 +3468,6 @@ static void gen_multi0F(DisasContext *s, X86DecodedIn= sn *decode) /* bndstx */ AddressParts a =3D decode->mem; if (reg >=3D 4 - || (prefixes & PREFIX_LOCK) || s->aflag =3D=3D MO_16 || a.base < -1) { goto illegal_op; --=20 2.45.2 From nobody Mon Nov 25 02:08:55 2024 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=1718877339; cv=none; d=zohomail.com; s=zohoarc; b=CndoznUH6M5yqJZafRxuvxgN1mo4QCSZfNfYr9EeUlpOCRKjf4r60OgdXbeXhIPO0tqmzArDuruDwKiZO06i8v+5fxd3HtKtAaqL2Lu7Y0Mhhem+zvo5ulXvGbj7QObS4tryIBPpHZqv7nQ5YU40Y0uQVVmexN/lQh4EMw3/wLQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1718877339; h=Content-Type: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=edfgvS3ELSSOyELG7RxvO1gV2FBychxCHSiOtjvR6gU=; b=NYT6YvB3dxQItUGd01dUuwhpWlvwEXNPNtWoNzKjMZPXPwhYUT9JqmpynGg4aBVmIwO8knMtrEbEyjz06Y2TV1QFK/pcMPXzkZFZYq9d68LzgzXRIroU6Pz4RVfcZWfZdAvV+mL3SDpzJd2XgMG65oyfOkBMSxO8noGa8OI9+6k= 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 1718877339479779.3321410029301; Thu, 20 Jun 2024 02:55:39 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sKEVQ-0002Zd-5M; Thu, 20 Jun 2024 05:55:00 -0400 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 1sKEVI-0002Nt-Gf for qemu-devel@nongnu.org; Thu, 20 Jun 2024 05:54:53 -0400 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 1sKEVG-0005V9-SE for qemu-devel@nongnu.org; Thu, 20 Jun 2024 05:54:52 -0400 Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-452-jvH3huPtMB22kTNjaaeIbw-1; Thu, 20 Jun 2024 05:54:46 -0400 Received: by mail-ed1-f72.google.com with SMTP id 4fb4d7f45d1cf-57d05177afaso1762302a12.1 for ; Thu, 20 Jun 2024 02:54:45 -0700 (PDT) Received: from avogadro.local ([151.62.196.71]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-57cb72ce08bsm9390731a12.1.2024.06.20.02.54.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 02:54:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718877290; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=edfgvS3ELSSOyELG7RxvO1gV2FBychxCHSiOtjvR6gU=; b=FxWm4nv+CsGBq8Ej2hm5A+S8GiA2kPifuvqKvW0MJ1lDlk77JJIkQO9vFaldV0M8cjrM39 jFDCfJgOS9vljGuV1vWDgiQTBboF31qZ79vCNQCuuosMGo+CskT3GGQvd4sFWH82nw/mtt YeeDFqK1XDUcP616VhiWAtnV+pUb23U= X-MC-Unique: jvH3huPtMB22kTNjaaeIbw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718877284; x=1719482084; 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=edfgvS3ELSSOyELG7RxvO1gV2FBychxCHSiOtjvR6gU=; b=LrIMp2OQjuSAhPld9q/JcNwzWnRDSsFUDm+6t9DtVPPPDTHWTq/P3sZsd8ZsCvY0jt Qu4TRAx3/rdoNwIyFnyx9zRng1WCqZlF/54mQI0mIb4Sd4ORb3VauvLQaBph6JhTvUOR +a1wQn251KfHQ+vxIY1C2zpGzBlDAnffJxKDlqlrprKYFAQ00lHEGMqeDLwMaBbLJAVX FchxmbqLd6IKizCsJr1Sz7u6AKL9KTSaX+ftSlApIsH76PJcyluq+hfRTQi1pqt1g9W4 m0WHYr1lsAUiSIXaESutX/MHiInZ2iGJBQ6CiNi6yfEgyhOettwajXAyScNcRsqKJJhI hVVg== X-Gm-Message-State: AOJu0YyqBJTA6ExYITTsKUG2XH9e/R98xmgiIXq2pRlIM+dAXKUWTDMV K82l6ryCoZ44O3LOZfNcUQSpKPB0xy0/8WjRjyBIZwpwL7LqlsmSWcmnsxibw7uuHDiYTMELMs6 r1asw9TfbR3yguyCXhN3P6Fj8yxQd/JLMgbc9CLKndhvEvaLTFeARuITbcGN7axnPfmADEpNePq WGf0q+b1oNtNajzTFVWNFpBxFKpkEKAukFm+40 X-Received: by 2002:aa7:d943:0:b0:57d:1d9e:d1fe with SMTP id 4fb4d7f45d1cf-57d1d9ed435mr1742409a12.9.1718877284106; Thu, 20 Jun 2024 02:54:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH5xX2HtQ30O1ak0ERNiiVoWS/wk9WiExgclELgLPcw5tkqMBZ5w461WrLaAax0ZDijlVDK5w== X-Received: by 2002:aa7:d943:0:b0:57d:1d9e:d1fe with SMTP id 4fb4d7f45d1cf-57d1d9ed435mr1742391a12.9.1718877283757; Thu, 20 Jun 2024 02:54:43 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Richard Henderson Subject: [PATCH 08/10] target/i386: list instructions still in translate.c Date: Thu, 20 Jun 2024 11:54:17 +0200 Message-ID: <20240620095419.386958-9-pbonzini@redhat.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240620095419.386958-1-pbonzini@redhat.com> References: <20240620095419.386958-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: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.144, 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: 1718877342792100001 Content-Type: text/plain; charset="utf-8" Group them so that it is easier to figure out which two-byte opcodes to tackle together. Reviewed-by: Richard Henderson Signed-off-by: Paolo Bonzini --- target/i386/tcg/decode-new.c.inc | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/target/i386/tcg/decode-new.c.inc b/target/i386/tcg/decode-new.= c.inc index fa51aadfcf2..f01a4f1f1fe 100644 --- a/target/i386/tcg/decode-new.c.inc +++ b/target/i386/tcg/decode-new.c.inc @@ -129,6 +129,37 @@ * * (^) these are the two cases in which Intel and AMD disagree on the * primary exception class + * + * Instructions still in translate.c + * --------------------------------- + * Generation of TCG opcodes for almost all instructions is in emit.c.inc; + * this file interprets the prefixes and opcode bytes down to individual + * instruction mnemonics. There is only a handful of opcodes still using + * a switch statement to decode modrm bits 3-5 and prefixes after decoding + * is complete; these are relics of the older x86 decoder and their code + * generation is performed in translate.c. + * + * These unconverted opcodes also perform their own effective address + * generation using the gen_lea_modrm() function. + * + * There is nothing particularly complicated about them; simply, they don't + * need any nasty hacks in the decoder, and they shouldn't get in the way + * of the implementation of new x86 instructions, so they are left alone + * for the time being. + * + * x87: + * 0xD8 - 0xDF + * + * privileged/system: + * 0x0F 0x00 group 6 (SLDT, STR, LLDT, LTR, VERR, VERW) + * 0x0F 0x01 group 7 (SGDT, SIDT, LGDT, LIDT, SMSW, LMSW, IN= VLPG, + * MONITOR, MWAIT, CLAC, STAC, XGETBV, XS= ETBV, + * SWAPGS, RDTSCP) + * 0x0F 0xC7 (reg operand) group 9 (RDRAND, RDSEED, RDPID) + * + * MPX: + * 0x0F 0x1A BNDLDX, BNDMOV, BNDCL, BNDCU + * 0x0F 0x1B BNDSTX, BNDMOV, BNDMK, BNDCN */ =20 #define X86_OP_NONE { 0 }, --=20 2.45.2 From nobody Mon Nov 25 02:08:55 2024 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=1718877399; cv=none; d=zohomail.com; s=zohoarc; b=GB56T/pafVC15yU9rwBmevspTvbgsDHJTXiHrjIQyo+7fhTlBzN8wl4kenQC48Yjw98PGUCw0RBPPWtd8SpBTHVXd6RSmGqL+zqkMu8tR3gXldevOkIZECa77MT3cRD7a1fh20uWvvn/FyU1WP0efb6nPH+ZwGGLNhbiaUtdk9I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1718877399; h=Content-Type: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=5vNRpvyeREGd2+Es2hiS7dffvsmxbIt4ClxNcgU2ADU=; b=TxQyhiPHsHD7C7T/MTWBOrTdn/adGWWQAnwG7OR6mLt91F6+a9e/7kcb1HwcKAsyuPrjM7Pt3q7CbK8bMjrpKayVf7ycicpIiVYVZeQv4radqcQbgVw0XqMQlyBarZh4jvMcGfVHYcd15ugyrjmMboMWDaH4TU/VO9RgLDn28F8= 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 1718877399291904.0862330520514; Thu, 20 Jun 2024 02:56:39 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sKEVN-0002Ro-0B; Thu, 20 Jun 2024 05:54:57 -0400 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 1sKEVI-0002Nr-Gi for qemu-devel@nongnu.org; Thu, 20 Jun 2024 05:54:53 -0400 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 1sKEVG-0005Uu-HH for qemu-devel@nongnu.org; Thu, 20 Jun 2024 05:54:52 -0400 Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-94-fb6hg6TwOEa5LZJ0LCA5wQ-1; Thu, 20 Jun 2024 05:54:48 -0400 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-a6def6e9ef2so171271366b.0 for ; Thu, 20 Jun 2024 02:54:48 -0700 (PDT) Received: from avogadro.local ([151.62.196.71]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a6f56ed3690sm752612166b.128.2024.06.20.02.54.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 02:54:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718877289; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5vNRpvyeREGd2+Es2hiS7dffvsmxbIt4ClxNcgU2ADU=; b=NSaz37lXXS+qO+PROB4u7cxRBubrrjkF3HO1FLoTUrI9FOO8gZb9ze1EkiGxmb8ywOZpai bplooe14dt6L/NHX+Dhd2oCfgKGa6eKGZNt3GKdE/lCpceSHQ/uPD1t7YKVj4ZhynXDWBH FSErAKjrJc2wZTNxP+NdrL9OEnu+Trs= X-MC-Unique: fb6hg6TwOEa5LZJ0LCA5wQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718877286; x=1719482086; 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=5vNRpvyeREGd2+Es2hiS7dffvsmxbIt4ClxNcgU2ADU=; b=jHosLTjZFNeqV3QtI78zKU2jL/nQE8sEDTYUHbv03wBv8zqtyE1r4H9Zz/5XsaWS/E 19QJBEVE0TdOGUTPxsvfW1RNX/KaGPSZ3AHkth/qUHfPxqhJSKbEDWnBZBOMQ9XxMzFS ief/pjdQe+dDRHdBdDCq4sgYBEs/7/D8TpfBVUQCkSDeCkK022EUGolVPv9vWOOD10eF cbMM27LHm3/HrykhhZ3sHAsx2eRe3Yy+T8rshau9GoRzoAgYmVJAN5ejr4ndLEGLfFm2 Vi1tmtzAhdFkVI51BGRFn4Npc2YNJRLK9TQ2AQllaIyD+9Wi3QNOilnZcb5M4GtZruox id9Q== X-Gm-Message-State: AOJu0YzVDZCX/HeSDKw1SbChsYSsYU7SA6AcfMZOMIcPjktmUuWtUn9+ l3Bpkrg3f6aqCN+LiqU0a3mUCLqb0VJpxYvzt5TzJqdY0GLY6sw12DqCx25Ib+hLhy0RsX5cCqv t9WPXYCqGBs36oTYLgmy2vHhNWrU2jFSTIVbVb8Gnfhb+GThFkYZX8Vd6mwv/j6XLH4VmIXFO91 TBzwZ1dsGhyQUqgi2Hi9u8/9NjpGHHk15YfaFn X-Received: by 2002:a17:906:ba84:b0:a6f:47c0:d8f2 with SMTP id a640c23a62f3a-a6fa430eeb9mr326710566b.17.1718877286567; Thu, 20 Jun 2024 02:54:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IENmVgcmb1wSDEp5PrylKItlNjOc8nB/OmezbgZ8+QbIRRfjYhWBBJwnhHa5lUI9FSCVapBew== X-Received: by 2002:a17:906:ba84:b0:a6f:47c0:d8f2 with SMTP id a640c23a62f3a-a6fa430eeb9mr326709366b.17.1718877286158; Thu, 20 Jun 2024 02:54:46 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Richard Henderson Subject: [PATCH 09/10] target/i386: assert that cc_op* and pc_save are preserved Date: Thu, 20 Jun 2024 11:54:18 +0200 Message-ID: <20240620095419.386958-10-pbonzini@redhat.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240620095419.386958-1-pbonzini@redhat.com> References: <20240620095419.386958-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: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.144, 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: 1718877400648100015 Content-Type: text/plain; charset="utf-8" Now all decoding has been done before any code generation. There is no need anymore to save and restore cc_op* and pc_save but, for the time being, assert that this is indeed the case. Reviewed-by: Richard Henderson Signed-off-by: Paolo Bonzini --- target/i386/tcg/translate.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index 501a1ef9313..d11c5e1dc13 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -3709,15 +3709,9 @@ static void i386_tr_translate_insn(DisasContextBase = *dcbase, CPUState *cpu) case 2: /* Restore state that may affect the next instruction. */ dc->pc =3D dc->base.pc_next; - /* - * TODO: These save/restore can be removed after the table-based - * decoder is complete; we will be decoding the insn completely - * before any code generation that might affect these variables. - */ - dc->cc_op_dirty =3D orig_cc_op_dirty; - dc->cc_op =3D orig_cc_op; - dc->pc_save =3D orig_pc_save; - /* END TODO */ + assert(dc->cc_op_dirty =3D=3D orig_cc_op_dirty); + assert(dc->cc_op =3D=3D orig_cc_op); + assert(dc->pc_save =3D=3D orig_pc_save); dc->base.num_insns--; tcg_remove_ops_after(dc->prev_insn_end); dc->base.insn_start =3D dc->prev_insn_start; --=20 2.45.2 From nobody Mon Nov 25 02:08:55 2024 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=1718877396; cv=none; d=zohomail.com; s=zohoarc; b=gp00ObgTTf4TbBavMffuG13NH8RwZfwL2EUSuzaz2wiasJHD0jGWpSVYlYL9tiS+e3ps5N+QuA9sGSnCV+fmLHfhu+ed/9+tvBWDzRTtvZcMOs99Q8M3LqrPFSJ/9iXnL+zEnJhFWqAE59EasEyPOiC7l1C0YTnHZX2Ox7nYOIQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1718877396; h=Content-Type: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=EbIvh5b7KQ5TRyXSWuEts9KNlhisXZ5PWf3o2CP+6Cg=; b=coXZYnJHHc2fGqddzUriZRcc+v/TrB9CVSW2rNGfNdWiM0j++japqyXE7/+57QSyasTvUk5w/uSnGJMzTIRz4e4f0/elE08KrlCGP2L7uCotDHDL5Z3+N8nwR9Tr0gC9SHsE2WccK4vYvXiHrxR9Vb4EO8gGHxw/J1O40LiebO8= 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 1718877396697399.8595351439901; Thu, 20 Jun 2024 02:56:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sKEVV-0002lA-Ff; Thu, 20 Jun 2024 05:55:05 -0400 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 1sKEVP-0002dO-FZ for qemu-devel@nongnu.org; Thu, 20 Jun 2024 05:55:00 -0400 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 1sKEVN-0005Wd-RV for qemu-devel@nongnu.org; Thu, 20 Jun 2024 05:54:59 -0400 Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-252-IxVW090qPyypyXcdt51uWA-1; Thu, 20 Jun 2024 05:54:51 -0400 Received: by mail-ed1-f72.google.com with SMTP id 4fb4d7f45d1cf-57d1f998b44so704719a12.0 for ; Thu, 20 Jun 2024 02:54:50 -0700 (PDT) Received: from avogadro.local ([151.62.196.71]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-57cb743890dsm9466090a12.83.2024.06.20.02.54.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 02:54:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718877297; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EbIvh5b7KQ5TRyXSWuEts9KNlhisXZ5PWf3o2CP+6Cg=; b=Ns1jD6YRgQfyry2V1qoEMhUH4YDymE1Qtz1DS9ZLl/rcPf6FYIBgKRgwXU+NLViq0bb1mw aOP9xzSEESz7YKh4TD2iluQ0JePuqnkSZCFyoQnZ+qGcZxha0Mx2QgYhVQrpBuL7CnvizQ YvS3STDG/ZPeZbXYUM23HgCtUPq/Kvs= X-MC-Unique: IxVW090qPyypyXcdt51uWA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718877289; x=1719482089; 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=EbIvh5b7KQ5TRyXSWuEts9KNlhisXZ5PWf3o2CP+6Cg=; b=S7vbSgGpsW0T6+Z2blnR4+2l/m9SLekgLPaxdBZdFOwSzgf6dr1/ifxdYXXDzI4OE1 7YLvdkKaGeCT93N+fUqWB76oj2PXdlikX9Yy5j1Ljddvf+I2VB2gyHb/TJnGG0S1wzgV o1Pi+OnLbfVoz+Jxf85NJOPUGXDcnA4UzG2oJJfCJFgUKOl8c05embG3Us8/d+zULI2/ WE03IuqZl167I800Gquu/S0IEpzM3XgMOwhcmLPGgo4+fuCJwS7H55HPOOtewxDziAHj Mq4b35i1pxlA1kCGVKQZCvGUew5+XlDDzCR+ku3IdaBBHjztfEBpD0OCuQVC6htrQrVV fJsw== X-Gm-Message-State: AOJu0YyEreathH2tlZhEKEllgX4K8ezV8mRdLleEhBSKN+aw6ygUstG/ do1nVnQ0tgRiRWPpyzxyIEDoNdMx1+dXDB5sB5myehcGVgbtbb9ZPsNxjHr0gYNOU/P7OQAdqeV Fjie5zQt/47NcethihjdFwoZQuj5JD4G10ePEcxI+NPoDMIAK/jxWYQwdMNSr/Gtc+86fC1qE/W HnWm9RAl90etrzwag9zTh+u41iuts83KhEaRLZ X-Received: by 2002:aa7:c315:0:b0:57d:1b21:1a25 with SMTP id 4fb4d7f45d1cf-57d1b211a76mr2045144a12.15.1718877289075; Thu, 20 Jun 2024 02:54:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFL68UWU2cO0MkRCzMl81MIIDL9bH37FneN/XgDJ5P76z5w1ELkfC/vQnB5fnlMuJp+NR1fIw== X-Received: by 2002:aa7:c315:0:b0:57d:1b21:1a25 with SMTP id 4fb4d7f45d1cf-57d1b211a76mr2045133a12.15.1718877288732; Thu, 20 Jun 2024 02:54:48 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Richard Henderson Subject: [PATCH 10/10] target/i386: remove gen_ext_tl Date: Thu, 20 Jun 2024 11:54:19 +0200 Message-ID: <20240620095419.386958-11-pbonzini@redhat.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240620095419.386958-1-pbonzini@redhat.com> References: <20240620095419.386958-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: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.144, 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: 1718877398670100011 Content-Type: text/plain; charset="utf-8" With the introduction of tcg_gen_ext_tl, most uses can be converted directly because they do not have a NULL destination. tcg_gen_ext_tl is able to drop no-ops like "tcg_gen_ext_tl(tcgv, tcgv, MO_TL)" just fine, and the only thi= ng that gen_ext_tl was adding on top was avoiding the creation of a useless temporary. This can be done in the only place where it matters, which is gen_op_j_ecx. Reviewed-by: Richard Henderson Signed-off-by: Paolo Bonzini --- target/i386/tcg/translate.c | 41 +++++++++++++++---------------------- 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index d11c5e1dc13..5c9c992400e 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -697,23 +697,16 @@ static inline TCGv gen_compute_Dshift(DisasContext *s= , MemOp ot) return dshift; }; =20 -static TCGv gen_ext_tl(TCGv dst, TCGv src, MemOp size, bool sign) -{ - if (size =3D=3D MO_TL) { - return src; - } - if (!dst) { - dst =3D tcg_temp_new(); - } - tcg_gen_ext_tl(dst, src, size | (sign ? MO_SIGN : 0)); - return dst; -} - static void gen_op_j_ecx(DisasContext *s, TCGCond cond, TCGLabel *label1) { - TCGv tmp =3D gen_ext_tl(NULL, cpu_regs[R_ECX], s->aflag, false); - - tcg_gen_brcondi_tl(cond, tmp, 0, label1); + TCGv lhs; + if (s->aflag =3D=3D MO_TL) { + lhs =3D cpu_regs[R_ECX]; + } else { + lhs =3D tcg_temp_new(); + tcg_gen_ext_tl(lhs, cpu_regs[R_ECX], s->aflag); + } + tcg_gen_brcondi_tl(cond, lhs, 0, label1); } =20 static inline void gen_op_jz_ecx(DisasContext *s, TCGLabel *label1) @@ -886,16 +879,16 @@ static CCPrepare gen_prepare_eflags_c(DisasContext *s= , TCGv reg) case CC_OP_SUBB ... CC_OP_SUBQ: /* (DATA_TYPE)CC_SRCT < (DATA_TYPE)CC_SRC */ size =3D s->cc_op - CC_OP_SUBB; - gen_ext_tl(s->cc_srcT, s->cc_srcT, size, false); - gen_ext_tl(cpu_cc_src, cpu_cc_src, size, false); + tcg_gen_ext_tl(s->cc_srcT, s->cc_srcT, size); + tcg_gen_ext_tl(cpu_cc_src, cpu_cc_src, size); return (CCPrepare) { .cond =3D TCG_COND_LTU, .reg =3D s->cc_srcT, .reg2 =3D cpu_cc_src, .use_reg2 =3D true }; =20 case CC_OP_ADDB ... CC_OP_ADDQ: /* (DATA_TYPE)CC_DST < (DATA_TYPE)CC_SRC */ size =3D s->cc_op - CC_OP_ADDB; - gen_ext_tl(cpu_cc_dst, cpu_cc_dst, size, false); - gen_ext_tl(cpu_cc_src, cpu_cc_src, size, false); + tcg_gen_ext_tl(cpu_cc_dst, cpu_cc_dst, size); + tcg_gen_ext_tl(cpu_cc_src, cpu_cc_src, size); return (CCPrepare) { .cond =3D TCG_COND_LTU, .reg =3D cpu_cc_dst, .reg2 =3D cpu_cc_src, .use_reg2 =3D true }; =20 @@ -920,7 +913,7 @@ static CCPrepare gen_prepare_eflags_c(DisasContext *s, = TCGv reg) =20 case CC_OP_BMILGB ... CC_OP_BMILGQ: size =3D s->cc_op - CC_OP_BMILGB; - gen_ext_tl(cpu_cc_src, cpu_cc_src, size, false); + tcg_gen_ext_tl(cpu_cc_src, cpu_cc_src, size); return (CCPrepare) { .cond =3D TCG_COND_EQ, .reg =3D cpu_cc_src }; =20 case CC_OP_ADCX: @@ -1050,8 +1043,8 @@ static CCPrepare gen_prepare_cc(DisasContext *s, int = b, TCGv reg) size =3D s->cc_op - CC_OP_SUBB; switch (jcc_op) { case JCC_BE: - gen_ext_tl(s->cc_srcT, s->cc_srcT, size, false); - gen_ext_tl(cpu_cc_src, cpu_cc_src, size, false); + tcg_gen_ext_tl(s->cc_srcT, s->cc_srcT, size); + tcg_gen_ext_tl(cpu_cc_src, cpu_cc_src, size); cc =3D (CCPrepare) { .cond =3D TCG_COND_LEU, .reg =3D s->cc_sr= cT, .reg2 =3D cpu_cc_src, .use_reg2 =3D true }; break; @@ -1061,8 +1054,8 @@ static CCPrepare gen_prepare_cc(DisasContext *s, int = b, TCGv reg) case JCC_LE: cond =3D TCG_COND_LE; fast_jcc_l: - gen_ext_tl(s->cc_srcT, s->cc_srcT, size, true); - gen_ext_tl(cpu_cc_src, cpu_cc_src, size, true); + tcg_gen_ext_tl(s->cc_srcT, s->cc_srcT, size | MO_SIGN); + tcg_gen_ext_tl(cpu_cc_src, cpu_cc_src, size | MO_SIGN); cc =3D (CCPrepare) { .cond =3D cond, .reg =3D s->cc_srcT, .reg2 =3D cpu_cc_src, .use_reg2 =3D true }; break; --=20 2.45.2