about summary refs log tree commit diff
diff options
context:
space:
mode:
authorreal-eren <erenalpkahriman@gmail.com>2025-02-02 17:59:43 -0500
committerreal-eren <erenalpkahriman@gmail.com>2025-02-02 21:51:56 -0500
commit3c7c38ad9335b043315addc1fcabf3631bbe1125 (patch)
tree38a708d7983ae91086c75080239fb2514971ba37
parent613bdd49978298648ed05ace086bd1ecad54b44a (diff)
downloadrust-3c7c38ad9335b043315addc1fcabf3631bbe1125.tar.gz
rust-3c7c38ad9335b043315addc1fcabf3631bbe1125.zip
Simplify SSE2 implementation
-rw-r--r--compiler/rustc_span/src/analyze_source_file.rs24
1 files changed, 6 insertions, 18 deletions
diff --git a/compiler/rustc_span/src/analyze_source_file.rs b/compiler/rustc_span/src/analyze_source_file.rs
index fba20566580..87c8e3fce07 100644
--- a/compiler/rustc_span/src/analyze_source_file.rs
+++ b/compiler/rustc_span/src/analyze_source_file.rs
@@ -110,25 +110,19 @@ cfg_match! {
                     if control_char_mask != 0 {
                         // Check for newlines in the chunk
                         let newlines_test = unsafe { _mm_cmpeq_epi8(chunk, _mm_set1_epi8(b'\n' as i8)) };
-                        let newlines_mask = unsafe { _mm_movemask_epi8(newlines_test) };
+                        let mut newlines_mask = unsafe { _mm_movemask_epi8(newlines_test) };
 
                         if control_char_mask == newlines_mask {
                             // All control characters are newlines, record them
-                            let mut newlines_mask = 0xFFFF0000 | newlines_mask as u32;
                             let output_offset = RelativeBytePos::from_usize(chunk_index * CHUNK_SIZE + 1);
 
-                            loop {
+                            while newlines_mask != 0 {
                                 let index = newlines_mask.trailing_zeros();
 
-                                if index >= CHUNK_SIZE as u32 {
-                                    // We have arrived at the end of the chunk.
-                                    break;
-                                }
-
                                 lines.push(RelativeBytePos(index) + output_offset);
 
                                 // Clear the bit, so we can find the next one.
-                                newlines_mask &= (!1) << index;
+                                newlines_mask &= newlines_mask - 1;
                             }
 
                             // We are done for this chunk. All control characters were
@@ -268,25 +262,19 @@ cfg_match! {
                     if control_char_mask != 0 {
                         // Check for newlines in the chunk
                         let newlines_test = unsafe { _mm_cmpeq_epi8(chunk, _mm_set1_epi8(b'\n' as i8)) };
-                        let newlines_mask = unsafe { _mm_movemask_epi8(newlines_test) };
+                        let mut newlines_mask = unsafe { _mm_movemask_epi8(newlines_test) };
 
                         if control_char_mask == newlines_mask {
                             // All control characters are newlines, record them
-                            let mut newlines_mask = 0xFFFF0000 | newlines_mask as u32;
                             let output_offset = RelativeBytePos::from_usize(chunk_index * CHUNK_SIZE + 1);
 
-                            loop {
+                            while newlines_mask != 0 {
                                 let index = newlines_mask.trailing_zeros();
 
-                                if index >= CHUNK_SIZE as u32 {
-                                    // We have arrived at the end of the chunk.
-                                    break;
-                                }
-
                                 lines.push(RelativeBytePos(index) + output_offset);
 
                                 // Clear the bit, so we can find the next one.
-                                newlines_mask &= (!1) << index;
+                                newlines_mask &= newlines_mask - 1;
                             }
 
                             // We are done for this chunk. All control characters were