Discussion:
Crosscompiling trouble
(too old to reply)
Fernando Pena López
2006-02-09 12:34:30 UTC
Permalink
Hi all...

I'm trying to crosscompile some code for a ppc403 and I'm getting problems
at the beginning...
The problem is not with the compiler, just the assembler (GNU as).
I'm trying to assemble some elementary code like this one:
li %r3, 0xFFFF
and I always get the same error:
"fast_init.s:96: Error: operand out of range (65535 not between -32768 and
32767)"
In this case, the offending line is the line number 96, but I get the error
in every "li" opcode.
The funny thing is that if the opcode is "lis", there are no errors...
Maybe It's a syntax mistake, but I can't find any doc about the syntax for
ppc arch.
The "as" version is 2.15, and the command that I use to assemble is
"powerpc-linux-as -o fast_init.o -m403 fast_init.s"
Any clue?

Thanks in advance.

Fernando Pena López.
<***@mundo-r.com>
l'indien
2006-02-09 22:05:35 UTC
Permalink
Post by Fernando Pena López
Hi all...
I'm trying to crosscompile some code for a ppc403 and I'm getting problems
at the beginning...
The problem is not with the compiler, just the assembler (GNU as). I'm
li %r3, 0xFFFF
"fast_init.s:96: Error: operand out of range (65535 not between -32768 and
32767)"
In this case, the offending line is the line number 96, but I get the
error in every "li" opcode.
The funny thing is that if the opcode is "lis", there are no errors...
Maybe It's a syntax mistake, but I can't find any doc about the syntax for
ppc arch.
The "as" version is 2.15, and the command that I use to assemble is
"powerpc-linux-as -o fast_init.o -m403 fast_init.s" Any clue?
li is a shortcut for addi rD, 0, value
and lis for addis rD, 0, value
add takes signed operands.
addi & addis sign extend their immediate operand to 32 bits.
When using addi, you need to give a signed operand because
0xFFFF extended to 32 bits is 0xFFFF if unsigned and 0xFFFFFFFF if
signed.
Then, you've got to use li %r3, 0xFFFFFFFF
You don't have this constraint when using lis on 32 bits PowerPC
architecture, as the immediate value is shifted left _before_ been
extended to 32 bits. Then, the result is the same when using signed or
unsigned values.
But the constraint will (should ?) come back if compiling for a 64 bits
PowerPC machine because the constant need to be signed extended from
(value << 16) to a signed 64 bits constant.

Hope this helps...
Fernando Pena López
2006-02-09 23:03:45 UTC
Permalink
Post by l'indien
li is a shortcut for addi rD, 0, value
and lis for addis rD, 0, value
add takes signed operands.
addi & addis sign extend their immediate operand to 32 bits.
When using addi, you need to give a signed operand because
0xFFFF extended to 32 bits is 0xFFFF if unsigned and 0xFFFFFFFF if
signed.
Then, you've got to use li %r3, 0xFFFFFFFF
You don't have this constraint when using lis on 32 bits PowerPC
architecture, as the immediate value is shifted left _before_ been
extended to 32 bits. Then, the result is the same when using signed or
unsigned values.
But the constraint will (should ?) come back if compiling for a 64 bits
PowerPC machine because the constant need to be signed extended from
(value << 16) to a signed 64 bits constant.
Hope this helps...
Hmm... Ok, now I understand.
Maybe I have to rewrite some parts of my code :P

Thanks a lot.
Fernando Pena López
2006-02-10 09:49:59 UTC
Permalink
Post by l'indien
li is a shortcut for addi rD, 0, value
and lis for addis rD, 0, value
add takes signed operands.
addi & addis sign extend their immediate operand to 32 bits.
When using addi, you need to give a signed operand because
0xFFFF extended to 32 bits is 0xFFFF if unsigned and 0xFFFFFFFF if
signed.
Then, you've got to use li %r3, 0xFFFFFFFF
You don't have this constraint when using lis on 32 bits PowerPC
architecture, as the immediate value is shifted left _before_ been
extended to 32 bits. Then, the result is the same when using signed or
unsigned values.
But the constraint will (should ?) come back if compiling for a 64 bits
PowerPC machine because the constant need to be signed extended from
(value << 16) to a signed 64 bits constant.
Hope this helps...
Ok, I can understand it, but, if I'm right, this error only happens if I try
to
compile/assemble for ppc64, but I'm compiling for a ppc32 (I use the -m403
modifier,
that means that it should compile for a ppc 403, 32 bit core).
Am I forgetting something?

Thanks.
l'indien
2006-02-11 11:02:46 UTC
Permalink
Post by Fernando Pena López
li is a shortcut for addi rD, 0, value and lis for addis rD, 0, value
add takes signed operands.
addi & addis sign extend their immediate operand to 32 bits. When using
addi, you need to give a signed operand because 0xFFFF extended to 32
bits is 0xFFFF if unsigned and 0xFFFFFFFF if signed.
Then, you've got to use li %r3, 0xFFFFFFFF You don't have this
constraint when using lis on 32 bits PowerPC architecture, as the
immediate value is shifted left _before_ been extended to 32 bits. Then,
the result is the same when using signed or unsigned values.
But the constraint will (should ?) come back if compiling for a 64 bits
PowerPC machine because the constant need to be signed extended from
(value << 16) to a signed 64 bits constant.
Hope this helps...
Ok, I can understand it, but, if I'm right, this error only happens if I
try to
compile/assemble for ppc64, but I'm compiling for a ppc32 (I use the -m403
modifier,
that means that it should compile for a ppc 403, 32 bit core). Am I
forgetting something?
The error should happen in 32 bits and 64 bits cases when using li:
the PowerPC will sign extend a 16 bits constant to 32 or 64 bits.
Then the constant really need to be signed.
The difference between 32 and 64 bits architecture may only appear when
using lis because on a 32 bit CPU, the sign extension of a 32 bits
constant do nothing.

Loading...