From adbf81ce9358d49c33aa068aeaac2ffaf8738a12 Mon Sep 17 00:00:00 2001 From: epetrich Date: Sun, 7 Sep 2003 07:50:07 +0000 Subject: [PATCH] * device/include/string.h: added size_t typedef, changed prototypes to use size_t, eliminated separate reentrant and non-reentrant declarations, added _memmove declaration * device/lib/_memcpy.c: changed to use size_t instead of int, changed /4 to >>2 to avoid division library call * device/lib/_memcmp.c, * device/lib/_memset.c, * device/lib/_strncat.c, * device/lib/_strncpy.c, * device/lib/_strncmp.c: changed to use size_t instead of int * device/lib/_memmove.c: new file (fixed bug #772294) * device/lib/Makefile.in: added _memmove.c * device/lib/z80/asm_strings.s: fixed bug #772290 * support/regression/tests/bitfields.c: attempt to fix host assertion failure on amd64-unknown-linux2.2 git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2881 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 22 +++++ device/include/string.h | 45 +++------- device/lib/Makefile.in | 6 +- device/lib/_memcmp.c | 2 +- device/lib/_memcpy.c | 4 +- device/lib/_memmove.c | 124 +++++++++++++++++++++++++++ device/lib/_memset.c | 2 +- device/lib/_strncat.c | 2 +- device/lib/_strncmp.c | 2 +- device/lib/_strncpy.c | 2 +- device/lib/z80/asm_strings.s | 38 ++++---- support/regression/tests/bitfields.c | 2 +- 12 files changed, 183 insertions(+), 68 deletions(-) create mode 100644 device/lib/_memmove.c diff --git a/ChangeLog b/ChangeLog index 0fa92ba5..6f0bdfb0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,23 @@ +2003-09-07 Erik Petrich + + * device/include/string.h: added size_t typedef, changed + prototypes to use size_t, eliminated separate reentrant and + non-reentrant declarations, added _memmove declaration + * device/lib/_memcpy.c: changed to use size_t instead of int, + changed /4 to >>2 to avoid division library call + * device/lib/_memcmp.c, + * device/lib/_memset.c, + * device/lib/_strncat.c, + * device/lib/_strncpy.c, + * device/lib/_strncmp.c: changed to use size_t instead of int + * device/lib/_memmove.c: new file (fixed bug #772294) + * device/lib/Makefile.in: added _memmove.c + * device/lib/z80/asm_strings.s: fixed bug #772290 + * support/regression/tests/bitfields.c: attempt to fix host assertion + failure on amd64-unknown-linux2.2 + 2003-09-06 Erik Petrich + * src/z80/gen.c (aopPut, spillPairReg): fixed bug #800998 * src/z80/gen.c (genFunction, genEndFunction): fixed "bug" #774700 * as/z80/asmain.c (main): fixed bug #801766 @@ -9,10 +28,12 @@ compilers 2003-09-05 Erik Petrich + * src/SDCCast.c (isConformingBody): fixed loop reversal bug reported in bug #800609 2003-09-04 Vangelis Rokas + * Top header beautifications in src/pic16 directory: device.c, device.h, gen.c, gen.h, genarith.c, glue.c, pcode.c, pcodeflow.c, pcodeflow.h, pcode.h, pcodepeep.c, pcoderegs.c, @@ -34,6 +55,7 @@ aren't part of the nRegs tally. 2003-08-31 Vangelis Rokas + * src/pic16/main.c: corrected offsets of interrupt vectors in _pic16_genIVT() * src/pic16/pcode.c: fix to disable inserting BANKSEL directive before instructions that use the _STATUS register diff --git a/device/include/string.h b/device/include/string.h index 9e0da877..2800db73 100644 --- a/device/include/string.h +++ b/device/include/string.h @@ -26,44 +26,21 @@ #ifndef __SDC51_STRING_H #define __SDC51_STRING_H 1 -#if !defined(SDCC_mcs51) && !defined(SDCC_ds390) -#define reentrant -#endif - #ifndef NULL # define NULL (void *)0 #endif -#define memmove memcpy - -#ifdef SDCC_STACK_AUTO - -extern char *strcpy (char *, char *) reentrant ; -extern char *strncpy(char *, char *,int ) reentrant ; -extern char *strcat (char *, char *) reentrant ; -extern char *strncat(char *, char *,int ) reentrant ; -extern int strcmp (char *, char *) reentrant ; -extern int strncmp(char *, char *,int ) reentrant ; -extern char *strchr (char *, char ) reentrant ; -extern char *strrchr(char *, char ) reentrant ; -extern int strspn (char *, char *) reentrant ; -extern int strcspn(char *, char *) reentrant ; -extern char *strpbrk(char *, char *) reentrant ; -extern char *strstr (char *, char *) reentrant ; -extern int strlen (char * ) reentrant ; -extern char *strtok (char *, char *) reentrant ; -extern void *memcpy (void *, void *, int ) reentrant ; -extern int memcmp (void *, void *, int ) reentrant ; -extern void *memset (void *, unsigned char , int ) reentrant ; - -#else +#ifndef _SIZE_T_DEFINED +# define _SIZE_T_DEFINED + typedef unsigned int size_t; +#endif extern char *strcpy (char *, char *) ; -extern char *strncpy(char *, char *,int ) ; +extern char *strncpy(char *, char *, size_t ) ; extern char *strcat (char *, char *) ; -extern char *strncat(char *, char *,int ) ; +extern char *strncat(char *, char *, size_t ) ; extern int strcmp (char *, char *) ; -extern int strncmp(char *, char *,int ) ; +extern int strncmp(char *, char *, size_t ) ; extern char *strchr (char *, char ) ; extern char *strrchr(char *, char ) ; extern int strspn (char *, char *) ; @@ -72,14 +49,14 @@ extern char *strpbrk(char *, char *) ; extern char *strstr (char *, char *) ; extern int strlen (char * ) ; extern char *strtok (char *, char *) ; -extern void *memcpy (void *, void *, int ) ; -extern int memcmp (void *, void *, int ) ; -extern void *memset (void *, unsigned char , int ) ; +extern void *memcpy (void *, void *, size_t ) ; +extern int memcmp (void *, void *, size_t ) ; +extern void *memset (void *, unsigned char , size_t ) ; +extern void *memmove (void *, void *, size_t ) ; #if SDCC_ds390 extern void xdata * memcpyx(void xdata *, void xdata *, int) _naked; #endif -#endif #endif diff --git a/device/lib/Makefile.in b/device/lib/Makefile.in index fe0bc318..54fd5c05 100644 --- a/device/lib/Makefile.in +++ b/device/lib/Makefile.in @@ -52,7 +52,7 @@ SOURCES = _atof.c _atoi.c _atol.c _autobaud.c _bp.c _schar2fs.c \ _islower.c _isprint.c _ispunct.c _isspace.c \ _isupper.c _isxdigit.c _itoa.c _ltoa.c \ _slong2fs.c _memcmp.c \ - _memcpy.c _memset.c _modsint.c _modslong.c \ + _memcpy.c _memmove.c _memset.c _modsint.c _modslong.c \ _moduint.c _modulong.c _mulint.c _mullong.c \ _ser.c _setjmp.c \ _spx.c _startup.c _strchr.c _strcmp.c _strcpy.c \ @@ -73,7 +73,7 @@ Z80SOURCES = _atof.c _atoi.c \ _iscntrl.c _isdigit.c _isgraph.c \ _islower.c _isprint.c _ispunct.c _isspace.c \ _isupper.c _isxdigit.c _memcmp.c \ - _memcpy.c _memset.c \ + _memcpy.c _memmove.c _memset.c \ _startup.c _strchr.c _strcmp.c _strcpy.c \ _strcspn.c _strlen.c _strncat.c _strncmp.c \ _strncpy.c _strpbrk.c _strrchr.c _strspn.c \ @@ -103,7 +103,7 @@ XA51SOURCES = _atof.c _atoi.c _atol.c _schar2fs.c \ _sint2fs.c _iscntrl.c _isdigit.c _isgraph.c \ _islower.c _isprint.c _ispunct.c _isspace.c \ _isupper.c _isxdigit.c _slong2fs.c _memcmp.c \ - _memcpy.c _memset.c _modsint.c _modslong.c \ + _memcpy.c _memmove.c _memset.c _modsint.c _modslong.c \ _moduint.c _modulong.c _mulint.c _mullong.c \ _strchr.c _strcmp.c _strcpy.c \ _strcspn.c _strlen.c _strncat.c _strncmp.c \ diff --git a/device/lib/_memcmp.c b/device/lib/_memcmp.c index 8a2cac86..08b06347 100644 --- a/device/lib/_memcmp.c +++ b/device/lib/_memcmp.c @@ -26,7 +26,7 @@ int memcmp ( void * buf1, void * buf2, - int count + size_t count ) { if (!count) diff --git a/device/lib/_memcpy.c b/device/lib/_memcpy.c index 38d01ad8..38681c84 100644 --- a/device/lib/_memcpy.c +++ b/device/lib/_memcpy.c @@ -29,7 +29,7 @@ void * memcpy ( void * dst, void * src, - int acount + size_t acount ) { #if _SDCC_Z80_STYLE_LIB_OPT @@ -39,7 +39,7 @@ void * memcpy ( char * d = dst; char * s = src; /* PENDING: Divide first to get around sign problems */ - int count = -(acount/4); + int count = -(acount >> 2); while (count) { *d++ = *s++; diff --git a/device/lib/_memmove.c b/device/lib/_memmove.c new file mode 100644 index 00000000..5144e3ba --- /dev/null +++ b/device/lib/_memmove.c @@ -0,0 +1,124 @@ +/*------------------------------------------------------------------------- + _memmove.c - part of string library functions + + Adapted By - Erik Petrich . epetrich@users.sourceforge.net + from _memcpy.c which was originally + Written By - Sandeep Dutta . sandeep.dutta@usa.net (1999) + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this program; if not, write to the Free Software + Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + In other words, you are welcome to use, share and improve this program. + You are forbidden to forbid anyone else to use, share and improve + what you give them. Help stamp out software-hoarding! +-------------------------------------------------------------------------*/ +#include "string.h" +#include + +#ifndef _SDCC_PORT_PROVIDES_MEMMOVE +#define _SDCC_PORT_PROVIDES_MEMMOVE 0 +#endif + +#if !_SDCC_PORT_PROVIDES_MEMMOVE + +void * memmove ( + void * dst, + void * src, + size_t acount + ) +{ +#if _SDCC_Z80_STYLE_LIB_OPT + +#pragma NOINDUCTION + + char * d; + char * s; + /* PENDING: Divide first to get around sign problems */ + int count = -(acount >> 2); + + if (((int)src < (int)dst) && ((((int)src)+acount) > (int)dst)) { + /* + * copy from higher addresses to lower addresses + */ + d = ((char *)dst)+acount-1; + s = ((char *)src)+acount-1; + while (count) { + *d-- = *s--; + *d-- = *s--; + *d-- = *s--; + *d-- = *s--; + count++; + } + + if (acount & 2) { + *d-- = *s--; + *d-- = *s--; + } + if (acount & 1) { + *d-- = *s--; + } + } + else { + /* + * copy from lower addresses to higher addresses + */ + d = dst; + s = src; + while (count) { + *d++ = *s++; + *d++ = *s++; + *d++ = *s++; + *d++ = *s++; + count++; + } + + if (acount & 2) { + *d++ = *s++; + *d++ = *s++; + } + if (acount & 1) { + *d++ = *s++; + } + } + return dst; +#else + void * ret = dst; + char * d; + char * s; + + if (((int)src < (int)dst) && ((((int)src)+acount) > (int)dst)) { + /* + * copy from higher addresses to lower addresses + */ + d = ((char *)dst)+acount-1; + s = ((char *)src)+acount-1; + while (acount--) { + *d-- = *s--; + } + } + else { + /* + * copy from lower addresses to higher addresses + */ + d = dst; + s = src; + while (acount--) { + *d++ = *s++; + } + } + + return(ret); +#endif +} +#endif diff --git a/device/lib/_memset.c b/device/lib/_memset.c index 9d903d2c..9bd603ed 100644 --- a/device/lib/_memset.c +++ b/device/lib/_memset.c @@ -26,7 +26,7 @@ void * memset ( void * buf, unsigned char ch , - int count) + size_t count) { register unsigned char * ret = buf; diff --git a/device/lib/_strncat.c b/device/lib/_strncat.c index 9aae0ff2..82685880 100644 --- a/device/lib/_strncat.c +++ b/device/lib/_strncat.c @@ -26,7 +26,7 @@ char * strncat ( char * front, char * back, - int count + size_t count ) { char *start = front; diff --git a/device/lib/_strncmp.c b/device/lib/_strncmp.c index c55b5fa6..f22ed3b9 100644 --- a/device/lib/_strncmp.c +++ b/device/lib/_strncmp.c @@ -26,7 +26,7 @@ int strncmp ( char * first, char * last, - int count + size_t count ) { if (!count) diff --git a/device/lib/_strncpy.c b/device/lib/_strncpy.c index 19b8a1a0..fd5f445c 100644 --- a/device/lib/_strncpy.c +++ b/device/lib/_strncpy.c @@ -26,7 +26,7 @@ char *strncpy ( char * d, char * s, - int n ) + size_t n ) { register char * d1 = d; diff --git a/device/lib/z80/asm_strings.s b/device/lib/z80/asm_strings.s index a6527fb9..1796b4a5 100644 --- a/device/lib/z80/asm_strings.s +++ b/device/lib/z80/asm_strings.s @@ -51,29 +51,21 @@ __memcpy_rrx_s:: ;; LDIR: do; *DE = *HL; HL++; BC--; while BC != 0 ;; All registers are already saved. - ld hl,#2 - add hl,sp - ld e,(hl) - inc hl - ld d,(hl) - inc hl - ld a,(hl) - inc hl - ld b,(hl) - inc hl - ld c,(hl) - inc hl - ld h,(hl) - ld l,a - ld a,h - ld h,b - ld b,a - - ;; Pending: could optimise this check to occur earlier. - or c - ret z - - ldir + pop iy ; iy = return address + pop de ; de = destination pointer + pop hl ; hl = source pointer + pop bc ; bc = count + push bc + push hl + push de + ld a,b + or c + jr z,1$ + ldir +1$: + pop hl ; return hl = original destination pointer + push hl + jp (iy) ret ; int strcmp(const char *s1, const char *s2) diff --git a/support/regression/tests/bitfields.c b/support/regression/tests/bitfields.c index cf7d004b..76b9df18 100644 --- a/support/regression/tests/bitfields.c +++ b/support/regression/tests/bitfields.c @@ -100,7 +100,7 @@ testBitfieldSizeof(void) ASSERT( sizeof(size2c_bf) >= 2); ASSERT( sizeof(size2d_bf) >= 2); ASSERT( sizeof(size3a_bf) >= 2); - ASSERT( sizeof(size1a_bf) == sizeof(size1b_bf)); + ASSERT( sizeof(size1a_bf) <= sizeof(size1b_bf)); ASSERT( sizeof(size1a_bf) < sizeof(size2a_bf)); /* Some SDCC specific assertions. SDCC uses 8 bit storage units. -- 2.47.2