Opened 6 years ago

Last modified 7 months ago

#4105 infoneeded bug

ffi005 fails on OS X

Reported by: igloo Owned by:
Priority: low Milestone:
Component: Compiler (FFI) Version: 6.12.2
Keywords: Cc:
Operating System: MacOS X Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case: ffi/should_run/ffi005
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

The ffi005 test is failing on OS X x86.

The test is only run the optc way, but we get other bad results when compiling in other ways.

normal:

{-# LANGUAGE ForeignFunctionInterface #-}

import Control.Monad
import Foreign.C

main :: IO ()
main = doit sin mysin (encodeFloat 7926335344172077 (-54))

doit :: (CDouble -> CDouble) -> (CDouble -> CDouble) -> CDouble -> IO ()
doit f g x = do let fx = f x
                    gx = g x
                when (fx /= gx) $ do print x
                                     print (decodeFloat x)
                                     print fx
                                     print gx
                                     print (fx - gx)

foreign import ccall "sin" mysin :: CDouble -> CDouble
$ ghc q.hs -o q; ./q
0.4400000000000002
(7926335344172077,-54)
0.4259394650659998
0.42593946506599983
-5.551115123125783e-17

optc:

{-# LANGUAGE ForeignFunctionInterface #-}

import Control.Monad
import Foreign
import Foreign.C

main :: IO ()
main = do sin_addr <- wrapId sin
          doit sin (dyn_sin sin_addr) (encodeFloat 7926335344172077 (-54))
          freeHaskellFunPtr sin_addr

doit :: (CDouble -> CDouble) -> (CDouble -> CDouble) -> CDouble -> IO ()
doit f g x = do let fx = f x
                    gx = g x
                when (fx /= gx) $ do print x
                                     print (decodeFloat x)
                                     print fx
                                     print gx
                                     print (fx - gx)

foreign import ccall "wrapper" wrapId :: (CDouble -> CDouble) -> IO (FunPtr (CDouble -> CDouble))
foreign import ccall "dynamic" dyn_sin :: FunPtr (CDouble -> CDouble) -> (CDouble -> CDouble)
$ ghc w.hs -o w -fvia-c -O; ./w
0.4400000000000002
(7926335344172077,-54)
0.42593946506599983
0.4259394650659998
5.551115123125783e-17

optasm:

{-# LANGUAGE ForeignFunctionInterface #-}

import Control.Monad
import Foreign
import Foreign.C

main :: IO ()
main = do sin_addr <- wrapId sin
          doit sin (dyn_sin sin_addr) (encodeFloat 7926335344172077 (-54))
          freeHaskellFunPtr sin_addr

doit :: (CDouble -> CDouble) -> (CDouble -> CDouble) -> CDouble -> IO ()
doit f g x = do let fx = f x
                    gx = g x
                when (fx /= gx) $ do print x
                                     print (decodeFloat x)
                                     print fx
                                     print gx
                                     print (decodeFloat fx)
                                     print (decodeFloat gx)
                                     print (fx == gx)
                                     print (decodeFloat fx == decodeFloat gx)
                                     print (fx - gx)

foreign import ccall "wrapper" wrapId :: (CDouble -> CDouble) -> IO (FunPtr (CDouble -> CDouble))
foreign import ccall "dynamic" dyn_sin :: FunPtr (CDouble -> CDouble) -> (CDouble -> CDouble)
$ ghc r.hs -o r -O; ./r
0.4400000000000002
(7926335344172077,-54)
0.4259394650659998
0.4259394650659998
(7673043264614500,-54)
(7673043264614500,-54)
False
True
0.0

Change History (14)

comment:1 Changed 6 years ago by igloo

  • Milestone changed from 7.0.1 to 7.0.2

comment:2 Changed 5 years ago by igloo

  • Milestone changed from 7.0.2 to 7.2.1

comment:3 Changed 5 years ago by igloo

  • Milestone changed from 7.2.1 to 7.4.1

comment:4 Changed 5 years ago by igloo

  • Milestone changed from 7.4.1 to 7.6.1
  • Priority changed from normal to low

comment:5 Changed 4 years ago by igloo

  • Milestone changed from 7.6.1 to 7.6.2

comment:6 Changed 2 years ago by thoughtpolice

  • Milestone changed from 7.6.2 to 7.10.1

Moving to 7.10.1.

comment:7 Changed 21 months ago by thomie

  • Component changed from Compiler to Compiler (FFI)
  • difficulty set to Unknown
  • Test Case changed from ffi005 to ffi/should_run/ffi005

comment:8 Changed 21 months ago by thoughtpolice

  • Milestone changed from 7.10.1 to 7.12.1

Moving to 7.12.1 milestone; if you feel this is an error and should be addressed sooner, please move it back to the 7.10.1 milestone.

comment:9 Changed 12 months ago by thoughtpolice

  • Milestone changed from 7.12.1 to 8.0.1

Milestone renamed

comment:10 Changed 8 months ago by bgamari

  • Status changed from new to infoneeded

Is this still the case?

comment:11 Changed 8 months ago by kseo

ffi005 passes on my OS X with the current HEAD (fbd6de2f0761b63a5f0a88ce0590f515d63790a4).

comment:12 follow-up: Changed 8 months ago by thomie

Did you test on x86, as it says in the description?

The following two commits are relevant. The first one changes the test to only run for WAY=optc on x86. The second deletes WAY=optc. So now the test is always skipped on x86. That doesn't mean the problem is solved though!

Author: Simon Marlow <marlowsd@gmail.com>
Date:   Tue Nov 24 10:14:34 2009 +0000

    ffi005: run only the via-C way on x86 platforms
    due to 80-bit vs. 64-bit precision leading to floating point
    differences when using the native code generator.  -fvia-C uses the
    -ffloat-store gcc sledgehammer to avoid this.
Author: Max Bolingbroke <batterseapower@hotmail.com>
Date:   Sat Apr 2 11:25:01 2011 +0100

    Remove any mention of optc/profc from all.T files

comment:13 in reply to: ↑ 12 Changed 8 months ago by kseo

Replying to thomie:

Did you test on x86, as it says in the description?

I ran in on x64. Sorry for the confusion!

comment:14 Changed 7 months ago by thomie

  • Milestone 8.0.1 deleted
Note: See TracTickets for help on using tickets.