From owner-cvs-src@FreeBSD.ORG Wed Oct 31 22:12:16 2007 Return-Path: Delivered-To: cvs-src@FreeBSD.ORG Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 3F57D16A419; Wed, 31 Oct 2007 22:12:16 +0000 (UTC) (envelope-from ache@nagual.pp.ru) Received: from nagual.pp.ru (nagual.pp.ru [194.87.13.69]) by mx1.freebsd.org (Postfix) with ESMTP id 5557213C491; Wed, 31 Oct 2007 22:12:15 +0000 (UTC) (envelope-from ache@nagual.pp.ru) Received: from nagual.pp.ru (ache@localhost [127.0.0.1]) by nagual.pp.ru (8.14.1/8.14.1) with ESMTP id l9VLtRo1090461; Thu, 1 Nov 2007 00:55:27 +0300 (MSK) (envelope-from ache@nagual.pp.ru) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=nagual.pp.ru; s=default; t=1193867727; bh=r/7FVgg7uI3TWg0fghGR1r21Xjz3EB/xqifgaml OUMo=; l=2275; h=Date:From:To:Cc:Subject:Message-ID: Mail-Followup-To:References:MIME-Version:Content-Type: Content-Disposition:In-Reply-To:User-Agent; b=Wq0eDX1xULVo4mmKQOu4 a+trARmapJrGtEnv1pGnPpsSzMGKPNWpXtyGnsGOSPV+OPd3umDTlawzRLN4vnU9tFc stc5r5JMWEBGSb8NoC3rrA7W3BQB0i2j+pD61+EM8712N4nSlwwgkeOzXnTRltfPNvs D2HXmyTfkZVGPk0Ck= Received: (from ache@localhost) by nagual.pp.ru (8.14.1/8.14.1/Submit) id l9VLtRvG090460; Thu, 1 Nov 2007 00:55:27 +0300 (MSK) (envelope-from ache) Date: Thu, 1 Nov 2007 00:55:26 +0300 From: Andrey Chernov To: Juli Mallett Message-ID: <20071031215526.GC89932@nagual.pp.ru> Mail-Followup-To: Andrey Chernov , Juli Mallett , src-committers@FreeBSD.ORG, cvs-src@FreeBSD.ORG, cvs-all@FreeBSD.ORG References: <200710272232.l9RMWSbK072082@repoman.freebsd.org> <20071030200331.GA29309@toxic.magnesium.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20071030200331.GA29309@toxic.magnesium.net> User-Agent: Mutt/1.5.16 (2007-06-09) Cc: cvs-src@FreeBSD.ORG, src-committers@FreeBSD.ORG, cvs-all@FreeBSD.ORG Subject: Re: cvs commit: src/include _ctype.h X-BeenThere: cvs-src@freebsd.org X-Mailman-Version: 2.1.5 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: Wed, 31 Oct 2007 22:12:16 -0000 On Tue, Oct 30, 2007 at 10:03:31AM -1000, Juli Mallett wrote: > * "Andrey A. Chernov" [ 2007-10-27 ] > [ cvs commit: src/include _ctype.h ] > > ache 2007-10-27 22:32:28 UTC > > > > FreeBSD src repository > > > > Modified files: > > include _ctype.h > > Log: > > Micro-optimization of prev. commit, change > > (_c < 0 || _c >= 128) to (_c & ~0x7F) > > Isn't that a non-optimization in code and a minor pessimization of readability? > Maybe I'm getting rusty, but those seem to result in nearly identical code on > i386 with a relatively modern GCC. Did you look at the compiler output for this > optimization? Is there a specific expensive instruction you're trying to avoid? > For such thoroughyl bit-aligned range checks, you shouldn't even get a branch > for the former case. Is there a platform other than i386 I should look at where > the previous expression is more clearly pessimized? Or a different compiler > than GCC? For ones who doubts there two tests compiled with -O2. As you may see the result is almost identical (andl vs cmpl): -------------------- a.c -------------------- main () { int c; return (c & ~0x7f) ? 0 : c * 2; } -------------------- a.s -------------------- .file "a.c" .text .p2align 4,,15 .globl main .type main, @function main: leal 4(%esp), %ecx andl $-16, %esp pushl -4(%ecx) movl %eax, %edx andl $-128, %edx addl %eax, %eax cmpl $1, %edx sbbl %edx, %edx pushl %ebp andl %edx, %eax movl %esp, %ebp pushl %ecx popl %ecx popl %ebp leal -4(%ecx), %esp ret .size main, .-main .ident "GCC: (GNU) 4.2.1 20070719 [FreeBSD]" -------------------- a1.c -------------------- main () { int c; return (c < 0 || c >= 128) ? 0 : c * 2; } -------------------- a1.s -------------------- .file "a1.c" .text .p2align 4,,15 .globl main .type main, @function main: leal 4(%esp), %ecx andl $-16, %esp pushl -4(%ecx) addl %eax, %eax cmpl $128, %eax sbbl %edx, %edx andl %edx, %eax pushl %ebp movl %esp, %ebp pushl %ecx popl %ecx popl %ebp leal -4(%ecx), %esp ret .size main, .-main .ident "GCC: (GNU) 4.2.1 20070719 [FreeBSD]" -- http://ache.pp.ru/