[3/3] i386: Replace inline asm rotates in pointer_guard with stdc_rotate_{left, right}
Checks
| Context |
Check |
Description |
| redhat-pt-bot/TryBot-apply_patch |
success
|
Patch applied to master at the time it was sent
|
| redhat-pt-bot/TryBot-32bit |
fail
|
Patch series failed to apply
|
Commit Message
Use the C23 <stdbit.h> rotation helpers instead of inline assembly
for pointer mangling and demangling on i386.
The PTR_MANGLE and PTR_DEMANGLE macros previously used rol/ror
inline asm with a constant rotation of 9. Replace these with
stdc_rotate_left and stdc_rotate_right operating on uintptr_t,
preserving the exact rotation count via 2 * sizeof (uintptr_t) + 1.
This change removes inline assembly, improves portability and
readability and lets the compiler select optimal code generation.
No functional change intended.
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
---
sysdeps/unix/sysv/linux/i386/pointer_guard.h | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
Comments
On 06/05/26 15:42, Uros Bizjak wrote:
> Use the C23 <stdbit.h> rotation helpers instead of inline assembly
> for pointer mangling and demangling on i386.
>
> The PTR_MANGLE and PTR_DEMANGLE macros previously used rol/ror
> inline asm with a constant rotation of 9. Replace these with
> stdc_rotate_left and stdc_rotate_right operating on uintptr_t,
> preserving the exact rotation count via 2 * sizeof (uintptr_t) + 1.
>
> This change removes inline assembly, improves portability and
> readability and lets the compiler select optimal code generation.
>
> No functional change intended.
>
> Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
LGTM, thanks.
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
> ---
> sysdeps/unix/sysv/linux/i386/pointer_guard.h | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/sysdeps/unix/sysv/linux/i386/pointer_guard.h b/sysdeps/unix/sysv/linux/i386/pointer_guard.h
> index 7c142fb526..c8311be444 100644
> --- a/sysdeps/unix/sysv/linux/i386/pointer_guard.h
> +++ b/sysdeps/unix/sysv/linux/i386/pointer_guard.h
> @@ -33,16 +33,19 @@
> # define PTR_DEMANGLE(reg) rorl $9, reg; \
> xorl %gs:POINTER_GUARD, reg
> # else
> +# include <stdbit.h>
> # include <tls.h>
> # define PTR_MANGLE(var) \
> do { \
> (var) = (__typeof (var)) ((uintptr_t) (var) \
> ^ ((tcbhead_t __seg_gs *)0)->pointer_guard); \
> - asm ("roll $9, %0" : "+r" (var)); \
> + (var) = (__typeof (var)) stdc_rotate_left ((uintptr_t) (var), \
> + 2 * sizeof (uintptr_t) + 1); \
> } while (0)
> # define PTR_DEMANGLE(var) \
> do { \
> - asm ("rorl $9, %0" : "+r" (var)); \
> + (var) = (__typeof (var)) stdc_rotate_right ((uintptr_t) (var), \
> + 2 * sizeof (uintptr_t) + 1); \
> (var) = (__typeof (var)) ((uintptr_t) (var) \
> ^ ((tcbhead_t __seg_gs *)0)->pointer_guard); \
> } while (0)
@@ -33,16 +33,19 @@
# define PTR_DEMANGLE(reg) rorl $9, reg; \
xorl %gs:POINTER_GUARD, reg
# else
+# include <stdbit.h>
# include <tls.h>
# define PTR_MANGLE(var) \
do { \
(var) = (__typeof (var)) ((uintptr_t) (var) \
^ ((tcbhead_t __seg_gs *)0)->pointer_guard); \
- asm ("roll $9, %0" : "+r" (var)); \
+ (var) = (__typeof (var)) stdc_rotate_left ((uintptr_t) (var), \
+ 2 * sizeof (uintptr_t) + 1); \
} while (0)
# define PTR_DEMANGLE(var) \
do { \
- asm ("rorl $9, %0" : "+r" (var)); \
+ (var) = (__typeof (var)) stdc_rotate_right ((uintptr_t) (var), \
+ 2 * sizeof (uintptr_t) + 1); \
(var) = (__typeof (var)) ((uintptr_t) (var) \
^ ((tcbhead_t __seg_gs *)0)->pointer_guard); \
} while (0)