From patchwork Sat Oct 8 08:58:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 9368053 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5F8C66075E for ; Sat, 8 Oct 2016 09:11:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 532E0299A0 for ; Sat, 8 Oct 2016 09:11:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 48003299A6; Sat, 8 Oct 2016 09:11:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id F11C2299A0 for ; Sat, 8 Oct 2016 09:11:44 +0000 (UTC) Received: from localhost ([::1]:40044 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bsnfU-0003WW-5b for patchwork-qemu-devel@patchwork.kernel.org; Sat, 08 Oct 2016 05:11:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44166) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bsnap-00088r-G1 for qemu-devel@nongnu.org; Sat, 08 Oct 2016 05:06:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bsnal-0003xk-BC for qemu-devel@nongnu.org; Sat, 08 Oct 2016 05:06:54 -0400 Received: from isrv.corpit.ru ([86.62.121.231]:39373) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bsnal-0003uR-4D; Sat, 08 Oct 2016 05:06:51 -0400 Received: from tsrv.tls.msk.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 40DDC40ED7; Sat, 8 Oct 2016 12:06:49 +0300 (MSK) Received: from tls.msk.ru (mjt.vpn.tls.msk.ru [192.168.177.99]) by tsrv.tls.msk.ru (Postfix) with SMTP id 57DE5B44; Sat, 8 Oct 2016 11:58:17 +0300 (MSK) Received: (nullmailer pid 19264 invoked by uid 1000); Sat, 08 Oct 2016 08:58:14 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org Date: Sat, 8 Oct 2016 11:58:07 +0300 Message-Id: X-Mailer: git-send-email 2.1.4 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 86.62.121.231 Subject: [Qemu-devel] [PULL 21/26] bitmap: refine and move BITMAP_{FIRST/LAST}_WORD_MASK X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-trivial@nongnu.org, Michael Tokarev , Wei Yang Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Wei Yang According to linux kernel commit <89c1e79eb30> ("linux/bitmap.h: improve BITMAP_{LAST,FIRST}_WORD_MASK"), these two macro could be improved. This patch takes this change and also move them all in header file. Signed-off-by: Wei Yang Signed-off-by: Michael Tokarev --- include/qemu/bitmap.h | 7 ++----- util/bitmap.c | 2 -- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/include/qemu/bitmap.h b/include/qemu/bitmap.h index 7247f14..63ea2d0 100644 --- a/include/qemu/bitmap.h +++ b/include/qemu/bitmap.h @@ -57,11 +57,8 @@ * find_next_bit(addr, nbits, bit) Position next set bit in *addr >= bit */ -#define BITMAP_LAST_WORD_MASK(nbits) \ - ( \ - ((nbits) % BITS_PER_LONG) ? \ - (1UL<<((nbits) % BITS_PER_LONG))-1 : ~0UL \ - ) +#define BITMAP_FIRST_WORD_MASK(start) (~0UL << ((start) & (BITS_PER_LONG - 1))) +#define BITMAP_LAST_WORD_MASK(nbits) (~0UL >> (-(nbits) & (BITS_PER_LONG - 1))) #define DECLARE_BITMAP(name,bits) \ unsigned long name[BITS_TO_LONGS(bits)] diff --git a/util/bitmap.c b/util/bitmap.c index 40aadfb..43ed011 100644 --- a/util/bitmap.c +++ b/util/bitmap.c @@ -157,8 +157,6 @@ int slow_bitmap_andnot(unsigned long *dst, const unsigned long *bitmap1, return result != 0; } -#define BITMAP_FIRST_WORD_MASK(start) (~0UL << ((start) % BITS_PER_LONG)) - void bitmap_set(unsigned long *map, long start, long nr) { unsigned long *p = map + BIT_WORD(start);