Discussion:
PowerPC pcc generates incorrect insn
Toru Nishimura
2012-04-20 11:44:19 UTC
Permalink
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
2012-04-20 13:45:54 UTC
Permalink
Post by Toru Nishimura
Hi, pcc-list,
I realized powerpc-pcc emits incorrect insn which gas refuses to accept.
/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,
" cmplwi AL,AR\n", },

so I guess that the TANY should be more limited here, perhaps
TUSHORT|TUCHAR ?

regards,
iain
Anders Magnusson
2012-04-20 19:49:15 UTC
Permalink
Hi,
Post by Iain Hibbert
Post by Toru Nishimura
Hi, pcc-list,
I realized powerpc-pcc emits incorrect insn which gas refuses to accept.
/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
/* 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().

-- Ragge
Toru Nishimura
2012-04-21 01:49:51 UTC
Permalink
Hi,
Post by Anders Magnusson
Post by Iain Hibbert
/* 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
2012-04-21 08:28:15 UTC
Permalink
Post by Toru Nishimura
Hi,
Post by Anders Magnusson
Post by Iain Hibbert
/* 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?
Post by Toru Nishimura
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.

-- Ragge
Post by Toru Nishimura
Toru Nishimura / ALKYL Technology
Toru Nishimura
2012-04-21 09:07:07 UTC
Permalink
Post by Anders Magnusson
Post by Toru Nishimura
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
2012-04-21 12:58:41 UTC
Permalink
Post by Toru Nishimura
Post by Anders Magnusson
Post by Toru Nishimura
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
2012-04-21 23:22:00 UTC
Permalink
Hi,
Post by Anders Magnusson
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
2012-04-21 12:53:29 UTC
Permalink
Post by Anders Magnusson
Post by Toru Nishimura
Hi,
Post by Anders Magnusson
Post by Iain Hibbert
/* 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.

-- Ragge
Toru Nishimura
2012-04-21 10:26:10 UTC
Permalink
Post by Toru Nishimura
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
Loading...