Toru Nishimura | 20 Apr 2012 13:44

PowerPC pcc generates incorrect insn

Hi, pcc-list,

I realized powerpc-pcc emits incorrect insn which gas refuses to accept.

$ pcc -c bogus.c 
/tmp/ctm.18892a: Assembler messages:
/tmp/ctm.18892a:17: Error: operand out of range (0xffffffff is not between 0x00000000 and 0x0000ffff)

The line is;

        cmplwi %r2,-1

The "cmplwi" instruction only takes zero-extened 16bit imm value and not
possible to have -1 in the imm operand.  How can I fix the error?  The pcc
version is 1.0.0 provided as one of precompiled NetBSD pkgsrc.

Toru Nishimura / ALKYL Technology

Iain Hibbert | 20 Apr 2012 15:45

Re: PowerPC pcc generates incorrect insn

On Fri, 20 Apr 2012, Toru Nishimura wrote:

> Hi, pcc-list,
>
> I realized powerpc-pcc emits incorrect insn which gas refuses to accept.
>
> $ pcc -c bogus.c /tmp/ctm.18892a: Assembler messages:
> /tmp/ctm.18892a:17: Error: operand out of range (0xffffffff is not between
> 0x00000000 and 0x0000ffff)
>
> The line is;
>
>        cmplwi %r2,-1
>
> The "cmplwi" instruction only takes zero-extened 16bit imm value and not
> possible to have -1 in the imm operand.  How can I fix the error?  The pcc
> version is 1.0.0 provided as one of precompiled NetBSD pkgsrc.

you may find updating to pcc-current more useful, not that I think there
were improvements in powerpc support, but there were other bugfixes in the
meantime

this instruction is emitted, I think, because of the entry in
arch/powerpc/table.c at line 1347 :

