From: Richard Henderson <richard.henderson@linaro.org>
To: Paolo Bonzini <pbonzini@redhat.com>, qemu-devel@nongnu.org
Subject: Re: [PATCH 07/14] target/i386: optimize computation of ZF from CC_OP_DYNAMIC
Date: Sun, 20 Oct 2024 13:18:15 -0700 [thread overview]
Message-ID: <bf2c054f-8664-41cd-9041-795adac25d2e@linaro.org> (raw)
In-Reply-To: <20241020155324.35273-8-pbonzini@redhat.com>
On 10/20/24 08:53, Paolo Bonzini wrote:
> Most uses of CC_OP_DYNAMIC are for CMP/JB/JE or similar sequences.
> We can optimize many of them to avoid computation of the flags.
> This eliminates both TCG ops to set up the new cc_op, and helper
> instructions because evaluating just ZF is much cheaper.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> target/i386/helper.h | 1 +
> target/i386/tcg/cc_helper.c | 20 ++++++++++++++++++++
> target/i386/tcg/translate.c | 10 +++++++---
> 3 files changed, 28 insertions(+), 3 deletions(-)
>
> diff --git a/target/i386/helper.h b/target/i386/helper.h
> index eeb8df56eaa..3f67098f11f 100644
> --- a/target/i386/helper.h
> +++ b/target/i386/helper.h
> @@ -1,5 +1,6 @@
> DEF_HELPER_FLAGS_4(cc_compute_all, TCG_CALL_NO_RWG_SE, tl, tl, tl, tl, int)
> DEF_HELPER_FLAGS_4(cc_compute_c, TCG_CALL_NO_RWG_SE, tl, tl, tl, tl, int)
> +DEF_HELPER_FLAGS_3(cc_compute_nz, TCG_CALL_NO_RWG_SE, tl, tl, tl, int)
>
> DEF_HELPER_3(write_eflags, void, env, tl, i32)
> DEF_HELPER_1(read_eflags, tl, env)
> diff --git a/target/i386/tcg/cc_helper.c b/target/i386/tcg/cc_helper.c
> index 40583c04cf9..c24e6a14c07 100644
> --- a/target/i386/tcg/cc_helper.c
> +++ b/target/i386/tcg/cc_helper.c
> @@ -95,6 +95,26 @@ static target_ulong compute_all_adcox(target_ulong dst, target_ulong src1,
> return (src1 & ~(CC_C | CC_O)) | (dst * CC_C) | (src2 * CC_O);
> }
>
> +target_ulong helper_cc_compute_nz(target_ulong dst, target_ulong src1,
> + int op)
> +{
> + target_ulong mask;
> +
> + if (CC_OP_HAS_EFLAGS(op)) {
> + return ~src1 & CC_Z;
> + } else {
> + MemOp size = cc_op_size(op);
> +
> + if (size == MO_TL) {
> + /* Avoid shift count overflow when computing the mask below. */
> + return dst;
> + }
> +
> + mask = (1ull << (8 << size)) - 1;
FWIW, MAKE_64BIT_MASK(0, 8 << size) does not have the overflow problem.
r~
next prev parent reply other threads:[~2024-10-20 20:19 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-20 15:53 [PATCH 00/14] target/i386: miscellaneous flags improvements Paolo Bonzini
2024-10-20 15:53 ` [PATCH 01/14] target/i386: use tcg_gen_ext_tl when applicable Paolo Bonzini
2024-10-20 19:50 ` Richard Henderson
2024-10-20 15:53 ` [PATCH 02/14] target/i386: Tidy cc_op_str usage Paolo Bonzini
2024-10-20 15:53 ` [PATCH 03/14] target/i386: remove CC_OP_CLR Paolo Bonzini
2024-10-20 19:55 ` Richard Henderson
2024-10-20 15:53 ` [PATCH 04/14] target/i386: Rearrange CCOp Paolo Bonzini
2024-10-20 15:53 ` [PATCH 05/14] target/i386: Introduce cc_op_size Paolo Bonzini
2024-10-20 15:53 ` [PATCH 06/14] target/i386: Wrap cc_op_live with a validity check Paolo Bonzini
2024-10-20 20:05 ` Richard Henderson
2024-10-20 15:53 ` [PATCH 07/14] target/i386: optimize computation of ZF from CC_OP_DYNAMIC Paolo Bonzini
2024-10-20 20:18 ` Richard Henderson [this message]
2024-10-20 15:53 ` [PATCH 08/14] target/i386: optimize TEST+Jxx sequences Paolo Bonzini
2024-10-20 20:19 ` Richard Henderson
2024-10-20 15:53 ` [PATCH 09/14] target/i386: add a few more trivial CCPrepare cases Paolo Bonzini
2024-10-20 20:23 ` Richard Henderson
2024-10-20 15:53 ` [PATCH 10/14] target/i386: add a note about gen_jcc1 Paolo Bonzini
2024-10-20 15:53 ` [PATCH 11/14] target/i386: make flag variables unsigned Paolo Bonzini
2024-10-20 20:26 ` Richard Henderson
2024-10-20 15:53 ` [PATCH 12/14] target/i386: use builtin popcnt or parity to compute PF, if available Paolo Bonzini
2024-10-20 20:40 ` Richard Henderson
2024-10-20 15:53 ` [PATCH 13/14] target/i386: use higher-precision arithmetic to compute CF Paolo Bonzini
2024-10-20 15:53 ` [PATCH 14/14] target/i386: use + to put flags together Paolo Bonzini
-- strict thread matches above, loose matches on Subject: below --
2024-10-28 15:18 [PATCH v2 00/14] target/i386: miscellaneous flags improvements Paolo Bonzini
2024-10-28 15:18 ` [PATCH 07/14] target/i386: optimize computation of ZF from CC_OP_DYNAMIC Paolo Bonzini
2024-10-29 15:43 ` 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=bf2c054f-8664-41cd-9041-795adac25d2e@linaro.org \
--to=richard.henderson@linaro.org \
--cc=pbonzini@redhat.com \
--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).