Files
LibretroAdmin f46db3577e state_manager: AVX-512BW rewind scans, line-aligned blocks, per-tier codec
Rewind diffing (find_change for the next dirty word, find_same for the
end of a dirty run) gains an AVX-512BW tier next to SSE2 and AVX2, and
find_same gets the AVX2 form it lacked. Tiers are picked once from
cpu_features_get(); RETRO_SIMD_AVX512 promises BW.

Three things make the wide scans pay off rather than lose to SSE2:

- The two blocks are now 64-byte aligned and a whole number of lines
  apart, so a scan position has the same offset within a line in both.
  The wide loops step back to a line boundary inside bytes already
  proven equal, and from there no load straddles a cache line on
  either block. Before this, AVX-512 lost to SSE2 on dirty states.

- Each scan starts narrow (16 bytes, then 32) and only then goes to
  full width, since most scans in a dirty state end within the first
  few words.

- raw_compress is compiled once per tier with the scans inlined. A
  target function cannot inline into baseline code, and a call per
  scan cost more than the scan on dirty states.

All tiers write byte-identical patches. Median time against SSE2,
paired runs on an Emerald Rapids Xeon (lower is faster):

  state  pattern          avx2  avx512
  16K    clean            0.49   0.28
  64K    1 dirty in 4096  0.60   0.45
  256K   16-word runs     0.61   0.49
  256K   1 dirty in 256   0.70   0.61
  1M     clean            0.85   0.84
  any    1 dirty in 64    ~1.0   ~1.0-1.05
  4M+    any              ~1.0   ~1.0   (memory bound)

samples/state_rewind allocates its blocks the same way and checks that
every tier the CPU has writes the same patch over 300 seeded pairs,
with the sentinel and scan-pad cases re-run under each tier.
2026-10-27 19:49:10 +01:00
..