On Fri, Apr 03, 2026 at 12:13:36AM +0200, Bruno Haible wrote: > Hi Eric, > > > multiplying by the inverse of the golden ratio, and then taking the > > high bits of the result with a shift, narrowing of a 32- or 64-bit > > hash value down to the power-of-two number of buckets can be done more > > efficiently than computing the remainder of a division by a prime > > number. > > This was true until ca. 1990. Since then, the CPUs have fast multiplication > and division instructions for integers. A remainder operation is fast > nowadays.
Still, I think benchmarks can demonstrate that divisions are slower than multiplies. > > > > which looks like it will mis-behave when handed an even number. > > You are confusing the next_prime() function with the is_prime() function. > > The next_prime() function has its specification in lib/next-prime.h, > and it does *not* require that the argument be an odd number. Indeed, I missed that on my first read; I was focusing on the only comment, without also realizing that two functions were present, where the comment was on the internal helper rather than the public entry point. -- Eric Blake, Principal Software Engineer Red Hat, Inc. Virtualization: qemu.org | libguestfs.org
