Skip to content

Commit

Permalink
Fix previous commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
zufuliu committed Nov 24, 2024
1 parent 633c1aa commit 21e16e6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
10 changes: 6 additions & 4 deletions scintilla/src/Document.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2971,19 +2971,20 @@ Sci::Position Document::BraceMatch(Sci::Position position, Sci::Position /*maxRe
const Sci::Position segmentLength = scanFirst ? cbView.length1 : length;
const char * const segment = scanFirst ? cbView.segment1 : cbView.segment2;
const __m256i *ptr = reinterpret_cast<const __m256i *>(segment + position);
Sci::Position index = position;
uint32_t mask = 0;
do {
const __m256i chunk1 = _mm256_loadu_si256(ptr);
mask = mm256_movemask_epi8(_mm256_or_si256(_mm256_cmpeq_epi8(chunk1, mmBrace), _mm256_cmpeq_epi8(chunk1, mmSeek)));
if (mask != 0) {
index = position;
break;
}
ptr++;
position += sizeof(mmBrace);
} while (position < segmentLength);
Sci::Position index = position;
position += sizeof(mmBrace);
if (position >= segmentLength && index <= segmentLength) {
if (position >= segmentLength && index < segmentLength) {
position = segmentLength;
const uint32_t offset = static_cast<uint32_t>(position - index);
mask = bit_zero_high_u32(mask, offset);
Expand Down Expand Up @@ -3015,19 +3016,20 @@ Sci::Position Document::BraceMatch(Sci::Position position, Sci::Position /*maxRe
const Sci::Position segmentLength = scanFirst ? cbView.length1 : length;
const char * const segment = scanFirst ? cbView.segment1 : cbView.segment2;
const __m128i *ptr = reinterpret_cast<const __m128i *>(segment + position);
Sci::Position index = position;
uint32_t mask = 0;
do {
const __m128i chunk1 = _mm_loadu_si128(ptr);
mask = mm_movemask_epi8(_mm_or_si128(_mm_cmpeq_epi8(chunk1, mmBrace), _mm_cmpeq_epi8(chunk1, mmSeek)));
if (mask != 0) {
index = position;
break;
}
ptr++;
position += sizeof(mmBrace);
} while (position < segmentLength);
Sci::Position index = position;
position += sizeof(mmBrace);
if (position >= segmentLength && index <= segmentLength) {
if (position >= segmentLength && index < segmentLength) {
position = segmentLength;
const uint32_t offset = static_cast<uint32_t>(position - index);
mask = bit_zero_high_u32(mask, offset);
Expand Down
10 changes: 6 additions & 4 deletions scintilla/test/BraceMatchTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,20 @@ void FindAllBraceForward(const SplitView &cbView, ptrdiff_t position, const ptrd
const ptrdiff_t segmentLength = scanFirst ? cbView.length1 : length;
const char * const segment = scanFirst ? cbView.segment1 : cbView.segment2;
const __m256i *ptr = reinterpret_cast<const __m256i *>(segment + position);
ptrdiff_t index = position;
uint32_t mask = 0;
do {
const __m256i chunk1 = _mm256_loadu_si256(ptr);
mask = _mm256_movemask_epi8(_mm256_or_si256(_mm256_cmpeq_epi8(chunk1, mmBrace), _mm256_cmpeq_epi8(chunk1, mmSeek)));
if (mask != 0) {
index = position;
break;
}
ptr++;
position += sizeof(__m256i);
} while (position < segmentLength);
ptrdiff_t index = position;
position += sizeof(__m256i);
if (position >= segmentLength && index <= segmentLength) {
if (position >= segmentLength && index < segmentLength) {
position = segmentLength;
const uint32_t offset = static_cast<uint32_t>(position - index);
mask = bit_zero_high_u32(mask, offset);
Expand All @@ -78,19 +79,20 @@ void FindAllBraceForward(const SplitView &cbView, ptrdiff_t position, const ptrd
const ptrdiff_t segmentLength = scanFirst ? cbView.length1 : length;
const char * const segment = scanFirst ? cbView.segment1 : cbView.segment2;
const __m128i *ptr = reinterpret_cast<const __m128i *>(segment + position);
ptrdiff_t index = position;
uint32_t mask = 0;
do {
const __m128i chunk1 = _mm_loadu_si128(ptr);
mask = _mm_movemask_epi8(_mm_or_si128(_mm_cmpeq_epi8(chunk1, mmBrace), _mm_cmpeq_epi8(chunk1, mmSeek)));
if (mask != 0) {
index = position;
break;
}
ptr++;
position += sizeof(__m128i);
} while (position < segmentLength);
ptrdiff_t index = position;
position += sizeof(__m128i);
if (position >= segmentLength && index <= segmentLength) {
if (position >= segmentLength && index < segmentLength) {
position = segmentLength;
const uint32_t offset = static_cast<uint32_t>(position - index);
mask = bit_zero_high_u32(mask, offset);
Expand Down

0 comments on commit 21e16e6

Please sign in to comment.