@@ -159,11 +159,14 @@ unsafe fn scan_chunks_avx512_vpopcnt(
159159 use std:: arch:: x86_64:: _mm512_popcnt_epi64;
160160 use std:: arch:: x86_64:: _mm512_reduce_add_epi64;
161161
162+ use vortex_error:: VortexExpect ;
163+
162164 for ( idx, chunk) in chunks. iter ( ) . enumerate ( ) {
163165 // SAFETY: chunk is exactly 64 bytes. `_mm512_loadu_si512` supports unaligned access.
164166 let block = unsafe { _mm512_loadu_si512 ( chunk. as_ptr ( ) . cast ( ) ) } ;
165167 let counts = _mm512_popcnt_epi64 ( block) ;
166- let total = _mm512_reduce_add_epi64 ( counts) as usize ;
168+ let total =
169+ usize:: try_from ( _mm512_reduce_add_epi64 ( counts) ) . vortex_expect ( "must fit in usize" ) ;
167170
168171 if remaining < total {
169172 return ( remaining, pos, idx) ;
@@ -295,6 +298,8 @@ unsafe fn select_in_chunk_vbmi2(chunk: &[u8; 64], mut nth: usize) -> usize {
295298 use std:: arch:: x86_64:: _mm512_popcnt_epi64;
296299 use std:: arch:: x86_64:: _mm512_storeu_epi64;
297300
301+ use vortex_error:: VortexExpect ;
302+
298303 let words = chunk. as_chunks :: < 8 > ( ) . 0 ;
299304
300305 // SAFETY: chunk is exactly 64 bytes. `_mm512_loadu_si512` supports unaligned access.
@@ -306,7 +311,7 @@ unsafe fn select_in_chunk_vbmi2(chunk: &[u8; 64], mut nth: usize) -> usize {
306311 unsafe { _mm512_storeu_epi64 ( lane_counts. as_mut_ptr ( ) , counts) } ;
307312
308313 for ( idx, count) in lane_counts. into_iter ( ) . enumerate ( ) {
309- let count = count as usize ;
314+ let count = usize :: try_from ( count) . vortex_expect ( "must fit in usize" ) ;
310315 if nth < count {
311316 return idx * 64 + select_in_word ( u64:: from_le_bytes ( words[ idx] ) , nth) ;
312317 }
0 commit comments