<p dir="auto">This feature was requested before <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="51282947" data-permission-text="Title is private" data-url="https://github.com/golang/go/issues/4988" data-hovercard-type="issue" data-hovercard-url="/golang/go/issues/4988/hovercard" href="https://github.com/golang/go/issues/4988">#4988</a> but the bug was closed as WAI. I believe having popcnt part of standard library would benefit greatly many libraries.</p>
<p dir="auto">For example there are two popcnt implementation in the golang tools:<br>
<a href="https://github.com/golang/go/blob/dev.ssa/src/cmd/internal/ssa/regalloc.go#L39">https://github.com/golang/go/blob/dev.ssa/src/cmd/internal/ssa/regalloc.go#L39</a><br>
<a href="https://github.com/golang/tools/blob/master/container/intsets/util.go#L22">https://github.com/golang/tools/blob/master/container/intsets/util.go#L22</a></p>
<p dir="auto">It is also provided by several third party libraries<br>
<a href="http://go-search.org/search?q=popcnt" rel="nofollow">http://go-search.org/search?q=popcnt</a><br>
<a href="http://go-search.org/search?q=popcount" rel="nofollow">http://go-search.org/search?q=popcount</a></p>
<p dir="auto">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 <a href="http://stackoverflow.com/questions/25471369/performance-discrepancy-in-compiled-vs-hand-written-assembly" rel="nofollow">http://stackoverflow.com/questions/25471369/performance-discrepancy-in-compiled-vs-hand-written-assembly</a>), are not well test, or are under a restrictive licence.</p>
<p dir="auto">There is also a long standing bug <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="51282683" data-permission-text="Title is private" data-url="https://github.com/golang/go/issues/4816" data-hovercard-type="issue" data-hovercard-url="/golang/go/issues/4816/hovercard" href="https://github.com/golang/go/issues/4816">#4816</a> which requests the POPCNT instruction on amd64. With POPCNT instruction population counting can be turned into a single instruction similarly to math.Sqrt (<a href="https://go-review.googlesource.com/#/c/8465/" rel="nofollow">https://go-review.googlesource.com/#/c/8465/</a>).</p>
<p dir="auto">popcnt is very often used by chess, go (the game), checkers engines, all of them would benefit from a fast popcnt. <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="51286587" data-permission-text="Title is private" data-url="https://github.com/golang/go/issues/7357" data-hovercard-type="issue" data-hovercard-url="/golang/go/issues/7357/hovercard" href="https://github.com/golang/go/issues/7357">#7357</a> 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 (<a href="https://go-review.googlesource.com/#/c/9761/1/src/cmd/internal/ssa/regalloc.go@41" rel="nofollow">https://go-review.googlesource.com/#/c/9761/1/src/cmd/internal/ssa/regalloc.go@41</a>).</p>
<p dir="auto">by <strong>fuzxxl</strong>:</p>
<pre class="notranslate">The Popcount (or hammington weight) is a function that determines the number of one-bits
in an integer. This function is useful for cryptographic applications and certain data
structures. As it is possible to implement this function efficiently with special
instructions (VCNT on ARM7 and POPCOUNT on amd64 since SSE 4.2), it would be nice to
have this function in the standard library.</pre>