【问题标题】:is it safe to use xmm registers to save the general-purpose ones?使用 xmm 寄存器来保存通用寄存器是否安全?
【发布时间】:2012-07-22 18:05:20
【问题描述】:
        pushf       //couldnt store this in other registers 
        movd xmm0,eax//storing in xmm registers instead of   pushing
        movd xmm1,ebx//
        movd xmm2,ecx//
        movd xmm3,edx//
        movd xmm4,edi//end of push backups
        .
        .//doing work
        .
        movd edi,xmm4//pop edi
        movd edx,xmm3//pop edx
        movd ecx,xmm2//pop ecx
        movd ebx,xmm1//pop ebx
        movd eax,xmm0//pop eax
        popf

比我电脑中的 push eax 版本快 %50。这安全吗?

【问题讨论】:

  • 这在 MSVC 内联汇编中是 100% 没有意义的;编译器会看到您编写了 EDI,但没有意识到您已恢复它,并将其视为已破坏。它还必须将 XMM0..4 视为已破坏。您也不需要保存/恢复 EFLAGS。即使在 GNU C 内联汇编中,条件代码也会被 asm("" :::) 语句隐式破坏。

标签: assembly x86 sse inline-assembly


【解决方案1】:

是的,只要您(或您正在调用的某些代码)在此期间没有将 XMM regs 用于其他任何事情。事实上,这个技巧在 RAM init 之前的 BIOS 代码中很常用。

【讨论】:

  • 内存初始化?你的意思是上电顺序?
  • 在重置之后但在检测到是否存在任何 RAM 以及是否可以安全使用之前。另见romcc
猜你喜欢
  • 1970-01-01
  • 2012-04-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-01-14
  • 1970-01-01
  • 2017-10-29
  • 2017-10-16
相关资源
最近更新 更多