Re:Building Your Own Efficient uint128 in C++
by PaulDavisThe1st on Monday February 02, 2026 @12:55AM
(#46852880)
[ Parent
| on HN ]
Re:Building Your Own Efficient uint128 in C++
by cmovq on Monday February 02, 2026 @02:55AM
(#46853538)
Last time I checked LLVM had surprisingly bad codegen for this using int128. On x86 you only need two instructions:
__asm (
"mulq %[multiplier]\n"
"divq %[divisor]\n"
: "=a"(result)
: "a"(num), [multiplier]"r"(multiplier), [divisor]"r"(divisor)
: "rdx"
);
The intermediate 128bit number is in rdx:rax.