guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

gcc optimisation breaks guile floating point


From: Gary Houston
Subject: gcc optimisation breaks guile floating point
Date: 27 Aug 2002 22:10:25 +0100

Floating point seems somewhat broken in latest CVS if compiled with
recent gcc (e.g., version 3.2):

guile> 3.2
0.0

The problem is in libguile/numbers.c:scm_make_real, and only if
scm_double_cell is inlined (so it isn't a problem in Guile 1.5).

Compiling with the -fno-strict-aliasing option fixes it.  Here's a
similar kind of problem code:

#include <stdlib.h>
#include <string.h>

static void * make_z (double x)
{
  void *z = malloc (50);

  memset (z, 0, 50);
  *((unsigned long *) z) = 0;
  *((double *) z) = x;
  return z;
}

main ()
{
  void *z = make_z (3.2);
  double d = *((double *) z);
  int i;

  for (i = 0; i < sizeof (double); i++)
    {
      printf ("%d\n", ((unsigned char *) &d)[i]);
    }
  return 0;
}

Apparently, "according to ANSI C" (no direct quotation available), the
compiler can assume that *((unsigned long *) z) and *((double *) z)
refer to different locations and reorder the statements!

I don't know what would be needed to make Guile conform to such
stringent interpretation of the standard, but I don't think it would
be easy to determine that it was correct and that it would always stay
that way.  Perhaps we should just add the -fno-strict-aliasing option
if the compiler supports it?





reply via email to

[Prev in Thread] Current Thread [Next in Thread]