From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36604) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VuhHT-0006Og-CX for qemu-devel@nongnu.org; Sun, 22 Dec 2013 06:33:16 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VuhHN-0001cw-Lv for qemu-devel@nongnu.org; Sun, 22 Dec 2013 06:33:11 -0500 Received: from hall.aurel32.net ([2001:bc8:30d7:101::1]:50353) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VuhHN-0001cs-Fq for qemu-devel@nongnu.org; Sun, 22 Dec 2013 06:33:05 -0500 From: Aurelien Jarno Date: Sun, 22 Dec 2013 12:32:37 +0100 Message-Id: <1387711957-703-1-git-send-email-aurelien@aurel32.net> Subject: [Qemu-devel] [PATCH] bitops: provide an inline implementation of find_first_bit List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Corentin Chary , Aurelien Jarno , Richard Henderson find_first_bit has started to be used heavily in TCG code. The current implementation based on find_next_bit is not optimal and can't be optimized be the compiler if the bit array has a fixed size, which is the case most of the time. This new implementation does not use find_next_bit and is yet small enough to be inlined. Cc: Richard Henderson Cc: Corentin Chary Signed-off-by: Aurelien Jarno --- include/qemu/bitops.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/include/qemu/bitops.h b/include/qemu/bitops.h index 304c90c..041142a 100644 --- a/include/qemu/bitops.h +++ b/include/qemu/bitops.h @@ -157,7 +157,17 @@ unsigned long find_next_zero_bit(const unsigned long *addr, static inline unsigned long find_first_bit(const unsigned long *addr, unsigned long size) { - return find_next_bit(addr, size, 0); + unsigned long result, tmp; + + for (result = 0; result < size; result += BITS_PER_LONG) { + tmp = *addr++; + if (tmp) { + result += ctzl(tmp); + return result < size ? result : size; + } + } + /* Not found */ + return size; } /** -- 1.7.10.4