From patchwork Mon Mar 11 15:24:07 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Lieven X-Patchwork-Id: 226570 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 308E52C029F for ; Tue, 12 Mar 2013 02:24:33 +1100 (EST) Received: from localhost ([::1]:54115 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UF4aV-0005AI-D0 for incoming@patchwork.ozlabs.org; Mon, 11 Mar 2013 11:24:31 -0400 Received: from eggs.gnu.org ([208.118.235.92]:33480) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UF4aD-00059x-L7 for qemu-devel@nongnu.org; Mon, 11 Mar 2013 11:24:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UF4a9-0007VU-9L for qemu-devel@nongnu.org; Mon, 11 Mar 2013 11:24:13 -0400 Received: from ssl.dlhnet.de ([91.198.192.8]:36967 helo=ssl.dlh.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UF4a9-0007VN-32 for qemu-devel@nongnu.org; Mon, 11 Mar 2013 11:24:09 -0400 Received: from localhost (localhost [127.0.0.1]) by ssl.dlh.net (Postfix) with ESMTP id 7626F1439C3; Mon, 11 Mar 2013 16:24:08 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at ssl.dlh.net Received: from ssl.dlh.net ([127.0.0.1]) by localhost (ssl.dlh.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 4JPMTqEOsGNp; Mon, 11 Mar 2013 16:24:08 +0100 (CET) Received: from lieven-mac.kamp-intra.net (unknown [82.141.1.207]) by ssl.dlh.net (Postfix) with ESMTPSA id 391D514396F; Mon, 11 Mar 2013 16:24:08 +0100 (CET) Mime-Version: 1.0 (Mac OS X Mail 6.2 \(1499\)) From: Peter Lieven In-Reply-To: <513DEBCF.9050407@redhat.com> Date: Mon, 11 Mar 2013 16:24:07 +0100 Message-Id: References: <513DDFA3.1020308@dlhnet.de> <513DE6D6.9000105@redhat.com> <513DEBCF.9050407@redhat.com> To: Paolo Bonzini X-Mailer: Apple Mail (2.1499) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 91.198.192.8 Cc: Orit Wasserman , "qemu-devel@nongnu.org" , Corentin Chary Subject: Re: [Qemu-devel] [RFC] find_next_bit optimizations X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org > How would that be different in your patch? But you can solve it by > making two >= loops, one checking for 4*BITS_PER_LONG and one checking > BITS_PER_LONG. This is what I have now: Reviewed-by: Paolo Bonzini diff --git a/util/bitops.c b/util/bitops.c index e72237a..b0dc93f 100644 --- a/util/bitops.c +++ b/util/bitops.c @@ -24,12 +24,13 @@ unsigned long find_next_bit(const unsigned long *addr, unsigned long size, const unsigned long *p = addr + BITOP_WORD(offset); unsigned long result = offset & ~(BITS_PER_LONG-1); unsigned long tmp; + unsigned long d0,d1,d2,d3; if (offset >= size) { return size; } size -= result; - offset %= BITS_PER_LONG; + offset &= (BITS_PER_LONG-1); if (offset) { tmp = *(p++); tmp &= (~0UL << offset); @@ -42,7 +43,19 @@ unsigned long find_next_bit(const unsigned long *addr, unsigned long size, size -= BITS_PER_LONG; result += BITS_PER_LONG; } - while (size & ~(BITS_PER_LONG-1)) { + while (size >= 4*BITS_PER_LONG) { + d0 = *p; + d1 = *(p+1); + d2 = *(p+2); + d3 = *(p+3); + if (d0 || d1 || d2 || d3) { + break; + } + p+=4; + result += 4*BITS_PER_LONG; + size -= 4*BITS_PER_LONG; + } + while (size >= BITS_PER_LONG) { if ((tmp = *(p++))) { goto found_middle; }