X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=folly%2FGroupVarint.h;h=ff1c33c385da09eb4d5b61c9f617899a4cb4ea30;hb=7d8fbeb8b9a69cee2a2f26c977ffb3f2b7b6fa92;hp=0ffae3a648d032941d5eae159bfbd0642684654b;hpb=ec4962764d97595a2c468f4342ab8c867517f6f4;p=folly.git diff --git a/folly/GroupVarint.h b/folly/GroupVarint.h index 0ffae3a6..ff1c33c3 100644 --- a/folly/GroupVarint.h +++ b/folly/GroupVarint.h @@ -1,5 +1,5 @@ /* - * Copyright 2012 Facebook, Inc. + * Copyright 2014 Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,15 +21,16 @@ #error GroupVarint.h requires GCC #endif -#if !defined(__x86_64__) && !defined(__i386__) -#error GroupVarint.h requires x86_64 or i386 -#endif +#include + +#if FOLLY_X64 || defined(__i386__) +#define HAVE_GROUP_VARINT 1 #include #include -#include "folly/detail/GroupVarintDetail.h" -#include "folly/Bits.h" -#include "folly/Range.h" +#include +#include +#include #include #ifdef __SSSE3__ @@ -175,7 +176,7 @@ class GroupVarint : public detail::GroupVarintBase { p += k2+1; size_t k3 = b3key(k); *d = loadUnaligned(p) & kMask[k3]; - p += k3+1; + // p += k3+1; return end; } @@ -188,6 +189,10 @@ class GroupVarint : public detail::GroupVarintBase { } #ifdef __SSSE3__ + /** + * Just like the non-SSSE3 decode below, but with the additional constraint + * 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]; __m128i val = _mm_loadu_si128((const __m128i*)(p+1)); @@ -197,6 +202,10 @@ class GroupVarint : public detail::GroupVarintBase { return p + detail::groupVarintLengths[key]; } + /** + * Just like decode_simple, but with the additional constraint 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* a, uint32_t* b, uint32_t* c, uint32_t* d) { uint8_t key = p[0]; @@ -510,15 +519,17 @@ class GroupVarintDecoder { : rrest_(data.end()), p_(data.data()), end_(data.end()), + limit_(end_), pos_(0), count_(0), remaining_(maxCount) { } - void reset(StringPiece data, size_t maxCount=(size_t)-1) { + void reset(StringPiece data, size_t maxCount = (size_t)-1) { rrest_ = data.end(); p_ = data.data(); end_ = data.end(); + limit_ = end_; pos_ = 0; count_ = 0; remaining_ = maxCount; @@ -541,10 +552,11 @@ class GroupVarintDecoder { // The best way to ensure this is to ensure that data has at least // Base::kMaxSize - 1 bytes readable *after* the end, otherwise we'll copy // into a temporary buffer. - if (rem < Base::kMaxSize) { + if (limit_ - p_ < Base::kMaxSize) { memcpy(tmp_, p_, rem); p_ = tmp_; end_ = p_ + rem; + limit_ = tmp_ + sizeof(tmp_); } pos_ = 0; const char* n = Base::decode(p_, buf_); @@ -592,7 +604,8 @@ class GroupVarintDecoder { const char* rrest_; const char* p_; const char* end_; - char tmp_[Base::kMaxSize]; + const char* limit_; + char tmp_[2 * Base::kMaxSize]; type buf_[Base::kGroupSize]; size_t pos_; size_t count_; @@ -604,5 +617,5 @@ typedef GroupVarintDecoder GroupVarint64Decoder; } // namespace folly +#endif /* FOLLY_X64 || defined(__i386__) */ #endif /* FOLLY_GROUPVARINT_H_ */ -