Documentation ¶
Overview ¶
Positional population counts.
This package contains a set of functions to compute positional population counts for arrays of uint8, uint16, uint32, or uint64. Optimised assembly optimisations are provided for amd64 (AVX-512, AVX2, SSE2), 386 (AVX2, SSE2), and ARM64 (NEON). An optimal implementation constrainted by the instruction set extensions available on your CPU is chosen automatically at runtime. If no assembly implementation exists, a generic fallback implementation will be used. The pospop package thus works on all architectures supported by the Go toolchain.
The kernels works on a block size of 240, 480, or 960 bytes. A buffer size that is a multiple of 64 bytes and at least 10 kB in size is recommended. The author's benchmarks show that a buffer size around 100 kB appears optimal.
See the example on the Count8 function for what the positional population count operation does.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Count16 ¶
Count the number of corresponding set bits of the values in buf and add the results to counts. Each element of counts keeps track of a different place; counts[0] for 0x0001, counts[1] for 0x0002, and so on to counts[15] for 0x8000.
func Count32 ¶
Count the number of corresponding set bits of the values in buf and add the results to counts. Each element of counts keeps track of a different place; counts[0] for 0x0000001, counts[1] for 0x00000002, and so on to counts[31] for 0x80000000.
func Count64 ¶
Count the number of corresponding set bits of the values in buf and add the results to counts. Each element of counts keeps track of a different place; counts[0] for 0x000000000000001, counts[1] for 0x0000000000000002, and so on to counts[63] for 0x8000000000000000.
func Count8 ¶
Count the number of corresponding set bits of the bytes in buf and add the results to counts. Each element of counts keeps track of a different place; counts[0] for 0x01, counts[1] for 0x02, and so on to counts[7] for 0x80.
Example ¶
This example illustrates the positional population count operation. For each number in the input, Count8() checks which of its bits are set and increments the corresponding counters. In this example, four numbers (1, 3, 5, 9) have bit 0 set; three numbers (2, 3, 6) have bit 1 set, two numbers (5, 6) have bit 2 set and only the number 9 has bit 3 set.
var counts [8]int numbers := []uint8{ 1, // bit 0 set 2, // bit 1 set 3, // bits 0 and 1 set 5, // bits 0 and 2 set 6, // bits 1 and 2 set 9, // bits 0 and 3 set } Count8(&counts, numbers) fmt.Println(counts)
Output: [4 3 2 1 0 0 0 0]
Types ¶
This section is empty.