[libcxx] r275114 - Don't compute modulus of hash if it is smaller than the bucket count.

Joerg Sonnenberger via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 18 04:28:46 PDT 2016


On Sun, Jul 17, 2016 at 01:54:57PM -0700, Arthur O'Dwyer via cfe-commits wrote:
> IMHO, if replacing "%" with "fastmod" in general-purpose code like this
> were a good idea,
> (A) libc++ should introduce a helper function __fastmod(m,n) for the
> purpose, not repeat the same patch everywhere there's currently a "%"
> operator; and/or
> (B) someone with authority over the Clang x86 backend
> (*cough*Chandler*cough*) should look into improving the codegen for "%" by
> auto-detecting when it might make sense to use this heuristic.

As I mentioned to Eric, the better idea is likely to just precompute the
multiplicative inverse and shift and just use the two multiplication
version instead. At least for compilers with basic uint128_t support or
on 32bit platforms, that's a definite win. It's not an optimisation the
compiler can do as it requires additional storage.

Joerg


More information about the cfe-commits mailing list