Improve many SImode shifts on the H8/300H
authorJeff Law <jlaw@localhost.localdomain>
Sun, 15 Aug 2021 04:13:23 +0000 (00:13 -0400)
committerJeff Law <jlaw@localhost.localdomain>
Sun, 15 Aug 2021 04:15:32 +0000 (00:15 -0400)
commit882f1d58bfa56737ff2de84c3cd1e0acfc318b86
tree53e5b9a5e8befa1037ebf41d9616656715f7c433
parent829931ec93ab7d5ab73f31be9da504abb6ae459e
Improve many SImode shifts on the H8/300H

As I've mentioned before, the H8/300H can only shift a single bit position at a time.  Naturally this means many shifts are implemented as loops.  There's a variety of special cases that we can do without loops by using rotates, sub-word moves, etc.  The general guidance for the port has been to only use inline or special sequences if they're shorter or just one instruction longer than the loop.

This was pretty reasonable guidance for QI/HI mode.  It was relaxed a bit about 10 years ago for HImode in particular where the kpit team realized they could save 50-100 cycles for some shifts by allowing 2 instructions of code growth over the loop implementation.

But they only re-tuned HImode shifts.  There's even bigger benefits for re-tuning SImode shifts.  There's cases where we can save close to 200 cycles by allowing 2 additional instructions.

This patch re-tunes SImode shifts on the H8/300H primarily by inlining more often or using a special sequence + inlining for residuals.  Both cases were already supported and this just uses those existing capabilities more often, so it was trivial to implement.  I think there's some cases were entirely new special sequences could be used, but I haven't tried those yet.

gcc/

* config/h8300/h8300.c (shift_alg_si): Retune H8/300H shifts
to allow a bit more code growth, saving many dozens of cycles.
(h8300_option_override): Adjus shift_alg_si if optimizing for
code size.
(get_shift_alg): Use special + inline shifts for residuals
in more cases.
gcc/config/h8300/h8300.c