1988-06-22 16:57:09 +00:00
|
|
|
/*
|
|
|
|
* Sources of the "INTEGER ARITHMETIC" group instructions
|
|
|
|
*/
|
|
|
|
|
1994-06-24 11:31:16 +00:00
|
|
|
/* $Id$ */
|
1988-06-22 16:57:09 +00:00
|
|
|
|
|
|
|
#include <em_abs.h>
|
|
|
|
#include "logging.h"
|
|
|
|
#include "global.h"
|
|
|
|
#include "log.h"
|
|
|
|
#include "mem.h"
|
|
|
|
#include "trap.h"
|
|
|
|
#include "warn.h"
|
|
|
|
#include "text.h"
|
|
|
|
#include "fra.h"
|
|
|
|
|
|
|
|
PRIVATE long adi(), sbi(), dvi(), mli(), rmi(), ngi(), sli(), sri();
|
|
|
|
|
1990-06-21 12:16:31 +00:00
|
|
|
DoADI(l)
|
|
|
|
register size l;
|
1988-06-22 16:57:09 +00:00
|
|
|
{
|
|
|
|
/* ADI w: Addition (*) */
|
|
|
|
register long t = spop(arg_wi(l));
|
|
|
|
|
1990-06-21 12:16:31 +00:00
|
|
|
LOG(("@I6 DoADI(%ld)", l));
|
1988-06-22 16:57:09 +00:00
|
|
|
spoilFRA();
|
|
|
|
npush(adi(spop(l), t, l), l);
|
|
|
|
}
|
|
|
|
|
1990-06-21 12:16:31 +00:00
|
|
|
DoSBI(l)
|
|
|
|
register size l;
|
1988-06-22 16:57:09 +00:00
|
|
|
{
|
|
|
|
/* SBI w: Subtraction (*) */
|
|
|
|
register long t = spop(arg_wi(l));
|
|
|
|
|
1990-06-21 12:16:31 +00:00
|
|
|
LOG(("@I6 DoSBI(%ld)", l));
|
1988-06-22 16:57:09 +00:00
|
|
|
spoilFRA();
|
|
|
|
npush(sbi(spop(l), t, l), l);
|
|
|
|
}
|
|
|
|
|
1990-06-21 12:16:31 +00:00
|
|
|
DoMLI(l)
|
|
|
|
register size l;
|
1988-06-22 16:57:09 +00:00
|
|
|
{
|
|
|
|
/* MLI w: Multiplication (*) */
|
|
|
|
register long t = spop(arg_wi(l));
|
|
|
|
|
1990-06-21 12:16:31 +00:00
|
|
|
LOG(("@I6 DoMLI(%ld)", l));
|
1988-06-22 16:57:09 +00:00
|
|
|
spoilFRA();
|
|
|
|
npush(mli(spop(l), t, l), l);
|
|
|
|
}
|
|
|
|
|
1990-06-21 12:16:31 +00:00
|
|
|
DoDVI(l)
|
|
|
|
register size l;
|
1988-06-22 16:57:09 +00:00
|
|
|
{
|
|
|
|
/* DVI w: Division (*) */
|
|
|
|
register long t = spop(arg_wi(l));
|
|
|
|
|
1990-06-21 12:16:31 +00:00
|
|
|
LOG(("@I6 DoDVI(%ld)", l));
|
1988-06-22 16:57:09 +00:00
|
|
|
spoilFRA();
|
|
|
|
npush(dvi(spop(l), t), l);
|
|
|
|
}
|
|
|
|
|
1990-06-21 12:16:31 +00:00
|
|
|
DoRMI(l)
|
|
|
|
register size l;
|
1988-06-22 16:57:09 +00:00
|
|
|
{
|
|
|
|
/* RMI w: Remainder (*) */
|
|
|
|
register long t = spop(arg_wi(l));
|
|
|
|
|
1990-06-21 12:16:31 +00:00
|
|
|
LOG(("@I6 DoRMI(%ld)", l));
|
1988-06-22 16:57:09 +00:00
|
|
|
spoilFRA();
|
|
|
|
npush(rmi(spop(l), t), l);
|
|
|
|
}
|
|
|
|
|
1990-06-21 12:16:31 +00:00
|
|
|
DoNGI(l)
|
|
|
|
register size l;
|
1988-06-22 16:57:09 +00:00
|
|
|
{
|
|
|
|
/* NGI w: Negate (two's complement) (*) */
|
|
|
|
|
1990-06-21 12:16:31 +00:00
|
|
|
LOG(("@I6 DoNGI(%ld)", l));
|
1988-06-22 16:57:09 +00:00
|
|
|
spoilFRA();
|
|
|
|
l = arg_wi(l);
|
|
|
|
npush(ngi(spop(l), l), l);
|
|
|
|
}
|
|
|
|
|
1990-06-21 12:16:31 +00:00
|
|
|
DoSLI(l)
|
|
|
|
register size l;
|
1988-06-22 16:57:09 +00:00
|
|
|
{
|
|
|
|
/* SLI w: Shift left (*) */
|
1989-11-22 13:38:37 +00:00
|
|
|
register long t = swpop();
|
1988-06-22 16:57:09 +00:00
|
|
|
|
1990-06-21 12:16:31 +00:00
|
|
|
LOG(("@I6 DoSLI(%ld)", l));
|
1988-06-22 16:57:09 +00:00
|
|
|
spoilFRA();
|
|
|
|
l = arg_wi(l);
|
|
|
|
npush(sli(spop(l), t, l), l);
|
|
|
|
}
|
|
|
|
|
1990-06-21 12:16:31 +00:00
|
|
|
DoSRI(l)
|
|
|
|
register size l;
|
1988-06-22 16:57:09 +00:00
|
|
|
{
|
|
|
|
/* SRI w: Shift right (*) */
|
1989-11-22 13:38:37 +00:00
|
|
|
register long t = swpop();
|
1988-06-22 16:57:09 +00:00
|
|
|
|
1990-06-21 12:16:31 +00:00
|
|
|
LOG(("@I6 DoSRI(%ld)", l));
|
1988-06-22 16:57:09 +00:00
|
|
|
spoilFRA();
|
|
|
|
l = arg_wi(l);
|
|
|
|
npush(sri(spop(l), t, l), l);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define i_maxs(n) ((n == 2) ? I_MAXS2 : I_MAXS4)
|
|
|
|
#define i_mins(n) ((n == 2) ? I_MINS2 : I_MINS4)
|
|
|
|
|
|
|
|
PRIVATE long adi(w1, w2, nbytes) /* returns w1 + w2 */
|
|
|
|
long w1, w2;
|
|
|
|
size nbytes;
|
|
|
|
{
|
|
|
|
if (must_test && !(IgnMask&BIT(EIOVFL))) {
|
|
|
|
if (w1 > 0 && w2 > 0) {
|
|
|
|
if (i_maxs(nbytes) - w1 < w2)
|
|
|
|
trap(EIOVFL);
|
|
|
|
}
|
|
|
|
else if (w1 < 0 && w2 < 0) {
|
|
|
|
if (i_mins(nbytes) - w1 > w2)
|
|
|
|
trap(EIOVFL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (w1 + w2);
|
|
|
|
}
|
|
|
|
|
|
|
|
PRIVATE long sbi(w1, w2, nbytes) /* returns w1 - w2 */
|
|
|
|
long w1, w2;
|
|
|
|
size nbytes;
|
|
|
|
{
|
|
|
|
if (must_test && !(IgnMask&BIT(EIOVFL))) {
|
|
|
|
if (w2 < 0 && w1 > 0) {
|
|
|
|
if (i_maxs(nbytes) + w2 < w1)
|
|
|
|
trap(EIOVFL);
|
|
|
|
}
|
|
|
|
else if (w2 > 0 && w1 < 0) {
|
|
|
|
if (i_mins(nbytes) + w2 > w1) {
|
|
|
|
trap(EIOVFL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (w1 - w2);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define labs(w) ((w < 0) ? (-w) : w)
|
|
|
|
|
|
|
|
PRIVATE long mli(w1, w2, nbytes) /* returns w1 * w2 */
|
|
|
|
long w1, w2;
|
|
|
|
size nbytes;
|
|
|
|
{
|
|
|
|
if (w1 == 0 || w2 == 0)
|
|
|
|
return (0L);
|
|
|
|
|
|
|
|
if (must_test && !(IgnMask&BIT(EIOVFL))) {
|
|
|
|
if ((w1 > 0 && w2 > 0) || (w2 < 0 && w1 < 0)) {
|
|
|
|
if ( w1 == i_mins(nbytes) || w2 == i_mins(nbytes)
|
|
|
|
|| (i_maxs(nbytes) / labs(w1)) < labs(w2)
|
|
|
|
) {
|
|
|
|
trap(EIOVFL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (w1 > 0) {
|
|
|
|
if (i_mins(nbytes) / w1 > w2)
|
|
|
|
trap(EIOVFL);
|
|
|
|
}
|
|
|
|
else if (i_mins(nbytes) / w2 > w1) {
|
|
|
|
trap(EIOVFL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (w1 * w2);
|
|
|
|
}
|
|
|
|
|
|
|
|
PRIVATE long dvi(w1, w2)
|
|
|
|
long w1, w2;
|
|
|
|
{
|
|
|
|
if (w2 == 0) {
|
|
|
|
if (!(IgnMask&BIT(EIDIVZ))) {
|
|
|
|
trap(EIDIVZ);
|
|
|
|
}
|
|
|
|
else return (0L);
|
|
|
|
}
|
|
|
|
return (w1 / w2);
|
|
|
|
}
|
|
|
|
|
|
|
|
PRIVATE long rmi(w1, w2)
|
|
|
|
long w1, w2;
|
|
|
|
{
|
|
|
|
if (w2 == 0) {
|
|
|
|
if (!(IgnMask&BIT(EIDIVZ))) {
|
|
|
|
trap(EIDIVZ);
|
|
|
|
}
|
|
|
|
else return (0L);
|
|
|
|
}
|
|
|
|
return (w1 % w2);
|
|
|
|
}
|
|
|
|
|
|
|
|
PRIVATE long ngi(w1, nbytes)
|
|
|
|
long w1;
|
|
|
|
size nbytes;
|
|
|
|
{
|
|
|
|
if (must_test && !(IgnMask&BIT(EIOVFL))) {
|
|
|
|
if (w1 == i_mins(nbytes)) {
|
|
|
|
trap(EIOVFL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (-w1);
|
|
|
|
}
|
|
|
|
|
|
|
|
PRIVATE long sli(w1, w2, nbytes) /* w1 << w2 */
|
|
|
|
long w1, w2;
|
|
|
|
size nbytes;
|
|
|
|
{
|
|
|
|
if (must_test) {
|
|
|
|
#ifdef LOGGING
|
|
|
|
/* check shift distance */
|
|
|
|
if (w2 < 0) {
|
|
|
|
warning(WSHNEG);
|
|
|
|
w2 = 0;
|
|
|
|
}
|
|
|
|
if (w2 >= nbytes*8) {
|
|
|
|
warning(WSHLARGE);
|
|
|
|
w2 = nbytes*8 - 1;
|
|
|
|
}
|
1991-12-17 15:28:58 +00:00
|
|
|
#endif /* LOGGING */
|
1988-06-22 16:57:09 +00:00
|
|
|
|
|
|
|
if (!(IgnMask&BIT(EIOVFL))) {
|
|
|
|
/* check overflow */
|
|
|
|
if ( (w1 >= 0 && (w1 >> (nbytes*8 - w2)) != 0)
|
|
|
|
|| (w1 < 0 && (w1 >> (nbytes*8 - w2)) != -1)
|
|
|
|
) {
|
|
|
|
trap(EIOVFL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* calculate result */
|
|
|
|
return (w1 << w2);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
PRIVATE long sri(w1, w2, nbytes) /* w1 >> w2 */
|
|
|
|
long w1, w2;
|
|
|
|
size nbytes;
|
|
|
|
{
|
|
|
|
#ifdef LOGGING
|
|
|
|
if (must_test) {
|
|
|
|
/* check shift distance */
|
|
|
|
if (w2 < 0) {
|
|
|
|
warning(WSHNEG);
|
|
|
|
w2 = 0;
|
|
|
|
}
|
|
|
|
if (w2 >= nbytes*8) {
|
|
|
|
warning(WSHLARGE);
|
|
|
|
w2 = nbytes*8 - 1;
|
|
|
|
}
|
|
|
|
}
|
1991-12-17 15:28:58 +00:00
|
|
|
#endif /* LOGGING */
|
1988-06-22 16:57:09 +00:00
|
|
|
|
|
|
|
/* calculate result */
|
|
|
|
return (w1 >> w2);
|
|
|
|
}
|
|
|
|
|