Question

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
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top