small improvements

This commit is contained in:
~d6 2022-10-23 15:07:48 -04:00
parent e6ded70af4
commit 3636782b9b
1 changed files with 26 additions and 6 deletions

View File

@ -28,9 +28,9 @@
( #ff00 -256/256 -1.000 ) ( #ff00 -256/256 -1.000 )
( #ffff -1/256 -0.004 ) ( #ffff -1/256 -0.004 )
( ) ( )
( many 8.8 operations are equivalent to uin16: ) ( many 8.8 operations are equivalent to unsigned int16: )
( * addition/subtraction ) ( * addition )
( * division ) ( * subtraction )
( or signed int16: ) ( or signed int16: )
( * comparisons/equality ) ( * comparisons/equality )
( ) ( )
@ -46,6 +46,14 @@
( that said, if either x or y is whole (i.e. ends in 00) ) ( that said, if either x or y is whole (i.e. ends in 00) )
( then we can just shift that argument right by 8 and use ) ( then we can just shift that argument right by 8 and use )
( MUL2. ) ( MUL2. )
( )
( similarly with division we have: )
( )
( x divided by #0100 -> x )
( x divided by #0001 -> x * 256, with likely overfow )
( #abcd divided by #1000 -> #0abc, rounding with d )
( x divided by #0200 -> x >> 1 )
( x divided by #0080 -> x << 1 )
%xyz { ;x16-emit JSR2 #0a #18 DEO } %xyz { ;x16-emit JSR2 #0a #18 DEO }
@ -82,7 +90,7 @@
%x16-emit-dec { #30 ADD #18 DEO } %x16-emit-dec { #30 ADD #18 DEO }
( |0100 |0100
x16-zero xyz x16-zero xyz
x16-one xyz x16-one xyz
x16-two xyz x16-two xyz
@ -97,11 +105,23 @@
x16-sqrt-3 xyz x16-sqrt-3 xyz
x16-epsilon xyz x16-epsilon xyz
#1234 xyz #1234 xyz
BRK ) #7fff xyz
#8000 xyz
#8001 xyz
#ffff xyz
BRK
@x16-emit ( x* -> ) @x16-emit ( x* -> )
DUP2 #8000 EQU2 ,&is-min JCN
DUP2 #8000 GTH2 ,&is-neg JCN
SWP DUP #64 LTH ,&<100 JCN SWP DUP #64 LTH ,&<100 JCN
#64 DIVk DUP x16-emit-dec MUL SUB ,&>=10 JMP #64 DIVk DUP x16-emit-dec MUL SUB ,&>=10 JMP
&is-min POP2
LIT "- #18 DEO LIT "1 #18 DEO LIT "2 #18 DEO LIT "8 #18 DEO
LIT ". #18 DEO LIT "0 #18 DEO LIT "0 #18 DEO LIT "0 #18 DEO
JMP2r
&is-neg
LIT "- #18 DEO #ffff EOR2 INC2 ,x16-emit JMP
&<100 DUP #0a LTH ,&<10 JCN &<100 DUP #0a LTH ,&<10 JCN
&>=10 #0a DIVk DUP x16-emit-dec MUL SUB &>=10 #0a DIVk DUP x16-emit-dec MUL SUB
&<10 x16-emit-dec &<10 x16-emit-dec
@ -123,7 +143,7 @@
POP2 POP2r #ff JMP2r ( x<0 y>=0 ) POP2 POP2r #ff JMP2r ( x<0 y>=0 )
&ypxp ;x16-ucmp JMP2 ( x>=0 y>=0 ) &ypxp ;x16-ucmp JMP2 ( x>=0 y>=0 )
&yn x16-is-neg ,&ynxn ( y<0 ) &yn x16-is-neg ,&ynxn ( y<0 )
POP2 POP2r #01 JMP2r ( x>=0 y<0 ) POP2 POP2r #01 JMP2r ( x>=0 y<0 )
&ynxn SWP2 ;x16-ucmp JMP2 ( x<0 y<0 ) &ynxn SWP2 ;x16-ucmp JMP2 ( x<0 y<0 )
( unsigned comparison between x and y. ) ( unsigned comparison between x and y. )