3 ms·
There is also the effect of pipelining: AVX might be slower in terms of execution latency/bit. but if this algorithm can fill the entire chain than its speed in
by Coding_Cat 11y ago
There is also the effect of pipelining: AVX might be slower in terms of execution latency/bit. but if this algorithm can fill the entire chain than its speed in terms of throughput can still be greater.
For example: say popcnt takes 5 cycles from start to finish per word, and uses 1 execution unit (we will assume there is 1 of each type of EU, which isn't true). Then it can process at most 1/5th a word per cycle.
The AVX implementation might take 20 cycles from start to finish per word, but it uses 5 execution units in serial (each taking 4 cycles). Then when the first word passes the first stage (4 cycles later) the second word can be passed to stage 0. Then the throughput for larger strings becomes 1 word/4 cycles = 1/4th word per cycle. So 25% more throughput even though it's 4 times as slow when measured for a single word.
In real-life situations this can become quite a nightmare (or a fun little puzzle :]) if you need to intersperse this "popcnt" with multiple other operations.