home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 3 / 3137 / flonum.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-03-27  |  4.0 KB  |  133 lines

  1.  
  2. /* Defs and macros for floating point code.  This stuff is heavily based
  3.    on Scott McCauley's code, except that this version works :-} */
  4.  
  5.  
  6. /* These definitions work for machines where an SF value is
  7.    returned in the same register as an int.  */
  8.  
  9. #ifndef SFVALUE  
  10. #define SFVALUE int
  11. #endif
  12.  
  13. #ifndef INTIFY
  14. #define INTIFY(FLOATVAL)  (intify.f = (FLOATVAL), intify.i)
  15. #endif
  16.  
  17. /* quasi-IEEE floating point number definitions */
  18.  
  19. struct bitfloat {
  20.     unsigned sign : 1;
  21.     unsigned exp : 8;
  22.     unsigned mant : 23;
  23. };
  24.  
  25. struct bitdouble {
  26.     unsigned sign : 1;
  27.     unsigned exp : 11;
  28.     unsigned mant1 : 20;
  29.     unsigned long mant2;
  30. };
  31.  
  32. union double_di { double d; int i[2]; };
  33. union flt_or_int { int i; float f; };
  34.  
  35. #ifdef WORDS_BIG_ENDIAN
  36. #define HIGH 0
  37. #define LOW 1
  38. #else
  39. #define HIGH 1
  40. #define LOW 0
  41. #endif
  42.  
  43. /* start of symbolic asm definitions */
  44.  
  45. /* you may have to change the g's to d's if you start getting
  46.    illegal operands from as */
  47.  
  48. #define MUL(a, b) asm volatile ("mulu %2,%0" : "=d" (b) : "0" (b) , "g" (a))
  49. #define DIV(a, b) asm volatile ("divu %2,%0" : "=d" (b) : "0" (b) , "g" (a))
  50. #define SWAP(a) asm volatile ("swap %0" : "=r" (a) : "r" (a) , "r" (a) )
  51.  
  52. #define ASL2(r1, r2) { asm volatile ("asll #1,%0" : "=d" (r2) : "d" (r2));\
  53.                asm volatile ("roxll #1,%0" : "=d" (r1) : "d" (r1)); }
  54. #define ASL3(r1, r2, r3) { asm volatile ("asll #1,%0" : "=d" (r3) : "d" (r3));\
  55.                asm volatile ("roxll #1,%0" : "=d" (r2) : "d" (r2));\
  56.                asm volatile ("roxll #1,%0" : "=d" (r1) : "d" (r1)); }
  57.  
  58. #define ASR2(r1, r2) { asm volatile ("asrl #1,%0" : "=d" (r1) : "d" (r1));\
  59.                asm volatile ("roxrl #1,%0" : "=d" (r2) : "d" (r2)); }
  60. #define ASR3(r1, r2, r3) { asm volatile ("asrl #1,%0" : "=d" (r1) : "d" (r1));\
  61.                asm volatile ("roxrl #1,%0" : "=d" (r2) : "d" (r2));\
  62.                asm volatile ("roxrl #1,%0" : "=d" (r3) : "d" (r3)); }
  63. #define ASR4(r1, r2, r3, r4) { asm volatile ("asrl #1,%0" : "=d" (r1) : "d" (r1));\
  64.                    asm volatile ("roxrl #1,%0" : "=d" (r2) : "d" (r2));\
  65.                    asm volatile ("roxrl #1,%0" : "=d" (r3) : "d" (r3));\
  66.                    asm volatile ("roxrl #1,%0" : "=d" (r4) : "d" (r4)); }
  67.  
  68. #define ADD2(r1, r2, r3, r4) \
  69.     { asm volatile ("addl %2,%0": "=g" (r4) : "0" (r4) , "g" (r2)); \
  70.       asm volatile ("addxl %2,%0": "=g" (r3) : "0" (r3) , "g" (r1)); }
  71.  
  72. /* y <- y - x  */
  73. #define SUB3(x1, x2, x3, y1, y2, y3) \
  74.     { asm volatile ("subl %2,%0": "=g" (y3) : "g" (y3) , "d" (x3)); \
  75.       asm volatile ("subxl %2,%0": "=g" (y2) : "g" (y2) , "d" (x2));\
  76.       asm volatile ("subxl %2,%0": "=g" (y1) : "g" (y1) , "d" (x1)); }
  77.  
  78. /* sub4 here is rather complex, as the compiler is overwhelmed by me wanting
  79.    to have 8 data registers allocated for mantissa accumulators.  Help it out
  80.    by declaring a temp that it can move stuff in and out of.  */
  81. #define SUB4(x1, x2, x3, x4, y1, y2, y3, y4) \
  82.     { register long temp = y4; \
  83.       asm volatile ("subl %2,%0": "=d" (temp) : "d" (temp) , "d" (x4)); \
  84.       y4 = temp; temp = y3; \
  85.       asm volatile ("subxl %2,%0": "=d" (temp) : "d" (temp) , "d" (x3));\
  86.       y3 = temp; temp = y2; \
  87.       asm volatile ("subxl %2,%0": "=d" (temp) : "d" (temp) , "d" (x2));\
  88.       y2 = temp; temp = y1; \
  89.       asm volatile ("subxl %2,%0": "=d" (temp) : "d" (temp) , "d" (x1));\
  90.       y1 = temp; }
  91.  
  92. #define NEG(r1, r2) { asm volatile ("negl %0" : "=d" (r2) : "d" (r2)); \
  93.               asm volatile ("negxl %0" : "=d" (r1) : "d" (r1)); } 
  94.  
  95. /* switches for which routines to compile.  All the single-float and
  96. long-int arithmetic routines are turned off here, as they were all
  97. done in assembly language last year.  */
  98.  
  99. /*
  100. #define L_umulsi3
  101. #define L_mulsi3
  102. #define L_udivsi3
  103. #define L_divsi3
  104. #define L_umodsi3
  105. #define L_modsi3
  106. #define L_lshrsi3
  107. #define L_lshlsi3
  108. #define L_ashrsi3
  109. #define L_ashlsi3
  110. */
  111. #define L_divdf3
  112. #define L_muldf3
  113. #define L_negdf2
  114. #define L_adddf3
  115. #define L_subdf3
  116. #define L_cmpdf2
  117. #define L_fixunsdfsi
  118. #define L_fixunsdfdi
  119. #define L_fixdfdi
  120. #define L_floatsidf
  121. #define L_floatdidf
  122. /*
  123. #define L_addsf3
  124. #define L_negsf2
  125. #define L_subsf3
  126. #define L_cmpsf2
  127. #define L_mulsf3
  128. #define L_divsf3
  129. */
  130. #define L_truncdfsf2
  131. #define L_extendsfdf2
  132.  
  133.