@@ -75,14 +75,15 @@ fn is_made_of_eight_digits_fast(chars: [u8; 8]) -> bool {
7575#[ cfg_attr( not( feature = "no-inline" ) , inline) ]
7676#[ cfg( all(
7777 any( target_arch = "x86" , target_arch = "x86_64" ) ,
78- feature = "swar-number-parsing"
78+ feature = "swar-number-parsing" ,
7979) ) ]
80+ #[ target_feature( enable = "ssse3" ) ]
8081#[ allow(
8182 clippy:: cast_sign_loss,
8283 clippy:: cast_possible_wrap,
8384 clippy:: cast_ptr_alignment
8485) ]
85- fn parse_eight_digits_unrolled ( chars : & [ u8 ] ) -> u32 {
86+ unsafe fn parse_eight_digits_ssse3 ( chars : & [ u8 ] ) -> u32 {
8687 unsafe {
8788 // this actually computes *16* values so we are being wasteful.
8889 let ascii0: __m128i = _mm_set1_epi8 ( b'0' as i8 ) ;
@@ -109,15 +110,24 @@ fn parse_eight_digits_unrolled(chars: &[u8]) -> u32 {
109110}
110111
111112#[ cfg_attr( not( feature = "no-inline" ) , inline) ]
112- #[ cfg( all(
113- not( any( target_arch = "x86" , target_arch = "x86_64" ) ) ,
114- feature = "swar-number-parsing"
115- ) ) ]
113+ #[ cfg( feature = "swar-number-parsing" ) ]
116114#[ allow( clippy:: cast_ptr_alignment) ]
117- fn parse_eight_digits_unrolled ( chars : & [ u8 ] ) -> u32 {
115+ fn parse_eight_digits_swar ( chars : & [ u8 ] ) -> u32 {
118116 let val = unsafe { chars. as_ptr ( ) . cast :: < u64 > ( ) . read_unaligned ( ) } ; // memcpy(&val, chars, sizeof(u64));
119117 let val = ( val & 0x0F0F_0F0F_0F0F_0F0F ) . wrapping_mul ( 2561 ) >> 8 ;
120118 let val = ( val & 0x00FF_00FF_00FF_00FF ) . wrapping_mul ( 6_553_601 ) >> 16 ;
121119
122120 ( ( val & 0x0000_FFFF_0000_FFFF ) . wrapping_mul ( 42_949_672_960_001 ) >> 32 ) as u32
123121}
122+
123+ #[ cfg( feature = "swar-number-parsing" ) ]
124+ #[ cfg_attr( not( feature = "no-inline" ) , inline) ]
125+ fn parse_eight_digits_unrolled ( chars : & [ u8 ] ) -> u32 {
126+ #[ cfg( any( target_arch = "x86" , target_arch = "x86_64" ) ) ]
127+ {
128+ if std:: is_x86_feature_detected!( "ssse3" ) {
129+ return unsafe { parse_eight_digits_ssse3 ( chars) } ;
130+ }
131+ }
132+ parse_eight_digits_swar ( chars)
133+ }
0 commit comments