1
0
mirror of https://github.com/Interlisp/maiko.git synced 2026-02-16 12:43:12 +00:00

Use gcc / clang overflow builtins. (#142)

* Use gcc / clang overflow builtins.

This avoids expensive checks for overflow that employ undefined
behavior.

This is a step along the way towards replacing the old hand-written
assembler that did the same thing in terms of using the CPU's
overflow detection.

* Remove unimplemented SPARC asm for multiplication, divide, and remainder.

This wasn't implemented before, and for multiplication, it is now
implemented for gcc and friends using overflow detection.

* Remove USE_INLINE_ARITH.

Now that we have the compiler built-ins for detecting overflow,
we don't need custom assembly for it for each platform.

For now, we keep, but still don't use, the code that do a hot
path through the dispatch loop for some math. This code isn't
actually running or in use, but it is separate from how the
other inline arithmetic was being performed. These are the
`fast_op_*` functions that are implemented in assembler.
This commit is contained in:
Bruce Mitchener
2021-01-21 15:27:31 +07:00
committed by GitHub
parent 36b8695bf6
commit 95b482d5d5
9 changed files with 63 additions and 407 deletions

View File

@@ -44,18 +44,18 @@
*/
/**********************************************************************/
int N_OP_times2(int tosm1, int tos) {
register int arg1, arg2;
register int result;
int arg1, arg2;
int result;
N_GETNUMBER(tosm1, arg1, doufn);
N_GETNUMBER(tos, arg2, doufn);
#ifdef SUN3_OS3_OR_OS4_IL
#ifdef USE_OVERFLOW_BUILTINS
result = mpy32(arg1, arg2);
if (__builtin_smul_overflow(arg1, arg2, &result)) {
goto doufn2;
}
N_ARITH_SWITCH(result);
dummy:
mpy_err_label();
#else
@@ -73,18 +73,18 @@ doufn:
} /* end N_OP_times2 */
int N_OP_itimes2(int tosm1, int tos) {
register int arg1, arg2;
register int result;
int arg1, arg2;
int result;
N_IGETNUMBER(tosm1, arg1, doufn);
N_IGETNUMBER(tos, arg2, doufn);
#ifdef SUN3_OS3_OR_OS4_IL
#ifdef USE_OVERFLOW_BUILTINS
result = impy32(arg1, arg2);
if (__builtin_smul_overflow(arg1, arg2, &result)) {
goto doufn;
}
N_ARITH_SWITCH(result);
dummy:
impy_err_label();
#else
@@ -108,25 +108,16 @@ doufn:
*/
/**********************************************************************/
int N_OP_quot(int tosm1, int tos) {
register int arg1, arg2;
register int result;
int arg1, arg2;
int result;
N_GETNUMBER(tosm1, arg1, doufn);
N_GETNUMBER(tos, arg2, doufn);
if (arg2 == 0) goto doufn2;
#ifdef SUN3_OS3_OR_OS4_IL
result = quot32(arg1, arg2);
N_ARITH_SWITCH(result);
dummy:
quot_err_label();
#else
result = arg1 / arg2; /* lmm: note: no error case!! */
N_ARITH_SWITCH(result);
#endif
doufn2:
ERROR_EXIT(tos);
doufn:
@@ -142,20 +133,9 @@ int N_OP_iquot(int tosm1, int tos) {
N_IGETNUMBER(tos, arg2, doufn);
if (arg2 == 0) goto doufn;
#ifdef SUN3_OS3_OR_OS4_IL
result = iquot32(arg1, arg2);
N_ARITH_SWITCH(result);
dummy:
iquot_err_label();
#else
result = arg1 / arg2;
N_ARITH_SWITCH(result);
#endif
doufn:
ERROR_EXIT(tos);
@@ -177,20 +157,9 @@ int N_OP_iremainder(int tosm1, int tos) {
N_IGETNUMBER(tos, arg2, doufn);
if (arg2 == 0) goto doufn;
#ifdef SUN3_OS3_OR_OS4_IL
result = irem32(arg1, arg2);
N_ARITH_SWITCH(result);
dummy:
irem_err_label();
#else
result = arg1 % arg2;
N_ARITH_SWITCH(result);
#endif
doufn:
ERROR_EXIT(tos);