From owner-cvs-src@FreeBSD.ORG Sun Apr 3 10:20:49 2005 Return-Path: Delivered-To: cvs-src@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 0F4D916A4CE; Sun, 3 Apr 2005 10:20:49 +0000 (GMT) Received: from VARK.MIT.EDU (VARK.MIT.EDU [18.95.3.179]) by mx1.FreeBSD.org (Postfix) with ESMTP id 9E03343D58; Sun, 3 Apr 2005 10:20:48 +0000 (GMT) (envelope-from das@FreeBSD.ORG) Received: from VARK.MIT.EDU (localhost [127.0.0.1]) by VARK.MIT.EDU (8.13.3/8.13.1) with ESMTP id j33AKiNG024857; Sun, 3 Apr 2005 06:20:44 -0400 (EDT) (envelope-from das@FreeBSD.ORG) Received: (from das@localhost) by VARK.MIT.EDU (8.13.3/8.13.1/Submit) id j33AKddL024856; Sun, 3 Apr 2005 06:20:39 -0400 (EDT) (envelope-from das@FreeBSD.ORG) Date: Sun, 3 Apr 2005 06:20:39 -0400 From: David Schultz To: Bruce Evans Message-ID: <20050403102039.GA24319@VARK.MIT.EDU> Mail-Followup-To: Bruce Evans , src-committers@FreeBSD.ORG, cvs-src@FreeBSD.ORG, cvs-all@FreeBSD.ORG References: <200504021852.j32IqjhR031587@repoman.freebsd.org> <20050402185706.GA19208@VARK.MIT.EDU> <20050403162709.Q30325@delplex.bde.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20050403162709.Q30325@delplex.bde.org> cc: cvs-src@FreeBSD.ORG cc: src-committers@FreeBSD.ORG cc: cvs-all@FreeBSD.ORG Subject: Re: cvs commit: src/lib/libc/string strcspn.c strspn.c src/sys/libkern strspn.c X-BeenThere: cvs-src@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: CVS commit messages for the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 03 Apr 2005 10:20:49 -0000 On Sun, Apr 03, 2005, Bruce Evans wrote: > On Sat, 2 Apr 2005, David Schultz wrote: > > >BTW, anyone know a good reason why we have optimized string > >functions (e.g. strcmp(), strcpy()) in libc, but not in libkern? > > It is because str* functions are almost never used in the kernel. > E.g., to a first approximation, strcmp() is only used for initialization. > Even the non-string function for copying pathnames from user space > (copyinstr()) rarely shows up in profiles. Standard C string functions > are a few orders of magnitude less important than this. Fair enough. I haven't done any profiling for a while, so I'll take your word for it that they're not important. As you mention, most of the uses seem to be for initialization. Or in the I/O path where nobody cares. > >In testing strcmp(s, s), I found that the libc version on i386 is > >11% faster when s has length 1 and 4% faster when s has length 400. > > That's surprisingly little for an "optimized" asm version versus an > unoptimized C version. Yes, particularly given that 400 bytes still fits in my L1 cache. AFAICT, the only trick that libc/i386/strcmp.S plays that gcc -O2 doesn't is loop unrolling. Both versions do byte-by-byte comparisons. With gcc -O2 -funroll-loops -march=pentium4, the C version isn't measurably slower at all for 400 byte strings.