public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Converting addc to adcx
@ 2019-05-31 10:34 Jeffrey Walton
  2019-05-31 11:19 ` Segher Boessenkool
  0 siblings, 1 reply; 5+ messages in thread
From: Jeffrey Walton @ 2019-05-31 10:34 UTC (permalink / raw)
  To: gcc-help

Hi Everyone,

We have this inline asm on x86_64. Notice adcq and the constant $0:

    asm ("addq %2, %0; adcq $0, %1;" : "+r"(a0), "+r"(a1) : "r"(b) : "cc");

I convert it to adcx. This conversion tests OK.

    asm ("addq %2, %0; adcx %3, %1;" : "+r"(a0), "+r"(a1) : "r"(b),
"r"(0ULL) : "cc");

Is this a valid conversion?

The reason I ask is, I've got a larger one with 9 operands. When I
make the same change (swap constant for a positional with 0) and test
it, it fails. The only thing I can think of is, it is not a valid
conversion but the tools don't reject it.

Jeff

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Converting addc to adcx
  2019-05-31 10:34 Converting addc to adcx Jeffrey Walton
@ 2019-05-31 11:19 ` Segher Boessenkool
  2019-05-31 11:30   ` Jeffrey Walton
  0 siblings, 1 reply; 5+ messages in thread
From: Segher Boessenkool @ 2019-05-31 11:19 UTC (permalink / raw)
  To: Jeffrey Walton; +Cc: gcc-help

On Fri, May 31, 2019 at 06:34:19AM -0400, Jeffrey Walton wrote:
> We have this inline asm on x86_64. Notice adcq and the constant $0:
> 
>     asm ("addq %2, %0; adcq $0, %1;" : "+r"(a0), "+r"(a1) : "r"(b) : "cc");
> 
> I convert it to adcx. This conversion tests OK.
> 
>     asm ("addq %2, %0; adcx %3, %1;" : "+r"(a0), "+r"(a1) : "r"(b),
> "r"(0ULL) : "cc");
> 
> Is this a valid conversion?

Writing to %0 can clobber %3, the way you wrote it.  Use an earlyclobber?

(Look at the generated code to see what is happening -- use -S instead of -c
for example).


Segher

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Converting addc to adcx
  2019-05-31 11:19 ` Segher Boessenkool
@ 2019-05-31 11:30   ` Jeffrey Walton
  2019-05-31 11:47     ` Segher Boessenkool
  0 siblings, 1 reply; 5+ messages in thread
From: Jeffrey Walton @ 2019-05-31 11:30 UTC (permalink / raw)
  To: Segher Boessenkool; +Cc: gcc-help

On Fri, May 31, 2019 at 7:19 AM Segher Boessenkool
<segher@kernel.crashing.org> wrote:
>
> On Fri, May 31, 2019 at 06:34:19AM -0400, Jeffrey Walton wrote:
> > We have this inline asm on x86_64. Notice adcq and the constant $0:
> >
> >     asm ("addq %2, %0; adcq $0, %1;" : "+r"(a0), "+r"(a1) : "r"(b) : "cc");
> >
> > I convert it to adcx. This conversion tests OK.
> >
> >     asm ("addq %2, %0; adcx %3, %1;" : "+r"(a0), "+r"(a1) : "r"(b),
> > "r"(0ULL) : "cc");
> >
> > Is this a valid conversion?
>
> Writing to %0 can clobber %3, the way you wrote it.  Use an earlyclobber?
>
> (Look at the generated code to see what is happening -- use -S instead of -c
> for example).

Man, it did not like that when using "&=r"(0ULL) (hundreds of them):

     error: lvalue required in asm statement

(I assume you wanted an early clobber on the input %3).

Jeff

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Converting addc to adcx
  2019-05-31 11:30   ` Jeffrey Walton
@ 2019-05-31 11:47     ` Segher Boessenkool
  2019-05-31 14:26       ` Jeffrey Walton
  0 siblings, 1 reply; 5+ messages in thread
From: Segher Boessenkool @ 2019-05-31 11:47 UTC (permalink / raw)
  To: Jeffrey Walton; +Cc: gcc-help

On Fri, May 31, 2019 at 07:29:43AM -0400, Jeffrey Walton wrote:
> On Fri, May 31, 2019 at 7:19 AM Segher Boessenkool
> <segher@kernel.crashing.org> wrote:
> >
> > On Fri, May 31, 2019 at 06:34:19AM -0400, Jeffrey Walton wrote:
> > > We have this inline asm on x86_64. Notice adcq and the constant $0:
> > >
> > >     asm ("addq %2, %0; adcq $0, %1;" : "+r"(a0), "+r"(a1) : "r"(b) : "cc");
> > >
> > > I convert it to adcx. This conversion tests OK.
> > >
> > >     asm ("addq %2, %0; adcx %3, %1;" : "+r"(a0), "+r"(a1) : "r"(b),
> > > "r"(0ULL) : "cc");
> > >
> > > Is this a valid conversion?
> >
> > Writing to %0 can clobber %3, the way you wrote it.  Use an earlyclobber?
> >
> > (Look at the generated code to see what is happening -- use -S instead of -c
> > for example).
> 
> Man, it did not like that when using "&=r"(0ULL) (hundreds of them):
> 
>      error: lvalue required in asm statement
> 
> (I assume you wanted an early clobber on the input %3).

You are saying there that you want to output to something that is constant 0.
Yeah that doesn't work ;-)

You should put the earlyclobber on the output, to tell GCC that that output
(register) is clobbered early, i.e. before all inputs are used (so that GCC
then knows to not put that output in the same place as one of the inputs).
Like so:

  asm ("addq %2, %0; adcx %3, %1;"
       : "+&r"(a0), "+r"(a1)
       : "r"(b), "r"(0ULL)
       : "cc");


Segher

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Converting addc to adcx
  2019-05-31 11:47     ` Segher Boessenkool
@ 2019-05-31 14:26       ` Jeffrey Walton
  0 siblings, 0 replies; 5+ messages in thread
From: Jeffrey Walton @ 2019-05-31 14:26 UTC (permalink / raw)
  To: Segher Boessenkool; +Cc: gcc-help

On Fri, May 31, 2019 at 7:47 AM Segher Boessenkool
<segher@kernel.crashing.org> wrote:
> ...
> > Man, it did not like that when using "&=r"(0ULL) (hundreds of them):
> >
> >      error: lvalue required in asm statement
> >
> > (I assume you wanted an early clobber on the input %3).
>
> You are saying there that you want to output to something that is constant 0.
> Yeah that doesn't work ;-)
>
> You should put the earlyclobber on the output, to tell GCC that that output
> (register) is clobbered early, i.e. before all inputs are used (so that GCC
> then knows to not put that output in the same place as one of the inputs).
> Like so:

Thanks Segher. That fixed it for me.

Jeff

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-05-31 14:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-31 10:34 Converting addc to adcx Jeffrey Walton
2019-05-31 11:19 ` Segher Boessenkool
2019-05-31 11:30   ` Jeffrey Walton
2019-05-31 11:47     ` Segher Boessenkool
2019-05-31 14:26       ` Jeffrey Walton

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).