EricP wrote:
> On 2026-Nov-23 05:47, Thomas Koenig wrote:
>> EricP <That…@thevillage.com> schrieb:
>>
>>> As both absolute and PC-rel methods are possible on all cpu's,
>>
>> It is possible in principle for Power previous to version 3.1, but
>> it was painful. The system has a TOC pointer in r2, which points
>> to local data and the GOT, restricted to 64k. If you really wanted
>> to do pc-relative, you had to get the PC via a branch and link
>> instruction into the link register, then transfer it from there to
>> a general register. Power version 3.0 added a add PC immediate
>> + shifted instruction. V3.1 finally allows for pc-relative with
>> 34-bit offset, in a 64-bit instruction.
>>
>
> The 32b x86 also does not have native PC-rel addressing,
> just absolute, register relative, with optional scaled-index.
> To get the PC into a register one calls a two instruction routine,
> which pushes the incremented PC on the stack, loads the bottom
> of stack dword into a register and returns.
> This routine could be positioned after a basic block near by.
>
> To make that perform well the core needs store-to-load forwarding
> so it can pull the PC from the store queue and not wait for the
> value to hit memory, and a branch predictor so the call does not
> cause a stall. A "MOVPC Rd" instruction would have been simpler.
We asm programmers didn't use that function call, we just did
call next
next:
pop bx
Two instructions, 4 bytes
but when return predictors turned up having a CALL without the expected RET caused mispredicts.
Terje
--
- <Terje.Mathisen at tmsw.no>
"almost all programming can be viewed as an exercise in caching"