1988-06-22 16:57:09 +00:00
|
|
|
/*
|
|
|
|
* Sources of the "UNSIGNED 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"
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* No checking is performed, except for division by zero. *
|
|
|
|
* The operands popped from the stack are put in unsigned *
|
|
|
|
* longs. Now the required operation can be performed *
|
|
|
|
* immediately. Whether the wordsize is two or four bytes *
|
|
|
|
* doesn't matter. Alas, arithmetic is performed modulo *
|
|
|
|
* the highest unsigned number for the given size plus 1. *
|
|
|
|
************************************************************************/
|
|
|
|
|
|
|
|
#ifdef LOGGING
|
|
|
|
extern int must_test;
|
1991-12-17 15:28:58 +00:00
|
|
|
#endif /* LOGGING */
|
1988-06-22 16:57:09 +00:00
|
|
|
|
|
|
|
#define adu(w1,w2) (unsigned long)(w1 + w2)
|
|
|
|
#define sbu(w1,w2) (unsigned long)(w1 - w2)
|
|
|
|
#define mlu(w1,w2) (unsigned long)(w1 * w2)
|
|
|
|
|
|
|
|
PRIVATE unsigned long dvu(), rmu(), slu(), sru();
|
|
|
|
|
1990-06-21 12:16:31 +00:00
|
|
|
DoADU(l)
|
|
|
|
register size l;
|
1988-06-22 16:57:09 +00:00
|
|
|
{
|
|
|
|
/* ADU w: Addition */
|
|
|
|
register unsigned long t = upop(arg_wi(l));
|
|
|
|
|
1990-06-21 12:16:31 +00:00
|
|
|
LOG(("@U6 DoADU(%ld)", l));
|
1988-06-22 16:57:09 +00:00
|
|
|
spoilFRA();
|
|
|
|
npush((long) adu(upop(l), t), l);
|
|
|
|
}
|
|
|
|
|
1990-06-21 12:16:31 +00:00
|
|
|
DoSBU(l)
|
|
|
|
register size l;
|
1988-06-22 16:57:09 +00:00
|
|
|
{
|
|
|
|
/* SBU w: Subtraction */
|
|
|
|
register unsigned long t = upop(arg_wi(l));
|
|
|
|
|
1990-06-21 12:16:31 +00:00
|
|
|
LOG(("@U6 DoSBU(%ld)", l));
|
1988-06-22 16:57:09 +00:00
|
|
|
spoilFRA();
|
|
|
|
npush((long) sbu(upop(l), t), l);
|
|
|
|
}
|
|
|
|
|
1990-06-21 12:16:31 +00:00
|
|
|
DoMLU(l)
|
|
|
|
register size l;
|
1988-06-22 16:57:09 +00:00
|
|
|
{
|
|
|
|
/* MLU w: Multiplication */
|
|
|
|
register unsigned long t = upop(arg_wi(l));
|
|
|
|
|
1990-06-21 12:16:31 +00:00
|
|
|
LOG(("@U6 DoMLU(%ld)", l));
|
1988-06-22 16:57:09 +00:00
|
|
|
spoilFRA();
|
|
|
|
npush((long) mlu(upop(l), t), l);
|
|
|
|
}
|
|
|
|
|
1990-06-21 12:16:31 +00:00
|
|
|
DoDVU(l)
|
|
|
|
register size l;
|
1988-06-22 16:57:09 +00:00
|
|
|
{
|
|
|
|
/* DVU w: Division */
|
|
|
|
register unsigned long t = upop(arg_wi(l));
|
|
|
|
|
1990-06-21 12:16:31 +00:00
|
|
|
LOG(("@U6 DoDVU(%ld)", l));
|
1988-06-22 16:57:09 +00:00
|
|
|
spoilFRA();
|
|
|
|
npush((long) dvu(upop(l), t), l);
|
|
|
|
}
|
|
|
|
|
1990-06-21 12:16:31 +00:00
|
|
|
DoRMU(l)
|
|
|
|
register size l;
|
1988-06-22 16:57:09 +00:00
|
|
|
{
|
|
|
|
/* RMU w: Remainder */
|
|
|
|
register unsigned long t = upop(arg_wi(l));
|
|
|
|
|
1990-06-21 12:16:31 +00:00
|
|
|
LOG(("@U6 DoRMU(%ld)", l));
|
1988-06-22 16:57:09 +00:00
|
|
|
spoilFRA();
|
|
|
|
npush((long) rmu(upop(l), t), l);
|
|
|
|
}
|
|
|
|
|
1990-06-21 12:16:31 +00:00
|
|
|
DoSLU(l)
|
|
|
|
register size l;
|
1988-06-22 16:57:09 +00:00
|
|
|
{
|
|
|
|
/* SLU w: Shift left */
|
1989-11-22 13:38:37 +00:00
|
|
|
register unsigned long t = uwpop();
|
1988-06-22 16:57:09 +00:00
|
|
|
|
1990-06-21 12:16:31 +00:00
|
|
|
LOG(("@U6 DoSLU(%ld)", l));
|
1988-06-22 16:57:09 +00:00
|
|
|
spoilFRA();
|
|
|
|
l = arg_wi(l);
|
|
|
|
npush((long) slu(upop(l), t, l), l);
|
|
|
|
}
|
|
|
|
|
1990-06-21 12:16:31 +00:00
|
|
|
DoSRU(l)
|
|
|
|
register size l;
|
1988-06-22 16:57:09 +00:00
|
|
|
{
|
|
|
|
/* SRU w: Shift right */
|
1989-11-22 13:38:37 +00:00
|
|
|
register unsigned long t = uwpop();
|
1988-06-22 16:57:09 +00:00
|
|
|
|
1990-06-21 12:16:31 +00:00
|
|
|
LOG(("@U6 DoSRU(%ld)", l));
|
1988-06-22 16:57:09 +00:00
|
|
|
spoilFRA();
|
|
|
|
l = arg_wi(l);
|
|
|
|
npush((long) sru(upop(l), t, l), l);
|
|
|
|
}
|
|
|
|
|
|
|
|
PRIVATE unsigned long dvu(w1, w2)
|
|
|
|
unsigned long w1, w2;
|
|
|
|
{
|
|
|
|
if (w2 == 0) {
|
|
|
|
if (!(IgnMask&BIT(EIDIVZ))) {
|
|
|
|
trap(EIDIVZ);
|
|
|
|
}
|
|
|
|
else return (0L);
|
|
|
|
}
|
|
|
|
return (w1 / w2);
|
|
|
|
}
|
|
|
|
|
|
|
|
PRIVATE unsigned long rmu(w1, w2)
|
|
|
|
unsigned long w1, w2;
|
|
|
|
{
|
|
|
|
if (w2 == 0) {
|
|
|
|
if (!(IgnMask&BIT(EIDIVZ))) {
|
|
|
|
trap(EIDIVZ);
|
|
|
|
}
|
|
|
|
else return (0L);
|
|
|
|
}
|
|
|
|
return (w1 % w2);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
PRIVATE unsigned long slu(w1, w2, nbytes) /* w1 << w2 */
|
|
|
|
unsigned long w1, w2;
|
|
|
|
size nbytes;
|
|
|
|
{
|
|
|
|
#ifdef LOGGING
|
|
|
|
if (must_test) {
|
|
|
|
/* check shift distance */
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
PRIVATE unsigned long sru(w1, w2, nbytes) /* w1 >> w2 */
|
|
|
|
unsigned long w1, w2;
|
|
|
|
size nbytes;
|
|
|
|
{
|
|
|
|
#ifdef LOGGING
|
|
|
|
if (must_test) {
|
|
|
|
/* check shift distance */
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|