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) ldy #0 default sign bit is 0 (positive)
lda mantissa+6 if mantissa is negative then lda mantissa+6 if mantissa is negative then
bpl lb0 bpl lb0
sub8 #0,mantissa,mantissa negate it negate8 mantissa negate it
ldy #$8000 sign bit is 1 (negative) ldy #$8000 sign bit is 1 (negative)
lb0 tya set sign lb0 tya set sign

View File

@ -1,4 +1,23 @@
macro 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 &l move4 &m1,&m2
lclb &yistwo lclb &yistwo
&l ~setm &l ~setm
@ -121,121 +140,3 @@
.d .d
sta 2+&op sta 2+&op
mend 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 dec strLength
lb1 ph8 llValue divide by 10 lb1 ph8 <llValue divide by 10
ph8 #10 ph8 #10
jsl ~UDIV8 jsl ~UDIV8
pl8 llValue pl8 llValue
@ -5195,7 +5195,7 @@ lb4b lda ~suppress if input is not suppressed then
bne lb7 bne lb7
lda minus if minus then lda minus if minus then
beq lb4c beq lb4c
sub8 #0,val,val negate the value negate8 val negate the value
lb4c lda val save the value lb4c lda val save the value
ldx ~size ldx ~size
bpl lb4d bpl lb4d
@ -5635,7 +5635,7 @@ lb4b lda ~suppress if input is not suppressed then
bne lb7 bne lb7
lda minus if minus then lda minus if minus then
beq lb4c beq lb4c
sub8 #0,val,val negate the value negate8 val negate the value
lb4c lda val save the value lb4c lda val save the value
ldx ~size ldx ~size
bpl lb4d 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 MACRO
&lab cstr &s &lab cstr &s
&lab dc c"&s",i1'0' &lab dc c"&s",i1'0'
@ -740,69 +811,6 @@
dc i4'&p' dc i4'&p'
mend mend
macro 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 &l pl8 &n1
lclc &c lclc &c
&l anop &l anop

View File

@ -518,7 +518,7 @@ retptr equ 1
stx retptr stx retptr
stz retptr+2 stz retptr+2
ph8 i ph8 <i
jsl ~ABS8 jsl ~ABS8
pla pla
sta [retptr] sta [retptr]
@ -596,8 +596,8 @@ addr equ 1
phb use local addressing phb use local addressing
phk phk
plb plb
ph8 n do the divide ph8 <n do the divide
ph8 d ph8 <d
jsl ~CDIV8 jsl ~CDIV8
pl8 lldiv_t pl8 lldiv_t
pl8 lldiv_t+8 pl8 lldiv_t+8
@ -1272,7 +1272,7 @@ rt1 pla remove the original value of str from
pla the stack pla the stack
lda negative if negative then lda negative if negative then
beq rt2 beq rt2
sub8 #0,val,val val = -val negate8 val val = -val
rt2 lda val get the value rt2 lda val get the value
sta [retptr] 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 ldx #1 note that we have found a number
stx foundOne stx foundOne
pha save the digit pha save the digit
ph8 val val = val*base ph8 <val val = val*base
pea 0 pea 0
pea 0 pea 0
pea 0 pea 0
@ -1499,7 +1499,7 @@ rt1a lda rangeOK check if number was out of range
bra rt3 bra rt3
rt2 lda negative if negative then rt2 lda negative if negative then
beq rt2a beq rt2a
sub8 #0,val,val val = -val negate8 val val = -val
rt2a lda val get the value rt2a lda val get the value
sta [retptr] sta [retptr]
ldy #2 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 MACRO
&LAB MOVE4 &F,&T &LAB MOVE4 &F,&T
&LAB ~SETM &LAB ~SETM
@ -586,55 +657,6 @@
~RESTM ~RESTM
MEND MEND
macro 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 &l pl8 &n1
lclc &c lclc &c
&l anop &l anop
@ -690,20 +712,6 @@
mnote "Missing closing '}'",16 mnote "Missing closing '}'",16
mend mend
macro 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 jge &bp
&l blt *+5 &l blt *+5
brl &bp brl &bp