From f73c151f536aa81875285ccb38adc309d01b5915 Mon Sep 17 00:00:00 2001 From: Alberto Ruiz Date: Sat, 12 Mar 2011 13:07:30 +0000 Subject: fpudebug --- hmatrix.cabal | 9 ++++++++- lib/Numeric/LinearAlgebra/LAPACK/lapack-aux.c | 19 ++++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/hmatrix.cabal b/hmatrix.cabal index 764198c..10c8173 100644 --- a/hmatrix.cabal +++ b/hmatrix.cabal @@ -1,5 +1,5 @@ Name: hmatrix -Version: 0.11.0.3 +Version: 0.11.0.4 License: GPL License-file: LICENSE Author: Alberto Ruiz @@ -87,6 +87,10 @@ flag finit description: Force FPU initialization in foreing calls default: False +flag fpudebug + description: Check FPU stack + default: False + library Build-Depends: base >= 4 && < 5, @@ -170,6 +174,9 @@ library if flag(finit) cpp-options: -DFINIT + if flag(fpudebug) + cc-options: -DFPUDEBUG + if impl(ghc == 7.0.1) cpp-options: -DNONORMVTEST diff --git a/lib/Numeric/LinearAlgebra/LAPACK/lapack-aux.c b/lib/Numeric/LinearAlgebra/LAPACK/lapack-aux.c index f4ae0f6..77a8847 100644 --- a/lib/Numeric/LinearAlgebra/LAPACK/lapack-aux.c +++ b/lib/Numeric/LinearAlgebra/LAPACK/lapack-aux.c @@ -47,7 +47,24 @@ //--------------------------------------- void asm_finit() { #ifdef i386 - asm("finit"); + + #if FPUDEBUG + uint val=0; + asm("fstsw" + : "=a" (val) + : "a" (val) + ); + + val = (val%16384)/2048; // bits 13-11 + + if (val != 0) { + printf("Warning: FPU Stack: %d\n",val); + asm("finit"); + } + #else + asm("finit"); + #endif + #endif } //--------------------------------------- -- cgit v1.2.3