From 2d6bb94895ca544a2ec02bcecb21abe40451f21d Mon Sep 17 00:00:00 2001 From: Orson Peters Date: Mon, 7 Oct 2024 20:06:20 +0200 Subject: [PATCH] refactor(rust): Minor CSV bit twiddle nitpick (#19121) --- crates/polars-io/src/csv/read/splitfields.rs | 16 ++++++++-------- crates/polars-utils/src/clmul.rs | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/crates/polars-io/src/csv/read/splitfields.rs b/crates/polars-io/src/csv/read/splitfields.rs index 68714c4fddd7..ac06b185a37a 100644 --- a/crates/polars-io/src/csv/read/splitfields.rs +++ b/crates/polars-io/src/csv/read/splitfields.rs @@ -265,10 +265,10 @@ mod inner { .unwrap_unchecked_release() }; let simd_bytes = SimdVec::from(lane); - let eol_mask = simd_bytes.simd_eq(self.simd_eol_char).to_bitmask(); - let sep_mask = simd_bytes.simd_eq(self.simd_separator).to_bitmask(); + let has_eol = simd_bytes.simd_eq(self.simd_eol_char); + let has_sep = simd_bytes.simd_eq(self.simd_separator); let quote_mask = simd_bytes.simd_eq(self.simd_quote_char).to_bitmask(); - let mut end_mask = sep_mask | eol_mask; + let mut end_mask = (has_sep | has_eol).to_bitmask(); let mut not_in_quote_field = prefix_xorsum_inclusive(quote_mask); @@ -360,12 +360,12 @@ mod inner { .unwrap_unchecked_release() }; let simd_bytes = SimdVec::from(lane); - let has_eol_char = simd_bytes.simd_eq(self.simd_eol_char).to_bitmask(); - let has_separator = simd_bytes.simd_eq(self.simd_separator).to_bitmask(); - let has_any = has_separator | has_eol_char; + let has_eol_char = simd_bytes.simd_eq(self.simd_eol_char); + let has_separator = simd_bytes.simd_eq(self.simd_separator); + let has_any_mask = (has_separator | has_eol_char).to_bitmask(); - if has_any != 0 { - total_idx += has_any.trailing_zeros() as usize; + if has_any_mask != 0 { + total_idx += has_any_mask.trailing_zeros() as usize; break; } else { total_idx += SIMD_SIZE; diff --git a/crates/polars-utils/src/clmul.rs b/crates/polars-utils/src/clmul.rs index c3467e6152e4..ac6fc541c400 100644 --- a/crates/polars-utils/src/clmul.rs +++ b/crates/polars-utils/src/clmul.rs @@ -57,7 +57,7 @@ pub fn portable_prefix_xorsum(x: u64) -> u64 { portable_prefix_xorsum_inclusive(x << 1) } -// Computes for each bit i the XOR of all less significant bits. +// Computes for each bit i the XOR of bits[0..i]. #[inline] pub fn prefix_xorsum(x: u64) -> u64 { #[cfg(all(target_arch = "x86_64", target_feature = "pclmulqdq"))] @@ -82,7 +82,7 @@ pub fn portable_prefix_xorsum_inclusive(mut x: u64) -> u64 { x } -// Computes for each bit i the XOR of all less significant bits. +// Computes for each bit i the XOR of bits[0..=i]. #[inline] pub fn prefix_xorsum_inclusive(x: u64) -> u64 { #[cfg(all(target_arch = "x86_64", target_feature = "pclmulqdq"))]