home *** CD-ROM | disk | FTP | other *** search
/ Atari FTP / ATARI_FTP_0693.zip / ATARI_FTP_0693 / Mint / mntlib32.zoo / flonum.h < prev    next >
C/C++ Source or Header  |  1992-12-12  |  5KB  |  199 lines

  1. #ifndef FLONUM_H
  2. #define FLONUM_H
  3.  
  4. /* Defs and macros for floating point code.  This stuff is heavily based
  5.    on Scott McCauley's code, except that this version works :-} */
  6.  
  7.  
  8. /* These definitions work for machines where an SF value is
  9.    returned in the same register as an int.  */
  10.  
  11. #ifndef SFVALUE  
  12. #define SFVALUE int
  13. #endif
  14.  
  15. #ifndef INTIFY
  16. #define INTIFY(FLOATVAL)  (intify.f = (FLOATVAL), intify.i)
  17. #endif
  18.  
  19. /* quasi-IEEE floating point number definitions */
  20.  
  21. #ifndef __TURBOC__
  22. struct bitfloat {
  23.     unsigned long sign : 1;
  24.     unsigned long exp  : 8;
  25.     unsigned long mant : 23;
  26. };
  27.  
  28. struct bitdouble {
  29.     unsigned long sign  : 1;
  30.     unsigned long exp   : 11;
  31.     unsigned long mant1 : 20;
  32.     unsigned long mant2;
  33. };
  34. #endif
  35.  
  36. #ifdef __TURBOC__
  37. # define __IEEE_DOUBLE_EXTENDED__
  38. /* IEEE double extended: 80 bits (1 sign + 15 exp + 64 mant) */
  39. #else
  40. # define __IEEE_DOUBLE_REAL__
  41. /* IEEE double real: 64 bits (1 sign + 11 exp + 52 mant) */
  42. #endif
  43.  
  44. #ifdef __IEEE_DOUBLE_EXTENDED__
  45. union double_di {
  46.     double d;
  47.     short j[5];  /* a double has 80 bits */
  48.     long i[2]; /* for accessing the first 64 bits as long words */
  49. };
  50. #endif
  51.  
  52. #ifdef __IEEE_DOUBLE_REAL__
  53. union double_di {
  54.     double d;
  55.     long   i[2]; /* a double has 64 bits */
  56. };
  57. #endif
  58.  
  59. union flt_or_int {
  60.         long  i;
  61.         float f;
  62. };
  63.  
  64. #ifdef WORDS_BIG_ENDIAN
  65. #  define HIGH 0
  66. #  define LOW 1
  67. #else
  68. #  define HIGH 1
  69. #  define LOW 0
  70. #endif
  71.  
  72. /*
  73.  * all float/double/long now coded in assembler, dont define anything
  74.  * below this line
  75.  */
  76. #if 0
  77. /* start of symbolic asm definitions */
  78.  
  79. /* you may have to change the g's to d's if you start getting
  80.    illegal operands from as */
  81.  
  82. #define MUL(a, b) \
  83.     asm volatile ("mulu    %2,%0"     : "=d" (b)    : "0" (b) , "g" (a))
  84.  
  85. #define DIV(a, b) \
  86.     asm volatile ("divu %2,%0"     : "=d" (b)    : "0" (b) , "g" (a))
  87.  
  88. #define SWAP(a)      \
  89.     asm volatile ("swap    %0"     : "=r" (a)     : "0" (a))
  90.  
  91. #define ASL2(r1, r2) { \
  92.     asm volatile ("asll  #1,%0"    : "=d" (r2)     : "0" (r2));    \
  93.     asm volatile ("roxll #1,%0" : "=d" (r1)    : "0" (r1));    \
  94.     }
  95.  
  96. #define ASL3(r1, r2, r3) { \
  97.     asm volatile ("asll  #1,%0" : "=d" (r3)     : "0" (r3));    \
  98.     asm volatile ("roxll #1,%0" : "=d" (r2)     : "0" (r2));    \
  99.     asm volatile ("roxll #1,%0" : "=d" (r1)     : "0" (r1));     \
  100.     }
  101.  
  102. #define ASR2(r1, r2) {    \
  103.     asm volatile ("asrl  #1,%0" : "=d" (r1)     : "0" (r1));    \
  104.     asm volatile ("roxrl #1,%0" : "=d" (r2)     : "0" (r2));    \
  105.     }
  106.  
  107. #define ASR3(r1, r2, r3) { \
  108.     asm volatile ("asrl  #1,%0" : "=d" (r1)     : "0" (r1));    \
  109.     asm volatile ("roxrl #1,%0" : "=d" (r2)     : "0" (r2));    \
  110.     asm volatile ("roxrl #1,%0" : "=d" (r3)     : "0" (r3));    \
  111.     }
  112.  
  113. #define ASR4(r1, r2, r3, r4) { \
  114.     asm volatile ("asrl  #1,%0" : "=d" (r1)     : "0" (r1));    \
  115.     asm volatile ("roxrl #1,%0" : "=d" (r2)     : "0" (r2));    \
  116.     asm volatile ("roxrl #1,%0" : "=d" (r3)    : "0" (r3));    \
  117.     asm volatile ("roxrl #1,%0" : "=d" (r4)     : "0" (r4));    \
  118.     }
  119.  
  120. #define ADD2(r1, r2, r3, r4) { \
  121.     asm volatile ("addl  %2,%0"    : "=g" (r4)     : "0" (r4) , "g" (r2));    \
  122.     asm volatile ("addxl %2,%0"    : "=g" (r3)    : "0" (r3) , "g" (r1));    \
  123.     }
  124.  
  125. /* y <- y - x  */
  126. #define SUB3(x1, x2, x3, y1, y2, y3) { \
  127.     asm volatile ("subl  %2,%0"    : "=g" (y3)    : "0" (y3) , "d" (x3));    \
  128.     asm volatile ("subxl %2,%0"    : "=g" (y2)     : "0" (y2) , "d" (x2)); \
  129.     asm volatile ("subxl %2,%0"    : "=g" (y1)     : "0" (y1) , "d" (x1));    \
  130.     }
  131.  
  132. /* sub4 here is rather complex, as the compiler is overwhelmed by me wanting
  133.    to have 8 data registers allocated for mantissa accumulators.  Help it out
  134.    by declaring a temp that it can move stuff in and out of.  */
  135. #define SUB4(x1, x2, x3, x4, y1, y2, y3, y4) { \
  136.     register long temp = y4;                          \
  137.     asm volatile ("subl  %2,%0"    : "=d" (temp)    : "0" (temp) , "d" (x4)); \
  138.     y4 = temp; temp = y3;                           \
  139.     asm volatile ("subxl %2,%0"    : "=d" (temp)    : "0" (temp) , "d" (x3)); \
  140.     y3 = temp; temp = y2;                          \
  141.     asm volatile ("subxl %2,%0"    : "=d" (temp)    : "0" (temp) , "d" (x2)); \
  142.     y2 = temp; temp = y1;                          \
  143.     asm volatile ("subxl %2,%0"    : "=d" (temp)    : "0" (temp) , "d" (x1)); \
  144.     y1 = temp;                                  \
  145.     }
  146.  
  147. #define NEG(r1, r2) { \
  148.     asm volatile ("negl  %0"    : "=d" (r2)    : "0" (r2));    \
  149.     asm volatile ("negxl %0"     : "=d" (r1)     : "0" (r1));    \
  150.     } 
  151.  
  152. /* switches for which routines to compile.  All the single-float and
  153. long-int arithmetic routines are turned off here, as they were all
  154. done in assembly language last year.  */
  155.  
  156. /*
  157. #define L_umulsi3
  158. #define L_mulsi3
  159. #define L_udivsi3
  160. #define L_divsi3
  161. #define L_umodsi3
  162. #define L_modsi3
  163. #define L_lshrsi3
  164. #define L_lshlsi3
  165. #define L_ashrsi3
  166. #define L_ashlsi3
  167. */
  168. /*    These are now in kai-uwe .s files
  169.   #define L_divdf3
  170.   #define L_muldf3
  171.   #define L_negdf2
  172.   #define L_adddf3
  173.   #define L_subdf3
  174.   #define L_cmpdf2
  175.   #define L_fixunsdfsi
  176.   #define L_floatsidf
  177. */
  178. /*
  179.   these three are now in gnulib2 (were in dflonum.h pre gcc1.36)
  180. #define L_fixunsdfdi
  181. #define L_fixdfdi
  182. #define L_floatdidf
  183.  
  184. #define L_addsf3
  185. #define L_negsf2
  186. #define L_subsf3
  187. #define L_cmpsf2
  188. #define L_mulsf3
  189. #define L_divsf3
  190. */
  191.  
  192. /* These too are now in kai-uwe .s files
  193.    #define L_truncdfsf2
  194.    #define L_extendsfdf2
  195. */
  196. #endif /* #if 0 */
  197.  
  198. #endif /* FLONUM_H */
  199.