This commit is contained in:
~d6 2021-12-27 15:09:49 -05:00
parent a8364516b3
commit e8b6990a9d
2 changed files with 30 additions and 40 deletions

View File

@ -5,7 +5,6 @@
%DEBUG { #ff #0e DEO } %DEBUG { #ff #0e DEO }
%RTN { JMP2r } %RTN { JMP2r }
%TOR { ROT ROT } ( a b c -> c a b ) %TOR { ROT ROT } ( a b c -> c a b )
%TOR2 { ROT2 ROT2 } %TOR2 { ROT2 ROT2 }
%POP4 { POP2 POP2 } %POP4 { POP2 POP2 }
@ -51,21 +50,17 @@ RTN
@eq32 ( xhi* xlo* yhi* ylo* -> bool^ ) @eq32 ( xhi* xlo* yhi* ylo* -> bool^ )
ROT2 EQU2 #00 TOR2 ROT2 EQU2 #00 TOR2
EQU2 SWP POP AND EQU2 SWP POP AND RTN
RTN
@is-zero32 ( x** -> bool^ ) @is-zero32 ( x** -> bool^ )
ORA2 #0000 EQU2 ORA2 #0000 EQU2 RTN
RTN
@ne32 ( xhi* xlo* yhi* ylo* -> bool^ ) @ne32 ( xhi* xlo* yhi* ylo* -> bool^ )
ROT2 NEQ2 #00 TOR2 ROT2 NEQ2 #00 TOR2
NEQ2 SWP POP ORA NEQ2 SWP POP ORA RTN
RTN
@non-zero32 ( x** -> bool^ ) @non-zero32 ( x** -> bool^ )
ORA2 #0000 NEQ2 ORA2 #0000 NEQ2 RTN
RTN
( comparisons ) ( comparisons )
@ -104,20 +99,16 @@ RTN
( bitwise operations ) ( bitwise operations )
@and32 ( xhi* xlo* yhi* ylo* -> xhi|yhi* xlo|ylo* ) @and32 ( xhi* xlo* yhi* ylo* -> xhi|yhi* xlo|ylo* )
ROT2 AND2 TOR2 AND2 SWP2 ROT2 AND2 TOR2 AND2 SWP2 RTN
RTN
@or32 ( xhi* xlo* yhi* ylo* -> xhi|yhi* xlo|ylo* ) @or32 ( xhi* xlo* yhi* ylo* -> xhi|yhi* xlo|ylo* )
ROT2 ORA2 TOR2 ORA2 SWP2 ROT2 ORA2 TOR2 ORA2 SWP2 RTN
RTN
@xor32 ( xhi* xlo* yhi* ylo* -> xhi|yhi* xlo|ylo* ) @xor32 ( xhi* xlo* yhi* ylo* -> xhi|yhi* xlo|ylo* )
ROT2 EOR2 TOR2 EOR2 SWP2 ROT2 EOR2 TOR2 EOR2 SWP2 RTN
RTN
@complement32 ( x** -> ~x** ) @complement32 ( x** -> ~x** )
COMPLEMENT32 COMPLEMENT32 RTN
RTN
( bit shifting ) ( bit shifting )
@ -279,8 +270,7 @@ RTN
RTN RTN
@sub32 ( x** y** -> z** ) @sub32 ( x** y** -> z** )
;negate32 JSR2 ;add32 JSR2 ;negate32 JSR2 ;add32 JSR2 RTN
RTN
@mul16 ( x* y* -> z** ) @mul16 ( x* y* -> z** )
,&y1 STR ,&y0 STR ( save ylo, yhi ) ,&y1 STR ,&y0 STR ( save ylo, yhi )

View File

@ -3,7 +3,7 @@
from math import floor, log from math import floor, log
from os import environ from os import environ
from random import randint from random import randint
from subprocess import Popen, PIPE from subprocess import Popen, PIPE, run
u3 = {'sz': 1 << 3, 'fmt': b'%02x'} u3 = {'sz': 1 << 3, 'fmt': b'%02x'}
u5 = {'sz': 1 << 5, '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)) print('%s failed %d/%d trials (%r)' % (name, fails, trials, cases))
def pipe(): def pipe():
cli = environ['HOME'] + '/w/uxn/bin/uxncli' return Popen(['uxncli', 'run.rom'], stdin=PIPE, stdout=PIPE)
return Popen([cli, 'run.rom'], stdin=PIPE, stdout=PIPE)
def bitcount(x): def bitcount(x):
return floor(log(x, 2)) + 1 return floor(log(x, 2)) + 1
def main(): def main():
trials = 1000 trials = 1000
run(['uxnasm', 'test-math32.tal', 'run.rom'])
p = pipe() 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)
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)