From patchwork Fri Mar 15 15:50:13 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Lieven X-Patchwork-Id: 228153 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 A19752C00B1 for ; Sat, 16 Mar 2013 06:30:36 +1100 (EST) Received: from localhost ([::1]:35458 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UGaKo-0005oc-PV for incoming@patchwork.ozlabs.org; Fri, 15 Mar 2013 15:30:34 -0400 Received: from eggs.gnu.org ([208.118.235.92]:58204) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UGXDr-0001XI-GD for qemu-devel@nongnu.org; Fri, 15 Mar 2013 12:11:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UGXDn-0006JE-7S for qemu-devel@nongnu.org; Fri, 15 Mar 2013 12:11:11 -0400 Received: from [2a02:248:0:30:223:aeff:fefe:7f1c] (port=48340 helo=dns.kamp-intra.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UGXDn-0006HY-0J for qemu-devel@nongnu.org; Fri, 15 Mar 2013 12:11:07 -0400 Received: from lieven-pc.kamp-intra.net (lieven-pc.kamp-intra.net [172.21.12.60]) by dns.kamp-intra.net (Postfix) with ESMTP id 227CA206EA; Fri, 15 Mar 2013 16:51:53 +0100 (CET) Received: by lieven-pc.kamp-intra.net (Postfix, from userid 1000) id DF8A562EA2; Fri, 15 Mar 2013 16:51:52 +0100 (CET) From: Peter Lieven To: qemu-devel@nongnu.org Date: Fri, 15 Mar 2013 16:50:13 +0100 Message-Id: <1363362619-3190-5-git-send-email-pl@kamp.de> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1363362619-3190-1-git-send-email-pl@kamp.de> References: <1363362619-3190-1-git-send-email-pl@kamp.de> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 2a02:248:0:30:223:aeff:fefe:7f1c X-Mailman-Approved-At: Fri, 15 Mar 2013 15:28:26 -0400 Cc: Peter Lieven Subject: [Qemu-devel] [PATCHv2 4/9] bitops: use vector algorithm to optimize find_next_bit() 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 this patch adds the usage of buffer_find_nonzero_offset() to skip large areas of zeroes. compared to loop unrolling presented in an earlier patch this adds another 50% performance benefit for skipping large areas of zeroes. loop unrolling alone added close to 100% speedup. Signed-off-by: Peter Lieven --- util/bitops.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/util/bitops.c b/util/bitops.c index e72237a..3c301fa 100644 --- a/util/bitops.c +++ b/util/bitops.c @@ -42,10 +42,30 @@ 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 * sizeof(VECTYPE) + * BUFFER_FIND_NONZERO_OFFSET_UNROLL_FACTOR) { + unsigned long tmp2 = + buffer_find_nonzero_offset(p, ((size / BITS_PER_BYTE) & + ~(BUFFER_FIND_NONZERO_OFFSET_UNROLL_FACTOR * + 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; }