From: Georg-Johann Lay <avr@gjlay.de>
To: Roger Sayle <roger@nextmovesoftware.com>, gcc-patches@gcc.gnu.org
Cc: 'Denis Chertykov' <chertykov@gmail.com>
Subject: Re: [AVR PATCH] Improvements to SImode and PSImode shifts by constants.
Date: Fri, 3 Nov 2023 19:28:23 +0100 [thread overview]
Message-ID: <e6262d74-873b-48d9-b2df-eae57141dfda@gjlay.de> (raw)
In-Reply-To: <026501da0d83$457b0d20$d0712760$@nextmovesoftware.com>
Am 02.11.23 um 12:54 schrieb Roger Sayle:
>
> This patch provides non-looping implementations for more SImode (32-bit)
> and PSImode (24-bit) shifts on AVR. For most cases, these are shorter
> and faster than using a loop, but for a few (controlled by optimize_size)
Maybe this should also adjust the insn costs, like in avr_rtx_costs_1?
Depending on what you are outputting, avr_asm_len() might be more
convenient.
What I am not sure about are the text cases that expect exact sequences
which might be annoying in the future?
Johann
> they are a little larger but significantly faster, The approach is to
> perform byte-based shifts by 1, 2 or 3 bytes, followed by bit-based shifts
> (effectively in a narrower type) for the remaining bits, beyond 8, 16 or 24.
>
> For example, the simple test case below (inspired by PR 112268):
>
> unsigned long foo(unsigned long x)
> {
> return x >> 26;
> }
>
> gcc -O2 currently generates:
>
> foo: ldi r18,26
> 1: lsr r25
> ror r24
> ror r23
> ror r22
> dec r18
> brne 1b
> ret
>
> which is 8 instructions, and takes ~158 cycles.
> With this patch, we now generate:
>
> foo: mov r22,r25
> clr r23
> clr r24
> clr r25
> lsr r22
> lsr r22
> ret
>
> which is 7 instructions, and takes ~7 cycles.
>
> One complication is that the modified functions sometimes use spaces instead
> of TABs, with occasional mistakes in GNU-style formatting, so I've fixed
> these indentation/whitespace issues. There's no change in the code for the
> cases previously handled/special-cased, with the exception of ashrqi3 reg,5
> where with -Os a (4-instruction) loop is shorter than the five single-bit
> shifts of a fully unrolled implementation.
>
> This patch has been (partially) tested with a cross-compiler to avr-elf
> hosted on x86_64, without a simulator, where the compile-only tests in
> the gcc testsuite show no regressions. If someone could test this more
> thoroughly that would be great.
>
>
> 2023-11-02 Roger Sayle <roger@nextmovesoftware.com>
>
> gcc/ChangeLog
> * config/avr/avr.cc (ashlqi3_out): Fix indentation whitespace.
> (ashlhi3_out): Likewise.
> (avr_out_ashlpsi3): Likewise. Handle shifts by 9 and 17-22.
> (ashlsi3_out): Fix formatting. Handle shifts by 9 and 25-30.
> (ashrqi3_our): Use loop for shifts by 5 when optimizing for size.
> Fix indentation whitespace.
> (ashrhi3_out): Likewise.
> (avr_out_ashrpsi3): Likewise. Handle shifts by 17.
> (ashrsi3_out): Fix indentation. Handle shifts by 17 and 25.
> (lshrqi3_out): Fix whitespace.
> (lshrhi3_out): Likewise.
> (avr_out_lshrpsi3): Likewise. Handle shifts by 9 and 17-22.
> (lshrsi3_out): Fix indentation. Handle shifts by 9,17,18 and 25-30.
>
> gcc/testsuite/ChangeLog
> * gcc.target/avr/ashlsi-1.c: New test case.
> * gcc.target/avr/ashlsi-2.c: Likewise.
> * gcc.target/avr/ashrsi-1.c: Likewise.
> * gcc.target/avr/ashrsi-2.c: Likewise.
> * gcc.target/avr/lshrsi-1.c: Likewise.
> * gcc.target/avr/lshrsi-2.c: Likewise.
>
>
> Thanks in advance,
> Roger
> --
>
prev parent reply other threads:[~2023-11-03 18:28 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-02 11:54 Roger Sayle
2023-11-03 18:28 ` Georg-Johann Lay [this message]
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=e6262d74-873b-48d9-b2df-eae57141dfda@gjlay.de \
--to=avr@gjlay.de \
--cc=chertykov@gmail.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=roger@nextmovesoftware.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).