diff --git a/libsrc/runtime/add.s b/libsrc/runtime/add.s index 6fb2dacf7..e644671c0 100644 --- a/libsrc/runtime/add.s +++ b/libsrc/runtime/add.s @@ -1,5 +1,6 @@ ; ; Ullrich von Bassewitz, 05.08.1998 +; Christian Krueger, 11-Mar-2017, spend two bytes for one cycle, improved 65SC02 optimization ; ; CC65 runtime: add ints ; @@ -8,32 +9,46 @@ ; called a lot! .export tosadda0, tosaddax - .importzp sp + .importzp sp, tmp1 .macpack cpu tosadda0: ldx #0 tosaddax: - clc -.if (.cpu .bitand CPU_ISET_65SC02) - adc (sp) ; 65SC02 version - saves 2 cycles - ldy #1 -.else - ldy #0 - adc (sp),y ; lo byte - iny -.endif - pha ; save it - txa - adc (sp),y ; hi byte - tax - clc - lda sp - adc #2 - sta sp - bcc L1 - inc sp+1 -L1: pla ; Restore low byte - rts + clc ; (2) +.if (.cpu .bitand ::CPU_ISET_65SC02) + + adc (sp) ; (7) + tay ; (9) + inc sp ; (14) + bne hiadd ; (17) + inc sp+1 ; (-1+5) +hiadd: txa ; (19) + adc (sp) ; (24) + tax ; (26) + inc sp ; (31) + bne done ; (34) + inc sp+1 ; (-1+5) +done: tya ; (36) + +.else + + ldy #0 ; (4) + adc (sp),y ; (9) lo byte + iny ; (11) + sta tmp1 ; (14) save it + txa ; (16) + adc (sp),y ; (21) hi byte + tax ; (23) + clc ; (25) + lda sp ; (28) + adc #2 ; (30) + sta sp ; (33) + bcc L1 ; (36) + inc sp+1 ; (-1+5) +L1: lda tmp1 ; (39) restore low byte + +.endif + rts ; (6502: 45 cycles, 26 bytes <-> 65SC02: 42 cycles, 22 bytes ) diff --git a/libsrc/runtime/along.s b/libsrc/runtime/along.s index 661b3124a..bd3462915 100644 --- a/libsrc/runtime/along.s +++ b/libsrc/runtime/along.s @@ -1,5 +1,6 @@ ; ; Ullrich von Bassewitz, 23.11.2002 +; Christian Krueger, 11-Mar-2017, saved 5 bytes ; ; CC65 runtime: Convert char in ax into a long ; @@ -9,16 +10,11 @@ ; Convert A from char to long in EAX +along: ldx #$ff + cmp #$80 ; Positive? + bcs store ; no, apply $FF + aulong: ldx #0 - stx sreg +store: stx sreg stx sreg+1 rts - -along: cmp #$80 ; Positive? - bcc aulong ; Yes, handle like unsigned type - ldx #$ff - stx sreg - stx sreg+1 - rts - - diff --git a/libsrc/runtime/laddeq.s b/libsrc/runtime/laddeq.s index 2632ec909..57bec0629 100644 --- a/libsrc/runtime/laddeq.s +++ b/libsrc/runtime/laddeq.s @@ -1,5 +1,6 @@ ; ; Ullrich von Bassewitz, 07.04.2000 +; Christian Krueger, 12-Mar-2017, added 65SC02 optimization ; ; CC65 runtime: += operator ; @@ -10,6 +11,7 @@ .export laddeq1, laddeqa, laddeq .importzp sreg, ptr1, tmp1 + .macpack cpu laddeq1: lda #$01 @@ -20,14 +22,20 @@ laddeqa: stx sreg+1 laddeq: sty ptr1+1 ; Store high byte of address - ldy #$00 ; Address low byte clc +.if (.cpu .bitand ::CPU_ISET_65SC02) + adc (ptr1) + sta (ptr1) + ldy #$01 ; Address byte 1 +.else + ldy #$00 ; Address low byte adc (ptr1),y sta (ptr1),y + iny ; Address byte 1 +.endif pha ; Save byte 0 of result for later - iny ; Address byte 1 txa adc (ptr1),y ; Load byte 1 sta (ptr1),y diff --git a/libsrc/runtime/land.s b/libsrc/runtime/land.s index 506c071a4..6ea4e5bcb 100644 --- a/libsrc/runtime/land.s +++ b/libsrc/runtime/land.s @@ -1,5 +1,6 @@ ; ; Ullrich von Bassewitz, 06.08.1998 +; Christian Krueger, 11-Mar-2017, added 65SC02 optimization ; ; CC65 runtime: and on longs ; @@ -8,17 +9,28 @@ .import addysp1 .importzp sp, sreg, tmp1 + .macpack cpu tosand0ax: +.if (.cpu .bitand ::CPU_ISET_65SC02) + stz sreg + stz sreg+1 +.else ldy #$00 sty sreg sty sreg+1 +.endif tosandeax: +.if (.cpu .bitand ::CPU_ISET_65SC02) + and (sp) ; byte 0 + ldy #1 +.else ldy #0 and (sp),y ; byte 0 - sta tmp1 iny +.endif + sta tmp1 txa and (sp),y ; byte 1 tax diff --git a/libsrc/runtime/leave.s b/libsrc/runtime/leave.s index 8f4e055f5..4a9ff7994 100644 --- a/libsrc/runtime/leave.s +++ b/libsrc/runtime/leave.s @@ -1,5 +1,6 @@ ; ; Ullrich von Bassewitz, 06.08.1998 +; Christian Krueger, 11-Mar-2017, added 65SC02 optimization ; ; CC65 runtime: function epilogue ; @@ -13,6 +14,8 @@ .import addysp .importzp sp + .macpack cpu + leave00: lda #0 leave0: ldx #0 @@ -24,6 +27,20 @@ leavey0: ldx #0 ; return < 256 leavey: jsr addysp ; drop stack frame + +.if (.cpu .bitand ::CPU_ISET_65SC02) + +leave: tay ; save A a sec + lda (sp) ; that's the pushed arg size + sec ; Count the byte, the count's stored in + adc sp + sta sp + bcc L1 + inc sp+1 +L1: tya ; Get return value back + +.else + leave: pha ; save A a sec ldy #0 lda (sp),y ; that's the pushed arg size @@ -33,5 +50,7 @@ leave: pha ; save A a sec bcc L1 inc sp+1 L1: pla ; Get return value back + +.endif rts diff --git a/libsrc/runtime/lmod.s b/libsrc/runtime/lmod.s index 74deb23f0..caeb0c4f6 100644 --- a/libsrc/runtime/lmod.s +++ b/libsrc/runtime/lmod.s @@ -1,6 +1,6 @@ ; ; Ullrich von Bassewitz, 07.08.1998 -; +; Christian Krueger, 11-Mar-2017, added 65SC02 optimization ; CC65 runtime: modulo operation for long signed ints ; @@ -11,10 +11,17 @@ .import poplsargs, udiv32, negeax .importzp sreg, ptr1, ptr2, tmp1, tmp3, tmp4 + .macpack cpu + tosmod0ax: +.if (.cpu .bitand ::CPU_ISET_65SC02) + stz sreg + stz sreg+1 +.else ldy #$00 sty sreg sty sreg+1 +.endif tosmodeax: jsr poplsargs ; Get arguments from stack, adjust sign diff --git a/libsrc/runtime/lmul.s b/libsrc/runtime/lmul.s index 7ad2b2aa4..860d58cba 100644 --- a/libsrc/runtime/lmul.s +++ b/libsrc/runtime/lmul.s @@ -1,5 +1,6 @@ ; ; Ullrich von Bassewitz, 13.08.1998 +; Christian Krueger, 11-Mar-2017, added 65SC02 optimization ; ; CC65 runtime: multiplication for long (unsigned) ints ; @@ -8,20 +9,32 @@ .import addysp1 .importzp sp, sreg, tmp1, tmp2, tmp3, tmp4, ptr1, ptr3, ptr4 + .macpack cpu + tosmul0ax: tosumul0ax: +.if (.cpu .bitand ::CPU_ISET_65SC02) + stz sreg + stz sreg+1 +.else ldy #$00 sty sreg sty sreg+1 +.endif tosmuleax: tosumuleax: mul32: sta ptr1 stx ptr1+1 ; op2 now in ptr1/sreg +.if (.cpu .bitand ::CPU_ISET_65SC02) + lda (sp) + ldy #1 +.else ldy #0 lda (sp),y - sta ptr3 iny +.endif + sta ptr3 lda (sp),y sta ptr3+1 iny diff --git a/libsrc/runtime/lor.s b/libsrc/runtime/lor.s index a74b33059..94ab3c890 100644 --- a/libsrc/runtime/lor.s +++ b/libsrc/runtime/lor.s @@ -1,5 +1,6 @@ ; ; Ullrich von Bassewitz, 06.08.1998 +; Christian Krueger, 11-Mar-2017, added 65SC02 optimization ; ; CC65 runtime: or on longs ; @@ -8,17 +9,28 @@ .import addysp1 .importzp sp, sreg, tmp1 + .macpack cpu tosor0ax: +.if (.cpu .bitand ::CPU_ISET_65SC02) + stz sreg + stz sreg+1 +.else ldy #$00 sty sreg - sty sreg+1 + sty sreg+1 +.endif tosoreax: +.if (.cpu .bitand ::CPU_ISET_65SC02) + ora (sp) + ldy #1 +.else ldy #0 ora (sp),y ; byte 0 - sta tmp1 iny +.endif + sta tmp1 txa ora (sp),y ; byte 1 tax diff --git a/libsrc/runtime/lpop.s b/libsrc/runtime/lpop.s index 7d281db52..ffff5ffc1 100644 --- a/libsrc/runtime/lpop.s +++ b/libsrc/runtime/lpop.s @@ -1,5 +1,6 @@ ; ; Ullrich von Bassewitz, 29.12.1999 +; Christian Krueger, 11-Mar-2017, added 65SC02 optimization ; ; CC65 runtime: long pop ; @@ -8,6 +9,7 @@ .import incsp4 .importzp sp, sreg + .macpack cpu popeax: ldy #3 lda (sp),y @@ -18,8 +20,12 @@ popeax: ldy #3 dey lda (sp),y tax +.if (.cpu .bitand ::CPU_ISET_65SC02) + lda (sp) +.else dey lda (sp),y +.endif jmp incsp4 diff --git a/libsrc/runtime/lpush.s b/libsrc/runtime/lpush.s index 074b4320a..4fed77f05 100644 --- a/libsrc/runtime/lpush.s +++ b/libsrc/runtime/lpush.s @@ -1,5 +1,6 @@ ; ; Ullrich von Bassewitz, 06.08.1998 +; Christian Krueger, 11-Mar-2017, added 65SC02 optimization ; ; CC65 runtime: long push ; @@ -11,13 +12,20 @@ .import decsp4 .importzp sp, sreg + .macpack cpu + pushl0: lda #0 tax push0ax: - ldy #0 +.if (.cpu .bitand ::CPU_ISET_65SC02) + stz sreg + stz sreg+1 +.else + ldy #$00 sty sreg sty sreg+1 +.endif pusheax: pha ; decsp will destroy A (but not X) jsr decsp4 @@ -30,8 +38,12 @@ pusheax: dey txa sta (sp),y - dey pla +.if (.cpu .bitand ::CPU_ISET_65SC02) + sta (sp) +.else + dey sta (sp),y +.endif rts diff --git a/libsrc/runtime/lrsub.s b/libsrc/runtime/lrsub.s index fd519ca4f..928164f40 100644 --- a/libsrc/runtime/lrsub.s +++ b/libsrc/runtime/lrsub.s @@ -1,5 +1,6 @@ ; ; Ullrich von Bassewitz, 05.08.1998 +; Christian Krueger, 11-Mar-2017, added 65SC02 optimization ; ; CC65 runtime: long sub reversed ; @@ -11,18 +12,30 @@ .import addysp1 .importzp sp, sreg, tmp1 + .macpack cpu + tosrsub0ax: +.if (.cpu .bitand ::CPU_ISET_65SC02) + stz sreg + stz sreg+1 +.else ldy #$00 sty sreg sty sreg+1 +.endif -tosrsubeax: - ldy #0 +tosrsubeax: sec +.if (.cpu .bitand ::CPU_ISET_65SC02) + sbc (sp) + ldy #1 +.else + ldy #0 sbc (sp),y ; byte 0 + iny +.endif sta tmp1 ; use as temp storage txa - iny sbc (sp),y ; byte 1 tax iny diff --git a/libsrc/runtime/lsave.s b/libsrc/runtime/lsave.s index fa21e463e..d5f4c45b3 100644 --- a/libsrc/runtime/lsave.s +++ b/libsrc/runtime/lsave.s @@ -1,7 +1,8 @@ ; ; Ullrich von Bassewitz, 08.08.1998 +; Christian Krueger, 11-Mar-2017, optimization ; -; CC65 runtime: save ax into temp storage/restore ax from temp storage +; CC65 runtime: save eax into temp storage/restore eax from temp storage ; .export saveeax, resteax @@ -10,11 +11,10 @@ saveeax: sta regsave stx regsave+1 - lda sreg - sta regsave+2 - lda sreg+1 - sta regsave+3 - lda regsave + ldy sreg + sty regsave+2 + ldy sreg+1 + sty regsave+3 rts resteax: @@ -25,4 +25,3 @@ resteax: ldx regsave+1 lda regsave rts - diff --git a/libsrc/runtime/lsub.s b/libsrc/runtime/lsub.s index 926d52e51..6f80491ca 100644 --- a/libsrc/runtime/lsub.s +++ b/libsrc/runtime/lsub.s @@ -1,6 +1,6 @@ ; ; Ullrich von Bassewitz, 05.08.1998 -; +; Christian Krueger, 11-Mar-2017, ímproved 65SC02 optimization ; CC65 runtime: long sub ; @@ -14,14 +14,19 @@ .macpack cpu tossub0ax: +.if (.cpu .bitand ::CPU_ISET_65SC02) + stz sreg + stz sreg+1 +.else ldy #$00 sty sreg sty sreg+1 +.endif tossubeax: sec eor #$FF -.if (.cpu .bitand CPU_ISET_65SC02) +.if (.cpu .bitand ::CPU_ISET_65SC02) adc (sp) ; 65SC02 version - saves 2 cycles ldy #1 .else diff --git a/libsrc/runtime/lsubeq.s b/libsrc/runtime/lsubeq.s index 9f5853d29..5e3d25783 100644 --- a/libsrc/runtime/lsubeq.s +++ b/libsrc/runtime/lsubeq.s @@ -1,5 +1,6 @@ ; ; Ullrich von Bassewitz, 07.04.2000 +; Christian Krueger, 12-Mar-2017, added 65SC02 optimization ; ; CC65 runtime: -= operator ; @@ -10,6 +11,7 @@ .export lsubeq1, lsubeqa, lsubeq .importzp sreg, ptr1 + .macpack cpu lsubeq1: lda #$01 @@ -20,15 +22,20 @@ lsubeqa: stx sreg+1 lsubeq: sty ptr1+1 ; Store high byte of address - ldy #$00 ; Address low byte + sec - eor #$FF + .if (.cpu .bitand ::CPU_ISET_65SC02) + adc (ptr1) ; Subtract byte 0 + sta (ptr1) + ldy #$01 ; Address byte 1 + .else + ldy #$00 ; Address low byte adc (ptr1),y ; Subtract byte 0 sta (ptr1),y + iny ; Address byte 1 + .endif pha ; Save byte 0 of result for later - - iny ; Address byte 1 txa eor #$FF adc (ptr1),y ; Subtract byte 1 diff --git a/libsrc/runtime/ludiv.s b/libsrc/runtime/ludiv.s index 149c98a78..54af4780e 100644 --- a/libsrc/runtime/ludiv.s +++ b/libsrc/runtime/ludiv.s @@ -1,5 +1,6 @@ ; ; Ullrich von Bassewitz, 17.08.1998 +; Christian Krueger, 11-Mar-2017, added 65SC02 optimization ; ; CC65 runtime: division for long unsigned ints ; @@ -8,10 +9,17 @@ .import addysp1 .importzp sp, sreg, tmp3, tmp4, ptr1, ptr2, ptr3, ptr4 + .macpack cpu + tosudiv0ax: +.if (.cpu .bitand ::CPU_ISET_65SC02) + stz sreg + stz sreg+1 +.else ldy #$00 sty sreg sty sreg+1 +.endif tosudiveax: jsr getlop ; Get the paramameters @@ -30,10 +38,15 @@ getlop: sta ptr3 ; Put right operand in place lda sreg+1 sta ptr4+1 +.if (.cpu .bitand ::CPU_ISET_65SC02) + lda (sp) + ldy #1 +.else ldy #0 ; Put left operand in place lda (sp),y - sta ptr1 iny +.endif + sta ptr1 lda (sp),y sta ptr1+1 iny diff --git a/libsrc/runtime/lumod.s b/libsrc/runtime/lumod.s index e290e1167..241801a90 100644 --- a/libsrc/runtime/lumod.s +++ b/libsrc/runtime/lumod.s @@ -1,5 +1,6 @@ ; ; Ullrich von Bassewitz, 27.09.1998 +; Christian Krueger, 11-Mar-2017, added 65SC02 optimization ; ; CC65 runtime: modulo operation for long unsigned ints ; @@ -8,10 +9,17 @@ .import getlop, udiv32 .importzp sreg, tmp3, tmp4, ptr2 + .macpack cpu + tosumod0ax: +.if (.cpu .bitand ::CPU_ISET_65SC02) + stz sreg + stz sreg+1 +.else ldy #$00 sty sreg sty sreg+1 +.endif tosumodeax: jsr getlop ; Get the paramameters diff --git a/libsrc/runtime/lxor.s b/libsrc/runtime/lxor.s index ce21ef35b..4ec9a4129 100644 --- a/libsrc/runtime/lxor.s +++ b/libsrc/runtime/lxor.s @@ -1,5 +1,6 @@ ; ; Ullrich von Bassewitz, 06.08.1998 +; Christian Krueger, 11-Mar-2017, added 65SC02 optimization ; ; CC65 runtime: xor on longs ; @@ -8,16 +9,28 @@ .import addysp1 .importzp sp, sreg, tmp1 + .macpack cpu + tosxor0ax: +.if (.cpu .bitand ::CPU_ISET_65SC02) + stz sreg + stz sreg+1 +.else ldy #$00 sty sreg sty sreg+1 +.endif -tosxoreax: +tosxoreax: +.if (.cpu .bitand ::CPU_ISET_65SC02) + eor (sp) ; byte 0 + ldy #1 +.else ldy #0 eor (sp),y ; byte 0 - sta tmp1 iny +.endif + sta tmp1 txa eor (sp),y ; byte 1 tax diff --git a/libsrc/runtime/makebool.s b/libsrc/runtime/makebool.s index a15b24b93..643f418aa 100644 --- a/libsrc/runtime/makebool.s +++ b/libsrc/runtime/makebool.s @@ -1,5 +1,6 @@ ; ; Ullrich von Bassewitz, 05.10.1998 +; Christian Krueger, 11-Mar-2017, optimization ; ; CC65 runtime: Make boolean according to flags ; @@ -9,14 +10,14 @@ boolne: bne ret1 - ldx #$00 +ret0: ldx #$00 txa rts -booleq: beq ret1 - ldx #$00 - txa +booleq: bne ret0 +ret1: ldx #$00 + lda #$01 rts @@ -44,17 +45,9 @@ boolult: boolugt: - beq L1 + beq ret0 booluge: - bcs ret1 -L1: ldx #$00 + ldx #$00 txa + rol a rts - - -ret1: ldx #$00 - lda #$01 - rts - - - diff --git a/libsrc/runtime/or.s b/libsrc/runtime/or.s index 8570c0cd7..1c2c4125e 100644 --- a/libsrc/runtime/or.s +++ b/libsrc/runtime/or.s @@ -1,5 +1,6 @@ ; ; Ullrich von Bassewitz, 05.08.1998 +; Christian Krueger, 11-Mar-2017, added 65SC02 optimization ; ; CC65 runtime: or on ints ; @@ -8,13 +9,20 @@ .import addysp1 .importzp sp, tmp1 + .macpack cpu + tosora0: ldx #$00 tosorax: +.if (.cpu .bitand ::CPU_ISET_65SC02) + ora (sp) + ldy #1 +.else ldy #0 ora (sp),y - sta tmp1 iny +.endif + sta tmp1 txa ora (sp),y tax diff --git a/libsrc/runtime/rsub.s b/libsrc/runtime/rsub.s index 475a69e76..69ee6da22 100644 --- a/libsrc/runtime/rsub.s +++ b/libsrc/runtime/rsub.s @@ -1,5 +1,6 @@ ; ; Ullrich von Bassewitz, 05.08.1998 +; Christian Krueger, 11-Mar-2017, added 65SC02 optimization ; ; CC65 runtime: sub ints reversed ; @@ -8,6 +9,8 @@ .import addysp1 .importzp sp, tmp1 + .macpack cpu + ; ; AX = AX - TOS ; @@ -15,12 +18,17 @@ tosrsuba0: ldx #0 tosrsubax: - ldy #0 sec +.if (.cpu .bitand CPU_ISET_65SC02) + sbc (sp) + ldy #1 +.else + ldy #0 sbc (sp),y ; lo byte + iny +.endif sta tmp1 ; save lo byte txa - iny sbc (sp),y ; hi byte tax lda tmp1 diff --git a/libsrc/runtime/staxspi.s b/libsrc/runtime/staxspi.s index 90738e0d2..3114f449c 100644 --- a/libsrc/runtime/staxspi.s +++ b/libsrc/runtime/staxspi.s @@ -1,5 +1,6 @@ ; ; Ullrich von Bassewitz, 26.10.2000 +; Christian Krueger, 12-Mar-2017, added 65SC02 optimization ; ; CC65 runtime: Store a/x indirect into address at top of stack with index ; @@ -8,6 +9,8 @@ .import incsp2 .importzp sp, tmp1, ptr1 + .macpack cpu + .proc staxspidx sty tmp1 ; Save Y @@ -15,8 +18,12 @@ ldy #1 lda (sp),y sta ptr1+1 +.if (.cpu .bitand ::CPU_ISET_65SC02) + lda (sp) +.else dey lda (sp),y +.endif sta ptr1 ; Address now in ptr1 ldy tmp1 ; Restore Y iny ; Address high byte diff --git a/libsrc/runtime/swap.s b/libsrc/runtime/swap.s index e91eeca31..d4a74df5f 100644 --- a/libsrc/runtime/swap.s +++ b/libsrc/runtime/swap.s @@ -1,5 +1,6 @@ ; ; Ullrich von Bassewitz, 06.08.1998 +; Christian Krueger, 11-Mar-2017, added 65SC02 optimization ; ; CC65 runtime: swap ax with TOS ; @@ -7,6 +8,8 @@ .export swapstk .importzp sp, ptr4 + .macpack cpu + swapstk: sta ptr4 stx ptr4+1 @@ -15,11 +18,18 @@ swapstk: tax lda ptr4+1 sta (sp),y +.if (.cpu .bitand ::CPU_ISET_65SC02) + lda (sp) + tay + lda ptr4 + sta (sp) + tya +.else dey lda (sp),y pha lda ptr4 sta (sp),y pla +.endif rts ; whew! - diff --git a/libsrc/runtime/xor.s b/libsrc/runtime/xor.s index 825c576d1..e03922926 100644 --- a/libsrc/runtime/xor.s +++ b/libsrc/runtime/xor.s @@ -1,5 +1,6 @@ ; ; Ullrich von Bassewitz, 05.08.1998 +; Christian Krueger, 11-Mar-2017, added 65SC02 optimization ; ; CC65 runtime: xor on ints ; @@ -8,13 +9,20 @@ .import addysp1 .importzp sp, tmp1 + .macpack cpu + tosxora0: ldx #$00 tosxorax: +.if (.cpu .bitand CPU_ISET_65SC02) + eor (sp) + ldy #1 +.else ldy #0 eor (sp),y - sta tmp1 iny +.endif + sta tmp1 txa eor (sp),y tax