我在汇编中编写了一些代码,并在linux-64bit下运行的c / g代码中使用它(gcc版本4.4.1 [gcc-4_4-branch revision 150839](SUSE Linux)) . 汇编代码运行完美无缺,但是周围的c代码提供了不同的结果(没有崩溃,只有4倍慢和略微不同的计算结果),这取决于汇编代码的实现/省略(即减少的代码片段) .

我删除了所有多余的东西,下面的代码片段就是现在实现的所有内容 . 只推送和弹出并存储xmmx,不超过这个 . BTW . 如果我只在代码段中存储和恢复xmmx,没有rbx,rsi,rdi,rbp push / pops c代码再次正常工作 . 调用约定要求rbx,rdi,rsi和rbp保持不变,因此它们被保存 . 如果我添加其他寄存器(rax,rcx,rdx,...以及其他推送和弹出),结果是相同的 - c代码不再正常工作 . 不幸的是,我在(这里:省略)汇编代码中需要这些regs .

围绕实现的代码片段的程序集调试没有显示任何明显的原因 . 假设它通常是一个不同编译的代码但不是那么容易比较(完整代码是几万行)必须是我遗漏了一些明显的东西或者必须在编译期间考虑一些事情 .

有什么建议 ?谢谢

extern "C" void store_xmmx();
extern "C" void restore_xmmx();
//
void xmmx_manipulation_cpp_not_working()
{
// cpp-Code before Assembly, same as in working function
//
store_xmmx();
// assembly code here, but removed from source for debugging
// cpp still executes differently with simple pushes and pops
restore_xmmx();
//
// cpp-Code after Assembly, same as in working function
};
void xmmx_manipulation_cpp_working()
{
// cpp-Code before Assembly, same as in not working function
//
// store_xmmx(); 
// assembly code 
// restore_xmmx(); 
//
// cpp-Code after Assembly, same as in not working function
};
//
//Assembly Code:
//
align 16
global store_xmmx
store_xmmx:
pop  r8         
push rbp
push rsi
push rdi
push rbx
sub     rsp,200h        
fxsave  [rsp]       
push r8            
ret
align 16
global restore_xmmx
restore_xmmx:
pop  r8         
fxrstor [rsp]
fwait
add  rsp,200h
pop  rbx
pop  rdi
pop  rsi
pop  rbp  
push r8            
ret