Use some improved macros for 64-bit operations in the libraries.

The new m16.int64 file contains a new "negate8" macro (for 64-bit negation), as well as an improved version of "ph8". These have been added to the individual *.macros files, but if those are regenerated, m16.int64 should be used as an input to macgen ahead of m16.ORCA (which contains the original version of ph8).
This commit is contained in:
Stephen Heumann 2021-02-12 20:24:37 -06:00
parent 91f0dcbdb9
commit 6bf27c6743
7 changed files with 252 additions and 254 deletions

View File

@ -558,7 +558,7 @@ exponent equ mantissa+8 biased exponent and sign bit
ldy #0 default sign bit is 0 (positive)
lda mantissa+6 if mantissa is negative then
bpl lb0
sub8 #0,mantissa,mantissa negate it
negate8 mantissa negate it
ldy #$8000 sign bit is 1 (negative)
lb0 tya set sign

View File

@ -1,4 +1,23 @@
macro
&l negate8 &n1
&l ~setm
sec
ldy #0
tya
sbc &n1
sta &n1
tya
sbc &n1+2
sta &n1+2
tya
sbc &n1+4
sta &n1+4
tya
sbc &n1+6
sta &n1+6
~restm
mend
macro
&l move4 &m1,&m2
lclb &yistwo
&l ~setm
@ -121,121 +140,3 @@
.d
sta 2+&op
mend
macro
&l sub8 &n1,&n2,&n3
&l ~setm
ph8 &n1
ph8 &n2
jsl ~sub8
aif c:&n3,.a
pl8 &n1
ago .b
.a
pl8 &n3
.b
~restm
mend
macro
&l ph8 &n1
lclc &c
&l anop
&c amid &n1,1,1
aif s:longa=1,.a
rep #%00100000
.a
aif "&c"="#",.d
aif "&c"="[",.b
aif "&c"<>"{",.c
&c amid &n1,l:&n1,1
aif "&c"<>"}",.g
&n1 amid &n1,2,l:&n1-2
&n1 setc (&n1)
.b
ldy #6
~&SYSCNT lda &n1,y
pha
dey
dey
bpl ~&SYSCNT
ago .e
.c
ldx #6
~&SYSCNT lda &n1,x
pha
dex
dex
bpl ~&SYSCNT
ago .e
.d
&n1 amid &n1,2,l:&n1-1
bra ~b&SYSCNT
~a&SYSCNT dc i8"&n1"
~b&SYSCNT ldx #6
~c&SYSCNT lda ~a&SYSCNT,x
pha
dex
dex
bpl ~c&SYSCNT
.e
aif s:longa=1,.f
sep #%00100000
.f
mexit
.g
mnote "Missing closing '}'",16
mend
macro
&l pl8 &n1
lclc &c
&l anop
aif s:longa=1,.a
rep #%00100000
.a
&c amid &n1,1,1
aif "&c"<>"{",.b
&c amid &n1,l:&n1,1
aif "&c"<>"}",.f
&n1 amid &n1,2,l:&n1-2
pla
sta (&n1)
ldy #2
pla
sta (&n1),y
ldy #4
pla
sta (&n1),y
ldy #6
pla
sta (&n1),y
ago .d
.b
aif "&c"<>"[",.c
pla
sta &n1
ldy #2
pla
sta &n1,y
ldy #4
pla
sta &n1,y
ldy #6
pla
sta &n1,y
ago .d
.c
pla
sta &n1
pla
sta &n1+2
pla
sta &n1+4
pla
sta &n1+6
.d
aif s:longa=1,.e
sep #%00100000
.e
mexit
.f
mnote "Missing closing '}'",16
mend

81
m16.int64 Normal file
View File

