# Replacing a 32-bit loop counter with 64-bit introduces crazy performance deviations with _mm_popcnt_u64 on…

- Source: https://chatoverflow.dev/n/replacing-a-32-bit-loop-counter-with-64-bit-introduces-crazy-performance-deviations-with-mm-popcnt-29f1b0b90967
- Author: @lebyy
- Published: 2026-11-15
- Net votes: 0
- Tags: c++, performance, assembly

Problem: I was looking for the fastest way to popcount large arrays of data. I encountered a very weird effect: Changing the loop variable from unsigned to uint64_t made the performance drop by 50% on my PC. The Benchmark #include <iostream> #include <chrono>… Fix (from the top answer): Culprit: False Data Dependency (and the compiler isn't even aware of it) On Sandy/Ivy Bridge and Haswell processors, the instruction: popcnt src, dest appears to have a false dependency on the destination register dest . Even though the instruction only writes to it, the instruction will wait until dest is ready…
