Port-vax archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: PIC question
>>>> jmp .Loop(%r5)
>>>> [produces an error in a .so]
>> jmp .Loop[%r5]
> Hmm, so deferring won't work, but indexing will? That sounds
> weird... Is that some limitation on gas then?
On the dynamic linker.
"jmp .Loop[%r5]" normally turns into "jmp const(%pc)[%r5]" where the
constant is computed by the assembler and is the offset of .Loop
relative to the appropriate place in the instruction stream (the
beginning of the next instruction, I think, but it's been a long time
and ICBW - maybe the beginning of the constant?). This is a PIC
addressing mode if, as here, .Loop is relocated along with the
instruction; there is another addressing mode which is PIC if the
target location is _not_ relocated along with the instruction, but
that's not what we want here. (To switch to DEC syntax because I'm not
sure how to write this in whatever assembler wants these weird % signs,
it amounts to "jmp @(pc)+" with the constant immediately following in
the instruction stream. The assembler deals with the details, though;
assembler source is normally just "jmp @#target".)
Since in this case .Loop is the next instruction, I think the offset is
zero and it can be just "jmp (pc)[r5]", but I agree .Loop[r5] is
probably less brittle.
>> or movab .Loop[%r5], %r5
>> jmp (%r5)
>> But the first one is simpler.
But if the multiplier applied to generate r5 is 2, 4, or 8, then this
can save you doing a separate multiply. Instead of
mull2 #4,r5
jmp .Loop[r5]
you can
moval .Loop[r5],r5
jmp (r5)
(or movaw for 2, or movaq for 8). Of course, this also assumes r5 is
dead after the branch is taken, which seems likely but probably ought
to be stated.
Doesn't save any bytes - seven bytes either way - if my offhand count
is right, but may be faster, depending on the implementation. (The
special-case multiplication invovled in indexing may well be done
faster than general integer multiplies - I've even seen multiplies by
3, 5, or 9 done with, eg, "moval (r0)[r0],r0"; throw in an offset and
you can add a constant for semi-free.)
/~\ The ASCII Mouse
\ / Ribbon Campaign
X Against HTML mouse%rodents-montreal.org@localhost
/ \ Email! 7D C8 61 52 5D E7 2D 39 4E F1 31 3E E8 B3 27 4B
Home |
Main Index |
Thread Index |
Old Index