From 5a1d5e778e85664f4e6657019348b4756b16eacb Mon Sep 17 00:00:00 2001 From: spth Date: Sun, 19 Apr 2009 11:37:21 +0000 Subject: [PATCH] Applied patch #2762516 git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@5436 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 10 ++++ device/lib/z80/div.s | 3 +- device/lib/z80/memmove.s | 51 +++++++++------------ device/lib/z80/mod.s | 19 +++----- device/lib/z80/mul.s | 17 +++---- device/lib/z80/mulchar.s | 14 +++--- device/lib/z80/shift.s | 98 ++++++++++++++++++---------------------- 7 files changed, 97 insertions(+), 115 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5c781d61..88c620ba 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2009-04-19 Philipp Klaus Krause + * device/lib/z80/shift.s, + device/lib/z80/memmove.s, + device/lib/z80/mul.s, + device/lib/z80/mulchar.s, + device/lib/z80/div.s, + device/lib/z80/mod.s: + Applied patch #2762516 from Marco Bodrato containing minor + improvementsof many Z80 asm routines. + 2009-04-19 Philipp Klaus Krause * support/regression/tests/strtok.c, diff --git a/device/lib/z80/div.s b/device/lib/z80/div.s index f0574eb5..305cd67a 100644 --- a/device/lib/z80/div.s +++ b/device/lib/z80/div.s @@ -39,10 +39,10 @@ __modsuchar_rrx_s:: __divuschar_rrx_s:: ld hl,#2+1 + ld d, h add hl,sp ld e,(hl) - ld d, #0 dec hl ld l,(hl) @@ -228,4 +228,3 @@ __divu16:: ld e,c ; DE = quotient, HL = remainder ex de,hl ; HL = quotient, DE = remainder ret - diff --git a/device/lib/z80/memmove.s b/device/lib/z80/memmove.s index 273a1eb5..d718c910 100644 --- a/device/lib/z80/memmove.s +++ b/device/lib/z80/memmove.s @@ -1,5 +1,5 @@ ; Copyright (C) 2008-2009 -; Philipp Klaus Krause +; Philipp Klaus Krause, Marco Bodrato ; This file is part of the sdcc Library. This library is free ; software; you can redistribute it and/or modify it under the @@ -33,40 +33,33 @@ ; The Z80 has the ldir and lddr instructions, which are perfect for implementing memmove(). _memmove: - push ix - ld ix, #0 - add ix, sp - ld c, 8(ix) - ld b, 9(ix) + pop af + pop hl + pop de + pop bc + push bc + push de + push hl + push af ld a, c or a, b - jr Z, memmove_end - ld e, 4(ix) - ld d, 5(ix) - ld l, 6(ix) - ld h, 7(ix) - ld a, l - sbc hl, de ; or above cleared carry. - ld l, a - ld h, 7(ix) - jr NC, memmove_up + ret Z + push hl + sbc hl, de ; or above cleared carry. + add hl, de ; same carry as the line before + jr C, memmove_up memmove_down: + dec bc add hl, bc - dec hl - ld a, e - add a, c - ld e, a - ld a, d - adc a, b - ld d, a - dec de + ex de, hl + add hl, bc + inc bc lddr - jr memmove_end + pop hl + ret memmove_up: + ex de, hl ldir -memmove_end: - ld l, 4(ix) - ld h, 5(ix) - pop ix + pop hl ret diff --git a/device/lib/z80/mod.s b/device/lib/z80/mod.s index 9d3b0480..77f75daf 100644 --- a/device/lib/z80/mod.s +++ b/device/lib/z80/mod.s @@ -17,19 +17,14 @@ __moduchar_rrx_hds:: ret __moduint_rrx_s:: - ld hl,#2+3 - add hl,sp + pop af + pop hl + pop de + push de + push hl + push af - ld d,(hl) - dec hl - ld e,(hl) - dec hl - ld a,(hl) - dec hl - ld l,(hl) - ld h,a ;; Fall through - __moduint_rrx_hds:: call __divu16 @@ -39,10 +34,10 @@ __moduint_rrx_hds:: __moduschar_rrx_s:: ld hl,#2+1 + ld d, h add hl,sp ld e,(hl) - ld d, #0 dec hl ld l,(hl) diff --git a/device/lib/z80/mul.s b/device/lib/z80/mul.s index 61ff5cf3..e81ac800 100644 --- a/device/lib/z80/mul.s +++ b/device/lib/z80/mul.s @@ -1,17 +1,12 @@ .area _CODE __mulint_rrx_s:: - ld hl,#2 - add hl,sp - - ld e,(hl) - inc hl - ld d,(hl) - inc hl - ld a,(hl) - inc hl - ld h,(hl) - ld l,a + pop af + pop hl + pop de + push de + push hl + push af ;; Fall through diff --git a/device/lib/z80/mulchar.s b/device/lib/z80/mulchar.s index 7217dd88..b77abcb8 100644 --- a/device/lib/z80/mulchar.s +++ b/device/lib/z80/mulchar.s @@ -7,12 +7,12 @@ ; still called from some asm files in this directory. __muluchar_rrx_s:: ld hl, #2+1 + ld d, h add hl, sp ld e, (hl) dec hl ld h, (hl) - ld l, #0 - ld d, l + ld l, d ld b, #8 muluchar_rrx_s_loop: add hl, hl @@ -26,22 +26,22 @@ muluchar_rrx_s_noadd: __mulsuchar_rrx_s:: ld hl,#2+1 + ld b, h add hl,sp ld e,(hl) dec hl ld c,(hl) - ld b, #0 jr signexte __muluschar_rrx_s:: - ld hl,#2+1 + ld hl,#2 + ld b, h add hl,sp - ld c,(hl) - ld b, #0 - dec hl ld e,(hl) + inc hl + ld c,(hl) jr signexte ;; Originally from GBDK by Pascal Felber. diff --git a/device/lib/z80/shift.s b/device/lib/z80/shift.s index a9ae6bfe..43b94f5a 100644 --- a/device/lib/z80/shift.s +++ b/device/lib/z80/shift.s @@ -3,83 +3,73 @@ __rrulong_rrx_s:: ld hl,#2+4 add hl,sp - ld c,(hl) - dec hl - ld d,(hl) - dec hl - ld e,(hl) - dec hl ld a,(hl) - dec hl - ld l,(hl) - ld h,a - - ld a,c -1$: or a,a + pop bc + pop hl + pop de + push de + push hl + push bc ret Z - - rr d - rr e - rr h + ld b,a + ld a,e +1$: + srl d + rra + rr h rr l - dec a - jp 1$ + djnz 1$ + ld e,a + ret __rrslong_rrx_s:: ld hl,#2+4 add hl,sp - ld c,(hl) - dec hl - ld d,(hl) - dec hl - ld e,(hl) - dec hl ld a,(hl) - dec hl - ld l,(hl) - ld h,a - - ld a,c -1$: or a,a + pop bc + pop hl + pop de + push de + push hl + push bc ret Z - + ld b,a + ld a,e +2$: sra d - rr e - rr h + rra + rr h rr l - dec a - jp 1$ + djnz 2$ + ld e,a + ret __rlslong_rrx_s:: __rlulong_rrx_s:: ld hl,#2+4 add hl,sp - ld c,(hl) - dec hl - ld d,(hl) - dec hl - ld e,(hl) - dec hl ld a,(hl) - dec hl - ld l,(hl) - ld h,a - - ld a,c -1$: or a,a + pop bc + pop hl + pop de + push de + push hl + push bc ret Z + ld b,a + ld a,e +3$: + add hl,hl + rla + rl d - rl l - rl h - rl e - rl d - - dec a - jp 1$ + djnz 3$ + ld e,a + ret -- 2.30.2