From owner-freebsd-hackers@freebsd.org Thu Aug 6 10:22:10 2015 Return-Path: Delivered-To: freebsd-hackers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id F0F7D9B5C0F for ; Thu, 6 Aug 2015 10:22:10 +0000 (UTC) (envelope-from hps@selasky.org) Received: from mail.turbocat.net (mail.turbocat.net [IPv6:2a01:4f8:d16:4514::2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id B4D5014DC; Thu, 6 Aug 2015 10:22:10 +0000 (UTC) (envelope-from hps@selasky.org) Received: from laptop015.home.selasky.org (cm-176.74.213.204.customer.telag.net [176.74.213.204]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.turbocat.net (Postfix) with ESMTPSA id C99A91FE023; Thu, 6 Aug 2015 12:22:06 +0200 (CEST) Message-ID: <55C335A7.8020503@selasky.org> Date: Thu, 06 Aug 2015 12:23:35 +0200 From: Hans Petter Selasky User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: Andriy Gapon , Konstantin Belousov CC: "freebsd-hackers@freebsd.org" , Erich Dollansky Subject: Re: allow ffs & co. a binary search References: <20150607081315.7c0f09fb@B85M-HD3-0.alogt.com> <5573EA5E.40806@selasky.org> <20150607195245.62dc191f@B85M-HD3-0.alogt.com> <20150607135453.GH2499@kib.kiev.ua> <558175FA.4040106@FreeBSD.org> <20150617165331.GA2080@kib.kiev.ua> <5582CCF1.8010505@FreeBSD.org> In-Reply-To: <5582CCF1.8010505@FreeBSD.org> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 06 Aug 2015 10:22:11 -0000 On 06/18/15 15:51, Andriy Gapon wrote: > On 17/06/2015 19:53, Konstantin Belousov wrote: >> AFAIR it was about 'sufficiently smart compiler' and the fact that the >> functions are not on the hottest paths. > > It seems that sufficiently smart compilers still do not exist :-) > At least as far as compilers that are used for compiling FreeBSD are considered. > > [Offtopic] my impression is that lately smartness of compilers is mostly being > improved by various tricks and shortcuts (undefined behavior, etc), rather than > by recognizing patterns in the C code that could be turned into more efficient > machine code. > Hi, Has there been any further thoughts on this topic during the summer? It sounds fair to me that "Sean Eron Anderson's Bit Twiddling Hacks" can be used in our code instead of a for() loop for the ffs() function, given that a 2-clause BSD license is fine by Sean. Typically the compilers can expand for loops using -O3, but I've never seen a compiler yet that convert for loops into a simpler functions where no constants are involved. For sake of readability I would leave the old implementation under "#if 0" so that readers not familiar with binary tricks can understand the code. Any strong objections? --HPS