[PATCH 0/3] stdlib, x86: Add internal stdc_rotate_left and use it in x86 pointer (de-)mangling
Uros Bizjak
ubizjak@gmail.com
Wed May 6 18:42:37 GMT 2026
x86 pointer (de-)mangling macros are currently implemented using
inline rol/ror assembly. This prevents the compiler from selecting
more efficient instructions on newer microarchitectures. In particular,
x86-64-v3 targets with BMI2 support can use rorx, which avoids
flag dependecies.
This series introduces an internal stdc_rotate_left helper, modelled
after Adhemerval Zanella's earlier stdc_rotate_right implementation.
It allows the compiler to emit optimal rotate sequences (including
rorx when available) instead of relying on inline assembly.
Tests are imported from gnulib and adapted to glibc's libsupport.
With these changes, pointer demangling improves from:
33d8: 48 8b 40 20 mov 0x20(%rax),%rax
33dc: 48 c1 c8 11 ror $0x11,%rax
33e0: 64 48 33 04 25 30 00 xor %fs:0x30,%rax
33e7: 00 00
to:
3678: c4 e3 fb f0 40 20 11 rorx $0x11,0x20(%rax),%rax
367f: 64 48 33 04 25 30 00 xor %fs:0x30,%rax
3686: 00 00
The series has been tested on {x86_64,i686}-pc-linux-gnu, both with
and without GCC rotate builtins used.
Cc: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Uros Bizjak (3):
stdlib: Add internal stdc_rotate_left implementation
x86_64: Replace inline asm rotates in pointer_guard with
stdc_rotate_{left,right}
i386: Replace inline asm rotates in pointer_guard with
stdc_rotate_{left,right}
SHARED-FILES | 1 +
include/stdbit.h | 62 ++-
stdlib/Makefile | 1 +
stdlib/tst-stdc_rotate_left.c | 457 ++++++++++++++++++
sysdeps/unix/sysv/linux/i386/pointer_guard.h | 7 +-
.../unix/sysv/linux/x86_64/pointer_guard.h | 14 +-
6 files changed, 535 insertions(+), 7 deletions(-)
create mode 100644 stdlib/tst-stdc_rotate_left.c
--
2.54.0
More information about the Libc-alpha
mailing list