News for hackers. Stuff that matters.
Re:Building Your Own Efficient uint128 in C++ by ThatGuyRaion on Sunday February 01, 2026 @11:40PM (#46852469)
I suppose that makes sense -- though SIMD seems more useful for accelerating a lot of crypto?
Re:Building Your Own Efficient uint128 in C++ by sparkie on Monday February 02, 2026 @12:10AM (#46852651)
SIMD is for performing parallel operations on many smaller types. It doesn't necessarily help when performing single arithmetic operations on larger types. (Though it does help when performing logic and shift operations on full vector registers).

If we were performing 128-bit arithmetic in parallel over many values, then a SIMD implementation may help, but without a SIMD equivalent of `addcarry`, there's a limit to how much it can help.

Something like this could potentially be added to AVX-512 for example by utilizing the `k` mask registers for the carries.

The best we have currently is `adcx` and `adox` which let us perform arithmetic on two 128-bit values simultaniously, where one utilizes the carry flag and the other utilizes the overflow flag.

Re:Building Your Own Efficient uint128 in C++ by wahern on Monday February 02, 2026 @03:16AM (#46853669)
> but It doesn't necessarily help when performing single arithmetic operations on larger types.

For the curious, AFAIU the problem is the dependency chains. For example, for simple bignum addition you can't just naively perform all the adds on each limb in parallel and then apply the carries in parallel; the addition of each limb depends on the carries from the previous limbs. Working around these issues with masking and other tricks typically ends up adding too many additional operations, resulting in lower throughput than non-SIMD approaches.

There's quite a few papers on using SIMD to accelerate bignum arithmetic for single operations, but they all seem quite complicated and heavily qualified. The threshold for eeking out any gain is quite high, e.g. minimum 512-bit numbers or much greater, depending. And they tend to target complex or specialized operations (not straight addition, multiplication, etc) where clever algebraic rearrangements can profitably reorder dependency chains for SIMD specifically.