From c15f60cd64922793c60f7dff67d451952241e082 Mon Sep 17 00:00:00 2001 From: d6 Date: Mon, 27 Dec 2021 15:51:59 -0500 Subject: [PATCH] small clean up --- math32.tal | 46 ++++++++++++++++++++++++++-------------------- tester.py | 2 +- 2 files changed, 27 insertions(+), 21 deletions(-) diff --git a/math32.tal b/math32.tal index 67507c7..3669622 100644 --- a/math32.tal +++ b/math32.tal @@ -111,17 +111,16 @@ COMPLEMENT32 RTN ( temporary registers ) -( used by all operations except div32 ) -@sh [ - &r $1 - &x0 $1 &x1 $1 &x2 $1 &x3 $1 - &y0 $1 &y1 $1 &y2 $1 &y3 $1 - &z0 $1 &z1 $1 &z2 $1 &z3 $1 - &a0 $1 &a1 $1 &a2 $2 -] +( used by most operations, except mul32 and div32 ) +@sh [ &r $1 + &x0 $1 &x1 $1 &x2 $1 &x3 $1 + &y0 $1 &y1 $1 &y2 $1 &y3 $1 + &z0 $1 &z1 $1 &z2 $1 &z3 $1 + &a0 $1 &a1 $1 &a2 $2 ] ( bit shifting ) +( shift right, i.e. >> ) @right-shift ( x** n^ -> x< x< zhi* zlo* ) ;sh/y2 STA2 ;sh/y0 STA2 ( save ylo, yhi ) ;sh/x2 STA2 ;sh/x0 STA2 ( save xlo, xhi ) @@ -259,6 +260,7 @@ ;sh/z0 LDA2 ;sh/z2 LDA2 RTN +( negation, i.e. unary - ) @negate32 ( x** -> -x** ) COMPLEMENT32 INC2 ( ~xhi -xlo ) @@ -268,9 +270,11 @@ &done RTN +( subtraction, i.e. binary - ) @sub32 ( x** y** -> z** ) ;negate32 JSR2 ;add32 JSR2 RTN +( 16-bit multiplication ) @mul16 ( x* y* -> z** ) ;sh/y1 STA ;sh/y0 STA ( save ylo, yhi ) ;sh/x1 STA ;sh/x0 STA ( save xlo, xhi ) @@ -295,22 +299,24 @@ ;add32 JSR2 RTN -@mul32 ( x** y** -> z** ) - ;sh/y2 STA2 ;sh/y0 STA2 ( save ylo, yhi ) - ;sh/x2 STA2 ;sh/x0 STA2 ( save xlo, xhi ) - ;sh/y2 LDA2 ;sh/x2 LDA2 ;mul16 JSR2 ( [x2*y2] ) - ;sh/z2 STA2 ;sh/z0 STA2 ( sum = x2*y2, save zlo, zhi ) +( multiplication, i.e. * ) +@mul32 ( x** y** -> z** ) + ,&y1 STR2 ,&y0 STR2 ( save ylo, yhi ) + ,&x1 STR2 ,&x0 STR2 ( save xlo, xhi ) + ,&y1 LDR2 ,&x1 LDR2 ;mul16 JSR2 ( [x1*y1] ) + ,&z1 STR2 ,&z0 STR2 ( sum = x1*y1, save zlo, zhi ) - ;sh/y2 LDA2 ;sh/x0 LDA2 MUL2 ( [x0*y2]<<16 ) - ;sh/y0 LDA2 ;sh/x2 LDA2 MUL2 ( [x2*y0]<<16 ) + ,&y1 LDR2 ,&x0 LDR2 MUL2 ( [x0*y1]<<16 ) + ,&y0 LDR2 ,&x1 LDR2 MUL2 ( [x1*y0]<<16 ) ( [x0*y0]<<32 will completely overflow ) - ADD2 ;sh/z0 LDA2 ADD2 ( sum += x0*y2<<16 + x2*y0<<16 ) - ;sh/z2 LDA2 + ADD2 ,&z0 LDR2 ADD2 ( sum += x0*y1<<16 + x1*y0<<16 ) + ,&z1 LDR2 RTN -[ &x0 $2 &x2 $2 ] -[ &y0 $2 &y2 $2 ] -[ &z0 $2 &z2 $2 ] +[ &x0 $2 &x1 $2 + &y0 $2 &y1 $2 + &z0 $2 &z1 $2 ] +( division, i.e. / ) @div32 ( x** y** -> q** ) ( store y and x for repeated use ) ;div32/div1 STA2 ;div32/div0 STA2 ( y -> div ) diff --git a/tester.py b/tester.py index bcb1944..e9cbbe8 100644 --- a/tester.py +++ b/tester.py @@ -56,7 +56,7 @@ def bitcount(x): return floor(log(x, 2)) + 1 def main(): - trials = 1000 + trials = 100 run(['uxnasm', 'test-math32.tal', 'run.rom']) p = pipe() test(p, trials, b'+', [('x', u32), ('y', u32)], u32, lambda x, y: x + y)