From: James Greenhalgh <james.greenhalgh@arm.com>
To: Sam Tebbs <Sam.Tebbs@arm.com>
Cc: "gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>,
Marcus Shawcroft <Marcus.Shawcroft@arm.com>,
Richard Earnshaw <Richard.Earnshaw@arm.com>, nd <nd@arm.com>
Subject: Re: [GCC][PATCH v2][Aarch64] Exploiting BFXIL when OR-ing two AND-operations with appropriate bitmasks
Date: Tue, 28 Aug 2018 22:53:00 -0000 [thread overview]
Message-ID: <20180828225320.GE22590@arm.com> (raw)
In-Reply-To: <44d5392a-f033-ed0d-d679-116b3eafa0b9@arm.com>
On Wed, Aug 01, 2018 at 10:07:23AM -0500, Sam Tebbs wrote:
> Hi all,
>
> This patch adds an optimisation that exploits the AArch64 BFXIL
> instruction when or-ing the result of two bitwise and operations
> with non-overlapping bitmasks
> (e.g. (a & 0xFFFF0000) | (b & 0x0000FFFF)).
>
> Example:
>
> unsigned long long combine(unsigned long long a, unsigned long
> long b) {
> Â return (a & 0xffffffff00000000ll) | (b & 0x00000000ffffffffll);
> }
>
> void read(unsigned long long a, unsigned long long b, unsigned
> long long *c) {
> Â *c = combine(a, b);
> }
>
> When compiled with -O2, read would result in:
>
> read:
>  and  x5, x1, #0xffffffff
>  and  x4, x0, #0xffffffff00000000
>  orr  x4, x4, x5
>  str  x4, [x2]
> Â ret
>
> But with this patch results in:
>
> read:
>  mov   x4, x0
>  bfxil   x4, x1, 0, 32
>  str   x4, [x2]
> Â ret
>
> Bootstrapped and regtested on aarch64-none-linux-gnu and
> aarch64-none-elf with no regressions.
>
>
> gcc/
> 2018-08-01Â Sam Tebbs<sam.tebbs@arm.com>
>
> Â Â Â Â Â Â Â PR target/85628
> Â Â Â Â Â Â Â * config/aarch64/aarch64.md (*aarch64_bfxil):
> Â Â Â Â Â Â Â Define.
> Â Â Â Â Â Â Â * config/aarch64/constraints.md (Ulc): Define
> Â Â Â Â Â Â Â * config/aarch64/aarch64-protos.h
> (aarch64_is_left_consecutive): Define.
Hm, I'm not very sure about the naming here; "left consecutive" isn't a
common phrase to denote the mask you're looking for (exact_log2 (-i) != -1
if I'm reading right), and is misleading 0x0000ffff is 'left consecutive'
too, just with zeroes rather than ones.
> Â Â Â Â Â Â Â * config/aarch64/aarch64.c (aarch64_is_left_consecutive):
> New function.
>
> gcc/testsuite
> 2018-08-01Â Sam Tebbs<sam.tebbs@arm.com>
>
> Â Â Â Â Â Â Â PR target/85628
> Â Â Â Â Â Â Â * gcc.target/aarch64/combine_bfxil.c: New file.
> Â Â Â Â Â Â Â * gcc.target/aarch64/combine_bfxil_2.c: New file.
>
> diff --git a/gcc/config/aarch64/aarch64-protos.h b/gcc/config/aarch64/aarch64-protos.h
> index af5db9c595385f7586692258f750b6aceb3ed9c8..01d9e1bd634572fcfa60208ba4dc541805af5ccd 100644
> --- a/gcc/config/aarch64/aarch64-protos.h
> +++ b/gcc/config/aarch64/aarch64-protos.h
> @@ -574,4 +574,6 @@ rtl_opt_pass *make_pass_fma_steering (gcc::context *ctxt);
>
> poly_uint64 aarch64_regmode_natural_size (machine_mode);
>
> +bool aarch64_is_left_consecutive (HOST_WIDE_INT);
> +
> #endif /* GCC_AARCH64_PROTOS_H */
> diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c
> index fa01475aa9ee579b6a3b2526295b622157120660..3cfa51b15af3e241672f1383cf881c12a44494a5 100644
> --- a/gcc/config/aarch64/aarch64.c
> +++ b/gcc/config/aarch64/aarch64.c
> @@ -1454,6 +1454,14 @@ aarch64_hard_regno_caller_save_mode (unsigned regno, unsigned,
> return SImode;
> }
>
> +/* Implement IS_LEFT_CONSECUTIVE. Check if I's bits are consecutive
What is IS_LEFT_CONSECUTIVE - I don't see it elsewhere in the GCC code, so
what does the comment refer to implementing?
> + ones from the MSB. */
> +bool
> +aarch64_is_left_consecutive (HOST_WIDE_INT i)
> +{
> + return (i | (i - 1)) == HOST_WIDE_INT_M1;
exact_log2(-i) != HOST_WIDE_INT_M1?
I don't have issues with the rest of the patch; but please try to find a more
descriptive name for this.
Thanks,
James
next prev parent reply other threads:[~2018-08-28 22:53 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-01 15:07 Sam Tebbs
2018-08-28 12:28 ` Sam Tebbs
2018-08-28 22:53 ` James Greenhalgh [this message]
2018-08-30 15:54 ` Sam Tebbs
2018-08-31 10:59 ` Kyrill Tkachov
2018-08-31 15:27 ` Sam Tebbs
2018-08-31 15:37 ` Kyrill Tkachov
2018-08-31 15:51 ` Alexander Monakov
2018-08-31 16:39 ` Sam Tebbs
2018-09-04 15:13 ` Sam Tebbs
2018-09-11 15:20 ` James Greenhalgh
2018-09-13 9:49 ` Sam Tebbs
2018-09-13 9:57 ` Kyrill Tkachov
2018-09-18 22:26 ` Christophe Lyon
2018-09-19 9:42 ` Kyrill Tkachov
2018-09-20 16:37 ` Christophe Lyon
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=20180828225320.GE22590@arm.com \
--to=james.greenhalgh@arm.com \
--cc=Marcus.Shawcroft@arm.com \
--cc=Richard.Earnshaw@arm.com \
--cc=Sam.Tebbs@arm.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=nd@arm.com \
/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 read-only IMAP folder(s) and NNTP newsgroup(s).