clean up fix16
This commit is contained in:
parent
9f72ee4490
commit
a870fc533a
51
fix16.tal
51
fix16.tal
|
@ -49,13 +49,11 @@
|
||||||
( )
|
( )
|
||||||
( similarly with division we have: )
|
( similarly with division we have: )
|
||||||
( )
|
( )
|
||||||
( x divided by #0100 -> x )
|
( x = x'/256 )
|
||||||
( x divided by #0001 -> x * 256, with likely overfow )
|
( y = y'/256 )
|
||||||
( #abcd divided by #1000 -> #0abc, rounding with d )
|
( x/y = z = z'/256 )
|
||||||
( x divided by #0200 -> x >> 1 )
|
( (x'/256)/(y'/256) = (x'*256 / y)/256 )
|
||||||
( x divided by #0080 -> x << 1 )
|
( z' = (x' * 256 / y)/256 )
|
||||||
|
|
||||||
%xyz { ;x16-emit JSR2 #0a #18 DEO }
|
|
||||||
|
|
||||||
( useful constants )
|
( useful constants )
|
||||||
( )
|
( )
|
||||||
|
@ -92,42 +90,6 @@
|
||||||
|
|
||||||
%x16-emit-dec { #30 ADD #18 DEO }
|
%x16-emit-dec { #30 ADD #18 DEO }
|
||||||
|
|
||||||
( |0100
|
|
||||||
x16-zero xyz
|
|
||||||
x16-one xyz
|
|
||||||
x16-two xyz
|
|
||||||
x16-ten xyz
|
|
||||||
x16-hundred xyz
|
|
||||||
x16-pi/2 xyz
|
|
||||||
x16-pi xyz
|
|
||||||
x16-pi*2 xyz
|
|
||||||
x16-e xyz
|
|
||||||
x16-phi xyz
|
|
||||||
x16-sqrt-2 xyz
|
|
||||||
x16-sqrt-3 xyz
|
|
||||||
x16-epsilon xyz
|
|
||||||
#0002 xyz
|
|
||||||
#1234 xyz
|
|
||||||
#7fff xyz
|
|
||||||
#8000 xyz
|
|
||||||
#8001 xyz
|
|
||||||
#ffff xyz
|
|
||||||
#0200 xyz
|
|
||||||
#0834 #0000 ;x16-add JSR2 xyz
|
|
||||||
#0834 #0834 ;x16-add JSR2 xyz
|
|
||||||
#0834 #0834 ;x16-mul JSR2 xyz
|
|
||||||
#0834 #0200 ;x16-div JSR2 xyz
|
|
||||||
#0100 xyz
|
|
||||||
#0003 xyz
|
|
||||||
#0100 #0003 ;x16-div JSR2 xyz
|
|
||||||
#0834 xyz
|
|
||||||
#0080 xyz
|
|
||||||
#0834 #0080 ;x16-div JSR2 xyz
|
|
||||||
#0834 xyz
|
|
||||||
#0300 xyz
|
|
||||||
#0834 #0300 ;x16-div JSR2 xyz
|
|
||||||
BRK )
|
|
||||||
|
|
||||||
@x16-emit ( x* -> )
|
@x16-emit ( x* -> )
|
||||||
DUP2 #8000 EQU2 ,&is-min JCN
|
DUP2 #8000 EQU2 ,&is-min JCN
|
||||||
DUP2 #8000 GTH2 ,&is-neg JCN
|
DUP2 #8000 GTH2 ,&is-neg JCN
|
||||||
|
@ -201,9 +163,6 @@
|
||||||
&rhs-whole #08 SFT2 MUL2 JMP2r
|
&rhs-whole #08 SFT2 MUL2 JMP2r
|
||||||
|
|
||||||
@x16-div ( x* y* -> x/y* )
|
@x16-div ( x* y* -> x/y* )
|
||||||
( DUP ,¬-whole JCN
|
|
||||||
#08 SFT2 DIV2 JMP2r ( since y is whole, x/(y>>8) is correct )
|
|
||||||
¬-whole )
|
|
||||||
DIV2k STH2k ( x y x/y {x/y} )
|
DIV2k STH2k ( x y x/y {x/y} )
|
||||||
LITr 80 SFT2r ( x y x/y {div=(x/y)<<8 )
|
LITr 80 SFT2r ( x y x/y {div=(x/y)<<8 )
|
||||||
OVR2 STH2 ( x y x/y {y div} )
|
OVR2 STH2 ( x y x/y {y div} )
|
||||||
|
|
59
fixed.tal
59
fixed.tal
|
@ -1,59 +0,0 @@
|
||||||
( use short as a fixed point number 8.8 )
|
|
||||||
( )
|
|
||||||
( so #0001 is interpreted as 1/256 )
|
|
||||||
( and #ffff is interpreted as 255+255/256 )
|
|
||||||
( )
|
|
||||||
( x = x0 + x1/256 )
|
|
||||||
( y = y0 + y1/256 )
|
|
||||||
( )
|
|
||||||
( many 8.8 operations are equivalent to u16: )
|
|
||||||
( * comparisons/equality )
|
|
||||||
( * addition/subtraction )
|
|
||||||
( )
|
|
||||||
( but due to 16-bit truncation multiplication is different. )
|
|
||||||
( )
|
|
||||||
( x*y = x0*y0 + x0*y1/256 + x1*y0/256 + x1*y1/65536 )
|
|
||||||
( )
|
|
||||||
( since we only have 16-bits: )
|
|
||||||
( 1. we need to drop the 8 high bits from x0*y0 )
|
|
||||||
( 2. we need to drop the 8 low bits from x1*y1 )
|
|
||||||
( 3. we need to use all the bits from x0*y1 and x1*y0 )
|
|
||||||
|
|
||||||
%EMIT { #18 DEO }
|
|
||||||
%DIGIT { #00 SWP ;digits ADD2 LDA EMIT }
|
|
||||||
%SPACE { #20 EMIT }
|
|
||||||
%NEWLINE { #0a EMIT }
|
|
||||||
%EMIT-BYTE { DUP #04 SFT DIGIT #0f AND DIGIT }
|
|
||||||
|
|
||||||
( program )
|
|
||||||
|0100
|
|
||||||
#0100 #0100 ;mul-fix JSR2 ;emit-short JSR2 NEWLINE
|
|
||||||
#0999 #0100 ;mul-fix JSR2 ;emit-short JSR2 NEWLINE
|
|
||||||
#abcd #0100 ;mul-fix JSR2 ;emit-short JSR2 NEWLINE
|
|
||||||
#0200 #0200 ;mul-fix JSR2 ;emit-short JSR2 NEWLINE
|
|
||||||
#0400 #0200 ;mul-fix JSR2 ;emit-short JSR2 NEWLINE
|
|
||||||
BRK
|
|
||||||
|
|
||||||
%LO { NIP #00 SWP }
|
|
||||||
%HI { POP #00 SWP }
|
|
||||||
|
|
||||||
@mul-fix ( x* y* -> z* )
|
|
||||||
OVR2 OVR2 LO SWP2 LO MUL2 ( x1*y1 )
|
|
||||||
#08 SFT2 STH2 ( z = (x1*y1)>>8 )
|
|
||||||
|
|
||||||
OVR2 OVR2 HI SWP2 LO MUL2 ( x0*y1 )
|
|
||||||
STH2 ADD2r ( z += x0*y1 )
|
|
||||||
|
|
||||||
OVR2 OVR2 LO SWP2 HI MUL2 ( x1*y0 )
|
|
||||||
STH2 ADD2r ( z += x1*y0 )
|
|
||||||
|
|
||||||
HI SWP2 HI MUL2 ( x0*y0 )
|
|
||||||
#80 SFT2 STH2r ADD2 ( z += (x0*y0)<<8 )
|
|
||||||
JMP2r
|
|
||||||
|
|
||||||
@emit-short SWP EMIT-BYTE EMIT-BYTE JMP2r
|
|
||||||
|
|
||||||
( convenience for less branching when printing hex )
|
|
||||||
@digits
|
|
||||||
30 31 32 33 34 35 36 37
|
|
||||||
38 39 61 62 63 64 65 66
|
|
Loading…
Reference in New Issue