News for hackers. Stuff that matters.
Re:Optimizing a Bignum Library for Fun by rurban on Tuesday July 16, 2024 @03:29PM (#40979508)
For maximum efficiency you'd avoid addc like hell, because it blocks internal precomputation, and use guarantees like he did, avoiding overflow better. Better use int128 types though.

I'd just just stack objects for small typical sizes. And esp. do formal proofs than the random test joke.

Re:Optimizing a Bignum Library for Fun by minimize on Tuesday July 16, 2024 @04:12PM (#40979882)
> For maximum efficiency you'd avoid addc like hell, because it blocks internal precomputation, and use guarantees like he did, avoiding overflow better.

Whether that is the case depends on the CPU. I hit memory bandwidth limits before adc becomes a problem. But I concede that you have a valid point and that there are definitely cases where leaving sufficient space for carries is the better strategy.

Anyway, we can probably both agree that "% 1000000000" is not a great idea.

Re:Optimizing a Bignum Library for Fun by koverstreet on Tuesday July 16, 2024 @04:13PM (#40979884)
addc makes all your adds serialize on the flags register, which is really painful.

more modern approach is to reserve some bits out of every word for carries, but that drastically complicates things.

Re:Optimizing a Bignum Library for Fun by JonChesterfield on Tuesday July 16, 2024 @06:26PM (#40980900)
I remembered and ultimately found a source for a workaround for the serialising on flags problem, intel paper at https://web.archive.org/web/20150131061304/http://www.intel.... amounts to new instructions with better behaviour for ILP
Re:Optimizing a Bignum Library for Fun by haberman on Tuesday July 16, 2024 @08:15PM (#40981477)
Is this really true? I would expect that register renaming would apply to eflags too, so that reads from flags don't truly need to be serialized despite nominally writing a bunch of things to the same register.
Re:Optimizing a Bignum Library for Fun by phire on Wednesday July 17, 2024 @01:36PM (#40988294)
EFLAGS is actually put in the same renaming register as the result, so you get renaming for free.

The renaming registers in the Intel Pentium Pro and Pentium II are actually over 80 bits wide. They need to hold a full 80bit float, or 64bit MMX result. The Pentium III extends this to 128bit wide renaming registers to support SSE.

This is despite the fact that the P6 architecture only had 32bit bit integer registers until the Core 2 in 2006. So there is plenty of room to store EFLAGS in the same renaming register as the result. This also means that the branch uops point to the result of the most recent flag modifying instruction.

It was only with Sandybridge (and the introduction of AVX) that the P6 switched to a PRF design, with separate registers for floats and integers. Of course, Netburst also had a PRF design.

Re:Optimizing a Bignum Library for Fun by variadix on Wednesday July 17, 2024 @01:59PM (#40988551)