This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Simplify handling of NOPOWER4 and mfcr


On Tue, 2008-09-09 at 12:17 +0930, Alan Modra wrote:
> On Mon, Sep 08, 2008 at 08:00:22PM -0500, Peter Bergner wrote:
> > --- gas/config/tc-ppc.c	2 Aug 2008 04:38:50 -0000	1.141
> > +++ gas/config/tc-ppc.c	8 Sep 2008 22:48:17 -0000
> > @@ -1428,15 +1428,8 @@ ppc_setup_opcodes (void)
> >  	  && ((op->flags & PPC_OPCODE_BOOKE64) == 0
> >  	      || (ppc_cpu & PPC_OPCODE_BOOKE64) == PPC_OPCODE_BOOKE64
> >  	      || (ppc_cpu & PPC_OPCODE_BOOKE) == 0)
> > -	  && ((op->flags & (PPC_OPCODE_POWER4 | PPC_OPCODE_NOPOWER4)) == 0
> > -	      || ((op->flags & PPC_OPCODE_POWER4)
> > -		  == (ppc_cpu & PPC_OPCODE_POWER4)))
> > -	  && ((op->flags & PPC_OPCODE_POWER5) == 0
> > -	      || ((op->flags & PPC_OPCODE_POWER5)
> > -		  == (ppc_cpu & PPC_OPCODE_POWER5)))
> > -	  && ((op->flags & PPC_OPCODE_POWER6) == 0
> > -	      || ((op->flags & PPC_OPCODE_POWER6)
> > -		  == (ppc_cpu & PPC_OPCODE_POWER6))))
> > +	  && ((ppc_cpu & PPC_OPCODE_POWER4) == 0
> > +	      || (op->flags & PPC_OPCODE_NOPOWER4) == 0))
> 
> Seems to me this will enable power4 instructions when ppc_cpu says
> otherwise.

To say I had to stare at this piece of code for a while before I understood
(if I really even do understand) it, would be an understatement.  I don't think
the new code will enable power4 instructions, but I wouldn't be surprised to
be proven wrong.

How I _think_ the IF test works, is basically it inserts all opcodes into the
hash list (assuming (op->flags & ppc_cpu) != 0 which is tested for in the first
IF condition), except for those that are explicitly disallowed by the other
IF conditions.  So the secondary tests always "true" except when we explicitly
want to disallow an opcode even though (op->flags & ppc_cpu) != 0.  An example
is the mfcr instruction which I'm trying to hack on.  The first mfcr opcode
normally would be what would be added to the hash list for POWER4 since
POWER4 contains the COM flag, but it is explicitly skipped by the NOPOWER4
flag, so we end up picking up the second entry which has the optional FXM
field.

Looking at your old code, we see that if the insn does not have either of
the POWER4 or NOPOWER4 flags set, then we allow the opcode to pass (ie, be
inserted into the hash list).  However, if one of them is set in the insn,
then we only allow this insn to be inserted if POWER4 is set in both the
insn flags and ppc_cpu flags.

          && ((op->flags & (PPC_OPCODE_POWER4 | PPC_OPCODE_NOPOWER4)) == 0
              || ((op->flags & PPC_OPCODE_POWER4)
                  == (ppc_cpu & PPC_OPCODE_POWER4)))

I believe my code does the same thing, meaning if we're not compiling for
POWER4 (ie, ppc_cpu does not contain POWER4), then this insn cannot be one
of the special cases we're trying to exclude, so we let it pass.  If we are
compiling for POWER4, then we only allow this insn to pass if it does not
have the NOPOWER4 insn flag set.  Note that it doesn't have to have the
POWER4 op->flags bit set, since this might be a COM, PPCOM or ... insn.
The first condition in the IF has already confirmed this insn has at least
one common bit between op->flags and ppc_cpu.

Of course, I really trust myself, so I did try assembling some examples
of POWER4 and non POWER4 instructions to make sure we accept insns when
we should and reject them when we should.  The example below seems to
sow to me its working as intended.  Do you have a specific example of
how you think this will fail?

...and sorry for the long winded reply. :)

Peter



bergner@etna:~/binutils/tests> cat mfcr.s 
	.section	".text"
start:
	attn		# POWER4 insn
	mfcr	2,128	# POWER4 insn
	mfcr	2	# PowerPC Common insn
bergner@etna:~/binutils/tests> ~/binutils/build/gas/as-new -a32 -mpower4 mfcr.s 
bergner@etna:~/binutils/tests> ~/binutils/build/gas/as-new -a32 -mpower5 mfcr.s 
bergner@etna:~/binutils/tests> ~/binutils/build/gas/as-new -a32 -mpower6 mfcr.s 
bergner@etna:~/binutils/tests> ~/binutils/build/gas/as-new -a32 -mppc mfcr.s 
mfcr.s: Assembler messages:
mfcr.s:3: Error: Unrecognized opcode: `attn'
mfcr.s:4: Error: junk at end of line: `128'
bergner@etna:~/binutils/tests> ~/binutils/build/gas/as-new -a32 -mcom mfcr.s 
mfcr.s: Assembler messages:
mfcr.s:3: Error: Unrecognized opcode: `attn'
mfcr.s:4: Error: junk at end of line: `128'
bergner@etna:~/binutils/tests> ~/binutils/build/gas/as-new -a32 -mpwr mfcr.s 
mfcr.s: Assembler messages:
mfcr.s:3: Error: Unrecognized opcode: `attn'
mfcr.s:4: Error: junk at end of line: `128'



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]