Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Provide a builtin for population counting / hamming distance #10757
This feature was requested before #4988 but the bug was closed as WAI. I believe having popcnt part of standard library would benefit greatly many libraries.
For example there are two popcnt implementation in the golang tools:
These implementation are incomplete: the libraries provide assembly for one platform (amd64 in the best case), may not be not inlined (function call will dominate the benchmarks http://stackoverflow.com/questions/25471369/performance-discrepancy-in-compiled-vs-hand-written-assembly), are not well test, or are under a restrictive licence.
There is also a long standing bug #4816 which requests the POPCNT instruction on amd64. With POPCNT instruction population counting can be turned into a single instruction similarly to math.Sqrt (https://go-review.googlesource.com/#/c/8465/).
popcnt is very often used by chess, go (the game), checkers engines, all of them would benefit from a fast popcnt. #7357 provides another real word usage. Also a Go developer expressed his wish for popcnt (and other similar operations) to be provided by the standard library (https://go-review.googlesource.com/#/c/9761/1/src/cmd/internal/ssa/regalloc.go@41).