Skip to content

Match SIMD coverage rounding to scalar output - #606

Merged
treeform merged 2 commits into
masterfrom
fix-simd-coverage-rounding
Nov 16, 2026
Merged

treeform merged 2 commits into
masterfrom
fix-simd-coverage-rounding

Conversation

@treeform

Copy link
Copy Markdown
Owner

Partially covered pixels could differ between SIMD blocks and scalar prefixes or tails because SSE2 and AVX2 coverage multiplication truncated where the scalar code rounds. Add the same 127 bias before division by 255 in both helpers.

Add a regression for normal and overwrite blending across all 256 coverage values, four colors, and eight buffer offsets, checking scalar results and surrounding sentinel pixels. This moves the small fix already carried by Runway into Pixie.

Validation: the new regression failed before the fix at SSE2 coverage 1, then passed in debug and release x86-64 builds on this Mac. nim check --cpu:amd64 tests/test_simd.nim passes. AVX2 code compiles, but its runtime checks are skipped locally because Rosetta does not expose AVX2; the test runs that path on capable machines.

Only skip fully covered mask pixels when the mask is also opaque. Match
the vector behavior in SSE2/AVX2/NEON scalar prefixes and tails and in the
scalar fallback.

Exercise normal, overwrite, and mask coverage on SSE2 and AVX2 across all
coverage values, lengths 0 through 160, pixel and coverage alignments,
mixed coverage lanes, translucent colors, and surrounding sentinels.
Add a path-level mask regression for every backend and report AVX2 skips.

Validated on Windows x64 (Ryzen 9 5900X, Nim 2.2.10): full C test suite;
SIMD debug/release and C++ tests; SSE2-only tests; path mask tests with
AVX2, SSE2, and scalar dispatch; ARM64 Nim static check. Confirmed the
new mask tests fail before the shortcut fix.
@treeform
treeform merged commit 0801093 into master Nov 16, 2026
3 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.

1 participant