155714Skris/* NOCW */ 255714Skris/* sgibug.c */ 355714Skris/* bug found by Eric Young (eay@mincom.oz.au) May 95 */ 455714Skris 555714Skris#include <stdio.h> 655714Skris 7296465Sdelphij/* 8296465Sdelphij * This compiler bug it present on IRIX 5.3, 5.1 and 4.0.5 (these are the 9296465Sdelphij * only versions of IRIX I have access to. defining FIXBUG removes the bug. 10296465Sdelphij * (bug is still present in IRIX 6.3 according to Gage 11296465Sdelphij * <agage@forgetmenot.Mines.EDU> 1255714Skris */ 13296465Sdelphij 14296465Sdelphij/*- 15296465Sdelphij * Compare the output from 1655714Skris * cc sgiccbug.c; ./a.out 1755714Skris * and 1855714Skris * cc -O sgiccbug.c; ./a.out 1955714Skris */ 2055714Skris 21296465Sdelphijstatic unsigned long a[4] = 22296465Sdelphij { 0x01234567, 0x89ABCDEF, 0xFEDCBA98, 0x76543210 }; 23296465Sdelphijstatic unsigned long b[4] = 24296465Sdelphij { 0x89ABCDEF, 0xFEDCBA98, 0x76543210, 0x01234567 }; 25296465Sdelphijstatic unsigned long c[4] = 26296465Sdelphij { 0x77777778, 0x8ACF1357, 0x88888888, 0x7530ECA9 }; 2755714Skris 2855714Skrismain() 29296465Sdelphij{ 30296465Sdelphij unsigned long r[4]; 31296465Sdelphij sub(r, a, b); 32296465Sdelphij fprintf(stderr, "input a= %08X %08X %08X %08X\n", a[3], a[2], a[1], a[0]); 33296465Sdelphij fprintf(stderr, "input b= %08X %08X %08X %08X\n", b[3], b[2], b[1], b[0]); 34296465Sdelphij fprintf(stderr, "output = %08X %08X %08X %08X\n", r[3], r[2], r[1], r[0]); 35296465Sdelphij fprintf(stderr, "correct= %08X %08X %08X %08X\n", c[3], c[2], c[1], c[0]); 36296465Sdelphij} 3755714Skris 38296465Sdelphijint sub(r, a, b) 39296465Sdelphijunsigned long *r, *a, *b; 40296465Sdelphij{ 41296465Sdelphij register unsigned long t1, t2, *ap, *bp, *rp; 42296465Sdelphij int i, carry; 4355714Skris#ifdef FIXBUG 44296465Sdelphij unsigned long dummy; 4555714Skris#endif 4655714Skris 47296465Sdelphij ap = a; 48296465Sdelphij bp = b; 49296465Sdelphij rp = r; 50296465Sdelphij carry = 0; 51296465Sdelphij for (i = 0; i < 4; i++) { 52296465Sdelphij t1 = *(ap++); 53296465Sdelphij t2 = *(bp++); 54296465Sdelphij t1 = (t1 - t2); 5555714Skris#ifdef FIXBUG 56296465Sdelphij dummy = t1; 5755714Skris#endif 58296465Sdelphij *(rp++) = t1 & 0xffffffff; 59296465Sdelphij } 60296465Sdelphij} 61