small clean up

This commit is contained in:
~d6 2021-12-27 15:51:59 -05:00
parent 00bdb689c2
commit c15f60cd64
2 changed files with 27 additions and 21 deletions

View File

@ -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<<n )
DUP #08 LTH ;right-shift0 JCN2 ( x n )
DUP #10 LTH ;right-shift1 JCN2 ( x n )
@ -168,6 +167,7 @@
;sh/r LDA SFT
RTN
( shift left, i.e. << )
@left-shift ( x** n^ -> x<<n )
DUP #08 LTH ;left-shift0 JCN2 ( x n )
DUP #10 LTH ;left-shift1 JCN2 ( x n )
@ -235,6 +235,7 @@
( arithmetic )
( addition, i.e. + )
@add32 ( xhi* xlo* yhi* ylo* -> 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
( multiplication, i.e. * )
@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 )
,&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 )

View File

@ -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)