FPU IA-32 SIGFPE, Arithmetic exception

倾然丶 夕夏残阳落幕 提交于 2019-12-11 04:10:02

问题


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

回答1:


Setting the control word to 0x200 switches the FPU to double precision and unmasks all exceptions including the precision exception. As such for most inputs (probably everything except 0) the fsqrt will raise this exception and that's what you are seeing.

You can set the control word to 0x220 instead to mask the precision exception.



来源:https://stackoverflow.com/questions/17099872/fpu-ia-32-sigfpe-arithmetic-exception

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!