From: tietz@eos.informatik.uni-bonn.de (Benno Tietz)
Subject: schedule-insns2-bug
Organization: Gnus Not Usenet
Distribution: gnu
Date: Tue, 28 Jul 1992 18:08:44 GMT

Hi,

I found a bug in gcc-2.2.2

Machine	: Sun 4/330
OS	: 4.1.1
Configuration: ./configure sun4 -prefix=/home/tietz/gnu
Syptoms	: program computes incorrect results
Command	: 

	tietz@eos$ gcc -v -O2 bug.c -o bug
	Reading specs from /home/tietz/gnu/lib/gcc-lib/sun4/2.2.2/specs
	gcc version 2.2.2
	 /home/tietz/gnu/lib/gcc-lib/sun4/2.2.2/cpp -lang-c -v -undef -D__GNUC__=2 -Dsparc -Dsun -Dunix -D__sparc__ -D__sun__ -D__unix__ -D__sparc -D__sun -D__unix -D__OPTIMIZE__ bug.c /usr/tmp/cca05651.i
	GNU CPP version 2.2.2 (sparc)
	 /home/tietz/gnu/lib/gcc-lib/sun4/2.2.2/cc1 /usr/tmp/cca05651.i -quiet -dumpbase bug.c -O2 -version -o /usr/tmp/cca05651.s
	GNU C version 2.2.2 (sparc) compiled by GNU C version 2.2.2.
	 as -o bug.o /usr/tmp/cca05651.s
	 /home/tietz/gnu/lib/gcc-lib/sun4/2.2.2/ld -e start -dc -dp -o bug /lib/crt0.o -L/home/tietz/gnu/lib/gcc-lib/sun4/2.2.2 -L/home/tietz/gnu/lib bug.o -lgcc -lc -lgcc

	tietz@eos$ gcc -v -O2 -fno-schedule-insns2 bug.c -o nobug
	Reading specs from /home/tietz/gnu/lib/gcc-lib/sun4/2.2.2/specs
	gcc version 2.2.2
	 /home/tietz/gnu/lib/gcc-lib/sun4/2.2.2/cpp -lang-c -v -undef -D__GNUC__=2 -Dsparc -Dsun -Dunix -D__sparc__ -D__sun__ -D__unix__ -D__sparc -D__sun -D__unix -D__OPTIMIZE__ bug.c /usr/tmp/cca05664.i
	GNU CPP version 2.2.2 (sparc)
	 /home/tietz/gnu/lib/gcc-lib/sun4/2.2.2/cc1 /usr/tmp/cca05664.i -quiet -dumpbase bug.c -O2 -version -fno-schedule-insns2 -o /usr/tmp/cca05664.s
	GNU C version 2.2.2 (sparc) compiled by GNU C version 2.2.2.
	 as -o bug.o /usr/tmp/cca05664.s
	 /home/tietz/gnu/lib/gcc-lib/sun4/2.2.2/ld -e start -dc -dp -o nobug /lib/crt0.o -L/home/tietz/gnu/lib/gcc-lib/sun4/2.2.2 -L/home/tietz/gnu/lib bug.o -lgcc -lc -lgcc

	tietz@eos$ bug
	50
	0
	0
	0

	tietz@eos$ nobug
	50
	98
	246
	0


programm:
/* bug.c */
#define umul_ppmm(w1, w0, u, v) \
  __asm__ ("! Inlined umul_ppmm
	wr	%%g0,%2,%%y	! SPARC has 0-3 delay insn after a wr
	sra	%3,31,%%g2	! Don't move this insn
	and	%2,%%g2,%%g2	! Don't move this insn
	andcc	%%g0,0,%%g1	! Don't move this insn
	mulscc	%%g1,%3,%%g1
	mulscc	%%g1,%3,%%g1
	mulscc	%%g1,%3,%%g1
	mulscc	%%g1,%3,%%g1
	mulscc	%%g1,%3,%%g1
	mulscc	%%g1,%3,%%g1
	mulscc	%%g1,%3,%%g1
	mulscc	%%g1,%3,%%g1
	mulscc	%%g1,%3,%%g1
	mulscc	%%g1,%3,%%g1
	mulscc	%%g1,%3,%%g1
	mulscc	%%g1,%3,%%g1
	mulscc	%%g1,%3,%%g1
	mulscc	%%g1,%3,%%g1
	mulscc	%%g1,%3,%%g1
	mulscc	%%g1,%3,%%g1
	mulscc	%%g1,%3,%%g1
	mulscc	%%g1,%3,%%g1
	mulscc	%%g1,%3,%%g1
	mulscc	%%g1,%3,%%g1
	mulscc	%%g1,%3,%%g1
	mulscc	%%g1,%3,%%g1
	mulscc	%%g1,%3,%%g1
	mulscc	%%g1,%3,%%g1
	mulscc	%%g1,%3,%%g1
	mulscc	%%g1,%3,%%g1
	mulscc	%%g1,%3,%%g1
	mulscc	%%g1,%3,%%g1
	mulscc	%%g1,%3,%%g1
	mulscc	%%g1,%3,%%g1
	mulscc	%%g1,%3,%%g1
	mulscc	%%g1,%3,%%g1
	mulscc	%%g1,0,%%g1
	add	%%g1,%%g2,%0
	rd	%%y,%1"							\
	: "=r" ((unsigned long int)(w1)), "=r" ((unsigned long int)(w0))\
	: "%rI" ((unsigned long int)(u)), "r" ((unsigned long int)(v))	\
       : "%g1", "%g2")

#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
  __asm__ ("addcc %4,%5,%1
	addx %2,%3,%0"							\
	: "=r" ((unsigned long int)(sh)), "=&r" ((unsigned long int)(sl))\
	: "%r" ((unsigned long int)(ah)), "rI" ((unsigned long int)(bh)),\
	  "%r" ((unsigned long int)(al)), "rI" ((unsigned long int)(bl)))



int cy_limb, prod_high, prod_low, v_limb, j;
int up[4], yprodp[4];
int *yup, *prodp;

main ()
{
  int i;

  v_limb = 2;
      yup = &up[3];
      prodp = &yprodp[3];
      up[0] = 25;
      up[1] = 49;
      up[2] = 123;
      up[3] = 12;

      cy_limb = 0;
      j = -3;
      do
	{
	  umul_ppmm (prod_high, prod_low, yup[j], v_limb);
	  add_ssaaaa (cy_limb, prodp[j], prod_high, prod_low, 0, cy_limb);
	  j++;
	}
      while (j < 0);

      for (i=0; i<4; i++)
	printf ("%d\n", yprodp[i]);
    }


----------------------------------------------------------------------
         Jacquin's Postulate on Democratic Government:
                No man's life, liberty, or property are safe
                while the legislature is in session.
----------------------------------------------------------------------
    tietz@eos.informatik.uni-bonn.de    or     tietz@cs.bonn.edu

######################################################################
#         Member of the League for Programming Freedom               #
#          -- write to league@prep.ai.mit.edu                        #
######################################################################

Newsgroups: gnu.gcc.bug