From: Aurelien Jarno <aurelien@aurel32.net>
To: Richard Henderson <rth@twiddle.net>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 20/22] tcg-i386: Tidy lea.
Date: Fri, 21 May 2010 11:43:57 +0200 [thread overview]
Message-ID: <20100521094357.GL1950@volta.aurel32.net> (raw)
In-Reply-To: <f4f8312c2b47a6444259e699d3ec2d522df55bb6.1272479073.git.rth@twiddle.net>
On Wed, Apr 14, 2010 at 12:08:28PM -0700, Richard Henderson wrote:
> Implement full modrm+sib addressing mode processing.
> Use that in qemu_ld/st to output the LEA.
>
> Signed-off-by: Richard Henderson <rth@twiddle.net>
Acked-by: Aurelien Jarno <aurelien@aurel32.net>
> ---
> tcg/i386/tcg-target.c | 91 ++++++++++++++++++++++++++++++++-----------------
> 1 files changed, 60 insertions(+), 31 deletions(-)
>
> diff --git a/tcg/i386/tcg-target.c b/tcg/i386/tcg-target.c
> index bf3c0d6..755d46d 100644
> --- a/tcg/i386/tcg-target.c
> +++ b/tcg/i386/tcg-target.c
> @@ -176,6 +176,7 @@ static inline int tcg_target_const_match(tcg_target_long val,
> #define OPC_JCC_short (0x70) /* ... plus condition code */
> #define OPC_JMP_long (0xe9)
> #define OPC_JMP_short (0xeb)
> +#define OPC_LEA (0x8d)
> #define OPC_MOVB_EvGv (0x88) /* stores, more or less */
> #define OPC_MOVL_EvGv (0x89) /* stores, more or less */
> #define OPC_MOVL_GvEv (0x8b) /* loads, more or less */
> @@ -277,40 +278,70 @@ static inline void tcg_out_modrm(TCGContext *s, int opc, int r, int rm)
> tcg_out8(s, 0xc0 | (r << 3) | rm);
> }
>
> -/* rm == -1 means no register index */
> -static inline void tcg_out_modrm_offset(TCGContext *s, int opc, int r, int rm,
> - int32_t offset)
> +/* Output an opcode with a full "rm + (index<<shift) + offset" address mode.
> + We handle either RM and INDEX missing with a -1 value. */
> +
> +static void tcg_out_modrm_sib_offset(TCGContext *s, int opc, int r, int rm,
> + int index, int shift, int32_t offset)
> {
> + int mod, len;
> +
> + if (index == -1 && rm == -1) {
> + /* Absolute address. */
> + tcg_out_opc(s, opc);
> + tcg_out8(s, (r << 3) | 5);
> + tcg_out32(s, offset);
> + return;
> + }
> +
> tcg_out_opc(s, opc);
> +
> + /* Find the length of the immediate addend. Note that the encoding
> + that would be used for (%ebp) indicates absolute addressing. */
> if (rm == -1) {
> - tcg_out8(s, 0x05 | (r << 3));
> - tcg_out32(s, offset);
> + mod = 0, len = 4, rm = 5;
> } else if (offset == 0 && rm != TCG_REG_EBP) {
> - if (rm == TCG_REG_ESP) {
> - tcg_out8(s, 0x04 | (r << 3));
> - tcg_out8(s, 0x24);
> - } else {
> - tcg_out8(s, 0x00 | (r << 3) | rm);
> - }
> - } else if ((int8_t)offset == offset) {
> - if (rm == TCG_REG_ESP) {
> - tcg_out8(s, 0x44 | (r << 3));
> - tcg_out8(s, 0x24);
> - } else {
> - tcg_out8(s, 0x40 | (r << 3) | rm);
> - }
> - tcg_out8(s, offset);
> + mod = 0, len = 0;
> + } else if (offset == (int8_t)offset) {
> + mod = 0x40, len = 1;
> } else {
> - if (rm == TCG_REG_ESP) {
> - tcg_out8(s, 0x84 | (r << 3));
> - tcg_out8(s, 0x24);
> + mod = 0x80, len = 4;
> + }
> +
> + /* Use a single byte MODRM format if possible. Note that the encoding
> + that would be used for %esp is the escape to the two byte form. */
> + if (index == -1 && rm != TCG_REG_ESP) {
> + /* Single byte MODRM format. */
> + tcg_out8(s, mod | (r << 3) | rm);
> + } else {
> + /* Two byte MODRM+SIB format. */
> +
> + /* Note that the encoding that would place %esp into the index
> + field indicates no index register. */
> + if (index == -1) {
> + index = 4;
> } else {
> - tcg_out8(s, 0x80 | (r << 3) | rm);
> + assert(index != TCG_REG_ESP);
> }
> +
> + tcg_out8(s, mod | (r << 3) | 4);
> + tcg_out8(s, (shift << 6) | (index << 3) | rm);
> + }
> +
> + if (len == 1) {
> + tcg_out8(s, offset);
> + } else if (len == 4) {
> tcg_out32(s, offset);
> }
> }
>
> +/* rm == -1 means no register index */
> +static inline void tcg_out_modrm_offset(TCGContext *s, int opc, int r, int rm,
> + int32_t offset)
> +{
> + tcg_out_modrm_sib_offset(s, opc, r, rm, -1, 0, offset);
> +}
> +
> /* Generate dest op= src. Uses the same ARITH_* codes as tgen_arithi. */
> static inline void tgen_arithr(TCGContext *s, int subop, int dest, int src)
> {
> @@ -733,10 +764,9 @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args,
> tgen_arithi(s, ARITH_AND, r0, TARGET_PAGE_MASK | ((1 << s_bits) - 1), 0);
> tgen_arithi(s, ARITH_AND, r1, (CPU_TLB_SIZE - 1) << CPU_TLB_ENTRY_BITS, 0);
>
> - tcg_out_opc(s, 0x8d); /* lea offset(r1, %ebp), r1 */
> - tcg_out8(s, 0x80 | (r1 << 3) | 0x04);
> - tcg_out8(s, (5 << 3) | r1);
> - tcg_out32(s, offsetof(CPUState, tlb_table[mem_index][0].addr_read));
> + tcg_out_modrm_sib_offset(s, OPC_LEA, r1, TCG_AREG0, r1, 0,
> + offsetof(CPUState,
> + tlb_table[mem_index][0].addr_read));
>
> /* cmp 0(r1), r0 */
> tcg_out_modrm_offset(s, OPC_CMP_GvEv, r0, r1, 0);
> @@ -924,10 +954,9 @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args,
> tgen_arithi(s, ARITH_AND, r0, TARGET_PAGE_MASK | ((1 << s_bits) - 1), 0);
> tgen_arithi(s, ARITH_AND, r1, (CPU_TLB_SIZE - 1) << CPU_TLB_ENTRY_BITS, 0);
>
> - tcg_out_opc(s, 0x8d); /* lea offset(r1, %ebp), r1 */
> - tcg_out8(s, 0x80 | (r1 << 3) | 0x04);
> - tcg_out8(s, (5 << 3) | r1);
> - tcg_out32(s, offsetof(CPUState, tlb_table[mem_index][0].addr_write));
> + tcg_out_modrm_sib_offset(s, OPC_LEA, r1, TCG_AREG0, r1, 0,
> + offsetof(CPUState,
> + tlb_table[mem_index][0].addr_write));
>
> /* cmp 0(r1), r0 */
> tcg_out_modrm_offset(s, OPC_CMP_GvEv, r0, r1, 0);
> --
> 1.6.6.1
>
>
>
>
--
Aurelien Jarno GPG: 1024D/F1BCDB73
aurelien@aurel32.net http://www.aurel32.net
next prev parent reply other threads:[~2010-05-21 9:45 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-04-28 18:24 [Qemu-devel] [PATCH 00/22] tcg-i386 cleanup and improvement, v2 Richard Henderson
2010-04-13 22:23 ` [Qemu-devel] [PATCH 01/22] tcg-i386: Allocate call-saved registers first Richard Henderson
2010-05-19 6:46 ` Aurelien Jarno
2010-04-13 22:26 ` [Qemu-devel] [PATCH 02/22] tcg-i386: Tidy initialization of tcg_target_call_clobber_regs Richard Henderson
2010-05-19 6:46 ` Aurelien Jarno
2010-04-13 22:59 ` [Qemu-devel] [PATCH 03/22] tcg-i386: Tidy ext8u and ext16u operations Richard Henderson
2010-05-19 6:47 ` Aurelien Jarno
2010-05-19 18:31 ` Richard Henderson
2010-05-20 13:39 ` Aurelien Jarno
2010-05-20 14:04 ` Aurelien Jarno
2010-05-20 14:40 ` Richard Henderson
2010-05-20 18:50 ` Aurelien Jarno
2010-04-13 23:13 ` [Qemu-devel] [PATCH 04/22] tcg-i386: Tidy ext8s and ext16s operations Richard Henderson
2010-05-20 18:52 ` Aurelien Jarno
2010-04-14 14:58 ` [Qemu-devel] [PATCH 07/22] tcg-i386: Tidy move operations Richard Henderson
2010-04-14 15:06 ` [Qemu-devel] [PATCH 08/22] tcg-i386: Eliminate extra move from qemu_ld64 Richard Henderson
2010-04-14 15:26 ` [Qemu-devel] [PATCH 09/22] tcg-i386: Tidy jumps Richard Henderson
2010-04-14 15:38 ` [Qemu-devel] [PATCH 10/22] tcg-i386: Tidy immediate arithmetic operations Richard Henderson
2010-05-21 9:38 ` Aurelien Jarno
2010-04-14 17:16 ` [Qemu-devel] [PATCH 11/22] tcg-i386: Tidy non-immediate " Richard Henderson
2010-05-21 9:38 ` Aurelien Jarno
2010-04-14 17:20 ` [Qemu-devel] [PATCH 12/22] tcg-i386: Tidy movi Richard Henderson
2010-05-21 9:38 ` Aurelien Jarno
2010-04-14 17:59 ` [Qemu-devel] [PATCH 13/22] tcg-i386: Tidy push/pop Richard Henderson
2010-05-21 9:38 ` Aurelien Jarno
2010-04-14 18:02 ` [Qemu-devel] [PATCH 14/22] tcg-i386: Tidy calls Richard Henderson
2010-05-21 9:40 ` Aurelien Jarno
2010-04-14 18:04 ` [Qemu-devel] [PATCH 15/22] tcg-i386: Tidy ret Richard Henderson
2010-05-21 9:40 ` Aurelien Jarno
2010-04-14 18:07 ` [Qemu-devel] [PATCH 16/22] tcg-i386: Tidy setcc Richard Henderson
2010-05-21 9:40 ` Aurelien Jarno
2010-04-14 18:22 ` [Qemu-devel] [PATCH 17/22] tcg-i386: Tidy unary arithmetic Richard Henderson
2010-05-21 9:41 ` Aurelien Jarno
2010-04-14 18:29 ` [Qemu-devel] [PATCH 18/22] tcg-i386: Tidy multiply Richard Henderson
2010-05-21 9:41 ` Aurelien Jarno
2010-04-14 18:32 ` [Qemu-devel] [PATCH 19/22] tcg-i386: Tidy xchg Richard Henderson
2010-05-21 9:42 ` Aurelien Jarno
2010-04-14 19:08 ` [Qemu-devel] [PATCH 20/22] tcg-i386: Tidy lea Richard Henderson
2010-05-21 9:43 ` Aurelien Jarno [this message]
2010-04-14 20:29 ` [Qemu-devel] [PATCH 21/22] tcg-i386: Use lea for three-operand add Richard Henderson
2010-05-21 9:44 ` Aurelien Jarno
2010-04-28 17:31 ` [Qemu-devel] [PATCH 05/22] tcg-i386: Tidy bswap operations Richard Henderson
2010-04-28 17:38 ` [Qemu-devel] [PATCH 06/22] tcg-i386: Tidy shift operations Richard Henderson
2010-04-28 18:23 ` [Qemu-devel] [PATCH 22/22] tcg-i386: Tidy data16 prefixes Richard Henderson
2010-05-21 9:45 ` Aurelien Jarno
2010-05-17 18:26 ` [Qemu-devel] [PATCH 00/22] tcg-i386 cleanup and improvement, v2 Richard Henderson
2010-05-17 19:54 ` Aurelien Jarno
2010-05-21 9:46 ` Aurelien Jarno
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=20100521094357.GL1950@volta.aurel32.net \
--to=aurelien@aurel32.net \
--cc=qemu-devel@nongnu.org \
--cc=rth@twiddle.net \
/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).