New code for the shift functions

git-svn-id: svn://svn.cc65.org/cc65/trunk@3143 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz
2004-07-05 22:24:06 +00:00
parent 07419b62f8
commit c122f18605
7 changed files with 240 additions and 406 deletions

View File

@@ -1,95 +1,44 @@
;
; Ullrich von Bassewitz, 20.09.1998
; Ullrich von Bassewitz, 2004-06-30
;
; CC65 runtime: left shift support for longs
; CC65 runtime: left shift support for long and unsigned long
;
; Note: The standard declares a shift count that is negative or >= the
; bitcount of the shifted type for undefined behaviour.
;
; Note^2: The compiler knowns about the register/zero page usage of this
; function, so you need to change the compiler source if you change it!
;
.export tosasleax, tosshleax
.import addysp1
.importzp sp, sreg, ptr1, ptr2
.import popeax
.importzp sreg, tmp1
tosshleax:
tosasleax:
and #$1F ; Bring the shift count into a valid range
sta tmp1 ; Save it
; Get the lhs from stack into ptr1/ptr2
jsr popeax ; Get the left hand operand
pha
ldy #0
lda (sp),y
sta ptr1
iny
lda (sp),y
sta ptr1+1
iny
lda (sp),y
sta ptr2
iny
lda (sp),y
sta ptr2+1
pla
jsr addysp1
ldy tmp1 ; Get shift count
beq L9 ; Bail out if shift count zero
stx tmp1 ; Save byte 1
; Check for shift overflow or zero shift
; Do the actual shift. Faster solutions are possible but need a lot more code.
tay ; Low byte of shift count into y
txa ; Get byte 2
ora sreg
ora sreg+1 ; Check high 24 bit
bne @L6 ; Shift count too large
cpy #32
bcs @L6
cpy #0 ; Shift count zero?
beq @L5
; We must shift. Shift by multiples of eight if possible
tya
@L1: cmp #8
bcc @L3
sbc #8
ldx ptr2
stx ptr2+1
ldx ptr1+1
stx ptr2
ldx ptr1
stx ptr1+1
ldx #0
stx ptr1
beq @L1
; Shift count is now less than eight. Do a real shift.
@L3: tay ; Shift count to Y
lda ptr1 ; Get one byte into A for speed
cpy #0
beq @L4a ; Jump if done
@L4: asl a
rol ptr1+1
rol ptr2
rol ptr2+1
dey
bne @L4
; Put the result in place
@L4a: ldx ptr2
stx sreg
ldx ptr2+1
stx sreg+1
ldx ptr1+1
@L5: rts
; Jump here if shift count overflow
@L6: lda #0
sta sreg+1
sta sreg
tax
rts
L2: asl a
rol tmp1
rol sreg
rol sreg+1
dey
bne L2
; Shift done
ldx tmp1
L9: rts