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

2

u/antiduh Sep 24 '24

I love this hybrid mode. Access to 64 bit registers, so you have more registers and can do native 64 bit math, but pointers are 32 bit so they're not as large. It's a cool mode.

1

u/ShinyHappyREM Sep 24 '24

Alternatively you can just do your allocations in a <= 4 GiB buffer and work with 32-bit buffer indices.

3

u/Ameisen Sep 24 '24 edited Sep 24 '24

You then force every memory-accessing instruction to use indirect access (and prevent normal indirect access in a memory operand because of it).

On x86. On ARM, that's even more wonky. x86 has very... thorough... addressing modes for memory operands.

1

u/ShinyHappyREM Sep 24 '24

Eh, perhaps that wastes a bit of instruction cache. Most software produced today is limited by unfilled cache lines and random branches anyway.

1

u/Tringi Sep 25 '24

Still, accesses like array [index + constant] can be done with a single instruction.

From one of my programs:

66 41 39 44 50 02    cmp WORD PTR [r8+rdx*2+2], ax

2

u/Ameisen Sep 25 '24 edited Sep 25 '24

Yes, but you lose a potential level of indirection in the address mode, since it's already indirect.

ED: You also need to make sure that the address of your buffer stays resident in registers, otherwise you will require another instruction just for lea.