public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Xi Ruoyao <xry111@xry111.site>
To: Adhemerval Zanella Netto <adhemerval.zanella@linaro.org>,
	Andreas Schwab <schwab@suse.de>, caiyinyu <caiyinyu@loongson.cn>
Cc: libc-alpha@sourceware.org
Subject: Re: [PATCH] LoongArch: Add Syscall Assembly Implementation
Date: Fri, 24 Mar 2023 03:08:09 +0800	[thread overview]
Message-ID: <736fc1a007e8296612601bb53b3880f89e88c60e.camel@xry111.site> (raw)
In-Reply-To: <d32a838e-8887-3a62-498f-8e3f2d0b4882@linaro.org>

On Thu, 2023-03-23 at 15:40 -0300, Adhemerval Zanella Netto wrote:
> 
> On 23/03/23 15:26, Xi Ruoyao wrote:
> > 
> > LoongArch has a TARGET_SETUP_INCOMING_VARARGS but it does not use the
> > information from stdarg pass.  I can fix it, but even with the fix GCC
> > would still save 7 registers (now GCC trunk saves 9 registers, the fix
> > would make some improvement but no much).
> > 
> > And the issue seems not trivial to fix.  On x86_64, all of GCC, Clang,
> > and MSVC will save some registers if va_arg is used.  I've not found any
> > compiler which can avoid saving the va_arg GARs unnecessarily yet:
> > 
> > https://godbolt.org/z/n1YqWq9c9
> > 
> > Now to me it seems a bad idea to use va_arg in syscall.c.
> > 
> 
> I think it was the natural way to express kernel communication mechanism
> that indeed takes variadic arguments.   And since it is older than Linux
> (man-pages stated it was from 4BSD), it also mean that you don't bind a
> maximum limit or arguments (although on Linux and BSD does have a pratical
> limit).

Well, my statement is only for Linux and a modern architecture with
enough GARs.

> We can maybe add a implementation that uses named args (which extra
> boilerplate to architectures that accepts 7 arguments instead of usual
> 6); and just enable it if a per-architecture flag is set meaning that
> for that specific ABI the variadic is essentially the same as named
> functions calls.  Something like:
> 
> long int
> syscall (long int number, 
> #if __ASSUME_SYSCALL_NAMED_WORKS
>          long int a0, long int a1, long int a2,
>          long int a3, long int a4, long int a5
> #else
>          ...
> #endif

/* snip */

> It might need some more hacks to hide the syscall prototype.

I've already tried something similar on my box (I named the macro
"SYSCALL_VA_ARG_NOT_NEEDED"); it looks like we don't need to hide the
syscall prototype:  unistd.h is not in misc/syscall.o.d.

The disassemble of misc/syscall.o looks perfect when I defined the macro
in sysdep/unix/sysv/linux/loongarch/sysdep.h:

0000000000000000 <syscall>:
   0:	0015008b 	move        	$a7, $a0
   4:	001500a4 	move        	$a0, $a1
   8:	001500c5 	move        	$a1, $a2
   c:	001500e6 	move        	$a2, $a3
  10:	00150107 	move        	$a3, $a4
  14:	00150128 	move        	$a4, $a5
  18:	00150149 	move        	$a5, $a6
  1c:	002b0000 	syscall     	0x0
  20:	15ffffec 	lu12i.w     	$t0, -1(0xfffff)
  24:	68000984 	bltu        	$t0, $a0, 8(0x8)	# 2c <syscall+0x2c>
  28:	4c000020 	jirl        	$zero, $ra, 0
  2c:	1a00000c 	pcalau12i   	$t0, 0
  30:	00111004 	sub.w       	$a0, $zero, $a0
  34:	28c0018c 	ld.d        	$t0, $t0, 0
  38:	38180984 	stx.w       	$a0, $t0, $tp
  3c:	02bffc04 	addi.w      	$a0, $zero, -1(0xfff)
  40:	4c000020 	jirl        	$zero, $ra, 0

-- 
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University

  reply	other threads:[~2023-03-23 19:08 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-23  8:40 caiyinyu
2023-03-23  9:25 ` Xi Ruoyao
2023-03-23 12:01   ` caiyinyu
2023-03-23 13:12     ` Andreas Schwab
2023-03-23 13:34       ` Xi Ruoyao
2023-03-23 13:43         ` Xi Ruoyao
2023-03-23 17:34           ` Xi Ruoyao
2023-03-23 18:26             ` Xi Ruoyao
2023-03-23 18:40               ` Adhemerval Zanella Netto
2023-03-23 19:08                 ` Xi Ruoyao [this message]
2023-03-23 13:12     ` Xi Ruoyao
2023-03-23 12:00 caiyinyu

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=736fc1a007e8296612601bb53b3880f89e88c60e.camel@xry111.site \
    --to=xry111@xry111.site \
    --cc=adhemerval.zanella@linaro.org \
    --cc=caiyinyu@loongson.cn \
    --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).