From: Florian Weimer <fweimer@redhat.com>
To: libc-alpha@sourceware.org
Cc: Jakub Jelinek <jakub@redhat.com>, "H.J. Lu" <hjl.tools@gmail.com>
Subject: [PATCH 1/2] i386: Always treat %ebx as an allocatable register
Date: Tue, 11 Jan 2022 11:06:44 +0100 [thread overview]
Message-ID: <e5609b0199e5f16f9b1c1178ea642ff0a3724152.1641895400.git.fweimer@redhat.com> (raw)
In-Reply-To: <cover.1641895400.git.fweimer@redhat.com>
!CAN_USE_REGISTER_ASM_EBP also disables the direct use of %ebx
in system calls, but that is not actually needed anymore.
---
sysdeps/unix/sysv/linux/i386/sysdep.h | 192 ++++----------------------
1 file changed, 25 insertions(+), 167 deletions(-)
diff --git a/sysdeps/unix/sysv/linux/i386/sysdep.h b/sysdeps/unix/sysv/linux/i386/sysdep.h
index 66c2833a49..fcd78e3157 100644
--- a/sysdeps/unix/sysv/linux/i386/sysdep.h
+++ b/sysdeps/unix/sysv/linux/i386/sysdep.h
@@ -239,35 +239,6 @@ extern int __syscall_error (int)
attribute_hidden __attribute__ ((__regparm__ (1)));
#ifndef OPTIMIZE_FOR_GCC_5
-/* We need some help from the assembler to generate optimal code. We
- define some macros here which later will be used. */
-asm (".L__X'%ebx = 1\n\t"
- ".L__X'%ecx = 2\n\t"
- ".L__X'%edx = 2\n\t"
- ".L__X'%eax = 3\n\t"
- ".L__X'%esi = 3\n\t"
- ".L__X'%edi = 3\n\t"
- ".L__X'%ebp = 3\n\t"
- ".L__X'%esp = 3\n\t"
- ".macro bpushl name reg\n\t"
- ".if 1 - \\name\n\t"
- ".if 2 - \\name\n\t"
- "error\n\t"
- ".else\n\t"
- "xchgl \\reg, %ebx\n\t"
- ".endif\n\t"
- ".endif\n\t"
- ".endm\n\t"
- ".macro bpopl name reg\n\t"
- ".if 1 - \\name\n\t"
- ".if 2 - \\name\n\t"
- "error\n\t"
- ".else\n\t"
- "xchgl \\reg, %ebx\n\t"
- ".endif\n\t"
- ".endif\n\t"
- ".endm\n\t");
-
/* Six-argument syscalls use an out-of-line helper, because an inline
asm using all registers apart from %esp cannot work reliably and
the assembler does not support describing an asm that saves and
@@ -379,187 +350,74 @@ struct libc_do_syscall_args
(int) resultvar; })
#if I386_USE_SYSENTER
-# ifdef OPTIMIZE_FOR_GCC_5
-# ifdef PIC
-# define INTERNAL_SYSCALL_MAIN_INLINE(name, nr, args...) \
+# ifdef PIC
+# define INTERNAL_SYSCALL_MAIN_INLINE(name, nr, args...) \
LOADREGS_##nr(args) \
asm volatile ( \
"call *%%gs:%P2" \
: "=a" (resultvar) \
: "a" (__NR_##name), "i" (offsetof (tcbhead_t, sysinfo)) \
ASMARGS_##nr(args) : "memory", "cc")
-# define INTERNAL_SYSCALL_MAIN_NCS(name, nr, args...) \
+# define INTERNAL_SYSCALL_MAIN_NCS(name, nr, args...) \
LOADREGS_##nr(args) \
asm volatile ( \
"call *%%gs:%P2" \
: "=a" (resultvar) \
: "a" (name), "i" (offsetof (tcbhead_t, sysinfo)) \
ASMARGS_##nr(args) : "memory", "cc")
-# else
-# define INTERNAL_SYSCALL_MAIN_INLINE(name, nr, args...) \
+# else /* I386_USE_SYSENTER && !PIC */
+# define INTERNAL_SYSCALL_MAIN_INLINE(name, nr, args...) \
LOADREGS_##nr(args) \
asm volatile ( \
"call *_dl_sysinfo" \
: "=a" (resultvar) \
: "a" (__NR_##name) ASMARGS_##nr(args) : "memory", "cc")
-# define INTERNAL_SYSCALL_MAIN_NCS(name, nr, args...) \
+# define INTERNAL_SYSCALL_MAIN_NCS(name, nr, args...) \
LOADREGS_##nr(args) \
asm volatile ( \
"call *_dl_sysinfo" \
: "=a" (resultvar) \
: "a" (name) ASMARGS_##nr(args) : "memory", "cc")
-# endif
-# else /* GCC 5 */
-# ifdef PIC
-# define INTERNAL_SYSCALL_MAIN_INLINE(name, nr, args...) \
- EXTRAVAR_##nr \
- asm volatile ( \
- LOADARGS_##nr \
- "movl %1, %%eax\n\t" \
- "call *%%gs:%P2\n\t" \
- RESTOREARGS_##nr \
- : "=a" (resultvar) \
- : "i" (__NR_##name), "i" (offsetof (tcbhead_t, sysinfo)) \
- ASMFMT_##nr(args) : "memory", "cc")
-# define INTERNAL_SYSCALL_MAIN_NCS(name, nr, args...) \
- EXTRAVAR_##nr \
- asm volatile ( \
- LOADARGS_##nr \
- "call *%%gs:%P2\n\t" \
- RESTOREARGS_##nr \
- : "=a" (resultvar) \
- : "0" (name), "i" (offsetof (tcbhead_t, sysinfo)) \
- ASMFMT_##nr(args) : "memory", "cc")
-# else
-# define INTERNAL_SYSCALL_MAIN_INLINE(name, nr, args...) \
- EXTRAVAR_##nr \
- asm volatile ( \
- LOADARGS_##nr \
- "movl %1, %%eax\n\t" \
- "call *_dl_sysinfo\n\t" \
- RESTOREARGS_##nr \
- : "=a" (resultvar) \
- : "i" (__NR_##name) ASMFMT_##nr(args) : "memory", "cc")
-# define INTERNAL_SYSCALL_MAIN_NCS(name, nr, args...) \
- EXTRAVAR_##nr \
- asm volatile ( \
- LOADARGS_##nr \
- "call *_dl_sysinfo\n\t" \
- RESTOREARGS_##nr \
- : "=a" (resultvar) \
- : "0" (name) ASMFMT_##nr(args) : "memory", "cc")
-# endif
-# endif /* GCC 5 */
-#else
-# ifdef OPTIMIZE_FOR_GCC_5
-# define INTERNAL_SYSCALL_MAIN_INLINE(name, nr, args...) \
+# endif /* I386_USE_SYSENTER && !PIC */
+#else /* !I386_USE_SYSENTER */
+# define INTERNAL_SYSCALL_MAIN_INLINE(name, nr, args...) \
LOADREGS_##nr(args) \
asm volatile ( \
"int $0x80" \
: "=a" (resultvar) \
: "a" (__NR_##name) ASMARGS_##nr(args) : "memory", "cc")
-# define INTERNAL_SYSCALL_MAIN_NCS(name, nr, args...) \
+# define INTERNAL_SYSCALL_MAIN_NCS(name, nr, args...) \
LOADREGS_##nr(args) \
asm volatile ( \
"int $0x80" \
: "=a" (resultvar) \
: "a" (name) ASMARGS_##nr(args) : "memory", "cc")
-# else /* GCC 5 */
-# define INTERNAL_SYSCALL_MAIN_INLINE(name, nr, args...) \
- EXTRAVAR_##nr \
- asm volatile ( \
- LOADARGS_##nr \
- "movl %1, %%eax\n\t" \
- "int $0x80\n\t" \
- RESTOREARGS_##nr \
- : "=a" (resultvar) \
- : "i" (__NR_##name) ASMFMT_##nr(args) : "memory", "cc")
-# define INTERNAL_SYSCALL_MAIN_NCS(name, nr, args...) \
- EXTRAVAR_##nr \
- asm volatile ( \
- LOADARGS_##nr \
- "int $0x80\n\t" \
- RESTOREARGS_##nr \
- : "=a" (resultvar) \
- : "0" (name) ASMFMT_##nr(args) : "memory", "cc")
-# endif /* GCC 5 */
-#endif
+#endif /* !I386_USE_SYSENTER */
-#define LOADARGS_0
-#ifdef __PIC__
-# if I386_USE_SYSENTER && defined PIC
-# define LOADARGS_1 \
- "bpushl .L__X'%k3, %k3\n\t"
-# define LOADARGS_5 \
- "movl %%ebx, %4\n\t" \
- "movl %3, %%ebx\n\t"
-# else
-# define LOADARGS_1 \
- "bpushl .L__X'%k2, %k2\n\t"
-# define LOADARGS_5 \
- "movl %%ebx, %3\n\t" \
- "movl %2, %%ebx\n\t"
-# endif
-# define LOADARGS_2 LOADARGS_1
-# define LOADARGS_3 \
- "xchgl %%ebx, %%edi\n\t"
-# define LOADARGS_4 LOADARGS_3
-#else
-# define LOADARGS_1
-# define LOADARGS_2
-# define LOADARGS_3
-# define LOADARGS_4
-# define LOADARGS_5
-#endif
-
-#define RESTOREARGS_0
-#ifdef __PIC__
-# if I386_USE_SYSENTER && defined PIC
-# define RESTOREARGS_1 \
- "bpopl .L__X'%k3, %k3\n\t"
-# define RESTOREARGS_5 \
- "movl %4, %%ebx"
-# else
-# define RESTOREARGS_1 \
- "bpopl .L__X'%k2, %k2\n\t"
-# define RESTOREARGS_5 \
- "movl %3, %%ebx"
-# endif
-# define RESTOREARGS_2 RESTOREARGS_1
-# define RESTOREARGS_3 \
- "xchgl %%edi, %%ebx\n\t"
-# define RESTOREARGS_4 RESTOREARGS_3
-#else
-# define RESTOREARGS_1
-# define RESTOREARGS_2
-# define RESTOREARGS_3
-# define RESTOREARGS_4
-# define RESTOREARGS_5
-#endif
-
-#ifdef OPTIMIZE_FOR_GCC_5
-# define LOADREGS_0()
-# define ASMARGS_0()
-# define LOADREGS_1(arg1) \
+#define LOADREGS_0()
+#define ASMARGS_0()
+#define LOADREGS_1(arg1) \
LOADREGS_0 ()
-# define ASMARGS_1(arg1) \
+#define ASMARGS_1(arg1) \
ASMARGS_0 (), "b" ((unsigned int) (arg1))
-# define LOADREGS_2(arg1, arg2) \
+#define LOADREGS_2(arg1, arg2) \
LOADREGS_1 (arg1)
-# define ASMARGS_2(arg1, arg2) \
+#define ASMARGS_2(arg1, arg2) \
ASMARGS_1 (arg1), "c" ((unsigned int) (arg2))
-# define LOADREGS_3(arg1, arg2, arg3) \
+#define LOADREGS_3(arg1, arg2, arg3) \
LOADREGS_2 (arg1, arg2)
-# define ASMARGS_3(arg1, arg2, arg3) \
+#define ASMARGS_3(arg1, arg2, arg3) \
ASMARGS_2 (arg1, arg2), "d" ((unsigned int) (arg3))
-# define LOADREGS_4(arg1, arg2, arg3, arg4) \
+#define LOADREGS_4(arg1, arg2, arg3, arg4) \
LOADREGS_3 (arg1, arg2, arg3)
-# define ASMARGS_4(arg1, arg2, arg3, arg4) \
+#define ASMARGS_4(arg1, arg2, arg3, arg4) \
ASMARGS_3 (arg1, arg2, arg3), "S" ((unsigned int) (arg4))
-# define LOADREGS_5(arg1, arg2, arg3, arg4, arg5) \
+#define LOADREGS_5(arg1, arg2, arg3, arg4, arg5) \
LOADREGS_4 (arg1, arg2, arg3, arg4)
-# define ASMARGS_5(arg1, arg2, arg3, arg4, arg5) \
+#define ASMARGS_5(arg1, arg2, arg3, arg4, arg5) \
ASMARGS_4 (arg1, arg2, arg3, arg4), "D" ((unsigned int) (arg5))
+
+#ifdef OPTIMIZE_FOR_GCC_5
# define LOADREGS_6(arg1, arg2, arg3, arg4, arg5, arg6) \
register unsigned int _a6 asm ("ebp") = (unsigned int) (arg6); \
LOADREGS_5 (arg1, arg2, arg3, arg4, arg5)
--
2.34.1
next prev parent reply other threads:[~2022-01-11 10:06 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-11 10:05 [PATCH 0/2] Remove some i386 system call optimizations Florian Weimer
2022-01-11 10:06 ` Florian Weimer [this message]
2022-01-11 10:06 ` [PATCH 2/2] i386: Always use __libc_do_syscall for 6-argument syscalls (bug 27997) Florian Weimer
2022-01-11 14:00 ` [PATCH 0/2] Remove some i386 system call optimizations H.J. Lu
2022-01-11 20:30 ` H.J. Lu
2022-01-11 20:37 ` Florian Weimer
2022-01-11 22:20 ` H.J. Lu
2022-01-11 22:52 ` Florian Weimer
2022-01-12 18:49 ` H.J. Lu
2022-01-12 19:37 ` Florian Weimer
2022-01-12 19:56 ` H.J. Lu
2022-01-12 20:12 ` Florian Weimer
2022-01-12 21:59 ` H.J. Lu
2022-01-12 22:33 ` Florian Weimer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e5609b0199e5f16f9b1c1178ea642ff0a3724152.1641895400.git.fweimer@redhat.com \
--to=fweimer@redhat.com \
--cc=hjl.tools@gmail.com \
--cc=jakub@redhat.com \
--cc=libc-alpha@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).