1

I have a problem with this code below. It is GAS asm syntax on IA-32 architecture. It generates arithmetic exception, after fsqrt instruction. SetDouble is int type of value 0x0200 and input is a float number. I'm compiling this with -m32 flag using gcc. Can someone point where I made mistake.

pushl %ebp
movl %esp,%ebp
finit                   
fldcw SetDouble          
fld input               
fld input
fmulp
fld1                    
faddp                   
fsqrt                   
fld1
fxch                    
fsubp
fstp output
mov %ebp,%esp 
pop %ebp
4

1 回答 1

1

将控制字设置为 0x200 将 FPU 切换为双精度并取消屏蔽所有异常,包括精度异常。因此,对于大多数输入(可能除了 0 之外的所有输入)fsqrt都会引发此异常,这就是您所看到的。

您可以将控制字设置为 0x220 来屏蔽精度异常。

于 2013-06-14T10:18:11.240 回答