X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;ds=sidebyside;f=folly%2FGroupVarint.h;h=ae3afdb8d3f683ca737b5e648cbd4ad637563ebf;hb=d7d91eb119b9f0758cd7c9e952e9a58209ca5a67;hp=0e8f5edd74dc89544f54e3385cb1ffbd24e62b21;hpb=9be1d48f835b80fef5a4a2e66763d9cbec679277;p=folly.git diff --git a/folly/GroupVarint.h b/folly/GroupVarint.h index 0e8f5edd..ae3afdb8 100644 --- a/folly/GroupVarint.h +++ b/folly/GroupVarint.h @@ -102,7 +102,7 @@ class GroupVarint : public detail::GroupVarintBase { * buffer of size bytes. */ static size_t partialCount(const char* p, size_t size) { - char v = *p; + uint8_t v = uint8_t(*p); size_t s = kHeaderSize; s += 1 + b0key(v); if (s > size) return 0; @@ -120,8 +120,9 @@ class GroupVarint : public detail::GroupVarintBase { * return the number of bytes used by the encoding. */ static size_t encodedSize(const char* p) { - return (kHeaderSize + kGroupSize + - b0key(*p) + b1key(*p) + b2key(*p) + b3key(*p)); + return kHeaderSize + kGroupSize + + b0key(uint8_t(*p)) + b1key(uint8_t(*p)) + + b2key(uint8_t(*p)) + b3key(uint8_t(*p)); } /** @@ -194,7 +195,7 @@ class GroupVarint : public detail::GroupVarintBase { * that we must be able to read at least 17 bytes from the input pointer, p. */ static const char* decode(const char* p, uint32_t* dest) { - uint8_t key = p[0]; + uint8_t key = uint8_t(p[0]); __m128i val = _mm_loadu_si128((const __m128i*)(p+1)); __m128i mask = _mm_load_si128((const __m128i*)&detail::groupVarintSSEMasks[key * 2]); @@ -209,7 +210,7 @@ class GroupVarint : public detail::GroupVarintBase { */ static const char* decode(const char* p, uint32_t* a, uint32_t* b, uint32_t* c, uint32_t* d) { - uint8_t key = p[0]; + uint8_t key = uint8_t(p[0]); __m128i val = _mm_loadu_si128((const __m128i*)(p+1)); __m128i mask = _mm_load_si128((const __m128i*)&detail::groupVarintSSEMasks[key * 2]); @@ -217,10 +218,10 @@ class GroupVarint : public detail::GroupVarintBase { // Extracting 32 bits at a time out of an XMM register is a SSE4 feature #if FOLLY_SSE >= 4 - *a = _mm_extract_epi32(r, 0); - *b = _mm_extract_epi32(r, 1); - *c = _mm_extract_epi32(r, 2); - *d = _mm_extract_epi32(r, 3); + *a = uint32_t(_mm_extract_epi32(r, 0)); + *b = uint32_t(_mm_extract_epi32(r, 1)); + *c = uint32_t(_mm_extract_epi32(r, 2)); + *d = uint32_t(_mm_extract_epi32(r, 3)); #else /* !__SSE4__ */ *a = _mm_extract_epi16(r, 0) + (_mm_extract_epi16(r, 1) << 16); *b = _mm_extract_epi16(r, 2) + (_mm_extract_epi16(r, 3) << 16); @@ -245,7 +246,7 @@ class GroupVarint : public detail::GroupVarintBase { private: static uint8_t key(uint32_t x) { // __builtin_clz is undefined for the x==0 case - return 3 - (__builtin_clz(x|1) / 8); + return uint8_t(3 - (__builtin_clz(x | 1) / 8)); } static size_t b0key(size_t x) { return x & 3; } static size_t b1key(size_t x) { return (x >> 2) & 3; } @@ -274,8 +275,8 @@ class GroupVarint : public detail::GroupVarintBase { */ static size_t size(uint64_t a, uint64_t b, uint64_t c, uint64_t d, uint64_t e) { - return (kHeaderSize + kGroupSize + - key(a) + key(b) + key(c) + key(d) + key(e)); + return kHeaderSize + kGroupSize + + key(a) + key(b) + key(c) + key(d) + key(e); } /** @@ -327,8 +328,8 @@ class GroupVarint : public detail::GroupVarintBase { */ static size_t encodedSize(const char* p) { uint16_t n = loadUnaligned(p); - return (kHeaderSize + kGroupSize + - b0key(n) + b1key(n) + b2key(n) + b3key(n) + b4key(n)); + return kHeaderSize + kGroupSize + + b0key(n) + b1key(n) + b2key(n) + b3key(n) + b4key(n); } /** @@ -338,14 +339,19 @@ class GroupVarint : public detail::GroupVarintBase { */ static char* encode(char* p, uint64_t a, uint64_t b, uint64_t c, uint64_t d, uint64_t e) { - uint8_t b0key = key(a); - uint8_t b1key = key(b); - uint8_t b2key = key(c); - uint8_t b3key = key(d); - uint8_t b4key = key(e); + uint16_t b0key = key(a); + uint16_t b1key = key(b); + uint16_t b2key = key(c); + uint16_t b3key = key(d); + uint16_t b4key = key(e); storeUnaligned( p, - (b4key << 12) | (b3key << 9) | (b2key << 6) | (b1key << 3) | b0key); + uint16_t( + (b4key << 12) | + (b3key << 9) | + (b2key << 6) | + (b1key << 3) | + b0key)); p += 2; storeUnaligned(p, a); p += b0key+1; @@ -409,14 +415,14 @@ class GroupVarint : public detail::GroupVarintBase { static uint8_t key(uint64_t x) { // __builtin_clzll is undefined for the x==0 case - return 7 - (__builtin_clzll(x|1) / 8); + return uint8_t(7 - (__builtin_clzll(x | 1) / 8)); } - static uint8_t b0key(uint16_t x) { return x & 7; } - static uint8_t b1key(uint16_t x) { return (x >> 3) & 7; } - static uint8_t b2key(uint16_t x) { return (x >> 6) & 7; } - static uint8_t b3key(uint16_t x) { return (x >> 9) & 7; } - static uint8_t b4key(uint16_t x) { return (x >> 12) & 7; } + static uint8_t b0key(uint16_t x) { return x & 7u; } + static uint8_t b1key(uint16_t x) { return (x >> 3) & 7u; } + static uint8_t b2key(uint16_t x) { return (x >> 6) & 7u; } + static uint8_t b3key(uint16_t x) { return (x >> 9) & 7u; } + static uint8_t b4key(uint16_t x) { return (x >> 12) & 7u; } static const uint64_t kMask[]; };