On Tue, Sep 01, 2026 at 02:26:38PM +0800, Ewan Young wrote:
> I see this went in as 8e483af5515 in the meantime -- thanks a lot for
> the commit and the credit!
>
> FWIW, the two um/div sites left out, int2um() and int2div(), turn out
> to be mixed rather than clean: clang 15 compiles the int16
> __builtin_sub_overflow() one instruction worse on the hot path, while
> gcc 12 does one better (neg + jo).
Please note that I'd be OK to look at this stuff again if we have
other similar opportunities. I am not really convinced by your
v2-0002. The other opportunities in v2-0001 could be reconsidered if
rewritten in a different way, but it's also tricky to evaluate due to
the with/without builtin and compiler requirements.
I would accept something that proves to be a net benefit in rather new
versions of gcc and clang, as well as a net benefit with/without the
builtin. 8e483af5515 was exactly that, with less or the same amount of
instructions (the cash change was super nice) for all setups I have
tested (Linux and macos).
--
Michael