在32位Windows下使用Amd64指令的轻量级方法? [英] Lightweight method to use Amd64 instructions under 32-bit Windows?

查看:151
本文介绍了在32位Windows下使用Amd64指令的轻量级方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于某些使用64位变量的CPU绑定代码,使用Amd64指令集而不是x86是有益的.在32位Windows(例如Windows XP SP3)下如何完成?当然,我假设使用的是现代的,支持Amd64的CPU.我排除了有效但重量级的方法:将成熟的64位OS作为虚拟机运行,例如Virtualbox下的Ubuntu for Amd64.

我知道需要一些汇编,并且会有一些限制,特别是要处理比32位Windows管理的更多的内存.但是我在考虑纯粹的计算任务,只需要适度的内存,而无需调用外部函数.

解决方案

在32位通用操作系统(没有内核修改/特殊驱动程序/管理程序)中,无法使用Amd64指令(长模式).

这是因为:

1)要使用本机64位指令,您需要切换到长模式.这是特权操作.如果将CPU切换为64位模式,则32位OS内核将无法继续工作,因此您应在进入内核之前先切换回

2)但是内核通常被异步调用,用于定时器(调度程序)和其他硬件中断(驱动程序).它将不会保存64位寄存器,也不会将模式从长久更改为受保护.

也许可以编写特殊的驱动程序,该驱动程序将在32位OS上执行64位任务,但是这种驱动程序更像是64位内核和内核的动态修补程序.我不知道这样的解决方案.

在32位OS中运行时,您只能使用MMX,SSE,SSE2,SSE3,AVX来访问64位ALU和CPU的寄存器.

我可以说,使用64位内核但用户空间软件是32位时,Linux,某些BSD和Mac OS X都有一种模式.在这种情况下,将可能同时运行32位和64位应用程序,因为内核知道64位模式,并且可以访问64位寄存器来执行任务切换.据我所知,MS Windows本身并没有这种模式(W7模拟32位模式,但这被称为MS作为模拟器,因此我认为它不是内核功能).

其他可能性(更好的是,您的CPU支持硬件虚拟化),是将64位虚拟机管理程序(VMware/Xen,其他价格过高的解决方案)与32位和64位来宾OS一起使用. VirtualBox是使用虚拟机管理程序的另一种选择,它是免费使用的.

For some CPU-bound code using 64-bit variables, it is beneficial to use the Amd64 instruction set rather than x86. How can it be done under 32-bit Windows (e.g. Windows XP SP3)? Of course I assume a modern, Amd64-enabled CPU. I'm excluding the working but heavyweight method: running a full-blown 64-bit OS as a virtual machine, e.g. Ubuntu for Amd64 under Virtualbox.

I understand some assembly is needed, and there will restrictions, in particular addressing more memory than 32-bit Windows manages. But I'm thinking of purely computational tasks needing only a moderate amount of memory and no call to external functions.

解决方案

There is no way to use Amd64 instructions (Long mode) in 32-bit general-purpose OS (without kernel modification/special drivers/hypervisor).

This is because:

1) to use native 64-bit instructions you need to switch into long mode. This is privileged action. 32-bit OS kernel can't continue to work if the CPU is switched into 64-bit mode, so you should switch back before entering a kernel

2) But kernel are often called asynchronously, for timer (scheduler) and other hardware interrupts (drivers). It will not save 64-bit registers nor change mode from long into protected.

May be it is possible to write special driver, which will do the 64-bit tasks on 32-bit OS, but such driver is more like 64-bit kernel and dynamic patcher of kernel. I know no one such solution.

You can only use MMX, SSE, SSE2, SSE3, AVX for accessing 64-bit ALU and registers of your CPU when running in 32-bit OS.

I can say, that Linux, some BSD, Mac OS X have a mode, when 64-bit kernel is used, but user-space software is 32-bit. In such case it will be possible to run both 32-bit and 64-bit applications, because kernel knows about 64-bit mode and can access 64-bit registers to do a task switch. As far as I know, MS Windows have not such mode itself (the W7 emulates 32bit mode, but this is called my MS as simulator so I assume it is not an in-kernel feature).

Other possibility (this is better, is your CPU has support of hardware virtualization), is to use 64-bit hypervisor (VMware/Xen, other overpriced solutions) with 32-bit and 64-bit guest OSes. VirtualBox is other option of using hypervisor, and it is free to use.

这篇关于在32位Windows下使用Amd64指令的轻量级方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