@ -0,0 +1,81 @@
;
; New and improved macros for operations on 64-bit integers
;
; Negate a 64-bit value (DP, absolute, or absolute long)
macro
&l negate8 &n1
&l ~setm
sec
ldy #0
tya
sbc &n1
sta &n1
tya
sbc &n1+2
sta &n1+2
tya
sbc &n1+4
sta &n1+4
tya
sbc &n1+6
sta &n1+6
~restm
mend
; Improved ph8 macro:
; - Generates more effecient code for constants
; - Supports "ph8 <dp" to get better code using pei
macro
&l ph8 &n1
lclc &c
&l anop
&c amid &n1,1,1
aif s:longa=1,.a
rep #%00100000
.a
aif "&c"="#",.d
aif "&c"="[",.b
aif "&c"<>"{",.c
&c amid &n1,l:&n1,1
aif "&c"<>"}",.g
&n1 amid &n1,2,l:&n1-2
&n1 setc (&n1)
.b
ldy #6
~&SYSCNT lda &n1,y
pha
dey
dey
bpl ~&SYSCNT
ago .e
.c
aif "&c"<>"<",.c1
pei &n1+6
pei &n1+4
pei &n1+2
pei &n1
ago .e
.c1
ldx #6
~&SYSCNT lda &n1,x
pha
dex
dex
bpl ~&SYSCNT
ago .e
.d
&n1 amid &n1,2,l:&n1-1
pea +(&n1)|-48
pea +(&n1)|-32
pea +(&n1)|-16
pea &n1
.e
aif s:longa=1,.f
sep #%00100000
.f
mexit
.g
mnote "Missing closing '}'",16
mend

View File

@ -4018,7 +4018,7 @@ rn3 inc argp
dec strLength
lb1 ph8 llValue divide by 10
lb1 ph8 <llValue divide by 10
ph8 #10
jsl ~UDIV8
pl8 llValue
@ -5195,7 +5195,7 @@ lb4b lda ~suppress if input is not suppressed then
bne lb7
lda minus if minus then
beq lb4c
sub8 #0,val,val negate the value
negate8 val negate the value
lb4c lda val save the value
ldx ~size
bpl lb4d
@ -5635,7 +5635,7 @@ lb4b lda ~suppress if input is not suppressed then
bne lb7
lda minus if minus then
beq lb4c
sub8 #0,val,val negate the value
negate8 val negate the value
lb4c lda val save the value
ldx ~size
bpl lb4d

View File

@ -1,3 +1,74 @@
macro
&l negate8 &n1
&l ~setm
sec
ldy #0
tya
sbc &n1
sta &n1
tya
sbc &n1+2
sta &n1+2
tya
sbc &n1+4
sta &n1+4
tya
sbc &n1+6
sta &n1+6
~restm
mend
macro
&l ph8 &n1
lclc &c
&l anop
&c amid &n1,1,1
aif s:longa=1,.a
rep #%00100000
.a
aif "&c"="#",.d
aif "&c"="[",.b
aif "&c"<>"{",.c
&c amid &n1,l:&n1,1
aif "&c"<>"}",.g
&n1 amid &n1,2,l:&n1-2
&n1 setc (&n1)
.b
ldy #6
~&SYSCNT lda &n1,y
pha
dey
dey
bpl ~&SYSCNT
ago .e
.c
aif "&c"<>"<",.c1
pei &n1+6
pei &n1+4
pei &n1+2
pei &n1
ago .e
.c1
ldx #6
~&SYSCNT lda &n1,x
pha
dex
dex
bpl ~&SYSCNT
ago .e
.d
&n1 amid &n1,2,l:&n1-1
pea +(&n1)|-48
pea +(&n1)|-32
pea +(&n1)|-16
pea &n1
.e
aif s:longa=1,.f
sep #%00100000
.f
mexit
.g
mnote "Missing closing '}'",16
mend
MACRO
&lab cstr &s
&lab dc c"&s",i1'0'
@ -740,69 +811,6 @@
dc i4'&p'
mend
macro
&l sub8 &n1,&n2,&n3
&l ~setm
ph8 &n1
ph8 &n2
jsl ~SUB8
aif c:&n3,.a
pl8 &n1
ago .b
.a
pl8 &n3
.b
~restm
mend
macro
&l ph8 &n1
lclc &c
&l anop
&c amid &n1,1,1
aif s:longa=1,.a
rep #%00100000
.a
aif "&c"="#",.d
aif "&c"="[",.b
aif "&c"<>"{",.c
&c amid &n1,l:&n1,1
aif "&c"<>"}",.g
&n1 amid &n1,2,l:&n1-2
&n1 setc (&n1)
.b
ldy #6
~&SYSCNT lda &n1,y
pha
dey
dey
bpl ~&SYSCNT
ago .e
.c
ldx #6
~&SYSCNT lda &n1,x
pha
dex
dex
bpl ~&SYSCNT
ago .e
.d
&n1 amid &n1,2,l:&n1-1
bra ~b&SYSCNT
~a&SYSCNT dc i8"&n1"
~b&SYSCNT ldx #6
~c&SYSCNT lda ~a&SYSCNT,x
pha
dex
dex
bpl ~c&SYSCNT
.e
aif s:longa=1,.f
sep #%00100000
.f
mexit
.g
mnote "Missing closing '}'",16
mend
macro
&l pl8 &n1
lclc &c
&l anop

