adder.c 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
  3. See the copyright notice in the ACK home directory, in the file "Copyright".
  4. */
  5. /* $Id$ */
  6. /*
  7. * these are the routines the routines to do 32 and 64-bit addition
  8. */
  9. # ifdef EXT_DEBUG
  10. # include <stdio.h>
  11. # endif
  12. # include "FP_types.h"
  13. # define UNKNOWN -1
  14. # define TRUE 1
  15. # define FALSE 0
  16. # define MAXBIT 0x80000000L
  17. /*
  18. * add 64 bits
  19. */
  20. int
  21. b64_add(e1,e2)
  22. /*
  23. * pointers to 64 bit 'registers'
  24. */
  25. register B64 *e1,*e2;
  26. {
  27. register int overflow;
  28. int carry;
  29. /* add higher pair of 32 bits */
  30. overflow = ((unsigned long) 0xFFFFFFFF - e1->h_32 < e2->h_32);
  31. e1->h_32 += e2->h_32;
  32. /* add lower pair of 32 bits */
  33. carry = ((unsigned long) 0xFFFFFFFF - e1->l_32 < e2->l_32);
  34. e1->l_32 += e2->l_32;
  35. # ifdef EXT_DEBUG
  36. printf("\t\t\t\t\tb64_add: overflow (%d); internal carry(%d)\n",
  37. overflow,carry);
  38. fflush(stdout);
  39. # endif
  40. if ((carry) && (++e1->h_32 == 0))
  41. return(TRUE); /* had a 64 bit overflow */
  42. return(overflow); /* return status from higher add */
  43. }