@@ -1283,30 +1283,24 @@ fn longest_prefix_bit(a: &U256, b: &U256) -> usize {
12831283#[ inline]
12841284fn longest_prefix < const EXACT : bool > ( a : & U256 , b : & U256 ) -> usize {
12851285 cfg_if ! {
1286- if #[ cfg( target_arch = "x86_64" ) ] {
1287- #[ cfg( feature = "std" ) ]
1288- let enabled = std:: is_x86_feature_detected!( "avx2" ) ;
1289- #[ cfg( not( feature = "std" ) ) ]
1290- let enabled = cfg!( target_feature = "avx2" ) ;
1291- if enabled {
1292- return unsafe {
1293- use core:: arch:: x86_64:: * ;
1294- let x = _mm256_loadu_si256( a. as_limbs( ) . as_ptr( ) . cast( ) ) ;
1295- let y = _mm256_loadu_si256( b. as_limbs( ) . as_ptr( ) . cast( ) ) ;
1296- let diff = _mm256_cmpeq_epi8( x, y) ;
1297- let mask = _mm256_movemask_epi8( diff) ;
1298- let bytes = mask. leading_ones( ) as usize ;
1299- if !EXACT || bytes == 32 {
1300- return bytes * 8 ;
1301- }
1302- let le_idx = 31 - bytes;
1303- let a = * a. as_le_slice( ) . get_unchecked( le_idx) ;
1304- let b = * b. as_le_slice( ) . get_unchecked( le_idx) ;
1305- let diff = a ^ b;
1306- let bits = diff. leading_zeros( ) as usize ;
1307- bytes * 8 + bits
1308- } ;
1309- }
1286+ if #[ cfg( all( target_arch = "x86_64" , target_feature = "avx2" ) ) ] {
1287+ return unsafe {
1288+ use core:: arch:: x86_64:: * ;
1289+ let x = _mm256_loadu_si256( a. as_limbs( ) . as_ptr( ) . cast( ) ) ;
1290+ let y = _mm256_loadu_si256( b. as_limbs( ) . as_ptr( ) . cast( ) ) ;
1291+ let diff = _mm256_cmpeq_epi8( x, y) ;
1292+ let mask = _mm256_movemask_epi8( diff) ;
1293+ let bytes = mask. leading_ones( ) as usize ;
1294+ if !EXACT || bytes == 32 {
1295+ return bytes * 8 ;
1296+ }
1297+ let le_idx = 31 - bytes;
1298+ let a = * a. as_le_slice( ) . get_unchecked( le_idx) ;
1299+ let b = * b. as_le_slice( ) . get_unchecked( le_idx) ;
1300+ let diff = a ^ b;
1301+ let bits = diff. leading_zeros( ) as usize ;
1302+ bytes * 8 + bits
1303+ } ;
13101304 }
13111305 }
13121306
0 commit comments