From nobody Tue Nov 26 22:16:35 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=1704012599; cv=none; d=zohomail.com; s=zohoarc; b=CXdwbOdbIeEe3hwJY4auUfnAycBE2MFHzm2/CYwSYPy9Cl9UhiG+4NJq6mtyQ97PZ8SMybNSxhy4+0uZtqEB9/d2NUjz8WPWFoBmuZgsQ3Qiow51IG9Wr0162m0P9XIXcZ62nBulDaeSefcZVmcPmtOosOELcjDq95+vYaW8u7w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1704012599; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=tLPI67uvlQZKaVvNx50rUiIpMzZGv+crtvT7BwDPfRs=; b=TXpjTmzL3TWNaeE6G9KuMOq2nLUh7WsphLNOL46RTOjGPZ6LGWHjA+wc1XYxEQ9pIQCE6irYzj1VbdgxRYogXbn+VU9wkqZcMOBCLK752lZTY5zABw8WTPUJEvIvjSjcgtfB9Qufe6DuPJYciwURyesX7eEFV9MQXQHt0UZvwGg= 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 1704012599542423.8026298041989; Sun, 31 Dec 2023 00:49:59 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rJrSE-0004Ex-Il; Sun, 31 Dec 2023 03:45:54 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rJrSC-0004EU-Ku for qemu-devel@nongnu.org; Sun, 31 Dec 2023 03:45:53 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rJrS4-0000jc-Tf for qemu-devel@nongnu.org; Sun, 31 Dec 2023 03:45:51 -0500 Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-191-86hLOrTzMqO5vT4DBpvlUw-1; Sun, 31 Dec 2023 03:45:36 -0500 Received: by mail-ed1-f69.google.com with SMTP id 4fb4d7f45d1cf-5551f8ec1c8so2416882a12.1 for ; Sun, 31 Dec 2023 00:45:36 -0800 (PST) Received: from [192.168.10.118] ([2001:b07:6468:f312:1c09:f536:3de6:228c]) by smtp.gmail.com with ESMTPSA id ca26-20020aa7cd7a000000b005528a899fccsm13276171edb.37.2023.12.31.00.45.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 31 Dec 2023 00:45:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704012344; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tLPI67uvlQZKaVvNx50rUiIpMzZGv+crtvT7BwDPfRs=; b=JOjblGv5IxeOSVrIS0gutjLyS4K83RhVqQUpDeLD6ckivkmQLCGBB8/MKQ6MTjR2RctMCd AeLdvPECSnC2RhiQ6hVOdF7B4giOOMsaP+nhl8F82Yi+GSjAqIxhKBDxvTbJuPjH+qbRcF X6OrEGftP2JYfiBlrcTiEAn5zuyfJrQ= X-MC-Unique: 86hLOrTzMqO5vT4DBpvlUw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704012335; x=1704617135; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tLPI67uvlQZKaVvNx50rUiIpMzZGv+crtvT7BwDPfRs=; b=FD6iIl1qWTSnLC6j4CFoaz/KcSkS9Aes/l1YF2btMBMebqyXUI7KxCurqkfbCRMS4w pAfx1ZE3c8qD+DJP/ecNZOK/DWKfM0AO5WGSJG0U5Ilnp6gmveaKl2S4OXO6kgAKQU9p k7cXDzSl697om7zyYKWqsC7wkPGN4jS5ciFBMbunO5N/KMTeSAQrpcMDZLhDx7FtBbIh NvbR9YdcUcqqhR6x+Vf6HSbgPBBdl0aS8W0yGDMVIi3gi5RgrnnaiYhiT8qCZpeASjcn ECaOs4L50cKvQyPnZWoI8cqfo4BhzfIi0HdO0rAqDyynKIYrIbvzHEcUb42gZDjGKIA+ f82Q== X-Gm-Message-State: AOJu0Yx7aDaeHZKGKW8enlqQkQ64f6PRd5ZiiliilCjpur3cbMsaZoE6 6Ftmim76O7sGyXIzz47QE8hVcCyq98Vu9jwdM+FeMdJ/mvwxrl7iSPnh77k2IZRgT/cZBge9U36 PPg5FEmcSDx/2L4Hfr/DcG/1H0dGiMGGh4rFy8KeEE5CGd5zlpwur0d913OSwb4TI5k/kyHSkjF sN+yH6k44= X-Received: by 2002:a50:aa9b:0:b0:553:a3ec:85fc with SMTP id q27-20020a50aa9b000000b00553a3ec85fcmr10184124edc.12.1704012335117; Sun, 31 Dec 2023 00:45:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IFb4UKiXjwzaOOVNWWfGIjxP89prkeaHTd9+PGwMgBjsFz8ETCgH2AalryP5eWe3LIMBvxs0Q== X-Received: by 2002:a50:aa9b:0:b0:553:a3ec:85fc with SMTP id q27-20020a50aa9b000000b00553a3ec85fcmr10184115edc.12.1704012334799; Sun, 31 Dec 2023 00:45:34 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Richard Henderson Subject: [PULL 11/46] target/i386: add X86_SPECIALs for MOVSX and MOVZX Date: Sun, 31 Dec 2023 09:44:27 +0100 Message-ID: <20231231084502.235366-12-pbonzini@redhat.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231231084502.235366-1-pbonzini@redhat.com> References: <20231231084502.235366-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: -47 X-Spam_score: -4.8 X-Spam_bar: ---- X-Spam_report: (-4.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.667, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1704012601057100008 Content-Type: text/plain; charset="utf-8" Usually the registers are just moved into s->T0 without much care for their operand size. However, in some cases we can get more efficient code if the operand fetching logic syncs with the emission function on what is nicer. All the current uses are mostly demonstrative and only reduce the code in the emission functions, because the instructions do not support memory operands. However the logic is generic and applies to several more instructions such as MOVSXD (aka movslq), one-byte shift instructions, multiplications, XLAT, and indirect calls/jumps. Reviewed-by: Richard Henderson Signed-off-by: Paolo Bonzini --- target/i386/tcg/decode-new.c.inc | 18 ++++++++++---- target/i386/tcg/decode-new.h | 4 +++ target/i386/tcg/emit.c.inc | 42 +++++++++++++++++--------------- 3 files changed, 40 insertions(+), 24 deletions(-) diff --git a/target/i386/tcg/decode-new.c.inc b/target/i386/tcg/decode-new.= c.inc index 00fdb243857..d7a86d96c0c 100644 --- a/target/i386/tcg/decode-new.c.inc +++ b/target/i386/tcg/decode-new.c.inc @@ -156,6 +156,8 @@ #define op0_Rd .special =3D X86_SPECIAL_Op0_Rd, #define op2_Ry .special =3D X86_SPECIAL_Op2_Ry, #define avx_movx .special =3D X86_SPECIAL_AVXExtMov, +#define sextT0 .special =3D X86_SPECIAL_SExtT0, +#define zextT0 .special =3D X86_SPECIAL_ZExtT0, =20 #define vex1 .vex_class =3D 1, #define vex1_rep3 .vex_class =3D 1, .vex_special =3D X86_VEX_REPScalar, @@ -571,8 +573,8 @@ static const X86OpEntry opcodes_0F38_F0toFF[16][5] =3D { [5] =3D { X86_OP_ENTRY3(BZHI, G,y, E,y, B,y, vex13 cpuid(BMI1)), {}, - X86_OP_ENTRY3(PEXT, G,y, B,y, E,y, vex13 cpuid(BMI2)), - X86_OP_ENTRY3(PDEP, G,y, B,y, E,y, vex13 cpuid(BMI2)), + X86_OP_ENTRY3(PEXT, G,y, B,y, E,y, vex13 zextT0 cpuid(BMI2)), + X86_OP_ENTRY3(PDEP, G,y, B,y, E,y, vex13 zextT0 cpuid(BMI2)), {}, }, [6] =3D { @@ -583,10 +585,10 @@ static const X86OpEntry opcodes_0F38_F0toFF[16][5] = =3D { {}, }, [7] =3D { - X86_OP_ENTRY3(BEXTR, G,y, E,y, B,y, vex13 cpuid(BMI1)), + X86_OP_ENTRY3(BEXTR, G,y, E,y, B,y, vex13 zextT0 cpuid(BMI1)), X86_OP_ENTRY3(SHLX, G,y, E,y, B,y, vex13 cpuid(BMI1)), - X86_OP_ENTRY3(SARX, G,y, E,y, B,y, vex13 cpuid(BMI1)), - X86_OP_ENTRY3(SHRX, G,y, E,y, B,y, vex13 cpuid(BMI1)), + X86_OP_ENTRY3(SARX, G,y, E,y, B,y, vex13 sextT0 cpuid(BMI1)), + X86_OP_ENTRY3(SHRX, G,y, E,y, B,y, vex13 zextT0 cpuid(BMI1)), {}, }, }; @@ -1905,6 +1907,12 @@ static void disas_insn_new(DisasContext *s, CPUState= *cpu, int b) } break; =20 + case X86_SPECIAL_SExtT0: + case X86_SPECIAL_ZExtT0: + /* Handled in gen_load. */ + assert(decode.op[1].unit =3D=3D X86_OP_INT); + break; + default: break; } diff --git a/target/i386/tcg/decode-new.h b/target/i386/tcg/decode-new.h index b253f7457ae..70b6717227f 100644 --- a/target/i386/tcg/decode-new.h +++ b/target/i386/tcg/decode-new.h @@ -191,6 +191,10 @@ typedef enum X86InsnSpecial { * become P/P/Q/N, and size "x" becomes "q". */ X86_SPECIAL_MMX, + + /* When loaded into s->T0, register operand 1 is zero/sign extended. = */ + X86_SPECIAL_SExtT0, + X86_SPECIAL_ZExtT0, } X86InsnSpecial; =20 /* diff --git a/target/i386/tcg/emit.c.inc b/target/i386/tcg/emit.c.inc index f5e44117eab..4c2006fdd09 100644 --- a/target/i386/tcg/emit.c.inc +++ b/target/i386/tcg/emit.c.inc @@ -232,9 +232,30 @@ static void gen_load(DisasContext *s, X86DecodedInsn *= decode, int opn, TCGv v) break; case X86_OP_INT: if (op->has_ea) { - gen_op_ld_v(s, op->ot, v, s->A0); + if (v =3D=3D s->T0 && decode->e.special =3D=3D X86_SPECIAL_SEx= tT0) { + gen_op_ld_v(s, op->ot | MO_SIGN, v, s->A0); + } else { + gen_op_ld_v(s, op->ot, v, s->A0); + } + + } else if (op->ot =3D=3D MO_8 && byte_reg_is_xH(s, op->n)) { + if (v =3D=3D s->T0 && decode->e.special =3D=3D X86_SPECIAL_SEx= tT0) { + tcg_gen_sextract_tl(v, cpu_regs[op->n - 4], 8, 8); + } else { + tcg_gen_extract_tl(v, cpu_regs[op->n - 4], 8, 8); + } + + } else if (op->ot < MO_TL && v =3D=3D s->T0 && + (decode->e.special =3D=3D X86_SPECIAL_SExtT0 || + decode->e.special =3D=3D X86_SPECIAL_ZExtT0)) { + if (decode->e.special =3D=3D X86_SPECIAL_SExtT0) { + tcg_gen_ext_tl(v, cpu_regs[op->n], op->ot | MO_SIGN); + } else { + tcg_gen_ext_tl(v, cpu_regs[op->n], op->ot); + } + } else { - gen_op_mov_v_reg(s, op->ot, v, op->n); + tcg_gen_mov_tl(v, cpu_regs[op->n]); } break; case X86_OP_IMM: @@ -1084,9 +1105,6 @@ static void gen_BEXTR(DisasContext *s, CPUX86State *e= nv, X86DecodedInsn *decode) * Shifts larger than operand size get zeros. */ tcg_gen_ext8u_tl(s->A0, s->T1); - if (TARGET_LONG_BITS =3D=3D 64 && ot =3D=3D MO_32) { - tcg_gen_ext32u_tl(s->T0, s->T0); - } tcg_gen_shr_tl(s->T0, s->T0, s->A0); =20 tcg_gen_movcond_tl(TCG_COND_LEU, s->T0, s->A0, bound, s->T0, zero); @@ -1428,19 +1446,11 @@ static void gen_PCMPISTRM(DisasContext *s, CPUX86St= ate *env, X86DecodedInsn *dec =20 static void gen_PDEP(DisasContext *s, CPUX86State *env, X86DecodedInsn *de= code) { - MemOp ot =3D decode->op[1].ot; - if (ot < MO_64) { - tcg_gen_ext32u_tl(s->T0, s->T0); - } gen_helper_pdep(s->T0, s->T0, s->T1); } =20 static void gen_PEXT(DisasContext *s, CPUX86State *env, X86DecodedInsn *de= code) { - MemOp ot =3D decode->op[1].ot; - if (ot < MO_64) { - tcg_gen_ext32u_tl(s->T0, s->T0); - } gen_helper_pext(s->T0, s->T0, s->T1); } =20 @@ -1796,9 +1806,6 @@ static void gen_SARX(DisasContext *s, CPUX86State *en= v, X86DecodedInsn *decode) =20 mask =3D ot =3D=3D MO_64 ? 63 : 31; tcg_gen_andi_tl(s->T1, s->T1, mask); - if (ot !=3D MO_64) { - tcg_gen_ext32s_tl(s->T0, s->T0); - } tcg_gen_sar_tl(s->T0, s->T0, s->T1); } =20 @@ -1873,9 +1880,6 @@ static void gen_SHRX(DisasContext *s, CPUX86State *en= v, X86DecodedInsn *decode) =20 mask =3D ot =3D=3D MO_64 ? 63 : 31; tcg_gen_andi_tl(s->T1, s->T1, mask); - if (ot !=3D MO_64) { - tcg_gen_ext32u_tl(s->T0, s->T0); - } tcg_gen_shr_tl(s->T0, s->T0, s->T1); } =20 --=20 2.43.0