code wiki / (root) / nx_chain_selfref_adversary.nx

nx_chain_selfref_adversary.nx

buildroot/runtime/nx_chain_selfref_adversary.nx

2465 B62 linesdepth 3pulls 3 transitivereach 0 importersview sourcekind tooltopic chain
docsdependenciesstructsconstsfunctions

about

nx_chain_selfref_adversary.nx -- T10 class: the SELF-REFERENTIAL chain-fusion miscompile. A loop-carried alloca updated by `z = z OP (z OP' c)` (BOTH operands read z) was chain-fused IN PLACE: the inner (z OP' c) mutated z's home register, so the outer OP read the destroyed z. Symptom: `z = z & (z-1)` (Brian Kernighan bit-clear) degraded to `z = z - 1` (decrement) -> popcount of 0xFF returned 255 not 8 -> nx_hw_cpu_count popcounted a 16-bit CPU mask to 510 -> every auto-sized thread pool spawned 510 workers (32x oversubscription). Fixed by the chain-scan guard: a chain step's src must not read the chained alloca. This adversary is the regression witness; exit 0 == all correct. license_tier: ORIGINAL No hw writes (Rule 26).

dependencies 1 imports · 0 importers

nx_syscalls_x86_64.nx nx_chain_selfref_adversary.nx

imports: nx_syscalls_x86_64.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main popcount popcount_swapped xor_lowmask and_plus1

structs

none

consts

12const K_MAGIC_65535: i64 = 65535
13const K_MAGIC_1024: i64 = 1024

functions

16func popcount(x: i64) -> i64
called by 1: main
23func popcount_swapped(x: i64) -> i64
called by 1: main
31func xor_lowmask(x: i64) -> i64
called by 1: main
37func and_plus1(x: i64) -> i64
called by 1: main
43func main() -> i64