From: Xi Ruoyao <xry111@xry111.site>
To: libc-alpha@sourceware.org
Cc: caiyinyu <caiyinyu@loongson.cn>, Wang Xuerui <i@xen0n.name>,
Adhemerval Zanella Netto <adhemerval.zanella@linaro.org>,
Andreas Schwab <schwab@suse.de>,
Florian Weimer <fw@deneb.enyo.de>, Xi Ruoyao <xry111@xry111.site>
Subject: [PATCH v2 1/5] linux: Add __ASSUME_SYSCALL_NAMED_WORKS to allow avoiding va_list for generic syscall
Date: Sat, 25 Mar 2023 22:08:11 +0800 [thread overview]
Message-ID: <20230325140815.4170296-2-xry111@xry111.site> (raw)
In-Reply-To: <20230325140815.4170296-1-xry111@xry111.site>
Currently GCC generates highly sub-optimal code on architectures where
the calling convention prefers registers for argument passing. This is
GCC PR100955. While it's technically a missed-optimization in GCC, it
seems not trivial to fix (I've not seen any compiler which can optimize
this properly yet).
As the generic Linux syscall actually uses a fixed number of arguments,
we can avoid va_list if possible and make the compiler do right thing.
Add a macro __ASSUME_SYSCALL_NAMED_WORKS which should be defined if the
calling convention treats (x named arguments + y variable arguments)
exactly same as (x + y) named arguments, while each argument is either
an integer of which the width is less than or equal to "long" or a
pointer; and each argument can be fetched from the same register or the
same offset from the stack pointer no matter how many (maybe zero)
arguments are passed after it.
---
sysdeps/unix/sysv/linux/syscall.c | 35 ++++++++++++++++++++++++-------
1 file changed, 27 insertions(+), 8 deletions(-)
diff --git a/sysdeps/unix/sysv/linux/syscall.c b/sysdeps/unix/sysv/linux/syscall.c
index a5a2843b73..ed5ad5afd5 100644
--- a/sysdeps/unix/sysv/linux/syscall.c
+++ b/sysdeps/unix/sysv/linux/syscall.c
@@ -16,9 +16,33 @@
License along with the GNU C Library. If not, see
<https://www.gnu.org/licenses/>. */
-#include <stdarg.h>
#include <sysdep.h>
+#ifndef __ASSUME_SYSCALL_NAMED_WORKS
+#include <stdarg.h>
+#endif
+
+static inline long int
+__syscall (long int number, long int a0, long int a1, long int a2, long int a3,
+ long int a4, long int a5)
+{
+ long int r = INTERNAL_SYSCALL_NCS_CALL (number, a0, a1, a2, a3, a4, a5);
+ if (__glibc_unlikely (INTERNAL_SYSCALL_ERROR_P (r)))
+ {
+ __set_errno (-r);
+ return -1;
+ }
+ return r;
+}
+
+#ifdef __ASSUME_SYSCALL_NAMED_WORKS
+long int
+syscall (long int number, long int a0, long int a1, long int a2, long int a3,
+ long int a4, long int a5)
+{
+ return __syscall (number, a0, a1, a2, a3, a4, a5);
+}
+#else
long int
syscall (long int number, ...)
{
@@ -33,11 +57,6 @@ syscall (long int number, ...)
long int a5 = va_arg (args, long int);
va_end (args);
- long int r = INTERNAL_SYSCALL_NCS_CALL (number, a0, a1, a2, a3, a4, a5);
- if (__glibc_unlikely (INTERNAL_SYSCALL_ERROR_P (r)))
- {
- __set_errno (-r);
- return -1;
- }
- return r;
+ return __syscall (number, a0, a1, a2, a3, a4, a5);
}
+#endif
--
2.40.0
next prev parent reply other threads:[~2023-03-25 14:08 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-25 14:08 [PATCH v2 0/5] linux: Avoid va_list for generic syscall wrappers if possible Xi Ruoyao
2023-03-25 14:08 ` Xi Ruoyao [this message]
2023-03-25 14:08 ` [PATCH v2 2/5] linux: [__ASSUME_SYSCALL_NAMED_WORKS] Avoid using va_list for various syscall wrappers Xi Ruoyao
2023-03-25 14:08 ` [PATCH v2 3/5] LoongArch: Define __ASSUME_SYSCALL_NAMED_WORKS for Linux Xi Ruoyao
2023-03-25 14:08 ` [PATCH v2 4/5] x86_64: " Xi Ruoyao
2023-03-25 14:08 ` [PATCH v2 5/5] aarch64: " Xi Ruoyao
2023-03-27 13:06 ` Adhemerval Zanella Netto
2023-03-27 13:32 ` Xi Ruoyao
2023-03-27 14:04 ` [PATCH v2 0/5] linux: Avoid va_list for generic syscall wrappers if possible Carlos O'Donell
2023-03-27 14:44 ` Xi Ruoyao
2023-03-27 14:45 ` Xi Ruoyao
2023-03-27 14:51 ` Xi Ruoyao
2023-04-04 1:25 ` caiyinyu
2023-04-04 12:12 ` Xi Ruoyao
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=20230325140815.4170296-2-xry111@xry111.site \
--to=xry111@xry111.site \
--cc=adhemerval.zanella@linaro.org \
--cc=caiyinyu@loongson.cn \
--cc=fw@deneb.enyo.de \
--cc=i@xen0n.name \
--cc=libc-alpha@sourceware.org \
--cc=schwab@suse.de \
/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).