From nobody Wed Nov 27 15:47:23 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=1697712539; cv=none; d=zohomail.com; s=zohoarc; b=OWMqo5JILn07lhUGx3kwcDgADdB+EXlvkwldPdR+lMEzH0GEIMCRITDakk+ziX9ToPzeYhlcj4PFZquESLitt+6dp+4ipESheb/B4PrF1XGOqwrnIHeG4CZDEO7fm1OzOWTa5GjLv+Eh5NErfYiOmHYmYX8m+HxVDOwJhjmDxck= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697712539; 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=Ypl19ID9rWp7SnfV9jL8pJ7ArDpt8Bkcpd7SvsYCvJI=; b=Bz7qPI/yMuKjVTXAvbbf3aZfAXn1eBplxOBs1gp9ko3NJiYEx3J4EqBe9dwZaQ6FC7UAsJI22Mr7ajZ/n9LMO1EOkDUd6YAoOU8Fgyn/bZF/8Cdt9GpcCGAWT+p1ZkXRAJbS+6ZIG3W0SFU5XkYwUW11pw5j/XQf0i1qHvsQb+4= 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 1697712539352237.85916911736115; Thu, 19 Oct 2023 03:48:59 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qtQYY-0006YR-2V; Thu, 19 Oct 2023 06:47:10 -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 1qtQYW-0006Xl-Oy for qemu-devel@nongnu.org; Thu, 19 Oct 2023 06:47:08 -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 1qtQYU-0006Dc-Tw for qemu-devel@nongnu.org; Thu, 19 Oct 2023 06:47:08 -0400 Received: from mail-lf1-f69.google.com (mail-lf1-f69.google.com [209.85.167.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-642-BeZkAr0oMxuDyh_rwzquqQ-1; Thu, 19 Oct 2023 06:46:55 -0400 Received: by mail-lf1-f69.google.com with SMTP id 2adb3069b0e04-5079630993dso6784276e87.1 for ; Thu, 19 Oct 2023 03:46:54 -0700 (PDT) Received: from [192.168.10.118] ([2001:b07:6468:f312:5e2c:eb9a:a8b6:fd3e]) by smtp.gmail.com with ESMTPSA id d29-20020a50f69d000000b0053daf92f0easm4260318edn.97.2023.10.19.03.46.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 03:46:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697712426; 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=Ypl19ID9rWp7SnfV9jL8pJ7ArDpt8Bkcpd7SvsYCvJI=; b=W1iWnJ2uYLYxWdWYlZ7qNzfATW+3erhplOB2Tg0kv5mn3zzhlgydanUkIXU2c9Izcw+3es IDq4w9mtlke+Hic5CLD6AGUi6+9kqxQP9pc+fBrFUyVDy8C2V0HKLDa6mop9aeRi83j4Ip 0R4ZuyYTNKocMTebja8chN1kz7gb3lc= X-MC-Unique: BeZkAr0oMxuDyh_rwzquqQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697712413; x=1698317213; 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=Ypl19ID9rWp7SnfV9jL8pJ7ArDpt8Bkcpd7SvsYCvJI=; b=X4928y9LB7lST0dooYaw8H5GPPGF5Qlx9JxKse0u5f6/xYd1DVm6KSzK8FSmQV7Fyv nDd92pXoflXeM3WLCfqhndvEv+8QWFxMsB562N6X0rlsFKJ/DWJWoM2xOJ2zO8U3zN56 GquJfibSkoMFyYlX6RFHHJOaBAdRIymSZzLcN7Jy5Ltr4D86hZ0zPAskt9mLfBuydQv1 e6Dtw8O04KZREWrSiDZBJfDdrwHJQ+dGHbSGkEYqo8aUTQiDP5f8XL0G+1k4xrj7fetp I5gSPGi5Qp6NQ9bx880M0W7y2eu5DJv0FDHFaPA/VO14s9oUYJ+m+B6//Ps6T2pf0z97 jklg== X-Gm-Message-State: AOJu0Yw8MvlyL3jGAlTMRMcfHSUif+e9WdPVSJ4RU3GmYE183sNrgcxw /alVCrHMhJkcmLE9a/BULlYKPyzovNa2Ly5GSFL9QcLWwW4SsF659wFU0B/U7FDAhsJVcQNT8V4 eXh08X8CTNWOpL4SIByyrwv1XlhCh05uvHyfqce/ZNmbydRaMpSlNFnRUaOwZqbmUq24OLjr5/z Y= X-Received: by 2002:a05:6512:33ce:b0:503:257a:7f5d with SMTP id d14-20020a05651233ce00b00503257a7f5dmr1365635lfg.31.1697712412813; Thu, 19 Oct 2023 03:46:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFBwFtCL67NumZflLUDy7nS/GG6pFa5pqZAzlkREcoLdgqVvSzBf8N5BDV1+sUufy4pgNOSmQ== X-Received: by 2002:a05:6512:33ce:b0:503:257a:7f5d with SMTP id d14-20020a05651233ce00b00503257a7f5dmr1365616lfg.31.1697712412248; Thu, 19 Oct 2023 03:46:52 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH v2 01/19] target/i386: group common checks in the decoding phase Date: Thu, 19 Oct 2023 12:46:30 +0200 Message-ID: <20231019104648.389942-2-pbonzini@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231019104648.389942-1-pbonzini@redhat.com> References: <20231019104648.389942-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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1697712539638100005 Content-Type: text/plain; charset="utf-8" In preparation for adding more similar checks, move the VEX.L=3D0 check and several X86_SPECIAL_* checks to a new field, where each bit represent a common check on unused bits, or a restriction on the processor mode. Likewise, many SVM intercepts can be checked during the decoding phase, the main exception being the selective CR0 write, MSR and IOIO intercepts. Signed-off-by: Paolo Bonzini Reviewed-by: Richard Henderson --- target/i386/tcg/decode-new.c.inc | 79 +++++++++++++++++++++++--------- target/i386/tcg/decode-new.h | 25 +++++++--- target/i386/tcg/emit.c.inc | 8 ---- 3 files changed, 76 insertions(+), 36 deletions(-) diff --git a/target/i386/tcg/decode-new.c.inc b/target/i386/tcg/decode-new.= c.inc index 7d76f152758..790339eaf25 100644 --- a/target/i386/tcg/decode-new.c.inc +++ b/target/i386/tcg/decode-new.c.inc @@ -90,8 +90,6 @@ X86_OP_ENTRY3(op, None, None, None, None, None, None, ## __VA_ARGS__) =20 #define cpuid(feat) .cpuid =3D X86_FEAT_##feat, -#define i64 .special =3D X86_SPECIAL_i64, -#define o64 .special =3D X86_SPECIAL_o64, #define xchg .special =3D X86_SPECIAL_Locked, #define mmx .special =3D X86_SPECIAL_MMX, #define zext0 .special =3D X86_SPECIAL_ZExtOp0, @@ -114,6 +112,9 @@ #define vex12 .vex_class =3D 12, #define vex13 .vex_class =3D 13, =20 +#define chk(a) .check =3D X86_CHECK_##a, +#define svm(a) .intercept =3D SVM_EXIT_##a, + #define avx2_256 .vex_special =3D X86_VEX_AVX2_256, =20 #define P_00 1 @@ -161,8 +162,8 @@ static void decode_group15(DisasContext *s, CPUX86State= *env, X86OpEntry *entry, }; =20 static const X86OpEntry group15_mem[8] =3D { - [2] =3D X86_OP_ENTRYr(LDMXCSR, E,d, vex5), - [3] =3D X86_OP_ENTRYw(STMXCSR, E,d, vex5), + [2] =3D X86_OP_ENTRYr(LDMXCSR, E,d, vex5 chk(VEX128)), + [3] =3D X86_OP_ENTRYw(STMXCSR, E,d, vex5 chk(VEX128)), }; =20 uint8_t modrm =3D get_modrm(s, env); @@ -1579,6 +1580,12 @@ static bool validate_vex(DisasContext *s, X86Decoded= Insn *decode) if (s->flags & HF_EM_MASK) { goto illegal; } + + if (e->check & X86_CHECK_VEX128) { + if (s->vex_l) { + goto illegal; + } + } return true; =20 nm_exception: @@ -1764,6 +1771,25 @@ static void disas_insn_new(DisasContext *s, CPUState= *cpu, int b) goto illegal_op; } =20 + /* Checks that result in #UD come first. */ + if (decode.e.check) { + if (decode.e.check & X86_CHECK_i64) { + if (CODE64(s)) { + goto illegal_op; + } + } + if (decode.e.check & X86_CHECK_o64) { + if (!CODE64(s)) { + goto illegal_op; + } + } + if (decode.e.check & X86_CHECK_prot) { + if (!PE(s) || VM86(s)) { + goto illegal_op; + } + } + } + switch (decode.e.special) { case X86_SPECIAL_None: break; @@ -1774,23 +1800,6 @@ static void disas_insn_new(DisasContext *s, CPUState= *cpu, int b) } break; =20 - case X86_SPECIAL_ProtMode: - if (!PE(s) || VM86(s)) { - goto illegal_op; - } - break; - - case X86_SPECIAL_i64: - if (CODE64(s)) { - goto illegal_op; - } - break; - case X86_SPECIAL_o64: - if (!CODE64(s)) { - goto illegal_op; - } - break; - case X86_SPECIAL_ZExtOp0: assert(decode.op[0].unit =3D=3D X86_OP_INT); if (!decode.op[0].has_ea) { @@ -1820,6 +1829,31 @@ static void disas_insn_new(DisasContext *s, CPUState= *cpu, int b) if (!validate_vex(s, &decode)) { return; } + + /* + * Checks that result in #GP or VMEXIT come second. Intercepts are + * generally checked after non-memory exceptions (i.e. before all + * exceptions if there is no memory operand). Exceptions are + * vm86 checks (INTn, IRET, PUSHF/POPF), RSM and XSETBV (!). + * + * RSM and XSETBV will be handled in the gen_* functions + * instead of using chk(). + */ + if (decode.e.check & X86_CHECK_cpl0) { + if (CPL(s) !=3D 0) { + goto gp_fault; + } + } + if (decode.e.intercept && unlikely(GUEST(s))) { + gen_helper_svm_check_intercept(tcg_env, + tcg_constant_i32(decode.e.intercept= )); + } + if (decode.e.check & X86_CHECK_vm86_iopl) { + if (VM86(s) && IOPL(s) < 3) { + goto gp_fault; + } + } + if (decode.e.special =3D=3D X86_SPECIAL_MMX && !(s->prefix & (PREFIX_REPZ | PREFIX_REPNZ | PREFIX_DATA))) { gen_helper_enter_mmx(tcg_env); @@ -1846,6 +1880,9 @@ static void disas_insn_new(DisasContext *s, CPUState = *cpu, int b) gen_writeback(s, &decode, 0, s->T0); } return; + gp_fault: + gen_exception_gpf(s); + return; illegal_op: gen_illegal_opcode(s); return; diff --git a/target/i386/tcg/decode-new.h b/target/i386/tcg/decode-new.h index a542ec16813..631d39220bb 100644 --- a/target/i386/tcg/decode-new.h +++ b/target/i386/tcg/decode-new.h @@ -130,15 +130,28 @@ typedef enum X86OpUnit { X86_OP_MMX, /* address in either s->ptrX or s->A0 depending on has= _ea */ } X86OpUnit; =20 +typedef enum X86InsnCheck { + /* Illegal or exclusive to 64-bit mode */ + X86_CHECK_i64 =3D 1, + X86_CHECK_o64 =3D 2, + + /* Fault outside protected mode */ + X86_CHECK_prot =3D 4, + + /* Privileged instruction checks */ + X86_CHECK_cpl0 =3D 8, + X86_CHECK_vm86_iopl =3D 16, + + /* Fault if VEX.L=3D1 */ + X86_CHECK_VEX128 =3D 32, +} X86InsnCheck; + typedef enum X86InsnSpecial { X86_SPECIAL_None, =20 /* Always locked if it has a memory operand (XCHG) */ X86_SPECIAL_Locked, =20 - /* Fault outside protected mode */ - X86_SPECIAL_ProtMode, - /* * Register operand 0/2 is zero extended to 32 bits. Rd/Mb or Rd/Mw * in the manual. @@ -157,10 +170,6 @@ typedef enum X86InsnSpecial { * become P/P/Q/N, and size "x" becomes "q". */ X86_SPECIAL_MMX, - - /* Illegal or exclusive to 64-bit mode */ - X86_SPECIAL_i64, - X86_SPECIAL_o64, } X86InsnSpecial; =20 /* @@ -224,6 +233,8 @@ struct X86OpEntry { unsigned vex_class:8; X86VEXSpecial vex_special:8; uint16_t valid_prefix:16; + uint8_t check:8; + uint8_t intercept:8; bool is_decode:1; }; =20 diff --git a/target/i386/tcg/emit.c.inc b/target/i386/tcg/emit.c.inc index 88793ba988d..7c36cf8a6df 100644 --- a/target/i386/tcg/emit.c.inc +++ b/target/i386/tcg/emit.c.inc @@ -1236,10 +1236,6 @@ static void gen_INSERTQ_r(DisasContext *s, CPUX86Sta= te *env, X86DecodedInsn *dec =20 static void gen_LDMXCSR(DisasContext *s, CPUX86State *env, X86DecodedInsn = *decode) { - if (s->vex_l) { - gen_illegal_opcode(s); - return; - } tcg_gen_trunc_tl_i32(s->tmp2_i32, s->T1); gen_helper_ldmxcsr(tcg_env, s->tmp2_i32); } @@ -1832,10 +1828,6 @@ static void gen_VAESKEYGEN(DisasContext *s, CPUX86St= ate *env, X86DecodedInsn *de =20 static void gen_STMXCSR(DisasContext *s, CPUX86State *env, X86DecodedInsn = *decode) { - if (s->vex_l) { - gen_illegal_opcode(s); - return; - } gen_helper_update_mxcsr(tcg_env); tcg_gen_ld32u_tl(s->T0, tcg_env, offsetof(CPUX86State, mxcsr)); } --=20 2.41.0 From nobody Wed Nov 27 15:47:23 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=1697712505; cv=none; d=zohomail.com; s=zohoarc; b=LGk0L7S0d+0DVBRAOHJDmsk5awgHoxSPal0YSV5uKoQSj610jrIxIqVTuxORuHQ7s5xNrbnX4QKDnbuMr+GGwN/aiKXJkiz+ehol8sAjy/zgLqdRZ+FfaFAMDUac3NZYF3e3wN5KxnJ43wG/NX7DP4GIuXAj60O3c0c6+xwWCEI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697712505; 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=QFLukNUS7TwhCPaS3HQhDICPcAy2Wkea09tTCaxB9eE=; b=Vqprrg9MpH9mWldgW4dSUWOjUgGKSuOMdM+NenAk0drL0MVUWi+tZ5VHlXXHw47YrrTOvd5Q7VWY19v2E4A0kv734q6CVpiOzLXWTUCixi2TSqK07H2syrt7XgN8GbQYrXvbRkP9wObRfJU1pdjMAwINxfqZR1Mhli9mhyPnMgg= 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 1697712505522812.3160047637132; Thu, 19 Oct 2023 03:48:25 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qtQYW-0006X4-63; Thu, 19 Oct 2023 06:47:08 -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 1qtQYP-0006FO-Uo for qemu-devel@nongnu.org; Thu, 19 Oct 2023 06:47:04 -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 1qtQYN-0006CE-99 for qemu-devel@nongnu.org; Thu, 19 Oct 2023 06:47:01 -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-641-En7GdAJlMc-SHW-j_WbPRQ-1; Thu, 19 Oct 2023 06:46:56 -0400 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-9ba247e03aeso548530166b.1 for ; Thu, 19 Oct 2023 03:46:56 -0700 (PDT) Received: from [192.168.10.118] ([2001:b07:6468:f312:5e2c:eb9a:a8b6:fd3e]) by smtp.gmail.com with ESMTPSA id lh22-20020a170906f8d600b009b94c545678sm3270289ejb.153.2023.10.19.03.46.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 03:46:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697712417; 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=QFLukNUS7TwhCPaS3HQhDICPcAy2Wkea09tTCaxB9eE=; b=UU5wuzu3pPl6nbtKXihkHM0sn7huKlreMgBHthY4aFyX+Ri0r1tATrR+M10bN2fEYuIbpA BC/W3PjQeHvdRmsJNimohY2r8V1h4ELYqgZ5YpezAcyezM1JHy+FwRZBbpaym6W3vGyQHS D01TJLymw46gbAhsBgjW9wfQDIUXJqU= X-MC-Unique: En7GdAJlMc-SHW-j_WbPRQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697712414; x=1698317214; 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=QFLukNUS7TwhCPaS3HQhDICPcAy2Wkea09tTCaxB9eE=; b=HHtw5vGKMnkOcv5smGqODCNCAtV5boalcMB5D3FvL7DsC2gKrq9Qy1/h+irIYBlDZ2 vvtliPEb/GaR0pFmmp6+PO4islElAGmSe4IzMf5Y8mGj/YIptp1nMYEHoGiIoAIxi50t Y7xFuJNUOXIUD0kAGvlYJDyrUN3+ysQilXV7wDOrB8wyrUi1+WrcsZ0hsRvLbcyK7XMM BeHPdO14mn2y9IAyikFiJ1dYU20+rUQn8/vGQy3V3UXQUMBvdOG8CC3/nyFzabm4g7Te F5l2gSc0XntP9/z/RBdxzoBxXSOelQo4vYYb/8wHs/iUeqACeD/ZCkJ6XO72UC+ly+Kh VZHw== X-Gm-Message-State: AOJu0Yyc8TXAgqzM4Fw1zv1ByRzEiksC4QY3jRJrdu8uOZO5A+Dnzd+9 PXUYi3CxPxLPdKKRbDODQsEsqMfJ6TKbu0QRBy7RXwF2uRtToPpI9XHmbVdykmMLB5rB9i/TjHj 9CsBnaZ0OOsVFXmsBurLOlYM9OdJvrlG8ABUzKW9EtvwtcGli/zApzM2UUycwrtPUfAU4OawKL+ U= X-Received: by 2002:a17:907:a0b:b0:9c3:e158:316a with SMTP id bb11-20020a1709070a0b00b009c3e158316amr1421015ejc.68.1697712414275; Thu, 19 Oct 2023 03:46:54 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFMEykUrgLruNoEpOvG6cKU6BjQGmBhr2HT4ovXHzZPrU9xcBFHiFwn8kKjnfw89WYlr0LRBw== X-Received: by 2002:a17:907:a0b:b0:9c3:e158:316a with SMTP id bb11-20020a1709070a0b00b009c3e158316amr1420988ejc.68.1697712413553; Thu, 19 Oct 2023 03:46:53 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH v2 02/19] target/i386: validate VEX.W for AVX instructions Date: Thu, 19 Oct 2023 12:46:31 +0200 Message-ID: <20231019104648.389942-3-pbonzini@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231019104648.389942-1-pbonzini@redhat.com> References: <20231019104648.389942-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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 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: 1697712507518100003 Instructions in VEX exception class 6 generally look at the value of VEX.W. Note that the manual places some instructions incorrectly in class 4, for example VPERMQ which has no non-VEX encoding and no legacy SSE analogue. AMD does a mess of its own, as documented in the comment that this patch adds. Most of them are checked for VEX.W=3D0, and are listed in the manual (though with an omission) in table 2-16; VPERMQ and VPERMPD check for VEX.W=3D1, which is only listed in the instruction description. Others, such as VPSRLV, VPSLLV and the FMA3 instructions, use VEX.W to switch between a 32-bit and 64-bit operation. Fix more of the class 4/class 6 mismatches, and implement the check for VEX.W in TCG. Signed-off-by: Paolo Bonzini Acked-by: Richard Henderson --- target/i386/tcg/decode-new.c.inc | 133 +++++++++++++++++++++---------- target/i386/tcg/decode-new.h | 6 ++ 2 files changed, 99 insertions(+), 40 deletions(-) diff --git a/target/i386/tcg/decode-new.c.inc b/target/i386/tcg/decode-new.= c.inc index 790339eaf25..850271e0898 100644 --- a/target/i386/tcg/decode-new.c.inc +++ b/target/i386/tcg/decode-new.c.inc @@ -43,6 +43,47 @@ * There are a couple cases in which instructions (e.g. MOVD) write the * whole XMM or MM register but are established incorrectly in the manual * as "d" or "q". These have to be fixed for the decoder to work correctl= y. + * + * Speaking about imprecisions in the manual, the decoder treats all + * exception-class 4 instructions as having an optional VEX prefix, and + * all exception-class 6 instructions as having a mandatory VEX prefix. + * This is true except for a dozen instructions; these are in exception + * class 4 but do not ignore the VEX.W bit (which does not even exist + * without a VEX prefix). These instructions are mostly listed in Intel's + * table 2-16, but with a few exceptions. + * + * The AMD manual has more precise subclasses for exceptions, and unlike I= ntel + * they list the VEX.W requirements in the exception classes as well (exce= pt + * when they don't). AMD describes class 6 as "AVX Mixed Memory Argument" + * without defining what a mixed memory argument is, but still use 4 as the + * primary exception class... except when they don't. + * + * The summary is: + * Intel AMD VEX.W note + * ------------------------------------------------------------------- + * vpblendd 4 4J 0 + * vpblendvb 4 4E-X 0 (*) + * vpbroadcastq 6 6D 0 (+) + * vpermd/vpermps 4 4H 0 (=C2=A7) + * vpermq/vpermpd 4 4H-1 1 (=C2=A7) + * vpermilpd/vpermilps 4 6E 0 (^) + * vpmaskmovd 6 4K significant (^) + * vpsllv 4 4K significant + * vpsrav 4 4J 0 + * vpsrlv 4 4K significant + * vtestps/vtestpd 4 4G 0 + * + * (*) AMD lists VPBLENDVB as related to SSE4.1 PBLENDVB, which may + * explain why it is considered exception class 4. However, + * Intel says that VEX-only instructions should be in class 6... + * + * (+) Not found in Intel's table 2-16 + * + * (=C2=A7) 4H and 4H-1 do not mention VEX.W requirements, which are + * however present in the description of the instruction + * + * (^) these are the two cases in which Intel and AMD disagree on the + * primary exception class */ =20 #define X86_OP_NONE { 0 }, @@ -338,11 +379,11 @@ static const X86OpEntry opcodes_0F38_00toEF[240] =3D { [0x07] =3D X86_OP_ENTRY3(PHSUBSW, V,x, H,x, W,x, vex4 cpuid(SSSE= 3) mmx avx2_256 p_00_66), =20 [0x10] =3D X86_OP_ENTRY2(PBLENDVB, V,x, W,x, vex4 cpuid(SSE4= 1) avx2_256 p_66), - [0x13] =3D X86_OP_ENTRY2(VCVTPH2PS, V,x, W,xh, vex11 cpuid(F16= C) p_66), + [0x13] =3D X86_OP_ENTRY2(VCVTPH2PS, V,x, W,xh, vex11 chk(W0) c= puid(F16C) p_66), [0x14] =3D X86_OP_ENTRY2(BLENDVPS, V,x, W,x, vex4 cpuid(SSE4= 1) p_66), [0x15] =3D X86_OP_ENTRY2(BLENDVPD, V,x, W,x, vex4 cpuid(SSE4= 1) p_66), /* Listed incorrectly as type 4 */ - [0x16] =3D X86_OP_ENTRY3(VPERMD, V,qq, H,qq, W,qq, vex6 cpuid= (AVX2) p_66), + [0x16] =3D X86_OP_ENTRY3(VPERMD, V,qq, H,qq, W,qq, vex6 chk(W= 0) cpuid(AVX2) p_66), /* vpermps */ [0x17] =3D X86_OP_ENTRY3(VPTEST, None,None, V,x, W,x, vex4 cpuid= (SSE41) p_66), =20 /* @@ -363,14 +404,14 @@ static const X86OpEntry opcodes_0F38_00toEF[240] =3D { [0x33] =3D X86_OP_ENTRY3(VPMOVZXWD, V,x, None,None, W,q, vex5 cpuid= (SSE41) avx_movx avx2_256 p_66), [0x34] =3D X86_OP_ENTRY3(VPMOVZXWQ, V,x, None,None, W,d, vex5 cpuid= (SSE41) avx_movx avx2_256 p_66), [0x35] =3D X86_OP_ENTRY3(VPMOVZXDQ, V,x, None,None, W,q, vex5 cpuid= (SSE41) avx_movx avx2_256 p_66), - [0x36] =3D X86_OP_ENTRY3(VPERMD, V,qq, H,qq, W,qq, vex6 cpuid= (AVX2) p_66), + [0x36] =3D X86_OP_ENTRY3(VPERMD, V,qq, H,qq, W,qq, vex6 chk(W= 0) cpuid(AVX2) p_66), [0x37] =3D X86_OP_ENTRY3(PCMPGTQ, V,x, H,x, W,x, vex4 cpuid= (SSE42) avx2_256 p_66), =20 [0x40] =3D X86_OP_ENTRY3(PMULLD, V,x, H,x, W,x, vex4 cpui= d(SSE41) avx2_256 p_66), [0x41] =3D X86_OP_ENTRY3(VPHMINPOSUW, V,dq, None,None, W,dq, vex4 cpui= d(SSE41) p_66), /* Listed incorrectly as type 4 */ [0x45] =3D X86_OP_ENTRY3(VPSRLV, V,x, H,x, W,x, vex6 cpui= d(AVX2) p_66), - [0x46] =3D X86_OP_ENTRY3(VPSRAV, V,x, H,x, W,x, vex6 cpui= d(AVX2) p_66), + [0x46] =3D X86_OP_ENTRY3(VPSRAV, V,x, H,x, W,x, vex6 chk(= W0) cpuid(AVX2) p_66), [0x47] =3D X86_OP_ENTRY3(VPSLLV, V,x, H,x, W,x, vex6 cpui= d(AVX2) p_66), =20 [0x90] =3D X86_OP_ENTRY3(VPGATHERD, V,x, H,x, M,d, vex12 cpuid(AVX2= ) p_66), /* vpgatherdd/q */ @@ -392,14 +433,15 @@ static const X86OpEntry opcodes_0F38_00toEF[240] =3D { [0x09] =3D X86_OP_ENTRY3(PSIGNW, V,x, H,x, W,x, vex4 cpuid= (SSSE3) mmx avx2_256 p_00_66), [0x0a] =3D X86_OP_ENTRY3(PSIGND, V,x, H,x, W,x, vex4 cpuid= (SSSE3) mmx avx2_256 p_00_66), [0x0b] =3D X86_OP_ENTRY3(PMULHRSW, V,x, H,x, W,x, vex4 cpuid= (SSSE3) mmx avx2_256 p_00_66), - [0x0c] =3D X86_OP_ENTRY3(VPERMILPS, V,x, H,x, W,x, vex4 cpuid= (AVX) p_00_66), - [0x0d] =3D X86_OP_ENTRY3(VPERMILPD, V,x, H,x, W,x, vex4 cpuid= (AVX) p_66), - [0x0e] =3D X86_OP_ENTRY3(VTESTPS, None,None, V,x, W,x, vex4 cpuid= (AVX) p_66), - [0x0f] =3D X86_OP_ENTRY3(VTESTPD, None,None, V,x, W,x, vex4 cpuid= (AVX) p_66), + /* Listed incorrectly as type 4 */ + [0x0c] =3D X86_OP_ENTRY3(VPERMILPS, V,x, H,x, W,x, vex6 chk(W= 0) cpuid(AVX) p_00_66), + [0x0d] =3D X86_OP_ENTRY3(VPERMILPD, V,x, H,x, W,x, vex6 chk(W= 0) cpuid(AVX) p_66), + [0x0e] =3D X86_OP_ENTRY3(VTESTPS, None,None, V,x, W,x, vex6 chk(W= 0) cpuid(AVX) p_66), + [0x0f] =3D X86_OP_ENTRY3(VTESTPD, None,None, V,x, W,x, vex6 chk(W= 0) cpuid(AVX) p_66), =20 - [0x18] =3D X86_OP_ENTRY3(VPBROADCASTD, V,x, None,None, W,d, vex6 c= puid(AVX) p_66), /* vbroadcastss */ - [0x19] =3D X86_OP_ENTRY3(VPBROADCASTQ, V,qq, None,None, W,q, vex6 c= puid(AVX) p_66), /* vbroadcastsd */ - [0x1a] =3D X86_OP_ENTRY3(VBROADCASTx128, V,qq, None,None, WM,dq,vex6 c= puid(AVX) p_66), + [0x18] =3D X86_OP_ENTRY3(VPBROADCASTD, V,x, None,None, W,d, vex6 c= hk(W0) cpuid(AVX) p_66), /* vbroadcastss */ + [0x19] =3D X86_OP_ENTRY3(VPBROADCASTQ, V,qq, None,None, W,q, vex6 c= hk(W0) cpuid(AVX) p_66), /* vbroadcastsd */ + [0x1a] =3D X86_OP_ENTRY3(VBROADCASTx128, V,qq, None,None, WM,dq,vex6 c= hk(W0) cpuid(AVX) p_66), [0x1c] =3D X86_OP_ENTRY3(PABSB, V,x, None,None, W,x, vex4 c= puid(SSSE3) mmx avx2_256 p_00_66), [0x1d] =3D X86_OP_ENTRY3(PABSW, V,x, None,None, W,x, vex4 c= puid(SSSE3) mmx avx2_256 p_00_66), [0x1e] =3D X86_OP_ENTRY3(PABSD, V,x, None,None, W,x, vex4 c= puid(SSSE3) mmx avx2_256 p_00_66), @@ -408,11 +450,11 @@ static const X86OpEntry opcodes_0F38_00toEF[240] =3D { [0x29] =3D X86_OP_ENTRY3(PCMPEQQ, V,x, H,x, W,x, vex4 cpu= id(SSE41) avx2_256 p_66), [0x2a] =3D X86_OP_ENTRY3(MOVDQ, V,x, None,None, WM,x, vex1 cpu= id(SSE41) avx2_256 p_66), /* movntdqa */ [0x2b] =3D X86_OP_ENTRY3(VPACKUSDW, V,x, H,x, W,x, vex4 cpu= id(SSE41) avx2_256 p_66), - [0x2c] =3D X86_OP_ENTRY3(VMASKMOVPS, V,x, H,x, WM,x, vex6 cpu= id(AVX) p_66), - [0x2d] =3D X86_OP_ENTRY3(VMASKMOVPD, V,x, H,x, WM,x, vex6 cpu= id(AVX) p_66), + [0x2c] =3D X86_OP_ENTRY3(VMASKMOVPS, V,x, H,x, WM,x, vex6 chk= (W0) cpuid(AVX) p_66), + [0x2d] =3D X86_OP_ENTRY3(VMASKMOVPD, V,x, H,x, WM,x, vex6 chk= (W0) cpuid(AVX) p_66), /* Incorrectly listed as Mx,Hx,Vx in the manual */ - [0x2e] =3D X86_OP_ENTRY3(VMASKMOVPS_st, M,x, V,x, H,x, vex6 cpu= id(AVX) p_66), - [0x2f] =3D X86_OP_ENTRY3(VMASKMOVPD_st, M,x, V,x, H,x, vex6 cpu= id(AVX) p_66), + [0x2e] =3D X86_OP_ENTRY3(VMASKMOVPS_st, M,x, V,x, H,x, vex6 chk= (W0) cpuid(AVX) p_66), + [0x2f] =3D X86_OP_ENTRY3(VMASKMOVPD_st, M,x, V,x, H,x, vex6 chk= (W0) cpuid(AVX) p_66), =20 [0x38] =3D X86_OP_ENTRY3(PMINSB, V,x, H,x, W,x, vex4 cpuid(SS= E41) avx2_256 p_66), [0x39] =3D X86_OP_ENTRY3(PMINSD, V,x, H,x, W,x, vex4 cpuid(SS= E41) avx2_256 p_66), @@ -423,12 +465,13 @@ static const X86OpEntry opcodes_0F38_00toEF[240] =3D { [0x3e] =3D X86_OP_ENTRY3(PMAXUW, V,x, H,x, W,x, vex4 cpuid(SS= E41) avx2_256 p_66), [0x3f] =3D X86_OP_ENTRY3(PMAXUD, V,x, H,x, W,x, vex4 cpuid(SS= E41) avx2_256 p_66), =20 - [0x58] =3D X86_OP_ENTRY3(VPBROADCASTD, V,x, None,None, W,d, vex6 c= puid(AVX2) p_66), - [0x59] =3D X86_OP_ENTRY3(VPBROADCASTQ, V,x, None,None, W,q, vex6 c= puid(AVX2) p_66), - [0x5a] =3D X86_OP_ENTRY3(VBROADCASTx128, V,qq, None,None, WM,dq,vex6 c= puid(AVX2) p_66), + /* VPBROADCASTQ not listed as W0 in table 2-16 */ + [0x58] =3D X86_OP_ENTRY3(VPBROADCASTD, V,x, None,None, W,d, vex6 c= hk(W0) cpuid(AVX2) p_66), + [0x59] =3D X86_OP_ENTRY3(VPBROADCASTQ, V,x, None,None, W,q, vex6 c= hk(W0) cpuid(AVX2) p_66), + [0x5a] =3D X86_OP_ENTRY3(VBROADCASTx128, V,qq, None,None, WM,dq,vex6 c= hk(W0) cpuid(AVX2) p_66), =20 - [0x78] =3D X86_OP_ENTRY3(VPBROADCASTB, V,x, None,None, W,b, vex6 c= puid(AVX2) p_66), - [0x79] =3D X86_OP_ENTRY3(VPBROADCASTW, V,x, None,None, W,w, vex6 c= puid(AVX2) p_66), + [0x78] =3D X86_OP_ENTRY3(VPBROADCASTB, V,x, None,None, W,b, vex6 c= hk(W0) cpuid(AVX2) p_66), + [0x79] =3D X86_OP_ENTRY3(VPBROADCASTW, V,x, None,None, W,w, vex6 c= hk(W0) cpuid(AVX2) p_66), =20 [0x8c] =3D X86_OP_ENTRY3(VPMASKMOV, V,x, H,x, WM,x, vex6 cpuid(AVX= 2) p_66), [0x8e] =3D X86_OP_ENTRY3(VPMASKMOV_st, M,x, V,x, H,x, vex6 cpuid(AVX= 2) p_66), @@ -555,18 +598,18 @@ static const X86OpEntry opcodes_0F3A[256] =3D { * Also the "qq" instructions are sometimes omitted by Table 2-17, but= are VEX256 * only. */ - [0x00] =3D X86_OP_ENTRY3(VPERMQ, V,qq, W,qq, I,b, vex6 cpuid(AVX= 2) p_66), - [0x01] =3D X86_OP_ENTRY3(VPERMQ, V,qq, W,qq, I,b, vex6 cpuid(AVX= 2) p_66), /* VPERMPD */ - [0x02] =3D X86_OP_ENTRY4(VBLENDPS, V,x, H,x, W,x, vex6 cpuid(AVX= 2) p_66), /* VPBLENDD */ - [0x04] =3D X86_OP_ENTRY3(VPERMILPS_i, V,x, W,x, I,b, vex6 cpuid(AVX= ) p_66), - [0x05] =3D X86_OP_ENTRY3(VPERMILPD_i, V,x, W,x, I,b, vex6 cpuid(AVX= ) p_66), - [0x06] =3D X86_OP_ENTRY4(VPERM2x128, V,qq, H,qq, W,qq, vex6 cpuid(AVX= ) p_66), + [0x00] =3D X86_OP_ENTRY3(VPERMQ, V,qq, W,qq, I,b, vex6 chk(W1) c= puid(AVX2) p_66), + [0x01] =3D X86_OP_ENTRY3(VPERMQ, V,qq, W,qq, I,b, vex6 chk(W1) c= puid(AVX2) p_66), /* VPERMPD */ + [0x02] =3D X86_OP_ENTRY4(VBLENDPS, V,x, H,x, W,x, vex6 chk(W0) c= puid(AVX2) p_66), /* VPBLENDD */ + [0x04] =3D X86_OP_ENTRY3(VPERMILPS_i, V,x, W,x, I,b, vex6 chk(W0) c= puid(AVX) p_66), + [0x05] =3D X86_OP_ENTRY3(VPERMILPD_i, V,x, W,x, I,b, vex6 chk(W0) c= puid(AVX) p_66), + [0x06] =3D X86_OP_ENTRY4(VPERM2x128, V,qq, H,qq, W,qq, vex6 chk(W0) c= puid(AVX) p_66), =20 [0x14] =3D X86_OP_ENTRY3(PEXTRB, E,b, V,dq, I,b, vex5 cpuid(SSE4= 1) zext0 p_66), [0x15] =3D X86_OP_ENTRY3(PEXTRW, E,w, V,dq, I,b, vex5 cpuid(SSE4= 1) zext0 p_66), [0x16] =3D X86_OP_ENTRY3(PEXTR, E,y, V,dq, I,b, vex5 cpuid(SSE4= 1) p_66), [0x17] =3D X86_OP_ENTRY3(VEXTRACTPS, E,d, V,dq, I,b, vex5 cpuid(SSE4= 1) p_66), - [0x1d] =3D X86_OP_ENTRY3(VCVTPS2PH, W,xh, V,x, I,b, vex11 cpuid(F16= C) p_66), + [0x1d] =3D X86_OP_ENTRY3(VCVTPS2PH, W,xh, V,x, I,b, vex11 chk(W0) c= puid(F16C) p_66), =20 [0x20] =3D X86_OP_ENTRY4(PINSRB, V,dq, H,dq, E,b, vex5 cpuid(SSE4= 1) zext2 p_66), [0x21] =3D X86_OP_GROUP0(VINSERTPS), @@ -576,7 +619,7 @@ static const X86OpEntry opcodes_0F3A[256] =3D { [0x41] =3D X86_OP_ENTRY4(VDDPD, V,dq, H,dq, W,dq, vex2 cpuid(SSE4= 1) p_66), [0x42] =3D X86_OP_ENTRY4(VMPSADBW, V,x, H,x, W,x, vex2 cpuid(SSE4= 1) avx2_256 p_66), [0x44] =3D X86_OP_ENTRY4(PCLMULQDQ, V,dq, H,dq, W,dq, vex4 cpuid(PCLM= ULQDQ) p_66), - [0x46] =3D X86_OP_ENTRY4(VPERM2x128, V,qq, H,qq, W,qq, vex6 cpuid(AVX2= ) p_66), + [0x46] =3D X86_OP_ENTRY4(VPERM2x128, V,qq, H,qq, W,qq, vex6 chk(W0) cp= uid(AVX2) p_66), =20 [0x60] =3D X86_OP_ENTRY4(PCMPESTRM, None,None, V,dq, W,dq, vex4_unal = cpuid(SSE42) p_66), [0x61] =3D X86_OP_ENTRY4(PCMPESTRI, None,None, V,dq, W,dq, vex4_unal = cpuid(SSE42) p_66), @@ -599,16 +642,16 @@ static const X86OpEntry opcodes_0F3A[256] =3D { [0x0e] =3D X86_OP_ENTRY4(VPBLENDW, V,x, H,x, W,x, vex4 cpuid(SSE4= 1) avx2_256 p_66), [0x0f] =3D X86_OP_ENTRY4(PALIGNR, V,x, H,x, W,x, vex4 cpuid(SSSE= 3) mmx avx2_256 p_00_66), =20 - [0x18] =3D X86_OP_ENTRY4(VINSERTx128, V,qq, H,qq, W,qq, vex6 cpuid(AV= X) p_66), - [0x19] =3D X86_OP_ENTRY3(VEXTRACTx128, W,dq, V,qq, I,b, vex6 cpuid(AV= X) p_66), + [0x18] =3D X86_OP_ENTRY4(VINSERTx128, V,qq, H,qq, W,qq, vex6 chk(W0) = cpuid(AVX) p_66), + [0x19] =3D X86_OP_ENTRY3(VEXTRACTx128, W,dq, V,qq, I,b, vex6 chk(W0) = cpuid(AVX) p_66), =20 - [0x38] =3D X86_OP_ENTRY4(VINSERTx128, V,qq, H,qq, W,qq, vex6 cpuid(AV= X2) p_66), - [0x39] =3D X86_OP_ENTRY3(VEXTRACTx128, W,dq, V,qq, I,b, vex6 cpuid(AV= X2) p_66), + [0x38] =3D X86_OP_ENTRY4(VINSERTx128, V,qq, H,qq, W,qq, vex6 chk(W0) = cpuid(AVX2) p_66), + [0x39] =3D X86_OP_ENTRY3(VEXTRACTx128, W,dq, V,qq, I,b, vex6 chk(W0) = cpuid(AVX2) p_66), =20 /* Listed incorrectly as type 4 */ - [0x4a] =3D X86_OP_ENTRY4(VBLENDVPS, V,x, H,x, W,x, vex6 cpuid(AVX)= p_66), - [0x4b] =3D X86_OP_ENTRY4(VBLENDVPD, V,x, H,x, W,x, vex6 cpuid(AVX)= p_66), - [0x4c] =3D X86_OP_ENTRY4(VPBLENDVB, V,x, H,x, W,x, vex6 cpuid(AVX)= p_66 avx2_256), + [0x4a] =3D X86_OP_ENTRY4(VBLENDVPS, V,x, H,x, W,x, vex6 chk(W0) cp= uid(AVX) p_66), + [0x4b] =3D X86_OP_ENTRY4(VBLENDVPD, V,x, H,x, W,x, vex6 chk(W0) cp= uid(AVX) p_66), + [0x4c] =3D X86_OP_ENTRY4(VPBLENDVB, V,x, H,x, W,x, vex6 chk(W0) cp= uid(AVX) p_66 avx2_256), =20 [0xdf] =3D X86_OP_ENTRY3(VAESKEYGEN, V,dq, W,dq, I,b, vex4 cpuid(AES)= p_66), =20 @@ -1494,8 +1537,6 @@ static bool validate_vex(DisasContext *s, X86DecodedI= nsn *decode) } } =20 - /* TODO: instructions that require VEX.W=3D0 (Table 2-16) */ - switch (e->vex_class) { case 0: if (s->prefix & PREFIX_VEX) { @@ -1581,9 +1622,21 @@ static bool validate_vex(DisasContext *s, X86Decoded= Insn *decode) goto illegal; } =20 - if (e->check & X86_CHECK_VEX128) { - if (s->vex_l) { - goto illegal; + if (e->check) { + if (e->check & X86_CHECK_VEX128) { + if (s->vex_l) { + goto illegal; + } + } + if (e->check & X86_CHECK_W0) { + if (s->vex_w) { + goto illegal; + } + } + if (e->check & X86_CHECK_W1) { + if (!s->vex_w) { + goto illegal; + } } } return true; diff --git a/target/i386/tcg/decode-new.h b/target/i386/tcg/decode-new.h index 631d39220bb..ae987dfe0ba 100644 --- a/target/i386/tcg/decode-new.h +++ b/target/i386/tcg/decode-new.h @@ -144,6 +144,12 @@ typedef enum X86InsnCheck { =20 /* Fault if VEX.L=3D1 */ X86_CHECK_VEX128 =3D 32, + + /* Fault if VEX.W=3D1 */ + X86_CHECK_W0 =3D 64, + + /* Fault if VEX.W=3D0 */ + X86_CHECK_W1 =3D 128, } X86InsnCheck; =20 typedef enum X86InsnSpecial { --=20 2.41.0 From nobody Wed Nov 27 15:47:23 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=1697712539; cv=none; d=zohomail.com; s=zohoarc; b=KMWZZTKrCCeAW8dn+5bJj9XFNvH0gIYzy7Osg1sv/Vi2Xj6TU+mK9uioKJWOcvA4NGJQJrfx97EWhy2qDBAzvhK+CaNUVWz/x5AIKxcnevq2PiDYAPWknPTxfgtw5NUDo+hz4GlnIfUka7VPvzK6mXaAqCGHkR9o+zLip6d7Hz0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697712539; 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=8s7wHI4CkLj7mZOBGLOqYoTTD0JqgSZM75M93R4VQu8=; b=SVv6tAGK5SMtFF2NZZUhReaxxZWSrc0Lmr4oTE0hGP1uGMQYE3Z9AfxiGJH8D/mIswZ2TJ0+ClL3O5/uRSXqAcIciHKUhw2bfGIdQKmvzw4o5/uux4Uky6YoqIYNFfd7Euzlxg1nyaL+jh99/AhMJob1PxIozObDH7uqIEewzFc= 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 1697712539376831.2361636079099; Thu, 19 Oct 2023 03:48:59 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qtQYW-0006Y0-U7; Thu, 19 Oct 2023 06:47:08 -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 1qtQYR-0006FS-QW for qemu-devel@nongnu.org; Thu, 19 Oct 2023 06:47:04 -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 1qtQYP-0006CY-Ft for qemu-devel@nongnu.org; Thu, 19 Oct 2023 06:47:03 -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-668-61wEotYOM9KVxfTlHIbwKA-1; Thu, 19 Oct 2023 06:46:58 -0400 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-997c891a88dso576286066b.3 for ; Thu, 19 Oct 2023 03:46:58 -0700 (PDT) Received: from [192.168.10.118] ([2001:b07:6468:f312:5e2c:eb9a:a8b6:fd3e]) by smtp.gmail.com with ESMTPSA id 25-20020a170906225900b0098f99048053sm3371537ejr.148.2023.10.19.03.46.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 03:46:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697712420; 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=8s7wHI4CkLj7mZOBGLOqYoTTD0JqgSZM75M93R4VQu8=; b=Ip3Gs28vTJRixs3Fy+aId2D+PMybIv9OuddQhsqbbTqIg5SGkqb2zGn8XZzIv+r9SwLyt6 fUAPC3Hv0V7PTDhac6Ubj7cUNVGYMrYDXvHHZmHXCBFnwjbmQS7HQc8jpRnlIYEx1JKLw7 TZCjjwrkIjQnu8tWtvkd/a+EeJuBLLg= X-MC-Unique: 61wEotYOM9KVxfTlHIbwKA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697712416; x=1698317216; 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=8s7wHI4CkLj7mZOBGLOqYoTTD0JqgSZM75M93R4VQu8=; b=P6o1VhlSzeNInN6tg3tcoB45UflTjcA0YFB8ip+dcU/XpfjJmWkAGb379Rb66wD7B+ cQcCN5ng/vy7ZtV46rNralIstdqPRqaz13LU7JMiuQREZ5qiP2dNq8rh8xvY3/4kE2TU lJEWoodVVOccCCeibsaQpIvHqdFcLiKSd4hKVuqiM1+VGe+grFUBDrGOzjnuVG/6mP8M UW8GInI6wDqjB2KcK1BJ7I/2OPc0sWILwksW3zShxbUfd8PXfGS3tXvRX3Ww/ZhTGlBY wWlvps9eXmo31uBZ/VpGammtllbayreNYfHB1CjaWLHIspq31KZ+LH8k+y9lPaiWxmgr Sphg== X-Gm-Message-State: AOJu0Yzz9teD9LEXoSfLgVpDAWbXFhptdF3qpkyYNqvs13Xm9D5BzVBw BjRUCiD58QMRdvjuKquSboAo+nCpOaglTP4p1WSVababuSFWlcPwg7Zj8ewfhO3RAc0TtBUNhfz 4XjKr3CYI1WpQykTKcELs+IwvoZb9IHirqAY8Xk/R7rHZLilRcPuj5Oj3DI34JoSS8LAXWZPhhH k= X-Received: by 2002:a17:906:4fcd:b0:9bf:30e8:5bfb with SMTP id i13-20020a1709064fcd00b009bf30e85bfbmr1624019ejw.48.1697712416539; Thu, 19 Oct 2023 03:46:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG7h4jYNMM6NtDuhC4D0IVMyKX4+4rJMbV5p2SlkD9I6WdPfXEo4pDpoku8ySkG4R5QOmAPZQ== X-Received: by 2002:a17:906:4fcd:b0:9bf:30e8:5bfb with SMTP id i13-20020a1709064fcd00b009bf30e85bfbmr1624000ejw.48.1697712416055; Thu, 19 Oct 2023 03:46:56 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH v2 03/19] target/i386: implement SHA instructions Date: Thu, 19 Oct 2023 12:46:32 +0200 Message-ID: <20231019104648.389942-4-pbonzini@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231019104648.389942-1-pbonzini@redhat.com> References: <20231019104648.389942-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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1697712541599100011 Content-Type: text/plain; charset="utf-8" The implementation was validated with OpenSSL and with the test vectors in https://github.com/rust-lang/stdarch/blob/master/crates/core_arch/src/x86/s= ha.rs. The instructions provide a ~25% improvement on hashing a 64 MiB file: runtime goes down from 1.8 seconds to 1.4 seconds; instruction count on the host goes down from 5.8 billion to 4.8 billion with slightly better IPC too. Good job Intel. ;) Signed-off-by: Paolo Bonzini --- target/i386/cpu.c | 2 +- target/i386/ops_sse.h | 128 +++++++++++++++++++++++++++ target/i386/tcg/decode-new.c.inc | 11 +++ target/i386/tcg/decode-new.h | 1 + target/i386/tcg/emit.c.inc | 54 +++++++++++ target/i386/tcg/ops_sse_header.h.inc | 14 +++ 6 files changed, 209 insertions(+), 1 deletion(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index bdca901dfaa..070c02000fe 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -714,7 +714,7 @@ void x86_cpu_vendor_words2str(char *dst, uint32_t vendo= r1, CPUID_7_0_EBX_PCOMMIT | CPUID_7_0_EBX_CLFLUSHOPT | \ CPUID_7_0_EBX_CLWB | CPUID_7_0_EBX_MPX | CPUID_7_0_EBX_FSGSBASE = | \ CPUID_7_0_EBX_ERMS | CPUID_7_0_EBX_AVX2 | CPUID_7_0_EBX_RDSEED |= \ - CPUID_7_0_EBX_KERNEL_FEATURES) + CPUID_7_0_EBX_SHA_NI | CPUID_7_0_EBX_KERNEL_FEATURES) /* missing: CPUID_7_0_EBX_HLE CPUID_7_0_EBX_INVPCID, CPUID_7_0_EBX_RTM */ diff --git a/target/i386/ops_sse.h b/target/i386/ops_sse.h index 33908c0691f..6a465a35fdb 100644 --- a/target/i386/ops_sse.h +++ b/target/i386/ops_sse.h @@ -2527,6 +2527,134 @@ SSE_HELPER_FMAP(helper_fma4ps, ZMM_S, 2 << SHIFT, = float32_muladd) SSE_HELPER_FMAP(helper_fma4pd, ZMM_D, 1 << SHIFT, float64_muladd) #endif =20 +#if SHIFT =3D=3D 1 +#define SSE_HELPER_SHA1RNDS4(name, F, K) \ + void name(Reg *d, Reg *a, Reg *b) = \ + { = \ + uint32_t A, B, C, D, E, t, i; = \ + = \ + A =3D a->L(3); = \ + B =3D a->L(2); = \ + C =3D a->L(1); = \ + D =3D a->L(0); = \ + E =3D 0; = \ + = \ + for (i =3D 0; i <=3D 3; i++) { = \ + t =3D F(B, C, D) + rol32(A, 5) + b->L(3 - i) + E + K; = \ + E =3D D; = \ + D =3D C; = \ + C =3D rol32(B, 30); = \ + B =3D A; = \ + A =3D t; = \ + } = \ + = \ + d->L(3) =3D A; = \ + d->L(2) =3D B; = \ + d->L(1) =3D C; = \ + d->L(0) =3D D; = \ + } + +#define SHA1_F0(b, c, d) (((b) & (c)) ^ (~(b) & (d))) +#define SHA1_F1(b, c, d) ((b) ^ (c) ^ (d)) +#define SHA1_F2(b, c, d) (((b) & (c)) ^ ((b) & (d)) ^ ((c) & (d))) + +SSE_HELPER_SHA1RNDS4(helper_sha1rnds4_f0, SHA1_F0, 0x5A827999) +SSE_HELPER_SHA1RNDS4(helper_sha1rnds4_f1, SHA1_F1, 0x6ED9EBA1) +SSE_HELPER_SHA1RNDS4(helper_sha1rnds4_f2, SHA1_F2, 0x8F1BBCDC) +SSE_HELPER_SHA1RNDS4(helper_sha1rnds4_f3, SHA1_F1, 0xCA62C1D6) + +void helper_sha1nexte(Reg *d, Reg *a, Reg *b) +{ + d->L(3) =3D b->L(3) + rol32(a->L(3), 30); + d->L(2) =3D b->L(2); + d->L(1) =3D b->L(1); + d->L(0) =3D b->L(0); +} + +void helper_sha1msg1(Reg *d, Reg *a, Reg *b) +{ + /* These could be overwritten by the first two assignments, save them.= */ + uint32_t b3 =3D b->L(3); + uint32_t b2 =3D b->L(2); + + d->L(3) =3D a->L(3) ^ a->L(1); + d->L(2) =3D a->L(2) ^ a->L(0); + d->L(1) =3D a->L(1) ^ b3; + d->L(0) =3D a->L(0) ^ b2; +} + +void helper_sha1msg2(Reg *d, Reg *a, Reg *b) +{ + d->L(3) =3D rol32(a->L(3) ^ b->L(2), 1); + d->L(2) =3D rol32(a->L(2) ^ b->L(1), 1); + d->L(1) =3D rol32(a->L(1) ^ b->L(0), 1); + d->L(0) =3D rol32(a->L(0) ^ d->L(3), 1); +} + +#define SHA256_CH(e, f, g) (((e) & (f)) ^ (~(e) & (g))) +#define SHA256_MAJ(a, b, c) (((a) & (b)) ^ ((a) & (c)) ^ ((b) & (c))) + +#define SHA256_RNDS0(w) (ror32((w), 2) ^ ror32((w), 13) ^ ror32((w), 22)) +#define SHA256_RNDS1(w) (ror32((w), 6) ^ ror32((w), 11) ^ ror32((w), 25)) +#define SHA256_MSGS0(w) (ror32((w), 7) ^ ror32((w), 18) ^ ((w) >> 3)) +#define SHA256_MSGS1(w) (ror32((w), 17) ^ ror32((w), 19) ^ ((w) >> 10)) + +void helper_sha256rnds2(Reg *d, Reg *a, Reg *b, uint32_t wk0, uint32_t wk1) +{ + uint32_t t, AA, EE; + + uint32_t A =3D b->L(3); + uint32_t B =3D b->L(2); + uint32_t C =3D a->L(3); + uint32_t D =3D a->L(2); + uint32_t E =3D b->L(1); + uint32_t F =3D b->L(0); + uint32_t G =3D a->L(1); + uint32_t H =3D a->L(0); + + /* Even round */ + t =3D SHA256_CH(E, F, G) + SHA256_RNDS1(E) + wk0 + H; + AA =3D t + SHA256_MAJ(A, B, C) + SHA256_RNDS0(A); + EE =3D t + D; + + /* These will be B and F at the end of the odd round */ + d->L(2) =3D AA; + d->L(0) =3D EE; + + D =3D C, C =3D B, B =3D A, A =3D AA; + H =3D G, G =3D F, F =3D E, E =3D EE; + + /* Odd round */ + t =3D SHA256_CH(E, F, G) + SHA256_RNDS1(E) + wk1 + H; + AA =3D t + SHA256_MAJ(A, B, C) + SHA256_RNDS0(A); + EE =3D t + D; + + d->L(3) =3D AA; + d->L(1) =3D EE; +} + +void helper_sha256msg1(Reg *d, Reg *a, Reg *b) +{ + /* b->L(0) could be overwritten by the first assignment, save it. */ + uint32_t b0 =3D b->L(0); + + d->L(0) =3D a->L(0) + SHA256_MSGS0(a->L(1)); + d->L(1) =3D a->L(1) + SHA256_MSGS0(a->L(2)); + d->L(2) =3D a->L(2) + SHA256_MSGS0(a->L(3)); + d->L(3) =3D a->L(3) + SHA256_MSGS0(b0); +} + +void helper_sha256msg2(Reg *d, Reg *a, Reg *b) +{ + /* Earlier assignments cannot overwrite any of the two operands. */ + d->L(0) =3D a->L(0) + SHA256_MSGS1(b->L(2)); + d->L(1) =3D a->L(1) + SHA256_MSGS1(b->L(3)); + /* Yes, this reuses the previously computed values. */ + d->L(2) =3D a->L(2) + SHA256_MSGS1(d->L(0)); + d->L(3) =3D a->L(3) + SHA256_MSGS1(d->L(1)); +} +#endif + #undef SSE_HELPER_S =20 #undef LANE_WIDTH diff --git a/target/i386/tcg/decode-new.c.inc b/target/i386/tcg/decode-new.= c.inc index 850271e0898..eb2400095f8 100644 --- a/target/i386/tcg/decode-new.c.inc +++ b/target/i386/tcg/decode-new.c.inc @@ -504,6 +504,13 @@ static const X86OpEntry opcodes_0F38_00toEF[240] =3D { [0xbe] =3D X86_OP_ENTRY3(VFNMSUB231Px, V,x, H,x, W,x, vex6 cpuid(FMA= ) p_66), [0xbf] =3D X86_OP_ENTRY3(VFNMSUB231Sx, V,x, H,x, W,x, vex6 cpuid(FMA= ) p_66), =20 + [0xc8] =3D X86_OP_ENTRY2(SHA1NEXTE, V,dq, W,dq, cpuid(SHA_NI)), + [0xc9] =3D X86_OP_ENTRY2(SHA1MSG1, V,dq, W,dq, cpuid(SHA_NI)), + [0xca] =3D X86_OP_ENTRY2(SHA1MSG2, V,dq, W,dq, cpuid(SHA_NI)), + [0xcb] =3D X86_OP_ENTRY2(SHA256RNDS2, V,dq, W,dq, cpuid(SHA_NI)), + [0xcc] =3D X86_OP_ENTRY2(SHA256MSG1, V,dq, W,dq, cpuid(SHA_NI)), + [0xcd] =3D X86_OP_ENTRY2(SHA256MSG2, V,dq, W,dq, cpuid(SHA_NI)), + [0xdb] =3D X86_OP_ENTRY3(VAESIMC, V,dq, None,None, W,dq, vex4 cpui= d(AES) p_66), [0xdc] =3D X86_OP_ENTRY3(VAESENC, V,x, H,x, W,x, vex4 cpui= d(AES) p_66), [0xdd] =3D X86_OP_ENTRY3(VAESENCLAST, V,x, H,x, W,x, vex4 cpui= d(AES) p_66), @@ -653,6 +660,8 @@ static const X86OpEntry opcodes_0F3A[256] =3D { [0x4b] =3D X86_OP_ENTRY4(VBLENDVPD, V,x, H,x, W,x, vex6 chk(W0) cp= uid(AVX) p_66), [0x4c] =3D X86_OP_ENTRY4(VPBLENDVB, V,x, H,x, W,x, vex6 chk(W0) cp= uid(AVX) p_66 avx2_256), =20 + [0xcc] =3D X86_OP_ENTRY3(SHA1RNDS4, V,dq, W,dq, I,b, cpuid(SHA_NI)), + [0xdf] =3D X86_OP_ENTRY3(VAESKEYGEN, V,dq, W,dq, I,b, vex4 cpuid(AES)= p_66), =20 [0xF0] =3D X86_OP_ENTRY3(RORX, G,y, E,y, I,b, vex13 cpuid(BMI2) p_f2), @@ -1500,6 +1509,8 @@ static bool has_cpuid_feature(DisasContext *s, X86CPU= IDFeature cpuid) return (s->cpuid_7_0_ebx_features & CPUID_7_0_EBX_BMI2); case X86_FEAT_AVX2: return (s->cpuid_7_0_ebx_features & CPUID_7_0_EBX_AVX2); + case X86_FEAT_SHA_NI: + return (s->cpuid_7_0_ebx_features & CPUID_7_0_EBX_SHA_NI); } g_assert_not_reached(); } diff --git a/target/i386/tcg/decode-new.h b/target/i386/tcg/decode-new.h index ae987dfe0ba..ab21fa6db97 100644 --- a/target/i386/tcg/decode-new.h +++ b/target/i386/tcg/decode-new.h @@ -108,6 +108,7 @@ typedef enum X86CPUIDFeature { X86_FEAT_FMA, X86_FEAT_MOVBE, X86_FEAT_PCLMULQDQ, + X86_FEAT_SHA_NI, X86_FEAT_SSE, X86_FEAT_SSE2, X86_FEAT_SSE3, diff --git a/target/i386/tcg/emit.c.inc b/target/i386/tcg/emit.c.inc index 7c36cf8a6df..82da5488d47 100644 --- a/target/i386/tcg/emit.c.inc +++ b/target/i386/tcg/emit.c.inc @@ -1796,6 +1796,60 @@ static void gen_SARX(DisasContext *s, CPUX86State *e= nv, X86DecodedInsn *decode) tcg_gen_sar_tl(s->T0, s->T0, s->T1); } =20 +static void gen_SHA1NEXTE(DisasContext *s, CPUX86State *env, X86DecodedIns= n *decode) +{ + gen_helper_sha1nexte(OP_PTR0, OP_PTR1, OP_PTR2); +} + +static void gen_SHA1MSG1(DisasContext *s, CPUX86State *env, X86DecodedInsn= *decode) +{ + gen_helper_sha1msg1(OP_PTR0, OP_PTR1, OP_PTR2); +} + +static void gen_SHA1MSG2(DisasContext *s, CPUX86State *env, X86DecodedInsn= *decode) +{ + gen_helper_sha1msg2(OP_PTR0, OP_PTR1, OP_PTR2); +} + +static void gen_SHA1RNDS4(DisasContext *s, CPUX86State *env, X86DecodedIns= n *decode) +{ + switch(decode->immediate & 3) { + case 0: + gen_helper_sha1rnds4_f0(OP_PTR0, OP_PTR0, OP_PTR1); + break; + case 1: + gen_helper_sha1rnds4_f1(OP_PTR0, OP_PTR0, OP_PTR1); + break; + case 2: + gen_helper_sha1rnds4_f2(OP_PTR0, OP_PTR0, OP_PTR1); + break; + case 3: + gen_helper_sha1rnds4_f3(OP_PTR0, OP_PTR0, OP_PTR1); + break; + } +} + +static void gen_SHA256MSG1(DisasContext *s, CPUX86State *env, X86DecodedIn= sn *decode) +{ + gen_helper_sha256msg1(OP_PTR0, OP_PTR1, OP_PTR2); +} + +static void gen_SHA256MSG2(DisasContext *s, CPUX86State *env, X86DecodedIn= sn *decode) +{ + gen_helper_sha256msg2(OP_PTR0, OP_PTR1, OP_PTR2); +} + +static void gen_SHA256RNDS2(DisasContext *s, CPUX86State *env, X86DecodedI= nsn *decode) +{ + TCGv_i32 wk0 =3D tcg_temp_new_i32(); + TCGv_i32 wk1 =3D tcg_temp_new_i32(); + + tcg_gen_ld_i32(wk0, tcg_env, ZMM_OFFSET(0) + offsetof(ZMMReg, ZMM_L(0)= )); + tcg_gen_ld_i32(wk1, tcg_env, ZMM_OFFSET(0) + offsetof(ZMMReg, ZMM_L(1)= )); + + gen_helper_sha256rnds2(OP_PTR0, OP_PTR1, OP_PTR2, wk0, wk1); +} + static void gen_SHLX(DisasContext *s, CPUX86State *env, X86DecodedInsn *de= code) { MemOp ot =3D decode->op[0].ot; diff --git a/target/i386/tcg/ops_sse_header.h.inc b/target/i386/tcg/ops_sse= _header.h.inc index 8a7b2f4e2f6..d92c6faf6d6 100644 --- a/target/i386/tcg/ops_sse_header.h.inc +++ b/target/i386/tcg/ops_sse_header.h.inc @@ -399,6 +399,20 @@ DEF_HELPER_3(vpermq_ymm, void, Reg, Reg, i32) #endif #endif =20 +/* SHA helpers */ +#if SHIFT =3D=3D 1 +DEF_HELPER_3(sha1rnds4_f0, void, Reg, Reg, Reg) +DEF_HELPER_3(sha1rnds4_f1, void, Reg, Reg, Reg) +DEF_HELPER_3(sha1rnds4_f2, void, Reg, Reg, Reg) +DEF_HELPER_3(sha1rnds4_f3, void, Reg, Reg, Reg) +DEF_HELPER_3(sha1nexte, void, Reg, Reg, Reg) +DEF_HELPER_3(sha1msg1, void, Reg, Reg, Reg) +DEF_HELPER_3(sha1msg2, void, Reg, Reg, Reg) +DEF_HELPER_5(sha256rnds2, void, Reg, Reg, Reg, i32, i32) +DEF_HELPER_3(sha256msg1, void, Reg, Reg, Reg) +DEF_HELPER_3(sha256msg2, void, Reg, Reg, Reg) +#endif + #undef SHIFT #undef Reg #undef SUFFIX --=20 2.41.0 From nobody Wed Nov 27 15:47:24 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=1697712621; cv=none; d=zohomail.com; s=zohoarc; b=KAV7+KMwKnm9p/sjOJVCW8Kvlphhcfdj8vlgomvKrdXvz98zEehuneYiXmgrIV7pX5JNAi/HlborVNJn3LIgDLGWxXQN8qF6v5R8FKr9YidRjcn4i9KwEKsCwtKfZxpl0w2oaKGC2Ws0/NbbxNLotB0k+DNXlAJtGv1sRKZ4TEc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697712621; 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=O0fO7ODbzYSAx28Rwy633NyqFTt8J0HLgXe91UBK6GM=; b=NWfsi01JTFGpQ+FoFKdbqim4QKlsoyMvQEzE/hzt/KPdNtsLgOGnywx0fU4+PjG5W+XoVEECqRSp7LzoGSCTpPoRnIZWI3lBNSfj6LuCFRMPI6glc0bLbTW8Z8jb1EH22V3eJ13zqzT4fiGHmQWvpKVCvk/0ILu0EZm7rsV3uvM= 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 1697712621349565.7256428476339; Thu, 19 Oct 2023 03:50:21 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qtQYU-0006Ih-0X; Thu, 19 Oct 2023 06:47:06 -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 1qtQYR-0006FQ-7H for qemu-devel@nongnu.org; Thu, 19 Oct 2023 06:47:04 -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 1qtQYP-0006Ca-Lz for qemu-devel@nongnu.org; Thu, 19 Oct 2023 06:47:02 -0400 Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-84-wyELXB9mOAG3xZzY4Elqvw-1; Thu, 19 Oct 2023 06:46:59 -0400 Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-9b822f5c156so584548366b.3 for ; Thu, 19 Oct 2023 03:46:58 -0700 (PDT) Received: from [192.168.10.118] ([2001:b07:6468:f312:5e2c:eb9a:a8b6:fd3e]) by smtp.gmail.com with ESMTPSA id bh12-20020a170906a0cc00b0099bd7b26639sm3387872ejb.6.2023.10.19.03.46.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 03:46:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697712420; 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=O0fO7ODbzYSAx28Rwy633NyqFTt8J0HLgXe91UBK6GM=; b=X8Am7y2iEu5tTIylBbVrLo4V7Oxr8A9IaDQXYfAMMJ2bxOUVKByWEbhqNdwHbRVNvlD9Tf Z5z+GhO6O1cD2IfkwP8qT6od439owkfJLrga/D53HDXywriwZzBQy4o+dS4L3wNa8LTJn3 H5mpTiF8ILICLjRVG1FkEedurKD53Wg= X-MC-Unique: wyELXB9mOAG3xZzY4Elqvw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697712417; x=1698317217; 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=O0fO7ODbzYSAx28Rwy633NyqFTt8J0HLgXe91UBK6GM=; b=Tv0sTgfJ/5WB6F9S+SAVywDMG6j+tRI21mPeDYPrhYxq2hSAqbN2u5p7TEi2ZSbMYV Todth0V3Cg/Y5IUWa3155+WtLCGpanci4zdff9+YqEalSP9Zz8mJHpzNgslksDmDAUM7 ewkY75nljbYzGi7kmcjejlHbx1EAIvo+bo1/KOMwywfyJlIKTay0h9wTBe2u60mrLlYH UkWCAFVD1td3nsIK9wSxuxRumWKAeMS7YChA4ZLe96YImZKk0yB8M11vCIx3VUvdTuQo 0rNSEt7V/wo+J1dbpR01mNWhhDWrvWnNlRsvG68uMHt6Mt1XO/CMHpy3yJQCsQsZq/A1 1pNQ== X-Gm-Message-State: AOJu0YxF0uIiyJSejlNGbufKxQhkuVMDXq9McdjnWQ5Cf3EDzPz0MWNX 5LAxTUyJyTf5etRc6dR7cdJPMi9SOJ0bKYbq853+oT2fhY1n5CiDkIQurVHGw42nuzB7j8gvJv3 kloVKVJom71Bnhf6EirGpIxU/5v5Dd0knTdGUZeiROWJdamHnH6NGMUk6ckPD2V6OWL4S9LkvJk I= X-Received: by 2002:a17:907:25c9:b0:9ad:e180:16e3 with SMTP id ae9-20020a17090725c900b009ade18016e3mr1301468ejc.37.1697712417613; Thu, 19 Oct 2023 03:46:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHkTBqXwNLTNdQltyVMqnG4j9JcLUHPARHTpRIFS3dbboKMK8IeEiuoP0x6XQyaw0M4XY/ZNA== X-Received: by 2002:a17:907:25c9:b0:9ad:e180:16e3 with SMTP id ae9-20020a17090725c900b009ade18016e3mr1301455ejc.37.1697712417327; Thu, 19 Oct 2023 03:46:57 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH v2 04/19] tests/tcg/i386: initialize more registers in test-avx Date: Thu, 19 Oct 2023 12:46:33 +0200 Message-ID: <20231019104648.389942-5-pbonzini@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231019104648.389942-1-pbonzini@redhat.com> References: <20231019104648.389942-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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1697712621905100001 Content-Type: text/plain; charset="utf-8" Some instructions use YMM0 implicitly, or use YMM9 as a read-modify-write register destination. Initialize those registers as well. Signed-off-by: Paolo Bonzini --- tests/tcg/i386/test-avx.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/tcg/i386/test-avx.c b/tests/tcg/i386/test-avx.c index c39c0e5bce8..2a04c1ecf15 100644 --- a/tests/tcg/i386/test-avx.c +++ b/tests/tcg/i386/test-avx.c @@ -316,6 +316,8 @@ int main(int argc, char *argv[]) int i; =20 init_all(&initI); + init_intreg(&initI.ymm[0]); + init_intreg(&initI.ymm[9]); init_intreg(&initI.ymm[10]); init_intreg(&initI.ymm[11]); init_intreg(&initI.ymm[12]); @@ -324,6 +326,8 @@ int main(int argc, char *argv[]) dump_regs(&initI); =20 init_all(&initF16); + init_f16reg(&initF16.ymm[0]); + init_f16reg(&initF16.ymm[9]); init_f16reg(&initF16.ymm[10]); init_f16reg(&initF16.ymm[11]); init_f16reg(&initF16.ymm[12]); @@ -333,6 +337,8 @@ int main(int argc, char *argv[]) dump_regs(&initF16); =20 init_all(&initF32); + init_f32reg(&initF32.ymm[0]); + init_f32reg(&initF32.ymm[9]); init_f32reg(&initF32.ymm[10]); init_f32reg(&initF32.ymm[11]); init_f32reg(&initF32.ymm[12]); @@ -342,6 +348,8 @@ int main(int argc, char *argv[]) dump_regs(&initF32); =20 init_all(&initF64); + init_f64reg(&initF64.ymm[0]); + init_f64reg(&initF64.ymm[9]); init_f64reg(&initF64.ymm[10]); init_f64reg(&initF64.ymm[11]); init_f64reg(&initF64.ymm[12]); --=20 2.41.0 From nobody Wed Nov 27 15:47:24 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=1697712520; cv=none; d=zohomail.com; s=zohoarc; b=egNuZCqG8CdVXvw1doQVKL4m+ltJiYNmx7NzyJVKlqKjvKkAR/1Je8n391a70L2P3lOvTmfchLnR+R0Ts1ofwqBDEqjt57wp4tOndBrKoV2HToNs0qSiTr51XCUEMTKAp9Wsn3U4hXC1OFdmBWQ4ymrTKQPVRbHWQST3sAmC+1Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697712520; 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=e9AH2w7IcRILYZ2JEj5EmCtr4xLbCojrRKRbWDyxGwE=; b=hHn0idvGeBFICOVo7yWiEHgfpPZO1BK243IViih2tOP2iVmB3QAseO1nyLF1iypCIvpWH+iPLBDYoH63BA268oQ1iqW2UoVfZ2GG3BHOpy558FznbUIRijgbFeRuLQ2Mgn2zTiX1sZDgxdRr2ZV1fWDLpLrDOR4UyhtNPi0PuiQ= 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 16977125200664.902470190487406; Thu, 19 Oct 2023 03:48:40 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qtQYW-0006X6-6m; Thu, 19 Oct 2023 06:47:08 -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 1qtQYS-0006FT-B2 for qemu-devel@nongnu.org; Thu, 19 Oct 2023 06:47:04 -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 1qtQYQ-0006Cp-Rq for qemu-devel@nongnu.org; Thu, 19 Oct 2023 06:47:04 -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-94-hOG-D-DaMw61vcb1i2MGaA-1; Thu, 19 Oct 2023 06:47:01 -0400 Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-99bcb13d8ddso577675066b.0 for ; Thu, 19 Oct 2023 03:47:00 -0700 (PDT) Received: from [192.168.10.118] ([2001:b07:6468:f312:5e2c:eb9a:a8b6:fd3e]) by smtp.gmail.com with ESMTPSA id p6-20020a1709061b4600b009b65b2be80bsm3295871ejg.76.2023.10.19.03.46.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 03:46:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697712422; 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=e9AH2w7IcRILYZ2JEj5EmCtr4xLbCojrRKRbWDyxGwE=; b=O2rzjq+h1RG5bi1Vky4bkpb12XqoIhECTBnKW+Qame8s4hZ+5o8fyvFMiGDOi29uMBqt9T oYBPdp3/lq6dwe+uB2TzwOPyOdsLh3idyrhR8r3XgQWnLjkFuqQgH8lpGBkDnHaE4pF7Ne 5PNY6vPHZUdfY7sEoL2x9aiebVNdJzA= X-MC-Unique: hOG-D-DaMw61vcb1i2MGaA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697712419; x=1698317219; 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=e9AH2w7IcRILYZ2JEj5EmCtr4xLbCojrRKRbWDyxGwE=; b=ge6ErDdLpHu5oNbp0yW1LDxMhe8vnyVVgIMVJRB7FdDeZZ3iRhDAKMkaJ0uY7+tJOW m7zfZwZYbRtpT8hiGNqkwKZu/1d2HWUo+qUaro3dxCC5WyX9rAD2FO6IPT0i2Qf5tOKX SWBvex64R44CCABBVhoSSPDrNhvJm9XdZ8R1oRc/aavFcVEYfn1S8wlIGcygegzO4A9O 0/vAqw7F9iws8EDBrumW3EfqwYKZDXytRGb9eDfgzsjQs5C+wVlk8Mm0Ds1LkqvCtc20 X04IQVeExwUkChg8lCXCHRg/81Vqs4OB/ckJ4DpI70FhVPk9kWklCFLftrAzk1Jtu7b4 9Yvw== X-Gm-Message-State: AOJu0Yy4gh/MnHpqnW4Y0dNuyoD4fRMKrpw+CmxghIcNCvQ58Oyf/DV1 xAbzvfi2pHG71dhupJYQ7o6aPHOwOLP+S1FiDHiEG+PWjIysJben5QJNWCJQZjmgk9KkpkzSYoe ovW8BJTTa9pBQLgtjdLo8PD30GVLC5xdKDm0Bq+UMtVCdKphFifDUXBYcLnX8jMOLJ/yQRjgiiv 4= X-Received: by 2002:a17:906:eec5:b0:9bd:b8d0:c096 with SMTP id wu5-20020a170906eec500b009bdb8d0c096mr1576490ejb.21.1697712419523; Thu, 19 Oct 2023 03:46:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEbxz1GVwrajUgSC73v7tyV1Cg8PS9hKAufc34pV+bqCKRMqqbUVJU+SW/33jx/1OaxBmpKgg== X-Received: by 2002:a17:906:eec5:b0:9bd:b8d0:c096 with SMTP id wu5-20020a170906eec500b009bdb8d0c096mr1576479ejb.21.1697712419188; Thu, 19 Oct 2023 03:46:59 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH v2 05/19] tests/tcg/i386: test-avx: add test cases for SHA new instructions Date: Thu, 19 Oct 2023 12:46:34 +0200 Message-ID: <20231019104648.389942-6-pbonzini@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231019104648.389942-1-pbonzini@redhat.com> References: <20231019104648.389942-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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1697712521611100003 Content-Type: text/plain; charset="utf-8" --- tests/tcg/i386/test-avx.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/tcg/i386/test-avx.py b/tests/tcg/i386/test-avx.py index 641a2ef69eb..6063fb2d11d 100755 --- a/tests/tcg/i386/test-avx.py +++ b/tests/tcg/i386/test-avx.py @@ -9,7 +9,7 @@ archs =3D [ "SSE", "SSE2", "SSE3", "SSSE3", "SSE4_1", "SSE4_2", "AES", "AVX", "AVX2", "AES+AVX", "VAES+AVX", - "F16C", "FMA", + "F16C", "FMA", "SHA", ] =20 ignore =3D set(["FISTTP", @@ -43,6 +43,7 @@ 'vPS[LR][AL][WDQ]': 0x3f, 'vPS[RL]LDQ': 0x1f, 'vROUND[PS][SD]': 0x7, + 'SHA1RNDS4': 0x03, 'vSHUFPD': 0x0f, 'vSHUFPS': 0xff, 'vAESKEYGENASSIST': 0xff, --=20 2.41.0 From nobody Wed Nov 27 15:47:24 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=1697712501; cv=none; d=zohomail.com; s=zohoarc; b=bo5t8geVPw2Rb35I7mx8y5rCkKBaZK3ScILc7mz4GDIpfSaVYi+A8qYFjSaObeTiPM3mhr4/nvcVeir1GtwFHmPCK1bSX3nFHfcXejRqIa/P5dv67g02JVGW9vD3fL4Z53+ZRWhSeOrcMvnx/qFVS0Yi/6Lzd8WfVrMgJD1ALaM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697712501; 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=Mjv64jVCOuqPeYMYCBxNq/eHVS7qvoiEDFreWLDNaaU=; b=GPUi+CNx90tGy7GC/aMjJ0NfognBGcZr+aEms4d7tMJfLP9uKpj5uF6bhCoVJW0pXdpiQTlVxUMaFljrDx+0GB8mJPF6vijwPRLPOvUdlIW05Jd68Zcwga8VvzwXbDdDYRRvh5QGk1JWXp7cE1mCMf65+ZklMrgpUEtgILaTwU4= 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 1697712501086715.9133684026041; Thu, 19 Oct 2023 03:48:21 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qtQYX-0006YB-HP; Thu, 19 Oct 2023 06:47:09 -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 1qtQYU-0006P2-Rd for qemu-devel@nongnu.org; Thu, 19 Oct 2023 06:47:06 -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 1qtQYT-0006DI-6s for qemu-devel@nongnu.org; Thu, 19 Oct 2023 06:47:06 -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-684-DS79yMYBPKWTDIi0ITZfLg-1; Thu, 19 Oct 2023 06:47:02 -0400 Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-9b9ecd8c351so540333366b.1 for ; Thu, 19 Oct 2023 03:47:02 -0700 (PDT) Received: from [192.168.10.118] ([2001:b07:6468:f312:5e2c:eb9a:a8b6:fd3e]) by smtp.gmail.com with ESMTPSA id 1-20020a170906014100b009bf7a4d591csm3384263ejh.11.2023.10.19.03.46.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 03:46:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697712424; 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=Mjv64jVCOuqPeYMYCBxNq/eHVS7qvoiEDFreWLDNaaU=; b=h/AdOhuxBbhVwNLMH9qvWAu8iSceTMawLtcj7sLdBwxNlpQy7fjnOoPpabgz0Jpj40h1WL 5s+LDCT9dbtovK3Vc8SBSo3FiltqVEv1DlSKQRUR429HqJUbuP11h2JKIlZV8SEc8dGWPY U9pMm1JHhe6yplvmnO/qMVe0OK+cgW0= X-MC-Unique: DS79yMYBPKWTDIi0ITZfLg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697712421; x=1698317221; 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=Mjv64jVCOuqPeYMYCBxNq/eHVS7qvoiEDFreWLDNaaU=; b=jHaBnc8hTBoKHNqsM2v0UvFY/SL97ZBUbxZpQtK8paMOjW/LwkRpJsIzUAigc60l4R HghuSgHXg7LazXsb6rr39Zkodqzhjmg0NZ61fQEUEavr5Vgs4/kmaSlNvMmS6GLMtt+a Mx/BH2fJlqzndPdcoQtzCqUughBkXya1gnz0pDOhumyjMXzd2Vrp6cMG+/MXwGr6XRTX Vmeq70QgyRk1czpegQq+ayfnO1QirqCi2Gc2/WlkJelwD81x+2lRyIIML1sIl5ripuGW h83HN5n7DIK39LVubTcwzRKH1MZshgqCH1hMZ3NjZEAO9A8y1ERQ8oU+Z6WnCXkWDJNR 8Idw== X-Gm-Message-State: AOJu0YyvSDWdvjV3R2XhHXC4BycQcshtzybAR8zdQhpQeO4JpFFRX6TD k75XfuttChWXJh+i+ykwjviufBPyIb4ce+QprZ9yqahI/mFGtyOQZkcmOJvmUmTi/yWxFKUw84n ZfA3EwCGEktqTj9ljrKCeVQS94Yn7gwrPjKMgRHVOMDAalxtfHKIvQsg5hQ/ZkMG9OublgPj1St Q= X-Received: by 2002:a17:907:97c3:b0:9c3:87ff:67b8 with SMTP id js3-20020a17090797c300b009c387ff67b8mr1621777ejc.2.1697712421230; Thu, 19 Oct 2023 03:47:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFH9SdduFAXh6+GboKOMKn4MG67ftjAUZv8iJoxjdDXF0BKljXa1FoRUdKCgl9BCbieZPP55A== X-Received: by 2002:a17:907:97c3:b0:9c3:87ff:67b8 with SMTP id js3-20020a17090797c300b009c387ff67b8mr1621765ejc.2.1697712420882; Thu, 19 Oct 2023 03:47:00 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH v2 06/19] target/i386: accept full MemOp in gen_ext_tl Date: Thu, 19 Oct 2023 12:46:35 +0200 Message-ID: <20231019104648.389942-7-pbonzini@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231019104648.389942-1-pbonzini@redhat.com> References: <20231019104648.389942-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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1697712501440100003 Content-Type: text/plain; charset="utf-8" Use MO_SIGN to indicate signed vs. unsigned extension, and filter out bits other than MO_SIGN and MO_SIZE. Signed-off-by: Paolo Bonzini --- target/i386/tcg/translate.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index 4f6f9fa7e52..d7d6c85877d 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -699,18 +699,18 @@ static inline void gen_op_movl_T0_Dshift(DisasContext= *s, MemOp ot) tcg_gen_shli_tl(s->T0, s->T0, ot); }; =20 -static TCGv gen_ext_tl(TCGv dst, TCGv src, MemOp size, bool sign) +static TCGv gen_ext_tl(TCGv dst, TCGv src, MemOp ot) { - switch (size) { + switch (ot & MO_SIZE) { case MO_8: - if (sign) { + if (ot & MO_SIGN) { tcg_gen_ext8s_tl(dst, src); } else { tcg_gen_ext8u_tl(dst, src); } return dst; case MO_16: - if (sign) { + if (ot & MO_SIGN) { tcg_gen_ext16s_tl(dst, src); } else { tcg_gen_ext16u_tl(dst, src); @@ -718,7 +718,7 @@ static TCGv gen_ext_tl(TCGv dst, TCGv src, MemOp size, = bool sign) return dst; #ifdef TARGET_X86_64 case MO_32: - if (sign) { + if (ot & MO_SIGN) { tcg_gen_ext32s_tl(dst, src); } else { tcg_gen_ext32u_tl(dst, src); @@ -732,12 +732,12 @@ static TCGv gen_ext_tl(TCGv dst, TCGv src, MemOp size= , bool sign) =20 static void gen_extu(MemOp ot, TCGv reg) { - gen_ext_tl(reg, reg, ot, false); + gen_ext_tl(reg, reg, ot); } =20 static void gen_exts(MemOp ot, TCGv reg) { - gen_ext_tl(reg, reg, ot, true); + gen_ext_tl(reg, reg, ot | MO_SIGN); } =20 static void gen_op_j_ecx(DisasContext *s, TCGCond cond, TCGLabel *label1) @@ -926,7 +926,7 @@ 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; - t1 =3D gen_ext_tl(s->tmp0, cpu_cc_src, size, false); + t1 =3D gen_ext_tl(s->tmp0, cpu_cc_src, size); /* If no temporary was used, be careful not to alias t1 and t0. */ t0 =3D t1 =3D=3D cpu_cc_src ? s->tmp0 : reg; tcg_gen_mov_tl(t0, s->cc_srcT); @@ -936,8 +936,8 @@ static CCPrepare gen_prepare_eflags_c(DisasContext *s, = TCGv reg) case CC_OP_ADDB ... CC_OP_ADDQ: /* (DATA_TYPE)CC_DST < (DATA_TYPE)CC_SRC */ size =3D s->cc_op - CC_OP_ADDB; - t1 =3D gen_ext_tl(s->tmp0, cpu_cc_src, size, false); - t0 =3D gen_ext_tl(reg, cpu_cc_dst, size, false); + t1 =3D gen_ext_tl(s->tmp0, cpu_cc_src, size); + t0 =3D gen_ext_tl(reg, cpu_cc_dst, size); add_sub: return (CCPrepare) { .cond =3D TCG_COND_LTU, .reg =3D t0, .reg2 =3D t1, .mask =3D -1, .use_reg2 =3D tru= e }; @@ -965,7 +965,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; - t0 =3D gen_ext_tl(reg, cpu_cc_src, size, false); + t0 =3D gen_ext_tl(reg, cpu_cc_src, size); return (CCPrepare) { .cond =3D TCG_COND_EQ, .reg =3D t0, .mask =3D= -1 }; =20 case CC_OP_ADCX: @@ -1017,7 +1017,7 @@ static CCPrepare gen_prepare_eflags_s(DisasContext *s= , TCGv reg) default: { MemOp size =3D (s->cc_op - CC_OP_ADDB) & 3; - TCGv t0 =3D gen_ext_tl(reg, cpu_cc_dst, size, true); + TCGv t0 =3D gen_ext_tl(reg, cpu_cc_dst, size | MO_SIGN); return (CCPrepare) { .cond =3D TCG_COND_LT, .reg =3D t0, .mask= =3D -1 }; } } @@ -1062,7 +1062,7 @@ static CCPrepare gen_prepare_eflags_z(DisasContext *s= , TCGv reg) default: { MemOp size =3D (s->cc_op - CC_OP_ADDB) & 3; - TCGv t0 =3D gen_ext_tl(reg, cpu_cc_dst, size, false); + TCGv t0 =3D gen_ext_tl(reg, cpu_cc_dst, size); return (CCPrepare) { .cond =3D TCG_COND_EQ, .reg =3D t0, .mask= =3D -1 }; } } @@ -1088,7 +1088,7 @@ static CCPrepare gen_prepare_cc(DisasContext *s, int = b, TCGv reg) case JCC_BE: tcg_gen_mov_tl(s->tmp4, s->cc_srcT); gen_extu(size, s->tmp4); - t0 =3D gen_ext_tl(s->tmp0, cpu_cc_src, size, false); + t0 =3D gen_ext_tl(s->tmp0, cpu_cc_src, size); cc =3D (CCPrepare) { .cond =3D TCG_COND_LEU, .reg =3D s->tmp4, .reg2 =3D t0, .mask =3D -1, .use_reg2 =3D t= rue }; break; @@ -1101,7 +1101,7 @@ static CCPrepare gen_prepare_cc(DisasContext *s, int = b, TCGv reg) fast_jcc_l: tcg_gen_mov_tl(s->tmp4, s->cc_srcT); gen_exts(size, s->tmp4); - t0 =3D gen_ext_tl(s->tmp0, cpu_cc_src, size, true); + t0 =3D gen_ext_tl(s->tmp0, cpu_cc_src, size | MO_SIGN); cc =3D (CCPrepare) { .cond =3D cond, .reg =3D s->tmp4, .reg2 =3D t0, .mask =3D -1, .use_reg2 =3D t= rue }; break; --=20 2.41.0 From nobody Wed Nov 27 15:47:24 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=1697712500; cv=none; d=zohomail.com; s=zohoarc; b=Ti/1yDcpAvyKn2D5yOf81huDipN9h4FsQjMiIePxlngJ0oXo9tK8bo+qKGg173/wqmAg1Vc1a9V+a3ZMHeff0LshnCShrarHnOasnD2l/oS7B9J0i48uhWR/Z6DJl3/Dbk5jLLEluQRtm8FwIJhF31YHo2yWLASfY2YpcTbxefI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697712500; 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=EOzbu/wjGWx2mr4yETlU7YsiT23Laltl4wFFEew5M0c=; b=Wa0h6qsq1nVGSMGPiY5B7/tjvMKBKSMBBaJa60hL5mUb1PsC43jbwyA6YCIaSEgO6Mp6KU3nVTbre3fnwPsKpG07ua1unv72pfoDx8S9sBtF1kjof+8P3NY0DkRCiIV5YDmhuRAc7f3PeClNbjMiN5NymrhHfCd/V/PjybllEYE= 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 1697712500822202.45302152965792; Thu, 19 Oct 2023 03:48:20 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qtQZ8-0006yw-U0; Thu, 19 Oct 2023 06:47:46 -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 1qtQYh-0006Za-17 for qemu-devel@nongnu.org; Thu, 19 Oct 2023 06:47:20 -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 1qtQYf-0006Eu-4W for qemu-devel@nongnu.org; Thu, 19 Oct 2023 06:47:18 -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-621-T6Wg2kARO8mdTBSqFwUdQQ-1; Thu, 19 Oct 2023 06:47:04 -0400 Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-9bea60bd1adso72935766b.0 for ; Thu, 19 Oct 2023 03:47:04 -0700 (PDT) Received: from [192.168.10.118] ([2001:b07:6468:f312:5e2c:eb9a:a8b6:fd3e]) by smtp.gmail.com with ESMTPSA id a13-20020a1709064a4d00b009930042510csm3338815ejv.222.2023.10.19.03.47.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 03:47:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697712435; 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=EOzbu/wjGWx2mr4yETlU7YsiT23Laltl4wFFEew5M0c=; b=Cyej6BQ9Lz5wzB4JIuq3L6rSsMZ59pfBmNAx3ilucXkTjPXm2f8ZErxmfq4mF+gRJS8jIt vBgxAOYx174Z+U9uGWJVMrmtfe69PDii/VwoiE8g7gtmKSjNWxTqqcDazF8WBePFniKvnD Me9g0qeb5DgBq9gTHQblUXMYoWYvpEo= X-MC-Unique: T6Wg2kARO8mdTBSqFwUdQQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697712423; x=1698317223; 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=EOzbu/wjGWx2mr4yETlU7YsiT23Laltl4wFFEew5M0c=; b=MIRUBurNnbjU5kJaL8hRKgdIV8oPRAZJ/nJcB2onxmqmRQxwgua9YnVAHNokTMpCe0 CbOdWpiAv1qnppqr50uNY1pIbQevIyFvR5LD19XAcVYiM264mSfx7CL9zPt8jG91/3wB 6P88tHWf4BeSBaTHsa0FNgmqNAQ6WNNPhJ70pST3PsiuSbVe7yi/NJ/7IbE7qCbqp3fR PnHlUjuQ9LYfA5wVjH2pXR4vXesgAMEzGxPSDun5/lUYuYY90PUItGjuIKfKAvRK8Uyo xi4jM54u5ObazWkCH7HWD2zG2m9318JjjFrAyuxbwi/d3PKod76o4xpdJTDFFCz1E2q5 dPEQ== X-Gm-Message-State: AOJu0YztEESry1CbrlTq8UFMvqKZuUhahc9u02KP4jRbeZ5paALSTp37 1E+h5TGMmArFLGK3KXQapZj9mazMu82MrXyQdesV2xy5lbLNFNdvpM3CBx8heLK2LKe6oGBMwsx lbTj5imUj7xo8e/9Vp3uMy9yRu+PMiAGIep41ff3wr4r8ZqxI1lBEC5/L+rpEP8BtDY1sUGUfDZ c= X-Received: by 2002:a17:907:7e91:b0:9ae:5df2:2291 with SMTP id qb17-20020a1709077e9100b009ae5df22291mr1644646ejc.1.1697712423072; Thu, 19 Oct 2023 03:47:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFxXBr2mN+rekQr7nnh3RYGlV00Z0hxUVtS3ArzqvMPYU3YawtW0HULO8OAn3aEw6eY4Vy7rQ== X-Received: by 2002:a17:907:7e91:b0:9ae:5df2:2291 with SMTP id qb17-20020a1709077e9100b009ae5df22291mr1644624ejc.1.1697712422634; Thu, 19 Oct 2023 03:47:02 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH v2 07/19] target/i386: introduce flags writeback mechanism Date: Thu, 19 Oct 2023 12:46:36 +0200 Message-ID: <20231019104648.389942-8-pbonzini@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231019104648.389942-1-pbonzini@redhat.com> References: <20231019104648.389942-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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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 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: 1697712501443100004 Content-Type: text/plain; charset="utf-8" ALU instructions can write to both memory and flags. If the CC_SRC* and CC_DST locations have been written already when a memory access causes a fault, the value in CC_SRC* and CC_DST might be interpreted with the wrong CC_OP (the one that is in effect before the instruction. Besides just using the wrong result for the flags, something like subtracting -1 can have disastrous effects if the current CC_OP is CC_OP_EFLAGS: this is because QEMU does not expect bits outside the ALU flags to be set in CC_SRC, and env->eflags can end up set to all-ones. In the case of the attached testcase, this sets IOPL to 3 and would cause an assertion failure if SUB is moved to the new decoder. This mechanism is not really needed for BMI instructions, which can only write to a register, but put it to use anyway for cleanliness. Signed-off-by: Paolo Bonzini --- target/i386/cpu.h | 1 + target/i386/tcg/decode-new.c.inc | 31 ++++++++++++++++++++++++++ target/i386/tcg/decode-new.h | 4 ++++ target/i386/tcg/emit.c.inc | 19 ++++++++++------ tests/tcg/i386/Makefile.target | 2 +- tests/tcg/i386/test-flags.c | 37 ++++++++++++++++++++++++++++++++ 6 files changed, 87 insertions(+), 7 deletions(-) create mode 100644 tests/tcg/i386/test-flags.c diff --git a/target/i386/cpu.h b/target/i386/cpu.h index e1875466b9d..94a5137f068 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1285,6 +1285,7 @@ typedef enum { =20 CC_OP_NB, } CCOp; +QEMU_BUILD_BUG_ON(CC_OP_NB >=3D 128); =20 typedef struct SegmentCache { uint32_t selector; diff --git a/target/i386/tcg/decode-new.c.inc b/target/i386/tcg/decode-new.= c.inc index eb2400095f8..0a2aebf2ebb 100644 --- a/target/i386/tcg/decode-new.c.inc +++ b/target/i386/tcg/decode-new.c.inc @@ -1823,6 +1823,7 @@ static void disas_insn_new(DisasContext *s, CPUState = *cpu, int b) } =20 memset(&decode, 0, sizeof(decode)); + decode.cc_op =3D -1; decode.b =3D b; if (!decode_insn(s, env, decode_func, &decode)) { goto illegal_op; @@ -1943,6 +1944,36 @@ static void disas_insn_new(DisasContext *s, CPUState= *cpu, int b) decode.e.gen(s, env, &decode); gen_writeback(s, &decode, 0, s->T0); } + + /* + * Write back flags after last memory access. Some newer ALU instruct= ions, as + * well as SSE instructions, write flags in the gen_* function, but th= at can + * cause incorrect tracking of CC_OP for instructions that write to bo= th memory + * and flags. + */ + if (decode.cc_op !=3D -1) { + if (decode.cc_dst) { + tcg_gen_mov_tl(cpu_cc_dst, decode.cc_dst); + } + if (decode.cc_src) { + tcg_gen_mov_tl(cpu_cc_src, decode.cc_src); + } + if (decode.cc_src2) { + tcg_gen_mov_tl(cpu_cc_src2, decode.cc_src2); + } + if (decode.cc_op =3D=3D CC_OP_DYNAMIC) { + tcg_gen_mov_i32(cpu_cc_op, decode.cc_op_dynamic); + } else { + assert(!decode.cc_op_dynamic); + } + set_cc_op(s, decode.cc_op); + } else { + assert(!decode.cc_dst); + assert(!decode.cc_src); + assert(!decode.cc_src2); + assert(!decode.cc_op_dynamic); + } + return; gp_fault: gen_exception_gpf(s); diff --git a/target/i386/tcg/decode-new.h b/target/i386/tcg/decode-new.h index ab21fa6db97..4258db19899 100644 --- a/target/i386/tcg/decode-new.h +++ b/target/i386/tcg/decode-new.h @@ -265,6 +265,10 @@ struct X86DecodedInsn { target_ulong immediate; AddressParts mem; =20 + TCGv cc_dst, cc_src, cc_src2; + TCGv_i32 cc_op_dynamic; + int8_t cc_op; + uint8_t b; }; =20 diff --git a/target/i386/tcg/emit.c.inc b/target/i386/tcg/emit.c.inc index 82da5488d47..90da1401745 100644 --- a/target/i386/tcg/emit.c.inc +++ b/target/i386/tcg/emit.c.inc @@ -323,6 +323,12 @@ static inline int vector_len(DisasContext *s, X86Decod= edInsn *decode) return s->vex_l ? 32 : 16; } =20 +static void prepare_update1_cc(X86DecodedInsn *decode, DisasContext *s, CC= Op op) +{ + decode->cc_dst =3D s->T0; + decode->cc_op =3D op; +} + static void gen_store_sse(DisasContext *s, X86DecodedInsn *decode, int src= _ofs) { MemOp ot =3D decode->op[0].ot; @@ -1011,6 +1017,7 @@ static void gen_##uname(DisasContext *s, CPUX86State = *env, X86DecodedInsn *decod VSIB_AVX(VPGATHERD, vpgatherd) VSIB_AVX(VPGATHERQ, vpgatherq) =20 +/* ADCX/ADOX do not have memory operands and can use set_cc_op. */ static void gen_ADCOX(DisasContext *s, CPUX86State *env, MemOp ot, int cc_= op) { int opposite_cc_op; @@ -1073,8 +1080,7 @@ static void gen_ANDN(DisasContext *s, CPUX86State *en= v, X86DecodedInsn *decode) MemOp ot =3D decode->op[0].ot; =20 tcg_gen_andc_tl(s->T0, s->T1, s->T0); - gen_op_update1_cc(s); - set_cc_op(s, CC_OP_LOGICB + ot); + prepare_update1_cc(decode, s, CC_OP_LOGICB + ot); } =20 static void gen_BEXTR(DisasContext *s, CPUX86State *env, X86DecodedInsn *d= ecode) @@ -1105,10 +1111,10 @@ static void gen_BEXTR(DisasContext *s, CPUX86State = *env, X86DecodedInsn *decode) tcg_gen_movcond_tl(TCG_COND_LEU, s->T1, s->A0, bound, s->T1, zero); tcg_gen_andc_tl(s->T0, s->T0, s->T1); =20 - gen_op_update1_cc(s); - set_cc_op(s, CC_OP_LOGICB + ot); + prepare_update1_cc(decode, s, CC_OP_LOGICB + ot); } =20 +/* BLSI do not have memory operands and can use set_cc_op. */ static void gen_BLSI(DisasContext *s, CPUX86State *env, X86DecodedInsn *de= code) { MemOp ot =3D decode->op[0].ot; @@ -1120,6 +1126,7 @@ static void gen_BLSI(DisasContext *s, CPUX86State *en= v, X86DecodedInsn *decode) set_cc_op(s, CC_OP_BMILGB + ot); } =20 +/* BLSMSK do not have memory operands and can use set_cc_op. */ static void gen_BLSMSK(DisasContext *s, CPUX86State *env, X86DecodedInsn *= decode) { MemOp ot =3D decode->op[0].ot; @@ -1131,6 +1138,7 @@ static void gen_BLSMSK(DisasContext *s, CPUX86State *= env, X86DecodedInsn *decode set_cc_op(s, CC_OP_BMILGB + ot); } =20 +/* BLSR do not have memory operands and can use set_cc_op. */ static void gen_BLSR(DisasContext *s, CPUX86State *env, X86DecodedInsn *de= code) { MemOp ot =3D decode->op[0].ot; @@ -1161,8 +1169,7 @@ static void gen_BZHI(DisasContext *s, CPUX86State *en= v, X86DecodedInsn *decode) tcg_gen_movcond_tl(TCG_COND_LEU, s->A0, s->T1, bound, s->A0, zero); tcg_gen_andc_tl(s->T0, s->T0, s->A0); =20 - gen_op_update1_cc(s); - set_cc_op(s, CC_OP_BMILGB + ot); + prepare_update1_cc(decode, s, CC_OP_BMILGB + ot); } =20 static void gen_CRC32(DisasContext *s, CPUX86State *env, X86DecodedInsn *d= ecode) diff --git a/tests/tcg/i386/Makefile.target b/tests/tcg/i386/Makefile.target index fdf757c6ce4..ca0f543ef16 100644 --- a/tests/tcg/i386/Makefile.target +++ b/tests/tcg/i386/Makefile.target @@ -13,7 +13,7 @@ config-cc.mak: Makefile =20 I386_SRCS=3D$(notdir $(wildcard $(I386_SRC)/*.c)) ALL_X86_TESTS=3D$(I386_SRCS:.c=3D) -SKIP_I386_TESTS=3Dtest-i386-ssse3 test-avx test-3dnow test-mmx +SKIP_I386_TESTS=3Dtest-i386-ssse3 test-avx test-3dnow test-mmx test-flags X86_64_TESTS:=3D$(filter test-i386-adcox test-i386-bmi2 $(SKIP_I386_TESTS)= , $(ALL_X86_TESTS)) =20 test-i386-sse-exceptions: CFLAGS +=3D -msse4.1 -mfpmath=3Dsse diff --git a/tests/tcg/i386/test-flags.c b/tests/tcg/i386/test-flags.c new file mode 100644 index 00000000000..c379e296275 --- /dev/null +++ b/tests/tcg/i386/test-flags.c @@ -0,0 +1,37 @@ +#define _GNU_SOURCE +#include +#include +#include +#include + +volatile unsigned long flags; +volatile unsigned long flags_after; +int *addr; + +void sigsegv(int sig, siginfo_t *info, ucontext_t *uc) +{ + flags =3D uc->uc_mcontext.gregs[REG_EFL]; + mprotect(addr, 4096, PROT_READ|PROT_WRITE); +} + +int main() +{ + struct sigaction sa =3D { .sa_handler =3D (void *)sigsegv, .sa_flags = =3D SA_SIGINFO }; + sigaction(SIGSEGV, &sa, NULL); + + /* fault in the page then protect it */ + addr =3D mmap (NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON,= -1, 0); + *addr =3D 0x1234; + mprotect(addr, 4096, PROT_READ); + + asm("# set flags to all ones \n" + "mov $-1, %%eax \n" + "movq addr, %%rdi \n" + "sahf \n" + "sub %%eax, (%%rdi) \n" + "pushf \n" + "pop flags_after(%%rip) \n" : : : "eax", "edi", "memory"); + + /* OF can have any value before the SUB instruction. */ + assert((flags & 0xff) =3D=3D 0xd7 && (flags_after & 0x8ff) =3D=3D 0x17= ); +} --=20 2.41.0 From nobody Wed Nov 27 15:47:24 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=1697712500; cv=none; d=zohomail.com; s=zohoarc; b=BfeoB3ghKJgJUvSvHm6K4LK61qH+daIuln4RB9Z4/wcspbDmN+LTCWst/31GcZr/iBpGSpuJ31xry7jyjDSK2kI4orrMvLd8XVkUnN+ebmwVcTkC7PozRInrb2MWF7yRjQRSqdbQbJZjcLw3kzVNtHLMmyy3lxZ8kf/fdkrKLn0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697712500; 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=QKWaLD3NI87qdlaeYUXambR1Z2tAzEBYr1xgMGdEWOk=; b=bvHLbuxTa5AUqBHua9gFcFSIqtlrmtcQJICoB7HlZJEXnd/cM/w9fS4KDdeuUsMyRDOtpbwKgMuPqKqCxJDcQWPwmSgkyvvYKDRDT59fhtmfBehcUs9RtO0kqW5oJqV9zAuqR5qEz6uVkS3qlbM8SWNr+r2w7VSq8IiZ5OKFheU= 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 1697712500160892.6713027778165; Thu, 19 Oct 2023 03:48:20 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qtQYa-0006Yz-3G; Thu, 19 Oct 2023 06:47:12 -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 1qtQYY-0006YV-Pz for qemu-devel@nongnu.org; Thu, 19 Oct 2023 06:47:10 -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 1qtQYW-0006Dt-OD for qemu-devel@nongnu.org; Thu, 19 Oct 2023 06:47:10 -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-16-9UWnqmzyM6mDIuxpq-4xJA-1; Thu, 19 Oct 2023 06:47:06 -0400 Received: by mail-ed1-f72.google.com with SMTP id 4fb4d7f45d1cf-533d8a785a5so6305283a12.3 for ; Thu, 19 Oct 2023 03:47:06 -0700 (PDT) Received: from [192.168.10.118] ([2001:b07:6468:f312:5e2c:eb9a:a8b6:fd3e]) by smtp.gmail.com with ESMTPSA id gh6-20020a170906e08600b00977cad140a8sm3312456ejb.218.2023.10.19.03.47.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 03:47:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697712428; 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=QKWaLD3NI87qdlaeYUXambR1Z2tAzEBYr1xgMGdEWOk=; b=PPDroQJuHVnxeO4JoSvKC4bg0KlVISvWOM3KP+bYgkxReA5pJ4PH9e/j/GXuM8N6BNtTxE GZKXmBl6xc2hC5ZwLvekz5sWtgOIagVuVEGVYbE3ZcRhhI4Lw2+gPA+Dufmxp534ztUpGQ UTspH6e6YbInysq5dDJvDW2GzFMtb9k= X-MC-Unique: 9UWnqmzyM6mDIuxpq-4xJA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697712425; x=1698317225; 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=QKWaLD3NI87qdlaeYUXambR1Z2tAzEBYr1xgMGdEWOk=; b=NR/2Z1KsJXGAB3kCG5qUSPxU9rmWoojSybJ8gvQJLy3PsLym19bzi/bThf0wBa9KmH 4tDE8nt7u0ac6UwM8SQ+sJi7Txb5etuO2wYcqYXabpvf6REbCdWYTuxV/22ubkdQAgH2 N9VkpKGJ2SDDvpjE7MwwAwllFwWfUyGogzkWQrN8uypnOlzZRZRo78Sh9N1uihZJ1V5U SVNshqrPkzCu3iCh3QTmvW9SoK+LhIlZjS1l9a1dPHqHdTbvWDWqh/TI0kAoma3OddaN ZeIA5CA6X3Lr/UnNvH4hSZQjO5kHMQdFBz26PVrEhNWgxDlcGZT6QqNy1BBUZ1i1TAtz ajJg== X-Gm-Message-State: AOJu0YyyBhOlCn3FxfTq7wSvL/ABxJAfrbqNJJSecf0kAIaIUyxeKyg/ fKS45SC/Ww1moodL2kye+R1QR7CyjTctdz/e483BLTNpcKfDr41qJidXhu3Z2dI0BTFh3IDCu7h lQVvttFp/digWDR5/fcJ232Eavp7R7d5+aCRnVj4U6hlq/6Jz/sQYOWwba/VPxiDGJkOyIE60tZ U= X-Received: by 2002:a17:906:d552:b0:9c6:64be:a3c9 with SMTP id cr18-20020a170906d55200b009c664bea3c9mr1325320ejc.39.1697712424869; Thu, 19 Oct 2023 03:47:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHM++O382ORZPRaq4XqvfIixcgckYoXPdlJZqes6/iSzwdHkX9PlrtDgPz81C/Zv4mMRYeEbg== X-Received: by 2002:a17:906:d552:b0:9c6:64be:a3c9 with SMTP id cr18-20020a170906d55200b009c664bea3c9mr1325305ejc.39.1697712424476; Thu, 19 Oct 2023 03:47:04 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH v2 08/19] target/i386: implement CMPccXADD Date: Thu, 19 Oct 2023 12:46:37 +0200 Message-ID: <20231019104648.389942-9-pbonzini@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231019104648.389942-1-pbonzini@redhat.com> References: <20231019104648.389942-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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1697712501484100007 Content-Type: text/plain; charset="utf-8" The main difficulty here is that a page fault when writing to the destinati= on must not overwrite the flags. Therefore, the compute-flags helper must be called with a temporary destination instead of using gen_jcc1*. For simplicity, I am using an unconditional cmpxchg operation, that becomes a NOP if the comparison fails. Signed-off-by: Paolo Bonzini --- target/i386/cpu.c | 2 +- target/i386/tcg/decode-new.c.inc | 30 ++++++++++ target/i386/tcg/decode-new.h | 2 + target/i386/tcg/emit.c.inc | 98 ++++++++++++++++++++++++++++++++ target/i386/tcg/translate.c | 2 + 5 files changed, 133 insertions(+), 1 deletion(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 070c02000fe..15fc9d44e35 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -738,7 +738,7 @@ void x86_cpu_vendor_words2str(char *dst, uint32_t vendo= r1, #define TCG_7_0_EDX_FEATURES (CPUID_7_0_EDX_FSRM | CPUID_7_0_EDX_KERNEL_FE= ATURES) =20 #define TCG_7_1_EAX_FEATURES (CPUID_7_1_EAX_FZRM | CPUID_7_1_EAX_FSRS | \ - CPUID_7_1_EAX_FSRC) + CPUID_7_1_EAX_FSRC | CPUID_7_1_EAX_CMPCCXADD) #define TCG_7_1_EDX_FEATURES 0 #define TCG_7_2_EDX_FEATURES 0 #define TCG_APM_FEATURES 0 diff --git a/target/i386/tcg/decode-new.c.inc b/target/i386/tcg/decode-new.= c.inc index 0a2aebf2ebb..57a5014bc8a 100644 --- a/target/i386/tcg/decode-new.c.inc +++ b/target/i386/tcg/decode-new.c.inc @@ -516,6 +516,28 @@ static const X86OpEntry opcodes_0F38_00toEF[240] =3D { [0xdd] =3D X86_OP_ENTRY3(VAESENCLAST, V,x, H,x, W,x, vex4 cpui= d(AES) p_66), [0xde] =3D X86_OP_ENTRY3(VAESDEC, V,x, H,x, W,x, vex4 cpui= d(AES) p_66), [0xdf] =3D X86_OP_ENTRY3(VAESDECLAST, V,x, H,x, W,x, vex4 cpui= d(AES) p_66), + + /* + * REG selects srcdest2 operand, VEX.vvvv selects src3. VEX class not= found + * in manual, assumed to be 13 from the VEX.L0 =3D constraint. + */ + [0xe0] =3D X86_OP_ENTRY3(CMPccXADD, EM,y, G,y, B,y, vex13 xchg chk(= o64) cpuid(CMPCCXADD) p_66), + [0xe1] =3D X86_OP_ENTRY3(CMPccXADD, EM,y, G,y, B,y, vex13 xchg chk(= o64) cpuid(CMPCCXADD) p_66), + [0xe2] =3D X86_OP_ENTRY3(CMPccXADD, EM,y, G,y, B,y, vex13 xchg chk(= o64) cpuid(CMPCCXADD) p_66), + [0xe3] =3D X86_OP_ENTRY3(CMPccXADD, EM,y, G,y, B,y, vex13 xchg chk(= o64) cpuid(CMPCCXADD) p_66), + [0xe4] =3D X86_OP_ENTRY3(CMPccXADD, EM,y, G,y, B,y, vex13 xchg chk(= o64) cpuid(CMPCCXADD) p_66), + [0xe5] =3D X86_OP_ENTRY3(CMPccXADD, EM,y, G,y, B,y, vex13 xchg chk(= o64) cpuid(CMPCCXADD) p_66), + [0xe6] =3D X86_OP_ENTRY3(CMPccXADD, EM,y, G,y, B,y, vex13 xchg chk(= o64) cpuid(CMPCCXADD) p_66), + [0xe7] =3D X86_OP_ENTRY3(CMPccXADD, EM,y, G,y, B,y, vex13 xchg chk(= o64) cpuid(CMPCCXADD) p_66), + + [0xe8] =3D X86_OP_ENTRY3(CMPccXADD, EM,y, G,y, B,y, vex13 xchg chk(= o64) cpuid(CMPCCXADD) p_66), + [0xe9] =3D X86_OP_ENTRY3(CMPccXADD, EM,y, G,y, B,y, vex13 xchg chk(= o64) cpuid(CMPCCXADD) p_66), + [0xea] =3D X86_OP_ENTRY3(CMPccXADD, EM,y, G,y, B,y, vex13 xchg chk(= o64) cpuid(CMPCCXADD) p_66), + [0xeb] =3D X86_OP_ENTRY3(CMPccXADD, EM,y, G,y, B,y, vex13 xchg chk(= o64) cpuid(CMPCCXADD) p_66), + [0xec] =3D X86_OP_ENTRY3(CMPccXADD, EM,y, G,y, B,y, vex13 xchg chk(= o64) cpuid(CMPCCXADD) p_66), + [0xed] =3D X86_OP_ENTRY3(CMPccXADD, EM,y, G,y, B,y, vex13 xchg chk(= o64) cpuid(CMPCCXADD) p_66), + [0xee] =3D X86_OP_ENTRY3(CMPccXADD, EM,y, G,y, B,y, vex13 xchg chk(= o64) cpuid(CMPCCXADD) p_66), + [0xef] =3D X86_OP_ENTRY3(CMPccXADD, EM,y, G,y, B,y, vex13 xchg chk(= o64) cpuid(CMPCCXADD) p_66), }; =20 /* five rows for no prefix, 66, F3, F2, 66+F2 */ @@ -1273,8 +1295,13 @@ static bool decode_op(DisasContext *s, CPUX86State *= env, X86DecodedInsn *decode, =20 case X86_TYPE_WM: /* modrm byte selects an XMM/YMM memory operand */ op->unit =3D X86_OP_SSE; + goto get_modrm_mem; + + case X86_TYPE_EM: /* modrm byte selects an ALU memory operand */ + op->unit =3D X86_OP_INT; /* fall through */ case X86_TYPE_M: /* modrm byte selects a memory operand */ + get_modrm_mem: modrm =3D get_modrm(s, env); if ((modrm >> 6) =3D=3D 3) { return false; @@ -1511,6 +1538,9 @@ static bool has_cpuid_feature(DisasContext *s, X86CPU= IDFeature cpuid) return (s->cpuid_7_0_ebx_features & CPUID_7_0_EBX_AVX2); case X86_FEAT_SHA_NI: return (s->cpuid_7_0_ebx_features & CPUID_7_0_EBX_SHA_NI); + + case X86_FEAT_CMPCCXADD: + return (s->cpuid_7_1_eax_features & CPUID_7_1_EAX_CMPCCXADD); } g_assert_not_reached(); } diff --git a/target/i386/tcg/decode-new.h b/target/i386/tcg/decode-new.h index 4258db19899..15233fad62f 100644 --- a/target/i386/tcg/decode-new.h +++ b/target/i386/tcg/decode-new.h @@ -47,6 +47,7 @@ typedef enum X86OpType { X86_TYPE_Y, /* string destination */ =20 /* Custom */ + X86_TYPE_EM, /* modrm byte selects an ALU memory operand */ X86_TYPE_WM, /* modrm byte selects an XMM/YMM memory operand */ X86_TYPE_2op, /* 2-operand RMW instruction */ X86_TYPE_LoBits, /* encoded in bits 0-2 of the operand + REX.B */ @@ -104,6 +105,7 @@ typedef enum X86CPUIDFeature { X86_FEAT_AVX2, X86_FEAT_BMI1, X86_FEAT_BMI2, + X86_FEAT_CMPCCXADD, X86_FEAT_F16C, X86_FEAT_FMA, X86_FEAT_MOVBE, diff --git a/target/i386/tcg/emit.c.inc b/target/i386/tcg/emit.c.inc index 90da1401745..dd77a8c5511 100644 --- a/target/i386/tcg/emit.c.inc +++ b/target/i386/tcg/emit.c.inc @@ -1172,6 +1172,104 @@ static void gen_BZHI(DisasContext *s, CPUX86State *= env, X86DecodedInsn *decode) prepare_update1_cc(decode, s, CC_OP_BMILGB + ot); } =20 +static void gen_CMPccXADD(DisasContext *s, CPUX86State *env, X86DecodedIns= n *decode) +{ + TCGv z_tl =3D tcg_constant_tl(0); + TCGLabel *label_top =3D gen_new_label(); + TCGLabel *label_bottom =3D gen_new_label(); + TCGv oldv =3D tcg_temp_new(); + TCGv newv =3D tcg_temp_new(); + TCGv cmpv =3D tcg_temp_new(); + TCGv tmp_cc =3D tcg_temp_new(); + + TCGv cmp_lhs, cmp_rhs; + MemOp ot, ot_full; + + int jcc_op =3D (decode->b >> 1) & 7; + static const uint8_t cond[16] =3D { + TCG_COND_NE, /* o, just test OF=3D1 */ + TCG_COND_EQ, /* no, just test OF=3D0 */ + TCG_COND_LTU, /* b */ + TCG_COND_GEU, /* ae (nb) */ + TCG_COND_EQ, /* z */ + TCG_COND_NE, /* nz */ + TCG_COND_LEU, /* be */ + TCG_COND_GTU, /* a (nbe) */ + TCG_COND_LT, /* s, compares result against 0 */ + TCG_COND_GE, /* ns, compares result against 0 */ + TCG_COND_NE, /* p, just test PF=3D1 */ + TCG_COND_EQ, /* np, just test PF=3D0 */ + TCG_COND_LT, /* l */ + TCG_COND_GE, /* ge (nl) */ + TCG_COND_LE, /* le */ + TCG_COND_GT, /* g (nle) */ + }; + + ot =3D decode->op[0].ot; + ot_full =3D ot | MO_LE; + if (jcc_op >=3D JCC_S) { + /* + * Sign-extend values before subtracting for S, P (zero/sign exten= sion + * does not matter there) L, LE and their inverses. + */ + ot_full |=3D MO_SIGN; + } + + gen_ext_tl(cmpv, cpu_regs[decode->op[1].n], ot_full); + + /* + * Cmpxchg loop starts here. + * - s->T1: addition operand (from decoder) + * - s->A0: dest address (from decoder) + * - s->cc_srcT: memory operand (lhs for comparison) + * - cmpv: rhs for comparison (will be in cc_src except for o/no/p/np); + */ + gen_set_label(label_top); + gen_op_ld_v(s, ot_full, s->cc_srcT, s->A0); + tcg_gen_sub_tl(s->T0, s->cc_srcT, cmpv); + + /* Compute comparison result but do not clobber cc_* yet. */ + switch (jcc_op) { + case JCC_O: + case JCC_P: + gen_helper_cc_compute_all(tmp_cc, s->T0, cmpv, z_tl, + tcg_constant_i32(CC_OP_SUBB + ot)); + decode->cc_src =3D tmp_cc; + decode->cc_op =3D CC_OP_EFLAGS; + + tcg_gen_andi_tl(s->T0, tmp_cc, (jcc_op =3D=3D JCC_O ? CC_O : CC_P)= ); + cmp_lhs =3D s->T0, cmp_rhs =3D z_tl; + break; + + case JCC_S: + cmp_lhs =3D s->T0, cmp_rhs =3D z_tl; + goto cc_sub; + + default: + cmp_lhs =3D s->cc_srcT, cmp_rhs =3D cmpv; + cc_sub: + decode->cc_dst =3D s->T0; + decode->cc_src =3D cmpv; + decode->cc_op =3D CC_OP_SUBB + ot; + break; + } + + /* Compute new value: if condition does not hold, just store back s->c= c_srcT */ + tcg_gen_add_tl(newv, s->cc_srcT, s->T1); + tcg_gen_movcond_tl(cond[decode->b & 15], newv, cmp_lhs, cmp_rhs, newv,= s->cc_srcT); + tcg_gen_atomic_cmpxchg_tl(oldv, s->A0, s->cc_srcT, newv, s->mem_index,= ot_full); + + /* Exit unconditionally if cmpxchg succeeded. */ + tcg_gen_brcond_tl(TCG_COND_EQ, oldv, s->cc_srcT, label_bottom); + + /* Try again if there was actually a store to make. */ + tcg_gen_brcond_tl(cond[decode->b & 15], cmp_lhs, cmp_rhs, label_top); + gen_set_label(label_bottom); + + /* Store old value to registers only after a successful store. */ + gen_writeback(s, decode, 1, s->cc_srcT); +} + static void gen_CRC32(DisasContext *s, CPUX86State *env, X86DecodedInsn *d= ecode) { MemOp ot =3D decode->op[2].ot; diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index d7d6c85877d..038151a8c3e 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -122,6 +122,7 @@ typedef struct DisasContext { int cpuid_ext3_features; int cpuid_7_0_ebx_features; int cpuid_7_0_ecx_features; + int cpuid_7_1_eax_features; int cpuid_xsave_features; =20 /* TCG local temps */ @@ -6957,6 +6958,7 @@ static void i386_tr_init_disas_context(DisasContextBa= se *dcbase, CPUState *cpu) dc->cpuid_ext3_features =3D env->features[FEAT_8000_0001_ECX]; dc->cpuid_7_0_ebx_features =3D env->features[FEAT_7_0_EBX]; dc->cpuid_7_0_ecx_features =3D env->features[FEAT_7_0_ECX]; + dc->cpuid_7_1_eax_features =3D env->features[FEAT_7_1_EAX]; dc->cpuid_xsave_features =3D env->features[FEAT_XSAVE]; dc->jmp_opt =3D !((cflags & CF_NO_GOTO_TB) || (flags & (HF_TF_MASK | HF_INHIBIT_IRQ_MASK))); --=20 2.41.0 From nobody Wed Nov 27 15:47:24 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=1697712483; cv=none; d=zohomail.com; s=zohoarc; b=HLo/1XNYNo2Sxhzsauj9oGFc+rosDcZYkNZAgKbqTbpCvhhJ+l9hkHXe4Ov2BcOnOyqS08UPkmeNDEY26WDZBuSsterc0zGCDyUi+97hmm+6CYsz0rTLM41Uvz+RpLXzrjx5RW2W8MDAOdZsH2WSGZW2aJIUks2AJ9GefVW9qXU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697712483; 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=DuoXc2BU+ZIapePNKXerF9ciZjLeynT5HD0XoYbHuRI=; b=K4TOCHSFID9CLnuvI+TgQgxFMBgnFguk7rblze35/h6t8NvkUnorUuT+D64k4bpdTeqIdn7m1FEdyLA1bk6tpkw+VQYByntkXDYr/KwBRkx80Qh4WP8IucitQJ9W1A4w67MNbRiRfORlIpH9dIziCSG0wRv+ZClwSvAxGR1O2BI= 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 1697712483636767.4930088922579; Thu, 19 Oct 2023 03:48:03 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qtQZ8-0006vT-KT; Thu, 19 Oct 2023 06:47:46 -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 1qtQYf-0006ZV-Bo for qemu-devel@nongnu.org; Thu, 19 Oct 2023 06:47:20 -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 1qtQYd-0006El-9X for qemu-devel@nongnu.org; Thu, 19 Oct 2023 06:47:17 -0400 Received: from mail-lf1-f72.google.com (mail-lf1-f72.google.com [209.85.167.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-120-oUewJLerO8m1y_6NnY-Ppw-1; Thu, 19 Oct 2023 06:47:08 -0400 Received: by mail-lf1-f72.google.com with SMTP id 2adb3069b0e04-507cee14477so928364e87.3 for ; Thu, 19 Oct 2023 03:47:08 -0700 (PDT) Received: from [192.168.10.118] ([2001:b07:6468:f312:5e2c:eb9a:a8b6:fd3e]) by smtp.gmail.com with ESMTPSA id u27-20020a50a41b000000b0053dd798e38asm4293050edb.69.2023.10.19.03.47.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 03:47:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697712434; 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=DuoXc2BU+ZIapePNKXerF9ciZjLeynT5HD0XoYbHuRI=; b=UibnAj5adNBbqDAhqkzdZHITNcg9drs85GF/knDzx1L8ZFgZ26jUZxt0839j1eMwgDknlQ VjCh+ASoXX2Bt/C7toNDDThsuEs9kcnonmzrpKJMI0q7c3IqSucS1P+DlElAr97+glY9L6 uTdl2FUvFUAZ4ZGqaNa0VAoRIIGsEEM= X-MC-Unique: oUewJLerO8m1y_6NnY-Ppw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697712426; x=1698317226; 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=DuoXc2BU+ZIapePNKXerF9ciZjLeynT5HD0XoYbHuRI=; b=Sk1sE0vdHqi+4DR/1r1HgWoZlAgslH9fCGwfujz9hzAbh4H6hIjEnikgMlhbhIzkHJ hyhboZJXJvCOcKYGZsmxTOZcu6AFcOQxxxnTWPLnBa/lGkZB8CzbW5jFHO7kmsTVMh2a ETtzeu/2ZbPzN3NWzYZ/AgTf2OXfkdZWDCfpP0OzbJk9Y2A8lV+auV/sAGDQHq/Gl7mz 8Ivwb7k4J51zu8W3YHeBZ7Hk581RrQBtGDM8K2aDM2febMHzpOkZuNEP8S444HyoacLX QT5Rh2g75ocuqt+7WkL702t9LlGIu1LVbRUHkd+RBbPuqN8AcTHTyAcC+mvFroY4FDyW 9GHg== X-Gm-Message-State: AOJu0YzYDSXZxGpCxnf5zKPXv75IUKFBsFgijvtsO2cTcWFrZSMZDeLC qtiu54P98XVBMa72APVtDjFuBXtda3jz9J/0fZVOu3Un2s7QmFiD/yOV91v6IDmEuOUqGyrJZsX Y/hj9k42HKFYcxbLUOp13EWeh0Y3NCblAEhTzC8SENoO/ovOUS35o/gt5/c0k5rKg+hcdPRAnko 8= X-Received: by 2002:ac2:5f9b:0:b0:507:b988:7c3c with SMTP id r27-20020ac25f9b000000b00507b9887c3cmr1081067lfe.65.1697712426608; Thu, 19 Oct 2023 03:47:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFCN7JquQHbRCb9Pu+7Jdj9f/4XHtpCQkbDZsvmTHPjLnONdj+IidQQ3tlEqzPJh5brZKWi/A== X-Received: by 2002:ac2:5f9b:0:b0:507:b988:7c3c with SMTP id r27-20020ac25f9b000000b00507b9887c3cmr1081052lfe.65.1697712426234; Thu, 19 Oct 2023 03:47:06 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH v2 09/19] target/i386: do not clobber A0 in POP translation Date: Thu, 19 Oct 2023 12:46:38 +0200 Message-ID: <20231019104648.389942-10-pbonzini@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231019104648.389942-1-pbonzini@redhat.com> References: <20231019104648.389942-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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1697712485407100003 Content-Type: text/plain; charset="utf-8" The new decoder likes to compute the address in A0 very early, so the gen_lea_v_seg in gen_pop_T0 would clobber the address of the memory operand. Instead use T0 since it is already available and will be overwritten immediately after. Signed-off-by: Paolo Bonzini --- target/i386/tcg/translate.c | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index 038151a8c3e..39b5752e780 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -628,17 +628,17 @@ static TCGv eip_cur_tl(DisasContext *s) } } =20 -/* Compute SEG:REG into A0. SEG is selected from the override segment +/* Compute SEG:REG into DEST. SEG is selected from the override segment (OVR_SEG) and the default segment (DEF_SEG). OVR_SEG may be -1 to indicate no override. */ -static void gen_lea_v_seg(DisasContext *s, MemOp aflag, TCGv a0, - int def_seg, int ovr_seg) +static void gen_lea_v_seg_dest(DisasContext *s, MemOp aflag, TCGv dest, TC= Gv a0, + int def_seg, int ovr_seg) { switch (aflag) { #ifdef TARGET_X86_64 case MO_64: if (ovr_seg < 0) { - tcg_gen_mov_tl(s->A0, a0); + tcg_gen_mov_tl(dest, a0); return; } break; @@ -649,14 +649,14 @@ static void gen_lea_v_seg(DisasContext *s, MemOp afla= g, TCGv a0, ovr_seg =3D def_seg; } if (ovr_seg < 0) { - tcg_gen_ext32u_tl(s->A0, a0); + tcg_gen_ext32u_tl(dest, a0); return; } break; case MO_16: /* 16 bit address */ - tcg_gen_ext16u_tl(s->A0, a0); - a0 =3D s->A0; + tcg_gen_ext16u_tl(dest, a0); + a0 =3D dest; if (ovr_seg < 0) { if (ADDSEG(s)) { ovr_seg =3D def_seg; @@ -673,17 +673,23 @@ static void gen_lea_v_seg(DisasContext *s, MemOp afla= g, TCGv a0, TCGv seg =3D cpu_seg_base[ovr_seg]; =20 if (aflag =3D=3D MO_64) { - tcg_gen_add_tl(s->A0, a0, seg); + tcg_gen_add_tl(dest, a0, seg); } else if (CODE64(s)) { - tcg_gen_ext32u_tl(s->A0, a0); - tcg_gen_add_tl(s->A0, s->A0, seg); + tcg_gen_ext32u_tl(dest, a0); + tcg_gen_add_tl(dest, dest, seg); } else { - tcg_gen_add_tl(s->A0, a0, seg); - tcg_gen_ext32u_tl(s->A0, s->A0); + tcg_gen_add_tl(dest, a0, seg); + tcg_gen_ext32u_tl(dest, dest); } } } =20 +static void gen_lea_v_seg(DisasContext *s, MemOp aflag, TCGv a0, + int def_seg, int ovr_seg) +{ + gen_lea_v_seg_dest(s, aflag, s->A0, a0, def_seg, ovr_seg); +} + static inline void gen_string_movl_A0_ESI(DisasContext *s) { gen_lea_v_seg(s, s->aflag, cpu_regs[R_ESI], R_DS, s->override); @@ -2590,8 +2596,8 @@ static MemOp gen_pop_T0(DisasContext *s) { MemOp d_ot =3D mo_pushpop(s, s->dflag); =20 - gen_lea_v_seg(s, mo_stacksize(s), cpu_regs[R_ESP], R_SS, -1); - gen_op_ld_v(s, d_ot, s->T0, s->A0); + gen_lea_v_seg_dest(s, mo_stacksize(s), s->T0, cpu_regs[R_ESP], R_SS, -= 1); + gen_op_ld_v(s, d_ot, s->T0, s->T0); =20 return d_ot; } --=20 2.41.0 From nobody Wed Nov 27 15:47:24 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=1697712594; cv=none; d=zohomail.com; s=zohoarc; b=gvbuWPfHrVLLoa5r2jCTyj6ltSAOwDJLGOPJSin9b9yLSIBZeMonuK6WdGb3Oxqlmf11IzAQxo2iL4IV7LJ0mY1SWI+tIWRhuIr2KJeSsKnC3exvLJdbWDv9xR9O02vWbam1lZv6+aRcASDP0aXg3r7oDQcpwY5b5QgHlUIf1iM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697712594; 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=2h5Sv7Cu7V/LW3D5gdOyCZoMT0o3K+w+18w1QrPVYBc=; b=BLdtezaWsdfJqUO8Qf9HVnFy+Wj67VG4XR2tfJBRPxAYb2pajnBnoXy/YuVeBwh2Vc0111FAtc27+KSqr4S6kBmaRdXqFyndHpUjG22xMX+9ahByN2o3bn84Kp6G3cK0kKcIivFwqLouoAQsEN6jyIGTXza8bygi2gMBfhRbZI0= 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 1697712594021420.59635482781687; Thu, 19 Oct 2023 03:49:54 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qtQZH-0007MT-S9; Thu, 19 Oct 2023 06:47:55 -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 1qtQYn-0006aM-OO for qemu-devel@nongnu.org; Thu, 19 Oct 2023 06:47:29 -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 1qtQYk-0006KC-Rr for qemu-devel@nongnu.org; Thu, 19 Oct 2023 06:47:25 -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-15-L-PeBuj9MD6kVU9IQ4_PZg-1; Thu, 19 Oct 2023 06:47:09 -0400 Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-99c8bbc902eso582534566b.1 for ; Thu, 19 Oct 2023 03:47:09 -0700 (PDT) Received: from [192.168.10.118] ([2001:b07:6468:f312:5e2c:eb9a:a8b6:fd3e]) by smtp.gmail.com with ESMTPSA id w19-20020a17090652d300b009ae05f9eab3sm3268970ejn.65.2023.10.19.03.47.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 03:47:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697712441; 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=2h5Sv7Cu7V/LW3D5gdOyCZoMT0o3K+w+18w1QrPVYBc=; b=UHihQUMkCafDiYnmtlf4/QOsNMvkZCVLP81SScoF8UiBQOiAzmBw1k6eexKy2ehEC2bs9q UuTauyEVWcPc/W10NM8hQh3Z6dNh5qeiu11HJ6y/WjFT7oL+dNQV+Ehfw+iZGGVP65RkGB HzvFBPiDWlhOb/68xLPYWEsJmpAQNeo= X-MC-Unique: L-PeBuj9MD6kVU9IQ4_PZg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697712428; x=1698317228; 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=2h5Sv7Cu7V/LW3D5gdOyCZoMT0o3K+w+18w1QrPVYBc=; b=ac83/hJ+JY7vkpqu0ORyxFDrkoBCdnI7gHr1YZLkiB+k0Dq4PYujEURiqL5JZkSWVg kwmvIx2bSlqKwd6LkR5fNDe3Ptn8QI2rhILOYWFaAiFwuYlW7BCsxgzYq3zbQ9uReUvj FB/mlhKa8Hwp4EglhfY5LpZtm0EgqBWF4rIZVkB2qGT4C/XbTLGcFgbX7ADcolfIwvHx tl4b0auCJKARLKD9GdjoMLrOSZ3DzaTzW2D8xBrxIozSO8qFzc66Gvt2Ia4Ztr33iu0b IynFcXl2aag52ZkAgrRk579Psa/uC/mXEl9aRh7/pJGpuYlbTYjNESDNsoAtERsHNfKt HZ8Q== X-Gm-Message-State: AOJu0YxJHwoETPR52eR+MseSqJYUj83rgVc3rISj7PY3UixmWJQXK5ET OuRUad0U3/S7xrXqkLbgPYX3DX+ENn28SSXGZCPZpS9crtCejg4e3XGssMBcNn6vdUy5btWzm3r Xomn6dnlXzmWGctw8ugY7bshoRzchCXntQsGYaB4QarRI3WTGSaJvlw0fRWGPYOcVI6nSP+oHJm I= X-Received: by 2002:a17:907:3687:b0:9bd:abb2:d4e0 with SMTP id bi7-20020a170907368700b009bdabb2d4e0mr1252294ejc.22.1697712428258; Thu, 19 Oct 2023 03:47:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGBVFybQp7/FeV2G23g8d4VfAqd5ePqmgdthsIHMoexueLuZnectdgYZacH2SpeMQbRpyjTpA== X-Received: by 2002:a17:907:3687:b0:9bd:abb2:d4e0 with SMTP id bi7-20020a170907368700b009bdabb2d4e0mr1252285ejc.22.1697712427935; Thu, 19 Oct 2023 03:47:07 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH v2 10/19] target/i386: reintroduce debugging mechanism Date: Thu, 19 Oct 2023 12:46:39 +0200 Message-ID: <20231019104648.389942-11-pbonzini@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231019104648.389942-1-pbonzini@redhat.com> References: <20231019104648.389942-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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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 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: 1697712595957100005 Content-Type: text/plain; charset="utf-8" Signed-off-by: Paolo Bonzini --- target/i386/tcg/decode-new.c.inc | 3 +++ target/i386/tcg/translate.c | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/target/i386/tcg/decode-new.c.inc b/target/i386/tcg/decode-new.= c.inc index 57a5014bc8a..2f614e2a6f0 100644 --- a/target/i386/tcg/decode-new.c.inc +++ b/target/i386/tcg/decode-new.c.inc @@ -1701,6 +1701,9 @@ static void disas_insn_new(DisasContext *s, CPUState = *cpu, int b) X86DecodedInsn decode; X86DecodeFunc decode_func =3D decode_root; =20 +#ifdef CONFIG_USER_ONLY + if (limit) { --limit; } +#endif s->has_modrm =3D false; =20 next_byte: diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index 39b5752e780..080b56840da 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -2980,6 +2980,9 @@ static void gen_sty_env_A0(DisasContext *s, int offse= t, bool align) tcg_gen_qemu_st_i64(s->tmp1_i64, s->tmp0, mem_index, MO_LEUQ); } =20 +static bool first =3D true; +static unsigned long limit; + #include "decode-new.h" #include "emit.c.inc" #include "decode-new.c.inc" @@ -3134,15 +3137,39 @@ static bool disas_insn(DisasContext *s, CPUState *c= pu) =20 prefixes =3D 0; =20 + if (first) { + const char *env =3D getenv("QEMU_I386_LIMIT"); + limit =3D env ? atol(env) : -1; + first =3D false; + } + bool use_new =3D true; +#ifdef CONFIG_USER_ONLY + use_new &=3D limit > 0; +#endif + next_byte: s->prefix =3D prefixes; b =3D x86_ldub_code(env, s); /* Collect prefixes. */ switch (b) { default: +#ifndef CONFIG_USER_ONLY + use_new &=3D b <=3D limit; +#endif + if (use_new && 0) { + disas_insn_new(s, cpu, b); + return true; + } break; case 0x0f: b =3D x86_ldub_code(env, s) + 0x100; +#ifndef CONFIG_USER_ONLY + use_new &=3D b <=3D limit; +#endif + if (use_new && 0) { + disas_insn_new(s, cpu, b); + return true; + } break; case 0xf3: prefixes |=3D PREFIX_REPZ; --=20 2.41.0 From nobody Wed Nov 27 15:47:24 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=1697712548; cv=none; d=zohomail.com; s=zohoarc; b=EGcx9cFDrLwkPYrgg8RKAubcw9EYWNao2/5wcB14B6b0IEtr/GbAk0f9Ks47gNldGnlyRaq5epICuUvI56w6IkN0ilf9ZsGedZKZvhyPYABKOU6jqdsMOVFNSuoS1CskKy5YOkHQPQvT3OOhLPU8dv3aI3SM+CQeKshcplv4Ycg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697712548; 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=Fs52DQNF+J/9BPIlJPJYQ1L0iEAJSlKjoPIFBlxq3fc=; b=EB+7Z42raDE5RNNHNyAS6oMb433Xz+cb66p38hDxvdG0QNIWX0e6mZzJS/k+QOVr2MO81wj8CFdgNzcXgT160naSZ5ujZTtyQm+wl7AdketumtiYo8QP/sW7aB7YBpPFnQKjMiL/d+zqhNE2BweUK2Vy/f3Qz///GpVjPl9qj1k= 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 1697712548029519.085977006817; Thu, 19 Oct 2023 03:49:08 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qtQYz-0006aH-SZ; Thu, 19 Oct 2023 06:47:42 -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 1qtQYe-0006ZK-9F for qemu-devel@nongnu.org; Thu, 19 Oct 2023 06:47:17 -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 1qtQYb-0006Eb-Ut for qemu-devel@nongnu.org; Thu, 19 Oct 2023 06:47:16 -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-689-pd-I7VzeOnCgctvoo2GU8w-1; Thu, 19 Oct 2023 06:47:12 -0400 Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-9b98d8f6bafso581872666b.1 for ; Thu, 19 Oct 2023 03:47:11 -0700 (PDT) Received: from [192.168.10.118] ([2001:b07:6468:f312:5e2c:eb9a:a8b6:fd3e]) by smtp.gmail.com with ESMTPSA id bu23-20020a170906a15700b009b2c5363ebasm3339894ejb.26.2023.10.19.03.47.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 03:47:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697712433; 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=Fs52DQNF+J/9BPIlJPJYQ1L0iEAJSlKjoPIFBlxq3fc=; b=Fd5cElitrZPBelL4I0kYvjfB5uNM7ZB8b9l78oqbIBw8ZnpWmoRHCxI/w/5KMCfCYr49rI QwSweCv3LCe+bO/sOaGoN9rWHddYZPTPAXo1MpYWm4psX05N/bkeIj/LmSYaEuUznJ3ICz P8uDZJgWQOzbi9EgHlxp2uJJ8zCW8iY= X-MC-Unique: pd-I7VzeOnCgctvoo2GU8w-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697712430; x=1698317230; 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=Fs52DQNF+J/9BPIlJPJYQ1L0iEAJSlKjoPIFBlxq3fc=; b=gm+YkoFC1wQrEhcQoYRYhlHCRmpdKrgsbRJFCHmp9XDLu2dmDigSXy49fYUv70sjDI og/PqvCHUKsz7QyF9XaIqrkMEHs6xpdJkVe+p6LUU90x7tStafDtpvI9PYUIOVgI5muN 0XX3S7koao/385Y4UxSb242WfOj/ufq5JCc8vW7N864N3gX5LAO2C6j9WToGt/O5gg/K yXGJfABWaAKX9RS+2wGkwsRGAs6znfEYjUP5yQIw3ckC10+8OrQGxsgiCWxWUapKCzj5 2WI+qBUcrKqSI1uCYbTYvpwkXj3/89RHSQw9sbaPPo/iHFVYWfm6LrtXKsevvf1ZFFCp +MIA== X-Gm-Message-State: AOJu0Yxzz7VzP1zYCOzAVSnEeSeiPN+awxykLAWJsW3iSHF6VcApbEqb tNR0dXcbf2H6NZfTKmMFSfElJaNN9wpXbCWj/h5wOc2fTr5BiChumdzwdifpdgJ7DSiv73wQzRe Wh/lpLHO6sKQI6SccrY/odcWi5049unW1R+Dd57hAs/eKB2k6t0L69cwb8T0UsxLJMe7hIiiA25 o= X-Received: by 2002:a17:907:9705:b0:9c4:b8c9:1bf4 with SMTP id jg5-20020a170907970500b009c4b8c91bf4mr1217132ejc.19.1697712430262; Thu, 19 Oct 2023 03:47:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEXMctjGLvY8RcFqetHIfJEqs9hfJYFI7VeDANlLj8akGiia9NBJ+q4bbUsTJAPHrCZAIT8Jw== X-Received: by 2002:a17:907:9705:b0:9c4:b8c9:1bf4 with SMTP id jg5-20020a170907970500b009c4b8c91bf4mr1217108ejc.19.1697712429554; Thu, 19 Oct 2023 03:47:09 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH v2 11/19] target/i386: move 00-5F opcodes to new decoder Date: Thu, 19 Oct 2023 12:46:40 +0200 Message-ID: <20231019104648.389942-12-pbonzini@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231019104648.389942-1-pbonzini@redhat.com> References: <20231019104648.389942-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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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 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: 1697712549629100003 Content-Type: text/plain; charset="utf-8" Signed-off-by: Paolo Bonzini --- target/i386/tcg/decode-new.c.inc | 116 ++++++++++++++++++ target/i386/tcg/decode-new.h | 3 + target/i386/tcg/emit.c.inc | 203 +++++++++++++++++++++++++++++++ target/i386/tcg/translate.c | 2 +- 4 files changed, 323 insertions(+), 1 deletion(-) diff --git a/target/i386/tcg/decode-new.c.inc b/target/i386/tcg/decode-new.= c.inc index 2f614e2a6f0..dc596ba9f7a 100644 --- a/target/i386/tcg/decode-new.c.inc +++ b/target/i386/tcg/decode-new.c.inc @@ -102,6 +102,8 @@ =20 #define X86_OP_GROUP2(op, op0, s0, op1, s1, ...) \ X86_OP_GROUP3(op, op0, s0, 2op, s0, op1, s1, ## __VA_ARGS__) +#define X86_OP_GROUPw(op, op0, s0, ...) \ + X86_OP_GROUP3(op, op0, s0, None, None, None, None, ## __VA_ARGS__) #define X86_OP_GROUP0(op, ...) \ X86_OP_GROUP3(op, None, None, None, None, None, None, ## __VA_ARGS__) =20 @@ -127,10 +129,13 @@ X86_OP_ENTRY3(op, op0, s0, None, None, None, None, ## __VA_ARGS__) #define X86_OP_ENTRYr(op, op0, s0, ...) \ X86_OP_ENTRY3(op, None, None, None, None, op0, s0, ## __VA_ARGS__) +#define X86_OP_ENTRY1(op, op0, s0, ...) \ + X86_OP_ENTRY3(op, op0, s0, 2op, s0, None, None, ## __VA_ARGS__) #define X86_OP_ENTRY0(op, ...) \ X86_OP_ENTRY3(op, None, None, None, None, None, None, ## __VA_ARGS__) =20 #define cpuid(feat) .cpuid =3D X86_FEAT_##feat, +#define nowb .special =3D X86_SPECIAL_NoWriteback, #define xchg .special =3D X86_SPECIAL_Locked, #define mmx .special =3D X86_SPECIAL_MMX, #define zext0 .special =3D X86_SPECIAL_ZExtOp0, @@ -1074,7 +1079,114 @@ static void decode_0F(DisasContext *s, CPUX86State = *env, X86OpEntry *entry, uint } =20 static const X86OpEntry opcodes_root[256] =3D { + [0x00] =3D X86_OP_ENTRY2(ADD, E,b, G,b), + [0x01] =3D X86_OP_ENTRY2(ADD, E,v, G,v), + [0x02] =3D X86_OP_ENTRY2(ADD, G,b, E,b), + [0x03] =3D X86_OP_ENTRY2(ADD, G,v, E,v), + [0x04] =3D X86_OP_ENTRY2(ADD, 0,b, I,b), /* AL, Ib */ + [0x05] =3D X86_OP_ENTRY2(ADD, 0,v, I,z), /* rAX, Iz */ + [0x06] =3D X86_OP_ENTRYr(PUSH, ES, w, chk(i64)), + [0x07] =3D X86_OP_ENTRYw(POP, ES, w, chk(i64)), + + [0x10] =3D X86_OP_ENTRY2(ADC, E,b, G,b), + [0x11] =3D X86_OP_ENTRY2(ADC, E,v, G,v), + [0x12] =3D X86_OP_ENTRY2(ADC, G,b, E,b), + [0x13] =3D X86_OP_ENTRY2(ADC, G,v, E,v), + [0x14] =3D X86_OP_ENTRY2(ADC, 0,b, I,b), /* AL, Ib */ + [0x15] =3D X86_OP_ENTRY2(ADC, 0,v, I,z), /* rAX, Iz */ + [0x16] =3D X86_OP_ENTRYr(PUSH, SS, w, chk(i64)), + [0x17] =3D X86_OP_ENTRYw(POP, SS, w, chk(i64)), + + [0x20] =3D X86_OP_ENTRY2(AND, E,b, G,b), + [0x21] =3D X86_OP_ENTRY2(AND, E,v, G,v), + [0x22] =3D X86_OP_ENTRY2(AND, G,b, E,b), + [0x23] =3D X86_OP_ENTRY2(AND, G,v, E,v), + [0x24] =3D X86_OP_ENTRY2(AND, 0,b, I,b), /* AL, Ib */ + [0x25] =3D X86_OP_ENTRY2(AND, 0,v, I,z), /* rAX, Iz */ + [0x26] =3D {}, + [0x27] =3D X86_OP_ENTRY0(DAA, chk(i64)), + + [0x30] =3D X86_OP_ENTRY2(XOR, E,b, G,b), + [0x31] =3D X86_OP_ENTRY2(XOR, E,v, G,v), + [0x32] =3D X86_OP_ENTRY2(XOR, G,b, E,b), + [0x33] =3D X86_OP_ENTRY2(XOR, G,v, E,v), + [0x34] =3D X86_OP_ENTRY2(XOR, 0,b, I,b), /* AL, Ib */ + [0x35] =3D X86_OP_ENTRY2(XOR, 0,v, I,z), /* rAX, Iz */ + [0x36] =3D {}, + [0x37] =3D X86_OP_ENTRY0(AAA, chk(i64)), + + [0x40] =3D X86_OP_ENTRY1(INC, 0,v, chk(i64)), + [0x41] =3D X86_OP_ENTRY1(INC, 1,v, chk(i64)), + [0x42] =3D X86_OP_ENTRY1(INC, 2,v, chk(i64)), + [0x43] =3D X86_OP_ENTRY1(INC, 3,v, chk(i64)), + [0x44] =3D X86_OP_ENTRY1(INC, 4,v, chk(i64)), + [0x45] =3D X86_OP_ENTRY1(INC, 5,v, chk(i64)), + [0x46] =3D X86_OP_ENTRY1(INC, 6,v, chk(i64)), + [0x47] =3D X86_OP_ENTRY1(INC, 7,v, chk(i64)), + + [0x50] =3D X86_OP_ENTRYr(PUSH, LoBits,d64), + [0x51] =3D X86_OP_ENTRYr(PUSH, LoBits,d64), + [0x52] =3D X86_OP_ENTRYr(PUSH, LoBits,d64), + [0x53] =3D X86_OP_ENTRYr(PUSH, LoBits,d64), + [0x54] =3D X86_OP_ENTRYr(PUSH, LoBits,d64), + [0x55] =3D X86_OP_ENTRYr(PUSH, LoBits,d64), + [0x56] =3D X86_OP_ENTRYr(PUSH, LoBits,d64), + [0x57] =3D X86_OP_ENTRYr(PUSH, LoBits,d64), + + + [0x08] =3D X86_OP_ENTRY2(OR, E,b, G,b), + [0x09] =3D X86_OP_ENTRY2(OR, E,v, G,v), + [0x0A] =3D X86_OP_ENTRY2(OR, G,b, E,b), + [0x0B] =3D X86_OP_ENTRY2(OR, G,v, E,v), + [0x0C] =3D X86_OP_ENTRY2(OR, 0,b, I,b), /* AL, Ib */ + [0x0D] =3D X86_OP_ENTRY2(OR, 0,v, I,z), /* rAX, Iz */ + [0x0E] =3D X86_OP_ENTRYr(PUSH, CS, w, chk(i64)), [0x0F] =3D X86_OP_GROUP0(0F), + + [0x18] =3D X86_OP_ENTRY2(SBB, E,b, G,b), + [0x19] =3D X86_OP_ENTRY2(SBB, E,v, G,v), + [0x1A] =3D X86_OP_ENTRY2(SBB, G,b, E,b), + [0x1B] =3D X86_OP_ENTRY2(SBB, G,v, E,v), + [0x1C] =3D X86_OP_ENTRY2(SBB, 0,b, I,b), /* AL, Ib */ + [0x1D] =3D X86_OP_ENTRY2(SBB, 0,v, I,z), /* rAX, Iz */ + [0x1E] =3D X86_OP_ENTRYr(PUSH, DS, w, chk(i64)), + [0x1F] =3D X86_OP_ENTRYw(POP, DS, w, chk(i64)), + + [0x28] =3D X86_OP_ENTRY2(SUB, E,b, G,b), + [0x29] =3D X86_OP_ENTRY2(SUB, E,v, G,v), + [0x2A] =3D X86_OP_ENTRY2(SUB, G,b, E,b), + [0x2B] =3D X86_OP_ENTRY2(SUB, G,v, E,v), + [0x2C] =3D X86_OP_ENTRY2(SUB, 0,b, I,b), /* AL, Ib */ + [0x2D] =3D X86_OP_ENTRY2(SUB, 0,v, I,z), /* rAX, Iz */ + [0x2E] =3D {}, + [0x2F] =3D X86_OP_ENTRY0(DAS, chk(i64)), + + [0x38] =3D X86_OP_ENTRY2(SUB, E,b, G,b, nowb), + [0x39] =3D X86_OP_ENTRY2(SUB, E,v, G,v, nowb), + [0x3A] =3D X86_OP_ENTRY2(SUB, G,b, E,b, nowb), + [0x3B] =3D X86_OP_ENTRY2(SUB, G,v, E,v, nowb), + [0x3C] =3D X86_OP_ENTRY2(SUB, 0,b, I,b, nowb), /* AL, Ib */ + [0x3D] =3D X86_OP_ENTRY2(SUB, 0,v, I,z, nowb), /* rAX, Iz */ + [0x3E] =3D {}, + [0x3F] =3D X86_OP_ENTRY0(AAS, chk(i64)), + + [0x48] =3D X86_OP_ENTRY1(DEC, 0,v, chk(i64)), + [0x49] =3D X86_OP_ENTRY1(DEC, 1,v, chk(i64)), + [0x4A] =3D X86_OP_ENTRY1(DEC, 2,v, chk(i64)), + [0x4B] =3D X86_OP_ENTRY1(DEC, 3,v, chk(i64)), + [0x4C] =3D X86_OP_ENTRY1(DEC, 4,v, chk(i64)), + [0x4D] =3D X86_OP_ENTRY1(DEC, 5,v, chk(i64)), + [0x4E] =3D X86_OP_ENTRY1(DEC, 6,v, chk(i64)), + [0x4F] =3D X86_OP_ENTRY1(DEC, 7,v, chk(i64)), + + [0x58] =3D X86_OP_ENTRYw(POP, LoBits,d64), + [0x59] =3D X86_OP_ENTRYw(POP, LoBits,d64), + [0x5A] =3D X86_OP_ENTRYw(POP, LoBits,d64), + [0x5B] =3D X86_OP_ENTRYw(POP, LoBits,d64), + [0x5C] =3D X86_OP_ENTRYw(POP, LoBits,d64), + [0x5D] =3D X86_OP_ENTRYw(POP, LoBits,d64), + [0x5E] =3D X86_OP_ENTRYw(POP, LoBits,d64), + [0x5F] =3D X86_OP_ENTRYw(POP, LoBits,d64), }; =20 #undef mmx @@ -1898,6 +2010,10 @@ static void disas_insn_new(DisasContext *s, CPUState= *cpu, int b) } break; =20 + case X86_SPECIAL_NoWriteback: + decode.op[0].unit =3D X86_OP_SKIP; + break; + case X86_SPECIAL_ZExtOp0: assert(decode.op[0].unit =3D=3D X86_OP_INT); if (!decode.op[0].has_ea) { diff --git a/target/i386/tcg/decode-new.h b/target/i386/tcg/decode-new.h index 15233fad62f..a3983794ac5 100644 --- a/target/i386/tcg/decode-new.h +++ b/target/i386/tcg/decode-new.h @@ -161,6 +161,9 @@ typedef enum X86InsnSpecial { /* Always locked if it has a memory operand (XCHG) */ X86_SPECIAL_Locked, =20 + /* Writeback not needed or done manually in the callback */ + X86_SPECIAL_NoWriteback, + /* * Register operand 0/2 is zero extended to 32 bits. Rd/Mb or Rd/Mw * in the manual. diff --git a/target/i386/tcg/emit.c.inc b/target/i386/tcg/emit.c.inc index dd77a8c5511..6b9f518cc94 100644 --- a/target/i386/tcg/emit.c.inc +++ b/target/i386/tcg/emit.c.inc @@ -329,6 +329,27 @@ static void prepare_update1_cc(X86DecodedInsn *decode,= DisasContext *s, CCOp op) decode->cc_op =3D op; } =20 +static void prepare_update2_cc(X86DecodedInsn *decode, DisasContext *s, CC= Op op) +{ + decode->cc_src =3D s->T1; + decode->cc_dst =3D s->T0; + decode->cc_op =3D op; +} + +static void prepare_update_cc_incdec(X86DecodedInsn *decode, DisasContext = *s, CCOp op) +{ + gen_compute_eflags_c(s, s->T1); + prepare_update2_cc(decode, s, op); +} + +static void prepare_update3_cc(X86DecodedInsn *decode, DisasContext *s, CC= Op op, TCGv reg) +{ + decode->cc_src2 =3D reg; + decode->cc_src =3D s->T1; + decode->cc_dst =3D s->T0; + decode->cc_op =3D op; +} + static void gen_store_sse(DisasContext *s, X86DecodedInsn *decode, int src= _ofs) { MemOp ot =3D decode->op[0].ot; @@ -1017,6 +1038,36 @@ static void gen_##uname(DisasContext *s, CPUX86State= *env, X86DecodedInsn *decod VSIB_AVX(VPGATHERD, vpgatherd) VSIB_AVX(VPGATHERQ, vpgatherq) =20 +static void gen_AAA(DisasContext *s, CPUX86State *env, X86DecodedInsn *dec= ode) +{ + gen_update_cc_op(s); + gen_helper_aaa(tcg_env); + set_cc_op(s, CC_OP_EFLAGS); +} + +static void gen_AAS(DisasContext *s, CPUX86State *env, X86DecodedInsn *dec= ode) +{ + gen_update_cc_op(s); + gen_helper_aas(tcg_env); + set_cc_op(s, CC_OP_EFLAGS); +} + +static void gen_ADC(DisasContext *s, CPUX86State *env, X86DecodedInsn *dec= ode) +{ + MemOp ot =3D decode->op[0].ot; + + gen_compute_eflags_c(s, s->tmp4); + if (s->prefix & PREFIX_LOCK) { + tcg_gen_add_tl(s->T0, s->tmp4, s->T1); + tcg_gen_atomic_add_fetch_tl(s->T0, s->A0, s->T0, + s->mem_index, ot | MO_LE); + } else { + tcg_gen_add_tl(s->T0, s->T0, s->T1); + tcg_gen_add_tl(s->T0, s->T0, s->tmp4); + } + prepare_update3_cc(decode, s, CC_OP_ADCB + ot, s->tmp4); +} + /* ADCX/ADOX do not have memory operands and can use set_cc_op. */ static void gen_ADCOX(DisasContext *s, CPUX86State *env, MemOp ot, int cc_= op) { @@ -1070,11 +1121,37 @@ static void gen_ADCX(DisasContext *s, CPUX86State *= env, X86DecodedInsn *decode) gen_ADCOX(s, env, decode->op[0].ot, CC_OP_ADCX); } =20 +static void gen_ADD(DisasContext *s, CPUX86State *env, X86DecodedInsn *dec= ode) +{ + MemOp ot =3D decode->op[0].ot; + + if (s->prefix & PREFIX_LOCK) { + tcg_gen_atomic_add_fetch_tl(s->T0, s->A0, s->T1, + s->mem_index, ot | MO_LE); + } else { + tcg_gen_add_tl(s->T0, s->T0, s->T1); + } + prepare_update2_cc(decode, s, CC_OP_ADDB + ot); +} + static void gen_ADOX(DisasContext *s, CPUX86State *env, X86DecodedInsn *de= code) { gen_ADCOX(s, env, decode->op[0].ot, CC_OP_ADOX); } =20 +static void gen_AND(DisasContext *s, CPUX86State *env, X86DecodedInsn *dec= ode) +{ + MemOp ot =3D decode->op[0].ot; + + if (s->prefix & PREFIX_LOCK) { + tcg_gen_atomic_and_fetch_tl(s->T0, s->A0, s->T1, + s->mem_index, ot | MO_LE); + } else { + tcg_gen_and_tl(s->T0, s->T0, s->T1); + } + prepare_update1_cc(decode, s, CC_OP_LOGICB + ot); +} + static void gen_ANDN(DisasContext *s, CPUX86State *env, X86DecodedInsn *de= code) { MemOp ot =3D decode->op[0].ot; @@ -1308,6 +1385,34 @@ static void gen_CVTTPx2PI(DisasContext *s, CPUX86Sta= te *env, X86DecodedInsn *dec } } =20 +static void gen_DAA(DisasContext *s, CPUX86State *env, X86DecodedInsn *dec= ode) +{ + gen_update_cc_op(s); + gen_helper_daa(tcg_env); + set_cc_op(s, CC_OP_EFLAGS); +} + +static void gen_DAS(DisasContext *s, CPUX86State *env, X86DecodedInsn *dec= ode) +{ + gen_update_cc_op(s); + gen_helper_das(tcg_env); + set_cc_op(s, CC_OP_EFLAGS); +} + +static void gen_DEC(DisasContext *s, CPUX86State *env, X86DecodedInsn *dec= ode) +{ + MemOp ot =3D decode->op[0].ot; + + tcg_gen_movi_tl(s->T1, -1); + if (s->prefix & PREFIX_LOCK) { + tcg_gen_atomic_add_fetch_tl(s->T0, s->A0, s->T1, + s->mem_index, ot | MO_LE); + } else { + tcg_gen_add_tl(s->T0, s->T0, s->T1); + } + prepare_update_cc_incdec(decode, s, CC_OP_DECB + ot); +} + static void gen_EMMS(DisasContext *s, CPUX86State *env, X86DecodedInsn *de= code) { gen_helper_emms(tcg_env); @@ -1326,6 +1431,20 @@ static void gen_EXTRQ_r(DisasContext *s, CPUX86State= *env, X86DecodedInsn *decod gen_helper_extrq_r(tcg_env, OP_PTR0, OP_PTR2); } =20 +static void gen_INC(DisasContext *s, CPUX86State *env, X86DecodedInsn *dec= ode) +{ + MemOp ot =3D decode->op[0].ot; + + tcg_gen_movi_tl(s->T1, 1); + if (s->prefix & PREFIX_LOCK) { + tcg_gen_atomic_add_fetch_tl(s->T0, s->A0, s->T1, + s->mem_index, ot | MO_LE); + } else { + tcg_gen_add_tl(s->T0, s->T0, s->T1); + } + prepare_update_cc_incdec(decode, s, CC_OP_INCB + ot); +} + static void gen_INSERTQ_i(DisasContext *s, CPUX86State *env, X86DecodedIns= n *decode) { TCGv_i32 length =3D tcg_constant_i32(decode->immediate & 63); @@ -1477,6 +1596,19 @@ static void gen_MULX(DisasContext *s, CPUX86State *e= nv, X86DecodedInsn *decode) =20 } =20 +static void gen_OR(DisasContext *s, CPUX86State *env, X86DecodedInsn *deco= de) +{ + MemOp ot =3D decode->op[0].ot; + + if (s->prefix & PREFIX_LOCK) { + tcg_gen_atomic_or_fetch_tl(s->T0, s->A0, s->T1, + s->mem_index, ot | MO_LE); + } else { + tcg_gen_or_tl(s->T0, s->T0, s->T1); + } + prepare_update1_cc(decode, s, CC_OP_LOGICB + ot); +} + static void gen_PALIGNR(DisasContext *s, CPUX86State *env, X86DecodedInsn = *decode) { TCGv_i32 imm =3D tcg_constant8u_i32(decode->immediate); @@ -1728,6 +1860,18 @@ static void gen_PMOVMSKB(DisasContext *s, CPUX86Stat= e *env, X86DecodedInsn *deco } } =20 +static void gen_POP(DisasContext *s, CPUX86State *env, X86DecodedInsn *dec= ode) +{ + MemOp ot =3D gen_pop_T0(s); + if (decode->op[0].has_ea) { + /* NOTE: order is important for MMU exceptions */ + gen_op_st_v(s, ot, s->T0, s->A0); + decode->op[0].unit =3D X86_OP_SKIP; + } + /* NOTE: writing back registers after update is important for pop %sp = */ + gen_pop_update(s, ot); +} + static void gen_PSHUFW(DisasContext *s, CPUX86State *env, X86DecodedInsn *= decode) { TCGv_i32 imm =3D tcg_constant8u_i32(decode->immediate); @@ -1874,6 +2018,11 @@ static void gen_PSLLDQ_i(DisasContext *s, CPUX86Stat= e *env, X86DecodedInsn *deco } } =20 +static void gen_PUSH(DisasContext *s, CPUX86State *env, X86DecodedInsn *de= code) +{ + gen_push_v(s, s->T1); +} + static void gen_RORX(DisasContext *s, CPUX86State *env, X86DecodedInsn *de= code) { MemOp ot =3D decode->op[0].ot; @@ -1901,6 +2050,23 @@ static void gen_SARX(DisasContext *s, CPUX86State *e= nv, X86DecodedInsn *decode) tcg_gen_sar_tl(s->T0, s->T0, s->T1); } =20 +static void gen_SBB(DisasContext *s, CPUX86State *env, X86DecodedInsn *dec= ode) +{ + MemOp ot =3D decode->op[0].ot; + + gen_compute_eflags_c(s, s->tmp4); + if (s->prefix & PREFIX_LOCK) { + tcg_gen_add_tl(s->T0, s->T1, s->tmp4); + tcg_gen_neg_tl(s->T0, s->T0); + tcg_gen_atomic_add_fetch_tl(s->T0, s->A0, s->T0, + s->mem_index, ot | MO_LE); + } else { + tcg_gen_sub_tl(s->T0, s->T0, s->T1); + tcg_gen_sub_tl(s->T0, s->T0, s->tmp4); + } + prepare_update3_cc(decode, s, CC_OP_SBBB + ot, s->tmp4); +} + static void gen_SHA1NEXTE(DisasContext *s, CPUX86State *env, X86DecodedIns= n *decode) { gen_helper_sha1nexte(OP_PTR0, OP_PTR1, OP_PTR2); @@ -1991,6 +2157,22 @@ static void gen_STMXCSR(DisasContext *s, CPUX86State= *env, X86DecodedInsn *decod tcg_gen_ld32u_tl(s->T0, tcg_env, offsetof(CPUX86State, mxcsr)); } =20 +static void gen_SUB(DisasContext *s, CPUX86State *env, X86DecodedInsn *dec= ode) +{ + MemOp ot =3D decode->op[0].ot; + + if (s->prefix & PREFIX_LOCK) { + tcg_gen_neg_tl(s->T0, s->T1); + tcg_gen_atomic_fetch_add_tl(s->cc_srcT, s->A0, s->T0, + s->mem_index, ot | MO_LE); + tcg_gen_sub_tl(s->T0, s->cc_srcT, s->T1); + } else { + tcg_gen_mov_tl(s->cc_srcT, s->T0); + tcg_gen_sub_tl(s->T0, s->T0, s->T1); + } + prepare_update2_cc(decode, s, CC_OP_SUBB + ot); +} + static void gen_VAESIMC(DisasContext *s, CPUX86State *env, X86DecodedInsn = *decode) { assert(!s->vex_l); @@ -2470,3 +2652,24 @@ static void gen_VZEROUPPER(DisasContext *s, CPUX86St= ate *env, X86DecodedInsn *de tcg_gen_gvec_dup_imm(MO_64, offset, 16, 16, 0); } } + +static void gen_XOR(DisasContext *s, CPUX86State *env, X86DecodedInsn *dec= ode) +{ + /* special case XOR reg, reg */ + if (decode->op[1].unit =3D=3D X86_OP_INT && + decode->op[2].unit =3D=3D X86_OP_INT && + decode->op[1].n =3D=3D decode->op[2].n) { + tcg_gen_movi_tl(s->T0, 0); + set_cc_op(s, CC_OP_CLR); + } else { + MemOp ot =3D decode->op[0].ot; + + if (s->prefix & PREFIX_LOCK) { + tcg_gen_atomic_xor_fetch_tl(s->T0, s->A0, s->T1, + s->mem_index, ot | MO_LE); + } else { + tcg_gen_xor_tl(s->T0, s->T0, s->T1); + } + prepare_update1_cc(decode, s, CC_OP_LOGICB + ot); + } +} diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index 080b56840da..e13bf7df591 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -3156,7 +3156,7 @@ static bool disas_insn(DisasContext *s, CPUState *cpu) #ifndef CONFIG_USER_ONLY use_new &=3D b <=3D limit; #endif - if (use_new && 0) { + if (use_new && b <=3D 0x5f) { disas_insn_new(s, cpu, b); return true; } --=20 2.41.0 From nobody Wed Nov 27 15:47:24 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=1697712537; cv=none; d=zohomail.com; s=zohoarc; b=Lek/pNibiGUYqAI+0N6yBmA+aHo77KicHkc8nQANy+8JIVVXmxhHho2UH+Zdjexr4+Xj02lUV1dtTbzsxPFneFD6Tj13OS+cqa8zhvonWr9SfyP7Q6X6bUImsZ6OXRdjAXUa27141OkS7VmjbZLwjYOHtbd6Ywrzhwk4fuvy8NU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697712537; 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=Fy633mC5t4qXfpOf5yp7kSxDtLSJN2IR1Rkjsh86ZrY=; b=jHUVuyAy4B7QSJo1SLGIgZuC0hMPBnfHEv9AqK8fif6usZqo8fCXE2ElQsqzaAULOHhZPjKOzVH42teXfU9rqdLUfHLjjj2fq3nLu5eXoVV/F35Al1hqH/L4Empsb8/WP3WbmfkdnTgAgI76/H/Lz46wdKRcijFKlkHbgU96tos= 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 1697712537657510.30200974375146; Thu, 19 Oct 2023 03:48:57 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qtQZF-00079a-5V; Thu, 19 Oct 2023 06:47:53 -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 1qtQYv-0006bv-GH for qemu-devel@nongnu.org; Thu, 19 Oct 2023 06:47:39 -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 1qtQYu-0006c5-1i for qemu-devel@nongnu.org; Thu, 19 Oct 2023 06:47:33 -0400 Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-386-cycq79nINimX2u7QLm0ETQ-1; Thu, 19 Oct 2023 06:47:12 -0400 Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-9c7558b7b85so84309766b.3 for ; Thu, 19 Oct 2023 03:47:12 -0700 (PDT) Received: from [192.168.10.118] ([2001:b07:6468:f312:5e2c:eb9a:a8b6:fd3e]) by smtp.gmail.com with ESMTPSA id s4-20020a170906c30400b009b65a698c16sm3245790ejz.220.2023.10.19.03.47.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 03:47:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697712449; 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=Fy633mC5t4qXfpOf5yp7kSxDtLSJN2IR1Rkjsh86ZrY=; b=NXO5bIGIe67BmCT8YCkvlREwUB0vY47B56ZtWfkv9aRjOt5/0yqUG9K79cQt9Tw783KV9i RkhR+FmEmeWm9671CeeXmvnMmv1JxxzoxUnDOzi4J55bcIKEhMXehi/S40MdVmVqJhXXvp Pa+GXHbBPfOp4hunLv9raC1TYKjTVQ8= X-MC-Unique: cycq79nINimX2u7QLm0ETQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697712431; x=1698317231; 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=Fy633mC5t4qXfpOf5yp7kSxDtLSJN2IR1Rkjsh86ZrY=; b=o1PxplsVDnRtws9oVB6nIVmrw8eJm1jkLfl61O4AiWMg5UTJtEXVNvPv+IUp+wEznD hGZAQ0245Sj2rRkQsDKxInFSnAJZoPYrB4Y2hH6utvmI8htgFtZ4D4QyjvfcNAdrky8V Bvwz+9PYeWe6nKtVsqb3Fbh5TmgEJyHy0FmzIUwkH6zviF4ZZ7k9seZanVJ7/zG3kqqH jxvSuH3homUvDwX4dY6aEUONOMqhS7x1lsyQAC9RxLMUzkon8JRm38lEybUog0Q/tl/J LIKcAQ4JzaAv8M6Kh6/C1IIb1irluo/iXu9q5UIO/3U5mWkbF+YHbpUiWOTqi7+UGi/I Inmw== X-Gm-Message-State: AOJu0YyyOy8lugj3hUEeqfxB53UoqZnx2wOORFGtoEQIVfeq65QA49Ne QNPwV+9yZQNolTb1YQLTe1DrDPff+VCLbcdKXQUb7RpA6trWxg6RlEZpQW9zYqWqEZrhg4bDHzj B8sjhV3mPWex+/WUWz61+0smXgrkErOmuauJvZci1bJsrEdNExdpAo5yONfoR/NwB394pim+rN0 g= X-Received: by 2002:a17:907:8687:b0:9c5:2806:72e9 with SMTP id qa7-20020a170907868700b009c5280672e9mr1301409ejc.34.1697712431186; Thu, 19 Oct 2023 03:47:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFpEQrhV/lHhwRF69vtx+BLWaN+KOLDcBmnEjGIWts4P+3KMlPKTaSIXlUoHUIudXB2kyrbnQ== X-Received: by 2002:a17:907:8687:b0:9c5:2806:72e9 with SMTP id qa7-20020a170907868700b009c5280672e9mr1301398ejc.34.1697712430909; Thu, 19 Oct 2023 03:47:10 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH v2 12/19] target/i386: adjust decoding of J operand Date: Thu, 19 Oct 2023 12:46:41 +0200 Message-ID: <20231019104648.389942-13-pbonzini@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231019104648.389942-1-pbonzini@redhat.com> References: <20231019104648.389942-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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1697712539604100003 Content-Type: text/plain; charset="utf-8" gen_jcc() has been changed to accept a relative offset since the new decoder was written. Adjust the J operand, which is meant to be used with jump instructions and gen_jcc(), to not include the program counter and to not truncate the result, as both operations are now performed by common code. The result is that J is now the same as the I operand. Signed-off-by: Paolo Bonzini --- target/i386/tcg/decode-new.c.inc | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/target/i386/tcg/decode-new.c.inc b/target/i386/tcg/decode-new.= c.inc index dc596ba9f7a..1ae731459b7 100644 --- a/target/i386/tcg/decode-new.c.inc +++ b/target/i386/tcg/decode-new.c.inc @@ -1448,19 +1448,9 @@ static bool decode_op(DisasContext *s, CPUX86State *= env, X86DecodedInsn *decode, } =20 case X86_TYPE_I: /* Immediate */ - op->unit =3D X86_OP_IMM; - decode->immediate =3D insn_get_signed(env, s, op->ot); - break; - case X86_TYPE_J: /* Relative offset for a jump */ op->unit =3D X86_OP_IMM; decode->immediate =3D insn_get_signed(env, s, op->ot); - decode->immediate +=3D s->pc - s->cs_base; - if (s->dflag =3D=3D MO_16) { - decode->immediate &=3D 0xffff; - } else if (!CODE64(s)) { - decode->immediate &=3D 0xffffffffu; - } break; =20 case X86_TYPE_L: /* The upper 4 bits of the immediate select a 128-bi= t register */ --=20 2.41.0 From nobody Wed Nov 27 15:47:24 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=1697712552; cv=none; d=zohomail.com; s=zohoarc; b=LH+0AFDgqLjqL3AmjYX5UYU8i74yuwAXyH0ZvRV78C0BhrN4m875pQQGgf/oqG1VAofYfhqo+qilR/4FGQA8JkWtiqRb5KtXPRu+X8+YmhUk9XD1+L52A1kMd0sOuJwk5mEQXK7u/GLHQPIfguBttBV9gTJAjB94BZlZCDaGvoo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697712552; 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=yc1wAytN855M32R5CShLNXtSB0oVJdwxN5lIj8DxbsA=; b=VVXSc5AUc/PThHUVSl/6GiSSWvaD2vF4FMH51Xg/75T9vgWxVLjqXsoy5P8BIuYWcHUMPRcK9UT+L8T+wUy/D12Kdi4F6QqrtPDPlIyi1+Ir+bhPTtpm9GAs71eTuIhwRoDPVnh3mMiomr6nsiZKu8jN9qjfOgJKAfwRisg4u84= 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 1697712552043572.7211789070818; Thu, 19 Oct 2023 03:49:12 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qtQZF-0007CV-9a; Thu, 19 Oct 2023 06:47:53 -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 1qtQYq-0006aU-63 for qemu-devel@nongnu.org; Thu, 19 Oct 2023 06:47: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 1qtQYk-0006K6-RX for qemu-devel@nongnu.org; Thu, 19 Oct 2023 06:47:27 -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-344-eP4CVUTMOFK6IIxgtGWm9w-1; Thu, 19 Oct 2023 06:47:14 -0400 Received: by mail-ed1-f70.google.com with SMTP id 4fb4d7f45d1cf-53e2acda9d6so5324654a12.2 for ; Thu, 19 Oct 2023 03:47:14 -0700 (PDT) Received: from [192.168.10.118] ([2001:b07:6468:f312:5e2c:eb9a:a8b6:fd3e]) by smtp.gmail.com with ESMTPSA id s14-20020a05640217ce00b0053e4d1cbc6esm4179905edy.55.2023.10.19.03.47.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 03:47:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697712440; 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=yc1wAytN855M32R5CShLNXtSB0oVJdwxN5lIj8DxbsA=; b=MjIRrDEUx3ioOghVof+h8urWbdazm2beTIXCUTUGVzLClhkAxKjynBHcKxNDeUtAUq5FLf xTYSnCUURBAkEQqnyeqVW785q/JHeYcp0zMtw+tIcWGiHHzspIR7R9WkdEZPPEDD2kOeSP gRpVs6/7H9C6N6UEn4vZuinAWtbsFZA= X-MC-Unique: eP4CVUTMOFK6IIxgtGWm9w-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697712432; x=1698317232; 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=yc1wAytN855M32R5CShLNXtSB0oVJdwxN5lIj8DxbsA=; b=HMfyjB7AqBIi+bDwA4K9vRNTAeWPfEktBfEEQBLtnK5Dji1XXWGj5z6afYt8WW6Vnh foYCLN8Zy1gr/oVhrONovQd9jUaqUMa5/txmFkX9E+atCIb1ZB1BpdSVjxOXSXyHNJ0Y tFyVd5OxUh0FjdZSDU+ZGqsUL0iUL41t9PDLSzLpSnKDmDUsuTXAnsD4bdVsxcR4FEhy XZLlol6rJFzLmneX2lO9KlnrOhkxwHzaMzGovZkw/VN7sbplOimlg/aUT2QiewuseUAF XP5WSq0TMlvbQJWtyRvJ8dQNTE8QiLu228/JNk9u7ULpP3Dci66+2wwTChp7ETHMyxeI 1gUQ== X-Gm-Message-State: AOJu0YwQ+s5eeuyNMDJU81FUkQhawiEYeZ/26to5bf79hWgrO5lSJ7D5 wVd5sRLNyaesUgU+x0ph3/huA/KRuxDo5QjhwN5NZEb+XBFTg/LrjwG4yG8GqWkBY0wyighEiPr 9vMuWCnr8zZLpk0FtlU5o/3CqCffkTwx6vV8KlAdKxwKu13ci5jC7jEer7gA5JqW9MtGuVbl03g M= X-Received: by 2002:a05:6402:430b:b0:53d:bc68:633d with SMTP id m11-20020a056402430b00b0053dbc68633dmr1531994edc.7.1697712432704; Thu, 19 Oct 2023 03:47:12 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEAK966MZBi3UTq1SDApChVnv8oYaJY9ExHCuYYa4I0GNcfjNCRyJlMOdCG0b/YkmLOOrRG0A== X-Received: by 2002:a05:6402:430b:b0:53d:bc68:633d with SMTP id m11-20020a056402430b00b0053dbc68633dmr1531970edc.7.1697712432295; Thu, 19 Oct 2023 03:47:12 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH v2 13/19] target/i386: split eflags computation out of gen_compute_eflags Date: Thu, 19 Oct 2023 12:46:42 +0200 Message-ID: <20231019104648.389942-14-pbonzini@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231019104648.389942-1-pbonzini@redhat.com> References: <20231019104648.389942-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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1697712553632100003 Content-Type: text/plain; charset="utf-8" The new x86 decoder wants to compute EFLAGS before writeback, which can be an issue for some instructions such as ARPL. Extract code to compute the EFLAGS without clobbering CC_SRC, in case the ARPL memory write causes a fault. Signed-off-by: Paolo Bonzini --- target/i386/tcg/translate.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index e13bf7df591..2da7c357cdc 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -872,18 +872,20 @@ static void gen_op_update_neg_cc(DisasContext *s) tcg_gen_movi_tl(s->cc_srcT, 0); } =20 -/* compute all eflags to cc_src */ -static void gen_compute_eflags(DisasContext *s) +/* compute all eflags to reg */ +static void gen_mov_eflags(DisasContext *s, TCGv reg) { TCGv zero, dst, src1, src2; int live, dead; =20 if (s->cc_op =3D=3D CC_OP_EFLAGS) { + if (reg !=3D cpu_cc_src) { + tcg_gen_mov_tl(reg, cpu_cc_src); + } return; } if (s->cc_op =3D=3D CC_OP_CLR) { - tcg_gen_movi_tl(cpu_cc_src, CC_Z | CC_P); - set_cc_op(s, CC_OP_EFLAGS); + tcg_gen_movi_tl(reg, CC_Z | CC_P); return; } =20 @@ -909,7 +911,13 @@ static void gen_compute_eflags(DisasContext *s) } =20 gen_update_cc_op(s); - gen_helper_cc_compute_all(cpu_cc_src, dst, src1, src2, cpu_cc_op); + gen_helper_cc_compute_all(reg, dst, src1, src2, cpu_cc_op); +} + +/* compute all eflags to cc_src */ +static void gen_compute_eflags(DisasContext *s) +{ + gen_mov_eflags(s, cpu_cc_src); set_cc_op(s, CC_OP_EFLAGS); } =20 --=20 2.41.0 From nobody Wed Nov 27 15:47:24 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=1697712593; cv=none; d=zohomail.com; s=zohoarc; b=iPVnQVwYLOkfbUGIT73fwCUAlDDiBPmMQWKE28/qH+e1TWLhSYGSVj/B/MobZbb8V/PiX6gSlLRYV3dOvVtfJ4Mu2nijsCuoRTEnGXjSVXTEY25+VKoMT+sQ99t98quKj5g7AQpbZwTxtNLNPAMJzK6BPY0Ty543+5zoH4GBlTM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697712593; 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=HucFfp4qoLeyj68yJbflzgWXe6rIJtZX6o3+tCqe+xk=; b=bJ3nkDfgjwe+b4x5xgsaBAkmTKN+YTt15nCMtb1UO3Kfb1+cmTdw7tTfg5dmU/rZpNxsAXDtueY56ZQzpvuFh6WiDiLEJXUSqvLWvWi/FC7YxN4V0advFLtZMrd+eZhEXSWQ+gS9YYTMpXPVgok5TgEJVdS8/fClFsk7Fe6wl7s= 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 1697712593629250.62634829648653; Thu, 19 Oct 2023 03:49:53 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qtQZ7-0006r1-HO; Thu, 19 Oct 2023 06:47:45 -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 1qtQYm-0006aI-Gi for qemu-devel@nongnu.org; Thu, 19 Oct 2023 06:47:28 -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 1qtQYk-0006Ly-RW for qemu-devel@nongnu.org; Thu, 19 Oct 2023 06:47:24 -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-438-j-sPvKjfOjmtCfCm4emKgQ-1; Thu, 19 Oct 2023 06:47:15 -0400 Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-9a9e12a3093so76124966b.0 for ; Thu, 19 Oct 2023 03:47:15 -0700 (PDT) Received: from [192.168.10.118] ([2001:b07:6468:f312:5e2c:eb9a:a8b6:fd3e]) by smtp.gmail.com with ESMTPSA id b20-20020a170906d11400b00982a352f078sm3323241ejz.124.2023.10.19.03.47.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 03:47:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697712442; 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=HucFfp4qoLeyj68yJbflzgWXe6rIJtZX6o3+tCqe+xk=; b=LqtncQQkSbrZBdFoth4fCiLc2EdfSYGM52ws5fRqc+kNchQnaZ5LdMONlxVYOsjj6258Ms 2044WSjTbRvZqfSihV/xWLvDZ0yI+BFKu+6ZngGP9NODZ4THZvqtbs6MWiY90LgElEi6/Q PCunFz/Ra7vJ0BZEaqacJotwiVHx8M4= X-MC-Unique: j-sPvKjfOjmtCfCm4emKgQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697712434; x=1698317234; 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=HucFfp4qoLeyj68yJbflzgWXe6rIJtZX6o3+tCqe+xk=; b=VziAe83EKi0Gl+p5EIR27VvpjjWUSd51uMov9xriZ4NLF4lc6V1aQ+Hqx9cZf0bz/b P1lymxss2Gb10X6Xpl2Nqhtq5TXsV+IUyLXuXtxgg5y1hL+ITJHg5vtWVrqKWkCtsljB FqeYDxRatTljLqcJkZ4NcA6fZKfG4yt20SxAGq/sdhCA3GFkRG8fBnW0mbXp9QvOcNzj 4kzxgzl4C6fm6W8GJ5Llq8qGEq3yAlZB0abB+qoK/fKS8P9y73BytWe5BSSkqS68XRzO JhJDT398aENbIn/Ff2E8S/2ng9/iXnOptdBFOmWaa/pZ//2+umuLYakVacHWGkxPXcQX Z9Sw== X-Gm-Message-State: AOJu0YwiEbTlnO6ohGMDYVK7KoLHMuaU9JbgZ6NvRlCJwlKFInP6Gq+p k3l35+Rn7moq03DUyzp79JFa1sp/Tl3/StYnwCtKA5NDVvgSCYKxlnEjsHaw2wMiY3jlTjcwyvq sG4DmRhGqPjOolKDVS6Mpi94wq3verqfOyym4Xx4LW1Jn8FhGpl6o3boeChsfU4rtqeBVdlD9Ts 0= X-Received: by 2002:a17:907:9490:b0:9ae:5a56:be32 with SMTP id dm16-20020a170907949000b009ae5a56be32mr1436738ejc.38.1697712434344; Thu, 19 Oct 2023 03:47:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEQCbrMypby97/T2G03Y9O866GRKqr+rWC+xwmij/CRfYeIjw0pxCYdyaPFufoQsam5jujJ7Q== X-Received: by 2002:a17:907:9490:b0:9ae:5a56:be32 with SMTP id dm16-20020a170907949000b009ae5a56be32mr1436729ejc.38.1697712434039; Thu, 19 Oct 2023 03:47:14 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH v2 14/19] tcg: add negsetcondi Date: Thu, 19 Oct 2023 12:46:43 +0200 Message-ID: <20231019104648.389942-15-pbonzini@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231019104648.389942-1-pbonzini@redhat.com> References: <20231019104648.389942-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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1697712595957100006 Content-Type: text/plain; charset="utf-8" This can be useful to write a shift bit extraction that does not depend on TARGET_LONG_BITS. Signed-off-by: Paolo Bonzini Reviewed-by: Richard Henderson --- include/tcg/tcg-op-common.h | 4 ++++ include/tcg/tcg-op.h | 2 ++ tcg/tcg-op.c | 12 ++++++++++++ 3 files changed, 18 insertions(+) diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h index 2048f92b5e1..2295f2d7085 100644 --- a/include/tcg/tcg-op-common.h +++ b/include/tcg/tcg-op-common.h @@ -346,6 +346,8 @@ void tcg_gen_setcondi_i32(TCGCond cond, TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2); void tcg_gen_negsetcond_i32(TCGCond cond, TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2); +void tcg_gen_negsetcondi_i32(TCGCond cond, TCGv_i32 ret, + TCGv_i32 arg1, int32_t arg2); void tcg_gen_movcond_i32(TCGCond cond, TCGv_i32 ret, TCGv_i32 c1, TCGv_i32 c2, TCGv_i32 v1, TCGv_i32 v2); void tcg_gen_add2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 al, @@ -544,6 +546,8 @@ void tcg_gen_setcondi_i64(TCGCond cond, TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2); void tcg_gen_negsetcond_i64(TCGCond cond, TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2); +void tcg_gen_negsetcondi_i64(TCGCond cond, TCGv_i64 ret, + TCGv_i64 arg1, int64_t arg2); void tcg_gen_movcond_i64(TCGCond cond, TCGv_i64 ret, TCGv_i64 c1, TCGv_i64 c2, TCGv_i64 v1, TCGv_i64 v2); void tcg_gen_add2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 al, diff --git a/include/tcg/tcg-op.h b/include/tcg/tcg-op.h index 80cfcf8104b..78e474d83e9 100644 --- a/include/tcg/tcg-op.h +++ b/include/tcg/tcg-op.h @@ -201,6 +201,7 @@ DEF_ATOMIC2(tcg_gen_atomic_umax_fetch, i64) #define tcg_gen_setcond_tl tcg_gen_setcond_i64 #define tcg_gen_setcondi_tl tcg_gen_setcondi_i64 #define tcg_gen_negsetcond_tl tcg_gen_negsetcond_i64 +#define tcg_gen_negsetcondi_tl tcg_gen_negsetcondi_i64 #define tcg_gen_mul_tl tcg_gen_mul_i64 #define tcg_gen_muli_tl tcg_gen_muli_i64 #define tcg_gen_div_tl tcg_gen_div_i64 @@ -319,6 +320,7 @@ DEF_ATOMIC2(tcg_gen_atomic_umax_fetch, i64) #define tcg_gen_setcond_tl tcg_gen_setcond_i32 #define tcg_gen_setcondi_tl tcg_gen_setcondi_i32 #define tcg_gen_negsetcond_tl tcg_gen_negsetcond_i32 +#define tcg_gen_negsetcondi_tl tcg_gen_negsetcondi_i32 #define tcg_gen_mul_tl tcg_gen_mul_i32 #define tcg_gen_muli_tl tcg_gen_muli_i32 #define tcg_gen_div_tl tcg_gen_div_i32 diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c index 393dbcd01c3..35dcdd88126 100644 --- a/tcg/tcg-op.c +++ b/tcg/tcg-op.c @@ -291,6 +291,12 @@ void tcg_gen_negsetcond_i32(TCGCond cond, TCGv_i32 ret, } } =20 +void tcg_gen_negsetcondi_i32(TCGCond cond, TCGv_i32 ret, + TCGv_i32 arg1, int32_t arg2) +{ + tcg_gen_negsetcond_i32(cond, ret, arg1, tcg_constant_i32(arg2)); +} + void tcg_gen_muli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2) { if (arg2 =3D=3D 0) { @@ -1602,6 +1608,12 @@ void tcg_gen_setcondi_i64(TCGCond cond, TCGv_i64 ret, } } =20 +void tcg_gen_negsetcondi_i64(TCGCond cond, TCGv_i64 ret, + TCGv_i64 arg1, int64_t arg2) +{ + tcg_gen_negsetcond_i64(cond, ret, arg1, tcg_constant_i64(arg2)); +} + void tcg_gen_negsetcond_i64(TCGCond cond, TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2) { --=20 2.41.0 From nobody Wed Nov 27 15:47:24 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=1697712620; cv=none; d=zohomail.com; s=zohoarc; b=abQdI9q37Tbo4izxvsayfZqsMz9iOgrmCVxSc2MXZjqL0etNwDQ2D07HCPjvgokP/Ro+qO4A4FFWIX7+wV2yQTlLIfTu3CLQm8ykPITjShdm6PjSGLmjx06MSz7Z9bhLyuVga+WNXXGnI/2lYpJUHmf2U8RqeSusjT68YcNjOgs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697712620; 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=NQvy7syiiufOxfPqDD9L59bp8SqwN2e9iIHVz8xvPLQ=; b=XmYyokksBoGkg/L/Qmi5L9Djn50WbhztTeF+fvZgxnn47Pt48JbFu8bBlpnZOxPmckXqodRoeBS1rP53ktnUJhZ1NWVtiicjXEjWmswA+IF/xZtztTLG72LtUy1jNJnzgWA08gp0XYDFxLoTT5bnmJvC2MmhNv7vYdpKyUWWEWw= 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 1697712620845527.9759325409375; Thu, 19 Oct 2023 03:50:20 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qtQZf-00017Z-9x; Thu, 19 Oct 2023 06:48:19 -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 1qtQZd-00016g-TI for qemu-devel@nongnu.org; Thu, 19 Oct 2023 06:48:17 -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 1qtQZa-00074F-H5 for qemu-devel@nongnu.org; Thu, 19 Oct 2023 06:48:17 -0400 Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-453-gQes3ku-PzaUoGuIhBmgOw-1; Thu, 19 Oct 2023 06:48:12 -0400 Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-9b274cc9636so578027666b.0 for ; Thu, 19 Oct 2023 03:48:11 -0700 (PDT) Received: from [192.168.10.118] ([2001:b07:6468:f312:5e2c:eb9a:a8b6:fd3e]) by smtp.gmail.com with ESMTPSA id p9-20020a17090635c900b009ad8796a6aesm3284055ejb.56.2023.10.19.03.48.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 03:48:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697712493; 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=NQvy7syiiufOxfPqDD9L59bp8SqwN2e9iIHVz8xvPLQ=; b=Pi+ATD5L/FnVj4L/fyagj6zzGCayrlAjxOS/zqNnLgjIBDCuiAU/gpLadKfmjabV2B5lIR o935/ZgI6OS6dDs5Set4CswaCk4QMQSWmG0O+KDhb8zTjU5fglfnmXiQ/X1ZYP5cvQrdDq 8IOr03fHZElWsC48Aiq56ZplQWC4Z5w= X-MC-Unique: gQes3ku-PzaUoGuIhBmgOw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697712490; x=1698317290; 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=NQvy7syiiufOxfPqDD9L59bp8SqwN2e9iIHVz8xvPLQ=; b=PR9slGdplqW7H/A1SYNc0ZagQB7HQKx6qidWW/fDzdA3HuXcL2hKYMDtVjBf6zqo4L 8j7BLMOm3aCYmLJ6BReBQrUggz3/gWPGyqcDcdSS3jdiL/sUI3BxeFg/l52/mz+IZ3fD OvGJzts35WQXbXxYKQbxgA895bpMyqSESkkQFCyy8c5S1rNDAvCcM6onwlPWytVeEGLm agOW1UFOpWzIMmKoR/xXpBDUwGxd7+vnK5U2jx51omuqngA6asqTaz6ED73D5+r8FDKc FvlnZhiXf8SdcmJFmXLQyX8dUCUCBYCgMUZfl1ZusWg6TFicYPsqKhKGpsT2mxqiLtqq dJKg== X-Gm-Message-State: AOJu0YxKJIDegKJfqzaLiZiglZO1WDlCayvN5kImw3CTCPf0JzIy2Hlc QLqtdhhm1itjX38HsDE/kvr72739Fyj3AFwHuIBpkRTdwgiuhFxAhu+au2+lhtpHB8pCe/TRBoc MnU8JFSAg7WdXWqa+oWMaGixoIXcXKtSxtrV47/o6SgGDMxlqgy91F53VpbIyucg8h31Wz54R4P I= X-Received: by 2002:a17:907:783:b0:9b2:d554:da0e with SMTP id xd3-20020a170907078300b009b2d554da0emr1524700ejb.69.1697712490169; Thu, 19 Oct 2023 03:48:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHyU/02DRMWqVZWxjKI0WmtveDhlo6H7mj0fXvqJEEi2yWmUE4IqMiCCoE2CeEowG46QUwh6g== X-Received: by 2002:a17:907:783:b0:9b2:d554:da0e with SMTP id xd3-20020a170907078300b009b2d554da0emr1524673ejb.69.1697712489298; Thu, 19 Oct 2023 03:48:09 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH v2 15/19] target/i386: move 60-BF opcodes to new decoder Date: Thu, 19 Oct 2023 12:48:03 +0200 Message-ID: <20231019104807.390468-1-pbonzini@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231019104648.389942-1-pbonzini@redhat.com> References: <20231019104648.389942-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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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 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: 1697712621971100007 Content-Type: text/plain; charset="utf-8" Signed-off-by: Paolo Bonzini --- target/i386/tcg/decode-new.c.inc | 157 ++++++++++++++ target/i386/tcg/decode-new.h | 3 + target/i386/tcg/emit.c.inc | 355 ++++++++++++++++++++++++++++++- target/i386/tcg/translate.c | 38 ++-- 4 files changed, 536 insertions(+), 17 deletions(-) diff --git a/target/i386/tcg/decode-new.c.inc b/target/i386/tcg/decode-new.= c.inc index 1ae731459b7..d0baf972208 100644 --- a/target/i386/tcg/decode-new.c.inc +++ b/target/i386/tcg/decode-new.c.inc @@ -136,6 +136,7 @@ =20 #define cpuid(feat) .cpuid =3D X86_FEAT_##feat, #define nowb .special =3D X86_SPECIAL_NoWriteback, +#define noseg .special =3D X86_SPECIAL_NoSeg, #define xchg .special =3D X86_SPECIAL_Locked, #define mmx .special =3D X86_SPECIAL_MMX, #define zext0 .special =3D X86_SPECIAL_ZExtOp0, @@ -179,6 +180,9 @@ #define p_66_f3_f2 .valid_prefix =3D P_66 | P_F3 | P_F2, #define p_00_66_f3_f2 .valid_prefix =3D P_00 | P_66 | P_F3 | P_F2, =20 +static X86OpEntry illegal_opcode =3D + X86_OP_ENTRY0(illegal); + static uint8_t get_modrm(DisasContext *s, CPUX86State *env) { if (!s->has_modrm) { @@ -1078,6 +1082,46 @@ static void decode_0F(DisasContext *s, CPUX86State *= env, X86OpEntry *entry, uint do_decode_0F(s, env, entry, b); } =20 +static void decode_63(DisasContext *s, CPUX86State *env, X86OpEntry *entry= , uint8_t *b) +{ + static const X86OpEntry arpl =3D X86_OP_ENTRY2(ARPL, E,w, G,w, chk(pro= t)); + static const X86OpEntry mov =3D X86_OP_ENTRY3(MOV, G,v, E,v, None, Non= e); + static const X86OpEntry movsxd =3D X86_OP_ENTRY3(MOVSXD, G,v, E,d, Non= e, None); + if (!CODE64(s)) { + *entry =3D arpl; + } else if (REX_W(s)) { + *entry =3D movsxd; + } else { + *entry =3D mov; + } +} + +static void decode_group1(DisasContext *s, CPUX86State *env, X86OpEntry *e= ntry, uint8_t *b) +{ + static const X86GenFunc group1_gen[8] =3D { + gen_ADD, gen_OR, gen_ADC, gen_SBB, gen_AND, gen_SUB, gen_XOR, gen_= SUB, + }; + int op =3D (get_modrm(s, env) >> 3) & 7; + entry->gen =3D group1_gen[op]; + + if (op =3D=3D 7) { + /* CMP */ + entry->special =3D X86_SPECIAL_NoWriteback; + } +} + +static void decode_group1A(DisasContext *s, CPUX86State *env, X86OpEntry *= entry, uint8_t *b) +{ + int op =3D (get_modrm(s, env) >> 3) & 7; + if (op !=3D 0) { + *entry =3D illegal_opcode; + } else { + entry->gen =3D gen_POP; + /* The address must use the value of ESP after the pop. */ + s->popl_esp_hack =3D 1 << mo_pushpop(s, s->dflag); + } +} + static const X86OpEntry opcodes_root[256] =3D { [0x00] =3D X86_OP_ENTRY2(ADD, E,b, G,b), [0x01] =3D X86_OP_ENTRY2(ADD, E,v, G,v), @@ -1133,6 +1177,60 @@ static const X86OpEntry opcodes_root[256] =3D { [0x56] =3D X86_OP_ENTRYr(PUSH, LoBits,d64), [0x57] =3D X86_OP_ENTRYr(PUSH, LoBits,d64), =20 + [0x60] =3D X86_OP_ENTRY0(PUSHA, chk(i64)), + [0x61] =3D X86_OP_ENTRY0(POPA, chk(i64)), + [0x62] =3D X86_OP_ENTRY2(BOUND, G,v, M,a, chk(i64)), + [0x63] =3D X86_OP_GROUP0(63), + [0x64] =3D {}, + [0x65] =3D {}, + [0x66] =3D {}, + [0x67] =3D {}, + + [0x70] =3D X86_OP_ENTRYr(Jcc, J,b), + [0x71] =3D X86_OP_ENTRYr(Jcc, J,b), + [0x72] =3D X86_OP_ENTRYr(Jcc, J,b), + [0x73] =3D X86_OP_ENTRYr(Jcc, J,b), + [0x74] =3D X86_OP_ENTRYr(Jcc, J,b), + [0x75] =3D X86_OP_ENTRYr(Jcc, J,b), + [0x76] =3D X86_OP_ENTRYr(Jcc, J,b), + [0x77] =3D X86_OP_ENTRYr(Jcc, J,b), + + [0x80] =3D X86_OP_GROUP2(group1, E,b, I,b), + [0x81] =3D X86_OP_GROUP2(group1, E,v, I,z), + [0x82] =3D X86_OP_GROUP2(group1, E,b, I,b, chk(i64)), + [0x83] =3D X86_OP_GROUP2(group1, E,v, I,b), + [0x84] =3D X86_OP_ENTRY2(AND, E,b, G,b, nowb), + [0x85] =3D X86_OP_ENTRY2(AND, E,v, G,v, nowb), + [0x86] =3D X86_OP_ENTRY2(XCHG, E,b, G,b, xchg), + [0x87] =3D X86_OP_ENTRY2(XCHG, E,v, G,v, xchg), + + [0x90] =3D X86_OP_ENTRY2(XCHG, 0,v, LoBits,v), + [0x91] =3D X86_OP_ENTRY2(XCHG, 0,v, LoBits,v), + [0x92] =3D X86_OP_ENTRY2(XCHG, 0,v, LoBits,v), + [0x93] =3D X86_OP_ENTRY2(XCHG, 0,v, LoBits,v), + [0x94] =3D X86_OP_ENTRY2(XCHG, 0,v, LoBits,v), + [0x95] =3D X86_OP_ENTRY2(XCHG, 0,v, LoBits,v), + [0x96] =3D X86_OP_ENTRY2(XCHG, 0,v, LoBits,v), + [0x97] =3D X86_OP_ENTRY2(XCHG, 0,v, LoBits,v), + + [0xA0] =3D X86_OP_ENTRY3(MOV, 0,b, O,b, None, None), /* AL, Ob */ + [0xA1] =3D X86_OP_ENTRY3(MOV, 0,v, O,v, None, None), /* rAX, Ov */ + [0xA2] =3D X86_OP_ENTRY3(MOV, O,b, 0,b, None, None), /* Ob, AL */ + [0xA3] =3D X86_OP_ENTRY3(MOV, O,v, 0,v, None, None), /* Ov, rAX */ + [0xA4] =3D X86_OP_ENTRY2(MOVS, Y,b, X,b, nowb), + [0xA5] =3D X86_OP_ENTRY2(MOVS, Y,v, X,v, nowb), + [0xA6] =3D X86_OP_ENTRY2(CMPS, Y,b, X,b, nowb), + [0xA7] =3D X86_OP_ENTRY2(CMPS, Y,v, X,v, nowb), + + [0xB0] =3D X86_OP_ENTRY3(MOV, LoBits,b, I,b, None, None), + [0xB1] =3D X86_OP_ENTRY3(MOV, LoBits,b, I,b, None, None), + [0xB2] =3D X86_OP_ENTRY3(MOV, LoBits,b, I,b, None, None), + [0xB3] =3D X86_OP_ENTRY3(MOV, LoBits,b, I,b, None, None), + [0xB4] =3D X86_OP_ENTRY3(MOV, LoBits,b, I,b, None, None), + [0xB5] =3D X86_OP_ENTRY3(MOV, LoBits,b, I,b, None, None), + [0xB6] =3D X86_OP_ENTRY3(MOV, LoBits,b, I,b, None, None), + [0xB7] =3D X86_OP_ENTRY3(MOV, LoBits,b, I,b, None, None), + =20 [0x08] =3D X86_OP_ENTRY2(OR, E,b, G,b), [0x09] =3D X86_OP_ENTRY2(OR, E,v, G,v), @@ -1187,6 +1285,60 @@ static const X86OpEntry opcodes_root[256] =3D { [0x5D] =3D X86_OP_ENTRYw(POP, LoBits,d64), [0x5E] =3D X86_OP_ENTRYw(POP, LoBits,d64), [0x5F] =3D X86_OP_ENTRYw(POP, LoBits,d64), + + [0x68] =3D X86_OP_ENTRYr(PUSH, I,z), + [0x69] =3D X86_OP_ENTRY3(IMUL3, G,v, E,v, I,z), + [0x6A] =3D X86_OP_ENTRYr(PUSH, I,b), + [0x6B] =3D X86_OP_ENTRY3(IMUL3, G,v, E,v, I,b), + [0x6C] =3D X86_OP_ENTRY2(INS, Y,b, 2,w, nowb), /* DX */ + [0x6D] =3D X86_OP_ENTRY2(INS, Y,z, 2,w, nowb), /* DX */ + [0x6E] =3D X86_OP_ENTRY2(OUTS, 2,w, X,b, nowb), /* DX */ + [0x6F] =3D X86_OP_ENTRY2(OUTS, 2,w, X,b, nowb), /* DX */ + + [0x78] =3D X86_OP_ENTRYr(Jcc, J,b), + [0x79] =3D X86_OP_ENTRYr(Jcc, J,b), + [0x7A] =3D X86_OP_ENTRYr(Jcc, J,b), + [0x7B] =3D X86_OP_ENTRYr(Jcc, J,b), + [0x7C] =3D X86_OP_ENTRYr(Jcc, J,b), + [0x7D] =3D X86_OP_ENTRYr(Jcc, J,b), + [0x7E] =3D X86_OP_ENTRYr(Jcc, J,b), + [0x7F] =3D X86_OP_ENTRYr(Jcc, J,b), + + [0x88] =3D X86_OP_ENTRY3(MOV, E,b, G,b, None, None), + [0x89] =3D X86_OP_ENTRY3(MOV, E,v, G,v, None, None), + [0x8A] =3D X86_OP_ENTRY3(MOV, G,b, E,b, None, None), + [0x8B] =3D X86_OP_ENTRY3(MOV, G,v, E,v, None, None), + [0x8C] =3D X86_OP_ENTRY3(MOV, E,v, S,w, None, None), + [0x8D] =3D X86_OP_ENTRY3(LEA, G,v, M,v, None, None, noseg), + [0x8E] =3D X86_OP_ENTRY3(MOV, S,w, E,v, None, None), + [0x8F] =3D X86_OP_GROUPw(group1A, E,v), + + [0x98] =3D X86_OP_ENTRY1(CBW, 0,v), /* rAX */ + [0x99] =3D X86_OP_ENTRY3(CWD, 2,v, 0,v, None, None), /* rDX, rAX */ + [0x9A] =3D X86_OP_ENTRYr(CALLF, A,p, chk(i64)), + [0x9B] =3D X86_OP_ENTRY0(WAIT), + [0x9C] =3D X86_OP_ENTRY0(PUSHF, chk(vm86_iopl) svm(PUSHF)), + [0x9D] =3D X86_OP_ENTRY0(POPF, chk(vm86_iopl) svm(POPF)), + [0x9E] =3D X86_OP_ENTRY0(SAHF), + [0x9F] =3D X86_OP_ENTRY0(LAHF), + + [0xA8] =3D X86_OP_ENTRY2(AND, 0,b, I,b, nowb), /* AL, Ib */ + [0xA9] =3D X86_OP_ENTRY2(AND, 0,v, I,z, nowb), /* rAX, Iz */ + [0xAA] =3D X86_OP_ENTRY2(STOS, Y,b, 0,b, nowb), + [0xAB] =3D X86_OP_ENTRY2(STOS, Y,v, 0,v, nowb), + [0xAC] =3D X86_OP_ENTRY2(LODS, 0,b, X,b, nowb), + [0xAD] =3D X86_OP_ENTRY2(LODS, 0,v, X,v, nowb), + [0xAE] =3D X86_OP_ENTRY2(SCAS, 0,b, Y,b, nowb), + [0xAF] =3D X86_OP_ENTRY2(SCAS, 0,v, Y,v, nowb), + + [0xB8] =3D X86_OP_ENTRY3(MOV, LoBits,v, I,v, None, None), + [0xB9] =3D X86_OP_ENTRY3(MOV, LoBits,v, I,v, None, None), + [0xBA] =3D X86_OP_ENTRY3(MOV, LoBits,v, I,v, None, None), + [0xBB] =3D X86_OP_ENTRY3(MOV, LoBits,v, I,v, None, None), + [0xBC] =3D X86_OP_ENTRY3(MOV, LoBits,v, I,v, None, None), + [0xBD] =3D X86_OP_ENTRY3(MOV, LoBits,v, I,v, None, None), + [0xBE] =3D X86_OP_ENTRY3(MOV, LoBits,v, I,v, None, None), + [0xBF] =3D X86_OP_ENTRY3(MOV, LoBits,v, I,v, None, None), }; =20 #undef mmx @@ -2028,6 +2180,11 @@ static void disas_insn_new(DisasContext *s, CPUState= *cpu, int b) =20 default: break; + + case X86_SPECIAL_NoSeg: + decode.mem.def_seg =3D -1; + s->override =3D -1; + break; } =20 if (!validate_vex(s, &decode)) { diff --git a/target/i386/tcg/decode-new.h b/target/i386/tcg/decode-new.h index a3983794ac5..32396630865 100644 --- a/target/i386/tcg/decode-new.h +++ b/target/i386/tcg/decode-new.h @@ -164,6 +164,9 @@ typedef enum X86InsnSpecial { /* Writeback not needed or done manually in the callback */ X86_SPECIAL_NoWriteback, =20 + /* Do not apply segment base to effective address */ + X86_SPECIAL_NoSeg, + /* * Register operand 0/2 is zero extended to 32 bits. Rd/Mb or Rd/Mw * in the manual. diff --git a/target/i386/tcg/emit.c.inc b/target/i386/tcg/emit.c.inc index 6b9f518cc94..267f4fe383a 100644 --- a/target/i386/tcg/emit.c.inc +++ b/target/i386/tcg/emit.c.inc @@ -1160,6 +1160,30 @@ static void gen_ANDN(DisasContext *s, CPUX86State *e= nv, X86DecodedInsn *decode) prepare_update1_cc(decode, s, CC_OP_LOGICB + ot); } =20 +static void gen_ARPL(DisasContext *s, CPUX86State *env, X86DecodedInsn *de= code) +{ + TCGLabel *label1 =3D gen_new_label(); + TCGv rpl_adj =3D tcg_temp_new(); + + gen_mov_eflags(s, s->tmp4); + tcg_gen_andi_tl(s->tmp4, s->tmp4, ~CC_Z); + + /* Compute dest[rpl] - src[rpl], adjust if result <0. */ + tcg_gen_andi_tl(rpl_adj, s->T0, 3); + tcg_gen_andi_tl(s->T1, s->T1, 3); + tcg_gen_sub_tl(rpl_adj, rpl_adj, s->T1); + + tcg_gen_brcondi_tl(TCG_COND_LT, rpl_adj, 0, label1); + + /* Subtract dest[rpl] - src[rpl] to set dest[rpl] =3D src[rpl]. */ + tcg_gen_sub_tl(s->T0, s->T0, rpl_adj); + tcg_gen_ori_tl(s->tmp4, s->tmp4, CC_Z); + gen_set_label(label1); + + decode->cc_src =3D s->tmp4; + decode->cc_op =3D CC_OP_EFLAGS; +} + static void gen_BEXTR(DisasContext *s, CPUX86State *env, X86DecodedInsn *d= ecode) { MemOp ot =3D decode->op[0].ot; @@ -1227,6 +1251,16 @@ static void gen_BLSR(DisasContext *s, CPUX86State *e= nv, X86DecodedInsn *decode) set_cc_op(s, CC_OP_BMILGB + ot); } =20 +static void gen_BOUND(DisasContext *s, CPUX86State *env, X86DecodedInsn *d= ecode) +{ + tcg_gen_trunc_tl_i32(s->tmp2_i32, s->T0); + if (decode->op[1].ot =3D=3D MO_16) { + gen_helper_boundw(tcg_env, s->A0, s->tmp2_i32); + } else { + gen_helper_boundl(tcg_env, s->A0, s->tmp2_i32); + } +} + static void gen_BZHI(DisasContext *s, CPUX86State *env, X86DecodedInsn *de= code) { MemOp ot =3D decode->op[0].ot; @@ -1249,6 +1283,43 @@ static void gen_BZHI(DisasContext *s, CPUX86State *e= nv, X86DecodedInsn *decode) prepare_update1_cc(decode, s, CC_OP_BMILGB + ot); } =20 +static void gen_CALLF(DisasContext *s, CPUX86State *env, X86DecodedInsn *d= ecode) +{ + MemOp ot =3D decode->op[2].ot; + unsigned int selector, offset; + + if (CODE64(s)) { + gen_illegal_opcode(s); + return; + } + + assert(ot >=3D MO_16); + offset =3D insn_get(env, s, ot); + selector =3D insn_get(env, s, MO_16); + tcg_gen_movi_tl(s->T0, selector); + tcg_gen_movi_tl(s->T1, offset); + return gen_far_call(s); +} + +static void gen_CBW(DisasContext *s, CPUX86State *env, X86DecodedInsn *dec= ode) +{ + switch(decode->op[0].ot) { +#ifdef TARGET_X86_64 + case MO_64: + tcg_gen_ext32s_tl(s->T0, s->T0); + break; +#endif + case MO_32: + tcg_gen_ext16s_tl(s->T0, s->T0); + break; + case MO_16: + tcg_gen_ext8s_tl(s->T0, s->T0); + break; + default: + g_assert_not_reached(); + } +} + static void gen_CMPccXADD(DisasContext *s, CPUX86State *env, X86DecodedIns= n *decode) { TCGv z_tl =3D tcg_constant_tl(0); @@ -1347,6 +1418,18 @@ static void gen_CMPccXADD(DisasContext *s, CPUX86Sta= te *env, X86DecodedInsn *dec gen_writeback(s, decode, 1, s->cc_srcT); } =20 +static void gen_CMPS(DisasContext *s, CPUX86State *env, X86DecodedInsn *de= code) +{ + MemOp ot =3D decode->op[0].ot; + if (s->prefix & PREFIX_REPNZ) { + gen_repz_cmps(s, ot, 1); + } else if (s->prefix & PREFIX_REPZ) { + gen_repz_cmps(s, ot, 0); + } else { + gen_cmps(s, ot); + } +} + static void gen_CRC32(DisasContext *s, CPUX86State *env, X86DecodedInsn *d= ecode) { MemOp ot =3D decode->op[2].ot; @@ -1385,6 +1468,24 @@ static void gen_CVTTPx2PI(DisasContext *s, CPUX86Sta= te *env, X86DecodedInsn *dec } } =20 +static void gen_CWD(DisasContext *s, CPUX86State *env, X86DecodedInsn *dec= ode) +{ + int shift =3D 8 << decode->op[0].ot; + switch (shift) { + case 64: + break; + case 32: + tcg_gen_ext32s_tl(s->T0, s->T0); + break; + case 16: + tcg_gen_ext16s_tl(s->T0, s->T0); + break; + default: + g_assert_not_reached(); + } + tcg_gen_sari_tl(s->T0, s->T0, shift - 1); +} + static void gen_DAA(DisasContext *s, CPUX86State *env, X86DecodedInsn *dec= ode) { gen_update_cc_op(s); @@ -1431,6 +1532,58 @@ static void gen_EXTRQ_r(DisasContext *s, CPUX86State= *env, X86DecodedInsn *decod gen_helper_extrq_r(tcg_env, OP_PTR0, OP_PTR2); } =20 +static void gen_IMUL3(DisasContext *s, CPUX86State *env, X86DecodedInsn *d= ecode) +{ + MemOp ot =3D decode->op[0].ot; + TCGv cc_src_rhs; + + switch (ot) { + case MO_16: + tcg_gen_ext16s_tl(s->T0, s->T0); + tcg_gen_ext16s_tl(s->T1, s->T1); + /* XXX: use 32 bit mul which could be faster */ + tcg_gen_mul_tl(s->T0, s->T0, s->T1); + /* Compare the full result to the extension of the truncated resul= t. */ + tcg_gen_ext16s_tl(s->T1, s->T0); + cc_src_rhs =3D s->T0; + break; + + case MO_32: +#ifdef TARGET_X86_64 + /* + * This could also use the same algorithm as MO_16. It produces f= ewer + * TCG ops and better code if flags are needed, but it requires a = 64-bit + * multiply even if they are not (and thus the high part of the mu= ltiply + * is dead). + */ + tcg_gen_trunc_tl_i32(s->tmp2_i32, s->T0); + tcg_gen_trunc_tl_i32(s->tmp3_i32, s->T1); + tcg_gen_muls2_i32(s->tmp2_i32, s->tmp3_i32, + s->tmp2_i32, s->tmp3_i32); + tcg_gen_extu_i32_tl(s->T0, s->tmp2_i32); + tcg_gen_extu_i32_tl(s->tmp0, s->tmp3_i32); + /* Compare the high part to the sign bit of the truncated result */ + tcg_gen_negsetcondi_i32(TCG_COND_LT, s->tmp2_i32, s->tmp2_i32, 0); + tcg_gen_extu_i32_tl(s->T1, s->tmp2_i32); + cc_src_rhs =3D s->tmp0; + break; + + case MO_64: +#endif + tcg_gen_muls2_tl(s->T0, s->tmp0, s->T0, s->T1); + /* Compare the high part to the sign bit of the truncated result */ + tcg_gen_negsetcondi_tl(TCG_COND_LT, s->T1, s->T0, 0); + cc_src_rhs =3D s->tmp0; + break; + + default: + g_assert_not_reached(); + } + + tcg_gen_sub_tl(s->T1, s->T1, cc_src_rhs); + prepare_update2_cc(decode, s, CC_OP_MULB + ot); +} + static void gen_INC(DisasContext *s, CPUX86State *env, X86DecodedInsn *dec= ode) { MemOp ot =3D decode->op[0].ot; @@ -1445,6 +1598,25 @@ static void gen_INC(DisasContext *s, CPUX86State *en= v, X86DecodedInsn *decode) prepare_update_cc_incdec(decode, s, CC_OP_INCB + ot); } =20 +static void gen_INS(DisasContext *s, CPUX86State *env, X86DecodedInsn *dec= ode) +{ + MemOp ot =3D decode->op[0].ot; + + tcg_gen_trunc_tl_i32(s->tmp2_i32, s->T1); + tcg_gen_ext16u_i32(s->tmp2_i32, s->tmp2_i32); + if (!gen_check_io(s, ot, s->tmp2_i32, + SVM_IOIO_TYPE_MASK | SVM_IOIO_STR_MASK)) { + return; + } + + translator_io_start(&s->base); + if (s->prefix & (PREFIX_REPZ | PREFIX_REPNZ)) { + gen_repz_ins(s, ot); + } else { + gen_ins(s, ot); + } +} + static void gen_INSERTQ_i(DisasContext *s, CPUX86State *env, X86DecodedIns= n *decode) { TCGv_i32 length =3D tcg_constant_i32(decode->immediate & 63); @@ -1458,12 +1630,50 @@ static void gen_INSERTQ_r(DisasContext *s, CPUX86St= ate *env, X86DecodedInsn *dec gen_helper_insertq_r(tcg_env, OP_PTR0, OP_PTR2); } =20 +static void gen_Jcc(DisasContext *s, CPUX86State *env, X86DecodedInsn *dec= ode) +{ + gen_bnd_jmp(s); + gen_jcc(s, decode->b & 0xf, decode->immediate); +} + +static void gen_LAHF(DisasContext *s, CPUX86State *env, X86DecodedInsn *de= code) +{ + if (CODE64(s) && !(s->cpuid_ext3_features & CPUID_EXT3_LAHF_LM)) { + return gen_illegal_opcode(s); + } + gen_compute_eflags(s); + /* Note: gen_compute_eflags() only gives the condition codes */ + tcg_gen_ori_tl(s->T0, cpu_cc_src, 0x02); + tcg_gen_deposit_tl(cpu_regs[R_EAX], cpu_regs[R_EAX], s->T0, 8, 8); +} + static void gen_LDMXCSR(DisasContext *s, CPUX86State *env, X86DecodedInsn = *decode) { tcg_gen_trunc_tl_i32(s->tmp2_i32, s->T1); gen_helper_ldmxcsr(tcg_env, s->tmp2_i32); } =20 +static void gen_LEA(DisasContext *s, CPUX86State *env, X86DecodedInsn *dec= ode) +{ + tcg_gen_mov_tl(s->T0, s->A0); +} + +static void gen_LODS(DisasContext *s, CPUX86State *env, X86DecodedInsn *de= code) +{ + MemOp ot =3D decode->op[0].ot; + if (s->prefix & (PREFIX_REPZ | PREFIX_REPNZ)) { + gen_repz_lods(s, ot); + } else { + gen_lods(s, ot); + } +} + +static void gen_MOV(DisasContext *s, CPUX86State *env, X86DecodedInsn *dec= ode) +{ + /* nothing to do! */ +} +#define gen_NOP gen_MOV + static void gen_MASKMOV(DisasContext *s, CPUX86State *env, X86DecodedInsn = *decode) { tcg_gen_mov_tl(s->A0, cpu_regs[R_EDI]); @@ -1573,6 +1783,21 @@ static void gen_MOVq_dq(DisasContext *s, CPUX86State= *env, X86DecodedInsn *decod return gen_MOVQ(s, env, decode); } =20 +static void gen_MOVS(DisasContext *s, CPUX86State *env, X86DecodedInsn *de= code) +{ + MemOp ot =3D decode->op[0].ot; + if (s->prefix & (PREFIX_REPZ | PREFIX_REPNZ)) { + gen_repz_movs(s, ot); + } else { + gen_movs(s, ot); + } +} + +static void gen_MOVSXD(DisasContext *s, CPUX86State *env, X86DecodedInsn *= decode) +{ + tcg_gen_ext32s_tl(s->T0, s->T0); +} + static void gen_MULX(DisasContext *s, CPUX86State *env, X86DecodedInsn *de= code) { MemOp ot =3D decode->op[0].ot; @@ -1609,6 +1834,24 @@ static void gen_OR(DisasContext *s, CPUX86State *env= , X86DecodedInsn *decode) prepare_update1_cc(decode, s, CC_OP_LOGICB + ot); } =20 +static void gen_OUTS(DisasContext *s, CPUX86State *env, X86DecodedInsn *de= code) +{ + MemOp ot =3D decode->op[1].ot; + + tcg_gen_trunc_tl_i32(s->tmp2_i32, s->T0); + tcg_gen_ext16u_i32(s->tmp2_i32, s->tmp2_i32); + if (!gen_check_io(s, ot, s->tmp2_i32, SVM_IOIO_STR_MASK)) { + return; + } + + translator_io_start(&s->base); + if (s->prefix & (PREFIX_REPZ | PREFIX_REPNZ)) { + gen_repz_outs(s, ot); + } else { + gen_outs(s, ot); + } +} + static void gen_PALIGNR(DisasContext *s, CPUX86State *env, X86DecodedInsn = *decode) { TCGv_i32 imm =3D tcg_constant8u_i32(decode->immediate); @@ -1872,6 +2115,33 @@ static void gen_POP(DisasContext *s, CPUX86State *en= v, X86DecodedInsn *decode) gen_pop_update(s, ot); } =20 +static void gen_POPA(DisasContext *s, CPUX86State *env, X86DecodedInsn *de= code) +{ + gen_popa(s); +} + +static void gen_POPF(DisasContext *s, CPUX86State *env, X86DecodedInsn *de= code) +{ + MemOp ot; + int mask =3D TF_MASK | AC_MASK | ID_MASK | NT_MASK; + + if (CPL(s) =3D=3D 0) { + mask |=3D IF_MASK | IOPL_MASK; + } else if (CPL(s) <=3D IOPL(s)) { + mask |=3D IF_MASK; + } + if (s->dflag =3D=3D MO_16) { + mask &=3D 0xffff; + } + + ot =3D gen_pop_T0(s); + gen_helper_write_eflags(tcg_env, s->T0, tcg_constant_i32(mask)); + gen_pop_update(s, ot); + set_cc_op(s, CC_OP_EFLAGS); + /* abort translation because TF/AC flag may change */ + s->base.is_jmp =3D DISAS_EOB_NEXT; +} + static void gen_PSHUFW(DisasContext *s, CPUX86State *env, X86DecodedInsn *= decode) { TCGv_i32 imm =3D tcg_constant8u_i32(decode->immediate); @@ -2023,6 +2293,18 @@ static void gen_PUSH(DisasContext *s, CPUX86State *e= nv, X86DecodedInsn *decode) gen_push_v(s, s->T1); } =20 +static void gen_PUSHA(DisasContext *s, CPUX86State *env, X86DecodedInsn *d= ecode) +{ + gen_pusha(s); +} + +static void gen_PUSHF(DisasContext *s, CPUX86State *env, X86DecodedInsn *d= ecode) +{ + gen_update_cc_op(s); + gen_helper_read_eflags(s->T0, tcg_env); + gen_push_v(s, s->T0); +} + static void gen_RORX(DisasContext *s, CPUX86State *env, X86DecodedInsn *de= code) { MemOp ot =3D decode->op[0].ot; @@ -2037,6 +2319,18 @@ static void gen_RORX(DisasContext *s, CPUX86State *e= nv, X86DecodedInsn *decode) } } =20 +static void gen_SAHF(DisasContext *s, CPUX86State *env, X86DecodedInsn *de= code) +{ + if (CODE64(s) && !(s->cpuid_ext3_features & CPUID_EXT3_LAHF_LM)) { + return gen_illegal_opcode(s); + } + tcg_gen_shri_tl(s->T0, cpu_regs[R_EAX], 8); + gen_compute_eflags(s); + tcg_gen_andi_tl(cpu_cc_src, cpu_cc_src, CC_O); + tcg_gen_andi_tl(s->T0, s->T0, CC_S | CC_Z | CC_A | CC_P | CC_C); + tcg_gen_or_tl(cpu_cc_src, cpu_cc_src, s->T0); +} + static void gen_SARX(DisasContext *s, CPUX86State *env, X86DecodedInsn *de= code) { MemOp ot =3D decode->op[0].ot; @@ -2067,6 +2361,18 @@ static void gen_SBB(DisasContext *s, CPUX86State *en= v, X86DecodedInsn *decode) prepare_update3_cc(decode, s, CC_OP_SBBB + ot, s->tmp4); } =20 +static void gen_SCAS(DisasContext *s, CPUX86State *env, X86DecodedInsn *de= code) +{ + MemOp ot =3D decode->op[0].ot; + if (s->prefix & PREFIX_REPNZ) { + gen_repz_scas(s, ot, 1); + } else if (s->prefix & PREFIX_REPZ) { + gen_repz_scas(s, ot, 0); + } else { + gen_scas(s, ot); + } +} + static void gen_SHA1NEXTE(DisasContext *s, CPUX86State *env, X86DecodedIns= n *decode) { gen_helper_sha1nexte(OP_PTR0, OP_PTR1, OP_PTR2); @@ -2157,6 +2463,16 @@ static void gen_STMXCSR(DisasContext *s, CPUX86State= *env, X86DecodedInsn *decod tcg_gen_ld32u_tl(s->T0, tcg_env, offsetof(CPUX86State, mxcsr)); } =20 +static void gen_STOS(DisasContext *s, CPUX86State *env, X86DecodedInsn *de= code) +{ + MemOp ot =3D decode->op[0].ot; + if (s->prefix & (PREFIX_REPZ | PREFIX_REPNZ)) { + gen_repz_stos(s, ot); + } else { + gen_stos(s, ot); + } +} + static void gen_SUB(DisasContext *s, CPUX86State *env, X86DecodedInsn *dec= ode) { MemOp ot =3D decode->op[0].ot; @@ -2653,6 +2969,43 @@ static void gen_VZEROUPPER(DisasContext *s, CPUX86St= ate *env, X86DecodedInsn *de } } =20 +static void gen_WAIT(DisasContext *s, CPUX86State *env, X86DecodedInsn *de= code) +{ + if ((s->flags & (HF_MP_MASK | HF_TS_MASK)) =3D=3D (HF_MP_MASK | HF_TS_= MASK)) { + gen_NM_exception(s); + } else { + /* needs to be treated as I/O because of ferr_irq */ + translator_io_start(&s->base); + gen_helper_fwait(tcg_env); + } +} + +static void gen_XCHG(DisasContext *s, CPUX86State *env, X86DecodedInsn *de= code) +{ + if (decode->b =3D=3D 0x90 && !REX_B(s)) { + if (s->prefix & PREFIX_REPZ) { + gen_update_cc_op(s); + gen_update_eip_cur(s); + gen_helper_pause(tcg_env, cur_insn_len_i32(s)); + s->base.is_jmp =3D DISAS_NORETURN; + } + /* No writeback. */ + decode->op[0].unit =3D X86_OP_SKIP; + return; + } + + if (s->prefix & PREFIX_LOCK) { + tcg_gen_atomic_xchg_tl(s->T0, s->A0, s->T1, + s->mem_index, decode->op[0].ot | MO_LE); + /* now store old value into register operand */ + gen_op_mov_reg_v(s, decode->op[2].ot, decode->op[2].n, s->T0); + } else { + /* move destination value into source operand, source preserved in= T1 */ + gen_op_mov_reg_v(s, decode->op[2].ot, decode->op[2].n, s->T0); + tcg_gen_mov_tl(s->T0, s->T1); + } +} + static void gen_XOR(DisasContext *s, CPUX86State *env, X86DecodedInsn *dec= ode) { /* special case XOR reg, reg */ @@ -2660,7 +3013,7 @@ static void gen_XOR(DisasContext *s, CPUX86State *env= , X86DecodedInsn *decode) decode->op[2].unit =3D=3D X86_OP_INT && decode->op[1].n =3D=3D decode->op[2].n) { tcg_gen_movi_tl(s->T0, 0); - set_cc_op(s, CC_OP_CLR); + decode->cc_op =3D CC_OP_CLR; } else { MemOp ot =3D decode->op[0].ot; =20 diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index 2da7c357cdc..9c799b5a980 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -2563,6 +2563,23 @@ static void gen_movl_seg_T0(DisasContext *s, X86Seg = seg_reg) } } =20 +static void gen_far_call(DisasContext *s) +{ + if (PE(s) && !VM86(s)) { + tcg_gen_trunc_tl_i32(s->tmp2_i32, s->T0); + gen_helper_lcall_protected(tcg_env, s->tmp2_i32, s->T1, + tcg_constant_i32(s->dflag - 1), + eip_next_tl(s)); + } else { + tcg_gen_trunc_tl_i32(s->tmp2_i32, s->T0); + tcg_gen_trunc_tl_i32(s->tmp3_i32, s->T1); + gen_helper_lcall_real(tcg_env, s->tmp2_i32, s->tmp3_i32, + tcg_constant_i32(s->dflag - 1), + eip_next_i32(s)); + } + s->base.is_jmp =3D DISAS_JUMP; +} + static void gen_svm_check_intercept(DisasContext *s, uint32_t type) { /* no SVM activated; fast case */ @@ -3108,6 +3125,7 @@ static bool disas_insn(DisasContext *s, CPUState *cpu) =20 s->pc =3D s->base.pc_next; s->override =3D -1; + s->popl_esp_hack =3D 0; #ifdef TARGET_X86_64 s->rex_r =3D 0; s->rex_x =3D 0; @@ -3164,7 +3182,7 @@ static bool disas_insn(DisasContext *s, CPUState *cpu) #ifndef CONFIG_USER_ONLY use_new &=3D b <=3D limit; #endif - if (use_new && b <=3D 0x5f) { + if (use_new && b <=3D 0xbf) { disas_insn_new(s, cpu, b); return true; } @@ -3675,20 +3693,7 @@ static bool disas_insn(DisasContext *s, CPUState *cp= u) gen_op_ld_v(s, ot, s->T1, s->A0); gen_add_A0_im(s, 1 << ot); gen_op_ld_v(s, MO_16, s->T0, s->A0); - do_lcall: - if (PE(s) && !VM86(s)) { - tcg_gen_trunc_tl_i32(s->tmp2_i32, s->T0); - gen_helper_lcall_protected(tcg_env, s->tmp2_i32, s->T1, - tcg_constant_i32(dflag - 1), - eip_next_tl(s)); - } else { - tcg_gen_trunc_tl_i32(s->tmp2_i32, s->T0); - tcg_gen_trunc_tl_i32(s->tmp3_i32, s->T1); - gen_helper_lcall_real(tcg_env, s->tmp2_i32, s->tmp3_i32, - tcg_constant_i32(dflag - 1), - eip_next_i32(s)); - } - s->base.is_jmp =3D DISAS_JUMP; + gen_far_call(s); break; case 4: /* jmp Ev */ if (dflag =3D=3D MO_16) { @@ -5200,7 +5205,8 @@ static bool disas_insn(DisasContext *s, CPUState *cpu) tcg_gen_movi_tl(s->T0, selector); tcg_gen_movi_tl(s->T1, offset); } - goto do_lcall; + gen_far_call(s); + break; case 0xe9: /* jmp im */ { int diff =3D (dflag !=3D MO_16 --=20 2.41.0 From nobody Wed Nov 27 15:47:24 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=1697712621; cv=none; d=zohomail.com; s=zohoarc; b=QYpqcupfmFnZofk/L2ZUyjo1m+8TD7Io2tZjL/oeV/2PaMOdRvUUYrW52g603S3Y6IaM2i/+llMNyqNcag2RIZB1qDLPvxgUqQI2diA3OeCK4Mw/mEwzNUcA5bEqGKqmbSSRRBSbKMw+aL1l1f2lS5rIp7lgchz14v8qJ7vFi8M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697712621; 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=qsD5wtu/TdqXR+WQTdnduyQC76Rdt0pgpfqmcEbH0mI=; b=Ehpryu9LrfxI/60op4X689VcqiUxdS1jYKeYp1ydcZFMDt8jr+ajIBTxc+keKlz/bTc+PCHpNRpwcfd52tuwlrcVnSzNvY6/fACxzYJPSwVR1GXnMnfkrr6U0hDthnyz3SBUeiZP9+YLrW9HpLtTHd1tkS8T3dAGE9NNzWb4Y0w= 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 1697712621149785.6850164598118; Thu, 19 Oct 2023 03:50:21 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qtQZe-00017A-Mo; Thu, 19 Oct 2023 06:48:18 -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 1qtQZc-00010H-UA for qemu-devel@nongnu.org; Thu, 19 Oct 2023 06:48:16 -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 1qtQZb-00074Q-BX for qemu-devel@nongnu.org; Thu, 19 Oct 2023 06:48:16 -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-455-o7CZbpLmNV66WU90zsmCjA-1; Thu, 19 Oct 2023 06:48:12 -0400 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-9c749c28651so124065466b.0 for ; Thu, 19 Oct 2023 03:48:12 -0700 (PDT) Received: from [192.168.10.118] ([2001:b07:6468:f312:5e2c:eb9a:a8b6:fd3e]) by smtp.gmail.com with ESMTPSA id a15-20020a170906684f00b00997d7aa59fasm3371501ejs.14.2023.10.19.03.48.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 03:48:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697712494; 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=qsD5wtu/TdqXR+WQTdnduyQC76Rdt0pgpfqmcEbH0mI=; b=HdI7qS/qCQfcvAEtD1Dbe6p2V9pYiEIAkK2hf0x/X3syz3fgFFvYKJYD34zJCLfWUPVh8h fvwgDlFHIHnZswKLc+MZLSukvD90qBcWkpMb3vKzfTzPQ5ol8y3Frc8RSCGcnkM6DsKdi+ ZI6NQ58Tk1o37gZf3KTN0/cNaCNewIA= X-MC-Unique: o7CZbpLmNV66WU90zsmCjA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697712491; x=1698317291; 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=qsD5wtu/TdqXR+WQTdnduyQC76Rdt0pgpfqmcEbH0mI=; b=ql1yWALldcMs+72leS3qiP2Ba9OwhiKw5yUgNvJZIlwCpmCx90K34Nbe3JQ0Bd12n2 FE4ayJZDRcdmgsXZXJ+UAhpXVXIAVxyvfMq9FAve2Xs/eixrpnX59ceJbGPLZNhWXJES W1X+AfSseDeTNnWHoQgq7YNoc4VAq9zG79zVmW2peaHSTtFyQHrlhHaqUsZpFaoTWr4o 7pIpEaAAvpaXUqmZRxw43nG5hvG6GehZ2bJtV+Hxspfdu8Afi+QHsFD/1Bd7A0uMsgov wJRMg3I2nTuOOgzRgKJNwjpvH1D+P15MryF0xaDF1gAvvfgs06V6ZPCp0XRT6QtWwns7 5VMA== X-Gm-Message-State: AOJu0YwapFvQ6KVRjJv5BCHzUknS8yBO4gG6ZEcEVmHg4Y3W+clKs5/W exINijt3OrPlclQM/wonjN9DN1ZVyD8iBx897mLUZPQ6EPbfwu9EGuR+oPhxfpincO3N434LQCB nGtsQWLjnCXw1ND74kUAeIfFgATv8FqAgvOUUYv8CCADPqShkB5iXXXXamNJCH4xfJ9v3TuVmkh I= X-Received: by 2002:a17:907:2cc4:b0:9a1:c991:a521 with SMTP id hg4-20020a1709072cc400b009a1c991a521mr1340954ejc.4.1697712490986; Thu, 19 Oct 2023 03:48:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH56xMRwCPRo5trlv9K71mRSwMEkMwuTHovGdi4o0YkH5GZQetquo40Gg208Wzir9MlkAI9DQ== X-Received: by 2002:a17:907:2cc4:b0:9a1:c991:a521 with SMTP id hg4-20020a1709072cc400b009a1c991a521mr1340944ejc.4.1697712490569; Thu, 19 Oct 2023 03:48:10 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH v2 16/19] target/i386: move operand load and writeback out of gen_cmovcc1 Date: Thu, 19 Oct 2023 12:48:04 +0200 Message-ID: <20231019104807.390468-2-pbonzini@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231019104648.389942-1-pbonzini@redhat.com> References: <20231019104648.389942-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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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 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: 1697712621906100002 Content-Type: text/plain; charset="utf-8" Similar to gen_setcc1, make gen_cmovcc1 receive TCGv. This is more friendly to simultaneous implementation in the old and the new decoder. A small wart is that s->T0 of CMOV is currently the *second* argument (which would ordinarily be in T1). Therefore, the condition as to be inverted in order to overwrite s->T0 with cpu_regs[reg] if the MOV is not performed. This only applies to the old decoder, and this code will go away soon. Signed-off-by: Paolo Bonzini --- target/i386/tcg/translate.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index 9c799b5a980..2c4e680a69e 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -2503,26 +2503,20 @@ static void gen_jcc(DisasContext *s, int b, int dif= f) gen_jmp_rel(s, s->dflag, diff, 0); } =20 -static void gen_cmovcc1(CPUX86State *env, DisasContext *s, MemOp ot, int b, - int modrm, int reg) +static void gen_cmovcc1(DisasContext *s, int b, TCGv dest, TCGv src) { CCPrepare cc; =20 - gen_ldst_modrm(env, s, modrm, ot, OR_TMP0, 0); - - cc =3D gen_prepare_cc(s, b, s->T1); + cc =3D gen_prepare_cc(s, b, s->tmp4); if (cc.mask !=3D -1) { - TCGv t0 =3D tcg_temp_new(); - tcg_gen_andi_tl(t0, cc.reg, cc.mask); - cc.reg =3D t0; + tcg_gen_andi_tl(s->tmp4, cc.reg, cc.mask); + cc.reg =3D s->tmp4; } if (!cc.use_reg2) { cc.reg2 =3D tcg_constant_tl(cc.imm); } =20 - tcg_gen_movcond_tl(cc.cond, s->T0, cc.reg, cc.reg2, - s->T0, cpu_regs[reg]); - gen_op_mov_reg_v(s, ot, reg, s->T0); + tcg_gen_movcond_tl(cc.cond, dest, cc.reg, cc.reg2, src, dest); } =20 static inline void gen_op_movl_T0_seg(DisasContext *s, X86Seg seg_reg) @@ -5265,7 +5259,9 @@ static bool disas_insn(DisasContext *s, CPUState *cpu) ot =3D dflag; modrm =3D x86_ldub_code(env, s); reg =3D ((modrm >> 3) & 7) | REX_R(s); - gen_cmovcc1(env, s, ot, b, modrm, reg); + gen_ldst_modrm(env, s, modrm, ot, OR_TMP0, 0); + gen_cmovcc1(s, b ^ 1, s->T0, cpu_regs[reg]); + gen_op_mov_reg_v(s, ot, reg, s->T0); break; =20 /************************/ --=20 2.41.0 From nobody Wed Nov 27 15:47:24 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=1697712569; cv=none; d=zohomail.com; s=zohoarc; b=Cwn0bpwlNfUz1TMeFIDKoyCwk/v98+SBhQcyMMj9bYoNGUjQD2mHBN4a5NYsnoFfPkdxuixCF/N86QhT3CVtLX/5kulMPZIXqzn1LoGC+2fhSzp1oiyKCvRpAjZHVGJUKzqZ4KJpFwz8b+eIl+J9gJ4vEdsWq7S00FUuiUO++dM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697712569; 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=KKRW9tHQ+kKiTYSl3ooxciwBclSit6L0VzHpjcZmQA8=; b=Pi2mTS0Fi44tN1Ma+0qoZJkHOde1YUBSX4PVF4dA4a0c5k113B4MzBmJlU5RJbqguCkxlPlay0rIOBDT9fnE42T6ureezzPvK6p7wzsYQ3QchxCSdZRxgbGrUS6WIK1gZ3W9PqxEXd0xzczl8I1opyGlhS4bVspQ/uocqPLOvCQ= 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 1697712569141282.1289074593973; Thu, 19 Oct 2023 03:49:29 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qtQZg-0001Gk-Gr; Thu, 19 Oct 2023 06:48:20 -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 1qtQZe-000177-Hz for qemu-devel@nongnu.org; Thu, 19 Oct 2023 06:48:18 -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 1qtQZb-00074W-V6 for qemu-devel@nongnu.org; Thu, 19 Oct 2023 06:48:18 -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-459-GuavpYG3N9Su_MBa_6_u8Q-1; Thu, 19 Oct 2023 06:48:13 -0400 Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-9bd91ce3033so530778466b.0 for ; Thu, 19 Oct 2023 03:48:13 -0700 (PDT) Received: from [192.168.10.118] ([2001:b07:6468:f312:5e2c:eb9a:a8b6:fd3e]) by smtp.gmail.com with ESMTPSA id b5-20020a1709062b4500b0099297782aa9sm3272343ejg.49.2023.10.19.03.48.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 03:48:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697712495; 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=KKRW9tHQ+kKiTYSl3ooxciwBclSit6L0VzHpjcZmQA8=; b=QSS1NVrux3JzIN4hVncpQq9khNNz8DxWvdOky9bhqwS3btvdmYZZXMMY1v+UROPOGqiKMz V5xtEq2sBeNGONaCoJTQbJqmyH724QYdtIYcXkftWN1VgZhDYAuLyoDYX0Y+ShdsPafBjC DvQYtuha7nWNMSByAH63QbvCoBSWUbI= X-MC-Unique: GuavpYG3N9Su_MBa_6_u8Q-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697712492; x=1698317292; 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=KKRW9tHQ+kKiTYSl3ooxciwBclSit6L0VzHpjcZmQA8=; b=W1mSKGlfp/VypJnAnTuUtvu5ciStcbseKBj7AbMCJv9/f95E0HmwCM+2GusE9jHrf4 glEbQ8NeVt+so4bASbjhzDk6u/nUnms6lLhKsBSuCKKatz5SquXEauZh8okUjC0IsU0s 5r7Frp+2ytwdhphvxGeJU6ZW2IomhIPuIevKpepj+yFHpfYlpp8TFU5GliIU/dYF0W5N xRvMI28oKyVySVbay2TDuXb/JKD+CYZJOX+n3wwGfZUfmkBTjoXT/Yd1HywohS3yQ40z Q9P6ruBybQSHLKz+mHoYv06OoymKxXdcnjG6D8/x1EtllZVrxCr6Wzi3RWiYReD1QKBt pMYA== X-Gm-Message-State: AOJu0Yyoc7jpHs+KSK59S2vUR5fNnVh1nSFfxtLFeWhQVPuI96935L/N eZjsaoH9+eqqzvwvPhs0iZChEiSLDkjS1pjxShuo5EXUoz/zkZhh6HkJERkHRUhGGhmIlOrxLsQ Ho6ABODWxGRTZ9+7yqGWW61FVWXjymCgWku/jh741WMj952Qx0a8dsWqa1453rxQGFyWETPu5QT o= X-Received: by 2002:a17:907:c16:b0:9ae:56da:6068 with SMTP id ga22-20020a1709070c1600b009ae56da6068mr1462020ejc.57.1697712492267; Thu, 19 Oct 2023 03:48:12 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHWVJX0cVHDjtBovShecgySY+GnSNhB50tMah6Ktril1i2IzXK/XxG/8jiMIRLmI9UlJskGyw== X-Received: by 2002:a17:907:c16:b0:9ae:56da:6068 with SMTP id ga22-20020a1709070c1600b009ae56da6068mr1462006ejc.57.1697712491905; Thu, 19 Oct 2023 03:48:11 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH v2 17/19] target/i386: move remaining conditional operations to new decoder Date: Thu, 19 Oct 2023 12:48:05 +0200 Message-ID: <20231019104807.390468-3-pbonzini@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231019104648.389942-1-pbonzini@redhat.com> References: <20231019104648.389942-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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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 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: 1697712569730100001 Content-Type: text/plain; charset="utf-8" Move long-displacement Jcc, SETcc and CMOVcc to the new decoder. While filling in the tables makes the code seem longer, the new emitters are all just one line of code. Signed-off-by: Paolo Bonzini --- target/i386/tcg/decode-new.c.inc | 56 ++++++++++++++++++++++++++++++++ target/i386/tcg/decode-new.h | 1 + target/i386/tcg/emit.c.inc | 10 ++++++ target/i386/tcg/translate.c | 4 ++- 4 files changed, 70 insertions(+), 1 deletion(-) diff --git a/target/i386/tcg/decode-new.c.inc b/target/i386/tcg/decode-new.= c.inc index d0baf972208..e68f5ae068e 100644 --- a/target/i386/tcg/decode-new.c.inc +++ b/target/i386/tcg/decode-new.c.inc @@ -944,6 +944,15 @@ static const X86OpEntry opcodes_0F[256] =3D { /* Incorrectly listed as Mq,Vq in the manual */ [0x17] =3D X86_OP_ENTRY3(VMOVHPx_st, M,q, None,None, V,dq, vex5 p_00_= 66), =20 + [0x40] =3D X86_OP_ENTRY2(CMOVcc, G,v, E,v, cpuid(CMOV)), + [0x41] =3D X86_OP_ENTRY2(CMOVcc, G,v, E,v, cpuid(CMOV)), + [0x42] =3D X86_OP_ENTRY2(CMOVcc, G,v, E,v, cpuid(CMOV)), + [0x43] =3D X86_OP_ENTRY2(CMOVcc, G,v, E,v, cpuid(CMOV)), + [0x44] =3D X86_OP_ENTRY2(CMOVcc, G,v, E,v, cpuid(CMOV)), + [0x45] =3D X86_OP_ENTRY2(CMOVcc, G,v, E,v, cpuid(CMOV)), + [0x46] =3D X86_OP_ENTRY2(CMOVcc, G,v, E,v, cpuid(CMOV)), + [0x47] =3D X86_OP_ENTRY2(CMOVcc, G,v, E,v, cpuid(CMOV)), + [0x50] =3D X86_OP_ENTRY3(MOVMSK, G,y, None,None, U,x, vex7 p_00_66= ), [0x51] =3D X86_OP_GROUP3(sse_unary, V,x, H,x, W,x, vex2_rep3 p_00_66_= f3_f2), /* sqrtps */ [0x52] =3D X86_OP_GROUP3(sse_unary, V,x, H,x, W,x, vex4_rep5 p_00_f3)= , /* rsqrtps */ @@ -971,6 +980,24 @@ static const X86OpEntry opcodes_0F[256] =3D { [0x76] =3D X86_OP_ENTRY3(PCMPEQD, V,x, H,x, W,x, vex4 mmx avx2_256= p_00_66), [0x77] =3D X86_OP_GROUP0(0F77), =20 + [0x80] =3D X86_OP_ENTRYr(Jcc, J,z), + [0x81] =3D X86_OP_ENTRYr(Jcc, J,z), + [0x82] =3D X86_OP_ENTRYr(Jcc, J,z), + [0x83] =3D X86_OP_ENTRYr(Jcc, J,z), + [0x84] =3D X86_OP_ENTRYr(Jcc, J,z), + [0x85] =3D X86_OP_ENTRYr(Jcc, J,z), + [0x86] =3D X86_OP_ENTRYr(Jcc, J,z), + [0x87] =3D X86_OP_ENTRYr(Jcc, J,z), + + [0x90] =3D X86_OP_ENTRYw(SETcc, E,b), + [0x91] =3D X86_OP_ENTRYw(SETcc, E,b), + [0x92] =3D X86_OP_ENTRYw(SETcc, E,b), + [0x93] =3D X86_OP_ENTRYw(SETcc, E,b), + [0x94] =3D X86_OP_ENTRYw(SETcc, E,b), + [0x95] =3D X86_OP_ENTRYw(SETcc, E,b), + [0x96] =3D X86_OP_ENTRYw(SETcc, E,b), + [0x97] =3D X86_OP_ENTRYw(SETcc, E,b), + [0x28] =3D X86_OP_ENTRY3(MOVDQ, V,x, None,None, W,x, vex1 p_00_6= 6), /* MOVAPS */ [0x29] =3D X86_OP_ENTRY3(MOVDQ, W,x, None,None, V,x, vex1 p_00_6= 6), /* MOVAPS */ [0x2A] =3D X86_OP_GROUP0(0F2A), @@ -983,6 +1010,15 @@ static const X86OpEntry opcodes_0F[256] =3D { [0x38] =3D X86_OP_GROUP0(0F38), [0x3a] =3D X86_OP_GROUP0(0F3A), =20 + [0x48] =3D X86_OP_ENTRY2(CMOVcc, G,v, E,v, cpuid(CMOV)), + [0x49] =3D X86_OP_ENTRY2(CMOVcc, G,v, E,v, cpuid(CMOV)), + [0x4a] =3D X86_OP_ENTRY2(CMOVcc, G,v, E,v, cpuid(CMOV)), + [0x4b] =3D X86_OP_ENTRY2(CMOVcc, G,v, E,v, cpuid(CMOV)), + [0x4c] =3D X86_OP_ENTRY2(CMOVcc, G,v, E,v, cpuid(CMOV)), + [0x4d] =3D X86_OP_ENTRY2(CMOVcc, G,v, E,v, cpuid(CMOV)), + [0x4e] =3D X86_OP_ENTRY2(CMOVcc, G,v, E,v, cpuid(CMOV)), + [0x4f] =3D X86_OP_ENTRY2(CMOVcc, G,v, E,v, cpuid(CMOV)), + [0x58] =3D X86_OP_ENTRY3(VADD, V,x, H,x, W,x, vex2_rep3 p_00_66_= f3_f2), [0x59] =3D X86_OP_ENTRY3(VMUL, V,x, H,x, W,x, vex2_rep3 p_00_66_= f3_f2), [0x5a] =3D X86_OP_GROUP0(0F5A), @@ -1008,6 +1044,24 @@ static const X86OpEntry opcodes_0F[256] =3D { [0x7e] =3D X86_OP_GROUP0(0F7E), [0x7f] =3D X86_OP_GROUP0(0F7F), =20 + [0x88] =3D X86_OP_ENTRYr(Jcc, J,z), + [0x89] =3D X86_OP_ENTRYr(Jcc, J,z), + [0x8a] =3D X86_OP_ENTRYr(Jcc, J,z), + [0x8b] =3D X86_OP_ENTRYr(Jcc, J,z), + [0x8c] =3D X86_OP_ENTRYr(Jcc, J,z), + [0x8d] =3D X86_OP_ENTRYr(Jcc, J,z), + [0x8e] =3D X86_OP_ENTRYr(Jcc, J,z), + [0x8f] =3D X86_OP_ENTRYr(Jcc, J,z), + + [0x98] =3D X86_OP_ENTRYw(SETcc, E,b), + [0x99] =3D X86_OP_ENTRYw(SETcc, E,b), + [0x9a] =3D X86_OP_ENTRYw(SETcc, E,b), + [0x9b] =3D X86_OP_ENTRYw(SETcc, E,b), + [0x9c] =3D X86_OP_ENTRYw(SETcc, E,b), + [0x9d] =3D X86_OP_ENTRYw(SETcc, E,b), + [0x9e] =3D X86_OP_ENTRYw(SETcc, E,b), + [0x9f] =3D X86_OP_ENTRYw(SETcc, E,b), + [0xae] =3D X86_OP_GROUP0(group15), =20 [0xc2] =3D X86_OP_ENTRY4(VCMP, V,x, H,x, W,x, vex2_rep3 p_= 00_66_f3_f2), @@ -1743,6 +1797,8 @@ static bool has_cpuid_feature(DisasContext *s, X86CPU= IDFeature cpuid) switch (cpuid) { case X86_FEAT_None: return true; + case X86_FEAT_CMOV: + return (s->cpuid_features & CPUID_CMOV); case X86_FEAT_F16C: return (s->cpuid_ext_features & CPUID_EXT_F16C); case X86_FEAT_FMA: diff --git a/target/i386/tcg/decode-new.h b/target/i386/tcg/decode-new.h index 32396630865..119de3bf342 100644 --- a/target/i386/tcg/decode-new.h +++ b/target/i386/tcg/decode-new.h @@ -105,6 +105,7 @@ typedef enum X86CPUIDFeature { X86_FEAT_AVX2, X86_FEAT_BMI1, X86_FEAT_BMI2, + X86_FEAT_CMOV, X86_FEAT_CMPCCXADD, X86_FEAT_F16C, X86_FEAT_FMA, diff --git a/target/i386/tcg/emit.c.inc b/target/i386/tcg/emit.c.inc index 267f4fe383a..05e1fb16844 100644 --- a/target/i386/tcg/emit.c.inc +++ b/target/i386/tcg/emit.c.inc @@ -1636,6 +1636,16 @@ static void gen_Jcc(DisasContext *s, CPUX86State *en= v, X86DecodedInsn *decode) gen_jcc(s, decode->b & 0xf, decode->immediate); } =20 +static void gen_SETcc(DisasContext *s, CPUX86State *env, X86DecodedInsn *d= ecode) +{ + gen_setcc1(s, decode->b & 0xf, s->T0); +} + +static void gen_CMOVcc(DisasContext *s, CPUX86State *env, X86DecodedInsn *= decode) +{ + gen_cmovcc1(s, decode->b & 0xf, s->T0, s->T1); +} + static void gen_LAHF(DisasContext *s, CPUX86State *env, X86DecodedInsn *de= code) { if (CODE64(s) && !(s->cpuid_ext3_features & CPUID_EXT3_LAHF_LM)) { diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index 2c4e680a69e..1f3cc6361c0 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -3186,7 +3186,9 @@ static bool disas_insn(DisasContext *s, CPUState *cpu) #ifndef CONFIG_USER_ONLY use_new &=3D b <=3D limit; #endif - if (use_new && 0) { + if (use_new && + ((b >=3D 0x140 && b <=3D 0x14f) || + (b >=3D 0x180 && b <=3D 0x19f))) { disas_insn_new(s, cpu, b); return true; } --=20 2.41.0 From nobody Wed Nov 27 15:47:24 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=1697712634; cv=none; d=zohomail.com; s=zohoarc; b=VedGDAFOtveTpfgeJmH0iuba6pwzfWy998SyYrjuTwzemxY6RtbJGfIPoyTbOBqNjZrzeVUX3c03wxnPhGRa3IKTV2e1wYmS92ctZCllrg9OL4do7WGraAARtxcPImV2jeIw4NCouZWsS6CSuuJgBjnIC7R8Kz28y6HVhwSwQ8E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697712634; 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=Nhn1J+V0Lp+hXlSmkE2LXj8IpgJGlbfgLmItrRofT44=; b=RkAcr1uHOuny0VyzrWkLo4TSMrk0lc8ge7kdpQfqqsXtTk+PwEGmzKu2ARkBLB4VicgjN8r17q0W8tIyOzfaeukvFM3uj373fJP9S8GgbR+F2gx0PIrxQr9pXLCPpwIIeS/hOCaOlOTpvMCywW0I3dMNNhHv+b9DhN+DqR9MQUE= 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 1697712634072834.3964879567045; Thu, 19 Oct 2023 03:50:34 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qtQZj-0001Uo-Ha; Thu, 19 Oct 2023 06:48:23 -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 1qtQZh-0001Pc-M2 for qemu-devel@nongnu.org; Thu, 19 Oct 2023 06:48:21 -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 1qtQZe-00074t-L6 for qemu-devel@nongnu.org; Thu, 19 Oct 2023 06:48:21 -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-193-APoqjbsoMCat9JkfMvOIPw-1; Thu, 19 Oct 2023 06:48:16 -0400 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-9b98d8f6bafso581929666b.1 for ; Thu, 19 Oct 2023 03:48:16 -0700 (PDT) Received: from [192.168.10.118] ([2001:b07:6468:f312:5e2c:eb9a:a8b6:fd3e]) by smtp.gmail.com with ESMTPSA id kj4-20020a170907764400b009b928eb8dd3sm3294301ejc.163.2023.10.19.03.48.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 03:48:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697712497; 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=Nhn1J+V0Lp+hXlSmkE2LXj8IpgJGlbfgLmItrRofT44=; b=ccFrnHU3NtU7UmZ54yV20R8YkjLn0fZiec44ONk069002oDFvSpWiY+PGAlVHPauWm0FxX tIt/Ypl74pA05UWFtX4vCbkONTKGyOi+auHPJfMljtF+u8ed7EvOgKZbc9o2j4aWPSuTRA C+MECJJkUxcY3pWhPdEgD93xoLMJIxE= X-MC-Unique: APoqjbsoMCat9JkfMvOIPw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697712495; x=1698317295; 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=Nhn1J+V0Lp+hXlSmkE2LXj8IpgJGlbfgLmItrRofT44=; b=Cb2vi9OANaksfAfFZrUFltSi2u2vN6ktmnZR0TPtXZl3KyqTd4/VjrzAUDoQfHib5n cxGofiRiVPS1Zo7cINCAgV6EisF8O2lPj2tHaK6OBt9VN1z0/g3aj3rNat3V2c11B47R Tz634Vd7o6yQrfoVlyPdemOPidALm/4R+b/nFWHGGRTakpN9/rVYdA4FwiOxHVM+xE0h hV3RHObdm5RDP1qhQZFINoOCsVcz/INhHoZ53DTpAQEULrIWohDgdbULUsvxpkFRaAhj V12vRy7DcoaCeyJk2Nq2AvpVpLTTbbZBZi0Vian3oOns5+0zKSn5vNjVOu4fB4zYCNXH XxLw== X-Gm-Message-State: AOJu0Yxx+bH/8b1NLZg5PDpVaGsHvNgbdZSSy5S7ybWWUqrFIoEpMS3x qdl/7QxaGXWIWRcPUw+1OsUg3AdlAp6jEwgBYlDHxE1KNRVdnYsAyy3wqxSFTghx0MDiKmlFLCb o+YLJr1SimLmDPmN8xvou65lNdu8laonQHTXyFko+hJDUIGmWUAUTAxFSw3W3BXhWlpuLhlZjUr g= X-Received: by 2002:a17:907:7f9f:b0:9bf:4915:22c7 with SMTP id qk31-20020a1709077f9f00b009bf491522c7mr1442889ejc.55.1697712494637; Thu, 19 Oct 2023 03:48:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEF70PeWBQy8bpgWyv5dFW387LotvpD+KUIotxuzWKb3ytVZYXMKwJYegcW8QUCFKA3ZWY/0w== X-Received: by 2002:a17:907:7f9f:b0:9bf:4915:22c7 with SMTP id qk31-20020a1709077f9f00b009bf491522c7mr1442864ejc.55.1697712493777; Thu, 19 Oct 2023 03:48:13 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH v2 18/19] target/i386: remove now converted opcodes from old decoder Date: Thu, 19 Oct 2023 12:48:06 +0200 Message-ID: <20231019104807.390468-4-pbonzini@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231019104648.389942-1-pbonzini@redhat.com> References: <20231019104648.389942-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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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 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: 1697712635970100003 Content-Type: text/plain; charset="utf-8" Signed-off-by: Paolo Bonzini --- target/i386/tcg/translate.c | 705 +----------------------------------- 1 file changed, 4 insertions(+), 701 deletions(-) diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index 1f3cc6361c0..6e091fdb7f6 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -3176,7 +3176,7 @@ static bool disas_insn(DisasContext *s, CPUState *cpu) #ifndef CONFIG_USER_ONLY use_new &=3D b <=3D limit; #endif - if (use_new && b <=3D 0xbf) { + if (use_new && 0) { disas_insn_new(s, cpu, b); return true; } @@ -3186,9 +3186,7 @@ static bool disas_insn(DisasContext *s, CPUState *cpu) #ifndef CONFIG_USER_ONLY use_new &=3D b <=3D limit; #endif - if (use_new && - ((b >=3D 0x140 && b <=3D 0x14f) || - (b >=3D 0x180 && b <=3D 0x19f))) { + if (use_new && 0) { disas_insn_new(s, cpu, b); return true; } @@ -3289,119 +3287,6 @@ static bool disas_insn(DisasContext *s, CPUState *c= pu) switch (b) { /**************************/ /* arith & logic */ - case 0x00 ... 0x05: - case 0x08 ... 0x0d: - case 0x10 ... 0x15: - case 0x18 ... 0x1d: - case 0x20 ... 0x25: - case 0x28 ... 0x2d: - case 0x30 ... 0x35: - case 0x38 ... 0x3d: - { - int f; - op =3D (b >> 3) & 7; - f =3D (b >> 1) & 3; - - ot =3D mo_b_d(b, dflag); - - switch(f) { - case 0: /* OP Ev, Gv */ - 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); - if (mod !=3D 3) { - gen_lea_modrm(env, s, modrm); - opreg =3D OR_TMP0; - } else if (op =3D=3D OP_XORL && rm =3D=3D reg) { - xor_zero: - /* xor reg, reg optimisation */ - set_cc_op(s, CC_OP_CLR); - tcg_gen_movi_tl(s->T0, 0); - gen_op_mov_reg_v(s, ot, reg, s->T0); - break; - } else { - opreg =3D rm; - } - gen_op_mov_v_reg(s, ot, s->T1, reg); - gen_op(s, op, ot, opreg); - break; - case 1: /* OP Gv, Ev */ - modrm =3D x86_ldub_code(env, s); - mod =3D (modrm >> 6) & 3; - reg =3D ((modrm >> 3) & 7) | REX_R(s); - rm =3D (modrm & 7) | REX_B(s); - if (mod !=3D 3) { - gen_lea_modrm(env, s, modrm); - gen_op_ld_v(s, ot, s->T1, s->A0); - } else if (op =3D=3D OP_XORL && rm =3D=3D reg) { - goto xor_zero; - } else { - gen_op_mov_v_reg(s, ot, s->T1, rm); - } - gen_op(s, op, ot, reg); - break; - case 2: /* OP A, Iv */ - val =3D insn_get(env, s, ot); - tcg_gen_movi_tl(s->T1, val); - gen_op(s, op, ot, OR_EAX); - break; - } - } - break; - - case 0x82: - if (CODE64(s)) - goto illegal_op; - /* fall through */ - case 0x80: /* GRP1 */ - case 0x81: - case 0x83: - { - ot =3D mo_b_d(b, dflag); - - modrm =3D x86_ldub_code(env, s); - mod =3D (modrm >> 6) & 3; - rm =3D (modrm & 7) | REX_B(s); - op =3D (modrm >> 3) & 7; - - if (mod !=3D 3) { - if (b =3D=3D 0x83) - s->rip_offset =3D 1; - else - s->rip_offset =3D insn_const_size(ot); - gen_lea_modrm(env, s, modrm); - opreg =3D OR_TMP0; - } else { - opreg =3D rm; - } - - switch(b) { - default: - case 0x80: - case 0x81: - case 0x82: - val =3D insn_get(env, s, ot); - break; - case 0x83: - val =3D (int8_t)insn_get(env, s, MO_8); - break; - } - tcg_gen_movi_tl(s->T1, val); - gen_op(s, op, ot, opreg); - } - break; - - /**************************/ - /* inc, dec, and other misc arith */ - case 0x40 ... 0x47: /* inc Gv */ - ot =3D dflag; - gen_inc(s, ot, OR_EAX + (b & 7), 1); - break; - case 0x48 ... 0x4f: /* dec Gv */ - ot =3D dflag; - gen_inc(s, ot, OR_EAX + (b & 7), -1); - break; case 0xf6: /* GRP3 */ case 0xf7: ot =3D mo_b_d(b, dflag); @@ -3725,81 +3610,7 @@ static bool disas_insn(DisasContext *s, CPUState *cp= u) } break; =20 - case 0x84: /* test Ev, Gv */ - case 0x85: - ot =3D mo_b_d(b, dflag); - - modrm =3D x86_ldub_code(env, s); - reg =3D ((modrm >> 3) & 7) | REX_R(s); - - gen_ldst_modrm(env, s, modrm, ot, OR_TMP0, 0); - gen_op_mov_v_reg(s, ot, s->T1, reg); - gen_op_testl_T0_T1_cc(s); - set_cc_op(s, CC_OP_LOGICB + ot); - break; - - case 0xa8: /* test eAX, Iv */ - case 0xa9: - ot =3D mo_b_d(b, dflag); - val =3D insn_get(env, s, ot); - - gen_op_mov_v_reg(s, ot, s->T0, OR_EAX); - tcg_gen_movi_tl(s->T1, val); - gen_op_testl_T0_T1_cc(s); - set_cc_op(s, CC_OP_LOGICB + ot); - break; - - case 0x98: /* CWDE/CBW */ - switch (dflag) { -#ifdef TARGET_X86_64 - case MO_64: - gen_op_mov_v_reg(s, MO_32, s->T0, R_EAX); - tcg_gen_ext32s_tl(s->T0, s->T0); - gen_op_mov_reg_v(s, MO_64, R_EAX, s->T0); - break; -#endif - case MO_32: - gen_op_mov_v_reg(s, MO_16, s->T0, R_EAX); - tcg_gen_ext16s_tl(s->T0, s->T0); - gen_op_mov_reg_v(s, MO_32, R_EAX, s->T0); - break; - case MO_16: - gen_op_mov_v_reg(s, MO_8, s->T0, R_EAX); - tcg_gen_ext8s_tl(s->T0, s->T0); - gen_op_mov_reg_v(s, MO_16, R_EAX, s->T0); - break; - default: - g_assert_not_reached(); - } - break; - case 0x99: /* CDQ/CWD */ - switch (dflag) { -#ifdef TARGET_X86_64 - case MO_64: - gen_op_mov_v_reg(s, MO_64, s->T0, R_EAX); - tcg_gen_sari_tl(s->T0, s->T0, 63); - gen_op_mov_reg_v(s, MO_64, R_EDX, s->T0); - break; -#endif - case MO_32: - gen_op_mov_v_reg(s, MO_32, s->T0, R_EAX); - tcg_gen_ext32s_tl(s->T0, s->T0); - tcg_gen_sari_tl(s->T0, s->T0, 31); - gen_op_mov_reg_v(s, MO_32, R_EDX, s->T0); - break; - case MO_16: - gen_op_mov_v_reg(s, MO_16, s->T0, R_EAX); - tcg_gen_ext16s_tl(s->T0, s->T0); - tcg_gen_sari_tl(s->T0, s->T0, 15); - gen_op_mov_reg_v(s, MO_16, R_EDX, s->T0); - break; - default: - g_assert_not_reached(); - } - break; case 0x1af: /* imul Gv, Ev */ - case 0x69: /* imul Gv, Ev, I */ - case 0x6b: ot =3D dflag; modrm =3D x86_ldub_code(env, s); reg =3D ((modrm >> 3) & 7) | REX_R(s); @@ -4008,53 +3819,6 @@ static bool disas_insn(DisasContext *s, CPUState *cp= u) =20 /**************************/ /* push/pop */ - case 0x50 ... 0x57: /* push */ - gen_op_mov_v_reg(s, MO_32, s->T0, (b & 7) | REX_B(s)); - gen_push_v(s, s->T0); - break; - case 0x58 ... 0x5f: /* pop */ - ot =3D gen_pop_T0(s); - /* NOTE: order is important for pop %sp */ - gen_pop_update(s, ot); - gen_op_mov_reg_v(s, ot, (b & 7) | REX_B(s), s->T0); - break; - case 0x60: /* pusha */ - if (CODE64(s)) - goto illegal_op; - gen_pusha(s); - break; - case 0x61: /* popa */ - if (CODE64(s)) - goto illegal_op; - gen_popa(s); - break; - case 0x68: /* push Iv */ - case 0x6a: - ot =3D mo_pushpop(s, dflag); - if (b =3D=3D 0x68) - val =3D insn_get(env, s, ot); - else - val =3D (int8_t)insn_get(env, s, MO_8); - tcg_gen_movi_tl(s->T0, val); - gen_push_v(s, s->T0); - break; - case 0x8f: /* pop Ev */ - modrm =3D x86_ldub_code(env, s); - mod =3D (modrm >> 6) & 3; - ot =3D gen_pop_T0(s); - if (mod =3D=3D 3) { - /* NOTE: order is important for pop %sp */ - gen_pop_update(s, ot); - rm =3D (modrm & 7) | REX_B(s); - gen_op_mov_reg_v(s, ot, rm, s->T0); - } else { - /* NOTE: order is important too for MMU exceptions */ - s->popl_esp_hack =3D 1 << ot; - gen_ldst_modrm(env, s, modrm, ot, OR_TMP0, 1); - s->popl_esp_hack =3D 0; - gen_pop_update(s, ot); - } - break; case 0xc8: /* enter */ { int level; @@ -4066,30 +3830,11 @@ static bool disas_insn(DisasContext *s, CPUState *c= pu) case 0xc9: /* leave */ gen_leave(s); break; - case 0x06: /* push es */ - case 0x0e: /* push cs */ - case 0x16: /* push ss */ - case 0x1e: /* push ds */ - if (CODE64(s)) - goto illegal_op; - gen_op_movl_T0_seg(s, b >> 3); - gen_push_v(s, s->T0); - break; case 0x1a0: /* push fs */ case 0x1a8: /* push gs */ gen_op_movl_T0_seg(s, (b >> 3) & 7); gen_push_v(s, s->T0); break; - case 0x07: /* pop es */ - case 0x17: /* pop ss */ - case 0x1f: /* pop ds */ - if (CODE64(s)) - goto illegal_op; - reg =3D b >> 3; - ot =3D gen_pop_T0(s); - gen_movl_seg_T0(s, reg); - gen_pop_update(s, ot); - break; case 0x1a1: /* pop fs */ case 0x1a9: /* pop gs */ ot =3D gen_pop_T0(s); @@ -4099,15 +3844,6 @@ static bool disas_insn(DisasContext *s, CPUState *cp= u) =20 /**************************/ /* mov */ - case 0x88: - case 0x89: /* mov Gv, Ev */ - ot =3D mo_b_d(b, dflag); - modrm =3D x86_ldub_code(env, s); - reg =3D ((modrm >> 3) & 7) | REX_R(s); - - /* generate a generic store */ - gen_ldst_modrm(env, s, modrm, ot, reg, 1); - break; case 0xc6: case 0xc7: /* mov Ev, Iv */ ot =3D mo_b_d(b, dflag); @@ -4125,33 +3861,6 @@ static bool disas_insn(DisasContext *s, CPUState *cp= u) gen_op_mov_reg_v(s, ot, (modrm & 7) | REX_B(s), s->T0); } break; - case 0x8a: - case 0x8b: /* mov Ev, Gv */ - ot =3D mo_b_d(b, dflag); - modrm =3D x86_ldub_code(env, s); - reg =3D ((modrm >> 3) & 7) | REX_R(s); - - gen_ldst_modrm(env, s, modrm, ot, OR_TMP0, 0); - gen_op_mov_reg_v(s, ot, reg, s->T0); - break; - case 0x8e: /* mov seg, Gv */ - modrm =3D x86_ldub_code(env, s); - reg =3D (modrm >> 3) & 7; - if (reg >=3D 6 || reg =3D=3D R_CS) - goto illegal_op; - gen_ldst_modrm(env, s, modrm, MO_16, OR_TMP0, 0); - gen_movl_seg_T0(s, reg); - break; - case 0x8c: /* mov Gv, seg */ - modrm =3D x86_ldub_code(env, s); - reg =3D (modrm >> 3) & 7; - mod =3D (modrm >> 6) & 3; - if (reg >=3D 6) - goto illegal_op; - gen_op_movl_T0_seg(s, reg); - ot =3D mod =3D=3D 3 ? dflag : MO_16; - gen_ldst_modrm(env, s, modrm, ot, OR_TMP0, 1); - break; =20 case 0x1b6: /* movzbS Gv, Eb */ case 0x1b7: /* movzwS Gv, Eb */ @@ -4203,40 +3912,6 @@ static bool disas_insn(DisasContext *s, CPUState *cp= u) } break; =20 - case 0x8d: /* lea */ - modrm =3D x86_ldub_code(env, s); - mod =3D (modrm >> 6) & 3; - if (mod =3D=3D 3) - goto illegal_op; - reg =3D ((modrm >> 3) & 7) | REX_R(s); - { - 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, s->aflag, ea, -1, -1); - gen_op_mov_reg_v(s, dflag, reg, s->A0); - } - break; - - case 0xa0: /* mov EAX, Ov */ - case 0xa1: - case 0xa2: /* mov Ov, EAX */ - case 0xa3: - { - target_ulong offset_addr; - - ot =3D mo_b_d(b, dflag); - offset_addr =3D insn_get_addr(env, s, s->aflag); - tcg_gen_movi_tl(s->A0, offset_addr); - gen_add_A0_ds_seg(s); - if ((b & 2) =3D=3D 0) { - gen_op_ld_v(s, ot, s->T0, s->A0); - gen_op_mov_reg_v(s, ot, R_EAX, s->T0); - } else { - gen_op_mov_v_reg(s, ot, s->T0, R_EAX); - gen_op_st_v(s, ot, s->T0, s->A0); - } - } - break; case 0xd7: /* xlat */ tcg_gen_mov_tl(s->A0, cpu_regs[R_EBX]); tcg_gen_ext8u_tl(s->T0, cpu_regs[R_EAX]); @@ -4246,59 +3921,6 @@ static bool disas_insn(DisasContext *s, CPUState *cp= u) gen_op_ld_v(s, MO_8, s->T0, s->A0); gen_op_mov_reg_v(s, MO_8, R_EAX, s->T0); break; - case 0xb0 ... 0xb7: /* mov R, Ib */ - val =3D insn_get(env, s, MO_8); - tcg_gen_movi_tl(s->T0, val); - gen_op_mov_reg_v(s, MO_8, (b & 7) | REX_B(s), s->T0); - break; - case 0xb8 ... 0xbf: /* mov R, Iv */ -#ifdef TARGET_X86_64 - if (dflag =3D=3D MO_64) { - uint64_t tmp; - /* 64 bit case */ - tmp =3D x86_ldq_code(env, s); - reg =3D (b & 7) | REX_B(s); - tcg_gen_movi_tl(s->T0, tmp); - gen_op_mov_reg_v(s, MO_64, reg, s->T0); - } else -#endif - { - ot =3D dflag; - val =3D insn_get(env, s, ot); - reg =3D (b & 7) | REX_B(s); - tcg_gen_movi_tl(s->T0, val); - gen_op_mov_reg_v(s, ot, reg, s->T0); - } - break; - - case 0x91 ... 0x97: /* xchg R, EAX */ - do_xchg_reg_eax: - ot =3D dflag; - reg =3D (b & 7) | REX_B(s); - rm =3D R_EAX; - goto do_xchg_reg; - case 0x86: - case 0x87: /* xchg Ev, Gv */ - ot =3D mo_b_d(b, dflag); - modrm =3D x86_ldub_code(env, s); - reg =3D ((modrm >> 3) & 7) | REX_R(s); - mod =3D (modrm >> 6) & 3; - if (mod =3D=3D 3) { - rm =3D (modrm & 7) | REX_B(s); - do_xchg_reg: - gen_op_mov_v_reg(s, ot, s->T0, reg); - gen_op_mov_v_reg(s, ot, s->T1, rm); - gen_op_mov_reg_v(s, ot, rm, s->T0); - gen_op_mov_reg_v(s, ot, reg, s->T1); - } else { - gen_lea_modrm(env, s, modrm); - gen_op_mov_v_reg(s, ot, s->T0, reg); - /* for xchg, lock is implicit */ - tcg_gen_atomic_xchg_tl(s->T1, s->A0, s->T0, - s->mem_index, ot | MO_LE); - gen_op_mov_reg_v(s, ot, reg, s->T1); - } - break; case 0xc4: /* les Gv */ /* In CODE64 this is VEX3; see above. */ op =3D R_ES; @@ -4973,91 +4595,6 @@ static bool disas_insn(DisasContext *s, CPUState *cp= u) } } break; - /************************/ - /* string ops */ - - case 0xa4: /* movsS */ - case 0xa5: - ot =3D mo_b_d(b, dflag); - if (prefixes & (PREFIX_REPZ | PREFIX_REPNZ)) { - gen_repz_movs(s, ot); - } else { - gen_movs(s, ot); - } - break; - - case 0xaa: /* stosS */ - case 0xab: - ot =3D mo_b_d(b, dflag); - if (prefixes & (PREFIX_REPZ | PREFIX_REPNZ)) { - gen_repz_stos(s, ot); - } else { - gen_stos(s, ot); - } - break; - case 0xac: /* lodsS */ - case 0xad: - ot =3D mo_b_d(b, dflag); - if (prefixes & (PREFIX_REPZ | PREFIX_REPNZ)) { - gen_repz_lods(s, ot); - } else { - gen_lods(s, ot); - } - break; - case 0xae: /* scasS */ - case 0xaf: - ot =3D mo_b_d(b, dflag); - if (prefixes & PREFIX_REPNZ) { - gen_repz_scas(s, ot, 1); - } else if (prefixes & PREFIX_REPZ) { - gen_repz_scas(s, ot, 0); - } else { - gen_scas(s, ot); - } - break; - - case 0xa6: /* cmpsS */ - case 0xa7: - ot =3D mo_b_d(b, dflag); - if (prefixes & PREFIX_REPNZ) { - gen_repz_cmps(s, ot, 1); - } else if (prefixes & PREFIX_REPZ) { - gen_repz_cmps(s, ot, 0); - } else { - gen_cmps(s, ot); - } - break; - case 0x6c: /* insS */ - case 0x6d: - ot =3D mo_b_d32(b, dflag); - tcg_gen_trunc_tl_i32(s->tmp2_i32, cpu_regs[R_EDX]); - tcg_gen_ext16u_i32(s->tmp2_i32, s->tmp2_i32); - if (!gen_check_io(s, ot, s->tmp2_i32, - SVM_IOIO_TYPE_MASK | SVM_IOIO_STR_MASK)) { - break; - } - translator_io_start(&s->base); - if (prefixes & (PREFIX_REPZ | PREFIX_REPNZ)) { - gen_repz_ins(s, ot); - } else { - gen_ins(s, ot); - } - break; - case 0x6e: /* outsS */ - case 0x6f: - ot =3D mo_b_d32(b, dflag); - tcg_gen_trunc_tl_i32(s->tmp2_i32, cpu_regs[R_EDX]); - tcg_gen_ext16u_i32(s->tmp2_i32, s->tmp2_i32); - if (!gen_check_io(s, ot, s->tmp2_i32, SVM_IOIO_STR_MASK)) { - break; - } - translator_io_start(&s->base); - if (prefixes & (PREFIX_REPZ | PREFIX_REPNZ)) { - gen_repz_outs(s, ot); - } else { - gen_outs(s, ot); - } - break; =20 /************************/ /* port I/O */ @@ -5188,21 +4725,6 @@ static bool disas_insn(DisasContext *s, CPUState *cp= u) gen_jmp_rel(s, dflag, diff, 0); } break; - case 0x9a: /* lcall im */ - { - unsigned int selector, offset; - - if (CODE64(s)) - goto illegal_op; - ot =3D dflag; - offset =3D insn_get(env, s, ot); - selector =3D insn_get(env, s, MO_16); - - tcg_gen_movi_tl(s->T0, selector); - tcg_gen_movi_tl(s->T1, offset); - } - gen_far_call(s); - break; case 0xe9: /* jmp im */ { int diff =3D (dflag !=3D MO_16 @@ -5232,89 +4754,9 @@ static bool disas_insn(DisasContext *s, CPUState *cp= u) gen_jmp_rel(s, dflag, diff, 0); } break; - case 0x70 ... 0x7f: /* jcc Jb */ - { - int diff =3D (int8_t)insn_get(env, s, MO_8); - gen_bnd_jmp(s); - gen_jcc(s, b, diff); - } - break; - case 0x180 ... 0x18f: /* jcc Jv */ - { - int diff =3D (dflag !=3D MO_16 - ? (int32_t)insn_get(env, s, MO_32) - : (int16_t)insn_get(env, s, MO_16)); - gen_bnd_jmp(s); - gen_jcc(s, b, diff); - } - break; - - case 0x190 ... 0x19f: /* setcc Gv */ - modrm =3D x86_ldub_code(env, s); - gen_setcc1(s, b, s->T0); - gen_ldst_modrm(env, s, modrm, MO_8, OR_TMP0, 1); - break; - case 0x140 ... 0x14f: /* cmov Gv, Ev */ - if (!(s->cpuid_features & CPUID_CMOV)) { - goto illegal_op; - } - ot =3D dflag; - modrm =3D x86_ldub_code(env, s); - reg =3D ((modrm >> 3) & 7) | REX_R(s); - gen_ldst_modrm(env, s, modrm, ot, OR_TMP0, 0); - gen_cmovcc1(s, b ^ 1, s->T0, cpu_regs[reg]); - gen_op_mov_reg_v(s, ot, reg, s->T0); - break; =20 /************************/ /* flags */ - case 0x9c: /* pushf */ - gen_svm_check_intercept(s, SVM_EXIT_PUSHF); - if (check_vm86_iopl(s)) { - gen_update_cc_op(s); - gen_helper_read_eflags(s->T0, tcg_env); - gen_push_v(s, s->T0); - } - break; - case 0x9d: /* popf */ - gen_svm_check_intercept(s, SVM_EXIT_POPF); - if (check_vm86_iopl(s)) { - int mask =3D TF_MASK | AC_MASK | ID_MASK | NT_MASK; - - if (CPL(s) =3D=3D 0) { - mask |=3D IF_MASK | IOPL_MASK; - } else if (CPL(s) <=3D IOPL(s)) { - mask |=3D IF_MASK; - } - if (dflag =3D=3D MO_16) { - mask &=3D 0xffff; - } - - ot =3D gen_pop_T0(s); - gen_helper_write_eflags(tcg_env, s->T0, tcg_constant_i32(mask)= ); - gen_pop_update(s, ot); - set_cc_op(s, CC_OP_EFLAGS); - /* abort translation because TF/AC flag may change */ - s->base.is_jmp =3D DISAS_EOB_NEXT; - } - break; - case 0x9e: /* sahf */ - if (CODE64(s) && !(s->cpuid_ext3_features & CPUID_EXT3_LAHF_LM)) - goto illegal_op; - tcg_gen_shri_tl(s->T0, cpu_regs[R_EAX], 8); - gen_compute_eflags(s); - tcg_gen_andi_tl(cpu_cc_src, cpu_cc_src, CC_O); - tcg_gen_andi_tl(s->T0, s->T0, CC_S | CC_Z | CC_A | CC_P | CC_C); - tcg_gen_or_tl(cpu_cc_src, cpu_cc_src, s->T0); - break; - case 0x9f: /* lahf */ - if (CODE64(s) && !(s->cpuid_ext3_features & CPUID_EXT3_LAHF_LM)) - goto illegal_op; - gen_compute_eflags(s); - /* Note: gen_compute_eflags() only gives the condition codes */ - tcg_gen_ori_tl(s->T0, cpu_cc_src, 0x02); - tcg_gen_deposit_tl(cpu_regs[R_EAX], cpu_regs[R_EAX], s->T0, 8, 8); - break; case 0xf5: /* cmc */ gen_compute_eflags(s); tcg_gen_xori_tl(cpu_cc_src, cpu_cc_src, CC_C); @@ -5527,34 +4969,6 @@ static bool disas_insn(DisasContext *s, CPUState *cp= u) break; /************************/ /* bcd */ - case 0x27: /* daa */ - if (CODE64(s)) - goto illegal_op; - gen_update_cc_op(s); - gen_helper_daa(tcg_env); - set_cc_op(s, CC_OP_EFLAGS); - break; - case 0x2f: /* das */ - if (CODE64(s)) - goto illegal_op; - gen_update_cc_op(s); - gen_helper_das(tcg_env); - set_cc_op(s, CC_OP_EFLAGS); - break; - case 0x37: /* aaa */ - if (CODE64(s)) - goto illegal_op; - gen_update_cc_op(s); - gen_helper_aaa(tcg_env); - set_cc_op(s, CC_OP_EFLAGS); - break; - case 0x3f: /* aas */ - if (CODE64(s)) - goto illegal_op; - gen_update_cc_op(s); - gen_helper_aas(tcg_env); - set_cc_op(s, CC_OP_EFLAGS); - break; case 0xd4: /* aam */ if (CODE64(s)) goto illegal_op; @@ -5575,32 +4989,6 @@ static bool disas_insn(DisasContext *s, CPUState *cp= u) break; /************************/ /* misc */ - case 0x90: /* nop */ - /* XXX: correct lock test for all insn */ - if (prefixes & PREFIX_LOCK) { - goto illegal_op; - } - /* If REX_B is set, then this is xchg eax, r8d, not a nop. */ - if (REX_B(s)) { - goto do_xchg_reg_eax; - } - if (prefixes & PREFIX_REPZ) { - gen_update_cc_op(s); - gen_update_eip_cur(s); - gen_helper_pause(tcg_env, cur_insn_len_i32(s)); - s->base.is_jmp =3D DISAS_NORETURN; - } - break; - case 0x9b: /* fwait */ - if ((s->flags & (HF_MP_MASK | HF_TS_MASK)) =3D=3D - (HF_MP_MASK | HF_TS_MASK)) { - gen_exception(s, EXCP07_PREX); - } else { - /* needs to be treated as I/O because of ferr_irq */ - translator_io_start(&s->base); - gen_helper_fwait(tcg_env); - } - break; case 0xcc: /* int3 */ gen_interrupt(s, EXCP03_INT3); break; @@ -5636,24 +5024,6 @@ static bool disas_insn(DisasContext *s, CPUState *cp= u) gen_eob_inhibit_irq(s, true); } break; - case 0x62: /* bound */ - if (CODE64(s)) - goto illegal_op; - ot =3D dflag; - modrm =3D x86_ldub_code(env, s); - reg =3D (modrm >> 3) & 7; - mod =3D (modrm >> 6) & 3; - if (mod =3D=3D 3) - goto illegal_op; - gen_op_mov_v_reg(s, ot, s->T0, reg); - gen_lea_modrm(env, s, modrm); - tcg_gen_trunc_tl_i32(s->tmp2_i32, s->T0); - if (ot =3D=3D MO_16) { - gen_helper_boundw(tcg_env, s->A0, s->tmp2_i32); - } else { - gen_helper_boundl(tcg_env, s->A0, s->tmp2_i32); - } - break; case 0x1c8 ... 0x1cf: /* bswap reg */ reg =3D (b & 7) | REX_B(s); #ifdef TARGET_X86_64 @@ -6205,72 +5575,6 @@ static bool disas_insn(DisasContext *s, CPUState *cp= u) /* nothing to do */ } break; - case 0x63: /* arpl or movslS (x86_64) */ -#ifdef TARGET_X86_64 - if (CODE64(s)) { - int d_ot; - /* d_ot is the size of destination */ - d_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); - - if (mod =3D=3D 3) { - gen_op_mov_v_reg(s, MO_32, s->T0, rm); - /* sign extend */ - if (d_ot =3D=3D MO_64) { - tcg_gen_ext32s_tl(s->T0, s->T0); - } - gen_op_mov_reg_v(s, d_ot, reg, s->T0); - } else { - gen_lea_modrm(env, s, modrm); - gen_op_ld_v(s, MO_32 | MO_SIGN, s->T0, s->A0); - gen_op_mov_reg_v(s, d_ot, reg, s->T0); - } - } else -#endif - { - TCGLabel *label1; - TCGv t0, t1, t2; - - if (!PE(s) || VM86(s)) - goto illegal_op; - t0 =3D tcg_temp_new(); - t1 =3D tcg_temp_new(); - t2 =3D tcg_temp_new(); - ot =3D MO_16; - modrm =3D x86_ldub_code(env, s); - reg =3D (modrm >> 3) & 7; - mod =3D (modrm >> 6) & 3; - rm =3D modrm & 7; - if (mod !=3D 3) { - gen_lea_modrm(env, s, modrm); - gen_op_ld_v(s, ot, t0, s->A0); - } else { - gen_op_mov_v_reg(s, ot, t0, rm); - } - gen_op_mov_v_reg(s, ot, t1, reg); - tcg_gen_andi_tl(s->tmp0, t0, 3); - tcg_gen_andi_tl(t1, t1, 3); - tcg_gen_movi_tl(t2, 0); - label1 =3D gen_new_label(); - tcg_gen_brcond_tl(TCG_COND_GE, s->tmp0, t1, label1); - tcg_gen_andi_tl(t0, t0, ~3); - tcg_gen_or_tl(t0, t0, t1); - tcg_gen_movi_tl(t2, CC_Z); - gen_set_label(label1); - if (mod !=3D 3) { - gen_op_st_v(s, ot, t0, s->A0); - } else { - gen_op_mov_reg_v(s, ot, rm, t0); - } - gen_compute_eflags(s); - tcg_gen_andi_tl(cpu_cc_src, cpu_cc_src, ~CC_Z); - tcg_gen_or_tl(cpu_cc_src, cpu_cc_src, t2); - } - break; case 0x102: /* lar */ case 0x103: /* lsl */ { @@ -6851,11 +6155,10 @@ static bool disas_insn(DisasContext *s, CPUState *c= pu) =20 set_cc_op(s, CC_OP_POPCNT); break; + case 0 ... 0xbf: case 0x10e ... 0x117: case 0x128 ... 0x12f: - case 0x138 ... 0x13a: - case 0x150 ... 0x179: - case 0x17c ... 0x17f: + case 0x138 ... 0x19f: case 0x1c2: case 0x1c4 ... 0x1c6: case 0x1d0 ... 0x1fe: --=20 2.41.0 From nobody Wed Nov 27 15:47:24 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=1697712663; cv=none; d=zohomail.com; s=zohoarc; b=LDM9jMaiOvnqwAitTguKqZ9HV3AVB2jaFOn+jxy7MFtMsIA7h7hzwqsl2rxGD6UfvODQcFAzjscfIisTWbJ5S4gXHjVZwONGMVBQp4OQyLVE4zj4mPDCiGrnKBKKnS64Ywshy3ot3Pmzb38/wJTyC5u4LBnbjSEXwN022vQa3uM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697712663; 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=kpdWFUP0vMGhbrH5/Yc8WKNagHY+QCFuagQ4DnKD+Uw=; b=NcFaXl7Zo4nY4GPhYuymr/EybkVofI6Z5sqPTUbrPDrNAFgRN1k/U5JPEMKlTb30ka6HjJCLdPhMKZt0OIGcIAt1bDAbPgDosDX1kuNJA5eMnQl6lhe3LCXmI8Ja0f/Tuo/D6A2SqOdkhlc05wNDBh8XAEgQX0hLpdh733qMUlQ= 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 1697712663642193.95129865357876; Thu, 19 Oct 2023 03:51:03 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qtQZj-0001UY-AS; Thu, 19 Oct 2023 06:48:23 -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 1qtQZh-0001Nj-Ca for qemu-devel@nongnu.org; Thu, 19 Oct 2023 06:48:21 -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 1qtQZf-000755-EL for qemu-devel@nongnu.org; Thu, 19 Oct 2023 06:48:21 -0400 Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-93-WW81fJiaNea1y70YeTNepg-1; Thu, 19 Oct 2023 06:48:17 -0400 Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-9bd86510329so565477966b.0 for ; Thu, 19 Oct 2023 03:48:17 -0700 (PDT) Received: from [192.168.10.118] ([2001:b07:6468:f312:5e2c:eb9a:a8b6:fd3e]) by smtp.gmail.com with ESMTPSA id a13-20020a1709064a4d00b009930042510csm3340599ejv.222.2023.10.19.03.48.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 03:48:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697712498; 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=kpdWFUP0vMGhbrH5/Yc8WKNagHY+QCFuagQ4DnKD+Uw=; b=iMa5bXhIFeMHdhMcYgRnAqfi8F+k4haugXQdPu+iBp8ylqFmVnYlsz/adciB01iQfwx0Pd cktWWhRggiKGKNOKuxrDf6/0EHKsnRnARd3v8U9NX0mz3vbOVsQc+WihcPfCzBjfRBqW+p 13PbmtOl12UtF6XSqhiGhS3xTQJ4Mxk= X-MC-Unique: WW81fJiaNea1y70YeTNepg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697712495; x=1698317295; 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=kpdWFUP0vMGhbrH5/Yc8WKNagHY+QCFuagQ4DnKD+Uw=; b=OGjw5H1uYGJm+cFZzazzxddzGLCCEk/qafbKyoIrZ8cfSQk9Q9NVN7Kg2eDX3JrGts 0LtrDCr1J7OoQxWnrtl8bop6G1jnfi0DHHH5/Esyy0a5b9pHc0emdtjrMKmucN84pGsp BHvYgBKW5gPcQpzp6sgJtQJok5vA/YGlXC12jH4zViQBuYibajLLHNOLu92oS+cV5MUh LssLJp2oBEIpDkWh1xbIXxKKTvXhH1HPqlxk+zxXd+9fOWKOQAbpuZGDuoUHMleyBz3q gZFJRm7Wi10SmhCq/7l1nfyk7oTPPp45rRh0uqGcYRbMR4fj8mdcvOQGpoeZXw/gmV3S utSw== X-Gm-Message-State: AOJu0Yy1IC0lvzFoXgDKO64EEyB0e7/pqHc1WSdO2526iX6zzfGh1qMg PLEiYNWSp+kaVVM41k4OvfViYbxXhwVK72JB4WgjNxItKVC9zkCFH4LnS1JqkOpXoE2kTqAcsUu YeVqkxIUlxPKshmzTF4yazdk2zxlH051/f/qwWHij8Yb+gSJmdkEBIQR3HgQW6oSE1ZlZDHe6Rv M= X-Received: by 2002:a17:907:3603:b0:9bd:d405:4e7e with SMTP id bk3-20020a170907360300b009bdd4054e7emr1305877ejc.6.1697712495515; Thu, 19 Oct 2023 03:48:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH3mygLDT/hyXoe/m8Pa7L+aDbh1DnfMEcUwMj/L8fDXYURm2LxuIqFPZ2cYcTPgHO3XTcJJw== X-Received: by 2002:a17:907:3603:b0:9bd:d405:4e7e with SMTP id bk3-20020a170907360300b009bdd4054e7emr1305868ejc.6.1697712495147; Thu, 19 Oct 2023 03:48:15 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH v2 19/19] target/i386: remove gen_op Date: Thu, 19 Oct 2023 12:48:07 +0200 Message-ID: <20231019104807.390468-5-pbonzini@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231019104648.389942-1-pbonzini@redhat.com> References: <20231019104648.389942-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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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 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: 1697712664082100001 Content-Type: text/plain; charset="utf-8" It is not used anymore by the old decoder, inline the CMP case into CMPS an= d SCAS. Signed-off-by: Paolo Bonzini --- target/i386/tcg/translate.c | 145 +++--------------------------------- 1 file changed, 12 insertions(+), 133 deletions(-) diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index 6e091fdb7f6..3d5cdf4d29a 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -238,21 +238,8 @@ static void gen_eob(DisasContext *s); static void gen_jr(DisasContext *s); static void gen_jmp_rel(DisasContext *s, MemOp ot, int diff, int tb_num); static void gen_jmp_rel_csize(DisasContext *s, int diff, int tb_num); -static void gen_op(DisasContext *s1, int op, MemOp ot, int d); static void gen_exception_gpf(DisasContext *s); =20 -/* i386 arith/logic operations */ -enum { - OP_ADDL, - OP_ORL, - OP_ADCL, - OP_SBBL, - OP_ANDL, - OP_SUBL, - OP_XORL, - OP_CMPL, -}; - /* i386 shift ops */ enum { OP_ROL, @@ -853,13 +840,6 @@ static void gen_op_update2_cc(DisasContext *s) tcg_gen_mov_tl(cpu_cc_dst, s->T0); } =20 -static void gen_op_update3_cc(DisasContext *s, TCGv reg) -{ - tcg_gen_mov_tl(cpu_cc_src2, reg); - tcg_gen_mov_tl(cpu_cc_src, s->T1); - tcg_gen_mov_tl(cpu_cc_dst, s->T0); -} - static inline void gen_op_testl_T0_T1_cc(DisasContext *s) { tcg_gen_and_tl(cpu_cc_dst, s->T0, s->T1); @@ -1288,7 +1268,12 @@ static void gen_scas(DisasContext *s, MemOp ot) { gen_string_movl_A0_EDI(s); gen_op_ld_v(s, ot, s->T1, s->A0); - gen_op(s, OP_CMPL, ot, R_EAX); + gen_op_mov_v_reg(s, ot, s->T0, R_EAX); + tcg_gen_mov_tl(cpu_cc_src, s->T1); + tcg_gen_mov_tl(s->cc_srcT, s->T0); + tcg_gen_sub_tl(cpu_cc_dst, s->T0, s->T1); + set_cc_op(s, CC_OP_SUBB + ot); + gen_op_movl_T0_Dshift(s, ot); gen_op_add_reg_T0(s, s->aflag, R_EDI); } @@ -1298,7 +1283,12 @@ static void gen_cmps(DisasContext *s, MemOp ot) gen_string_movl_A0_EDI(s); gen_op_ld_v(s, ot, s->T1, s->A0); gen_string_movl_A0_ESI(s); - gen_op(s, OP_CMPL, ot, OR_TMP0); + gen_op_ld_v(s, ot, s->T0, s->A0); + tcg_gen_mov_tl(cpu_cc_src, s->T1); + tcg_gen_mov_tl(s->cc_srcT, s->T0); + tcg_gen_sub_tl(cpu_cc_dst, s->T0, s->T1); + set_cc_op(s, CC_OP_SUBB + ot); + gen_op_movl_T0_Dshift(s, ot); gen_op_add_reg_T0(s, s->aflag, R_ESI); gen_op_add_reg_T0(s, s->aflag, R_EDI); @@ -1506,117 +1496,6 @@ static bool check_iopl(DisasContext *s) return false; } =20 -/* if d =3D=3D OR_TMP0, it means memory operand (address in A0) */ -static void gen_op(DisasContext *s1, int op, MemOp ot, int d) -{ - if (d !=3D OR_TMP0) { - if (s1->prefix & PREFIX_LOCK) { - /* Lock prefix when destination is not memory. */ - gen_illegal_opcode(s1); - return; - } - gen_op_mov_v_reg(s1, ot, s1->T0, d); - } else if (!(s1->prefix & PREFIX_LOCK)) { - gen_op_ld_v(s1, ot, s1->T0, s1->A0); - } - switch(op) { - case OP_ADCL: - gen_compute_eflags_c(s1, s1->tmp4); - if (s1->prefix & PREFIX_LOCK) { - tcg_gen_add_tl(s1->T0, s1->tmp4, s1->T1); - tcg_gen_atomic_add_fetch_tl(s1->T0, s1->A0, s1->T0, - s1->mem_index, ot | MO_LE); - } else { - tcg_gen_add_tl(s1->T0, s1->T0, s1->T1); - tcg_gen_add_tl(s1->T0, s1->T0, s1->tmp4); - gen_op_st_rm_T0_A0(s1, ot, d); - } - gen_op_update3_cc(s1, s1->tmp4); - set_cc_op(s1, CC_OP_ADCB + ot); - break; - case OP_SBBL: - gen_compute_eflags_c(s1, s1->tmp4); - if (s1->prefix & PREFIX_LOCK) { - tcg_gen_add_tl(s1->T0, s1->T1, s1->tmp4); - tcg_gen_neg_tl(s1->T0, s1->T0); - tcg_gen_atomic_add_fetch_tl(s1->T0, s1->A0, s1->T0, - s1->mem_index, ot | MO_LE); - } else { - tcg_gen_sub_tl(s1->T0, s1->T0, s1->T1); - tcg_gen_sub_tl(s1->T0, s1->T0, s1->tmp4); - gen_op_st_rm_T0_A0(s1, ot, d); - } - gen_op_update3_cc(s1, s1->tmp4); - set_cc_op(s1, CC_OP_SBBB + ot); - break; - case OP_ADDL: - if (s1->prefix & PREFIX_LOCK) { - tcg_gen_atomic_add_fetch_tl(s1->T0, s1->A0, s1->T1, - s1->mem_index, ot | MO_LE); - } else { - tcg_gen_add_tl(s1->T0, s1->T0, s1->T1); - gen_op_st_rm_T0_A0(s1, ot, d); - } - gen_op_update2_cc(s1); - set_cc_op(s1, CC_OP_ADDB + ot); - break; - case OP_SUBL: - if (s1->prefix & PREFIX_LOCK) { - tcg_gen_neg_tl(s1->T0, s1->T1); - tcg_gen_atomic_fetch_add_tl(s1->cc_srcT, s1->A0, s1->T0, - s1->mem_index, ot | MO_LE); - tcg_gen_sub_tl(s1->T0, s1->cc_srcT, s1->T1); - } else { - tcg_gen_mov_tl(s1->cc_srcT, s1->T0); - tcg_gen_sub_tl(s1->T0, s1->T0, s1->T1); - gen_op_st_rm_T0_A0(s1, ot, d); - } - gen_op_update2_cc(s1); - set_cc_op(s1, CC_OP_SUBB + ot); - break; - default: - case OP_ANDL: - if (s1->prefix & PREFIX_LOCK) { - tcg_gen_atomic_and_fetch_tl(s1->T0, s1->A0, s1->T1, - s1->mem_index, ot | MO_LE); - } else { - tcg_gen_and_tl(s1->T0, s1->T0, s1->T1); - gen_op_st_rm_T0_A0(s1, ot, d); - } - gen_op_update1_cc(s1); - set_cc_op(s1, CC_OP_LOGICB + ot); - break; - case OP_ORL: - if (s1->prefix & PREFIX_LOCK) { - tcg_gen_atomic_or_fetch_tl(s1->T0, s1->A0, s1->T1, - s1->mem_index, ot | MO_LE); - } else { - tcg_gen_or_tl(s1->T0, s1->T0, s1->T1); - gen_op_st_rm_T0_A0(s1, ot, d); - } - gen_op_update1_cc(s1); - set_cc_op(s1, CC_OP_LOGICB + ot); - break; - case OP_XORL: - if (s1->prefix & PREFIX_LOCK) { - tcg_gen_atomic_xor_fetch_tl(s1->T0, s1->A0, s1->T1, - s1->mem_index, ot | MO_LE); - } else { - tcg_gen_xor_tl(s1->T0, s1->T0, s1->T1); - gen_op_st_rm_T0_A0(s1, ot, d); - } - gen_op_update1_cc(s1); - set_cc_op(s1, CC_OP_LOGICB + ot); - break; - case OP_CMPL: - tcg_gen_mov_tl(cpu_cc_src, s1->T1); - tcg_gen_mov_tl(s1->cc_srcT, s1->T0); - tcg_gen_sub_tl(cpu_cc_dst, s1->T0, s1->T1); - set_cc_op(s1, CC_OP_SUBB + ot); - break; - } -} - /* if d =3D=3D OR_TMP0, it means memory operand (address in A0) */ static void gen_inc(DisasContext *s1, MemOp ot, int d, int c) { --=20 2.41.0