From owner-freebsd-hackers@freebsd.org Tue Aug 11 02:03:37 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 1D93D99DB48 for ; Tue, 11 Aug 2015 02:03:37 +0000 (UTC) (envelope-from erichsfreebsdlist@alogt.com) Received: from alogt.com (alogt.com [69.36.191.58]) (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 E995CE9A; Tue, 11 Aug 2015 02:03:36 +0000 (UTC) (envelope-from erichsfreebsdlist@alogt.com) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=alogt.com; s=default; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Subject:Cc:To:From:Date; bh=5uynL2LQXq29gs1HeBYL8SknN4FN6Jo/YsX5NDxBRnk=; b=a3vT+mb3KGvJJ0tEBmFEp2h6aIBWWMwoly2AFoMGaEgT4PQ0UyEd0lMvK8bsFGaBfqBEf2Z4iuyFaR9fb7lvaTUJudNFDGCXO3ep2H9J4fSxFQUHsJOhb89w5xz98rsJnJSKL/OkPg6KrAgGycYKDR6r/0XMfTdv5H2P0G7JGm8=; Received: from [39.255.12.223] (port=30549 helo=X220.alogt.com) by sl-508-2.slc.westdc.net with esmtpsa (TLSv1.2:AES128-GCM-SHA256:128) (Exim 4.85) (envelope-from ) id 1ZOyuc-0041cH-60; Mon, 10 Aug 2015 20:03:34 -0600 Date: Tue, 11 Aug 2015 10:03:27 +0800 From: Erich Dollansky To: Hans Petter Selasky Cc: Andriy Gapon , Konstantin Belousov , "freebsd-hackers@freebsd.org" Subject: Re: allow ffs & co. a binary search Message-ID: <20150811100327.0d12231f@X220.alogt.com> In-Reply-To: <55C335A7.8020503@selasky.org> 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> <55C335A7.8020503@selasky.org> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - sl-508-2.slc.westdc.net X-AntiAbuse: Original Domain - freebsd.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - alogt.com X-Get-Message-Sender-Via: sl-508-2.slc.westdc.net: authenticated_id: erichsfreebsdlist@alogt.com X-Source: X-Source-Args: X-Source-Dir: 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: Tue, 11 Aug 2015 02:03:37 -0000 Hi, On Thu, 06 Aug 2015 12:23:35 +0200 Hans Petter Selasky wrote: > 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. > > > Has there been any further thoughts on this topic during the summer? > I was just waiting for a clear result. I do not want to write something which is not accepted at the end. > 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. Why not detect the built-in functions and do the binary search when they are not available and leave the original implementation for all other sizes? > > 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? > A clear route would be good. I could do it then. Erich