This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

m68k/ColdFire has problems with "float"


Hi,

I have noticed a serious fault in the ColdFire(-m5200) support for floats
in EGCS-1.0.1 and recent(980203-CVS) builds(Linux and Cygwin32).

When trying to compile this simple program:

#include <math.h>
#include <stdio.h>

int main()
{
  float a;
  float b;
  float z;
  a = 1.3;
  b = 2.7; 
  printf(" a = %f , b = %f\n",a,b);
  z = a + b;
  printf(" a + b = %f\n",z);
  z = sqrt(z);
  printf("sqrt(a+b) = %f\n",z);
  
  return 0;
}

built using m68k-coff-gcc -m5200 -O2 -Wl,-s -Wl,-n -Tsbc5206-16M.ld
cfloat.c -o cfloat.x gives this output:

dBUG> go
 a = 1.300000 , b = 2.700000
 a + b = 4.000000
sqrt(a+b) = 2.000000

which is as I would expect. When compiled without any optimisation it gives
this output:

dBUG> go
 a = 1.300000 , b = 2.700000
 a + b = -0.000000
sqrt(a+b) = 2.000000

On examining z using my ColdFire's monitor reveals that z = 0xB2B33FF7
which I manually disassembled to be -1.19 x 10^-8 which is a bit wide of
the mark :)

When I tried to make a,b and z global vars the program stopped working
completely. The simplest program I could get to fail was:
float a = 1.3;
float b = 2.7;
float z = 0;

int main()
{
  z = a + b;
  return 0;
}

It seems to be any value of a or b causes z to be gibberish. I have tried
to isolate it further by copying the __addsf3 procedure from floatlib.c and
calling it DJF__addsf3 and calling it directly but it just seemed to work
perfectly. Calling __addsf3 directly to add the two numbers causes it fail
as when it is called implicitly by z = a + b;. Assembler output from all my
test examples seems to be reasonable but the fact that sqrt(z) works when z
= a+b has already failed makes me think that it could be the interface
between my program and libgcc.a. When I substitute doubles for floats
everything works as I would expect which at least provides a temporary work
around. I'm afraid it's beyond my skills to refine it much further... feel
free to contact me if further details are needed.

David Fiddes
Dept of Maths, Heriot-Watt University, Edinburgh
Tel: 0131-451-3251 email: D.J.Fiddes@hw.ac.uk


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]