From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Richard Henderson <richard.henderson@linaro.org>
Subject: [PULL 18/24] target/i386: clean up repeated string operations
Date: Sat, 25 May 2024 13:33:26 +0200 [thread overview]
Message-ID: <20240525113332.1404158-19-pbonzini@redhat.com> (raw)
In-Reply-To: <20240525113332.1404158-1-pbonzini@redhat.com>
Do not bother generating inline wrappers for gen_repz and gen_repz2;
use s->prefix to separate REPZ from REPNZ in the case of SCAS and
CMPS.
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
target/i386/tcg/translate.c | 22 ++++------------------
target/i386/tcg/emit.c.inc | 22 +++++++++-------------
2 files changed, 13 insertions(+), 31 deletions(-)
diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c
index 15993f83024..7dd7ebf60d4 100644
--- a/target/i386/tcg/translate.c
+++ b/target/i386/tcg/translate.c
@@ -1327,14 +1327,12 @@ static void gen_repz(DisasContext *s, MemOp ot,
gen_jmp_rel_csize(s, -cur_insn_len(s), 0);
}
-#define GEN_REPZ(op) \
- static inline void gen_repz_ ## op(DisasContext *s, MemOp ot) \
- { gen_repz(s, ot, gen_##op); }
-
-static void gen_repz2(DisasContext *s, MemOp ot, int nz,
- void (*fn)(DisasContext *s, MemOp ot))
+static void gen_repz_nz(DisasContext *s, MemOp ot,
+ void (*fn)(DisasContext *s, MemOp ot))
{
TCGLabel *l2;
+ int nz = (s->prefix & PREFIX_REPNZ) ? 1 : 0;
+
l2 = gen_jz_ecx_string(s);
fn(s, ot);
gen_op_add_reg_im(s, s->aflag, R_ECX, -1);
@@ -1350,18 +1348,6 @@ static void gen_repz2(DisasContext *s, MemOp ot, int nz,
gen_jmp_rel_csize(s, -cur_insn_len(s), 0);
}
-#define GEN_REPZ2(op) \
- static inline void gen_repz_ ## op(DisasContext *s, MemOp ot, int nz) \
- { gen_repz2(s, ot, nz, gen_##op); }
-
-GEN_REPZ(movs)
-GEN_REPZ(stos)
-GEN_REPZ(lods)
-GEN_REPZ(ins)
-GEN_REPZ(outs)
-GEN_REPZ2(scas)
-GEN_REPZ2(cmps)
-
static void gen_helper_fp_arith_ST0_FT0(int op)
{
switch (op) {
diff --git a/target/i386/tcg/emit.c.inc b/target/i386/tcg/emit.c.inc
index 0a13be4989a..377d2201c91 100644
--- a/target/i386/tcg/emit.c.inc
+++ b/target/i386/tcg/emit.c.inc
@@ -1508,10 +1508,8 @@ static void gen_CMPccXADD(DisasContext *s, CPUX86State *env, X86DecodedInsn *dec
static void gen_CMPS(DisasContext *s, CPUX86State *env, X86DecodedInsn *decode)
{
MemOp ot = decode->op[2].ot;
- if (s->prefix & PREFIX_REPNZ) {
- gen_repz_cmps(s, ot, 1);
- } else if (s->prefix & PREFIX_REPZ) {
- gen_repz_cmps(s, ot, 0);
+ if (s->prefix & (PREFIX_REPZ | PREFIX_REPNZ)) {
+ gen_repz_nz(s, ot, gen_cmps);
} else {
gen_cmps(s, ot);
}
@@ -1834,7 +1832,7 @@ static void gen_INS(DisasContext *s, CPUX86State *env, X86DecodedInsn *decode)
translator_io_start(&s->base);
if (s->prefix & (PREFIX_REPZ | PREFIX_REPNZ)) {
- gen_repz_ins(s, ot);
+ gen_repz(s, ot, gen_ins);
} else {
gen_ins(s, ot);
}
@@ -1993,7 +1991,7 @@ static void gen_LODS(DisasContext *s, CPUX86State *env, X86DecodedInsn *decode)
{
MemOp ot = decode->op[2].ot;
if (s->prefix & (PREFIX_REPZ | PREFIX_REPNZ)) {
- gen_repz_lods(s, ot);
+ gen_repz(s, ot, gen_lods);
} else {
gen_lods(s, ot);
}
@@ -2155,7 +2153,7 @@ static void gen_MOVS(DisasContext *s, CPUX86State *env, X86DecodedInsn *decode)
{
MemOp ot = decode->op[2].ot;
if (s->prefix & (PREFIX_REPZ | PREFIX_REPNZ)) {
- gen_repz_movs(s, ot);
+ gen_repz(s, ot, gen_movs);
} else {
gen_movs(s, ot);
}
@@ -2321,7 +2319,7 @@ static void gen_OUTS(DisasContext *s, CPUX86State *env, X86DecodedInsn *decode)
translator_io_start(&s->base);
if (s->prefix & (PREFIX_REPZ | PREFIX_REPNZ)) {
- gen_repz_outs(s, ot);
+ gen_repz(s, ot, gen_outs);
} else {
gen_outs(s, ot);
}
@@ -3329,10 +3327,8 @@ static void gen_SBB(DisasContext *s, CPUX86State *env, X86DecodedInsn *decode)
static void gen_SCAS(DisasContext *s, CPUX86State *env, X86DecodedInsn *decode)
{
MemOp ot = decode->op[2].ot;
- if (s->prefix & PREFIX_REPNZ) {
- gen_repz_scas(s, ot, 1);
- } else if (s->prefix & PREFIX_REPZ) {
- gen_repz_scas(s, ot, 0);
+ if (s->prefix & (PREFIX_REPZ | PREFIX_REPNZ)) {
+ gen_repz_nz(s, ot, gen_scas);
} else {
gen_scas(s, ot);
}
@@ -3495,7 +3491,7 @@ static void gen_STOS(DisasContext *s, CPUX86State *env, X86DecodedInsn *decode)
{
MemOp ot = decode->op[1].ot;
if (s->prefix & (PREFIX_REPZ | PREFIX_REPNZ)) {
- gen_repz_stos(s, ot);
+ gen_repz(s, ot, gen_stos);
} else {
gen_stos(s, ot);
}
--
2.45.1
next prev parent reply other threads:[~2024-05-25 11:36 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-25 11:33 [PULL 00/24] Build system and target/i386/translate.c cleanups for 2025-05-25 Paolo Bonzini
2024-05-25 11:33 ` [PULL 01/24] configure: move -mcx16 flag out of CPU_CFLAGS Paolo Bonzini
2024-10-04 16:08 ` Alex Bennée
2024-10-04 22:42 ` Pierrick Bouvier
2024-05-25 11:33 ` [PULL 02/24] target/i386: disable jmp_opt if EFLAGS.RF is 1 Paolo Bonzini
2024-05-25 11:33 ` [PULL 03/24] target/i386: no single-step exception after MOV or POP SS Paolo Bonzini
2024-05-25 11:33 ` [PULL 04/24] target/i386: cleanup eob handling of RSM Paolo Bonzini
2024-05-25 11:33 ` [PULL 05/24] target/i386: remove unnecessary gen_update_cc_op before gen_eob* Paolo Bonzini
2024-05-25 11:33 ` [PULL 06/24] target/i386: cpu_load_eflags already sets cc_op Paolo Bonzini
2024-05-25 11:33 ` [PULL 07/24] target/i386: set CC_OP in helpers if they want CC_OP_EFLAGS Paolo Bonzini
2024-05-25 11:33 ` [PULL 08/24] target/i386: document and group DISAS_* constants Paolo Bonzini
2024-05-25 11:33 ` [PULL 09/24] target/i386: avoid calling gen_eob_syscall before tb_stop Paolo Bonzini
2024-05-25 11:33 ` [PULL 10/24] target/i386: avoid calling gen_eob_inhibit_irq " Paolo Bonzini
2024-05-25 11:33 ` [PULL 11/24] target/i386: assert that gen_update_eip_cur and gen_update_eip_next are the same in tb_stop Paolo Bonzini
2024-05-25 11:33 ` [PULL 12/24] target/i386: raze the gen_eob* jungle Paolo Bonzini
2024-05-25 11:33 ` [PULL 13/24] target/i386: reg in gen_ldst_modrm is always OR_TMP0 Paolo Bonzini
2024-05-25 11:33 ` [PULL 14/24] target/i386: split gen_ldst_modrm for load and store Paolo Bonzini
2024-05-25 11:33 ` [PULL 15/24] target/i386: inline gen_add_A0_ds_seg Paolo Bonzini
2024-05-25 11:33 ` [PULL 16/24] target/i386: use mo_stacksize more Paolo Bonzini
2024-05-25 11:33 ` [PULL 17/24] target/i386: introduce gen_lea_ss_ofs Paolo Bonzini
2024-05-25 11:33 ` Paolo Bonzini [this message]
2024-05-25 11:33 ` [PULL 19/24] target/i386: remove aflag argument of gen_lea_v_seg Paolo Bonzini
2024-05-25 11:33 ` [PULL 20/24] meson: remove unnecessary reference to libm Paolo Bonzini
2024-05-25 11:33 ` [PULL 21/24] meson: remove unnecessary dependency Paolo Bonzini
2024-05-25 11:33 ` [PULL 22/24] tcg: include dependencies in static_library() Paolo Bonzini
2024-05-25 11:33 ` [PULL 23/24] meson: do not query modules before they are processed Paolo Bonzini
2024-05-25 11:33 ` [PULL 24/24] migration: remove unnecessary zlib dependency Paolo Bonzini
2024-05-26 1:34 ` [PULL 00/24] Build system and target/i386/translate.c cleanups for 2025-05-25 Richard Henderson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240525113332.1404158-19-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).