Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: python/cpython
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: main
Choose a base ref
...
head repository: gpshead/cpython
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: binascii-base64-avx2
Choose a head ref
Checking mergeability… Don’t worry, you can still create the pull request.
  • 1 commit
  • 4 files changed
  • 1 contributor

Commits on Nov 29, 2026

  1. gh-124951: Use AVX2 for base64 in binascii on x86-64

    Encode 24 bytes or decode 32 characters of base64 per step with AVX2
    when the CPU supports it, then hand the rest of the input to the
    existing scalar loops.  Those loops still handle inputs shorter than one
    step, the tail, padding, invalid characters and errors, so results and
    exceptions are unchanged.  There is no intermediate 128-bit code path.
    
    AVX2 is part of x86-64-v3.  A build that already targets it calls the
    kernels directly; otherwise they are compiled with a function target
    attribute and selected at run time, with __builtin_cpu_supports() for
    GCC and Clang and with CPUID for MSVC and clang-cl, where the check also
    confirms that the OS saves the YMM registers.
    
    The decoder handles the standard alphabet only.  The encoder takes any
    alphabet whose first 62 characters are the standard ones, which covers
    base64.urlsafe_b64encode() and base64.b64encode() with altchars.
    
    On an AMD Zen 2 with GCC 15, in GB/s for 64 KiB inputs:
    
                          scalar   AVX2
      b2a_base64            2.2     18
      a2b_base64            1.9     14
      urlsafe_b64encode     2.2     18
    
    and per call in nanoseconds for small inputs:
    
                b2a_base64        a2b_base64
      size    scalar   AVX2     scalar   AVX2
      64 B      150     140       120     110
      128 B     180     140       150     110
      256 B     230     150       220     120
      1 KiB     630     220       680     220
    
    test_base64_long_inputs is adapted from Justin Bennington's GH-162443.
    
    Co-authored with Claude Fable 5.2.
    gpshead committed Nov 29, 2026
    Configuration menu
    Copy the full SHA
    bf6f1d4 View commit details
    Browse the repository at this point in the history
Loading