From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1N1ECr-0008QT-Ck for qemu-devel@nongnu.org; Fri, 23 Oct 2009 03:05:01 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1N1ECq-0008PY-Ix for qemu-devel@nongnu.org; Fri, 23 Oct 2009 03:05:00 -0400 Received: from [199.232.76.173] (port=58331 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N1ECq-0008PU-Ai for qemu-devel@nongnu.org; Fri, 23 Oct 2009 03:05:00 -0400 Received: from hall.aurel32.net ([88.191.82.174]:57242) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1N1ECp-0005Di-N4 for qemu-devel@nongnu.org; Fri, 23 Oct 2009 03:05:00 -0400 Message-ID: <4AE15595.8050709@aurel32.net> Date: Fri, 23 Oct 2009 09:04:53 +0200 From: Aurelien Jarno MIME-Version: 1.0 Subject: Re: [Qemu-devel] [PATCH] target-arm: use clz32() instead of a for loop References: <20091015211452.GC7071@volta.aurel32.net> <20091023003417.GA31360@miranda.arrow> In-Reply-To: <20091023003417.GA31360@miranda.arrow> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stuart Brady Cc: qemu-devel@nongnu.org Stuart Brady a écrit : > On Thu, Oct 15, 2009 at 11:14:52PM +0200, Aurelien Jarno wrote: >> @@ -394,10 +395,7 @@ uint32_t HELPER(uxtb16)(uint32_t x) >> >> uint32_t HELPER(clz)(uint32_t x) >> { >> - int count; >> - for (count = 32; x; count--) >> - x >>= 1; >> - return count; >> + return clz32(x); >> } >> >> int32_t HELPER(sdiv)(int32_t num, int32_t den) > > Just a quick note that the implementation of clz, ctz and popcnt is > still listed in the TCG TODO list. The last time I looked, I noticed > that quite a few architectures have clz/ctz instructions: > > http://lkml.indiana.edu/hypermail/linux/kernel/0601.3/1683.html OTOH, a dump shows that those instruction are not used than often, so I am not sure it worth implementing it. > For those that don't, I think a combination the following two hacks at > http://graphics.stanford.edu/~seander/bithacks.html could be used: The best is probably to use an helper in that case, calling clz32(x). -- Aurelien Jarno GPG: 1024D/F1BCDB73 aurelien@aurel32.net http://www.aurel32.net