]> git.donarmstrong.com Git - lilypond.git/commitdiff
Use 64-bit rather than 80-bit floating point arithmetic on x86.
authorJoe Neeman <joeneeman@gmail.com>
Tue, 27 May 2008 12:42:38 +0000 (22:42 +1000)
committerJoe Neeman <joeneeman@gmail.com>
Tue, 27 May 2008 12:42:38 +0000 (22:42 +1000)
This fixes some subtle problems with truncation.

lily/main.cc

index 3c0f7ae88eb7a4f28a065d1555ff4ffcf9c07aa9..66a645f3202fa93518757b21ed1da9f368f26c4e 100644 (file)
@@ -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 <fpu_control.h>
+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<string> 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);