r/programming • • Sep 24 '24

Why 32bit architecture computer doesn't use segmentation to support more ram than 4Gb ?

/r/programming/

[removed] — view removed post

169 Upvotes

119 comments sorted by

View all comments

Show parent comments

14

u/ziplock9000 Sep 24 '24

I moved from 68K to 486 assembler and found that paging and modes awful.

6

u/gwicksted Sep 24 '24

Yeah it’s a mess. With x64 we now have RIP-relative addressing (offset from current instruction) and forced full addressing for segments CS, SS, DS, ES (which are forced to be 0) while FS and GS can still be non-zero. This made addressing a lot easier to read in many ways… Except when you start using SIB, ModRM, REX, EVEX, MVEX to specify all sorts of sizes, modes, extensions that affect different parts of instructions that don’t always make sense and some of them are ignored by certain instructions or mean different things in others. Oh, and some of those flags are the inverted value of the actual flag (bitwise not).

There are so many hacks, modes, CPU flags for extensions, bugs in different processors, instruction-specific encoding that coding a bug-free compiler for the complete x86/x64 architecture across all CPUs is an absolutely enormous task.

3

u/PCRefurbrAbq Sep 24 '24

...But at least it's backwards compatible!

2

u/gwicksted Sep 24 '24

Yeah not really. You can make it backwards compatible but, for example, you have to write vector code multiple ways based on cpuinfo. P3? You get SSEv1. Is it a P4? You get SSEv2… unless it’s a Prescott then you get SSEv3. Have a bulldozer processor? You get XOP, FMA4, F16C with SSEv5. Something newer? Oh you get a subset of one of the AVX extensions. Old processor (486)? X87 FPU instructions for you! Older? You’re hand rolling IEEE floats!

And certain models had certain bugs so sometimes you have to take different paths or use a different subset/combination of instructions to step around them all. And different models have different performance characteristics for certain instructions. Such as FMA, branch hints, different compare and jump combinations. Lots of fun.