diff mbox

[v6,02/11] Add uleb encoding/decoding functions

Message ID 1327490809-21393-3-git-send-email-owasserm@redhat.com
State New
Headers show

Commit Message

Orit Wasserman Jan. 25, 2012, 11:26 a.m. UTC
Implement Unsigned Little Endian Base 128.

Signed-off-by: Orit Wasserman <owasserm@redhat.com>
---
 migration.h |    4 ++++
 savevm.c    |   26 ++++++++++++++++++++++++++
 2 files changed, 30 insertions(+), 0 deletions(-)

Comments

Orit Wasserman Jan. 25, 2012, 12:22 p.m. UTC | #1
On 01/25/2012 01:48 PM, Avi Kivity wrote:
> On 01/25/2012 01:26 PM, Orit Wasserman wrote:
>> Implement Unsigned Little Endian Base 128.
>>
>>  
>> +/* 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 80be1ff..304db31 100644
>> --- a/savevm.c
>> +++ b/savevm.c
>> @@ -2297,3 +2297,29 @@ 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?
oops , where did it go ...
I will fix it asp.
> 
>> +    }
>> +    return 0;
>> +}
>> +
>> +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 0;
> 
> return 2?
> 
>> +    }
>> +}
>> +
> 
>
Orit Wasserman Jan. 25, 2012, 12:27 p.m. UTC | #2
On 01/25/2012 02:22 PM, Orit Wasserman wrote:
> On 01/25/2012 01:48 PM, Avi Kivity wrote:
>> On 01/25/2012 01:26 PM, Orit Wasserman wrote:
>>> Implement Unsigned Little Endian Base 128.
>>>
>>>  
>>> +/* 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 80be1ff..304db31 100644
>>> --- a/savevm.c
>>> +++ b/savevm.c
>>> @@ -2297,3 +2297,29 @@ 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?
> oops , where did it go ...
for some reason it is in patch 5 
I will fix the patch series ..

> I will fix it asp.
>>
>>> +    }
>>> +    return 0;
>>> +}
>>> +
>>> +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 0;
>>
>> return 2?
>>
>>> +    }
>>> +}
>>> +
>>
>>
>
diff mbox

Patch

diff --git a/migration.h b/migration.h
index 372b066..50dec18 100644
--- a/migration.h
+++ b/migration.h
@@ -95,4 +95,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 80be1ff..304db31 100644
--- a/savevm.c
+++ b/savevm.c
@@ -2297,3 +2297,29 @@  void vmstate_register_ram_global(MemoryRegion *mr)
 {
     vmstate_register_ram(mr, NULL);
 }
+
+/* ULEB128 */
+int uleb128_encode_small(uint8_t *out, uint32_t n)
+{
+    if (n < 0x80) {
+        *out++ = n;
+        return 1;
+    } else {
+        *out++ = (n & 0x7f) | 0x80;
+        *out++ = n >> 7;
+    }
+    return 0;
+}
+
+int uleb128_decode_small(const uint8 *in, uint32_t *n)
+{
+    if (!(*in & 0x80)) {
+        *n = *in++;
+        return 1;
+    } else {
+        *n = *in++ & 0x7f;
+        *n |= *in++ << 7;
+        return 0;
+    }
+}
+