From: Orit Wasserman <owasserm@redhat.com>
To: qemu-devel@nongnu.org
Cc: peter.maydell@linaro.org, aliguori@us.ibm.com,
quintela@redhat.com, stefanha@gmail.com,
mdroth@linux.vnet.ibm.com, lcapitulino@redhat.com,
blauwirbel@gmail.com, Orit Wasserman <owasserm@redhat.com>,
chegu_vinod@hp.com, avi@redhat.com, pbonzini@redhat.com,
eblake@redhat.com
Subject: [Qemu-devel] [PATCH 05/11] Add uleb encoding/decoding functions
Date: Sun, 29 Jul 2012 12:42:57 +0300 [thread overview]
Message-ID: <1343554983-4195-6-git-send-email-owasserm@redhat.com> (raw)
In-Reply-To: <1343554983-4195-1-git-send-email-owasserm@redhat.com>
Implement Unsigned Little Endian Base 128.
Signed-off-by: Orit Wasserman <owasserm@redhat.com>
---
cutils.c | 33 +++++++++++++++++++++++++++++++++
qemu-common.h | 8 ++++++++
2 files changed, 41 insertions(+), 0 deletions(-)
diff --git a/cutils.c b/cutils.c
index b0bdd4b..700f943 100644
--- a/cutils.c
+++ b/cutils.c
@@ -384,3 +384,36 @@ int64_t pow2floor(int64_t value)
}
return value;
}
+
+/*
+ * Implementation of ULEB128 (http://en.wikipedia.org/wiki/LEB128)
+ * Input is limited to 14-bit numbers
+ */
+int uleb128_encode_small(uint8_t *out, uint32_t n)
+{
+ g_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_t *in, uint32_t *n)
+{
+ if (!(*in & 0x80)) {
+ *n = *in++;
+ return 1;
+ } else {
+ *n = *in++ & 0x7f;
+ /* we exceed 14 bit number */
+ if (*in & 0x80) {
+ return -1;
+ }
+ *n |= *in++ << 7;
+ return 2;
+ }
+}
diff --git a/qemu-common.h b/qemu-common.h
index 855f242..93d1c63 100644
--- a/qemu-common.h
+++ b/qemu-common.h
@@ -426,4 +426,12 @@ int64_t pow2floor(int64_t value);
#include "module.h"
+/*
+ * Implementation of ULEB128 (http://en.wikipedia.org/wiki/LEB128)
+ * Input is limited to 14-bit numbers
+ */
+
+int uleb128_encode_small(uint8_t *out, uint32_t n);
+int uleb128_decode_small(const uint8_t *in, uint32_t *n);
+
#endif
--
1.7.7.6
next prev parent reply other threads:[~2012-07-29 9:43 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-29 9:42 [Qemu-devel] [PATCH 00/11] Migration next v7 Orit Wasserman
2012-07-29 9:42 ` [Qemu-devel] [PATCH 01/11] Add migration capabilities Orit Wasserman
2012-07-30 17:24 ` Luiz Capitulino
2012-07-30 17:29 ` Luiz Capitulino
2012-07-30 17:45 ` Eric Blake
2012-07-29 9:42 ` [Qemu-devel] [PATCH 02/11] Add migrate_set_parameter and query-migrate-parameters Orit Wasserman
2012-07-30 17:41 ` Luiz Capitulino
2012-07-31 7:46 ` Orit Wasserman
2012-07-31 13:09 ` Luiz Capitulino
2012-07-31 8:03 ` Orit Wasserman
2012-07-30 18:11 ` Eric Blake
2012-07-30 18:15 ` Luiz Capitulino
2012-07-30 19:12 ` Juan Quintela
2012-07-30 19:24 ` Eric Blake
2012-07-30 19:37 ` Anthony Liguori
2012-07-30 20:21 ` Juan Quintela
2012-07-30 19:45 ` Anthony Liguori
2012-07-30 19:58 ` Luiz Capitulino
2012-07-30 20:04 ` Anthony Liguori
2012-07-30 20:20 ` Luiz Capitulino
2012-07-29 9:42 ` [Qemu-devel] [PATCH 03/11] Add XBZRLE documentation Orit Wasserman
2012-07-29 9:42 ` [Qemu-devel] [PATCH 04/11] Add cache handling functions Orit Wasserman
2012-07-29 9:42 ` Orit Wasserman [this message]
2012-07-29 9:42 ` [Qemu-devel] [PATCH 06/11] Add xbzrle_encode_buffer and xbzrle_decode_buffer functions Orit Wasserman
2012-07-29 9:42 ` [Qemu-devel] [PATCH 07/11] Add XBZRLE to ram_save_block and ram_save_live Orit Wasserman
2012-07-29 9:43 ` [Qemu-devel] [PATCH 08/11] Add migrate_set_cachesize command Orit Wasserman
2012-07-29 9:43 ` [Qemu-devel] [PATCH 09/11] Add migration accounting for normal and duplicate pages Orit Wasserman
2012-07-30 19:30 ` Luiz Capitulino
2012-07-31 8:36 ` Orit Wasserman
2012-07-31 13:19 ` Luiz Capitulino
2012-07-29 9:43 ` [Qemu-devel] [PATCH 10/11] Add XBZRLE statistics Orit Wasserman
2012-07-30 19:37 ` Luiz Capitulino
2012-07-31 8:31 ` Orit Wasserman
2012-07-31 13:16 ` Luiz Capitulino
2012-07-31 14:13 ` Orit Wasserman
2012-07-31 15:54 ` Luiz Capitulino
2012-07-29 9:43 ` [Qemu-devel] [PATCH 11/11] Restart optimization on stage3 update version Orit Wasserman
2012-07-30 19:38 ` [Qemu-devel] [PATCH 00/11] Migration next v7 Luiz Capitulino
2012-07-30 20:36 ` Orit Wasserman
2012-07-30 22:13 ` Juan Quintela
-- strict thread matches above, loose matches on Subject: below --
2012-08-05 9:13 [Qemu-devel] [PATCH 00/11] Migration next v10 Orit Wasserman
2012-08-05 9:13 ` [Qemu-devel] [PATCH 05/11] Add uleb encoding/decoding functions Orit Wasserman
2012-08-02 12:44 [Qemu-devel] [PATCH 00/11] Migration next v9 Orit Wasserman
2012-08-02 12:44 ` [Qemu-devel] [PATCH 05/11] Add uleb encoding/decoding functions Orit Wasserman
2012-08-01 18:01 [Qemu-devel] [PULL 00/11] Migration next Juan Quintela
2012-08-01 18:01 ` [Qemu-devel] [PATCH 05/11] Add uleb encoding/decoding functions Juan Quintela
2012-07-31 18:54 [Qemu-devel] [PATCH 00/11] Migration next v8 Orit Wasserman
2012-07-31 18:54 ` [Qemu-devel] [PATCH 05/11] Add uleb encoding/decoding functions Orit Wasserman
2012-07-25 14:50 [Qemu-devel] [PATCH 00/11] Migration next v6 Orit Wasserman
2012-07-25 14:50 ` [Qemu-devel] [PATCH 05/11] Add uleb encoding/decoding functions Orit Wasserman
2012-07-24 18:19 [Qemu-devel] [PATCH 00/11] Migration next v5 Juan Quintela
2012-07-24 18:19 ` [Qemu-devel] [PATCH 05/11] Add uleb encoding/decoding functions Juan Quintela
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1343554983-4195-6-git-send-email-owasserm@redhat.com \
--to=owasserm@redhat.com \
--cc=aliguori@us.ibm.com \
--cc=avi@redhat.com \
--cc=blauwirbel@gmail.com \
--cc=chegu_vinod@hp.com \
--cc=eblake@redhat.com \
--cc=lcapitulino@redhat.com \
--cc=mdroth@linux.vnet.ibm.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=quintela@redhat.com \
--cc=stefanha@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).