Skip to content

Commit 3c7c38a

Browse files
committed
Simplify SSE2 implementation
1 parent 613bdd4 commit 3c7c38a

File tree

1 file changed

+6
-18
lines changed

1 file changed

+6
-18
lines changed

compiler/rustc_span/src/analyze_source_file.rs

+6-18
Original file line numberDiff line numberDiff line change
@@ -110,25 +110,19 @@ cfg_match! {
110110
if control_char_mask != 0 {
111111
// Check for newlines in the chunk
112112
let newlines_test = unsafe { _mm_cmpeq_epi8(chunk, _mm_set1_epi8(b'\n' as i8)) };
113-
let newlines_mask = unsafe { _mm_movemask_epi8(newlines_test) };
113+
let mut newlines_mask = unsafe { _mm_movemask_epi8(newlines_test) };
114114

115115
if control_char_mask == newlines_mask {
116116
// All control characters are newlines, record them
117-
let mut newlines_mask = 0xFFFF0000 | newlines_mask as u32;
118117
let output_offset = RelativeBytePos::from_usize(chunk_index * CHUNK_SIZE + 1);
119118

120-
loop {
119+
while newlines_mask != 0 {
121120
let index = newlines_mask.trailing_zeros();
122121

123-
if index >= CHUNK_SIZE as u32 {
124-
// We have arrived at the end of the chunk.
125-
break;
126-
}
127-
128122
lines.push(RelativeBytePos(index) + output_offset);
129123

130124
// Clear the bit, so we can find the next one.
131-
newlines_mask &= (!1) << index;
125+
newlines_mask &= newlines_mask - 1;
132126
}
133127

134128
// We are done for this chunk. All control characters were
@@ -268,25 +262,19 @@ cfg_match! {
268262
if control_char_mask != 0 {
269263
// Check for newlines in the chunk
270264
let newlines_test = unsafe { _mm_cmpeq_epi8(chunk, _mm_set1_epi8(b'\n' as i8)) };
271-
let newlines_mask = unsafe { _mm_movemask_epi8(newlines_test) };
265+
let mut newlines_mask = unsafe { _mm_movemask_epi8(newlines_test) };
272266

273267
if control_char_mask == newlines_mask {
274268
// All control characters are newlines, record them
275-
let mut newlines_mask = 0xFFFF0000 | newlines_mask as u32;
276269
let output_offset = RelativeBytePos::from_usize(chunk_index * CHUNK_SIZE + 1);
277270

278-
loop {
271+
while newlines_mask != 0 {
279272
let index = newlines_mask.trailing_zeros();
280273

281-
if index >= CHUNK_SIZE as u32 {
282-
// We have arrived at the end of the chunk.
283-
break;
284-
}
285-
286274
lines.push(RelativeBytePos(index) + output_offset);
287275

288276
// Clear the bit, so we can find the next one.
289-
newlines_mask &= (!1) << index;
277+
newlines_mask &= newlines_mask - 1;
290278
}
291279

292280
// We are done for this chunk. All control characters were

0 commit comments

Comments
 (0)