From: Segher Boessenkool <segher@kernel.crashing.org>
To: Florian Weimer <fweimer@redhat.com>
Cc: libc-alpha@sourceware.org,
Tulio Magno Quites Machado Filho <tuliom@linux.ibm.com>,
linuxppc-dev@lists.ozlabs.org,
Nicholas Piggin <npiggin@gmail.com>
Subject: Re: powerpc Linux scv support and scv system call ABI proposal
Date: Thu, 30 Jan 2020 07:50:30 -0600 [thread overview]
Message-ID: <20200130135030.GV22482@gate.crashing.org> (raw)
In-Reply-To: <87y2tp40d2.fsf@oldenburg2.str.redhat.com>
Hi again,
On Thu, Jan 30, 2020 at 01:03:53PM +0100, Florian Weimer wrote:
> > This is why that *is* the only supported use. The documentation could
> > use a touch-up, I think. Unless we still have problems here?
>
> I really don't know. GCC still has *some* support for the old behavior,
> though.
No. No support. It still does some of the same things, but that can
change (and probably should). But this hasn't been supported since the
dark ages, and the documentation has become gradually more explicit
about it.
> For example, local register variables are treated as
> initialized, and I think you can still use registers like global
> variables. GCC does not perform copy propagation here:
>
> int f1 (int);
>
> int
> f (void)
> {
> register int edi __asm__ ("edi");
> int edi_copy = edi;
> return f1 (1) + edi_copy;
> }
f:
pushl %edi
subl $20, %esp
pushl $1
call f1
addl %edi, %eax
addl $24, %esp
popl %edi
ret
It takes the edi value *after* the call. The behaviour is undefined,
so that is not a problem. (This is a GCC 10 from September, fwiw).
> And the case that we agreed should be defined in fact is not:
>
> void f1 (int);
>
> int
> f (void)
> {
> register int edi __asm__ ("edi");
> asm ("#" : "=r" (edi));
> f1 (1);
> return edi;
> }
f:
pushl %edi
subl $20, %esp
#APP
#
#NO_APP
pushl $1
call f1
movl %edi, %eax
addl $24, %esp
popl %edi
ret
Changing it to "# %0" (so that we can see what we are doing) gives
#APP
# %edi
#NO_APP
All as expected.
> On x86-64,
Oh, this was i386, since you used edi. On x86-64:
f:
pushq %rbx
movl %edi, %ebx
movl $1, %edi
call f1
addl %ebx, %eax
popq %rbx
ret
for that first testcase, taking edi before the call, which is not
*guaranteed* to happen, but still can; and
f:
subq $8, %rsp
movl $1, %edi
call f1
addq $8, %rsp
movl %edi, %eax
ret
The asm was right before that "mov $1,%edi", so it was optimised away:
it is not a volatile asm, and its output is unused. Making the asm
statement volatile gives
f:
subq $8, %rsp
#APP
# %edi
#NO_APP
movl $1, %edi
call f1
addq $8, %rsp
movl %edi, %eax
ret
> %edi is used to pass the first function parameter, so the
> call clobbers %edi. It is simply ambiguous whether edi (the variable)
> should retain the value prior to the call to f1 (which I think is what
> should happen under the new model, where register variables are only
> affect asm operands), or if edi (the variable) should have the value of
> %edi (the register) after the call (the old model).
There is nothing ambiguous there, afaics? Other than the edi value you
use in the asm is coming out of thin air (but it will always work with
current GCC; that's not really specified though).
> Should we move this to the gcc list?
Whoops, I thought that was on Cc:. Sure.
Segher
next prev parent reply other threads:[~2020-01-30 13:53 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-28 10:50 powerpc Linux scv support and scv system call ABI proposal Nicholas Piggin
2020-01-28 13:09 ` Florian Weimer
2020-01-28 14:05 ` Nicholas Piggin
2020-01-28 15:40 ` Segher Boessenkool
2020-01-28 16:04 ` Florian Weimer
2020-01-28 20:01 ` Segher Boessenkool
2020-01-29 16:19 ` Florian Weimer
2020-01-29 16:29 ` Segher Boessenkool
2020-01-29 17:02 ` Florian Weimer
2020-01-29 17:51 ` Segher Boessenkool
2020-01-30 10:42 ` Florian Weimer
2020-01-30 11:25 ` Segher Boessenkool
2020-01-30 12:03 ` Florian Weimer
2020-01-30 13:50 ` Segher Boessenkool [this message]
2020-01-30 17:04 ` Adhemerval Zanella
2020-01-30 21:41 ` Segher Boessenkool
2020-01-31 11:30 ` Adhemerval Zanella
2020-01-31 11:55 ` Segher Boessenkool
2020-01-28 15:58 ` Florian Weimer
2020-01-29 4:41 ` Nicholas Piggin
2020-01-28 17:26 ` Adhemerval Zanella
2020-01-29 4:58 ` Nicholas Piggin
2020-01-29 13:20 ` Segher Boessenkool
2020-01-29 15:51 ` Tulio Magno Quites Machado Filho
2020-02-19 11:03 ` Nicholas Piggin
2020-01-28 22:14 ` Joseph Myers
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=20200130135030.GV22482@gate.crashing.org \
--to=segher@kernel.crashing.org \
--cc=fweimer@redhat.com \
--cc=libc-alpha@sourceware.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=npiggin@gmail.com \
--cc=tuliom@linux.ibm.com \
/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 NNTP newsgroup(s).