GCC Newspaper
NOVEMBER 30, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
middle-end Performance Win

Introduce GCC builtin for carry-less multiplication (clmul).

GCC adds `__builtin_clmulg` to support carry-less multiplication, including widening operations.

GCC introduces a new intrinsic function, __builtin_clmulg, to support carry-less multiplication (clmul). This builtin is designed to align with C++23’s std::clmul and std::widening_clmul proposals. It handles both standard and widening carry-less multiplications, with the latter being crucial for targets like x86 that have specialized instructions for larger-than-operand-size results. The builtin is type-generic and handles potential type-width limitations on different architectures.

In Details

To support the upcoming C++23 std::clmul and std::widening_clmul, GCC introduces the __builtin_clmulg intrinsic. Unlike Clang's __builtin_elementwise_clmul, this builtin explicitly supports widening carry-less multiplication (e.g., 64x64->128 bits), which is essential for certain hardware instructions and the standard. It takes two or three arguments: two operands for standard clmul, or two operands and a pointer for the result of widening clmul, storing the upper bits there. This addresses type-width limitations on various targets by providing a flexible interface.

For Context
carry-less multiplication
A type of multiplication where the carry bits are discarded during the addition of partial products. It's often used in cryptography and error correction codes.
builtin
A function provided by the compiler that is not part of the standard language but is recognized and optimized by the compiler, often mapping directly to specific hardware instructions.
widening_clmul
A carry-less multiplication operation where the result is twice the bit-width of the operands, for example, multiplying two 64-bit numbers to produce a 128-bit result.
x86
A family of instruction set architectures developed by Intel, widely used in desktop and server computers.
intrinsic
A function or operation that the compiler recognizes and can translate into specific machine instructions, often providing direct access to hardware features.
_BitInt
A GCC extension for arbitrary-precision integer types, allowing the specification of integer types with a specific number of bits.
Filed Under: compilerbuiltinoptimizationc++i386