From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:57645) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UFRVS-0005WV-Hq for qemu-devel@nongnu.org; Tue, 12 Mar 2013 11:52:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UFRVO-0003IQ-VZ for qemu-devel@nongnu.org; Tue, 12 Mar 2013 11:52:50 -0400 Received: from ssl.dlhnet.de ([91.198.192.8]:46051 helo=ssl.dlh.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UFRVO-0003Hq-OI for qemu-devel@nongnu.org; Tue, 12 Mar 2013 11:52:46 -0400 Message-ID: <513F4F4E.1060009@dlhnet.de> Date: Tue, 12 Mar 2013 16:52:46 +0100 From: Peter Lieven MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] [RFC][PATCH 7/9] bitops: use vector algorithm to optimize find_next_bit() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "qemu-devel@nongnu.org" Cc: Kevin Wolf , Paolo Bonzini , Orit Wasserman , Stefan Hajnoczi this patch adds the usage of buffer_find_nonzero_offset() to skip large areas of zeroes. compared to loop unrolling this adds another 50% performance benefit for skipping large areas of zeroes. Signed-off-by: Peter Lieven --- util/bitops.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/util/bitops.c b/util/bitops.c index e72237a..0a056ff 100644 --- a/util/bitops.c +++ b/util/bitops.c @@ -42,10 +42,27 @@ 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)) { - if ((tmp = *(p++))) { - goto found_middle; + while (size >= BITS_PER_LONG) { + if ((tmp = *p)) { + goto found_middle; + } + if (((uintptr_t) p) % sizeof(VECTYPE) == 0 + && size >= BITS_PER_BYTE*8*sizeof(VECTYPE)) { + unsigned long tmp2 = + buffer_find_nonzero_offset(p, ((size/BITS_PER_BYTE) & ~(8*sizeof(VECTYPE)-1))); + result += tmp2 * BITS_PER_BYTE; + size -= tmp2 * BITS_PER_BYTE; + p += tmp2 / sizeof(unsigned long); + if (!size) { + return result; + } + if (tmp2) { + if ((tmp = *p)) { + goto found_middle; + } + } } + p++; result += BITS_PER_LONG; size -= BITS_PER_LONG; } -- 1.7.9.5