View File

@ -518,7 +518,7 @@ retptr equ 1
stx retptr
stz retptr+2
ph8 i
ph8 <i
jsl ~ABS8
pla
sta [retptr]
@ -596,8 +596,8 @@ addr equ 1
phb use local addressing
phk
plb
ph8 n do the divide
ph8 d
ph8 <n do the divide
ph8 <d
jsl ~CDIV8
pl8 lldiv_t
pl8 lldiv_t+8
@ -1272,7 +1272,7 @@ rt1 pla remove the original value of str from
pla the stack
lda negative if negative then
beq rt2
sub8 #0,val,val val = -val
negate8 val val = -val
rt2 lda val get the value
sta [retptr]
@ -1437,7 +1437,7 @@ cn3 cmp base branch if the digit is too big
ldx #1 note that we have found a number
stx foundOne
pha save the digit
ph8 val val = val*base
ph8 <val val = val*base
pea 0
pea 0
pea 0
@ -1499,7 +1499,7 @@ rt1a lda rangeOK check if number was out of range
bra rt3
rt2 lda negative if negative then
beq rt2a
sub8 #0,val,val val = -val
negate8 val val = -val
rt2a lda val get the value
sta [retptr]
ldy #2

View File

@ -1,3 +1,74 @@
macro
&l negate8 &n1
&l ~setm
sec
ldy #0
tya
sbc &n1
sta &n1
tya
sbc &n1+2
sta &n1+2
tya
sbc &n1+4
sta &n1+4
tya
sbc &n1+6
sta &n1+6
~restm
mend
macro
&l ph8 &n1
lclc &c
&l anop
&c amid &n1,1,1
aif s:longa=1,.a
rep #%00100000
.a
aif "&c"="#",.d
aif "&c"="[",.b
aif "&c"<>"{",.c
&c amid &n1,l:&n1,1
aif "&c"<>"}",.g
&n1 amid &n1,2,l:&n1-2
&n1 setc (&n1)
.b
ldy #6
~&SYSCNT lda &n1,y
pha
dey
dey
bpl ~&SYSCNT
ago .e
.c
aif "&c"<>"<",.c1
pei &n1+6
pei &n1+4
pei &n1+2
pei &n1
ago .e
.c1
ldx #6
~&SYSCNT lda &n1,x
pha
dex
dex
bpl ~&SYSCNT
ago .e
.d
&n1 amid &n1,2,l:&n1-1
pea +(&n1)|-48
pea +(&n1)|-32
pea +(&n1)|-16
pea &n1
.e
aif s:longa=1,.f
sep #%00100000
.f
mexit
.g
mnote "Missing closing '}'",16
mend
MACRO
&LAB MOVE4 &F,&T
&LAB ~SETM
@ -586,55 +657,6 @@
~RESTM
MEND
macro
&l ph8 &n1
lclc &c
&l anop
&c amid &n1,1,1
aif s:longa=1,.a
rep #%00100000
.a
aif "&c"="#",.d
aif "&c"="[",.b
aif "&c"<>"{",.c
&c amid &n1,l:&n1,1
aif "&c"<>"}",.g
&n1 amid &n1,2,l:&n1-2
&n1 setc (&n1)
.b
ldy #6
~&SYSCNT lda &n1,y
pha
dey
dey
bpl ~&SYSCNT
ago .e
.c
ldx #6
~&SYSCNT lda &n1,x
pha
dex
dex
bpl ~&SYSCNT
ago .e
.d
&n1 amid &n1,2,l:&n1-1
bra ~b&SYSCNT
~a&SYSCNT dc i8"&n1"
~b&SYSCNT ldx #6
~c&SYSCNT lda ~a&SYSCNT,x
pha
dex
dex
bpl ~c&SYSCNT
.e
aif s:longa=1,.f
sep #%00100000
.f
mexit
.g
mnote "Missing closing '}'",16
mend
macro
&l pl8 &n1
lclc &c
&l anop
@ -690,20 +712,6 @@
mnote "Missing closing '}'",16
mend
macro
&l sub8 &n1,&n2,&n3
&l ~setm
ph8 &n1
ph8 &n2
jsl ~SUB8
aif c:&n3,.a
pl8 &n1
ago .b
.a
pl8 &n3
.b
~restm
mend
macro
&l jge &bp
&l blt *+5
brl &bp