Hard
A popcnt reduction loop before and after adding `xor eax, eax`
On an Intel Haswell or Skylake core, popcnt has 3-cycle latency and a throughput of one per cycle on port 1. This loop sums population counts over an array resident in L1D, and it measures about 3 cycles per iteration, roughly twice what its uop count on a 4-wide front end predicts. Inserting xor eax, eax immediately before the popcnt brings it well under 2 cycles per iteration, despite adding an instruction. What explains both observations?
.loop:
popcnt rax, qword ptr [rdi + rcx*8]
add rdx, rax
inc rcx
cmp rcx, rsi
jb .loop45 of 47 in Computer Architecture