Page 2 of 2
Re: flat binary
Posted: Sat Apr 07, 2012 5:04 am
by Rudster816
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.)
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.
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.

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.
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
...
Only adds one extra instruction, albeit a memory access, but it will almost certainly be in cache. Since most calling conventions require EBX to be preserved, compilers will already try to avoid using it meaning it may not even be required to save it's value at all. Keeping global variable use to an absolute minimum will obviously further mitigate the impact. In the context of the 386, doing this really wouldn't have been a big deal since memory access was cheap. Obviously EIP relative addressing is better everything else aside, but given the alternative (drastic instruction format changes\increased code size), I think Intel made the right call.
Re: flat binary
Posted: Sat Apr 07, 2012 8:55 am
by Solar
PDP-8 was released 1965,
with relative addressing.
PDP-11 was released 1970,
with relative addressing.
The 6502 was released 1975,
with relative addressing.
The 8086 was released 1976,
without IP-relative addressing.
VAX was released 1977,
with relative addressing.
The 68000 was released 1979,
with relative addressing.
ARM was released 1983,
with relative addressing.
The 80386 was released 1985,
without EIP-relative addressing.
Unix was ten years old before the first port to the 8086 was done, and they had to use a custom-built MMU because the 8086 didn't have one. The first "real" port was Xenix, 1983.
Draw your own conclusions.

Re: flat binary
Posted: Sat Apr 07, 2012 11:56 am
by brain
Solar, if I remember correctly the 6502's program counter couldn't be directly accessed, to obtain it you had to do a JSR instruction to put it on the stack, then read it from the stack with PLA. there were relative branches, which were limited to +/- 128 bytes in either direction from the branch instruction. correct me if I'm wrong but true pic code would have been as much a pain as on x86 in fact I remember cooking some up many years ago. I had to be very careful about the mnemonics I put in the code.
Re: flat binary
Posted: Sat Apr 07, 2012 12:06 pm
by Solar
I admit that above timeline was google'd ad-hoc. I'm a bit to young for stuff like the PDP's, didn't dabble in ASM (much) during my C64 days, and switched more or less directly from BASIC to C (and later, C++). So yes, you got me there - I took "relative addressing" on the WIkipedia page to mean the whole thing.
Then again, the 6502 wasn't exactly a "Unix" CPU, either.

Re: flat binary
Posted: Sat Apr 07, 2012 12:26 pm
by brain
Solar wrote:I admit that above timeline was google'd ad-hoc. I'm a bit to young for stuff like the PDP's, didn't dabble in ASM (much) during my C64 days, and switched more or less directly from BASIC to C (and later, C++). So yes, you got me there - I took "relative addressing" on the WIkipedia page to mean the whole thing.
Then again, the 6502 wasn't exactly a "Unix" CPU, either.

That's true, I don't know of any 8-bit 'home user' cpus with an MMU
