From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Richard Henderson <richard.henderson@linaro.org>
Subject: [PULL 17/24] target/i386: introduce gen_lea_ss_ofs
Date: Sat, 25 May 2024 13:33:25 +0200 [thread overview]
Message-ID: <20240525113332.1404158-18-pbonzini@redhat.com> (raw)
In-Reply-To: <20240525113332.1404158-1-pbonzini@redhat.com>
Generalize gen_stack_A0() to include an initial add and to use an arbitrary
destination. This is a common pattern and it is not a huge burden to
add the extra arguments to the only caller of gen_stack_A0().
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
target/i386/tcg/translate.c | 51 +++++++++++++++----------------------
target/i386/tcg/emit.c.inc | 2 +-
2 files changed, 22 insertions(+), 31 deletions(-)
diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c
index 2a20f9bafbb..15993f83024 100644
--- a/target/i386/tcg/translate.c
+++ b/target/i386/tcg/translate.c
@@ -2035,24 +2035,27 @@ static inline void gen_stack_update(DisasContext *s, int addend)
gen_op_add_reg_im(s, mo_stacksize(s), R_ESP, addend);
}
+static void gen_lea_ss_ofs(DisasContext *s, TCGv dest, TCGv src, target_ulong offset)
+{
+ if (offset) {
+ tcg_gen_addi_tl(dest, src, offset);
+ src = dest;
+ }
+ gen_lea_v_seg_dest(s, mo_stacksize(s), dest, src, R_SS, -1);
+}
+
/* Generate a push. It depends on ss32, addseg and dflag. */
static void gen_push_v(DisasContext *s, TCGv val)
{
MemOp d_ot = mo_pushpop(s, s->dflag);
MemOp a_ot = mo_stacksize(s);
int size = 1 << d_ot;
- TCGv new_esp = s->A0;
+ TCGv new_esp = tcg_temp_new();
- tcg_gen_subi_tl(s->A0, cpu_regs[R_ESP], size);
-
- if (!CODE64(s)) {
- if (ADDSEG(s)) {
- new_esp = tcg_temp_new();
- tcg_gen_mov_tl(new_esp, s->A0);
- }
- gen_lea_v_seg(s, a_ot, s->A0, R_SS, -1);
- }
+ tcg_gen_subi_tl(new_esp, cpu_regs[R_ESP], size);
+ /* Now reduce the value to the address size and apply SS base. */
+ gen_lea_ss_ofs(s, s->A0, new_esp, 0);
gen_op_st_v(s, d_ot, val, s->A0);
gen_op_mov_reg_v(s, a_ot, R_ESP, new_esp);
}
@@ -2062,7 +2065,7 @@ static MemOp gen_pop_T0(DisasContext *s)
{
MemOp d_ot = mo_pushpop(s, s->dflag);
- gen_lea_v_seg_dest(s, mo_stacksize(s), s->T0, cpu_regs[R_ESP], R_SS, -1);
+ gen_lea_ss_ofs(s, s->T0, cpu_regs[R_ESP], 0);
gen_op_ld_v(s, d_ot, s->T0, s->T0);
return d_ot;
@@ -2073,21 +2076,14 @@ static inline void gen_pop_update(DisasContext *s, MemOp ot)
gen_stack_update(s, 1 << ot);
}
-static inline void gen_stack_A0(DisasContext *s)
-{
- gen_lea_v_seg(s, mo_stacksize(s), cpu_regs[R_ESP], R_SS, -1);
-}
-
static void gen_pusha(DisasContext *s)
{
- MemOp s_ot = mo_stacksize(s);
MemOp d_ot = s->dflag;
int size = 1 << d_ot;
int i;
for (i = 0; i < 8; i++) {
- tcg_gen_addi_tl(s->A0, cpu_regs[R_ESP], (i - 8) * size);
- gen_lea_v_seg(s, s_ot, s->A0, R_SS, -1);
+ gen_lea_ss_ofs(s, s->A0, cpu_regs[R_ESP], (i - 8) * size);
gen_op_st_v(s, d_ot, cpu_regs[7 - i], s->A0);
}
@@ -2096,7 +2092,6 @@ static void gen_pusha(DisasContext *s)
static void gen_popa(DisasContext *s)
{
- MemOp s_ot = mo_stacksize(s);
MemOp d_ot = s->dflag;
int size = 1 << d_ot;
int i;
@@ -2106,8 +2101,7 @@ static void gen_popa(DisasContext *s)
if (7 - i == R_ESP) {
continue;
}
- tcg_gen_addi_tl(s->A0, cpu_regs[R_ESP], i * size);
- gen_lea_v_seg(s, s_ot, s->A0, R_SS, -1);
+ gen_lea_ss_ofs(s, s->A0, cpu_regs[R_ESP], i * size);
gen_op_ld_v(s, d_ot, s->T0, s->A0);
gen_op_mov_reg_v(s, d_ot, 7 - i, s->T0);
}
@@ -2123,7 +2117,7 @@ static void gen_enter(DisasContext *s, int esp_addend, int level)
/* Push BP; compute FrameTemp into T1. */
tcg_gen_subi_tl(s->T1, cpu_regs[R_ESP], size);
- gen_lea_v_seg(s, a_ot, s->T1, R_SS, -1);
+ gen_lea_ss_ofs(s, s->A0, s->T1, 0);
gen_op_st_v(s, d_ot, cpu_regs[R_EBP], s->A0);
level &= 31;
@@ -2132,18 +2126,15 @@ static void gen_enter(DisasContext *s, int esp_addend, int level)
/* Copy level-1 pointers from the previous frame. */
for (i = 1; i < level; ++i) {
- tcg_gen_subi_tl(s->A0, cpu_regs[R_EBP], size * i);
- gen_lea_v_seg(s, a_ot, s->A0, R_SS, -1);
+ gen_lea_ss_ofs(s, s->A0, cpu_regs[R_EBP], -size * i);
gen_op_ld_v(s, d_ot, s->tmp0, s->A0);
- tcg_gen_subi_tl(s->A0, s->T1, size * i);
- gen_lea_v_seg(s, a_ot, s->A0, R_SS, -1);
+ gen_lea_ss_ofs(s, s->A0, s->T1, -size * i);
gen_op_st_v(s, d_ot, s->tmp0, s->A0);
}
/* Push the current FrameTemp as the last level. */
- tcg_gen_subi_tl(s->A0, s->T1, size * level);
- gen_lea_v_seg(s, a_ot, s->A0, R_SS, -1);
+ gen_lea_ss_ofs(s, s->A0, s->T1, -size * level);
gen_op_st_v(s, d_ot, s->T1, s->A0);
}
@@ -2160,7 +2151,7 @@ static void gen_leave(DisasContext *s)
MemOp d_ot = mo_pushpop(s, s->dflag);
MemOp a_ot = mo_stacksize(s);
- gen_lea_v_seg(s, a_ot, cpu_regs[R_EBP], R_SS, -1);
+ gen_lea_ss_ofs(s, s->A0, cpu_regs[R_EBP], 0);
gen_op_ld_v(s, d_ot, s->T0, s->A0);
tcg_gen_addi_tl(s->T1, cpu_regs[R_EBP], 1 << d_ot);
diff --git a/target/i386/tcg/emit.c.inc b/target/i386/tcg/emit.c.inc
index 01ad57629e4..0a13be4989a 100644
--- a/target/i386/tcg/emit.c.inc
+++ b/target/i386/tcg/emit.c.inc
@@ -3077,7 +3077,7 @@ static void gen_RETF(DisasContext *s, CPUX86State *env, X86DecodedInsn *decode)
int16_t adjust = decode->e.op2 == X86_TYPE_I ? decode->immediate : 0;
if (!PE(s) || VM86(s)) {
- gen_stack_A0(s);
+ gen_lea_ss_ofs(s, s->A0, cpu_regs[R_ESP], 0);
/* pop offset */
gen_op_ld_v(s, s->dflag, s->T0, s->A0);
/* NOTE: keeping EIP updated is not a problem in case of
--
2.45.1
next prev parent reply other threads:[~2024-05-25 11:37 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 ` Paolo Bonzini [this message]
2024-05-25 11:33 ` [PULL 18/24] target/i386: clean up repeated string operations Paolo Bonzini
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-18-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).