]> git.ipfire.org Git - thirdparty/gcc.git/commit
[committed] Improve shift loops on the H8
authorJeff Law <jlaw@ventanamicro.com>
Fri, 19 Dec 2025 17:13:24 +0000 (10:13 -0700)
committerJeff Law <jlaw@ventanamicro.com>
Fri, 19 Dec 2025 17:15:23 +0000 (10:15 -0700)
commit38d15216dbff426747b860e5e2e12f8f9ec60de2
tree69f81944569f8878e2b8333daed3f42d59e9b174
parenta6687d123301287a26c09073d360bc2d93176666
[committed] Improve shift loops on the H8

Inspired by Georg-Johann's work on the AVR to convert the shift loops to a
sentinel approach and a rough work week, I revisited the shift patterns on the
H8 to see if we could improve things on that port as well.  It also serves as a
good verification that things are working in my environment.

The basic idea of Georg-Johann's patch is to clear the bits that are going to
be shifted away, then turn on a sentinel bit (the last shifted away bit).  This
is done outside the loop.  The loop then iterates until the sentinel bit shows
up in C.  This eliminates decrementing the loop counter and better performance.

It turns out to be fairly easy to implement on the H8.  The first
implementation did the clearing and setting in the most simplistic way
possible, but to avoid significant code size regressions the clearing and
setting really needed to be handled by output_logical_op which has several
short cuts.  So a bit of adjustment was necessary to make output_logical_op
callable from other contexts.

Second the H8/S and newer parts have shift-by-2 instructions.  These aren't
normally used in shift loops unless we're optimizing for size.  This requires
slight adjustment of the sentinel location for odd shift counts.  The residual
single bit shift for that case is handled outside the loop.

Otherwise it's an uneventful patch.  My hope was that it will save a minuscule
amount of testing time as the H8 continues to be the slowest cross target for
testing. Hard to judge that right now -- while the latest run on the H8 was
about 30 minutes faster than any run in the last month, the machine was
unloaded for that run while it was fully loaded for the standard nightly runs.
If this even approaches 1% I'll jump for joy.

Anyway, tested on the H8 with no regressions.  Given the H8 is a dead ISA with
very few users, I'm going to go ahead and commit even though we're in stage3.

gcc/
* config/h8300/h8300.cc (output_logical_op): Adjust last argument to
be a pattern, not an insn.  Corresponding implementation changes.
(output_shift_loop): Extracted from output_a_shift and improved
to use a sentinel to indicate when to stop the loop.
(output_a_shift): Use output_shift_loop.
(compute_a_shift_length): Handle adjusted shift loop code.
* config/h8300/logical.md (logicals): Pass pattern to output_logical_op
rather then the full insn.
* config/h8300/h8300-protos.h (output_logical_op): Update prototype.
gcc/config/h8300/h8300-protos.h
gcc/config/h8300/h8300.cc
gcc/config/h8300/logical.md