Skip to content

Improve SSE4.1 ImagePngLoader decode-line handlers - #949

Merged
ermig1979 merged 1 commit into
devfrom
cursor/improve-sse41-png-decode-line-b4b5
Sep 8, 2026
Merged

Improve SSE4.1 ImagePngLoader decode-line handlers#949
ermig1979 merged 1 commit into
devfrom
cursor/improve-sse41-png-decode-line-b4b5

Conversation

@ermig1979

@ermig1979 ermig1979 commented Sep 8, 2026

Copy link
Copy Markdown
Owner

Process whole SSE vectors in PNG unfilters instead of per-pixel LoadN/StoreN.

The previous SSE4.1 _decodeLine Avg/Paeth/AvgFirst paths decoded srcN bytes at a time. That is slow for RGB (srcN=3) because each pixel does scalar-style 3-byte loads/stores around SIMD arithmetic.

Changes (SimdSse41ImageLoadPng.cpp)

  • Avg / first-row Avg: prefix-style propagation over a full 16-byte register (KeepFirst + Average), then StoreStep of 8/12/15/16 bytes, matching the existing Sub-filter approach.
  • Paeth: load a whole vector, run Paeth per pixel in-register with PaethPack, assemble and store the vector.
  • SIMD decode handlers are installed only when _width >= A; narrower images keep the Base scalar handlers.
  • Avg/Paeth/AvgFirst stay scalar for srcN == 1 (Gray8). A 16-step serial chain in SIMD was slower than Base.

Tests

Test::ImageLoadFromMemoryAutoTest and ImageLoadFromMemorySpecialTest both pass.

AutoTest (Release, -ts=1, 1920x1080 PNG), Sse41 vs Base speedup (Bs/S4):

Format Base ms Sse41 ms Bs/S4
Gray8 4.278 4.182 1.02
Rgb24 11.955 10.650 1.12
Bgr24 12.366 10.869 1.14
Rgba32 15.055 12.143 1.24
Bgra32 15.000 11.662 1.29

SpecialTest: PNG suite under data/image/png/ for Gray8, Bgr24, Bgra32, Rgb24, Rgba32. Base vs SimdImageLoadFromMemory (AVX-512BW dispatches to Sse41::ImagePngLoader).

Open in Web Open in Cursor 

Process whole SSE vectors in Avg/Paeth/AvgFirst unfilters instead of
per-pixel LoadN/StoreN, enable SIMD decode handlers only when width >= A,
and add n=1 paths for those filters.

Co-authored-by: igor.ermolaev <igor.ermolaev@altezza.org>
@ermig1979
ermig1979 marked this pull request as ready for review September 8, 2026 15:14
@ermig1979
ermig1979 merged commit 8cca8dc into dev Sep 8, 2026
2 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