home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 359_11 / patch5.000 / EMU387 / E16.CC < prev    next >
C/C++ Source or Header  |  1991-09-11  |  3KB  |  194 lines

  1. #include "emu.h"
  2. #include "rmov.h"
  3. #include "const.h"
  4. #include "compare.h"
  5.  
  6. void f2xm1()
  7. {
  8.   if (empty())
  9.     return;
  10.   reg xloga, val, rv, bottom, tmp;
  11.   long i;
  12.  
  13.   r_mul(CONST_LN2, st(), xloga);
  14.   r_mov(xloga, val);
  15.   r_mov(xloga, rv);
  16.  
  17.   for (i=2; i<16; i++)
  18.   {
  19.     r_mov(&i, bottom);
  20.     r_mul(val, xloga, tmp);
  21.     r_div(tmp, bottom, val);
  22.     r_add(val, rv, tmp);
  23.     r_mov(tmp, rv);
  24.   }
  25.   r_mov(rv, st());
  26. }
  27.  
  28. // logb(x) = loga(x) / loga(b)
  29. // log2(x) = loge(x) / loge(2)
  30.  
  31. void fyl2x()
  32. {
  33.   if (empty())
  34.     return;
  35.   reg frac2, sum, div, term, pow, temp;
  36.   r_sub(st(), CONST_1, frac2);
  37.   r_add(st(), CONST_1, div);
  38.   r_div(frac2, div, sum);
  39.   r_mul(sum, sum, frac2);
  40.   r_mul(sum, st(1), pow);
  41.   for (long i=3; i<15; i+=2)
  42.   {
  43.     r_mul(pow, frac2, temp);
  44.     r_mov(temp, pow);
  45.     r_mov(&i, div);
  46.     r_div(temp, div, term);
  47.     r_add(term, sum, temp);
  48.     r_mov(temp, sum);
  49.   }
  50.   r_div(sum, CONST_LN2, temp);
  51.   temp.exp++;
  52.   r_mov(temp, st(1));
  53.   st().tag = TW_E;
  54.   top++;
  55. }
  56.  
  57. void fptan()
  58. {
  59.   extern void fsincos();
  60.   fsincos();
  61.   if (empty(1))
  62.     return;
  63.   reg tmp;
  64.   r_div(st(1), st(), tmp);
  65.   r_mov(tmp, st(1));
  66.   r_mov(CONST_1, st());
  67. }
  68.  
  69. void fpatan()
  70. {
  71.   if (empty(1))
  72.     return;
  73.   if (mag_same(st(), CONST_Z))
  74.   {
  75.     r_mov(CONST_PI2, st(1));
  76.     st().tag = TW_E;
  77.     top++;
  78.     return;
  79.   }
  80.   if (mag_same(st(1), CONST_Z))
  81.   {
  82.     r_mov(CONST_Z, st(1));
  83.     st().tag = TW_E;
  84.     top++;
  85.     return;
  86.   }
  87.   reg x2, sum, term, pow, temp;
  88.   int quadrant = 0;
  89.   if (st(1).sign == SIGN_NEG)
  90.     quadrant |= 1;
  91.   if (st(0).sign == SIGN_NEG)
  92.     quadrant |= 2;
  93.   st(1).sign = st().sign = SIGN_POS;
  94.   if (compare(st(1), st()) == COMP_A_GT_B)
  95.   {
  96.     quadrant |= 4;
  97.     r_mov(st(1), temp);
  98.     r_mov(st(), st(1));
  99.     r_mov(temp, st());
  100.   }
  101.  
  102.   r_div(st(1), st(), sum);
  103.   r_mul(sum, sum, x2);
  104.   r_mov(sum, pow);
  105.  
  106.   x2.sign ^= SIGN_POS^SIGN_NEG;
  107.  
  108.   for (long i=3; i<25; i+=2)
  109.   {
  110.     r_mul(pow, x2, temp);
  111.     r_mov(temp, pow);
  112.     r_mov(&i, temp);
  113.     r_div(pow, temp, term);
  114.     r_add(sum, term, temp);
  115.     r_mov(temp, sum);
  116.   }
  117.  
  118.   if (quadrant & 4)
  119.   {
  120.     r_sub(CONST_PI2, sum, temp);
  121.     r_mov(temp, sum);
  122.   }
  123.   if (quadrant & 2)
  124.   {
  125.     r_sub(CONST_PI, sum, temp);
  126.     r_mov(temp, sum);
  127.   }
  128.   if (quadrant & 1)
  129.     sum.sign ^= SIGN_POS^SIGN_NEG;
  130.  
  131.   r_mov(sum, st(1));
  132.   st().tag = TW_E;
  133.   top++;
  134. }
  135.  
  136. void fxtract()
  137. {
  138.   if (empty())
  139.     return;
  140.   if (full())
  141.     return;
  142.   top--;
  143.   r_mov(st(1), st());
  144.   st().exp = EXP_BIAS;
  145.   long e = st(1).exp - EXP_BIAS;
  146.   r_mov(&e, st(1));
  147. }
  148.  
  149. extern int fprem_do(reg&,reg&,int);
  150.  
  151. void fprem1()
  152. {
  153.   if (empty(1))
  154.     return;
  155.   int q = fprem_do(st(), st(1), RC_RND);
  156.   if (q == -1)
  157.     setcc(SW_C2);
  158.   else
  159.   {
  160.     int c = 0;
  161.     if (q&4) c |= SW_C3;
  162.     if (q&2) c |= SW_C1;
  163.     if (q&1) c |= SW_C0;
  164.     setcc(c);
  165.   }
  166. }
  167.  
  168. void fdecstp()
  169. {
  170.   top--;
  171. }
  172.  
  173. void fincstp()
  174. {
  175.   top++;
  176. }
  177.  
  178. FUNC emu_16_table[] = {
  179.   f2xm1, fyl2x, fptan, fpatan, fxtract, fprem1, fdecstp, fincstp
  180. };
  181.  
  182. void emu_16()
  183. {
  184.   if (modrm > 0277)
  185.   {
  186.     (emu_16_table[modrm&7])();
  187.   }
  188.   else
  189.   {
  190.     emu_bad();
  191.   }
  192. }
  193.  
  194.