[PATCH] x86_64: Prefer EVEX512 code-path on AMD Zen5 CPUs
Sajan Karumanchi
sajan.karumanchi@gmail.com
Wed Feb 18 18:09:06 GMT 2026
This patch introduces a performance optimization for AMD Zen5 processors
by preferring 512-bit EVEX variants of string and memory functions when
AVX-512 is available.
Background
----------
Current Glibc's IFUNC dispatch mechanism selects 256-bit EVEX
variants for several string and memory functions on CPUs with AVX-512
support, regardless of their 512-bit execution capabilities. This
leaves significant performance potential untapped on Zen5, which
benefits substantially from using the full 512-bit EVEX512 variants.
Implementation
--------------
The patch introduces a new synthetic CPU feature flag 'Prefer_EVEX512'
that is automatically enabled on Zen5 CPUs when AVX-512F, AVX-512VL,
and AVX-512BW are supported. This flag influences IFUNC dispatch to
select EVEX512 implementations over EVEX (256-bit) variants.
Performance Results
-------------------
Benchmarks conducted on AMD Zen5 hardware demonstrate significant
performance improvements across all affected functions:
Function Baseline Patched Avg Avg Avg Max
Variant Variant Baseline Patched Change Improve
(ns) (ns) % %
------------+----------+----------+-----------+----------+--------+--------
STRCHR evex evex512 16.408 12.293 25.08% 37.69%
STRLEN evex evex512 16.862 11.436 32.18% 56.74%
STRNLEN evex evex512 18.493 11.762 36.40% 64.40%
STRRCHR evex evex512 15.154 10.874 28.24% 44.38%
STRCHRNUL evex evex512 16.464 12.605 23.44% 45.56%
MEMCHR evex evex512 9.984 8.268 17.19% 39.99%
Key findings:
- Average performance improvements range from 17% to 36%
- Maximum improvements reach up to 64% in some test cases
Testing
-------
- All glibc string and memory tests pass on Zen5 hardware
- IFUNC selection verified to correctly choose evex512 variants
- Backward compatibility maintained for non-Zen5 AMD processors
- No impact on Intel or other x86_64 processors
Affected Functions
------------------
- strchr
- strlen
- strnlen
- strrchr
- strchrnul
- memchr
The patch adds a new ifunc-evex512.h header for common IFUNC selection
logic and updates the affected functions to use it.
Sajan Karumanchi (1):
x86_64: Prefer EVEX512 code-path on AMD Zen5 CPUs
sysdeps/x86/cpu-features.c | 11 ++++
sysdeps/x86/include/cpu-features-preferred_feature_index_1.def | 1 +
sysdeps/x86_64/multiarch/ifunc-evex512.h | 60 +++++++++++++++++++
sysdeps/x86_64/multiarch/ifunc-impl-list.c | 28 +++++++--
sysdeps/x86_64/multiarch/memchr.c | 48 ++++++++++++++-
sysdeps/x86_64/multiarch/strchr.c | 8 ++-
sysdeps/x86_64/multiarch/strchrnul.c | 4 +-
sysdeps/x86_64/multiarch/strlen.c | 2 +-
sysdeps/x86_64/multiarch/strnlen.c | 2 +-
sysdeps/x86_64/multiarch/strrchr.c | 2 +-
10 files changed, 151 insertions(+), 15 deletions(-)
create mode 100644 sysdeps/x86_64/multiarch/ifunc-evex512.h
More information about the Libc-alpha
mailing list