From: loth AT gec DOT net (Burton Radons) To: djgpp-workers AT delorie DOT com Subject: libc replacement (memcmp) Date: Tue, 17 Mar 1998 12:53:21 GMT Message-ID: <350f6b73.34099775@mail.gec.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 8bit Precedence: bulk memcmp used to compare using char-by-char, so I replaced it with int-by-int -- quick optimizations, but it hadn't been done in three years, so... bcmp follows this message. 350% speed increase in memcmp at peak (12 bytes and up), never slower, reacts the same as before. - Burton Radons, loth AT gec DOT net Vancouver Island, British Columbia, Canada *** src/new/memcmp.c Tue Mar 17 00:41:56 1998 --- src/libc/ansi/string/memcmp.c Tue Nov 29 04:41:36 1994 *************** *** 1,41 **** ! /* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */ #include int memcmp(const void *s1, const void *s2, size_t n) { ! if (n != 0) ! { ! const unsigned char *p1 = s1; ! const unsigned char *p2 = s2; ! ! while (n > 4) { ! if (*((int *) p1) != *((int *) p2)) { ! if (*((short *) p1) != *((short *) p2)) { ! if (*p1 != *p2) ! return (*p1 - *p2); ! ! return (*++p1 - *++p2); ! } ! ! p1 += 2; ! p2 += 2; ! ! if (*p1 != *p2) ! return (*p1 - *p2); ! ! return (*++p1 - *++p2); ! } ! ! p1 += 4; ! p2 += 4; ! n -= 4; ! } ! ! for (; n; n --) ! if (*p1++ != *p2++) ! return *--p1 - *--p2; ! } ! ! return 0; } --- 1,17 ---- ! /* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ #include int memcmp(const void *s1, const void *s2, size_t n) { ! if (n != 0) ! { ! const unsigned char *p1 = s1, *p2 = s2; ! ! do { ! if (*p1++ != *p2++) ! return (*--p1 - *--p2); ! } while (--n != 0); ! } ! return 0; }