Skip to content

Fix infinite loop in get_excitation_degree_c with AVX-512 - #432

Merged
scemama merged 1 commit into
QuantumPackage:dev-stablefrom
michelcaffarel-hub:fix_avx512_excitation_degree
Nov 25, 2026
Merged

scemama merged 1 commit into
QuantumPackage:dev-stablefrom
michelcaffarel-hub:fix_avx512_excitation_degree

Conversation

@michelcaffarel-hub

Copy link
Copy Markdown

Segmentation fault in get_excitation_degree_c on AVX-512 machines

In the AVX-512 path, the loop bound is

for (; i <= (n >= 8 ? n - 8 : -1); i += 8) {

n and i are size_t, so for n = 2*Nint < 8 (Nint < 4) the -1 is converted to SIZE_MAX: the loop never ends and reads out of bounds. The remainder is already handled by the masked operation after the loop, so the bound can be written i + 8 <= n.

Found when running on Intel Xeon 6952P nodes (GCC 12.3, -march=native) with Nint = 2: segmentation fault in get_excitation_degree_c, called by i_H_j.

Check with a small test program on that machine (GCC 12.3, -O2 -march=native), comparing with a scalar popcount for Nint = 1 to 12 and 2000 random pairs each: the current code crashes, the fixed code gives no error in 24000 comparisons. The full test suite was not run.

🤖 Generated with Claude Code

When n = 2*Nint < 8, the bound (n >= 8 ? n - 8 : -1) is converted to
size_t, so that -1 becomes SIZE_MAX and the loop reads out of bounds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@scemama
scemama merged commit 45d4cb5 into QuantumPackage:dev-stable Nov 25, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants