home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / gnu / mntinc16 / fpu.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-29  |  1.9 KB  |  80 lines

  1. #ifndef _FPU_H
  2. #define _FPU_H
  3.  
  4. /*
  5.  * include file for FPU instructions.  
  6.  *
  7.  * It would be nice to be able to communicate the various forms of these
  8.  * insns to the compiler, but it is not to be.
  9.  *
  10.  * For instance, "fsinb #1,fp0" is reasonable and small, but
  11.  * I don't want to have multiple #define's for 'sin(x)'.
  12.  */
  13.  
  14. /*
  15.  * The _81 macro below turns "#define sin(x) _81("fsinx",x)" into this:
  16.  *
  17.  * #define sin(x) ({double in=(x), out; 
  18.  *     asm("fsinx %1,%0" : "=f" (out) : "f" (in)); out;})
  19.  *
  20.  * And then a call like x=sin(x) (for global double x) produces this 
  21.  * assembly code:
  22.  *
  23.  *    fmoved _x,fp0
  24.  *    fsinx fp0,fp0
  25.  *    fmoved fp0,_x
  26.  */
  27.  
  28. #define _81(insn,x) (double)({double in=(x), out; \
  29.     __asm(insn " %1,%0" : "=f" (out) : "f" (in)); out;})
  30.  
  31. #define acos(x) _81("facosx",x)
  32. #define asin(x) _81("fasinx",x)
  33. #define atan(x) _81("fatanx",x)
  34. #define atanh(x) _81("fatanhx",x)
  35. #define cos(x) _81("fcosx",x)
  36. #define cosh(x) _81("fcoshx",x)
  37. #define dabs(x) _81("fabsx",x)
  38. #define fabs(x) dabs(x)
  39. #define exp(x) _81("fetoxx",x)
  40. #define log(x) _81("flognx",x)
  41. #define log10(x) _81("flog10x",x)
  42. #define sin(x) _81("fsinx",x)
  43. #define sinh(x) _81("fsinhx",x)
  44. #define sqrt(x) _81("fsqrtx",x)
  45. #define tan(x) _81("ftanx",x)
  46. #define tanh(x) _81("ftanhx",x)
  47.  
  48. #define floor(x) _81("fintrzx",x)
  49. #define ceil(x) (- _81("fintrzx",-(x)))
  50.  
  51. #define rint(x) _81("fintx",x)
  52.  
  53. #define fmod(x,y) (double)({double _x=(x), _y=(y); \
  54.     __asm("fmodx %2,%0" : "=f" (_x) : "0" (_x), "f" (_y)); _x;})
  55.  
  56. #define copysign(x,y) ({double _x=x, _y=y; (y>0.0 ? (x>0.0 ? x : -x) : (x<0.0 ? x : -x));})
  57.  
  58. static inline double pow(double x,double y)
  59. {
  60.     double temp;
  61.     long l;
  62.     if (x <= 0.) {
  63.     if (x == 0.) {
  64.         if (y <= 0.) goto domain;
  65.         return 0.;
  66.     }
  67.     l = y;
  68.     if (l != y) goto domain;
  69.     temp = exp(y * log(-x));
  70.     if (l & 1) temp = -temp;
  71.     return temp;
  72.     }
  73.     return (exp(y * log(x)));
  74.  
  75. domain:
  76.     return HUGE;
  77. }
  78.  
  79. #endif
  80.