/* compare with constant */
{ OPLOG,	FORCC,
	SAREG,	TUWORD|TPOINT|TUSHORT|TUCHAR,
	SSCON,	TANY,
		0, 	RESCC,
(Continue reading)

Anders Magnusson | 20 Apr 2012 21:49
Picon

Re: PowerPC pcc generates incorrect insn

Hi,

On 04/20/2012 03:45 PM, Iain Hibbert wrote:
> On Fri, 20 Apr 2012, Toru Nishimura wrote:
>
>> Hi, pcc-list,
>>
>> I realized powerpc-pcc emits incorrect insn which gas refuses to accept.
>>
>> $ pcc -c bogus.c /tmp/ctm.18892a: Assembler messages:
>> /tmp/ctm.18892a:17: Error: operand out of range (0xffffffff is not between
>> 0x00000000 and 0x0000ffff)
>>
>> The line is;
>>
>>         cmplwi %r2,-1
>>
>> The "cmplwi" instruction only takes zero-extened 16bit imm value and not
>> possible to have -1 in the imm operand.  How can I fix the error?  The pcc
>> version is 1.0.0 provided as one of precompiled NetBSD pkgsrc.
> you may find updating to pcc-current more useful, not that I think there
> were improvements in powerpc support, but there were other bugfixes in the
> meantime
>
> this instruction is emitted, I think, because of the entry in
> arch/powerpc/table.c at line 1347 :
>
> /* compare with constant */
> { OPLOG,	FORCC,
> 	SAREG,	TUWORD|TPOINT|TUSHORT|TUCHAR,
(Continue reading)

Toru Nishimura | 21 Apr 2012 03:49

Re: PowerPC pcc generates incorrect insn

Hi,

>> /* compare with constant */
>> { OPLOG, FORCC,
>> SAREG, TUWORD|TPOINT|TUSHORT|TUCHAR,
>> SSCON, TANY,
>> 0, RESCC,
>> " cmplwi AL,AR\n", },
>>
>> so I guess that the TANY should be more limited here, perhaps
>> TUSHORT|TUCHAR ?
>
> Correct.  And depending on how the instruction works (sign
> extension or not of constants) modifications may be needed to
> the constant printout routine.  This is in local2.c:adrput().

To have 3 way brach cases?
- zero-extended 16bit imm
- sign-extended 16bit imm
- arbitray 32bit constant, in a scratch register

PowerPC gcc seems not to emit the trivial 'cmpi %c, %r, -1' there.

Toru Nishimura / ALKYL Technology

Anders Magnusson | 21 Apr 2012 10:28
Picon

Re: PowerPC pcc generates incorrect insn

On 04/21/2012 03:49 AM, Toru Nishimura wrote:
> Hi,
>
>>> /* compare with constant */
>>> { OPLOG, FORCC,
>>> SAREG, TUWORD|TPOINT|TUSHORT|TUCHAR,
>>> SSCON, TANY,
>>> 0, RESCC,
>>> " cmplwi AL,AR\n", },
>>>
>>> so I guess that the TANY should be more limited here, perhaps
>>> TUSHORT|TUCHAR ?
>>
>> Correct.  And depending on how the instruction works (sign
>> extension or not of constants) modifications may be needed to
>> the constant printout routine.  This is in local2.c:adrput().
>
> To have 3 way brach cases?
> - zero-extended 16bit imm
> - sign-extended 16bit imm
> - arbitray 32bit constant, in a scratch register
Yes, something like that;
     if (p->n_type == SHORT || p->n_type == USHORT)
         printf("%d", val & 0xffff);
     else
         printf("%d", val & 0xffff);
would work I assume?

>
> PowerPC gcc seems not to emit the trivial 'cmpi %c, %r, -1' there.
(Continue reading)

Toru Nishimura | 21 Apr 2012 11:07

Re: PowerPC pcc generates incorrect insn

>> PowerPC gcc seems not to emit the trivial 'cmpi %c, %r, -1' there.
>>
> Feel free to add it, my knowledge about powerpc architecture is ~NIL.
> If you explain what it does I can help writing a table entry for it.

The Appendix A "Instruction Set Listings" is a handy reference;
http://www.freescale.com/files/32bit/doc/ref_manual/e300coreRM.pdf

The Appendix C "Simplied Mnemonics" is found also useful.
http://www.phxmicro.com/CourseNotes/E600CORERM_rev0.pdf

Toru Nishimura / ALKYL Technology

Anders Magnusson | 21 Apr 2012 14:58
Picon

Re: PowerPC pcc generates incorrect insn

On 04/21/2012 11:07 AM, Toru Nishimura wrote:
>>> PowerPC gcc seems not to emit the trivial 'cmpi %c, %r, -1' there.
>>>
>> Feel free to add it, my knowledge about powerpc architecture is ~NIL.
>> If you explain what it does I can help writing a table entry for it.
>
> The Appendix A "Instruction Set Listings" is a handy reference;
> http://www.freescale.com/files/32bit/doc/ref_manual/e300coreRM.pdf
>
> The Appendix C "Simplied Mnemonics" is found also useful.
> http://www.phxmicro.com/CourseNotes/E600CORERM_rev0.pdf
Thanks, but to clarify what I meant (but didn't write); I do not have
neither test environment nor time to jump into one more architecture.

I will do my best though to help people that want to hack on these 
targets though.

-- Ragge

Toru Nishimura | 22 Apr 2012 01:22

Re: PowerPC pcc generates incorrect insn

Hi,

> Thanks, but to clarify what I meant (but didn't write); I do not have
> neither test environment nor time to jump into one more architecture.
> 
> I will do my best though to help people that want to hack on these 
> targets though.

Ok, I'm not complaining.  I try to understand pcc internal to enhance
code.  I have PPC at my desk for development.

Toru Nishimura / ALKYL Technology

Anders Magnusson | 21 Apr 2012 14:53
Picon

Re: PowerPC pcc generates incorrect insn

On 04/21/2012 10:28 AM, Anders Magnusson wrote:
> On 04/21/2012 03:49 AM, Toru Nishimura wrote:
>> Hi,
>>
>>>> /* compare with constant */
>>>> { OPLOG, FORCC,
>>>> SAREG, TUWORD|TPOINT|TUSHORT|TUCHAR,
>>>> SSCON, TANY,
>>>> 0, RESCC,
>>>> " cmplwi AL,AR\n", },
>>>>
>>>> so I guess that the TANY should be more limited here, perhaps
>>>> TUSHORT|TUCHAR ?
>>>
>>> Correct.  And depending on how the instruction works (sign
>>> extension or not of constants) modifications may be needed to
>>> the constant printout routine.  This is in local2.c:adrput().
>>
>> To have 3 way brach cases?
>> - zero-extended 16bit imm
>> - sign-extended 16bit imm
>> - arbitray 32bit constant, in a scratch register
> Yes, something like that;
>     if (p->n_type == SHORT || p->n_type == USHORT)
>         printf("%d", val & 0xffff);
>     else
>         printf("%d", val & 0xffff);
> would work I assume?
Err, second line should of course be printf("%d", val) :-)
Thanks HÃ¥vard for pointing it out.
(Continue reading)

Toru Nishimura | 21 Apr 2012 12:26

Re: PowerPC pcc generates incorrect insn

> The Appendix C "Simplied Mnemonics" is found also useful.
> http://www.phxmicro.com/CourseNotes/E600CORERM_rev0.pdf

It's a mis-quote.  I wanted to refer;
http://www.freescale.com/files/32bit/doc/ref_manual/EREF_RM.pdf

 Toru Nishimura / ALKYL Technology


Gmane