1/* NOCW */
2/* sgibug.c */
3/* bug found by Eric Young (eay@mincom.oz.au) May 95 */
4
5#include <stdio.h>
6
7/* This compiler bug it present on IRIX 5.3, 5.1 and 4.0.5 (these are
8 * the only versions of IRIX I have access to.
9 * defining FIXBUG removes the bug.
10 * (bug is still present in IRIX 6.3 according to
11 * Gage <agage@forgetmenot.Mines.EDU>
12 */
13
14/* Compare the output from
15 * cc sgiccbug.c; ./a.out
16 * and
17 * cc -O sgiccbug.c; ./a.out
18 */
19
20static unsigned long a[4]={0x01234567,0x89ABCDEF,0xFEDCBA98,0x76543210};
21static unsigned long b[4]={0x89ABCDEF,0xFEDCBA98,0x76543210,0x01234567};
22static unsigned long c[4]={0x77777778,0x8ACF1357,0x88888888,0x7530ECA9};
23
24main()
25	{
26	unsigned long r[4];
27	sub(r,a,b);
28	fprintf(stderr,"input a= %08X %08X %08X %08X\n",a[3],a[2],a[1],a[0]);
29	fprintf(stderr,"input b= %08X %08X %08X %08X\n",b[3],b[2],b[1],b[0]);
30	fprintf(stderr,"output = %08X %08X %08X %08X\n",r[3],r[2],r[1],r[0]);
31	fprintf(stderr,"correct= %08X %08X %08X %08X\n",c[3],c[2],c[1],c[0]);
32	}
33
34int sub(r,a,b)
35unsigned long *r,*a,*b;
36	{
37	register unsigned long t1,t2,*ap,*bp,*rp;
38	int i,carry;
39#ifdef FIXBUG
40	unsigned long dummy;
41#endif
42
43	ap=a;
44	bp=b;
45	rp=r;
46	carry=0;
47	for (i=0; i<4; i++)
48		{
49		t1= *(ap++);
50		t2= *(bp++);
51		t1=(t1-t2);
52#ifdef FIXBUG
53		dummy=t1;
54#endif
55		*(rp++)=t1&0xffffffff;
56		}
57	}
58