From owner-cvs-all@FreeBSD.ORG Thu Nov 1 01:52:31 2007 Return-Path: Delivered-To: cvs-all@FreeBSD.ORG Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 13F4816A41A for ; Thu, 1 Nov 2007 01:52:31 +0000 (UTC) (envelope-from christoph.mallon@gmx.de) Received: from mail.gmx.net (mail.gmx.net [213.165.64.20]) by mx1.freebsd.org (Postfix) with SMTP id 7195513C4A8 for ; Thu, 1 Nov 2007 01:52:30 +0000 (UTC) (envelope-from christoph.mallon@gmx.de) Received: (qmail invoked by alias); 01 Nov 2007 01:52:14 -0000 Received: from p54A3EA53.dip.t-dialin.net (EHLO tron.homeunix.org) [84.163.234.83] by mail.gmx.net (mp049) with SMTP; 01 Nov 2007 02:52:14 +0100 X-Authenticated: #1673122 X-Provags-ID: V01U2FsdGVkX19vGjseBUxvSg8y5/DFAfSAwxFzHnKkm0ZAESs0FD G3UP/oGtyqIrTz Message-ID: <4729314D.1090709@gmx.de> Date: Thu, 01 Nov 2007 02:52:13 +0100 From: Christoph Mallon User-Agent: Thunderbird 2.0.0.6 (X11/20070806) MIME-Version: 1.0 To: Andrey Chernov , Christoph Mallon , src-committers@FreeBSD.ORG, cvs-src@FreeBSD.ORG, cvs-all@FreeBSD.ORG References: <200710272232.l9RMWSbK072082@repoman.freebsd.org> <47264710.2000500@gmx.de> <20071031221934.GA90781@nagual.pp.ru> In-Reply-To: <20071031221934.GA90781@nagual.pp.ru> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Y-GMX-Trusted: 0 Cc: Subject: Re: cvs commit: src/include _ctype.h X-BeenThere: cvs-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: CVS commit messages for the entire tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 01 Nov 2007 01:52:31 -0000 Andrey Chernov wrote: > On Mon, Oct 29, 2007 at 09:48:16PM +0100, Christoph Mallon wrote: >> Andrey A. Chernov wrote: >>> 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) >>> Revision Changes Path >>> 1.33 +1 -1 src/include/_ctype.h >> Actually this is rather a micro-pessimisation. Every compiler worth its >> money transforms the range check into single unsigned comparison. The >> latter test on the other hand on x86 gets probably transformed into a test >> instruction. This instruction has no form with sign extended 8bit >> immediate, but only with 32bit immediate. This results in a significantly >> longer opcode (three bytes more) than a single (unsigned)_c > 127, which a >> sane compiler produces. I suspect some RISC machines need one more >> instruction for the "micro-optimised" code, too. >> In theory GCC could transform the _c & ~0x7F back into a (unsigned)_c > >> 127, but it does not do this (the only compiler I found, which does this >> transformation, is LLVM). >> Further IMO it is hard to decipher what _c & ~0x7F is supposed to do. > > 1. My variant is compiler optimization level independent. F.e. without > optimization completely there is no range check transform you talk about > at all and very long asm code is generated. I also mean the case where gcc > optimization bug was avoided, removing optimization (like compiling large > part of Xorg server recently), using non-gcc compilers etc. cases. Compiling without any optimisations makes the code slow for a zillion other reasons (no load/store optimisations, constant folding, common subexpression elimination, if-conversion, partial redundant expression elimination, strength reduction, reassociation, code placement, and many more), so a not transformed range check is really not of any concern. > 2. _c & ~0x7F comes right from is{w}ascii() so there is no such enormously > big problems to decifer. I just want to keep all ctype in style. Repeating cryptic code does not make it better, IMO. > 3. I see no "longer opcode (three bytes more)" you talk about in my tests > (andl vs cmpl was there, no testl). See the reply to the mail with your code example. Christoph