#4914: FPU initialization required again
---------------------------------+------------------------------------------
Reporter: aruiz | Owner: simonmar
Type: bug | Status: new
Priority: high | Milestone: 7.2.1
Component: Compiler (NCG) | Version: 7.0.1
Keywords: | Testcase:
Blockedby: | Difficulty:
Os: Unknown/Multiple | Blocking:
Architecture: x86 | Failure: Incorrect result at runtime
---------------------------------+------------------------------------------
Comment(by aruiz):
It is very difficult to get a small test case without dependencies. (For
instance, the problem disappears just when a more specialized signature of
a function is added, or if I try to reduce dependencies just copying the
required definitions). I think that this problem is very unlikely to
happen in normal programs, but here is a test case using the attached
debugging version of hmatrix:
{{{
$ sudo apt-get install libgsl0-dev libatlas-base-dev
$ ls
hmatrix-debug-0.11.0.4.tar.gz
$ tar -xzf hmatrix-debug-0.11.0.4.tar.gz
$ cd hmatrix-debug-0.11.0.4/
$ cabal install -f-vector -f-binary -fdebugfpu -fdebugnan
Resolving dependencies...
[1 of 2] Compiling Config ( Config.hs, dist/setup/Config.o )
[2 of 2] Compiling Main ( Setup.lhs, dist/setup/Main.o )
Linking ./dist/setup/setup ...
Configuring hmatrix-debug-0.11.0.4...
Checking foreign libraries... OK gsl lapack
Preprocessing library hmatrix-debug-0.11.0.4...
Building hmatrix-debug-0.11.0.4...
[ 1 of 36] Compiling Data.Packed.Internal.Signatures (...)
...
[36 of 36] Compiling Numeric.LinearAlgebra.Tests (...)
Registering hmatrix-debug-0.11.0.4...
Installing library in /home/brutus/.cabal/lib/hmatrix-
debug-0.11.0.4/ghc-7.0.2
Registering hmatrix-debug-0.11.0.4...
}}}
The problem is exposed by a simple deterministic program:
{{{
$ ghc --make bug.hs -fforce-recomp -o bug1
[1 of 1] Compiling Main ( bug.hs, bug.o )
Linking bug1 ...
$ ./bug1
Warning: Nonempty FPU Stack. TAG = ff 1f
NaN multR Output
13 x 13: -nan 0.0 0.0 0.0 0.0 ... 0.0 0.0 1.0
Warning: Nonempty FPU Stack. TAG = ff df
Warning: Nonempty FPU Stack. TAG = ff df
False
}}}
If we ran {{{cabal test}}} we will get lots of errors.
All problems disappear if we disable optimization:
{{{
$ cabal clean
cleaning...
$ cabal install -f-vector -f-binary -fdebugfpu -fdebugnan --disable-
optimization
Resolving dependencies...
...
Registering hmatrix-debug-0.11.0.4...
$ ghc --make bug.hs -fforce-recomp -o bug2
[1 of 1] Compiling Main ( bug.hs, bug.o )
Linking bug2 ...
$ ./bug2
True
}}}
Now all tests pass.
The flag -fdebugfpu checks for the fpu tag word at the beginning of the
foreign functions and shows a message if the stack is nonempty, but the
fpu is initialized so there will be no computation errors.
The flag -fdebugnan restores the fpu after fsave to let the computation go
on with the possibly bad fpu stack and checks if a NaN is produced in the
foreign calls for the matrix product.
The fpu checks are in {{{asm_finit()}}} in
{{{lib/Numeric/LinearAlgebra/LAPACK/lapack-aux.c}}} and are called by the
general wrapper infrastructure in {{{Data.Packed.Internal.Common.hs}}}.
The function producing the bug is defined in
{{{lib/Numeric/LinearAlgebra/Tests.hs}}} using
{{{lib/Numeric/LinearAlgebra/Tests/Properties.hs}}}.
I hope this is useful. Any suggestion to simplify the test case will be
welcome.
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/4914#comment:13>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs