sgiccbug.c 1.4 KB

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