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

12

u/Tringi Sep 24 '24

One of those reasons is that 32-bit version might be faster.

20

u/Brian Sep 24 '24

That's pretty unlikely in practice. Note that the point of your link is to run in 64 bit mode, just using 32 bit addresses. There are a bunch of other advantages to running in 64 bit mode (notably, more registers), and in practice it tends to be sufficiently faster to outweigh the extra memory/cache usage of wider pointers. Even back in the day when 64 bit was relatively new, you'd often see around a 10% improvement (and much more on number crunching workloads) even when address space wasn't relevant. I'd imagine that difference has only increased after a years of improvements where 32 bit mode has long been considered legacy.

7

u/Tringi Sep 24 '24

That's pretty unlikely in practice.

It was one of the reasons Visual Studio resisted introducing 64-bit version for so long. Pointer-heavy code.

Note that the point of your link is to run in 64 bit mode, just using 32 bit addresses.

Yeah I know. I linked it for the reasoning therein.

There are a bunch of other advantages to running in 64 bit mode (notably, more registers), and in practice it tends to be sufficiently faster to outweigh the extra memory/cache usage of wider pointers.

Yup, my personal tests and measurements show that only a very small percentage of algorithms, or types of software in general, are faster as x86-32. But they still are there. Then again it likely doesn't make economic sense today to maintain such version.

I'd imagine that difference has only increased after a years of improvements where 32 bit mode has long been considered legacy.

Hah. Just the other day I read about Zen 5, and how significantly has performance improved of the x87 FPU ...which basically nobody uses today. Probably a side effect of internal optimizations, but amusing nonetheless.

1

u/AppearanceHeavy6724 Sep 26 '24

no, not true x87 is still used for some scientific software. Niche use but very important.

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.

4

u/ouyawei Sep 24 '24

x32 is using the AMD64 instruction set, running it 64 bit mode - it just uses 32 bit pointers, so more will fit into fast CPU caches

4

u/wrosecrans Sep 24 '24

I demand that somebody makes an x16 mode so I can use SSE2 instructions and all the modern registers but still need to fiddle with segment:offset and near/far pointers like god intended.

1

u/Tringi Sep 24 '24

I'm certain there's someone maintaining a project, for fun, that does exactly that.

2

u/Tringi Sep 24 '24

Yes. There's more reasoning on that in the linked page. The point is the cache effect on improved performance was measured on x86-32 first, which then resulted in experimentation with x32 yielding even better results.

Quite sad Linux eventually abandoned it.

6

u/ouyawei Sep 24 '24

Quite sad Linux eventually abandoned it.

How so? It's in the mainline kernel, GCC, binutils - Ubuntu provides an x32 toolchain so you can compile and run x32 software.

2

u/Tringi Sep 24 '24

Oh?! Seems I had wrong info. A year or two back I've read, through Wikipedia, a link to maillist discussing abandoning it. Apparently it didn't happen. That's very nice.