February 1, 2026
Carry the drama, borrow the tea
Building Your Own Efficient uint128 in C++
Hand-rolled 128-bit number sparks nostalgia, pedantry, and 'just use the library' vibes
TLDR: A developer built a DIY 128-bit number type in C++ that performs like the built-in version, proving fixed-size math can be fast and predictable. Comments erupt over division tricks, a mysterious 564-bit choice, and whether to hand-roll code or just rely on modern compilers—cue nostalgia and spicy debates.
A dev just hand-built a 128-bit number type in C++ using two 64-bit chunks and special CPU instructions—and yes, it’s as fast as the built-in version. The author says it’s all about predictable, fixed-size math for real-world geometry and number crunching. Code receipts? They dropped the godbolt link.
Cue the comments: one engineer swooped in with a pre-JWT tale (JWT = JSON Web Token, a way to prove who you are online) of rolling their own UUID (unique ID) to handle RBAC (role-based access control) before OAuth (industry login standard) was cool. Meanwhile, an old-school crowd cheered, “This is giving 8-bit microcontroller vibes,” like retro gaming but for math. Then someone threw a curveball: why 564 bits? The thread spiraled into eyebrow-raises, byte math jokes, and “did they just pick a number and vibe?” energy.
The biggest drama: division. The post shrugs, “no neat code for division,” and Joker_vD instantly storms in with, “Wait, there is a trick,” igniting a mini flame war between DIY math purists and folks shouting “just use the compiler!” MSVC fans flexed that Microsoft already made 128-bit life easy, while others loved the low-level craft. Peak nerd soap opera, 10/10 entertainment.
Key Points
- •Defines a minimal unsigned 128-bit type as two 64-bit limbs and implements arithmetic via x64 intrinsics.
- •Achieves code generation comparable to builtin __uint128_t for add, sub, mul, and compare on Clang/GCC (with MSVC notes).
- •Uses _addcarry_u64 (adc) for addition and _subborrow_u64 (sbb) for subtraction; prefers intrinsics over inline assembly.
- •Argues for fixed-width integers over dynamic big-integer libraries when bounds are known for predictability and performance.
- •Demonstrates scalability: patterns extend to 192/256 bits, with production use of 256-bit and up to 564-bit integers.