Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions lib/compress/zstd_compress_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -855,11 +855,30 @@ MEM_STATIC size_t ZSTD_count(const BYTE* pIn, const BYTE* pMatch, const BYTE* co
{
const BYTE* const pStart = pIn;
const BYTE* const pInLoopLimit = pInLimit - (sizeof(size_t)-1);
#if defined(ZSTD_ARCH_X86_SSE2)
const BYTE* const pInLimit16 = pInLimit - (sizeof(__m128i)-1);
#endif

if (pIn < pInLoopLimit) {
{ size_t const diff = MEM_readST(pMatch) ^ MEM_readST(pIn);
if (diff) return ZSTD_NbCommonBytes(diff); }
pIn+=sizeof(size_t); pMatch+=sizeof(size_t);
#if defined(ZSTD_ARCH_X86_SSE2)
if ((size_t)(pInLimit - pIn) >= 32) {
while (pIn < pInLimit16) {
__m128i const matchVec = _mm_loadu_si128((const __m128i*)(const void*)pMatch);
__m128i const inVec = _mm_loadu_si128((const __m128i*)(const void*)pIn);
U32 const matchMask = (U32)_mm_movemask_epi8(_mm_cmpeq_epi8(matchVec, inVec));
if (matchMask != 0xFFFF) {
U32 const diffMask = ~matchMask & 0xFFFF;
pIn += ZSTD_countTrailingZeros32(diffMask);
return (size_t)(pIn - pStart);
}
pIn += sizeof(__m128i);
pMatch += sizeof(__m128i);
}
}
#endif
while (pIn < pInLoopLimit) {
size_t const diff = MEM_readST(pMatch) ^ MEM_readST(pIn);
if (!diff) { pIn+=sizeof(size_t); pMatch+=sizeof(size_t); continue; }
Expand Down