From owner-freebsd-hackers@FreeBSD.ORG Sun Jun 7 23:47:56 2015 Return-Path: Delivered-To: freebsd-hackers@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 56343B99 for ; Sun, 7 Jun 2015 23:47:56 +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 331691926 for ; Sun, 7 Jun 2015 23:47:56 +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=INYp7HK41wtzr6Sztgq8ap5XSTwRvxVQ6aBxWPwK2+4=; b=gbk1YVeUdwD9QOx090RDs+LZKUBVL9zYgGHb+X2mR/KAWZciUpG3ZRYdz3qcMIXhA90RqR8whkD/dVnXE09Ap5oa1KNMTzZmXmbPaPFY4uDDTqnDDuNpKi15sfp34VcdUXPyZ5cfjhBmdEiXxnVUkNXa6rqXAeFnCFQ+CjPfelA=; Received: from [114.121.131.162] (port=30897 helo=B85M-HD3-0.alogt.com) by sl-508-2.slc.westdc.net with esmtpsa (TLSv1.2:AES128-GCM-SHA256:128) (Exim 4.85) (envelope-from ) id 1Z1kID-001Un1-Jy; Sun, 07 Jun 2015 17:47:54 -0600 Date: Mon, 8 Jun 2015 07:47:47 +0800 From: Erich Dollansky To: Hans Petter Selasky Cc: "freebsd-hackers@freebsd.org" Subject: Re: allow ffs & co. a binary search Message-ID: <20150608074747.55be51c8@B85M-HD3-0.alogt.com> In-Reply-To: <55745D08.5000505@selasky.org> References: <20150607081315.7c0f09fb@B85M-HD3-0.alogt.com> <5573EA5E.40806@selasky.org> <20150607195245.62dc191f@B85M-HD3-0.alogt.com> <55745D08.5000505@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: Sun, 07 Jun 2015 23:47:56 -0000 Hi Hans, On Sun, 07 Jun 2015 17:02:32 +0200 Hans Petter Selasky wrote: > On 06/07/15 13:52, Erich Dollansky wrote: > > On Sun, 07 Jun 2015 08:53:18 +0200 > > Hans Petter Selasky wrote: > >> On 06/07/15 02:13, Erich Dollansky wrote: > >>> If you like the binary way I could give you the sources for the > >>> complete family following your style to replace the older > >>> functions. > >>> > >> I think this is not the fastest way to do it. You first find the > >> LSB, > > > > I never thought of this as I took the code a long, long time from > > university and expanded it over time from 8 to 64 bits. > > > >> then you do a sumbits, which doesn't have any conditionals IF/ELSE > >> and performs better with the CPU pipeline. I think the software > >> ffs() is only used for platforms which doesn't have a hardware > >> version btw: > > > > The code is not x86 specific. > >> > > This one is the same: > > > >> From my libmbin: > >> > >> int ffs(int value) > >> { > >> int retval = mbin_sumbits32(mbin_lsb32(value) - 1); > >> if (retval == 32) > >> retval = 0; > >> else > >> retval++; > >> return (retval); > >> } > >> > > Where is this? Should this also be in 10.1? > > It is currently nowhere, just in my private SVN. Would you wrap up > complete patch, and I can put it into Phabricator and let more people > look at it. Does your patch cover both kernel and userspace? > I can do this but will need some help especially in the coding style department. Can I e-mail the source first to see if it matches the formal requirements? > > > > What I saw is that all CPUs except ARM uses the software version. > > Kernel too? I did not check. Erich