Skip to content

modexp: GCC 15 and 16 keep the addmul() product in a stack slot #1801

Closed

Description

@chfast

With GCC 15, which CodSpeed uses since #1798, modexp<expmod_execute_evmone>[mod_len:32/mod_tz:254/exp_bits:256] is 16% slower than with GCC 14 (0.84x), and master runs 9% more instructions on it (135k vs 124k per call).

The difference is in the addmul() loop inlined into modexp_pow2(). GCC 15 and 16 keep the uint128 product of umul() in a stack slot, storing and reloading it in every iteration (16 instructions per word instead of 12):

mul    %r12
mov    %rax,(%rsp)
mov    %rdx,0x8(%rsp)
mov    (%rsp),%rdx
add    (%rdi,%rcx,8),%rdx
...
mov    0x8(%rsp),%rsi

GCC 14 keeps the product in registers on master, but compiles the same loop into this code after unrelated changes, e.g. the INTX_REQUIRE hints of #1794. A fix could keep the product in registers explicitly in addmul().

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions