Detect popcnt instruction at runtime, use it if available.
authorTudor Bosman <tudorb@fb.com>
Wed, 8 Aug 2012 17:39:47 +0000 (10:39 -0700)
committerTudor Bosman <tudorb@fb.com>
Wed, 8 Aug 2012 22:40:42 +0000 (15:40 -0700)
commit7fd87e7e86bb78dc693da2111bf915761346d540
treed2c724a1d69c48567c1840905f426cb3b24b9e61
parent192cff5da4fedc44707e34c9a7e0dc8ddc4e5eb7
Detect popcnt instruction at runtime, use it if available.

Summary:
If compiled for a popcnt-supporting target (-march=corei7, for example),
use __builtin_popcount, as it's presumably inlined.  Otherwise, detect
on startup (in the same way as glibc dispatches to one of the many
flavors of memcpy): GCC allows us to add a resolver function which the
dynamic loader will call on startup to resolve a function to one of
various alternatives; we check (using the cpuid instruction) whether
popcnt is supported, and use it if available.

Test Plan: tests added

Reviewed By: soren@fb.com

FB internal diff: D542977
folly/Bits.cpp [new file with mode: 0644]
folly/Bits.h
folly/CpuId.h [new file with mode: 0644]
folly/detail/BitsDetail.h [new file with mode: 0644]
folly/experimental/Bits.h
folly/test/BitsTest.cpp
folly/test/CpuIdTest.cpp [new file with mode: 0644]