Subject: Re: [PATCH] powerpc: cmp -> cmpd for 64-bit

From: Segher Boessenkool <[email-masked]>
Date: Wed, 12 Oct 2016 08:26:48 -0500

On Wed, Oct 12, 2016 at 02:05:19PM +1100, Michael Ellerman wrote:
> Segher Boessenkool <[email-masked]> writes:
> 
> > PowerPC's "cmp" instruction has four operands.  Normally people write
> > "cmpw" or "cmpd" for the second cmp operand 0 or 1.  But, frequently
> > people forget, and write "cmp" with just three operands.
> >
> > With older binutils this is silently accepted as if this was "cmpw",
> > while often "cmpd" is wanted.  With newer binutils GAS will complain
> > about this for 64-bit code.  For 32-bit code it still silently assumes
> > "cmpw" is what is meant.
> 
> Thanks.
> 
> Anton already sent a fix for the two vdso ones, which were real bugs,
> and that's now in Linus' tree.

Ah cool.  You'll just need the one then (and many more for book4e, but
I cannot really handle that, other people can do that a lot better).

> > --- a/arch/powerpc/include/asm/cpuidle.h
> > +++ b/arch/powerpc/include/asm/cpuidle.h
> > @@ -26,7 +26,7 @@ extern u64 pnv_first_deep_stop_state;
> 
> #define	IDLE_STATE_ENTER_SEQ(IDLE_INST)				\
> 	/* Magic NAP/SLEEP/WINKLE mode enter sequence */	\
> >  	std	r0,0(r1);					\
> >  	ptesync;						\
> >  	ld	r0,0(r1);					\
> > -1:	cmp	cr0,r0,r0;					\
> > +1:	cmpd	cr0,r0,r0;					\
> >  	bne	1b;						\
> >  	IDLE_INST;						\
> >  	b	.
> 
> What's this one doing, is it a bug? I can't really tell without knowing
> what the magic sequence is meant to do.

It looks like it is making sure the ptesync is done.  The ld/cmp/bne
is the usual to make sure the ld is done, and in std/ptesync/ld the ld
won't be done before the ptesync is done.

The cmp always compares equal, of course, so both cmpw and cmpd would
work fine here.  cmpd looks better after ld ;-)

Segher