Skip to content

fix: honour BASE64_FORCE_AVX512 in base64_stream_encode_init - #163

Open
mvanslobbe wants to merge 1 commit into
aklomp:masterfrom
mvanslobbe:fix-encode-init-avx512-flag
Open

mvanslobbe wants to merge 1 commit into
aklomp:masterfrom
mvanslobbe:fix-encode-init-avx512-flag

Conversation

@mvanslobbe

Copy link
Copy Markdown

base64_stream_encode_init only redoes codec selection when flags & 0xFF is non-zero. BASE64_FORCE_AVX512 is 1 << 8, so once any codec has been selected, a forced AVX512 encode carries on using the previous codec. base64_stream_decode_init uses 0xFFFF and is not affected. The mask dates from when AVX was the highest flag and was not widened when AVX512 was added in 98352df.

Output is unaffected, since all codecs produce identical results, but the wrong codec runs. Callers using the default flags of 0 never hit this; it only affects callers that force a codec. The visible consequence is in the test suite: test_streaming builds its reference with BASE64_FORCE_PLAIN, which switches the global codec to plain, and the following base64_stream_encode_init(&state, BASE64_FORCE_AVX512) keeps plain. The AVX512 streaming encode test has therefore never exercised the AVX512 encoder.

Measured by wrapping base64_stream_encode_avx512 with a call counter and running test_base64 under Intel SDE (-icl):

AVX512 encoder calls
before 536
after 2254

All tests pass after the change, including AVX512 streaming encode at every block size. test/benchmark.c is not affected, because codec_supported() selects the codec through a decode first.

A shared mask macro for both init functions would stop this from recurring when the next flag is added; happy to add that if you'd prefer it over the minimal change.

BASE64_FORCE_AVX512 is bit 8, but the encoder init only re-runs codec
selection for flags & 0xFF. Once a codec has been chosen, forcing AVX512
for encoding is silently ignored and the previous codec keeps running.
The decoder init already uses 0xFFFF.
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