From: Richard Henderson <rth@twiddle.net>
To: Bastian Koppelmann <kbastian@mail.uni-paderborn.de>,
qemu-devel@nongnu.org
Cc: peter.maydell@linaro.org
Subject: Re: [Qemu-devel] [PATCH 06/15] target-tricore: Add instructions of SRC opcode format
Date: Mon, 07 Jul 2014 13:06:10 -0700 [thread overview]
Message-ID: <53BAFDB2.7040200@twiddle.net> (raw)
In-Reply-To: <1404756822-3253-7-git-send-email-kbastian@mail.uni-paderborn.de>
On 07/07/2014 11:13 AM, Bastian Koppelmann wrote:
> +target_ulong helper_shac(CPUTRICOREState *env, target_ulong r1,
> + target_ulong r2)
Align the r2 argument properly.
> + shift_count = 0 - const6;
> + cond = r1 & 0x80000000;
> + if (cond != 0) {
> + msk = (((1 << shift_count) - 1) << (32 - shift_count));
> + } else {
> + msk = 0;
> + }
> + ret = msk | (r1 >> shift_count);
Surely using a normal signed right shift is easier here.
> +static int sign_extend(uint32_t val, uint32_t width)
> +{
> + int sval;
> + /* LSL. */
> + val <<= 31 - width;
> + sval = val;
> + /* ASR. */
> + sval >>= 31 - width;
> + return sval;
> +}
This is sextract32.
> +#define OP_COND(insn)\
> +static inline void gen_cond_##insn(int cond, TCGv r1, TCGv r2, TCGv r3, \
> + TCGv r4) \
> +{ \
> + int label = gen_new_label(); \
> + int label2 = gen_new_label(); \
> + \
> + tcg_gen_brcondi_tl(cond, r4, 0, label); \
> + tcg_gen_mov_tl(r3, r1); \
> + tcg_gen_br(label2); \
> + gen_set_label(label); \
> + tcg_gen_##insn ## _tl(r3, r1, r2); \
> + gen_set_label(label2); \
> +} \
Use tcg_gen_movcond_tl with the "insn" computation into a temporary.
> +static inline void gen_cond_mov(int cond, TCGv r1, TCGv r2, TCGv r3,
> + TCGv r4)
> +{
> + int label = gen_new_label();
> + int label2 = gen_new_label();
> +
> + tcg_gen_brcondi_tl(cond, r4, 0, label);
> + tcg_gen_mov_tl(r3, r1);
> + tcg_gen_br(label2);
> + gen_set_label(label);
> + tcg_gen_mov_tl(r3, r2);
> + gen_set_label(label2);
> +}
Use movcond.
> +static void gen_sh(TCGv ret, TCGv r1, TCGv r2)
> +{
> + int label, label2;
> + label = gen_new_label();
> + label2 = gen_new_label();
> + tcg_gen_brcondi_tl(TCG_COND_GE, r2, 0, label);
> + /* r1 >>(-r2) */
> + tcg_gen_shr_tl(ret, r1, r2);
> + tcg_gen_brcond_tl(TCG_COND_EQ, r2, r2, label2);
> + gen_set_label(label);
> + /* r1 << r2 */
> + tcg_gen_shl_tl(ret, r1, r2);
> + gen_set_label(label2);
The r2==r2 brcond is just silly. There's br (no cond) for that.
The branches are going to break most of the code that uses this, since TCG
temporaries not allocated with _local are discarded. And TCG temporaries
allocated *with* _local are more expensive, and thus best avoided when possible.
You'll be best off performing both shifts unconditionally and selecting the
correct result with movcond.
I do not see code to handle extracting the relevant bits from 0:5, nor perform
the required negation, nor handle the special case of -32 (resulting in zero),
nor are you examining the correct bit for the sign.
Note that the case of shift-by-32-equals-zero case can be handled easily, since
the 2's compliment negation is 1's compliment + 1. Thus the whole operation
can be implemented like
count = r2 & 31;
lret = r1 << count;
count = count ^ 31; /* one's complement of the field */
rret = r1 >> count; /* shr by count ... */
rret = r1 >> 1; /* ... + 1 */
neg = r2 & 32;
ret = neg ? rret : lret;
> +static void gen_shi(TCGv ret, TCGv r1, int32_t r2)
> +{
> + TCGv temp = tcg_const_i32(r2);
> + gen_sh(ret, r1, temp);
> + tcg_temp_free(temp);
> +}
You'd do well to examine the contents of the immediate here, performing the
checks at compile time that you'd perform at runtime in the fully variable
function above. While the TCG optimizer might be able to clean up the code,
shifts are common enough that it's worth the effort to do the right thing in
the first place.
> + case OPC1_16_SRC_ADD:
> + const16 = sign_extend(MASK_OP_SRC_CONST4(ctx->opcode), 3);
> + r1 = MASK_OP_SRC_S1D(ctx->opcode);
Surely this function can be improved by hoisting this computation. It's
identical for every entry, since they're all the same insn format. Note that
you can afford to compute both const16 and r2 at the top, even though only one
or the other will be used.
r~
next prev parent reply other threads:[~2014-07-07 20:06 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-07 18:13 [Qemu-devel] [PATCH 00/15] TriCore architecture guest implementation Bastian Koppelmann
2014-07-07 18:13 ` [Qemu-devel] [PATCH 01/15] target-tricore: Add target stubs and qom-cpu Bastian Koppelmann
2014-07-07 19:09 ` Richard Henderson
2014-07-07 19:14 ` Richard Henderson
2014-07-07 19:24 ` Peter Maydell
2014-07-11 11:05 ` Bastian Koppelmann
2014-07-11 11:10 ` Peter Maydell
2014-07-07 18:13 ` [Qemu-devel] [PATCH 02/15] target-tricore: Add board for systemmode Bastian Koppelmann
2014-07-07 18:13 ` [Qemu-devel] [PATCH 03/15] target-tricore: Add softmmu support Bastian Koppelmann
2014-07-07 18:13 ` [Qemu-devel] [PATCH 04/15] target-tricore: Add initialization for translation Bastian Koppelmann
2014-07-07 18:13 ` [Qemu-devel] [PATCH 05/15] target-tricore: Add masks and opcodes for decoding Bastian Koppelmann
2014-07-07 19:37 ` Richard Henderson
2014-07-07 18:13 ` [Qemu-devel] [PATCH 06/15] target-tricore: Add instructions of SRC opcode format Bastian Koppelmann
2014-07-07 20:06 ` Richard Henderson [this message]
2014-07-07 20:56 ` Max Filippov
2014-07-07 18:13 ` [Qemu-devel] [PATCH 07/15] target-tricore: Add instructions of SRR " Bastian Koppelmann
2014-07-07 20:17 ` Richard Henderson
2014-07-07 18:13 ` [Qemu-devel] [PATCH 08/15] target-tricore: Add instructions of SSR " Bastian Koppelmann
2014-07-07 20:22 ` Richard Henderson
2014-07-07 18:13 ` [Qemu-devel] [PATCH 09/15] target-tricore: Add instructions of SRRS and SLRO " Bastian Koppelmann
2014-07-07 20:30 ` Richard Henderson
2014-07-07 18:13 ` [Qemu-devel] [PATCH 10/15] target-tricore: Add instructions of SB " Bastian Koppelmann
2014-07-08 4:41 ` Richard Henderson
2014-07-07 18:13 ` [Qemu-devel] [PATCH 11/15] target-tricore: Add instructions of SBC and SBRN " Bastian Koppelmann
2014-07-08 4:47 ` Richard Henderson
2014-07-07 18:13 ` [Qemu-devel] [PATCH 12/15] target-tricore: Add instructions of SBR " Bastian Koppelmann
2014-07-08 5:26 ` Richard Henderson
2014-07-07 18:13 ` [Qemu-devel] [PATCH 13/15] target-tricore: Add instructions of SC " Bastian Koppelmann
2014-07-08 5:32 ` Richard Henderson
2014-07-07 18:13 ` [Qemu-devel] [PATCH 14/15] target-tricore: Add instructions of SLR, SSRO and SRO " Bastian Koppelmann
2014-07-08 5:36 ` Richard Henderson
2014-07-07 18:13 ` [Qemu-devel] [PATCH 15/15] target-tricore: Add instructions of SR " Bastian Koppelmann
2014-07-08 5:58 ` 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=53BAFDB2.7040200@twiddle.net \
--to=rth@twiddle.net \
--cc=kbastian@mail.uni-paderborn.de \
--cc=peter.maydell@linaro.org \
--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 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).