From patchwork Sat Mar 25 14:08:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xi Ruoyao X-Patchwork-Id: 1761145 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=K/FXaHOk; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PkLXt11YKz1yYB for ; Sun, 26 Mar 2023 01:09:02 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0C0983851C20 for ; Sat, 25 Mar 2023 14:09:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0C0983851C20 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1679753340; bh=K5h+k1aTYafzTsjEq9ovLtcjzhUqIjDSegHcXb2ddzU=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=K/FXaHOkHQfUCV0PmTIofQw6CnuXy2iKVzaaeIxQk5tS1GOrOIyq/oYq2rItlcOEn uuDbhhJTBzl+H7lQ5FVdKPDeMkx8svdignmWVHHgyxsX+Muq1bmjOR+JUym4Vi/t1t tjnQYL1Px40TFfqyWUeTRHkQ/CWINywHC2wtHJJE= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from xry111.site (xry111.site [IPv6:2001:470:683e::1]) by sourceware.org (Postfix) with ESMTPS id C1B513858C33 for ; Sat, 25 Mar 2023 14:08:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C1B513858C33 Received: from stargazer.. (unknown [IPv6:240e:358:1172:ca00:dc73:854d:832e:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (Client did not present a certificate) (Authenticated sender: xry111@xry111.site) by xry111.site (Postfix) with ESMTPSA id 6E5DC6647A; Sat, 25 Mar 2023 10:08:35 -0400 (EDT) To: libc-alpha@sourceware.org Cc: caiyinyu , Wang Xuerui , Adhemerval Zanella Netto , Andreas Schwab , Florian Weimer , Xi Ruoyao 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 Message-Id: <20230325140815.4170296-2-xry111@xry111.site> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230325140815.4170296-1-xry111@xry111.site> References: <20230325140815.4170296-1-xry111@xry111.site> MIME-Version: 1.0 X-Spam-Status: No, score=-8.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, LIKELY_SPAM_FROM, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Xi Ruoyao via Libc-alpha From: Xi Ruoyao Reply-To: Xi Ruoyao Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" 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 . */ -#include #include +#ifndef __ASSUME_SYSCALL_NAMED_WORKS +#include +#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