[Qemu-devel] [PATCH 05/11] Add uleb encoding/decoding functions

2012-08-05 Thread Orit Wasserman
Implement Unsigned Little Endian Base 128.

Signed-off-by: Orit Wasserman owass...@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




[Qemu-devel] [PATCH 05/11] Add uleb encoding/decoding functions

2012-08-02 Thread Orit Wasserman
Implement Unsigned Little Endian Base 128.

Signed-off-by: Orit Wasserman owass...@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




[Qemu-devel] [PATCH 05/11] Add uleb encoding/decoding functions

2012-08-01 Thread Juan Quintela
From: Orit Wasserman owass...@redhat.com

Implement Unsigned Little Endian Base 128.

Signed-off-by: Orit Wasserman owass...@redhat.com
Signed-off-by: Juan Quintela quint...@redhat.com
---
 cutils.c  | 33 +
 qemu-common.h |  8 
 2 files changed, 41 insertions(+)

diff --git a/cutils.c b/cutils.c
index 35e2e2b..ee4614d 100644
--- a/cutils.c
+++ b/cutils.c
@@ -391,3 +391,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 432545b..b906b21 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.11.2




[Qemu-devel] [PATCH 05/11] Add uleb encoding/decoding functions

2012-07-31 Thread Orit Wasserman
Implement Unsigned Little Endian Base 128.

Signed-off-by: Orit Wasserman owass...@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




[Qemu-devel] [PATCH 05/11] Add uleb encoding/decoding functions

2012-07-29 Thread Orit Wasserman
Implement Unsigned Little Endian Base 128.

Signed-off-by: Orit Wasserman owass...@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




[Qemu-devel] [PATCH 05/11] Add uleb encoding/decoding functions

2012-07-25 Thread Orit Wasserman
Implement Unsigned Little Endian Base 128.

Signed-off-by: Orit Wasserman owass...@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 195bab5..3188bdd 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




[Qemu-devel] [PATCH 05/11] Add uleb encoding/decoding functions

2012-07-24 Thread Juan Quintela
From: Orit Wasserman owass...@redhat.com

Implement Unsigned Little Endian Base 128.

Signed-off-by: Orit Wasserman owass...@redhat.com
Signed-off-by: Juan Quintela quint...@redhat.com
---
 cutils.c  |   33 +
 qemu-common.h |8 
 2 files changed, 41 insertions(+)

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 5ced6ec..6ed48cc 100644
--- a/qemu-common.h
+++ b/qemu-common.h
@@ -425,4 +425,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.10.4