[Haskell-cafe] Possible floating point bug in GHC?

Peter Verswyvelen bugfact at gmail.com
Fri Apr 3 13:58:35 EDT 2009


For days I'm fighting against a weird bug.
My Haskell code calls into a C function residing in a DLL (I'm on Windows,
the DLL is generated using Visual Studio). This C function computes a
floating point expression. However, the floating point result is incorrect.

I think I found the source of the problem: the C code expects that all the
Intel's x86's floating point register tag bits are set to 1, but it seems
the Haskell code does not preserve that.

Since the x86 has all kinds of floating point
weirdness<http://www.informit.com/articles/article.aspx?p=770362> -
it is both a stack based and register based system - so it is crucially
important that generated code plays nice. For example, when using MMX one
must always emit an EMMS
instruction<http://msdn.microsoft.com/en-us/library/590b9ks9(VS.80).aspx>to
clear these tag bits.

If I manually clear these tags bits, my code works fine.

Is this something other people encountered as well? I'm trying to make a
very simple test case to reproduce the behavior...

I'm not sure if this is a visual C compiler bug, GHC bug, or something I'm
doing wrong...

Is it possible to annotate a foreign imported C function to tell the Haskell
code generator the functioin is using floating point registers somehow?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090403/4836d571/attachment.htm


More information about the Haskell-Cafe mailing list