Is it possible to use 64-bit instruction in a 32-bit application on intel/64-bit win7

后端 未结 2 1737
孤独总比滥情好
孤独总比滥情好 2021-01-13 23:21

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 ap

相关标签:
2条回答
  • 2021-01-14 00:03

    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.

    0 讨论(0)
  • 2021-01-14 00:14

    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:

    • Use SIMD instructions, such as SSE, AVX, etc. This is documented here: http://msdn.microsoft.com/en-us/library/t467de55(v=vs.90).aspx
    • Port your 32-bit code to 64-bit. Maybe it's not so hard?
    • Split your program in two: a 32-bit process with your legacy code, and a 64-bit process with new code. You could map memory between them, and one could launch the other, so it's a bit like a multithreaded program then. Whether it would perform well depends a lot on details we don't know at this time.
    0 讨论(0)
提交回复
热议问题