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]
Other format: [Raw text]

SH gcc 2.95.2 _divdi3 miscompiled


Hi,

Compiler: gcc 2.95.2 cygwin -> sh-hitachi-coff cross

The generated m2/libgcc2.a (big endian) is broken,
__divdi3 is miscompiled. The following function

long long foo(void)
{
   long long x, y;

   x = -1296760832;
   y = -39829;

   return x / y;
}

returns 0 instead of the correct value.

Replacing __divdi3.o in libgcc.a with 

typedef int word_type __attribute__ ((mode (__word__)));
typedef		 int DItype	__attribute__ ((mode (DI)));
typedef unsigned int UDItype	__attribute__ ((mode (DI)));

DItype
__divdi3 (DItype u, DItype v)
{
  word_type c = 0;
  DItype w;

  if (u < 0)
    c = ~c, u = -u;

  if (v < 0)
    c = ~c, v = -v;

  w = (UDItype)u / (UDItype)v;
  if (c)
    w = -w;

  return w;
}

fixes the problem

Hartmut


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