From patchwork Wed Apr 11 18:49:05 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Orit Wasserman X-Patchwork-Id: 151851 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 40A42B7060 for ; Thu, 12 Apr 2012 04:50:04 +1000 (EST) Received: from localhost ([::1]:52168 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SI2cD-0004x5-Kz for incoming@patchwork.ozlabs.org; Wed, 11 Apr 2012 14:50:01 -0400 Received: from eggs.gnu.org ([208.118.235.92]:48010) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SI2bz-0004ty-9T for qemu-devel@nongnu.org; Wed, 11 Apr 2012 14:49:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SI2bw-0004v2-5h for qemu-devel@nongnu.org; Wed, 11 Apr 2012 14:49:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56405) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SI2bv-0004ul-TO for qemu-devel@nongnu.org; Wed, 11 Apr 2012 14:49:44 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q3BInfgF018596 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 11 Apr 2012 14:49:41 -0400 Received: from dhcp-1-120.tlv.redhat.com (reserved-201-244.tlv.redhat.com [10.35.201.244] (may be forged)) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q3BInUsG008086; Wed, 11 Apr 2012 14:49:39 -0400 From: Orit Wasserman To: qemu-devel@nongnu.org Date: Wed, 11 Apr 2012 21:49:05 +0300 Message-Id: <1334170153-9503-3-git-send-email-owasserm@redhat.com> In-Reply-To: <1334170153-9503-1-git-send-email-owasserm@redhat.com> References: <1334170153-9503-1-git-send-email-owasserm@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: aliguori@us.ibm.com, quintela@redhat.com, stefanha@gmail.com, blauwirbel@gmail.com, Orit Wasserman , avi@redhat.com Subject: [Qemu-devel] [PATCH v9 02/10] Add uleb encoding/decoding functions X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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; + } +} +