Added timing and asm implementations of strcpy, strcmp, memcpy.
authormichaelh <michaelh@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Mon, 7 Feb 2000 05:35:29 +0000 (05:35 +0000)
committermichaelh <michaelh@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Mon, 7 Feb 2000 05:35:29 +0000 (05:35 +0000)
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
device/lib/z80/asm_strings.s
device/lib/z80/crt0.s
device/lib/z80/string.c
support/tests/dhrystone/dhry.c

index 33a4159ccbf4b13b5768219213732a5ea9480f86..27d5d2c973d30dc9937c73005fca38ab5226f0cc 100644 (file)
@@ -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)
index da0aa8c5cb2db979ba55acdddc8adca6b2891683..fd26392779e4e1a27223e3369045ad800346a6fb 100644 (file)
@@ -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
index 9d51c51aaee1a57d95faae08b054b217548f66e4..56fade760693b17629e7fe05c4ab5d6f0903444d 100644 (file)
        .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
index 4e3583b22afd82c8998416a853e546967b69cd5f..ea7d5b88a9a66f6258d2a1a04ee42abc213ab0ef 100644 (file)
@@ -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;
 }
+
index 0848672a3cf470cc1a891f2a9c72960b067ac9c7..67ba7e5288193e4714ad61571d4806fe33c44f66 100644 (file)
@@ -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)