From owner-freebsd-mips@FreeBSD.ORG Thu Nov 15 22:25:06 2012 Return-Path: Delivered-To: mips@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 15DB73EE for ; Thu, 15 Nov 2012 22:25:06 +0000 (UTC) (envelope-from imp@bsdimp.com) Received: from mail-oa0-f54.google.com (mail-oa0-f54.google.com [209.85.219.54]) by mx1.freebsd.org (Postfix) with ESMTP id BB6FD8FC12 for ; Thu, 15 Nov 2012 22:25:05 +0000 (UTC) Received: by mail-oa0-f54.google.com with SMTP id n9so2782711oag.13 for ; Thu, 15 Nov 2012 14:25:04 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=sender:subject:mime-version:content-type:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to:x-mailer :x-gm-message-state; bh=0Ogq9S+QQCrdCi6ElEAYSAELFjVjyubSx3N9YOZoq/I=; b=e6kuUEtYKCHDqU5VeBIX+1cR9yt89ZM3c0L0RhvF2MQyLDFqtG3pr1QLdiloQLeodQ cChn7Mi23MXGOFQna8Uuhq8nT8kj2nE5coJg+SLQzSDNuwp97H2SP39TVUzxPBmNzfxJ xFrs8e/JGjzYytxcaRfXX7UC1deHlXskvxeDqSSq9ib0u4I2yAFC1hLK/Hvb/yyzjygz 7CNd7Zt564jXbYI4zn031qc/5i1REGE6n3+92jG4O6A15TmoGus4e+1IKGtw3V71uJu+ r82cc14AzU0/AmyfrB9IJD0+0voCXMCAmQf5OYC6y9R+3qzg/DTeNqdD9zK96MYILGt5 l9rw== Received: by 10.60.27.39 with SMTP id q7mr2197676oeg.109.1353018304750; Thu, 15 Nov 2012 14:25:04 -0800 (PST) Received: from [10.30.101.53] ([209.117.142.2]) by mx.google.com with ESMTPS id yn8sm17083729obb.12.2012.11.15.14.25.02 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 15 Nov 2012 14:25:03 -0800 (PST) Sender: Warner Losh Subject: Re: ZERO_REGION_SIZE Mime-Version: 1.0 (Apple Message framework v1085) Content-Type: text/plain; charset=us-ascii From: Warner Losh In-Reply-To: Date: Thu, 15 Nov 2012 15:25:01 -0700 Content-Transfer-Encoding: 7bit Message-Id: <953A0D95-54E1-4023-A1F5-A4A7DE1C6175@bsdimp.com> References: <50A53391.4080909@rice.edu> <50A54CCD.8070409@rice.edu> To: Patrick Kelsey X-Mailer: Apple Mail (2.1085) X-Gm-Message-State: ALoCoQmiPrQ1aVJS8a+zw/Yl5+pNpxS36IAszFwWA3mD8nb6kN9dY1RPs55SBMumr4UHOk1B5Q0H Cc: "Jayachandran C." , "freebsd-mips@FreeBSD.org" , Alan Cox X-BeenThere: freebsd-mips@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Porting FreeBSD to MIPS List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 15 Nov 2012 22:25:06 -0000 On Nov 15, 2012, at 3:11 PM, Patrick Kelsey wrote: > On Thu, Nov 15, 2012 at 5:02 PM, Juli Mallett wrote: >> On Thu, Nov 15, 2012 at 1:07 PM, Warner Losh wrote: >> >>> >>> On Nov 15, 2012, at 1:13 PM, Alan Cox wrote: >>>> P.S. I would encourage someone with hardware to look into implementing a >>>> non-iterative ffs*() using (d)clz. The MIPS pmap would benefit from >>>> this. Basically, most pmap_enter() calls are doing an ffs*(). >>> >>> ffs finds the first bit set. clz counts the number of leading zeros and >>> thus finds the last bit set. Would a non-iterative fls* be helpful? >>> >> >> Right. And no widespread ctz/ffs MIPS instructions as far as I know. We >> could use pop/dpop on processors that support them to do non-iterative >> ffs*, with a few additional instructions, though. > > I was thinking something like this might work: > > value to ffs is in r1, MSB is the index of the MSB (so, 31 or 63): > > if (0 == r1) return(your_choice); > r2 = r1 - 1; > r2 = r1 ^ r2; > return (MSB - clz(r2)); Turns out NetBSD has one that does exactly this... Warner