From: Paul Brook <paul@codesourcery.com>
To: qemu-devel@nongnu.org
Cc: Aurelien Jarno <aurelien@aurel32.net>
Subject: Re: [Qemu-devel] [PATCH 0/9] tcg: reorganize bswap* functions
Date: Thu, 12 Mar 2009 12:29:46 +0000 [thread overview]
Message-ID: <200903121229.47365.paul@codesourcery.com> (raw)
In-Reply-To: <20090311170836.GD32521@hall.aurel32.net>
> This patch series tries to reorganize a bit the bswap* TCG functions.
In principle this looks ok, however several implementation issues:
> +/* Note: we assume the six high bytes are set to zero */
> +static inline void tcg_gen_bswap16_i64(TCGv_i64 ret, TCGv_i64 arg)
> +{
> + tcg_gen_bswap16_i32(TCGV_LOW(ret), TCGV_LOW(arg));
> +}
> +
> +/* Note: we assume the four high bytes are set to zero */
> +static inline void tcg_gen_bswap32_i64(TCGv_i64 ret, TCGv_i64 arg)
> +{
> + tcg_gen_bswap32_i32(TCGV_LOW(ret), TCGV_LOW(arg));
> +}
I think we want to preserve the zero extension of the value, i.e. you want
something along the lines of:
if (!TCGV_EQUAL_I64(ret, arg))
tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
- I'm not sure whether it's more efficient to do movi(ret, 0) or mov(ret,
arg). With a bit of luck they'll both be optimized away most of the time.
> +/* Note: we assume the four high bytes are set to zero */
> +static inline void tcg_gen_bswap32_i64(TCGv_i64 ret, TCGv_i64 arg)
> +{
>...
> + tcg_gen_shli_i64(t0, arg, 24);
Likewise this is missing a mask operation. ext32u_i64(t0, t0) is probably the
most efficient way).
> +++ b/tcg/i386/tcg-target.c
> + case INDEX_op_bswap16_i32:
> + tcg_out8(s, 0x66);
> + tcg_out_modrm(s, 0xc1, SHIFT_ROL, args[0]);
> + tcg_out8(s, 8);
> + { INDEX_op_bswap16_i32, { "r", "0" } },
This is wrong. The r/m field of the modrm byte can only address the first 4
registers (AL-DL). Values 4-7 address te second bytes of these registers
(a.k.a. AH-DH). I suspect you need to use the "q" constraint.
> +++ b/tcg/x86_64/tcg-target.c
> + case INDEX_op_bswap16_i32:
> + case INDEX_op_bswap16_i64:
> + tcg_out8(s, 0x66);
> + tcg_out_modrm(s, 0xc1, SHIFT_ROL, args[0]);
> + tcg_out8(s, 8);
> + break;
You need to use tcg_out_opc here to get REX prefixes. You need P_REXB to avoid
the legacy encoding issues mentioned above, and the high bit of the r/m field
also goes in the REX byte.
Paul
next prev parent reply other threads:[~2009-03-12 12:29 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-11 17:08 [Qemu-devel] [PATCH 0/9] tcg: reorganize bswap* functions Aurelien Jarno
2009-03-11 11:02 ` [Qemu-devel] [PATCH 1/9] tcg: rename bswap_i32/i64 functions Aurelien Jarno
2009-03-11 11:06 ` [Qemu-devel] [PATCH 2/9] tcg: allow bswap16_i32 to be implemented by TCG backends Aurelien Jarno
2009-03-11 11:08 ` [Qemu-devel] [PATCH 3/9] tcg: add bswap16_i64 and bswap32_i64 TCG ops Aurelien Jarno
2009-03-11 11:13 ` [Qemu-devel] [PATCH 4/9] tcg: add _tl aliases to bswap16/32/64 " Aurelien Jarno
2009-03-11 12:51 ` [Qemu-devel] [PATCH 6/9] target-ppc: use the new bswap* " Aurelien Jarno
2009-03-11 12:59 ` [Qemu-devel] [PATCH 7/9] target-i386: " Aurelien Jarno
2009-03-11 13:41 ` [Qemu-devel] [PATCH 8/9] tcg/x86: add bswap16_i32 ops Aurelien Jarno
2009-03-11 15:54 ` [Qemu-devel] [PATCH 9/9] tcg/x86_64: add bswap16_i{32, 64} and bswap32_i64 ops Aurelien Jarno
2009-03-11 16:32 ` [Qemu-devel] [PATCH 5/9] tcg: update README wrt recent bswap changes Aurelien Jarno
2009-03-12 12:29 ` Paul Brook [this message]
2009-03-12 12:56 ` [Qemu-devel] [PATCH 0/9] tcg: reorganize bswap* functions Aurelien Jarno
2009-03-12 13:31 ` Paul Brook
2009-03-12 13:37 ` 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=200903121229.47365.paul@codesourcery.com \
--to=paul@codesourcery.com \
--cc=aurelien@aurel32.net \
--cc=qemu-devel@nongnu.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.