From c413c5feebe720058f111b682ddde9696136af9a Mon Sep 17 00:00:00 2001 From: cuz Date: Sat, 17 Nov 2001 11:25:12 +0000 Subject: [PATCH] Several SBC optimizations suggested by Piotr Fusik git-svn-id: svn://svn.cc65.org/cc65/trunk@1121 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- libsrc/runtime/ldec.s | 10 +++++----- libsrc/runtime/lsub.s | 19 +++++++++---------- libsrc/runtime/lsubeq.s | 19 +++++++++---------- libsrc/runtime/lsubeqsp.s | 17 ++++++++--------- libsrc/runtime/sub.s | 29 ++++++++++++++--------------- libsrc/runtime/subeqsp.s | 17 ++++++++--------- 6 files changed, 53 insertions(+), 58 deletions(-) diff --git a/libsrc/runtime/ldec.s b/libsrc/runtime/ldec.s index 404019b81..a87323e61 100644 --- a/libsrc/runtime/ldec.s +++ b/libsrc/runtime/ldec.s @@ -5,13 +5,13 @@ ; .export deceaxy - .importzp ptr4, sreg + .importzp sreg, tmp1 deceaxy: - sty ptr4 + sty tmp1 sec - sbc ptr4 - sta ptr4 + sbc tmp1 + sta tmp1 txa sbc #0 tax @@ -21,6 +21,6 @@ deceaxy: lda sreg+1 sbc #0 sta sreg+1 - lda ptr4 + lda tmp1 rts diff --git a/libsrc/runtime/lsub.s b/libsrc/runtime/lsub.s index 8854e9e50..0ba716a9d 100644 --- a/libsrc/runtime/lsub.s +++ b/libsrc/runtime/lsub.s @@ -9,19 +9,18 @@ ; .export tossubeax .import addysp1 - .importzp sp, sreg, tmp1, tmp2 + .importzp sp, sreg tossubeax: ldy #0 sec - sta tmp1 - lda (sp),y - sbc tmp1 ; byte 0 - sta tmp2 ; use as temp storage + eor #$FF + adc (sp),y ; byte 0 + pha ; Save low byte iny - stx tmp1 - lda (sp),y - sbc tmp1 ; byte 1 + txa + eor #$FF + adc (sp),y ; byte 1 tax iny lda (sp),y @@ -31,6 +30,6 @@ tossubeax: lda (sp),y sbc sreg+1 ; byte 3 sta sreg+1 - lda tmp2 ; load byte 0 - jmp addysp1 ; drop TOS + pla ; Restore byte 0 + jmp addysp1 ; Drop TOS diff --git a/libsrc/runtime/lsubeq.s b/libsrc/runtime/lsubeq.s index 974626c14..acc6a2861 100644 --- a/libsrc/runtime/lsubeq.s +++ b/libsrc/runtime/lsubeq.s @@ -1,4 +1,4 @@ -; +; ; Ullrich von Bassewitz, 07.04.2000 ; ; CC65 runtime: -= operator @@ -8,7 +8,7 @@ ; .export lsubeq1, lsubeqa, lsubeq - .importzp sreg, ptr1, tmp1 + .importzp sreg, ptr1 lsubeq1: @@ -23,16 +23,15 @@ lsubeq: sty ptr1+1 ; Store high byte of address ldy #$00 ; Address low byte sec - sta tmp1 - lda (ptr1),y ; Load byte 0 - sbc tmp1 + eor #$FF + adc (ptr1),y ; Subtract byte 0 sta (ptr1),y pha ; Save byte 0 of result for later iny ; Address byte 1 - stx tmp1 - lda (ptr1),y ; Load byte 1 - sbc tmp1 + txa + eor #$FF + adc (ptr1),y ; Subtract byte 1 sta (ptr1),y tax @@ -48,9 +47,9 @@ lsubeq: sty ptr1+1 ; Store high byte of address sta (ptr1),y sta sreg+1 - pla ; Retrieve byte 0 of result + pla ; Retrieve byte 0 of result - rts ; Done + rts ; Done diff --git a/libsrc/runtime/lsubeqsp.s b/libsrc/runtime/lsubeqsp.s index 6474f4059..c679c8806 100644 --- a/libsrc/runtime/lsubeqsp.s +++ b/libsrc/runtime/lsubeqsp.s @@ -2,24 +2,23 @@ ; Ullrich von Bassewitz, 08.10.1998 ; ; CC65 runtime: -= operator for longs on the stack -; +; .export lsubeq0sp, lsubeqysp - .importzp sp, sreg, tmp1, tmp2 + .importzp sp, sreg lsubeq0sp: ldy #0 lsubeqysp: sec - sta tmp1 - stx tmp2 - lda (sp),y - sbc tmp1 + eor #$FF + adc (sp),y sta (sp),y - pha + pha ; Save low byte iny - lda (sp),y - sbc tmp2 + txa + eor #$FF + adc (sp),y sta (sp),y tax iny diff --git a/libsrc/runtime/sub.s b/libsrc/runtime/sub.s index cb7ae6de7..1240737ad 100644 --- a/libsrc/runtime/sub.s +++ b/libsrc/runtime/sub.s @@ -6,7 +6,7 @@ .export tossuba0, tossubax .import addysp1 - .importzp sp, ptr1 + .importzp sp ; ; AX = TOS - AX @@ -15,22 +15,21 @@ tossuba0: ldx #0 tossubax: - sta ptr1 - stx ptr1+1 + sec + eor #$FF .ifpc02 - lda (sp) ; Get lo byte - ldy #1 ; Hi index + adc (sp) + ldy #1 .else ldy #0 - lda (sp),y ; Lo byte - iny ; Hi index + adc (sp),y ; Subtract low byte + iny .endif - sec - sbc ptr1 - sta ptr1 ; save lo byte - lda (sp),y - sbc ptr1+1 - tax - lda ptr1 - jmp addysp1 ; drop TOS, set condition codes + pha ; Save high byte + txa + eor #$FF + adc (sp),y ; Subtract high byte + tax ; High byte into X + pla ; Restore low byte + jmp addysp1 ; drop TOS diff --git a/libsrc/runtime/subeqsp.s b/libsrc/runtime/subeqsp.s index a6f75798f..8a2e3e3ee 100644 --- a/libsrc/runtime/subeqsp.s +++ b/libsrc/runtime/subeqsp.s @@ -5,23 +5,22 @@ ; .export subeq0sp, subeqysp - .importzp sp, tmp1, tmp2 + .importzp sp subeq0sp: ldy #0 subeqysp: sec - sta tmp1 - stx tmp2 - lda (sp),y - sbc tmp1 + eor #$FF + adc (sp),y sta (sp),y - pha + pha ; Save low byte iny - lda (sp),y - sbc tmp2 + txa + eor #$FF + adc (sp),y sta (sp),y tax - pla + pla ; Restore low byte rts -- 2.39.5