mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-26 21:50:52 +01:00
[PR #1974] perf(bcpack): 128-bit register BitWriter, lazy BPTC state init, index_row LUT, and portable decode test #1982
Labels
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
starred/leonida#1982
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/ubiquitarianism/leonida/pull/1974
Author: @IlyassRS3
Created: 11/25/2026
Status: 🔄 Open
Base:
main← Head:perf/rt-bcpack-decode-fast-bitwriter-and-bptc📝 Commits (1)
b26f581perf(bcpack): 128-bit register BitWriter, lazy BPTC zero/ring init, and index_row LUT📊 Changes
3 files changed (+344 additions, -104 deletions)
View changed files
📝
runtime/CMakeLists.txt(+30 -0)📝
runtime/src/bcpack.cpp(+186 -104)➕
runtime/test/bcpack_decode_test.cpp(+128 -0)📄 Description
Claim:
RT-BCPACK-DECODE-FAST-BITWRITER-AND-BPTC(claim comment#7168983247on #1608).Independent of #1935 (
runtime/src/bcpack_stream.h, untouched here); the two optimizations compose cleanly.Optimizations (
runtime/src/bcpack.cpp)BitWriterfor BC6H/BC7:while (bits > 0)memory-RMW byte loops (called 82+ times per BC6H block) and per-blockfill_n(dest, 16, 0)pre-zeroing with twouint64_taccumulators (lo/hi) and a singleput1()helper, flushed in two 64-bit little-endian stores (with portable big-endian fallback).decode():decode()call zero-initialized botharray<Endpoints, 256> classic{}(8 KiB) andarray<BptcState, 256> bptc{}(59 KiB) on the stack, even when decoding classic codecs or small mipmaps.codec >= 6vscodec < 6into separate trivially default-constructible ring buffers without up-front zeroing (bothrebuild_classicandrebuild_bptconly readpast[(i - d) & 255]when0 < d <= i, after that slot was written).zero/ history fallback and per-block zeroing elimination (rebuild_bptc):kZeroBc6andkZeroBc7constants and only constructs a stackhist_statewheneslot >= 0 || islot >= 0, skipping 232 bytes of stack zeroing + BC6 endpoint/index fill on steady-state blocks (i >= 256).bc6Modes/bc7Config, eliminates the 232-bytenext = {}wipe per BPTC block by explicitly zeroing only unused BC7 endpoint/secondary-index slots, and uses a 6-byte little-endianmemcpyinrebuild_classic.kUnzigEven[256]/kUnzigOdd[256]LUTs forindex_row(): replaces the per-pixel bit-extraction andunzig()arithmetic inside the 4–8× per-block index loop.bcpack_decode(runtime/test/bcpack_decode_test.cpp): verifies all 6 codecs (BC1, BC3, BC4, BC5, BC6H, BC7) bit-exactly againstdstorage_vectors.pywith bothfast_entropy = true/false, calibration profile history (missing-profile,confirmed,unconfirmed-predictor,fitted), classic fitted gating, and invalid/misaligned/truncated inputs.Verification
bcpack_decode_testcleanly under:clang++ -std=c++20 -O1 -g -fsanitize=address,undefined -Wall -Wextra -Werrorclang++ -std=c++20 -O1 -g -fsanitize=thread -Wall -Wextra -Werrorclang++ -std=c++20 -O2 -Wall -Wextra -Werror-O2vsmain(including full rANS entropy decode, best of 5 runs, Apple Silicon):python3 -I scripts/check_no_game_data.pyon all 3 changed files andpython3 -I tests/test_text_write_line_endings.py: all passed.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.