From 484f664f56a3b7a8744e175d9378e6f4954fde29 Mon Sep 17 00:00:00 2001 From: Joe Neeman Date: Tue, 27 May 2008 22:42:38 +1000 Subject: [PATCH] Use 64-bit rather than 80-bit floating point arithmetic on x86. This fixes some subtle problems with truncation. --- lily/main.cc | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/lily/main.cc b/lily/main.cc index 3c0f7ae88e..66a645f320 100644 --- a/lily/main.cc +++ b/lily/main.cc @@ -166,6 +166,28 @@ static Long_option_init options_static[] char const *LILYPOND_DATADIR = PACKAGE_DATADIR "/" TOPLEVEL_VERSION; + +/* x86 defaults to using 80-bit extended precision arithmetic. This can cause + problems because the truncation from 80 bits to 64 bits can occur in + unpredictable places. To get around this, we tell the x87 FPU to use only + double precision. Note that this is not needed for x86_64 because that uses + the SSE unit by default instead of the x87 FPU. */ +#ifdef __x86__ + +#include +static void configure_fpu() { + fpu_control_t fpu_control = 0x027f; + _FPU_SETCW (fpu_control); +} + +#else + +static void configure_fpu() { +} + +#endif /* __x86__ */ + + static void env_var_info (FILE *out, char const *key) { @@ -569,6 +591,8 @@ vector start_environment_global; int main (int argc, char **argv, char **envp) { + configure_fpu(); + for (char **p = envp; *p; p++) start_environment_global.push_back(*p); -- 2.39.5