pretty flag
Conversation
Replying to
On the contrary, this aims at obtaining from GCC the constants that allow to implement these divisions as multiplications… in a context where the numbers to divide could have been represented as BCD, and then division would be trivial, but they weren't.
1
5
There's a great blog post on generating them yourself. We explored doing it in musl ldso to perform the % operation for hash lookups. I'll try to find link if you're interested.
2
3
There's an even faster way to do 32-bit mod, for cases like that hash example:
arxiv.org/pdf/1902.01961
github.com/lemire/fastmod
2
7
It looks like it depends on __int128_t, which is a non-starter. The whole point is that 32-bit div/mod is a _function call_ on some archs; these certainly don't have 64x64->128 mul or full 128 mul.
2
1
That can be implemented fairly efficiently via 64-bit integer operations though. GCC / Clang provide a decent 64-bit int on 32-bit and 128-bit on 64-bit in software. It could be open coded too. It's going to make an even bigger difference if there's no hardware mod / div at all.
Well it was measured as making no difference or even negative benefit (probably cache effects to access the constants for each lib) on archs with division. So the *only* interesting case was archs with sw-only div...
1
And in that case, the classic mul & shift approach is going to work better than anything requiring emulation of 64x64->128 muls.



