From 4a99abba123fc1d2bef62778846a1f27b2012de0 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Fri, 6 May 2011 13:18:38 -0700 Subject: Refactor varint encoding/decoding. --- src/upb_decoder_x86.dasc | 25 ++----------------------- 1 file changed, 2 insertions(+), 23 deletions(-) (limited to 'src/upb_decoder_x86.dasc') diff --git a/src/upb_decoder_x86.dasc b/src/upb_decoder_x86.dasc index 4088eba..d02f7d1 100644 --- a/src/upb_decoder_x86.dasc +++ b/src/upb_decoder_x86.dasc @@ -249,28 +249,7 @@ void upb_reg_jit_gdb(upb_decoder *d) { |.endmacro #include -#include "upb_varint_decoder.h" - -static size_t upb_value_size(uint64_t val) { -#ifdef __GNUC__ - int high_bit = 63 - __builtin_clzll(val); // 0-based, undef if val == 0. -#else - int high_bit = 0; - uint64_t tmp = val; - while(tmp >>= 1) high_bit++; -#endif - return val == 0 ? 1 : high_bit / 8 + 1; -} - -static uint64_t upb_encode_varint(uint64_t val) -{ - uint64_t ret = 0; - for (int bitpos = 0; val; bitpos+=8, val >>=7) { - if (bitpos > 0) ret |= (1 << (bitpos-1)); - ret |= (val & 0x7f) << bitpos; - } - return ret; -} +#include "upb_varint.h" // PTR should point to the beginning of the tag. static void upb_decoder_jit_field(upb_decoder *d, uint32_t tag, uint32_t next_tag, @@ -493,7 +472,7 @@ static void upb_decoder_jit_msg(upb_decoder *d, upb_handlers_msgent *m) { for(int i = 0; i < num_keys; i++) { uint32_t key = keys[i]; upb_handlers_fieldent *f = upb_inttable_lookup(&m->fieldtab, key); - uint32_t tag = upb_encode_varint(key); + uint32_t tag = upb_vencode(key); if (last_f) upb_decoder_jit_field(d, last_tag, tag, m, last_f, f); last_tag = tag; last_f = f; -- cgit v1.2.3