MCPcopy Create free account
hub / github.com/CodingGay/BlackDex / UnsignedLeb128Size

Function UnsignedLeb128Size

Bcore/src/main/cpp/base/leb128.h:201–208  ·  view source on GitHub ↗

Returns the number of bytes needed to encode the value in unsigned LEB128.

Source from the content-addressed store, hash-verified

199
200// Returns the number of bytes needed to encode the value in unsigned LEB128.
201static inline uint32_t UnsignedLeb128Size(uint32_t data) {
202 // bits_to_encode = (data != 0) ? 32 - CLZ(x) : 1 // 32 - CLZ(data | 1)
203 // bytes = ceil(bits_to_encode / 7.0); // (6 + bits_to_encode) / 7
204 uint32_t x = 6 + 32 - CLZ(data | 1U);
205 // Division by 7 is done by (x * 37) >> 8 where 37 = ceil(256 / 7).
206 // This works for 0 <= x < 256 / (7 * 37 - 256), i.e. 0 <= x <= 85.
207 return (x * 37) >> 8;
208}
209
210static inline bool IsLeb128Terminator(const uint8_t* ptr) {
211 return *ptr <= 0x7f;

Callers 1

UpdateUnsignedLeb128Function · 0.85

Calls 1

CLZFunction · 0.85

Tested by

no test coverage detected