From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:34381) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SFkGJ-0001P0-4d for qemu-devel@nongnu.org; Thu, 05 Apr 2012 06:50:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SFkGC-0004yO-J9 for qemu-devel@nongnu.org; Thu, 05 Apr 2012 06:49:53 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51337) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SFkGC-0004xy-BM for qemu-devel@nongnu.org; Thu, 05 Apr 2012 06:49:48 -0400 From: Orit Wasserman Date: Thu, 5 Apr 2012 13:47:51 +0300 Message-Id: <1333622879-12055-3-git-send-email-owasserm@redhat.com> In-Reply-To: <1333622879-12055-1-git-send-email-owasserm@redhat.com> References: <1333622879-12055-1-git-send-email-owasserm@redhat.com> Subject: [Qemu-devel] [PATCH v8 02/10] Add uleb encoding/decoding functions List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: aliguori@us.ibm.com, quintela@redhat.com, stefanha@gmail.com, blauwirbel@gmail.com, Orit Wasserman , avi@redhat.com Implement Unsigned Little Endian Base 128. Signed-off-by: Orit Wasserman --- migration.h | 4 ++++ savevm.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 0 deletions(-) diff --git a/migration.h b/migration.h index 691b367..d798fac 100644 --- a/migration.h +++ b/migration.h @@ -92,4 +92,8 @@ void migrate_add_blocker(Error *reason); */ void migrate_del_blocker(Error *reason); +/* ULEB128 */ +int uleb128_encode_small(uint8_t *out, uint32_t n); +int uleb128_decode_small(const uint8 *in, uint32_t *n); + #endif diff --git a/savevm.c b/savevm.c index 12fb209..0b2fe38 100644 --- a/savevm.c +++ b/savevm.c @@ -2368,3 +2368,31 @@ void vmstate_register_ram_global(MemoryRegion *mr) { vmstate_register_ram(mr, NULL); } + +/* ULEB128 */ +int uleb128_encode_small(uint8_t *out, uint32_t n) +{ + assert(n <= 0x3fff); + if (n < 0x80) { + *out++ = n; + return 1; + } else { + *out++ = (n & 0x7f) | 0x80; + *out++ = n >> 7; + return 2; + } +} + +int uleb128_decode_small(const uint8 *in, uint32_t *n) +{ + if (!(*in & 0x80)) { + *n = *in++; + return 1; + } else { + *n = *in++ & 0x7f; + assert(!(*in & 0x80)); + *n |= *in++ << 7; + return 2; + } +} + -- 1.7.7.6