mirror of
https://github.com/Interlisp/maiko.git
synced 2026-01-27 12:22:24 +00:00
Combine three small arithmetic opcode implementation files into one
Combines arith2.c ... arith4.c files and their associated header files into new arithops.c/arithopsdefs.h files, and adjusts the CMakeLists.txt, and old-style makefile-tail. Also updates makefile-dos, inlnPS2.h, and inlndos.h to reflect these changes, though these are not used.
This commit is contained in:
93
src/arith3.c
93
src/arith3.c
@@ -1,93 +0,0 @@
|
||||
/* $Id: arith3.c,v 1.3 1999/05/31 23:35:21 sybalsky Exp $ (C) Copyright Venue, All Rights Reserved
|
||||
*/
|
||||
|
||||
/************************************************************************/
|
||||
/* */
|
||||
/* (C) Copyright 1989-95 Venue. All Rights Reserved. */
|
||||
/* Manufactured in the United States of America. */
|
||||
/* */
|
||||
/************************************************************************/
|
||||
|
||||
|
||||
/************************************************************************/
|
||||
/* */
|
||||
/* A R I T H 3 . C */
|
||||
/* */
|
||||
/* Including : OP_makenumber */
|
||||
/* OP_boxiplus */
|
||||
/* OP_boxidiff */
|
||||
/* */
|
||||
/* */
|
||||
/************************************************************************/
|
||||
|
||||
#include "version.h"
|
||||
#include "adr68k.h" // for Addr68k_from_LADDR
|
||||
#include "arith.h" // for N_GETNUMBER, N_ARITH_SWITCH
|
||||
#include "arith3defs.h" // for N_OP_boxidiff, N_OP_boxiplus, N_OP_makenumber
|
||||
#include "lispemul.h" // for state, LispPTR, ERROR_EXIT
|
||||
#include "lispmap.h" // for S_POSITIVE
|
||||
#include "lspglob.h"
|
||||
#include "lsptypes.h" // for GetTypeNumber, TYPE_FIXP
|
||||
|
||||
/************************************************************************/
|
||||
/* */
|
||||
/* N _ O P _ m a k e n u m b e r */
|
||||
/* */
|
||||
/* Given the 2 halves of a FIXP as SMALLP's, create a number */
|
||||
/* box for the number, and fill it in. */
|
||||
/* */
|
||||
/************************************************************************/
|
||||
|
||||
LispPTR N_OP_makenumber(int tosm1, int tos) {
|
||||
register int result;
|
||||
|
||||
if (((tosm1 & 0xFFFF0000) != S_POSITIVE) || ((tos & 0xFFFF0000) != S_POSITIVE)) ERROR_EXIT(tos);
|
||||
/* UB: left shift of 49152 by 16 places cannot be represented in type 'int' */
|
||||
result = ((tosm1 & 0xffff) << 16) | (tos & 0xffff);
|
||||
N_ARITH_SWITCH(result);
|
||||
} /* end OP_makenumber */
|
||||
|
||||
/************************************************************************/
|
||||
/* */
|
||||
/* N _ O P _ b o x i p l u s */
|
||||
/* */
|
||||
/* Given a FIXP box and a number to add to it, add the number, */
|
||||
/* leaving the result in the box given. Used to avoid garbaging. */
|
||||
/* */
|
||||
/************************************************************************/
|
||||
|
||||
LispPTR N_OP_boxiplus(register int a, int tos) {
|
||||
register int arg2;
|
||||
|
||||
if (GetTypeNumber(a) == TYPE_FIXP) {
|
||||
N_GETNUMBER(tos, arg2, bad);
|
||||
*((LispPTR *)Addr68k_from_LADDR(a)) += arg2;
|
||||
return (a);
|
||||
}
|
||||
bad:
|
||||
ERROR_EXIT(tos);
|
||||
|
||||
} /* OP_boxiplus */
|
||||
|
||||
/************************************************************************/
|
||||
/* */
|
||||
/* O P _ b o x i d i f f */
|
||||
/* */
|
||||
/* Given a FIXP box and a number to subtract from it, do the */
|
||||
/* subtraction, and leave the result in the box given. */
|
||||
/* Used to avoid allocating storage in low-level routines. */
|
||||
/* */
|
||||
/************************************************************************/
|
||||
|
||||
LispPTR N_OP_boxidiff(register int a, int tos) {
|
||||
register int arg2;
|
||||
|
||||
if (GetTypeNumber(a) == TYPE_FIXP) {
|
||||
N_GETNUMBER(tos, arg2, bad);
|
||||
*((LispPTR *)Addr68k_from_LADDR(a)) -= arg2;
|
||||
return (a);
|
||||
}
|
||||
bad:
|
||||
ERROR_EXIT(tos);
|
||||
|
||||
} /* end OP_boxidiff */
|
||||
157
src/arith4.c
157
src/arith4.c
@@ -1,157 +0,0 @@
|
||||
/* $Id: arith4.c,v 1.3 1999/05/31 23:35:21 sybalsky Exp $ (C) Copyright Venue, All Rights Reserved
|
||||
*/
|
||||
|
||||
/************************************************************************/
|
||||
/* */
|
||||
/* (C) Copyright 1989-95 Venue. All Rights Reserved. */
|
||||
/* Manufactured in the United States of America. */
|
||||
/* */
|
||||
/************************************************************************/
|
||||
|
||||
/***********************************************************************/
|
||||
/*
|
||||
File Name : arith4.c
|
||||
|
||||
Including : OP_times2 326Q(OP_itimes2 332Q)
|
||||
|
||||
OP_quot 327Q(OP_iquot 333Q)
|
||||
OP_reminder 334Q
|
||||
|
||||
*/
|
||||
/**********************************************************************/
|
||||
#include "version.h"
|
||||
#include "arith.h" // for N_IGETNUMBER, N_ARITH_SWITCH, N_GETNUMBER
|
||||
#include "arith4defs.h" // for N_OP_iquot, N_OP_iremainder, N_OP_itimes2
|
||||
#include "fpdefs.h" // for N_OP_fquotient, N_OP_ftimes2
|
||||
#include "lispemul.h" // for state, ERROR_EXIT, LispPTR
|
||||
#include "lspglob.h"
|
||||
#include "lsptypes.h"
|
||||
|
||||
/**********************************************************************/
|
||||
/*
|
||||
|
||||
Func name : N_OP_times2(itimes2)
|
||||
|
||||
*/
|
||||
/**********************************************************************/
|
||||
LispPTR N_OP_times2(int tosm1, int tos) {
|
||||
int arg1, arg2;
|
||||
int result;
|
||||
|
||||
N_GETNUMBER(tosm1, arg1, doufn);
|
||||
N_GETNUMBER(tos, arg2, doufn);
|
||||
|
||||
#ifdef USE_OVERFLOW_BUILTINS
|
||||
|
||||
if (__builtin_smul_overflow(arg1, arg2, &result)) {
|
||||
goto doufn2;
|
||||
}
|
||||
N_ARITH_SWITCH(result);
|
||||
|
||||
#else
|
||||
|
||||
result = arg1 * arg2;
|
||||
if ((arg2 != 0) && ((result / arg2) != arg1)) goto doufn2;
|
||||
N_ARITH_SWITCH(result);
|
||||
|
||||
#endif
|
||||
|
||||
doufn2:
|
||||
ERROR_EXIT(tos);
|
||||
doufn:
|
||||
return (N_OP_ftimes2(tosm1, tos));
|
||||
|
||||
} /* end N_OP_times2 */
|
||||
|
||||
LispPTR N_OP_itimes2(int tosm1, int tos) {
|
||||
int arg1, arg2;
|
||||
int result;
|
||||
|
||||
N_IGETNUMBER(tosm1, arg1, doufn);
|
||||
N_IGETNUMBER(tos, arg2, doufn);
|
||||
|
||||
#ifdef USE_OVERFLOW_BUILTINS
|
||||
|
||||
if (__builtin_smul_overflow(arg1, arg2, &result)) {
|
||||
goto doufn;
|
||||
}
|
||||
N_ARITH_SWITCH(result);
|
||||
|
||||
#else
|
||||
|
||||
/* UB: signed integer overflow: 1073741824 * 32768 cannot be represented in type 'int' */
|
||||
result = arg1 * arg2;
|
||||
if ((arg2 != 0) && ((result / arg2) != arg1)) { goto doufn; }
|
||||
N_ARITH_SWITCH(result);
|
||||
|
||||
#endif
|
||||
|
||||
doufn:
|
||||
ERROR_EXIT(tos);
|
||||
|
||||
} /* end N_OP_itimes2 */
|
||||
|
||||
/**********************************************************************/
|
||||
/*
|
||||
|
||||
Func name : N_OP_quot(iquot)
|
||||
|
||||
*/
|
||||
/**********************************************************************/
|
||||
LispPTR N_OP_quot(int tosm1, int tos) {
|
||||
int arg1, arg2;
|
||||
int result;
|
||||
|
||||
N_GETNUMBER(tosm1, arg1, doufn);
|
||||
N_GETNUMBER(tos, arg2, doufn);
|
||||
if (arg2 == 0) goto doufn2;
|
||||
|
||||
result = arg1 / arg2; /* lmm: note: no error case!! */
|
||||
N_ARITH_SWITCH(result);
|
||||
|
||||
doufn2:
|
||||
ERROR_EXIT(tos);
|
||||
doufn:
|
||||
return (N_OP_fquotient(tosm1, tos));
|
||||
|
||||
} /* end N_OP_quot */
|
||||
|
||||
LispPTR N_OP_iquot(int tosm1, int tos) {
|
||||
register int arg1, arg2;
|
||||
register int result;
|
||||
|
||||
N_IGETNUMBER(tosm1, arg1, doufn);
|
||||
N_IGETNUMBER(tos, arg2, doufn);
|
||||
if (arg2 == 0) goto doufn;
|
||||
|
||||
result = arg1 / arg2;
|
||||
N_ARITH_SWITCH(result);
|
||||
|
||||
doufn:
|
||||
ERROR_EXIT(tos);
|
||||
|
||||
} /* end N_OP_quot */
|
||||
|
||||
/**********************************************************************/
|
||||
/*
|
||||
|
||||
Func name : N_OP_iremainder
|
||||
|
||||
*/
|
||||
/**********************************************************************/
|
||||
|
||||
LispPTR N_OP_iremainder(int tosm1, int tos) {
|
||||
register int arg1, arg2;
|
||||
register int result;
|
||||
|
||||
N_IGETNUMBER(tosm1, arg1, doufn);
|
||||
N_IGETNUMBER(tos, arg2, doufn);
|
||||
if (arg2 == 0) goto doufn;
|
||||
|
||||
result = arg1 % arg2;
|
||||
N_ARITH_SWITCH(result);
|
||||
|
||||
doufn:
|
||||
ERROR_EXIT(tos);
|
||||
|
||||
} /* end N_OP_iremainder */
|
||||
@@ -1,18 +1,18 @@
|
||||
/* $Id: arith2.c,v 1.4 2001/12/24 01:08:58 sybalsky Exp $ (C) Copyright Venue, All Rights Reserved
|
||||
*/
|
||||
|
||||
/************************************************************************/
|
||||
/* */
|
||||
/* (C) Copyright 1989-99 Venue. All Rights Reserved. */
|
||||
/* (C) Copyright 1989-95 Venue. All Rights Reserved. */
|
||||
/* Manufactured in the United States of America. */
|
||||
/* */
|
||||
/************************************************************************/
|
||||
|
||||
#include "version.h"
|
||||
|
||||
#include "adr68k.h" // for Addr68k_from_LADDR
|
||||
#include "arith.h" // for N_IGETNUMBER, N_ARITH_SWITCH, N_GETNUMBER
|
||||
#include "arith2defs.h" // for N_OP_difference, N_OP_greaterp, N_OP_idiffer...
|
||||
#include "arithopsdefs.h" // for N_OP_difference, N_OP_greaterp, N_OP_idiffer...
|
||||
#include "fpdefs.h" // for N_OP_fdifference, N_OP_fgreaterp, N_OP_fplus2
|
||||
#include "lispemul.h" // for state, ERROR_EXIT, LispPTR, ATOM_T, NIL_PTR
|
||||
#include "lispmap.h" // for S_POSITIVE
|
||||
#include "lspglob.h"
|
||||
#include "lsptypes.h"
|
||||
|
||||
@@ -150,21 +150,57 @@ N_OP_logxor
|
||||
return(tosm1 ^ tos)
|
||||
************************************************************/
|
||||
|
||||
LispPTR N_OP_logxor(int tosm1, int tos) { N_IARITH_BODY_2(tosm1, tos, ^); }
|
||||
LispPTR N_OP_logxor(int tosm1, int tos) {
|
||||
int arg1, arg2;
|
||||
|
||||
N_IGETNUMBER(tosm1, arg1, do_ufn);
|
||||
N_IGETNUMBER(tos, arg2, do_ufn);
|
||||
|
||||
arg1 = arg1 ^ arg2;
|
||||
|
||||
N_ARITH_SWITCH(arg1);
|
||||
|
||||
do_ufn:
|
||||
ERROR_EXIT(tos);
|
||||
}
|
||||
|
||||
/************************************************************
|
||||
N_OP_logand
|
||||
entry LOGAND2 OPCODE[0345]
|
||||
return(tosm1 & tos)
|
||||
************************************************************/
|
||||
LispPTR N_OP_logand(int tosm1, int tos) { N_IARITH_BODY_2(tosm1, tos, &); }
|
||||
LispPTR N_OP_logand(int tosm1, int tos) {
|
||||
int arg1, arg2;
|
||||
|
||||
N_IGETNUMBER(tosm1, arg1, do_ufn);
|
||||
N_IGETNUMBER(tos, arg2, do_ufn);
|
||||
|
||||
arg1 = arg1 & arg2;
|
||||
|
||||
N_ARITH_SWITCH(arg1);
|
||||
|
||||
do_ufn:
|
||||
ERROR_EXIT(tos);
|
||||
}
|
||||
|
||||
/************************************************************
|
||||
N_OP_logor
|
||||
entry LOGOR2 OPCODE[0344]
|
||||
return(tosm1 | tos)
|
||||
************************************************************/
|
||||
LispPTR N_OP_logor(int tosm1, int tos) { N_IARITH_BODY_2(tosm1, tos, |); }
|
||||
LispPTR N_OP_logor(int tosm1, int tos) {
|
||||
int arg1, arg2;
|
||||
|
||||
N_IGETNUMBER(tosm1, arg1, do_ufn);
|
||||
N_IGETNUMBER(tos, arg2, do_ufn);
|
||||
|
||||
arg1 = arg1 | arg2;
|
||||
|
||||
N_ARITH_SWITCH(arg1);
|
||||
|
||||
do_ufn:
|
||||
ERROR_EXIT(tos);
|
||||
}
|
||||
|
||||
/************************************************************
|
||||
N_OP_greaterp
|
||||
@@ -174,7 +210,7 @@ N_OP_greaterp
|
||||
|
||||
************************************************************/
|
||||
LispPTR N_OP_greaterp(int tosm1, int tos) {
|
||||
register int arg1, arg2;
|
||||
int arg1, arg2;
|
||||
|
||||
N_GETNUMBER(tosm1, arg1, do_ufn);
|
||||
N_GETNUMBER(tos, arg2, do_ufn);
|
||||
@@ -189,7 +225,7 @@ do_ufn:
|
||||
}
|
||||
|
||||
LispPTR N_OP_igreaterp(int tosm1, int tos) {
|
||||
register int arg1, arg2;
|
||||
int arg1, arg2;
|
||||
|
||||
N_IGETNUMBER(tosm1, arg1, do_ufn);
|
||||
N_IGETNUMBER(tos, arg2, do_ufn);
|
||||
@@ -262,3 +298,195 @@ LispPTR N_OP_idifferencen(int tos, int n) {
|
||||
do_ufn:
|
||||
ERROR_EXIT(tos);
|
||||
}
|
||||
|
||||
/************************************************************************/
|
||||
/* */
|
||||
/* N _ O P _ m a k e n u m b e r */
|
||||
/* */
|
||||
/* Given the 2 halves of a FIXP as SMALLP's, create a number */
|
||||
/* box for the number, and fill it in. */
|
||||
/* */
|
||||
/************************************************************************/
|
||||
|
||||
LispPTR N_OP_makenumber(int tosm1, int tos) {
|
||||
int result;
|
||||
|
||||
if (((tosm1 & 0xFFFF0000) != S_POSITIVE) || ((tos & 0xFFFF0000) != S_POSITIVE)) ERROR_EXIT(tos);
|
||||
/* UB: left shift of 49152 by 16 places cannot be represented in type 'int' */
|
||||
result = ((tosm1 & 0xffff) << 16) | (tos & 0xffff);
|
||||
N_ARITH_SWITCH(result);
|
||||
} /* end OP_makenumber */
|
||||
|
||||
/************************************************************************/
|
||||
/* */
|
||||
/* N _ O P _ b o x i p l u s */
|
||||
/* */
|
||||
/* Given a FIXP box and a number to add to it, add the number, */
|
||||
/* leaving the result in the box given. Used to avoid garbaging. */
|
||||
/* */
|
||||
/************************************************************************/
|
||||
|
||||
LispPTR N_OP_boxiplus(int a, int tos) {
|
||||
int arg2;
|
||||
|
||||
if (GetTypeNumber(a) == TYPE_FIXP) {
|
||||
N_GETNUMBER(tos, arg2, bad);
|
||||
*((LispPTR *)Addr68k_from_LADDR(a)) += arg2;
|
||||
return (a);
|
||||
}
|
||||
bad:
|
||||
ERROR_EXIT(tos);
|
||||
|
||||
} /* OP_boxiplus */
|
||||
|
||||
/************************************************************************/
|
||||
/* */
|
||||
/* O P _ b o x i d i f f */
|
||||
/* */
|
||||
/* Given a FIXP box and a number to subtract from it, do the */
|
||||
/* subtraction, and leave the result in the box given. */
|
||||
/* Used to avoid allocating storage in low-level routines. */
|
||||
/* */
|
||||
/************************************************************************/
|
||||
|
||||
LispPTR N_OP_boxidiff(int a, int tos) {
|
||||
int arg2;
|
||||
|
||||
if (GetTypeNumber(a) == TYPE_FIXP) {
|
||||
N_GETNUMBER(tos, arg2, bad);
|
||||
*((LispPTR *)Addr68k_from_LADDR(a)) -= arg2;
|
||||
return (a);
|
||||
}
|
||||
bad:
|
||||
ERROR_EXIT(tos);
|
||||
|
||||
} /* end OP_boxidiff */
|
||||
|
||||
/**********************************************************************/
|
||||
/*
|
||||
|
||||
Func name : N_OP_times2
|
||||
|
||||
*/
|
||||
/**********************************************************************/
|
||||
LispPTR N_OP_times2(int tosm1, int tos) {
|
||||
int arg1, arg2;
|
||||
int result;
|
||||
|
||||
N_GETNUMBER(tosm1, arg1, doufn);
|
||||
N_GETNUMBER(tos, arg2, doufn);
|
||||
|
||||
#ifdef USE_OVERFLOW_BUILTINS
|
||||
|
||||
if (__builtin_smul_overflow(arg1, arg2, &result)) {
|
||||
goto doufn2;
|
||||
}
|
||||
N_ARITH_SWITCH(result);
|
||||
|
||||
#else
|
||||
|
||||
result = arg1 * arg2;
|
||||
if ((arg2 != 0) && ((result / arg2) != arg1)) goto doufn2;
|
||||
N_ARITH_SWITCH(result);
|
||||
|
||||
#endif
|
||||
|
||||
doufn2:
|
||||
ERROR_EXIT(tos);
|
||||
doufn:
|
||||
return (N_OP_ftimes2(tosm1, tos));
|
||||
|
||||
} /* end N_OP_times2 */
|
||||
|
||||
LispPTR N_OP_itimes2(int tosm1, int tos) {
|
||||
int arg1, arg2;
|
||||
int result;
|
||||
|
||||
N_IGETNUMBER(tosm1, arg1, doufn);
|
||||
N_IGETNUMBER(tos, arg2, doufn);
|
||||
|
||||
#ifdef USE_OVERFLOW_BUILTINS
|
||||
|
||||
if (__builtin_smul_overflow(arg1, arg2, &result)) {
|
||||
goto doufn;
|
||||
}
|
||||
N_ARITH_SWITCH(result);
|
||||
|
||||
#else
|
||||
|
||||
/* UB: signed integer overflow: 1073741824 * 32768 cannot be represented in type 'int' */
|
||||
result = arg1 * arg2;
|
||||
if ((arg2 != 0) && ((result / arg2) != arg1)) { goto doufn; }
|
||||
N_ARITH_SWITCH(result);
|
||||
|
||||
#endif
|
||||
|
||||
doufn:
|
||||
ERROR_EXIT(tos);
|
||||
|
||||
} /* end N_OP_itimes2 */
|
||||
|
||||
/**********************************************************************/
|
||||
/*
|
||||
|
||||
Func name : N_OP_quot(iquot)
|
||||
|
||||
*/
|
||||
/**********************************************************************/
|
||||
LispPTR N_OP_quot(int tosm1, int tos) {
|
||||
int arg1, arg2;
|
||||
int result;
|
||||
|
||||
N_GETNUMBER(tosm1, arg1, doufn);
|
||||
N_GETNUMBER(tos, arg2, doufn);
|
||||
if (arg2 == 0) goto doufn2;
|
||||
|
||||
result = arg1 / arg2; /* lmm: note: no error case!! */
|
||||
N_ARITH_SWITCH(result);
|
||||
|
||||
doufn2:
|
||||
ERROR_EXIT(tos);
|
||||
doufn:
|
||||
return (N_OP_fquotient(tosm1, tos));
|
||||
|
||||
} /* end N_OP_quot */
|
||||
|
||||
LispPTR N_OP_iquot(int tosm1, int tos) {
|
||||
int arg1, arg2;
|
||||
int result;
|
||||
|
||||
N_IGETNUMBER(tosm1, arg1, doufn);
|
||||
N_IGETNUMBER(tos, arg2, doufn);
|
||||
if (arg2 == 0) goto doufn;
|
||||
|
||||
result = arg1 / arg2;
|
||||
N_ARITH_SWITCH(result);
|
||||
|
||||
doufn:
|
||||
ERROR_EXIT(tos);
|
||||
|
||||
} /* end N_OP_quot */
|
||||
|
||||
/**********************************************************************/
|
||||
/*
|
||||
|
||||
Func name : N_OP_iremainder
|
||||
|
||||
*/
|
||||
/**********************************************************************/
|
||||
|
||||
LispPTR N_OP_iremainder(int tosm1, int tos) {
|
||||
int arg1, arg2;
|
||||
int result;
|
||||
|
||||
N_IGETNUMBER(tosm1, arg1, doufn);
|
||||
N_IGETNUMBER(tos, arg2, doufn);
|
||||
if (arg2 == 0) goto doufn;
|
||||
|
||||
result = arg1 % arg2;
|
||||
N_ARITH_SWITCH(result);
|
||||
|
||||
doufn:
|
||||
ERROR_EXIT(tos);
|
||||
|
||||
} /* end N_OP_iremainder */
|
||||
Reference in New Issue
Block a user