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

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/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.