home *** CD-ROM | disk | FTP | other *** search
- #include "register.h"
- #include "symtab.h"
- #include "diblock.h"
- #include "instrn.h"
- #include "process.h"
-
- static
- void
- notdiv0(dipc)
- dinstrn *dipc;
- {
- GLOBALdipc = dipc;
- vcouldnot("divide by 0");
- }
-
- static
- dinstrn *
- c_div(dipc)
- dinstrn *dipc;
- {
- long s;
- long t;
-
- s = (long)*dipc->di_0;
- t = (long)*dipc->di_1;
-
- if (t == 0)
- notdiv0(dipc);
- else
- {
- P.p_state[R_LO] = s / t;
- P.p_state[R_HI] = s % t;
- }
-
- return dipc;
- }
-
- dinstrn *
- i_div(dipc, rs, rt, rd, shamt, funct)
- dinstrn *dipc;
- int rs;
- int rt;
- int rd;
- int shamt;
- int funct;
- {
- long s;
- long t;
-
- if (compile_ok)
- {
- dipc->di_handler = c_div;
- dipc->di_0 = &P.p_state[rs];
- dipc->di_1 = &P.p_state[rt];
-
- return (*dipc->di_handler)(dipc);
- }
-
- procsget(rs, s);
-
- procsget(rt, t);
-
- if (t == (long)0)
- notdiv0(dipc);
- else
- {
- procsput(R_LO, s / t);
- procsput(R_HI, s % t);
- }
-
- return dipc;
- }
-
- dinstrn *
- i_divfmt(dipc, fmt, ft, fs, fd)
- dinstrn *dipc;
- int fmt;
- int ft;
- int fs;
- int fd;
- {
- float singles;
- float singlet;
- float singled;
- double doubles;
- double doublet;
- double doubled;
-
- switch (fmt)
- {
- case FMT_SINGLE:
- procsget(CP1G(fs), *(unsigned long *)&singles);
-
- procsget(CP1G(ft), *(unsigned long *)&singlet);
-
- if (singlet == (float)0)
- notdiv0(dipc);
- else
- {
- singled = singles / singlet;
-
- procsput(CP1G(fd), *(unsigned long *)&singled);
- }
-
- break;
-
- case FMT_DOUBLE:
- /*
- * Note apparent reversal of words within
- * doubles here -- no idea why.
- */
- procsget(CP1G(fs), *((unsigned long *)&doubles + 1));
-
- procsget(CP1G(fs) + 1, *(unsigned long *)&doubles);
-
- procsget(CP1G(ft), *((unsigned long *)&doublet + 1));
-
- procsget(CP1G(ft) + 1, *(unsigned long *)&doublet);
-
- if (doublet == (double)0)
- notdiv0(dipc);
- else
- {
- doubled = doubles / doublet;
-
- procsput(CP1G(fd), *((unsigned long *)&doubled + 1));
-
- procsput(CP1G(fd) + 1, *(unsigned long *)&doubled);
- }
- break;
-
- default:
- unrecognised(dipc);
- break;
- }
-
- return dipc;
- }
-
- dinstrn *
- i_divu(dipc, rs, rt, rd, shamt, funct)
- dinstrn *dipc;
- int rs;
- int rt;
- int rd;
- int shamt;
- int funct;
- {
- unsigned long s;
- unsigned long t;
-
- procsget(rs, s);
-
- procsget(rt, t);
-
- if (t == (unsigned long)0)
- notdiv0(dipc);
- else
- {
- procsput(R_LO, s / t);
- procsput(R_HI, s % t);
- }
-
- return dipc;
- }
-