https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128111
Bug ID: 128111
Summary: Add support for __builtin_clmulg
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: middle-end
Assignee: unassigned at gcc dot gnu.org
Reporter: jakub at gcc dot gnu.org
Target Milestone: ---
https://wg21.link/P3642R7 proposes addition of wi::clmul and wi::widening_clmul
function templates, we need some underlying builtin because lots of backends
can handle those in various ISAs natively and there are various optimizations
possible on those too (some mentioned in the paper).
While clang 23 has __builtin_elementwise_clmul for this, I don't buy much into
their elementwise naming and much more importantly, it can deal only with the
non-widening cases, not the widening ones (unless arguments are promoted to
twice as large types).
Now, if there are twice as large types, that is one possibility, but there are
cases where there are no such types, e.g. std::widening_clmul (ull_var1,
ull_var2) on 32-bit targets, or std::widening_clmul (uint128_var1,
uint128_var2) on 64-bit targets, or
std::widening_clmul (bitint_BITINT_MAXWIDTH_var1, bitint_BITINT_MAXWIDTH_var2)
etc. (for unsigned _BitInt anything larger than BITINT_MAXWIDTH / 2).
So, I'm proposing instead __builtin_clmulg type-generic builtin, which can be
called as
T __builtin_clmulg (T, T) or T __builtin_clmulg (T, T, T *) where T is some
unsigned integer type, the latter stores the most significant bits of the
result to what the last argument points at.