From mboxrd@z Thu Jan 1 00:00:00 1970 From: Liang Li Subject: [QEMU v2 7/9] bitmap: Add a new bitmap_move function Date: Fri, 15 Jul 2016 10:47:27 +0800 Message-ID: <1468550849-22172-8-git-send-email-liang.z.li@intel.com> References: <1468550849-22172-1-git-send-email-liang.z.li@intel.com> Cc: mst@redhat.com, pbonzini@redhat.com, quintela@redhat.com, amit.shah@redhat.com, kvm@vger.kernel.org, dgilbert@redhat.com, thuth@redhat.com, Liang Li To: qemu-devel@nongnu.org Return-path: Received: from mga01.intel.com ([192.55.52.88]:10619 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752353AbcGOC4A (ORCPT ); Thu, 14 Jul 2016 22:56:00 -0400 In-Reply-To: <1468550849-22172-1-git-send-email-liang.z.li@intel.com> Sender: kvm-owner@vger.kernel.org List-ID: 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 --- include/qemu/bitmap.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/qemu/bitmap.h b/include/qemu/bitmap.h index ec5146f..6ac89ca 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 */ @@ -136,6 +137,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) { -- 1.9.1 From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56511) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bNtIH-0007Dr-Gt for qemu-devel@nongnu.org; Thu, 14 Jul 2016 22:56:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bNtIG-0006kH-If for qemu-devel@nongnu.org; Thu, 14 Jul 2016 22:56:01 -0400 Received: from mga14.intel.com ([192.55.52.115]:62918) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bNtIG-0006ik-DC for qemu-devel@nongnu.org; Thu, 14 Jul 2016 22:56:00 -0400 From: Liang Li Date: Fri, 15 Jul 2016 10:47:27 +0800 Message-Id: <1468550849-22172-8-git-send-email-liang.z.li@intel.com> In-Reply-To: <1468550849-22172-1-git-send-email-liang.z.li@intel.com> References: <1468550849-22172-1-git-send-email-liang.z.li@intel.com> Subject: [Qemu-devel] [QEMU v2 7/9] bitmap: Add a new bitmap_move function List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: mst@redhat.com, pbonzini@redhat.com, quintela@redhat.com, amit.shah@redhat.com, kvm@vger.kernel.org, dgilbert@redhat.com, thuth@redhat.com, Liang Li 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 --- include/qemu/bitmap.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/qemu/bitmap.h b/include/qemu/bitmap.h index ec5146f..6ac89ca 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 */ @@ -136,6 +137,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) { -- 1.9.1