From e8b6990a9d4d642293e07978338f2aa9825ef428 Mon Sep 17 00:00:00 2001 From: d6 Date: Mon, 27 Dec 2021 15:09:49 -0500 Subject: [PATCH] clean up --- math32.tal | 64 +++++++++++++++++++++++------------------------------- tester.py | 6 ++--- 2 files changed, 30 insertions(+), 40 deletions(-) diff --git a/math32.tal b/math32.tal index f63ad83..cce6606 100644 --- a/math32.tal +++ b/math32.tal @@ -5,7 +5,6 @@ %DEBUG { #ff #0e DEO } %RTN { JMP2r } - %TOR { ROT ROT } ( a b c -> c a b ) %TOR2 { ROT2 ROT2 } %POP4 { POP2 POP2 } @@ -24,7 +23,7 @@ ,&loop JMP &done POP ( n ) -RTN + RTN @bitcount16 ( x* -> n^ ) SWP ( xlo xhi ) @@ -35,7 +34,7 @@ RTN RTN &hi-set SWP POP #08 ADD ( nhi+8 ) -RTN + RTN @bitcount32 ( x** -> n^ ) SWP2 ( xlo* xhi* ) @@ -45,27 +44,23 @@ RTN TOR ;bitcount16 JSR2 ADD RTN ( nhi+nlo ) &hi-set TOR POP2 #10 ADD ( nhi+16 ) -RTN + RTN ( equality ) @eq32 ( xhi* xlo* yhi* ylo* -> bool^ ) ROT2 EQU2 #00 TOR2 - EQU2 SWP POP AND -RTN + EQU2 SWP POP AND RTN @is-zero32 ( x** -> bool^ ) - ORA2 #0000 EQU2 -RTN + ORA2 #0000 EQU2 RTN @ne32 ( xhi* xlo* yhi* ylo* -> bool^ ) ROT2 NEQ2 #00 TOR2 - NEQ2 SWP POP ORA -RTN + NEQ2 SWP POP ORA RTN @non-zero32 ( x** -> bool^ ) - ORA2 #0000 NEQ2 -RTN + ORA2 #0000 NEQ2 RTN ( comparisons ) @@ -104,20 +99,16 @@ RTN ( bitwise operations ) @and32 ( xhi* xlo* yhi* ylo* -> xhi|yhi* xlo|ylo* ) - ROT2 AND2 TOR2 AND2 SWP2 -RTN + ROT2 AND2 TOR2 AND2 SWP2 RTN @or32 ( xhi* xlo* yhi* ylo* -> xhi|yhi* xlo|ylo* ) - ROT2 ORA2 TOR2 ORA2 SWP2 -RTN + ROT2 ORA2 TOR2 ORA2 SWP2 RTN @xor32 ( xhi* xlo* yhi* ylo* -> xhi|yhi* xlo|ylo* ) - ROT2 EOR2 TOR2 EOR2 SWP2 -RTN + ROT2 EOR2 TOR2 EOR2 SWP2 RTN @complement32 ( x** -> ~x** ) - COMPLEMENT32 -RTN + COMPLEMENT32 RTN ( bit shifting ) @@ -126,7 +117,7 @@ RTN DUP #10 LTH ;right-shift1 JCN2 ( x n ) DUP #18 LTH ;right-shift2 JCN2 ( x n ) ;right-shift3 JMP2 ( x n ) -RTN + RTN ( shift right by 0-7 bits ) @right-shift0 ( x** n^ -> x< r ) POP2 POP #00 SWP #0000 SWP2 ( 00 00 00 x0 ) ,&r LDR SFT -RTN + RTN [ &r $1 ] @left-shift ( x** n^ -> x< x< don't inc hi ) SWP2 INC2 SWP2 ( -xhi -xlo ) &done -RTN + RTN @sub32 ( x** y** -> z** ) - ;negate32 JSR2 ;add32 JSR2 -RTN + ;negate32 JSR2 ;add32 JSR2 RTN @mul16 ( x* y* -> z** ) ,&y1 STR ,&y0 STR ( save ylo, yhi ) @@ -304,7 +294,7 @@ RTN #00 ,&z0 LDR2 ,&z2 LDR ,&a0 LDR2 ,&a2 LDR #00 ;add32 JSR2 -RTN + RTN [ &x0 $1 &x1 $1 ] [ &y0 $1 &y1 $1 ] [ &z0 $1 &z1 $1 &z2 $1 ] @@ -321,7 +311,7 @@ RTN ( [x0*y0]<<32 will completely overflow ) ADD2 ,&z0 LDR2 ADD2 ( sum += x0*y1<<16 + x1*y0<<16 ) ,&z1 LDR2 -RTN + RTN [ &x0 $2 &x1 $2 ] [ &y0 $2 &y1 $2 ] [ &z0 $2 &z1 $2 ] @@ -370,7 +360,7 @@ RTN ,&cur0 LDR2 ,&cur1 LDR2 #01 ;right-shift JSR2 ,&cur1 STR2 ,&cur0 STR2 ( cur >>= 1 ) ,&cur0 LDR2 ,&cur1 LDR2 ;non-zero32 JSR2 ,&loop JCN ( if cur>0, loop. else we're done ) ,&quo0 LDR2 ,&quo1 LDR2 ( TODO: consider making this divmod32 ) -RTN + RTN [ &div0 $2 &div1 $2 &rem0 $2 &rem1 $2 &quo0 $2 &quo1 $2 diff --git a/tester.py b/tester.py index 1174fd6..bcb1944 100644 --- a/tester.py +++ b/tester.py @@ -3,7 +3,7 @@ from math import floor, log from os import environ from random import randint -from subprocess import Popen, PIPE +from subprocess import Popen, PIPE, run u3 = {'sz': 1 << 3, 'fmt': b'%02x'} u5 = {'sz': 1 << 5, 'fmt': b'%02x'} @@ -50,14 +50,14 @@ def test(p, trials, sym, args, out, f): print('%s failed %d/%d trials (%r)' % (name, fails, trials, cases)) def pipe(): - cli = environ['HOME'] + '/w/uxn/bin/uxncli' - return Popen([cli, 'run.rom'], stdin=PIPE, stdout=PIPE) + return Popen(['uxncli', 'run.rom'], stdin=PIPE, stdout=PIPE) def bitcount(x): return floor(log(x, 2)) + 1 def main(): trials = 1000 + run(['uxnasm', 'test-math32.tal', 'run.rom']) p = pipe() test(p, trials, b'+', [('x', u32), ('y', u32)], u32, lambda x, y: x + y) test(p, trials, b'-', [('x', u32), ('y', u32)], u32, lambda x, y: x - y)