From: Aurelien Jarno <aurelien@aurel32.net>
To: Richard Henderson <rth@twiddle.net>
Cc: av1474@comtv.ru, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH v4 28/33] tcg-ppc64: Use ISEL for setcond
Date: Mon, 15 Apr 2013 10:13:49 +0200 [thread overview]
Message-ID: <20130415081349.GA11810@ohm.aurel32.net> (raw)
In-Reply-To: <1365116186-19382-29-git-send-email-rth@twiddle.net>
On Thu, Apr 04, 2013 at 05:56:21PM -0500, Richard Henderson wrote:
> There are a few simple special cases that should be handled first.
> Break these out to subroutines to avoid code duplication.
>
> Signed-off-by: Richard Henderson <rth@twiddle.net>
> ---
> tcg/ppc64/tcg-target.c | 181 ++++++++++++++++++++++++++++++++-----------------
> 1 file changed, 119 insertions(+), 62 deletions(-)
>
> diff --git a/tcg/ppc64/tcg-target.c b/tcg/ppc64/tcg-target.c
> index f0ed698..27a7ff2 100644
> --- a/tcg/ppc64/tcg-target.c
> +++ b/tcg/ppc64/tcg-target.c
> @@ -45,6 +45,7 @@ static uint8_t *tb_ret_addr;
> #endif
>
> #define HAVE_ISA_2_06 0
> +#define HAVE_ISEL 0
>
> #ifdef CONFIG_USE_GUEST_BASE
> #define TCG_GUEST_BASE_REG 30
> @@ -390,6 +391,7 @@ static int tcg_target_const_match (tcg_target_long val,
> #define ORC XO31(412)
> #define EQV XO31(284)
> #define NAND XO31(476)
> +#define ISEL XO31( 15)
>
> #define MULLD XO31(233)
> #define MULHD XO31( 73)
> @@ -445,6 +447,7 @@ static int tcg_target_const_match (tcg_target_long val,
> #define BT(n, c) (((c)+((n)*4))<<21)
> #define BA(n, c) (((c)+((n)*4))<<16)
> #define BB(n, c) (((c)+((n)*4))<<11)
> +#define BC_(n, c) (((c)+((n)*4))<<6)
>
> #define BO_COND_TRUE BO (12)
> #define BO_COND_FALSE BO ( 4)
> @@ -470,6 +473,20 @@ static const uint32_t tcg_to_bc[] = {
> [TCG_COND_GTU] = BC | BI (7, CR_GT) | BO_COND_TRUE,
> };
>
> +/* The low bit here is set if the RA and RB fields must be inverted. */
> +static const uint32_t tcg_to_isel[] = {
> + [TCG_COND_EQ] = ISEL | BC_(7, CR_EQ),
> + [TCG_COND_NE] = ISEL | BC_(7, CR_EQ) | 1,
> + [TCG_COND_LT] = ISEL | BC_(7, CR_LT),
> + [TCG_COND_GE] = ISEL | BC_(7, CR_LT) | 1,
> + [TCG_COND_LE] = ISEL | BC_(7, CR_GT) | 1,
> + [TCG_COND_GT] = ISEL | BC_(7, CR_GT),
> + [TCG_COND_LTU] = ISEL | BC_(7, CR_LT),
> + [TCG_COND_GEU] = ISEL | BC_(7, CR_LT) | 1,
> + [TCG_COND_LEU] = ISEL | BC_(7, CR_GT) | 1,
> + [TCG_COND_GTU] = ISEL | BC_(7, CR_GT),
> +};
> +
> static inline void tcg_out_mov(TCGContext *s, TCGType type,
> TCGReg ret, TCGReg arg)
> {
> @@ -1131,79 +1148,119 @@ static void tcg_out_cmp(TCGContext *s, int cond, TCGArg arg1, TCGArg arg2,
> }
> }
>
> -static void tcg_out_setcond (TCGContext *s, TCGType type, TCGCond cond,
> - TCGArg arg0, TCGArg arg1, TCGArg arg2,
> - int const_arg2)
> +static void tcg_out_setcond_eq0(TCGContext *s, TCGType type,
> + TCGReg dst, TCGReg src)
> {
> - int crop, sh, arg;
> + tcg_out32(s, (type == TCG_TYPE_I64 ? CNTLZD : CNTLZW) | RS(src) | RA(dst));
> + tcg_out_shri64(s, dst, dst, type == TCG_TYPE_I64 ? 6 : 5);
> +}
>
> - switch (cond) {
> - case TCG_COND_EQ:
> - if (const_arg2) {
> - if (!arg2) {
> - arg = arg1;
> - }
> - else {
> - arg = 0;
> - if ((uint16_t) arg2 == arg2) {
> - tcg_out32(s, XORI | SAI(arg1, 0, arg2));
> - }
> - else {
> - tcg_out_movi (s, type, 0, arg2);
> - tcg_out32 (s, XOR | SAB (arg1, 0, 0));
> - }
> - }
> - }
> - else {
> - arg = 0;
> - tcg_out32 (s, XOR | SAB (arg1, 0, arg2));
> - }
> +static void tcg_out_setcond_ne0(TCGContext *s, TCGReg dst, TCGReg src)
> +{
> + /* X != 0 implies X + -1 generates a carry. Extra addition
> + trickery means: R = X-1 + ~X + C = X-1 + (-X+1) + C = C. */
> + if (dst != src) {
> + tcg_out32(s, ADDIC | TAI(dst, src, -1));
> + tcg_out32(s, SUBFE | TAB(dst, dst, src));
> + } else {
> + tcg_out32(s, ADDIC | TAI(0, src, -1));
> + tcg_out32(s, SUBFE | TAB(dst, 0, src));
> + }
> +}
>
> - if (type == TCG_TYPE_I64) {
> - tcg_out32 (s, CNTLZD | RS (arg) | RA (0));
> - tcg_out_rld (s, RLDICL, arg0, 0, 58, 6);
> - }
> - else {
> - tcg_out32 (s, CNTLZW | RS (arg) | RA (0));
> - tcg_out_rlw(s, RLWINM, arg0, 0, 27, 5, 31);
> +static TCGReg tcg_gen_setcond_xor(TCGContext *s, TCGReg arg1, TCGArg arg2,
> + bool const_arg2)
> +{
> + if (const_arg2) {
> + if ((uint32_t)arg2 == arg2) {
> + tcg_out_xori32(s, TCG_REG_R0, arg1, arg2);
> + } else {
> + tcg_out_movi(s, TCG_TYPE_I64, TCG_REG_R0, arg2);
> + tcg_out32(s, XOR | SAB(arg1, TCG_REG_R0, TCG_REG_R0));
> }
> - break;
> + } else {
> + tcg_out32(s, XOR | SAB(arg1, TCG_REG_R0, arg2));
> + }
> + return TCG_REG_R0;
> +}
>
> - case TCG_COND_NE:
> - if (const_arg2) {
> - if (!arg2) {
> - arg = arg1;
> - }
> - else {
> - arg = 0;
> - if ((uint16_t) arg2 == arg2) {
> - tcg_out32(s, XORI | SAI(arg1, 0, arg2));
> - } else {
> - tcg_out_movi (s, type, 0, arg2);
> - tcg_out32 (s, XOR | SAB (arg1, 0, 0));
> - }
> +static void tcg_out_setcond(TCGContext *s, TCGType type, TCGCond cond,
> + TCGArg arg0, TCGArg arg1, TCGArg arg2,
> + int const_arg2)
> +{
> + int crop, sh;
> +
> + /* Ignore high bits of a potential constant arg2. */
> + if (type == TCG_TYPE_I32) {
> + arg2 = (uint32_t)arg2;
> + }
> +
> + /* Handle common and trivial cases before handling anything else. */
> + if (arg2 == 0) {
> + switch (cond) {
> + case TCG_COND_EQ:
> + tcg_out_setcond_eq0(s, type, arg0, arg1);
> + return;
> + case TCG_COND_NE:
> + if (type == TCG_TYPE_I32) {
> + tcg_out_ext32u(s, TCG_REG_R0, arg1);
> + arg1 = TCG_REG_R0;
> }
> + tcg_out_setcond_ne0(s, arg0, arg1);
> + return;
> + case TCG_COND_GE:
> + tcg_out32(s, NOR | SAB(arg1, arg0, arg1));
> + arg1 = arg0;
> + /* FALLTHRU */
> + case TCG_COND_LT:
> + /* Extract the sign bit. */
> + tcg_out_rld(s, RLDICL, arg0, arg1,
> + type == TCG_TYPE_I64 ? 1 : 33, 63);
> + return;
> + default:
> + break;
> }
> - else {
> - arg = 0;
> - tcg_out32 (s, XOR | SAB (arg1, 0, arg2));
> - }
> + }
>
> - /* Make sure and discard the high 32-bits of the input. */
> - if (type == TCG_TYPE_I32) {
> - tcg_out32(s, EXTSW | RA(TCG_REG_R0) | RS(arg));
> - arg = TCG_REG_R0;
> - }
> + /* If we have ISEL, we can implement everything with 3 or 4 insns.
> + All other cases below are also at least 3 insns, so speed up the
> + code generator by not considering them and always using ISEL. */
> + if (HAVE_ISEL) {
> + int isel, tab;
> +
> + tcg_out_cmp(s, cond, arg1, arg2, const_arg2, 7, type);
> +
> + isel = tcg_to_isel[cond];
>
> - if (arg == arg1 && arg1 == arg0) {
> - tcg_out32(s, ADDIC | TAI(0, arg, -1));
> - tcg_out32(s, SUBFE | TAB(arg0, 0, arg));
> + tcg_out_movi(s, type, arg0, 1);
> + if (isel & 1) {
> + /* arg0 = (bc ? 0 : 1) */
> + tab = TAB(arg0, 0, arg0);
> + isel &= ~1;
> + } else {
> + /* arg0 = (bc ? 1 : 0) */
> + tcg_out_movi(s, type, TCG_REG_R0, 0);
> + tab = TAB(arg0, arg0, TCG_REG_R0);
> }
> - else {
> - tcg_out32(s, ADDIC | TAI(arg0, arg, -1));
> - tcg_out32(s, SUBFE | TAB(arg0, arg0, arg));
> + tcg_out32(s, isel | tab);
> + return;
> + }
> +
> + switch (cond) {
> + case TCG_COND_EQ:
> + arg1 = tcg_gen_setcond_xor(s, arg1, arg2, const_arg2);
> + tcg_out_setcond_eq0(s, type, arg0, arg1);
> + return;
> +
> + case TCG_COND_NE:
> + arg1 = tcg_gen_setcond_xor(s, arg1, arg2, const_arg2);
> + /* Discard the high bits only once, rather than both inputs. */
> + if (type == TCG_TYPE_I32) {
> + tcg_out_ext32u(s, TCG_REG_R0, arg1);
> + arg1 = TCG_REG_R0;
> }
> - break;
> + tcg_out_setcond_ne0(s, arg0, arg1);
> + return;
>
> case TCG_COND_GT:
> case TCG_COND_GTU:
Reviewed-by: Aurelien Jarno <aurelien@aurel32.net>
--
Aurelien Jarno GPG: 1024D/F1BCDB73
aurelien@aurel32.net http://www.aurel32.net
next prev parent reply other threads:[~2013-04-15 8:14 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-04-04 22:55 [Qemu-devel] [PATCH v4 00/33] Modernize tcg/ppc64 Richard Henderson
2013-04-04 22:55 ` [Qemu-devel] [PATCH v4 01/33] disas: Disassemble all ppc insns for the host Richard Henderson
2013-04-04 22:55 ` [Qemu-devel] [PATCH v4 02/33] tcg-ppc64: Use TCGReg everywhere Richard Henderson
2013-04-04 22:55 ` [Qemu-devel] [PATCH v4 03/33] tcg-ppc64: Introduce and use tcg_out_rlw Richard Henderson
2013-04-04 22:55 ` [Qemu-devel] [PATCH v4 04/33] tcg-ppc64: Introduce and use tcg_out_ext32u Richard Henderson
2013-04-04 22:55 ` [Qemu-devel] [PATCH v4 05/33] tcg-ppc64: Introduce and use tcg_out_shli64 Richard Henderson
2013-04-04 22:55 ` [Qemu-devel] [PATCH v4 06/33] tcg-ppc64: Introduce and use tcg_out_shri64 Richard Henderson
2013-04-04 22:56 ` [Qemu-devel] [PATCH v4 07/33] tcg-ppc64: Introduce and use TAI and SAI Richard Henderson
2013-04-04 22:56 ` [Qemu-devel] [PATCH v4 08/33] tcg-ppc64: Fix setcond_i32 Richard Henderson
2013-04-15 7:54 ` Aurelien Jarno
2013-04-04 22:56 ` [Qemu-devel] [PATCH v4 09/33] tcg-ppc64: Cleanup tcg_out_movi Richard Henderson
2013-04-04 22:56 ` [Qemu-devel] [PATCH v4 10/33] tcg-ppc64: Rearrange integer constant constraints Richard Henderson
2013-04-04 22:56 ` [Qemu-devel] [PATCH v4 11/33] tcg-ppc64: Improve constant add and sub ops Richard Henderson
2013-04-15 7:54 ` Aurelien Jarno
2013-04-04 22:56 ` [Qemu-devel] [PATCH v4 12/33] tcg-ppc64: Allow constant first argument to sub Richard Henderson
2013-04-15 7:59 ` Aurelien Jarno
2013-04-04 22:56 ` [Qemu-devel] [PATCH v4 13/33] tcg-ppc64: Tidy or and xor patterns Richard Henderson
2013-04-04 22:56 ` [Qemu-devel] [PATCH v4 14/33] tcg-ppc64: Improve and_i32 with constant Richard Henderson
2013-04-04 22:56 ` [Qemu-devel] [PATCH v4 15/33] tcg-ppc64: Improve and_i64 " Richard Henderson
2013-04-13 12:24 ` Aurelien Jarno
2013-04-04 22:56 ` [Qemu-devel] [PATCH v4 16/33] tcg-ppc64: Use automatic implementation of ext32u_i64 Richard Henderson
2013-04-13 12:25 ` Aurelien Jarno
2013-04-04 22:56 ` [Qemu-devel] [PATCH v4 17/33] tcg-ppc64: Streamline qemu_ld/st insn selection Richard Henderson
2013-04-13 12:25 ` Aurelien Jarno
2013-04-04 22:56 ` [Qemu-devel] [PATCH v4 18/33] tcg-ppc64: Implement rotates Richard Henderson
2013-04-04 22:56 ` [Qemu-devel] [PATCH v4 19/33] tcg-ppc64: Implement bswap16 and bswap32 Richard Henderson
2013-04-15 7:59 ` Aurelien Jarno
2013-04-04 22:56 ` [Qemu-devel] [PATCH v4 20/33] tcg-ppc64: Implement bswap64 Richard Henderson
2013-04-04 22:56 ` [Qemu-devel] [PATCH v4 21/33] tcg-ppc64: Implement compound logicals Richard Henderson
2013-04-04 22:56 ` [Qemu-devel] [PATCH v4 22/33] tcg-ppc64: Handle constant inputs for some " Richard Henderson
2013-04-04 22:56 ` [Qemu-devel] [PATCH v4 23/33] tcg-ppc64: Implement deposit Richard Henderson
2013-04-04 22:56 ` [Qemu-devel] [PATCH v4 24/33] tcg-ppc64: Use I constraint for mul Richard Henderson
2013-04-04 22:56 ` [Qemu-devel] [PATCH v4 25/33] tcg-ppc64: Cleanup i32 constants to tcg_out_cmp Richard Henderson
2013-04-15 8:01 ` Aurelien Jarno
2013-04-04 22:56 ` [Qemu-devel] [PATCH v4 26/33] tcg-ppc64: Use TCGType throughout compares Richard Henderson
2013-04-04 22:56 ` [Qemu-devel] [PATCH v4 27/33] tcg-ppc64: Use MFOCRF instead of MFCR Richard Henderson
2013-04-15 8:02 ` Aurelien Jarno
2013-04-04 22:56 ` [Qemu-devel] [PATCH v4 28/33] tcg-ppc64: Use ISEL for setcond Richard Henderson
2013-04-15 8:13 ` Aurelien Jarno [this message]
2013-04-04 22:56 ` [Qemu-devel] [PATCH v4 29/33] tcg-ppc64: Implement movcond Richard Henderson
2013-04-04 22:56 ` [Qemu-devel] [PATCH v4 30/33] tcg-ppc64: Use getauxval for ISA detection Richard Henderson
2013-04-05 16:59 ` Richard Henderson
2013-04-15 8:13 ` Aurelien Jarno
2013-04-04 22:56 ` [Qemu-devel] [PATCH v4 31/33] tcg-ppc64: Implement add2/sub2_i64 Richard Henderson
2013-04-04 22:56 ` [Qemu-devel] [PATCH v4 32/33] tcg-ppc64: Implement mulu2/muls2_i64 Richard Henderson
2013-04-04 22:56 ` [Qemu-devel] [PATCH v4 33/33] tcg-ppc64: Handle deposit of zero Richard Henderson
2013-04-15 8:14 ` Aurelien Jarno
2013-04-13 12:24 ` [Qemu-devel] [PATCH v4 00/33] Modernize tcg/ppc64 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=20130415081349.GA11810@ohm.aurel32.net \
--to=aurelien@aurel32.net \
--cc=av1474@comtv.ru \
--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 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.