From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45416) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1asWf7-0000TL-8I for qemu-devel@nongnu.org; Tue, 19 Apr 2016 10:29:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1asWf4-0002sN-JG for qemu-devel@nongnu.org; Tue, 19 Apr 2016 10:29:57 -0400 Received: from mga03.intel.com ([134.134.136.65]:58403) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1asWf4-0002s0-Dp for qemu-devel@nongnu.org; Tue, 19 Apr 2016 10:29:54 -0400 From: Liang Li Date: Tue, 19 Apr 2016 22:20:39 +0800 Message-Id: <1461075643-3668-2-git-send-email-liang.z.li@intel.com> In-Reply-To: <1461075643-3668-1-git-send-email-liang.z.li@intel.com> References: <1461075643-3668-1-git-send-email-liang.z.li@intel.com> Subject: [Qemu-devel] [PATCH QEMU 1/5] bitmap: Add a new bitmap_move function List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: mst@redhat.com, quintela@redhat.com, amit.shah@redhat.com, pbonzini@redhat.com, lcapitulino@redhat.com Cc: armbru@redhat.com, peter.maydell@linaro.org, rth@twiddle.net, ehabkost@redhat.com, james.hogan@imgtec.com, aurelien@aurel32.net, leon.alrae@imgtec.com, agraf@suse.de, borntraeger@de.ibm.com, cornelia.huck@de.ibm.com, qemu-devel@nongnu.org, kvm@vger.kernel.org, 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 0e33fa5..ce07444 100644 --- a/include/qemu/bitmap.h +++ b/include/qemu/bitmap.h @@ -38,6 +38,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 */ @@ -137,6 +138,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.8.3.1