mirror of
https://github.com/Interlisp/maiko.git
synced 2026-01-19 09:18:33 +00:00
* arithmetic opcode implementations should return LispPTR rather than int * all callers of ERROR_EXIT() have return type LispPTR, therefore ERROR_EXIT should too * N_[I]GETNUMBER, [N_]ARITH_SWITCH need (int) casts for some large constants that would otherwise be unsigned * Expand use of macro N_ARITH_BODY_1_UNSIGNED and correct types * Remove unused macros N_ARITH_BODY_1 and N_ARITH_BODY_1_UNSIGNED * Cast to correct type for storing to TopOfStack, and return type of TIMER_EXIT()
167 lines
3.6 KiB
C
167 lines
3.6 KiB
C
/* $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. */
|
|
/* */
|
|
/************************************************************************/
|
|
|
|
#include "version.h"
|
|
|
|
/***********************************************************************/
|
|
/*
|
|
File Name : arith4.c
|
|
|
|
Including : OP_times2 326Q(OP_itimes2 332Q)
|
|
|
|
OP_quot 327Q(OP_iquot 333Q)
|
|
OP_reminder 334Q
|
|
|
|
*/
|
|
/**********************************************************************/
|
|
|
|
#include "lispemul.h"
|
|
#include "lispmap.h"
|
|
#include "lspglob.h"
|
|
#include "lsptypes.h"
|
|
#include "address.h"
|
|
#include "adr68k.h"
|
|
#include "cell.h"
|
|
#include "medleyfp.h"
|
|
#include "arith.h"
|
|
|
|
#include "arith4defs.h"
|
|
#include "fpdefs.h"
|
|
#include "mkcelldefs.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 */
|