From patchwork Tue Mar 12 15:52:46 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Lieven X-Patchwork-Id: 227062 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 B7CF92C0080 for ; Wed, 13 Mar 2013 02:53:17 +1100 (EST) Received: from localhost ([::1]:55694 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UFRVs-0005cd-03 for incoming@patchwork.ozlabs.org; Tue, 12 Mar 2013 11:53:16 -0400 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 Received: from localhost (localhost [127.0.0.1]) by ssl.dlh.net (Postfix) with ESMTP id E9E3914540E; Tue, 12 Mar 2013 16:52:44 +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 f4oQ0H+a5LEk; Tue, 12 Mar 2013 16:52:44 +0100 (CET) Received: from [172.21.12.60] (unknown [82.141.1.226]) by ssl.dlh.net (Postfix) with ESMTPSA id 7ECE513F711; Tue, 12 Mar 2013 16:52:44 +0100 (CET) Message-ID: <513F4F4E.1060009@dlhnet.de> Date: Tue, 12 Mar 2013 16:52:46 +0100 From: Peter Lieven User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130221 Thunderbird/17.0.3 MIME-Version: 1.0 To: "qemu-devel@nongnu.org" X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 91.198.192.8 Cc: Kevin Wolf , Paolo Bonzini , Orit Wasserman , Stefan Hajnoczi Subject: [Qemu-devel] [RFC][PATCH 7/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 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; }