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

  1. #include    "register.h"
  2. #include    "symtab.h"
  3. #include    "diblock.h"
  4. #include    "instrn.h"
  5. #include    "process.h"
  6.  
  7. extern double    fabs();
  8.  
  9. dinstrn    *
  10. i_absfmt(dipc, fmt, ft, fs, fd)
  11. dinstrn    *dipc;
  12. int    fmt;
  13. int    ft;
  14. int    fs;
  15. int    fd;
  16. {
  17.     float    singles;
  18.     float    singled;
  19.     double    doubles;
  20.     double    doubled;
  21.  
  22.     switch (fmt)
  23.     {
  24.     case FMT_SINGLE:
  25.         procsget(CP1G(fs), *(unsigned long *)&singles);
  26.  
  27.         singled = (float)fabs(singles);
  28.  
  29.         procsput(CP1G(fd), *(unsigned long *)&singled);
  30.  
  31.         break;
  32.  
  33.     case FMT_DOUBLE:
  34.         /*
  35.          * Note apparent reversal of words within
  36.          * doubles here -- no idea why.
  37.          */
  38.         procsget(CP1G(fs), *((unsigned long *)&doubles + 1));
  39.  
  40.         procsget(CP1G(fs) + 1, *(unsigned long *)&doubles);
  41.  
  42.         doubled = fabs(doubles);
  43.  
  44.         procsput(CP1G(fd), *((unsigned long *)&doubled + 1));
  45.  
  46.         procsput(CP1G(fd) + 1, *(unsigned long *)&doubled);
  47.         break;
  48.  
  49.     default:
  50.         unrecognised(dipc);
  51.         break;
  52.     }
  53.  
  54.     return dipc;
  55. }
  56.  
  57. dinstrn    *
  58. i_add(dipc, rs, rt, rd, shamt, funct)
  59. dinstrn    *dipc;
  60. int    rs;
  61. int    rt;
  62. int    rd;
  63. int    shamt;
  64. int    funct;
  65. {
  66.     unsigned long    s;
  67.     unsigned long    t;
  68.  
  69.     procsget(rs, s);
  70.  
  71.     procsget(rt, t);
  72.  
  73.     /*
  74.      * TODO -- overflow exception.
  75.      */
  76.     procsput(rd, s + t);
  77.  
  78.     return dipc;
  79. }
  80.  
  81. dinstrn    *
  82. i_addfmt(dipc, fmt, ft, fs, fd)
  83. dinstrn    *dipc;
  84. int    fmt;
  85. int    ft;
  86. int    fs;
  87. int    fd;
  88. {
  89.     float        singles;
  90.     float        singlet;
  91.     float        singled;
  92.     double        doubles;
  93.     double        doublet;
  94.     double        doubled;
  95.     unsigned long    l[2];
  96.  
  97.     switch (fmt)
  98.     {
  99.     case FMT_SINGLE:
  100.         procsget(CP1G(fs), *(unsigned long *)&singles);
  101.  
  102.         procsget(CP1G(ft), *(unsigned long *)&singlet);
  103.  
  104.         singled = singles + singlet;
  105.  
  106.         procsput(CP1G(fd), *(unsigned long *)&singled);
  107.  
  108.         break;
  109.  
  110.     case FMT_DOUBLE:
  111.         /*
  112.          * Note apparent reversal of words within
  113.          * doubles here -- no idea why.
  114.          */
  115.         procsget(CP1G(fs), *((unsigned long *)&doubles + 1));
  116.  
  117.         procsget(CP1G(fs) + 1, *(unsigned long *)&doubles);
  118.  
  119.         procsget(CP1G(ft), *((unsigned long *)&doublet + 1));
  120.  
  121.         procsget(CP1G(ft) + 1, *(unsigned long *)&doublet);
  122.  
  123.         doubled = doubles + doublet;
  124.  
  125.         procsput(CP1G(fd), *((unsigned long *)&doubled + 1));
  126.  
  127.         procsput(CP1G(fd) + 1, *(unsigned long *)&doubled);
  128.         break;
  129.  
  130.     default:
  131.         unrecognised(dipc);
  132.         break;
  133.     }
  134.  
  135.     return dipc;
  136. }
  137.  
  138. static
  139. dinstrn    *
  140. c_addi_li(dipc)
  141. dinstrn    *dipc;
  142. {
  143.     *dipc->di_0 = (long)dipc->di_2;
  144.  
  145.     return dipc;
  146. }
  147.  
  148. static
  149. dinstrn    *
  150. c_addi(dipc)
  151. dinstrn    *dipc;
  152. {
  153.     *dipc->di_0 = *dipc->di_1 + (long)dipc->di_2;
  154.  
  155.     return dipc;
  156. }
  157.  
  158. dinstrn    *
  159. i_addi(dipc, rs, rt, immediate)
  160. dinstrn    *dipc;
  161. int    rs;
  162. int    rt;
  163. short    immediate;
  164. {
  165.     unsigned long    r;
  166.  
  167.     if (compile_ok)
  168.     {
  169.         if (rt == R_0)
  170.             dipc->di_handler = c_noop;
  171.         else
  172.         {
  173.             if (rs == R_0)
  174.                 dipc->di_handler = c_addi_li;
  175.             else
  176.                 dipc->di_handler = c_addi;
  177.             dipc->di_0 = &P.p_state[rt];
  178.             dipc->di_1 = &P.p_state[rs];
  179.             dipc->di_2 = (unsigned long *)(long)immediate;
  180.         }
  181.  
  182.         return (*dipc->di_handler)(dipc);
  183.     }
  184.  
  185.     procsget(rs, r);
  186.  
  187.     procsput(rt, r + immediate);
  188.  
  189.     /*
  190.      * Overflow exception?
  191.      */
  192.  
  193.     return dipc;
  194. }
  195.  
  196. static
  197. dinstrn    *
  198. c_addiu_li(dipc)
  199. dinstrn    *dipc;
  200. {
  201.     *dipc->di_0 = (long)dipc->di_2;
  202.  
  203.     return dipc;
  204. }
  205.  
  206. static
  207. dinstrn    *
  208. c_addiu(dipc)
  209. dinstrn    *dipc;
  210. {
  211.     *dipc->di_0 = *dipc->di_1 + (long)dipc->di_2;
  212.  
  213.     return dipc;
  214. }
  215.  
  216. dinstrn    *
  217. i_addiu(dipc, rs, rt, immediate)
  218. dinstrn    *dipc;
  219. int    rs;
  220. int    rt;
  221. short    immediate;
  222. {
  223.     unsigned long    s;
  224.  
  225.     if (compile_ok)
  226.     {
  227.         if (rt == R_0)
  228.             dipc->di_handler = c_noop;
  229.         else
  230.         {
  231.             if (rs == R_0)
  232.                 dipc->di_handler = c_addiu_li;
  233.             else
  234.                 dipc->di_handler = c_addiu;
  235.             dipc->di_0 = &P.p_state[rt];
  236.             dipc->di_1 = &P.p_state[rs];
  237.             dipc->di_2 = (unsigned long *)(long)immediate;
  238.         }
  239.  
  240.         return (*dipc->di_handler)(dipc);
  241.     }
  242.  
  243.     procsget(rs, s);
  244.  
  245.     procsput(rt, s + (long)immediate);
  246.  
  247.     return dipc;
  248. }
  249.  
  250. static
  251. dinstrn    *
  252. c_addu_move(dipc)
  253. dinstrn    *dipc;
  254. {
  255.     *dipc->di_0 = *dipc->di_2;
  256.  
  257.     return dipc;
  258. }
  259.  
  260. static
  261. dinstrn    *
  262. c_addu_move2(dipc)
  263. dinstrn    *dipc;
  264. {
  265.     *dipc->di_0 = *dipc->di_1;
  266.  
  267.     return dipc;
  268. }
  269.  
  270. static
  271. dinstrn    *
  272. c_addu(dipc)
  273. dinstrn    *dipc;
  274. {
  275.     *dipc->di_0 = *dipc->di_1 + *dipc->di_2;
  276.  
  277.     return dipc;
  278. }
  279.  
  280. dinstrn    *
  281. i_addu(dipc, rs, rt, rd, shamt, funct)
  282. dinstrn    *dipc;
  283. int    rs;
  284. int    rt;
  285. int    rd;
  286. int    shamt;
  287. int    funct;
  288. {
  289.     unsigned long    s;
  290.     unsigned long    t;
  291.  
  292.     if (compile_ok)
  293.     {
  294.         if (rd == R_0)
  295.             dipc->di_handler = c_noop;
  296.         else
  297.         {
  298.             if (rs == R_0)
  299.                 dipc->di_handler = c_addu_move;
  300.             else if (rt == R_0)
  301.                 dipc->di_handler = c_addu_move2;
  302.             else
  303.                 dipc->di_handler = c_addu;
  304.             dipc->di_0 = &P.p_state[rd];
  305.             dipc->di_1 = &P.p_state[rs];
  306.             dipc->di_2 = &P.p_state[rt];
  307.         }
  308.  
  309.         return (*dipc->di_handler)(dipc);
  310.     }
  311.  
  312.     procsget(rs, s);
  313.  
  314.     procsget(rt, t);
  315.  
  316.     procsput(rd, s + t);
  317.  
  318.     return dipc;
  319. }
  320.  
  321. dinstrn    *
  322. i_and(dipc, rs, rt, rd, shamt, funct)
  323. dinstrn    *dipc;
  324. int    rs;
  325. int    rt;
  326. int    rd;
  327. int    shamt;
  328. int    funct;
  329. {
  330.     unsigned long    s;
  331.     unsigned long    t;
  332.  
  333.     procsget(rs, s);
  334.  
  335.     procsget(rt, t);
  336.  
  337.     procsput(rd, s & t);
  338.  
  339.     return dipc;
  340. }
  341.  
  342. static
  343. dinstrn    *
  344. c_andi(dipc)
  345. dinstrn    *dipc;
  346. {
  347.     *dipc->di_0 = *dipc->di_1 & (unsigned long)dipc->di_2;
  348.  
  349.     return dipc;
  350. }
  351.  
  352. dinstrn    *
  353. i_andi(dipc, rs, rt, immediate)
  354. dinstrn    *dipc;
  355. int    rs;
  356. int    rt;
  357. short    immediate;
  358. {
  359.     unsigned long    s;
  360.  
  361.     if (compile_ok)
  362.     {
  363.         if (rt == R_0)
  364.             dipc->di_handler = c_noop;
  365.         else
  366.         {
  367.             dipc->di_handler = c_andi;
  368.             dipc->di_0 = &P.p_state[rt];
  369.             dipc->di_1 = &P.p_state[rs];
  370.             dipc->di_2 = (unsigned long *)(((unsigned long)immediate) & 0xFFFF);
  371.         }
  372.  
  373.         return (*dipc->di_handler)(dipc);
  374.     }
  375.  
  376.     procsget(rs, s);
  377.  
  378.     procsput(rt, s & (((unsigned long)immediate) & 0xFFFF));
  379.  
  380.     return dipc;
  381. }
  382.