Alvaro Herrera <alvhe...@2ndquadrant.com> writes: > Hah, I just realized you have to add -mlzcnt in order for these builtins > to use the lzcnt instructions. It goes from something like
> bsrq %rax, %rax > xorq $63, %rax > to > lzcntq %rax, %rax > Significant? I'd bet a fair amount of money that we'd be better off *not* using lzcnt, even if available, because then we could just expose things along this line: static inline int pg_clz(...) { #ifdef HAVE__BUILTIN_CLZ return __builtin_clz(x); #else handwritten implementation; #endif } Avoiding a function call (that has to indirect through a pointer) probably saves much more than the difference between lzcnt and the other way. The tradeoff might be different for popcount, though, especially since it looks like __builtin_popcount() is not nearly as widely available as the clz/ctz builtins. regards, tom lane