[SDL] Flickering and division by zero in Windows
Andre de Leiradella
leiradella at bigfoot.com
Thu Mar 1 17:59:40 PST 2007
>> 2) Is the FPU control register something I can change just by reading
>> it, and'ing or or'ing with a mask and writing back the new value?
>>
>
> Yes, but probably not in Lua directly. There's an x86/amd64 assembly
> instruction for reading and writing that register (and, from C, there's
> usually a non-standard function called _controlfp() or something similar
> to do the same).
>
> If you can't figure out what's changing the control word, or you can't
> stop it from changing it, forcing it back yourself will probably Just Work.
>
> --ryan.
>
>
I was already playing with fstcw and fldcw when I received your message.
For the records, to disable division by zero exceptions one can use
_control87(MCW_EM, EM_ZERODIVIDE);
Also for the records, here is a small assembler function that disables
the same exception for those who doesn't have _control87 nor _controlfp:
-------------------8<-------------------
segment _TEXT use32 align=4 class=CODE
global _setzm
_setzm:
lea eax, [esp - 4]
fstcw [eax]
or byte [eax], 4
fldcw [eax]
ret
-------------------8<-------------------
It can be compiled with nasm.
The strange part is that no function is resetting the flag, it already
comes zeroed when the program starts! I imagine that it must be
something from the bootstrap code... Oh well, using _control87 at the
beginning of the program solved the issue.
Thanks a lot Ryan for pointing me to both fldcw and _control87.
Cheers,
Andre
More information about the SDL
mailing list