From patchwork Thu Mar 21 15:57:32 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Lieven X-Patchwork-Id: 229740 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 5561F2C0092 for ; Fri, 22 Mar 2013 02:58:49 +1100 (EST) Received: from localhost ([::1]:42266 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UIht9-0006wr-HR for incoming@patchwork.ozlabs.org; Thu, 21 Mar 2013 11:58:47 -0400 Received: from eggs.gnu.org ([208.118.235.92]:38558) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UIhsS-0006hq-3X for qemu-devel@nongnu.org; Thu, 21 Mar 2013 11:58:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UIhsO-0002jO-3G for qemu-devel@nongnu.org; Thu, 21 Mar 2013 11:58:03 -0400 Received: from [2a02:248:0:30:223:aeff:fefe:7f1c] (port=33566 helo=dns.kamp-intra.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UIhsN-0002jB-U4 for qemu-devel@nongnu.org; Thu, 21 Mar 2013 11:58:00 -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 5A1CE206AE; Thu, 21 Mar 2013 16:57:59 +0100 (CET) Received: by lieven-pc.kamp-intra.net (Postfix, from userid 1000) id 103495FCAE; Thu, 21 Mar 2013 16:58:10 +0100 (CET) From: Peter Lieven To: qemu-devel@nongnu.org Date: Thu, 21 Mar 2013 16:57:32 +0100 Message-Id: <1363881457-14814-5-git-send-email-pl@kamp.de> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1363881457-14814-1-git-send-email-pl@kamp.de> References: <1363881457-14814-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 Cc: kwolf@redhat.com, pbonzini@redhat.com, Peter Lieven Subject: [Qemu-devel] [PATCHv3 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 Reviewed-by: Eric Blake --- util/bitops.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/util/bitops.c b/util/bitops.c index e72237a..8ea79ae 100644 --- a/util/bitops.c +++ b/util/bitops.c @@ -42,10 +42,26 @@ 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 (can_use_buffer_find_nonzero_offset(p, size / BITS_PER_BYTE)) { + size_t tmp2 = + buffer_find_nonzero_offset(p, size / BITS_PER_BYTE); + 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; }