From 04d0542968f763a0b8b1a75b24f3db04a321bb2a Mon Sep 17 00:00:00 2001 From: michaelh Date: Mon, 7 Feb 2000 05:35:29 +0000 Subject: [PATCH] Added timing and asm implementations of strcpy, strcmp, memcpy. Now up to 174 d/s. git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@74 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- device/lib/z80/Makefile | 2 +- device/lib/z80/asm_strings.s | 73 +++++++++++++++++++++++++++++++++- device/lib/z80/crt0.s | 32 ++++++++++++++- device/lib/z80/string.c | 7 +++- support/tests/dhrystone/dhry.c | 10 ++++- 5 files changed, 119 insertions(+), 5 deletions(-) diff --git a/device/lib/z80/Makefile b/device/lib/z80/Makefile index 33a4159c..27d5d2c9 100644 --- a/device/lib/z80/Makefile +++ b/device/lib/z80/Makefile @@ -5,7 +5,7 @@ TOPDIR = ../../.. SCC = $(TOPDIR)/bin/sdcc -mz80 -v SAS = as-z80 -OBJ = div.o mul.o putchar.o string.o printf.o +OBJ = div.o mul.o putchar.o string.o printf.o asm_strings.o LIB = z80.lib CC = $(SCC) AS = $(SAS) diff --git a/device/lib/z80/asm_strings.s b/device/lib/z80/asm_strings.s index da0aa8c5..fd263927 100644 --- a/device/lib/z80/asm_strings.s +++ b/device/lib/z80/asm_strings.s @@ -14,7 +14,7 @@ _strcpy:: ld e,8(ix) ld d,9(ix) - push de + push hl 1$: ld a,(de) ld (hl),a @@ -28,4 +28,75 @@ _strcpy:: pop de ret +; void *memcpy(void *dest, const void *source, int count) +_memcpy:: + push de + push bc + push ix + ld ix,#0 + add ix,sp + ld l,8(ix) + ld h,9(ix) + ld e,10(ix) + ld d,11(ix) + ld c,12(ix) + ld b,13(ix) + + inc b + inc c + push hl + + jr 2$ +1$: + ld a,(de) + ld (hl),a + inc de + inc hl +2$: + dec c + jr nz,1$ + dec b + jr nz,1$ + + pop hl + pop ix + pop bc + pop de + ret + +; int strcmp(const char *s1, const char *s2) +_strcmp:: + push de + push ix + ld ix,#0 + add ix,sp + ld e,6(ix) + ld d,7(ix) + ld l,8(ix) + ld h,9(ix) + + jr 1$ +2$: + ld a,(de) + sub (hl) + jr nz,4$ + ;; A == 0 + cp (hl) + jr z,3$ +1$: + inc de + inc hl + jr 2$ + +3$: + ld hl,#0 + jr 5$ +4$: + ld hl,#1 + jr nc,5$ + ld hl,#-1 +5$: + pop ix + pop de + ret \ No newline at end of file diff --git a/device/lib/z80/crt0.s b/device/lib/z80/crt0.s index 9d51c51a..56fade76 100644 --- a/device/lib/z80/crt0.s +++ b/device/lib/z80/crt0.s @@ -19,14 +19,20 @@ .org 0x30 reti .org 0x38 - reti + jp __int .org 0x150 init: ;; Stack at the top of memory. ld sp,#0xffff + ld a,#0x01 + out (0x09),a + ld a,#0xEF + out (0x07),a + ;; Use _main instead of main to bypass sdcc's intelligence + ei call __main jp _exit @@ -34,7 +40,31 @@ init: .area _CODE .area _DATA +__ticks: + .ds 2 .area _CODE +__int: + push af + push hl + ld hl,#__ticks + inc (hl) + jr nz,1$ + inc hl + inc (hl) +1$: + pop hl + pop af + ei + ret + +_clock:: + ld hl,#__ticks + ld a,(hl) + inc hl + ld h,(hl) + ld l,a + ret + _getsp:: ld hl,#0 add hl,sp diff --git a/device/lib/z80/string.c b/device/lib/z80/string.c index 4e3583b2..ea7d5b88 100644 --- a/device/lib/z80/string.c +++ b/device/lib/z80/string.c @@ -1,13 +1,16 @@ /* Dumb strings stub. Wanted a quick hack for now - will use the libc version later. */ +#if 0 char *strcpy(char *dest, const char *source) { char *ret = dest; while (*dest++ = *source++); return ret; } +#endif +#if 0 void *memcpy(void *dest, const void *source, int count) { char *d = dest; @@ -17,8 +20,9 @@ void *memcpy(void *dest, const void *source, int count) return dest; } +#endif -int strcmp(const char *s1, const char *s2) +int __strcmp(const char *s1, const char *s2) { int ret = 0; @@ -31,3 +35,4 @@ int strcmp(const char *s1, const char *s2) return 1; return 0; } + diff --git a/support/tests/dhrystone/dhry.c b/support/tests/dhrystone/dhry.c index 0848672a..67ba7e52 100644 --- a/support/tests/dhrystone/dhry.c +++ b/support/tests/dhrystone/dhry.c @@ -71,6 +71,7 @@ Boolean Func_3 (Enumeration Enum_Par_Val); void printf(const char *format, ...); void exit(int val); +unsigned clock(void); /*#define DPRINTF(_a) printf _a*/ #define DPRINTF(_a) @@ -92,6 +93,7 @@ int main(void) Str_30 Str_2_Loc; REG int Run_Index; REG int Number_Of_Runs; + unsigned endTime; printf("[dhry]\n"); @@ -113,7 +115,8 @@ int main(void) /* Warning: With 16-Bit processors and Number_Of_Runs > 32000, */ /* overflow may occur for this array element. */ - Number_Of_Runs = 5000; + Number_Of_Runs = 32000; + clock(); /* Main test loop */ for (Run_Index = 1; Run_Index <= Number_Of_Runs; ++Run_Index) { @@ -185,6 +188,8 @@ int main(void) printf("Run_Index = %d\n", Run_Index); + endTime = clock(); + printf ("Execution ends\n"); printf ("\n"); printf ("Final values of the variables used in the benchmark:\n"); @@ -237,6 +242,9 @@ int main(void) printf ("Str_2_Loc: %s\n", Str_2_Loc); printf (" should be: DHRYSTONE PROGRAM, 2'ND STRING\n"); printf ("\n"); + + printf("Time: %u secs\n", endTime); + printf("Dhrystones/tick = %u\n", Number_Of_Runs / endTime); } void Proc_1 (REG Rec_Pointer Ptr_Val_Par) -- 2.30.2