Skip to content

upscale: AVX-512 permute gather, inline YCbCr, hoisted broadcasts (55 to 37 ms) - #147

Merged
tannevaled merged 4 commits into
mainfrom
upscale/gather-perm
Nov 29, 2026
Merged

tannevaled merged 4 commits into
mainfrom
upscale/gather-perm

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

Refs #141.

EASU+RCAS 720p to 1080p, one core of a Ryzen 9 7950X (AVX-512, 16 lanes), GOEXPERIMENT=simd, ms per frame, interleaved runs:

Step Full EASU alone
v0.23.0 55.2 45.7
permute gather (ConcatPermute, per-phase index table) 52.8 41.8
+ permute x-interpolation of the analysis 45.2 34.8
+ inline YCbCr to planar (no At()/COffset) 40.4 30.2
+ broadcasts and tap offsets hoisted out of block 37.2 28.4
  • The gather falls back to the scalar one without AVX-512 or when a column step exceeds one source pixel; both paths are tested and the scalar build keeps 100% coverage, as does the simd build.
  • The planes now carry 64 floats of slack so the vector loads cannot overrun (a fuzz seed had caught the overrun on AVX-512).
  • ycc is checked against color.YCbCrToRGB on all 2^24 inputs; every subsampling ratio and an odd-origin sub-image are checked against At().

No API change.

🤖 Generated with Claude Code

tannevaled and others added 4 commits November 29, 2026 15:55
…12 permutes

Scaling up, the column table steps by 0 or 1 source pixel per output pixel,
so 16 outputs read at most 16 consecutive source floats: two loads cover the
window, one ConcatPermute per tap (index vectors precomputed per frame) picks
the lanes. The same trick replaces the scalar x-interpolation of the analysis.
Falls back to the scalar gather without AVX-512 or when the table does not fit.

Ryzen 9 7950X, one core, 720p to 1080p, EASU+RCAS 55.2 -> 45.1 ms, EASU alone
45.7 -> 34.8 ms (interleaved with the v0.23.0 build).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
color.YCbCrToRGB per pixel with YOffset/COffset calls becomes an inlinable
copy of the same integer arithmetic over row slices, chroma indexed by the
subsampling shift. Tested against the standard library on all 2^24 inputs,
and against At() for every subsampling ratio on a sub-image with an odd origin.

Ryzen 9 7950X, one core, 720p to 1080p: EASU+RCAS 44.5 -> ~41 ms.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…of the EASU vector block

The constants, the row-dependent y offsets and the x offsets (tapDX - ppx, a
per-frame table) were rebuilt for every vector of 16 pixels; they are now made
once per row or once per frame.

Ryzen 9 7950X, one core, 720p to 1080p, EASU+RCAS ~40.4 -> ~37.2 ms, EASU alone
~30.2 -> ~28.4 ms (interleaved).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The arm64 vector lane could not cover the branch that only exists where the
permute gather does. The selection now lives in usePerm, defined per
architecture (an empty stub off amd64), and the amd64 test covers the refusal.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@tannevaled
tannevaled merged commit c01f0f3 into main Nov 29, 2026
20 checks passed
@tannevaled
tannevaled deleted the upscale/gather-perm branch November 29, 2026 15:17
tannevaled added a commit that referenced this pull request Nov 29, 2026
… re-measured at the merged code (#150)

* ci: the vector coverage gate no longer depends on the runner's CPU

main went red on the merge commit of #149 (run 46292291989, job "test,
GOEXPERIMENT=simd (ubuntu-latest)": upscale coverage 94.4% < 100%) although
the same tree had 21 green checks on the pull request.

upscale/easu_perm_amd64.go, added by #147, runs only with AVX-512, and a
hosted amd64 runner has it or not from one job to the next. Reproduced on a
Ryzen 9 7950X at 0a15a86: 100.0% natively, 94.5% under
GODEBUG=cpu.avx512f=off, the only functions below 100% being usePerm and
permGather. The gate was a draw since #147.

tools/covgate (cobra, a module of its own, 100% covered, parser fuzzed)
requires every block of the profile and excuses the blocks of one named file
only when /proc/cpuinfo lacks the named flag, printing a warning that counts
the statements that were not measured. An unreadable cpuinfo, an empty
profile and a malformed line are refusals, not passes.

Not solved here: on a runner without AVX-512 the permute gather is not
executed at all, so a commit can be released with that kernel untested by CI.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

* README: the upscale speed table as measured at the merged code

The table merged with #149 was measured one commit before its head. At
0a15a86 on the same core (Ryzen 9 7950X, core 9, interleaved runs) the Scaler
takes 28.7 to 29.3 ms per frame, not 26.2: the only non-test difference is the
integer position of an output pixel (72c6376), and why it costs 10 % with the
per-pixel code unchanged is not established. Multicore figures re-measured:
14.5, 7.5, 5.4 and 3.6 ms at 2, 4, 8 and 16 workers; with several workers
-benchmem reports 0 allocs/op and 1 to 522 B/op.

covgate also says, on a CPU that has the flag, that the file is held like the
rest, so the job log states which of the two the runner was.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

---------

Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
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.

1 participant