From e100e9c2fb6d222c1dcca93b7fcd9de1ee1144b5 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Thu, 17 Nov 2011 15:51:56 +0800 Subject: [PATCH] Usermode/libc - Fixing little bugs/speed issues --- Usermode/Libraries/Makefile.cfg | 2 +- Usermode/Libraries/libc.so_src/string.c | 38 ++++++++++++++++++------- Usermode/include/errno.h | 7 +++++ Usermode/include/string.h | 2 +- 4 files changed, 36 insertions(+), 13 deletions(-) diff --git a/Usermode/Libraries/Makefile.cfg b/Usermode/Libraries/Makefile.cfg index c3b24667..d7dab2d6 100644 --- a/Usermode/Libraries/Makefile.cfg +++ b/Usermode/Libraries/Makefile.cfg @@ -7,5 +7,5 @@ MAKEDEP = $(CC) -M ASFLAGS += -D ARCHDIR=$(ARCHDIR) -D __ASSEMBLER__=1 CPPFLAGS := -I$(ACESSDIR)/Usermode/include/ -DARCHDIR=$(ARCHDIR) -DARCHDIR_is_$(ARCHDIR)=1 -CFLAGS := -g -Wall -fPIC -fno-builtin -fno-stack-protector $(CPPFLAGS) +CFLAGS := -g -Wall -fPIC -fno-stack-protector -O3 LDFLAGS := -g -nostdlib -shared -I/Acess/Libs/ld-acess.so -lld-acess -e SoMain -x -L$(OUTPUTDIR)Libs/ --no-undefined diff --git a/Usermode/Libraries/libc.so_src/string.c b/Usermode/Libraries/libc.so_src/string.c index a5becf8b..e9e15741 100644 --- a/Usermode/Libraries/libc.so_src/string.c +++ b/Usermode/Libraries/libc.so_src/string.c @@ -14,7 +14,7 @@ */ EXPORT int strcmp(const char *s1, const char *s2) { - while(*s1 == *s2 && *s1 != '\0' && *s2 != '\0') { + while(*s1 && *s1 == *s2) { s1++; s2++; } return (int)*s1 - (int)*s2; @@ -26,7 +26,7 @@ EXPORT int strcmp(const char *s1, const char *s2) */ EXPORT int strncmp(const char *s1, const char *s2, size_t n) { - while(n && *s1 == *s2 && *s1 != '\0' && *s2 != '\0') + while(n && *s1 && *s1 == *s2) { s1++; s2++; n --; @@ -229,6 +229,21 @@ EXPORT void *memcpy(void *__dest, const void *__src, size_t count) const char *sp = __src; while(count--) *dp++ = *sp ++; } + // TODO: Bulk aligned copies + #if 0 + else if(count > 128 && (dst & 15) == (src & 15) ) + { + // SSE/bulk copy + for( ; dst & 15; count -- ) + *(char*)dst++ = *(char*)src++; + memcpy_16byte(dst, src, count / 16); + dst += count & ~15; + src += count & ~15; + count &= 15; + while(count --) + *(char*)dst++ = *(char*)src++; + } + #endif else { void **dp, **sp; @@ -255,14 +270,14 @@ EXPORT void *memcpy(void *__dest, const void *__src, size_t count) */ EXPORT void *memmove(void *dest, const void *src, size_t count) { - char *sp = (char *)src; - char *dp = (char *)dest; - // Check if corruption will happen + char *sp = (char *)src; + char *dp = (char *)dest; + // Check if the areas overlap if( (intptr_t)dest > (intptr_t)src && (intptr_t)dest < (intptr_t)src+count ) for(;count--;) dp[count] = sp[count]; else - for(;count--;) *dp++ = *sp++; - return dest; + for(;count--;) *dp++ = *sp++; + return dest; } /** @@ -274,12 +289,13 @@ EXPORT void *memmove(void *dest, const void *src, size_t count) */ EXPORT int memcmp(const void *mem1, const void *mem2, size_t count) { + const unsigned char *p1 = mem1, *p2 = mem2; while(count--) { - if( *(unsigned char*)mem1 != *(unsigned char*)mem2 ) - return *(unsigned char*)mem1 - *(unsigned char*)mem2; - mem1 ++; - mem2 ++; + if( *p1 != *p2 ) + return *p1 - *p2; + p1 ++; + p2 ++; } return 0; } diff --git a/Usermode/include/errno.h b/Usermode/include/errno.h index e4228b7a..738541d1 100644 --- a/Usermode/include/errno.h +++ b/Usermode/include/errno.h @@ -1,8 +1,15 @@ #ifndef _ERRNO_H_ #define _ERRNO_H_ +// TODO: Fully implement errno.h, make sure it matches the kernel one + #define errno _errno #define strerror(_x) "Unimplemented" +enum +{ + EINVAL +}; + #endif diff --git a/Usermode/include/string.h b/Usermode/include/string.h index b77d8074..7c38602d 100644 --- a/Usermode/include/string.h +++ b/Usermode/include/string.h @@ -18,7 +18,7 @@ extern char *strcpy(char *dst, const char *src); extern char *strncpy(char *dst, const char *src, size_t num); extern char *strcat(char *dst, const char *src); extern char *strdup(const char *src); -extern char *strndup(const char *src, int length); +extern char *strndup(const char *src, size_t length); extern char *strchr(const char *str, int character); extern char *strrchr(const char *str, int character); extern char *strstr(const char *str1, const char *str2); -- 2.20.1