some constness stuff for buffer_0, an experimental optimization for
byte_copy and add buffer_putspace, a trivial shortcut.
This commit is contained in:
parent
ffd6158589
commit
05b4cf85f7
4
Makefile
4
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
|
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. -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 -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
|
#CFLAGS=-I../dietlibc/include -pipe -Os -march=pentiumpro -mcpu=pentiumpro -fomit-frame-pointer -fschedule-insns2 -Wall
|
||||||
|
|
||||||
|
2
buffer.h
2
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_putsalign(buffer* b,const char* x);
|
||||||
extern int buffer_putsflush(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) \
|
#define buffer_PUTC(s,c) \
|
||||||
( ((s)->n != (s)->p) \
|
( ((s)->n != (s)->p) \
|
||||||
? ( (s)->x[(s)->p++] = (c), 0 ) \
|
? ( (s)->x[(s)->p++] = (c), 0 ) \
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include "buffer.h"
|
#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;
|
if (buffer_flush(buffer_1)<0) return -1;
|
||||||
return read(fd,buf,len);
|
return read(fd,buf,len);
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include "buffer.h"
|
#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;
|
if (buffer_flush(buffer_1small)<0) return -1;
|
||||||
return read(fd,buf,len);
|
return read(fd,buf,len);
|
||||||
}
|
}
|
||||||
|
7
buffer/buffer_putspace.c
Normal file
7
buffer/buffer_putspace.c
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#include "str.h"
|
||||||
|
#include "buffer.h"
|
||||||
|
|
||||||
|
int buffer_putspace(buffer* b) {
|
||||||
|
static char space=' ';
|
||||||
|
return buffer_put(b,&space,1);
|
||||||
|
}
|
@ -6,6 +6,21 @@ void byte_copy(void* out, unsigned int len, const void* in) {
|
|||||||
register char* s=out;
|
register char* s=out;
|
||||||
register const char* t=in;
|
register const char* t=in;
|
||||||
register const char* u=in+len;
|
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 (;;) {
|
for (;;) {
|
||||||
if (t==u) break; *s=*t; ++s; ++t;
|
if (t==u) break; *s=*t; ++s; ++t;
|
||||||
if (t==u) break; *s=*t; ++s; ++t;
|
if (t==u) break; *s=*t; ++s; ++t;
|
||||||
|
17
t.c
17
t.c
@ -14,6 +14,22 @@
|
|||||||
__asm__ __volatile__ ("rdtsc" : "=a" (low) : : "edx")
|
__asm__ __volatile__ ("rdtsc" : "=a" (low) : : "edx")
|
||||||
|
|
||||||
int main(int argc,char* argv[]) {
|
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];
|
char ip[16];
|
||||||
int i;
|
int i;
|
||||||
if ((i=scan_ip6(argv[1],ip))) {
|
if ((i=scan_ip6(argv[1],ip))) {
|
||||||
@ -21,6 +37,7 @@ int main(int argc,char* argv[]) {
|
|||||||
buf[fmt_ip6(buf,ip)]=0;
|
buf[fmt_ip6(buf,ip)]=0;
|
||||||
puts(buf);
|
puts(buf);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
#if 0
|
#if 0
|
||||||
char buf[100];
|
char buf[100];
|
||||||
strcpy(buf,"foobarbaz");
|
strcpy(buf,"foobarbaz");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user