Re: Speed up KConfig - fix hashtable confusion
From: Linus Torvalds
Date: Mon Nov 02 2026 - 13:21:13 EST
On Mon, 2 Nov 2026 at 01:47, David Laight <david.laight.linux@xxxxxxxxx> wrote:
>
> An alternative would be:
> ((key) * (u64)(size)) >> 32
> which avoids the division when size isn't a constant power of 2.
That's certainly cleaner
Not that it should matter - afaik the size is always a constant (it
comes from 'sizeof()'), and I would actually prefer it if
HASHTABLE_DECLARE and HASHTABLE_DEFINE took the number of *bits* (like
DECLARE_HASHTABLE() does for the kernel proper), and we'd just make it
a rule that it's always a power-of-2.
It already *is* always a power-of-two, and the old code used to make
it a slow modulus operation if it wasn't.
I'd also worry a tiny bit about what the compilers do on 32-bit
targets, although obviously hopefully (a) they'd optimize it to the
right 32-bit code rather than do 64-bit ops and (b) it's not like we
seriously care about 32-bit host builds anyway.
Linus