From d31d8fb2cc1aa0ec025216f356797936369a066a Mon Sep 17 00:00:00 2001 From: jshepher <> Date: Mon, 20 Dec 2004 01:51:43 +0000 Subject: [PATCH] Went back to original fast versions. Redid using unions to get rid of the gcc 3.x warnings. --- libnix/sources/nix/misc/bcopy.c | 94 +++++++++++++++++++++++++----- libnix/sources/nix/misc/bzero.c | 46 +++++++++++++-- libnix/sources/nix/string/memset.c | 44 ++++++++++++-- 3 files changed, 159 insertions(+), 25 deletions(-) diff --git a/libnix/sources/nix/misc/bcopy.c b/libnix/sources/nix/misc/bcopy.c index 9f8364b..97a47d1 100755 --- a/libnix/sources/nix/misc/bcopy.c +++ b/libnix/sources/nix/misc/bcopy.c @@ -1,21 +1,85 @@ #include -#include +/* This is a _fast_ block move routine! */ +typedef union { + void *v; + char *c; + short *s; + long *l; +} val; void bcopy(const void *s1,void *s2,size_t n) -{ - unsigned char *ch1 = s1; - unsigned char *ch2 = s2; - if (ch1 < ch2) { - while (n > 0) { - *ch2++ = *ch1++; - n--; - } +{ + size_t m; + val v1, v2; + v1.v = s1; + v2.v = s2; + + if(!n) + return; + + if(s2 < s1) { + if(n > 15) { + if((long)s1 & 1) { + *v2.c++ = *v1.c++; + n--; + } + if(!((long)s2 & 1)) { + if((long)s1 & 2) { + *v2.s++ = *v1.s++; + n-=2; + } + for(m=n/(8*sizeof(long));m;--m) { + *v2.l++ = *v1.l++; + *v2.l++ = *v1.l++; + *v2.l++ = *v1.l++; + *v2.l++ = *v1.l++; + *v2.l++ = *v1.l++; + *v2.l++ = *v1.l++; + *v2.l++ = *v1.l++; + *v2.l++ = *v1.l++; + } + n &= 8 * sizeof(long) - 1; + for(m = n / sizeof(long); m; --m) + *v2.l++ = *v1.l++; + n &= sizeof(long) - 1; + } + if(!n) + return; + } + do; + while(*v2.c++ = *v1.c++, --n); } else { - ch1 += n; - ch2 += n; - while (n > 0) { - *ch2-- = *ch1--; - n--; - } + v1.c += n; + v2.c += n; + if(n > 15) { + if((long)s1&1) { + *--v2.c = *--v1.c; + n--; + } + if(!((long)s2 & 1)) { + if((long)s1 & 2) { + *--v2.s=*--v1.s; + n -= 2; + } + for(m = n / (8*sizeof(long)); m; --m) { + *--v2.l = *--v1.l; + *--v2.l = *--v1.l; + *--v2.l = *--v1.l; + *--v2.l = *--v1.l; + *--v2.l = *--v1.l; + *--v2.l = *--v1.l; + *--v2.l = *--v1.l; + *--v2.l = *--v1.l; + } + n &= 8*sizeof(long)-1; + for(m = n / sizeof(long); m; --m) + *--v2.l = *--v1.l; + n &= sizeof(long)-1; + } + if(!n) + return; + } + do; + while(*--v2.c = *--v1.c,--n); } } diff --git a/libnix/sources/nix/misc/bzero.c b/libnix/sources/nix/misc/bzero.c index e694d00..ec9593c 100755 --- a/libnix/sources/nix/misc/bzero.c +++ b/libnix/sources/nix/misc/bzero.c @@ -1,10 +1,44 @@ -#include +#include +typedef union { + void *v; + char *c; + short *s; + long *l; +} val; void bzero(void *b,size_t n) -{ - unsigned char *ch = (unsigned char *)b; - while (n > 0) { - *ch++ = 0; - n--; +{ + val v; + size_t m; + v.v = b; + + if(!n) + return; + if(n > 15) { + if((long)v.l & 1) { + *v.c++ = 0; + n--; + } + if((long)v.l & 2) { + *v.s++ = 0; + n-= 2; + } + for(m = n / (8 * sizeof(long)); m; --m) { + *v.l++ = 0; + *v.l++ = 0; + *v.l++ = 0; + *v.l++ = 0; + *v.l++ = 0; + *v.l++ = 0; + *v.l++ = 0; + *v.l++ = 0; + } + n &= 8 * sizeof(long) - 1; + for(m = n / sizeof(long); m; --m) + *v.l++ = 0; + if((n &= sizeof(long) - 1)==0) + return; } + do; + while(*v.c++ = 0, --n); } diff --git a/libnix/sources/nix/string/memset.c b/libnix/sources/nix/string/memset.c index 6c6f693..00274ab 100755 --- a/libnix/sources/nix/string/memset.c +++ b/libnix/sources/nix/string/memset.c @@ -1,11 +1,47 @@ #include +typedef union { + void *v; + char *c; + short *s; + long *l; +} val; void *memset(void *s,int c,size_t n) { - unsigned char *ch = (unsigned char *)s; - while (n > 0) { - *ch++ = c; - n--; + size_t m; + val v; + v.v = s; + + if(n) { + if(n > 15) { + c *= 0x01010101; + if((long)v.l & 1) { + *v.c++ = c; + n--; + } + if((long)v.l & 2) { + *v.s++ = c; + n-=2; + } + for(m= n / (8 * sizeof(long)); m; --m) { + *v.l++ = c; + *v.l++ = c; + *v.l++ = c; + *v.l++ = c; + *v.l++ = c; + *v.l++ = c; + *v.l++ = c; + *v.l++ = c; + } + n &= (8 * sizeof(long)-1); + for(m = n / sizeof(long); m; --m) + *v.l++ = c; + if((n &= sizeof(long) - 1)==0) + goto leave; + } + do; + while(*v.c++ = c, --n); } +leave: return s; }