To: gcc AT gcc DOT gnu DOT org Cc: djgpp-workers AT delorie DOT com Message-Id: <2.7.9.181SX.H8JVM1@pauzner.dnttm.ru> From: "Leonid Pauzner" Date: Sat, 11 Jan 2003 15:49:13 +0300 (MSK) X-Mailer: dMail [Demos Mail for DOS v2.7.9] Subject: gcc 3.2.1 optimizer degradation (strlen, -O2) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Reply-To: djgpp-workers AT delorie DOT com Hi! It turns out that the libc strlen() function (compiled with -O2) became nearly 2 times slower when I switched from gcc 2.95.3 to gcc 3.2.1 on a Pentium machine. Hand-optimised version improve performance of 3.2.1 compiled strlen code up to the level of 2.95.3 (and with 2.95.3 both optimized and original versions show the same performance). This is DJGPP libc, strlen.c: ============================= /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ #include size_t strlen(const char *str) { const char *s; if (str == 0) return 0; for (s = str; *s; ++s); return s-str; } ============================= My version (strlen2.c) ====================== #include size_t strlen(const char *str) { register const char *s = str; if (s == 0) return 0; while (*s++); return s-1-str; } ====================== Sample test case: ================= #include int main () { const char* str = "jhrfhruiehfiuerhifuhreihfgihrighihrfghkrjehklhlqkmjewbfjkfgtyhjjhgrwae3k"; int len = strlen(str); int l, res; int n = 100000; for (; n > 0; n--) { l = len; while (l != 0) { res = strlen(str+l); /* res = len - l */ l = len - res; /* touch res */ l--; } } return 0; }