Explorar el Código

some constness stuff for buffer_0, an experimental optimization for

byte_copy and add buffer_putspace, a trivial shortcut.
master
Felix von Leitner hace 19 años
padre
commit
9c1ce2b6a5
Se han modificado 7 ficheros con 45 adiciones y 4 borrados
  1. +2
    -2
      Makefile
  2. +2
    -0
      buffer.h
  3. +1
    -1
      buffer/buffer_0.c
  4. +1
    -1
      buffer/buffer_0small.c
  5. +7
    -0
      buffer/buffer_putspace.c
  6. +15
    -0
      byte/byte_copy.c
  7. +17
    -0
      t.c

+ 2
- 2
Makefile Ver fichero

@@ -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



+ 2
- 0
buffer.h Ver fichero

@@ -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 ) \


+ 1
- 1
buffer/buffer_0.c Ver fichero

@@ -1,7 +1,7 @@
#include <unistd.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;
return read(fd,buf,len);
}


+ 1
- 1
buffer/buffer_0small.c Ver fichero

@@ -1,7 +1,7 @@
#include <unistd.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;
return read(fd,buf,len);
}


+ 7
- 0
buffer/buffer_putspace.c Ver fichero

@@ -0,0 +1,7 @@
#include "str.h"
#include "buffer.h"

int buffer_putspace(buffer* b) {
static char space=' ';
return buffer_put(b,&space,1);
}

+ 15
- 0
byte/byte_copy.c Ver fichero

@@ -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;


+ 17
- 0
t.c Ver fichero

@@ -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");


Cargando…
Cancelar
Guardar