static __tb_inline__ tb_size_t tb_object_bplist_bits_get(tb_byte_t const* p, tb_size_t n) { tb_size_t v = 0; switch (n) { case 1: v = tb_bits_get_u8((p)); break; case 2: v = tb_bits_get_u16_be((p)); break; case 4: v = tb_bits_get_u32_be((p)); break; case 8: v = tb_bits_get_u64_be((p)); break; default: break; } return v; }
/* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ tb_uint32_t tb_bits_get_ubits32(tb_byte_t const* p, tb_size_t b, tb_size_t n) { // check tb_assert(p && n <= 32); // no bits? tb_check_return_val(n, 0); // done p += b >> 3; b &= 0x07; if (!b && n == 1) return tb_bits_get_u1(p); else if (!b && n == 8) return tb_bits_get_u8(p); else if (!b && n == 16) return tb_bits_get_u16_be(p); else if (!b && n == 24) return tb_bits_get_u24_be(p); else if (!b && n == 32) return tb_bits_get_u32_be(p); else { #if defined(tb_bits_get_ubits32_impl) return tb_bits_get_ubits32_impl(p, b, n); #elif defined(__tb_small__) tb_uint32_t x = 0; tb_size_t i = b; tb_int_t j = 24; b += n; while (b > 7) { x |= *p++ << (i + j); j -= 8; b -= 8; } if (b > 0) x |= j < 0? (*p >> (8 - i)) : *p << (i + j); return (n < 32)? (x >> (32 - n)) : x; #else tb_uint32_t x = 0; tb_size_t i = b; b += n; if (b > 32) { x |= p[0] << (i + 24); x |= p[1] << (i + 16); x |= p[2] << (i + 8); x |= p[3] << (i + 0); x |= p[4] >> (8 - i); } else if (b > 24)