4 ms·
> [Using 64-bit registers in 32-bit mode] is not possible. If the system is in 32-bit mode, it will act as a 32-bit system, the extra 32-bits of the registers
by rewqfdsa 11y ago
> [Using 64-bit registers in 32-bit mode] is not possible. If the system is in 32-bit mode, it will act as a 32-bit system, the extra 32-bits of the registers is completely invisible, just as it would be if the system was actually a "true 32-bit system".
That's not entirely true. Under Linux, with the x32 ABI (see https://lwn.net/Articles/456731/ https://lwn.net/Articles/456731/) you have access to the entire register file, but still use 32-bit pointers.
In many ways, it combines the advantages of 32- and 64-bit mode code.
- simcop2387 11y agoAs addressed in the comments on SO[1], x32 mode is actually still long mode. It's just a change in ABI to use the upper and lower 2GB of address space so that you can fit pointers in 32bits. It doesn't really act like a 32bit system because it isn't it's a 64bit system with a restricted address space. That said it can be useful for certain loads where you aren't consuming large amounts of memory but are doing lots of calculations. [1] http://stackoverflow.com/questions/16841382/what-is-the-performance-impact-of-using-int64-t-instead-of-int32-t-on-32-bit-sys#comment24292419_16841814 http://stackoverflow.com/questions/16841382/what-is-the-perf...
- AnthonyMouse 11y agoI'm surprised it's not more common on small [virtual] machines where the total memory+swap can still be addressed by a 32-bit pointer. 32-bit pointers are much more cache-friendly if you don't need the address space.
- joosters 11y agox32 mode can be a huge win if your data structures contain lots of pointers/references. It can shrink the memory usage and speed up computation by surprising amounts (compared to running the same process in a 'full' 64 bit mode). It's not just for when you are writing your own intricate code, either. An x32 build of perl sped up some of my programs dramatically, and let me run stuff on a 4GB machine that previously couldn't fit the data in. Ubuntu has some x32 packages available for their standard 64 bit distribution, but the selection is limited.
- qb45 11y agoDid you compare x32 versus the old fashioned i386?
- joosters 11y agoNope, other stuff on the machine needed 64 bits so unfortunately it would be difficult to do the comparison. In theory, x32 should still be faster because the code gets to use all the other x64 features, like a larger register set and so on. I've no idea how big a difference that actually would make though.
- qb45 11y agoYou can run 32 bit binaries on 64 bit system. I bet Ubuntu has several 32 bit packages available because they are needed by Wine and and closed-source 32 bit binaries. The theoretical possibility for speedup is exactly why I asked. The x32 website has benchmarks where it's as fast as i386 and 40% faster than amd64 on pointers or as fast as amd64 and 40% faster than i386 on 64 bit math, but what's missing to really justify x32 is some "20% better than either" case.
- Dylan16807 11y agoNot that you need to use x32 to use arena allocation with 32 bit pointers inside it.
- JoeAltmaier 11y agoThere is an opcode prefix in x86 machine code, that asserts 64-bit mode for the next instruction. Even when compiled for 32-bit and running on a 32-bit OS. Its anybody's guess if your particular compiler is smart enough to use this.
- 0x0 11y agoI don't think you can access 64bit registers from 32bit code. I know you could access EAX (32bit registers) from 16bit code with a prefix (0x66), but I do not think there's an equivalent access to RAX for the 32<->64bit case.
- JoeAltmaier 11y agoAh right - those prefixes in 32-bit mode are inc/dec register operations. They only exist in 64-bit mode (where reg inc/dec is done with other instructions).
- apaprocki 11y agoI've also seen this happen on POWER. When generating 32-bit binaries, but with compiler tuning parameters telling it what minimum CPU it is on, I'be seen it generate 64-bit instructions for certain operations. Another fun tidbit -- the debugger is blissfully unaware that the CPU and compiler are conspiring to do this. If you debug such a program, it will work fine. If you set a breakpoint on the instruction in question and simply continue, the entire program freaks out because the debugger just chopped off the high 32 bits of whatever it touched. I found that amusing when hitting it while debugging an issue. (Sad face) In general most tools freak out if they encounter this because they were built under the assumption this was impossible.