Reputation: 2193
My environment is 64-bit win7, VC2010.
Of course, the intel inside is 64-bit CPU.
Can I use the 64-bit instruction/native machine word(64-bit) in a 32-bit application? Since most of my code is 32-bit, I do not want to port it to 64-bit.
For some performance critical hot code, I want to manually optimize it by compiler intrinsic or inline assembly(Also 64-bit VC compiler do NOT support inline assembly), is it possible to run 64-bit code fox example mov rax, rbx in a 32-bit mode application?
Upvotes: 5
Views: 1466
Reputation: 64904
Actually, you kind of can. The mechanism used to switch from 32 to 64 bit mode (which clearly must exist on a 64 bit OS capable of running 32 bit code) is not in any way protected, and can be used from user code. On Windows it is called Heaven's Gate, and it's pretty simple: just a far call with a segment selector of 33h.
So, how to run 64bit code?
call 33h:your64bitcode
...
your64bitcode:
; do something
retf
There are, of course, some limitations to what you can do from 64bit code entered in that way, because you're not truly in a 64bit process.
Upvotes: 13
Reputation: 249153
If your application uses the 32-bit instruction set, then no, you cannot elect to use 64-bit instructions "sometimes" within the same application. There are some options, however:
Upvotes: 4