From 05b4cf85f7c2e98d1fb72d881a7e9263719e29ec Mon Sep 17 00:00:00 2001 From: leitner Date: Mon, 10 Sep 2001 10:37:00 +0000 Subject: [PATCH] some constness stuff for buffer_0, an experimental optimization for byte_copy and add buffer_putspace, a trivial shortcut. --- Makefile | 4 ++-- buffer.h | 2 ++ buffer/buffer_0.c | 2 +- buffer/buffer_0small.c | 2 +- buffer/buffer_putspace.c | 7 +++++++ byte/byte_copy.c | 15 +++++++++++++++ t.c | 17 +++++++++++++++++ 7 files changed, 45 insertions(+), 4 deletions(-) create mode 100644 buffer/buffer_putspace.c diff --git a/Makefile b/Makefile index 935f0c1..e2d6d58 100644 --- a/Makefile +++ b/Makefile @@ -2,9 +2,9 @@ all: t byte.a fmt.a scan.a str.a uint.a open.a stralloc.a unix.a socket.a buffer VPATH=str:byte:fmt:scan:uint:open:stralloc:unix:socket:buffer:mmap -CC=egcc +CC=gcc #CFLAGS=-I. -pipe -Wall -Os -march=pentiumpro -fomit-frame-pointer -fschedule-insns2 -Wall -CFLAGS=-I. -I../dietlibc/include -pipe -Wall -Os -march=athlon -mcpu=athlon -malign-functions=2 -fschedule-insns2 -g +CFLAGS=-I. -I../dietlibc/include -pipe -Wall -Os -malign-functions=2 -fschedule-insns2 -g #CFLAGS=-I../dietlibc/include -I. -pipe -Wall -Os -march=pentiumpro -mcpu=athlon -fomit-frame-pointer -fschedule-insns2 -Wall #CFLAGS=-I../dietlibc/include -pipe -Os -march=pentiumpro -mcpu=pentiumpro -fomit-frame-pointer -fschedule-insns2 -Wall diff --git a/buffer.h b/buffer.h index 2d64184..cb7c4e7 100644 --- a/buffer.h +++ b/buffer.h @@ -25,6 +25,8 @@ extern int buffer_puts(buffer* b,const char* x); extern int buffer_putsalign(buffer* b,const char* x); extern int buffer_putsflush(buffer* b,const char* x); +extern int buffer_putspace(buffer* b); + #define buffer_PUTC(s,c) \ ( ((s)->n != (s)->p) \ ? ( (s)->x[(s)->p++] = (c), 0 ) \ diff --git a/buffer/buffer_0.c b/buffer/buffer_0.c index 244d6c4..258de28 100644 --- a/buffer/buffer_0.c +++ b/buffer/buffer_0.c @@ -1,7 +1,7 @@ #include #include "buffer.h" -static int b0read(int fd,const char* buf, unsigned int len) { +static int b0read(int fd,char* buf, unsigned int len) { if (buffer_flush(buffer_1)<0) return -1; return read(fd,buf,len); } diff --git a/buffer/buffer_0small.c b/buffer/buffer_0small.c index 40fed23..ff9917b 100644 --- a/buffer/buffer_0small.c +++ b/buffer/buffer_0small.c @@ -1,7 +1,7 @@ #include #include "buffer.h" -static int b0read(int fd,const char* buf, unsigned int len) { +static int b0read(int fd,char* buf, unsigned int len) { if (buffer_flush(buffer_1small)<0) return -1; return read(fd,buf,len); } diff --git a/buffer/buffer_putspace.c b/buffer/buffer_putspace.c new file mode 100644 index 0000000..48fea2a --- /dev/null +++ b/buffer/buffer_putspace.c @@ -0,0 +1,7 @@ +#include "str.h" +#include "buffer.h" + +int buffer_putspace(buffer* b) { + static char space=' '; + return buffer_put(b,&space,1); +} diff --git a/byte/byte_copy.c b/byte/byte_copy.c index 1493ae6..95be5b4 100644 --- a/byte/byte_copy.c +++ b/byte/byte_copy.c @@ -6,6 +6,21 @@ void byte_copy(void* out, unsigned int len, const void* in) { register char* s=out; register const char* t=in; register const char* u=in+len; + if (len>127) { + if (sizeof(unsigned long)>4) { /* a good compiler should optimize this check away */ + for (;(unsigned long)t&7;) { + if (t==u) break; *s=*t; ++s; ++t; + } + } else { + for (;(unsigned long)t&3;) { + if (t==u) break; *s=*t; ++s; ++t; + } + } + while (t+sizeof(long)<=u) { + *(unsigned long*)s=*(unsigned long*)t; + s+=sizeof(long); t+=sizeof(long); + } + } for (;;) { if (t==u) break; *s=*t; ++s; ++t; if (t==u) break; *s=*t; ++s; ++t; diff --git a/t.c b/t.c index 445b419..7966a09 100644 --- a/t.c +++ b/t.c @@ -14,6 +14,22 @@ __asm__ __volatile__ ("rdtsc" : "=a" (low) : : "edx") int main(int argc,char* argv[]) { + buffer_putspace(buffer_1); + buffer_flush(buffer_1); +#if 0 + long a,b,c; + char buf[4096]; + char buf2[4096]; + memcpy(buf,buf2,4096); + byte_copy(buf,4096,buf2); + rdtscl(a); + memcpy(buf,buf2,4096); + rdtscl(b); + byte_copy(buf,4096,buf2); + rdtscl(c); + printf("memcpy: %d - byte_copy: %d\n",b-a,c-b); +#endif +#if 0 char ip[16]; int i; if ((i=scan_ip6(argv[1],ip))) { @@ -21,6 +37,7 @@ int main(int argc,char* argv[]) { buf[fmt_ip6(buf,ip)]=0; puts(buf); } +#endif #if 0 char buf[100]; strcpy(buf,"foobarbaz");