From 3034a6c8cfb50e2b5af4ef57c419986039b53a94 Mon Sep 17 00:00:00 2001 From: Simon Marlow Date: Wed, 22 Feb 2006 14:07:19 +0000 Subject: [PATCH] floating-point fix for x86_64 For 32-bit float primtives like sinFloat#, we currently call the double versions of the C library functions (sin(), cos() etc.). It seems more correct to call the float versions (sinf(), cosf() etc.). This makes a difference on x86_64, I'm not entirely sure why, but this way at least generates more consistent results and avoids extra promotion/demotion instructions when calling these primitives. --- ghc/compiler/cmm/PprC.hs | 26 ++++++++++++------------ ghc/compiler/nativeGen/MachCodeGen.hs | 35 +++++++++++++++++++-------------- 2 files changed, 33 insertions(+), 28 deletions(-) diff --git a/ghc/compiler/cmm/PprC.hs b/ghc/compiler/cmm/PprC.hs index d085ce0..6ce2df5 100644 --- a/ghc/compiler/cmm/PprC.hs +++ b/ghc/compiler/cmm/PprC.hs @@ -533,19 +533,19 @@ pprCallishMachOp_for_C mop MO_F64_Log -> ptext SLIT("log") MO_F64_Exp -> ptext SLIT("exp") MO_F64_Sqrt -> ptext SLIT("sqrt") - MO_F32_Pwr -> ptext SLIT("pow") - MO_F32_Sin -> ptext SLIT("sin") - MO_F32_Cos -> ptext SLIT("cos") - MO_F32_Tan -> ptext SLIT("tan") - MO_F32_Sinh -> ptext SLIT("sinh") - MO_F32_Cosh -> ptext SLIT("cosh") - MO_F32_Tanh -> ptext SLIT("tanh") - MO_F32_Asin -> ptext SLIT("asin") - MO_F32_Acos -> ptext SLIT("acos") - MO_F32_Atan -> ptext SLIT("atan") - MO_F32_Log -> ptext SLIT("log") - MO_F32_Exp -> ptext SLIT("exp") - MO_F32_Sqrt -> ptext SLIT("sqrt") + MO_F32_Pwr -> ptext SLIT("powf") + MO_F32_Sin -> ptext SLIT("sinf") + MO_F32_Cos -> ptext SLIT("cosf") + MO_F32_Tan -> ptext SLIT("tanf") + MO_F32_Sinh -> ptext SLIT("sinhf") + MO_F32_Cosh -> ptext SLIT("coshf") + MO_F32_Tanh -> ptext SLIT("tanhf") + MO_F32_Asin -> ptext SLIT("asinf") + MO_F32_Acos -> ptext SLIT("acosf") + MO_F32_Atan -> ptext SLIT("atanf") + MO_F32_Log -> ptext SLIT("logf") + MO_F32_Exp -> ptext SLIT("expf") + MO_F32_Sqrt -> ptext SLIT("sqrtf") -- --------------------------------------------------------------------- -- Useful #defines diff --git a/ghc/compiler/nativeGen/MachCodeGen.hs b/ghc/compiler/nativeGen/MachCodeGen.hs index 2d1e6aa..32dad13 100644 --- a/ghc/compiler/nativeGen/MachCodeGen.hs +++ b/ghc/compiler/nativeGen/MachCodeGen.hs @@ -3083,27 +3083,32 @@ outOfLineFloatOp mop res args vols code2 <- stmtToInstrs (CmmAssign res (demote (CmmReg tmp))) return (code1 `appOL` code2) where +#if i386_TARGET_ARCH promote (x,hint) = (CmmMachOp (MO_S_Conv F32 F64) [x], hint) demote x = CmmMachOp (MO_S_Conv F64 F32) [x] +#else + promote (x,hint) = (x,hint) + demote x = x +#endif lbl = mkForeignLabel fn Nothing True fn = case mop of - MO_F32_Sqrt -> FSLIT("sqrt") - MO_F32_Sin -> FSLIT("sin") - MO_F32_Cos -> FSLIT("cos") - MO_F32_Tan -> FSLIT("tan") - MO_F32_Exp -> FSLIT("exp") - MO_F32_Log -> FSLIT("log") - - MO_F32_Asin -> FSLIT("asin") - MO_F32_Acos -> FSLIT("acos") - MO_F32_Atan -> FSLIT("atan") - - MO_F32_Sinh -> FSLIT("sinh") - MO_F32_Cosh -> FSLIT("cosh") - MO_F32_Tanh -> FSLIT("tanh") - MO_F32_Pwr -> FSLIT("pow") + MO_F32_Sqrt -> FSLIT("sqrtf") + MO_F32_Sin -> FSLIT("sinf") + MO_F32_Cos -> FSLIT("cosf") + MO_F32_Tan -> FSLIT("tanf") + MO_F32_Exp -> FSLIT("expf") + MO_F32_Log -> FSLIT("logf") + + MO_F32_Asin -> FSLIT("asinf") + MO_F32_Acos -> FSLIT("acosf") + MO_F32_Atan -> FSLIT("atanf") + + MO_F32_Sinh -> FSLIT("sinhf") + MO_F32_Cosh -> FSLIT("coshf") + MO_F32_Tanh -> FSLIT("tanhf") + MO_F32_Pwr -> FSLIT("powf") MO_F64_Sqrt -> FSLIT("sqrt") MO_F64_Sin -> FSLIT("sin") -- 1.7.10.4