I notice in some of Wind's code for the PowerPC 860 that the
macro HIADJ() is used. Looking at assembler output, I see that
HIADJ(arg) translates to arg@ha . Unfortunately, I can't find out what the
"@" or the "ha" are supposed to be doing. It looks like a 16-bit shift
left, but I am confused on this syntax. Can anyone enlighten me?
Thanks,
Dave Hill
To understand this you need to understand the instruction set a little... PPC
860 is a RISC CPU that has one 32 bit word per instruction; the largest
constant value you can load into a register is 16 bits because the remainder
of the bits are needed to encode the instruction and the destination register
etc. So, to load a 32 bit constant requires two instructions: a load+shift
and an add operation. In the PPC world the add is a signed operation, with
the 16 bit value being sign extended to 32 bits first. HIADJ() obtains the
upper half of the 32 bit constant, but it also compensates for the sign of
the lower half so the addition that is expected to follow (an addi
instruction, or equivalent) will result in the correct value being used.
There is another macro, HI(), which doesn't do the compensation and is used
with an OR operation following. LO() is used in both cases.
So, why not use the OR option always? Well, the add can be implied as part of
an indexed load to access external memory through a pointer. For example, the
following two instructions load the value pointed to by myPointer into r30:
lis r31, HIADJ(myPointer)
lwz r30,LO(myPointer)(r31)
Had you used HI(myPointer), the operation would only work if LO(myPointer)
was between 0x0000 and 0x7fff; outside that range you would be loading from
the wrong location.
Hope that helps,
John...
In article <__6d4.1385$9F3.1...@news.corecomm.net>,
Sent via Deja.com http://www.deja.com/
Before you buy.