[PATCH] Optimize strchr(x, 0), strcmp("a","b") and strstr("abc","bc")

Bernd Schmidt bernds@redhat.co.uk
Wed Nov 8 02:32:00 GMT 2000


On Tue, 7 Nov 2000, Joseph S. Myers wrote:

> The optimizations may have been overridden by glibc's string macros; it
> might be useful (i.e., save me the work :-)) if when producing patches for
> string optimizations you also produce the corresponding patches to glibc
> to stop it attempting to be clever in the cases gcc handles.  (This is
> simplest of course if you cover everything glibc does for a particular
> function.  Proper glibc patches may need ideally to cover the various
> <bits/string.h> files with assembler versions - which include similar
> macros to those in <bits/string2.h> - but probably few people use
> <bits/string.h> which needs -D__USE_STRING_INLINES so fixing
> <bits/string2.h> is more important.)

We probably want to fixinclude the glibc macros out once we have the
necessary optimizations in the compiler.  Not only are they occasionally
bad for run-time performance, they can also increase compile times and
memory requirements in some cases.

The patch below could serve as a starting point if someone wants to keep
track of this; I made it shortly after discovering that the strcpy macro
is a major pessimization on bigendian machines.


Bernd

Index: gcc/fixinc/inclhack.def
===================================================================
RCS file: /cvs/gcc/egcs/gcc/fixinc/inclhack.def,v
retrieving revision 1.93
diff -u -p -r1.93 inclhack.def
--- gcc/fixinc/inclhack.def	2000/10/29 19:34:53	1.93
+++ gcc/fixinc/inclhack.def	2000/11/06 11:02:31
@@ -156,6 +156,25 @@ typedef char * va_list;
 \#endif /*  #ifndef __INT_VARARGS_H  */\n";
 };
 
+/*
+ * This fixes the broken strcpy macro for glibc 2.x
+ */
+fix = {
+    hackname  = AAB_strcpy_bits_string2_h;
+    files     = bits/string2.h;
+    mach      = '*-*-linux*';
+    replace   =
+'/* This file gets rid of several undesirable string function "optimizations"
+    done by glibc.  */
+\#ifndef _BITS_STRING2_H_WRAPPER
+\#include_next <bits/string2.h>
+
+\#undef strcpy
+
+\#define _BITS_STRING2_H_WRAPPER
+\#endif /* _BITS_STRING2_H_WRAPPER */
+';
+};
 
 /*
  *  This fixes __FD_ZERO bug for linux 2.x.y (x <= 2 && y <= some n)
Index: gcc/fixinc/mkfixinc.sh
===================================================================
RCS file: /cvs/gcc/egcs/gcc/fixinc/mkfixinc.sh,v
retrieving revision 1.24
diff -u -p -r1.24 mkfixinc.sh
--- gcc/fixinc/mkfixinc.sh	2000/08/30 22:57:10	1.24
+++ gcc/fixinc/mkfixinc.sh	2000/11/06 11:02:31
@@ -13,7 +13,8 @@ echo constructing ${target} for $machine
 fixincludes="${machine}"
 
 case $machine in
-	i[34567]86-*-linux*)
+	*-*-linux* | \
+	*-*-gnu*)
 		:
 		;;
 
@@ -63,7 +64,6 @@ case $machine in
 	hppa1.1-*-bsd* | \
 	hppa1.0-*-bsd* | \
 	hppa*-*-lites* | \
-	*-*-linux* | \
 	*-*-gnu* | \
 	i?86-moss-msdos* | i?86-*-moss* | \
 	i?86-*-osf1* | \



More information about the Gcc-patches mailing list