From patchwork Wed Jan 11 08:48:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Liang Z" X-Patchwork-Id: 713634 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3tz2x84nXYz9t0q for ; Wed, 11 Jan 2017 20:03:22 +1100 (AEDT) Received: from localhost ([::1]:52356 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cREoR-0000Ly-Eu for incoming@patchwork.ozlabs.org; Wed, 11 Jan 2017 04:03:19 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33378) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cREhi-0002eN-K5 for qemu-devel@nongnu.org; Wed, 11 Jan 2017 03:56:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cREhf-00050p-G1 for qemu-devel@nongnu.org; Wed, 11 Jan 2017 03:56:22 -0500 Received: from mga02.intel.com ([134.134.136.20]:3591) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cREhf-0004zB-5y for qemu-devel@nongnu.org; Wed, 11 Jan 2017 03:56:19 -0500 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga101.jf.intel.com with ESMTP; 11 Jan 2017 00:56:17 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.33,345,1477983600"; d="scan'208"; a="1110966988" Received: from ll.sh.intel.com (HELO localhost) ([10.239.13.123]) by fmsmga002.fm.intel.com with ESMTP; 11 Jan 2017 00:56:15 -0800 From: Liang Li To: qemu-devel@nongnu.org Date: Wed, 11 Jan 2017 16:48:42 +0800 Message-Id: <1484124524-481-5-git-send-email-liang.z.li@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1484124524-481-1-git-send-email-liang.z.li@intel.com> References: <1484124524-481-1-git-send-email-liang.z.li@intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 134.134.136.20 Subject: [Qemu-devel] [PATCH v4 qemu 4/6] bitmap: Add a new bitmap_move function 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: mtosatti@redhat.com, kvm@vger.kernel.org, mst@redhat.com, uintela@redhat.com, dgilbert@redhat.com, dave.hansen@intel.com, wei.w.wang@intel.com, amit.shah@redhat.com, pbonzini@redhat.com, Liang Li Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Sometimes, it is need to move a portion of bitmap to another place in a large bitmap, if overlap happens, the bitmap_copy can't not work correctly, we need a new function to do this work. Signed-off-by: Liang Li Reviewed-by: Dr. David Alan Gilbert --- include/qemu/bitmap.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/qemu/bitmap.h b/include/qemu/bitmap.h index 63ea2d0..775d05e 100644 --- a/include/qemu/bitmap.h +++ b/include/qemu/bitmap.h @@ -37,6 +37,7 @@ * bitmap_set(dst, pos, nbits) Set specified bit area * bitmap_set_atomic(dst, pos, nbits) Set specified bit area with atomic ops * bitmap_clear(dst, pos, nbits) Clear specified bit area + * bitmap_move(dst, src, nbits) Move *src to *dst * bitmap_test_and_clear_atomic(dst, pos, nbits) Test and clear area * bitmap_find_next_zero_area(buf, len, pos, n, mask) Find bit free area */ @@ -129,6 +130,18 @@ static inline void bitmap_copy(unsigned long *dst, const unsigned long *src, } } +static inline void bitmap_move(unsigned long *dst, const unsigned long *src, + long nbits) +{ + if (small_nbits(nbits)) { + unsigned long tmp = *src; + *dst = tmp; + } else { + long len = BITS_TO_LONGS(nbits) * sizeof(unsigned long); + memmove(dst, src, len); + } +} + static inline int bitmap_and(unsigned long *dst, const unsigned long *src1, const unsigned long *src2, long nbits) {