home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume25 / trash / part01 / i_d.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-22  |  2.2 KB  |  166 lines

  1. #include    "register.h"
  2. #include    "symtab.h"
  3. #include    "diblock.h"
  4. #include    "instrn.h"
  5. #include    "process.h"
  6.  
  7. static
  8. void
  9. notdiv0(dipc)
  10. dinstrn    *dipc;
  11. {
  12.     GLOBALdipc = dipc;
  13.     vcouldnot("divide by 0");
  14. }
  15.  
  16. static
  17. dinstrn    *
  18. c_div(dipc)
  19. dinstrn    *dipc;
  20. {
  21.     long    s;
  22.     long    t;
  23.  
  24.     s = (long)*dipc->di_0;
  25.     t = (long)*dipc->di_1;
  26.  
  27.     if (t == 0)
  28.         notdiv0(dipc);
  29.     else
  30.     {
  31.         P.p_state[R_LO] = s / t;
  32.         P.p_state[R_HI] = s % t;
  33.     }
  34.  
  35.     return dipc;
  36. }
  37.  
  38. dinstrn    *
  39. i_div(dipc, rs, rt, rd, shamt, funct)
  40. dinstrn    *dipc;
  41. int    rs;
  42. int    rt;
  43. int    rd;
  44. int    shamt;
  45. int    funct;
  46. {
  47.     long    s;
  48.     long    t;
  49.  
  50.     if (compile_ok)
  51.     {
  52.         dipc->di_handler = c_div;
  53.         dipc->di_0 = &P.p_state[rs];
  54.         dipc->di_1 = &P.p_state[rt];
  55.  
  56.         return (*dipc->di_handler)(dipc);
  57.     }
  58.  
  59.     procsget(rs, s);
  60.  
  61.     procsget(rt, t);
  62.  
  63.     if (t == (long)0)
  64.         notdiv0(dipc);
  65.     else
  66.     {
  67.         procsput(R_LO, s / t);
  68.         procsput(R_HI, s % t);
  69.     }
  70.  
  71.     return dipc;
  72. }
  73.  
  74. dinstrn    *
  75. i_divfmt(dipc, fmt, ft, fs, fd)
  76. dinstrn    *dipc;
  77. int    fmt;
  78. int    ft;
  79. int    fs;
  80. int    fd;
  81. {
  82.     float    singles;
  83.     float    singlet;
  84.     float    singled;
  85.     double    doubles;
  86.     double    doublet;
  87.     double    doubled;
  88.  
  89.     switch (fmt)
  90.     {
  91.     case FMT_SINGLE:
  92.         procsget(CP1G(fs), *(unsigned long *)&singles);
  93.  
  94.         procsget(CP1G(ft), *(unsigned long *)&singlet);
  95.  
  96.         if (singlet == (float)0)
  97.             notdiv0(dipc);
  98.         else
  99.         {
  100.             singled = singles / singlet;
  101.  
  102.             procsput(CP1G(fd), *(unsigned long *)&singled);
  103.         }
  104.  
  105.         break;
  106.  
  107.     case FMT_DOUBLE:
  108.         /*
  109.          * Note apparent reversal of words within
  110.          * doubles here -- no idea why.
  111.          */
  112.         procsget(CP1G(fs), *((unsigned long *)&doubles + 1));
  113.  
  114.         procsget(CP1G(fs) + 1, *(unsigned long *)&doubles);
  115.  
  116.         procsget(CP1G(ft), *((unsigned long *)&doublet + 1));
  117.  
  118.         procsget(CP1G(ft) + 1, *(unsigned long *)&doublet);
  119.  
  120.         if (doublet == (double)0)
  121.             notdiv0(dipc);
  122.         else
  123.         {
  124.             doubled = doubles / doublet;
  125.  
  126.             procsput(CP1G(fd), *((unsigned long *)&doubled + 1));
  127.  
  128.             procsput(CP1G(fd) + 1, *(unsigned long *)&doubled);
  129.         }
  130.         break;
  131.  
  132.     default:
  133.         unrecognised(dipc);
  134.         break;
  135.     }
  136.  
  137.     return dipc;
  138. }
  139.  
  140. dinstrn    *
  141. i_divu(dipc, rs, rt, rd, shamt, funct)
  142. dinstrn    *dipc;
  143. int    rs;
  144. int    rt;
  145. int    rd;
  146. int    shamt;
  147. int    funct;
  148. {
  149.     unsigned long    s;
  150.     unsigned long    t;
  151.  
  152.     procsget(rs, s);
  153.  
  154.     procsget(rt, t);
  155.  
  156.     if (t == (unsigned long)0)
  157.         notdiv0(dipc);
  158.     else
  159.     {
  160.         procsput(R_LO, s / t);
  161.         procsput(R_HI, s % t);
  162.     }
  163.  
  164.     return dipc;
  165. }
  166.