Repository navigation
Conversation
The SSSE3, AVX2, AVX-512 VBMI and NEON decoders now share one loop, following simdutf: each block of 64 bytes is translated to 6-bit values with a mask of the bytes outside the alphabet, and the alphabet characters of a block with whitespace or other ignorable bytes are compressed into a buffer of pending values. So line-wrapped input (MIME, PEM) stays on the vector path instead of falling back to the scalar loop at the first line break, and short input no longer goes through the scalar loop. Strict mode is handled in the same loop: whitespace is skipped, padding is checked in the last block, and only '=' or an invalid byte before the last block goes to the scalar loop. The NEON encoder uses a 64-entry table lookup, and the AVX-512 VBMI encoder handles the tail with masked loads and stores. The AVX-512 VBMI tier now also requires VBMI2 (vpcompressb). The plain AVX-512 decoder is removed: those CPUs use the AVX2 decoder. Output is unchanged, including every strict-mode rejection.
Without pending values, the last 0 to 63 bytes were decoded through the buffers of the vector loop, at the cost of store-forwarding stalls: on short input, the SSSE3 decoder was slower than before. They are now decoded 16 bytes at a time while they are in the alphabet, and the rest (usually the padding) one character at a time.
Member
|
I used our benchmark framework (https://github.com/kocsismate/php-version-benchmarks) to check the performance changes. I used the following pieces of code: and (please note that both I got the following results on X86-64, using an AWS metal instance (see first table for more details): AWS x86_64 (c6id.metal)
PHP base64_decode - 50 iterations, 10 warmups, 15 requests (sec)
PHP base64_encode - 50 iterations, 10 warmups, 10 requests (sec)
The relative std dev % is much worse than it usually is. On a typical day, this should be below 0.15% in most cases when running our demo app benchmark (https://github.com/php/real-time-benchmark-data/blob/main/2026/2026_11_14_00_43_35_1_aws_x86_64_c6id.metal/result.md). Still, the performance improvement is definitely significant. |
The main loop used a 48-byte masked load on every iteration, which made large inputs about 10% slower than before the port on Emerald Rapids. Only the first 48 loaded bytes are used, so load 64 bytes while at least 64 bytes remain, and use a masked load for at most one final step.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to the discussion in #24774.
The SSSE3, AVX2, AVX-512 VBMI and NEON base64 decoders now share one loop, following simdutf. Each 64-byte block is translated to 6-bit values together with a mask of the bytes outside the alphabet. When a block contains whitespace or other ignorable bytes, its alphabet characters are compressed into a buffer of pending values instead of falling back to the scalar loop. As a result:
=or an invalid byte before the last block goes to the scalar loop.Output is unchanged, including every strict-mode rejection.
Other changes:
vqtbl4q), and the AVX-512 VBMI encoder handles the tail with masked loads and stores.vpcompressb). The plain AVX-512 decoder is removed; those CPUs use the AVX2 decoder.Performance
These are decode cycles per call measured with
perf stat, master → this PR. The numbers are from Ice Lake (Xeon 6338); Emerald Rapids gives similar results.On an Apple M4, decoding MIME input goes from 0.67 to 9.7 GB/s. Every kernel is at least as fast as master in every case measured: 24 B, 44 B, 1 KB, 64 KB clean and 64 KB MIME. The AVX2, AVX-512 and NEON decoders are within a few percent of simdutf.
Testing
ext/standard/tests/url/base64_decode_blocks.phpt, compares the result with a character-at-a-time reference decoder in both modes. It covers lengths 0 to 150, line breaks, padding, an inserted byte at every offset around block boundaries, and long inputs.References