The 8086 used 3 bits to denote a register, so without a large change to the instruction format, the 386 wouldn't be able to denote more than 8 registers, like the 8086. Seeing as the 386 was released in 1985, I think the decision not to provide EIP relative addressing was logical. Especially considering the enormity of the 4GB address space at the time. x64 obviously got around the 8 register limitation with the REX.W prefix, but this adds a full byte to any instruction referencing R8-R15\RIP, which in 1985 would have been a big deal, unlike now when code size (at least for x86\x64 based PCs) is almost completely irrelevant.Solar wrote:@ Combuster:
Thanks for the benchmark data. (The theory was clear to me, I just wondered what the real-world impact would be like.)
PIC is clearly the superior technology compared to relocations. The thing that sucks isn't UNIX using PIC, it's x86 not supporting it properly. (On a MC680x0, for example, you won't have any performance penalty, and I'd expect the same from equally modern architectures like PPC or ARM. Actually, anything but x86.Nable wrote:Overuse of PIC is one of the things that i hate most in *nix systems, windows style of relocations is (IMHO) better than using -fPIC for all dynamic libraries.
A simple optimization for x86 PIC is just to store the program base at the top of the stack in functions. Say EBX is always the program base...
Code: Select all
push ebp
mov ebp, esp
push ebx
...
; Code can use registers like normal
...
mov ebx, [ebp - 4]
mov edx, [ebx + variable_offset]
...
; Can continue to trash ebx
...

