@@ -185,9 +185,9 @@ cfg_if! {
185185 type Tokens = ( ) ;
186186 } else if #[ cfg( any( target_arch = "x86" , target_arch = "x86_64" ) ) ] {
187187 cfg_if! {
188- if #[ cfg( chacha20_force_avx512) ] {
188+ if #[ cfg( all ( chacha20_avx512 , chacha20_force_avx512) ) ] {
189189 #[ cfg( not( all( target_feature = "avx512f" , target_feature = "avx512vl" ) ) ) ]
190- compile_error!( "You must enable `avx512f` target feature with \
190+ compile_error!( "You must enable `avx512f` and `avx512vl` target features with \
191191 `chacha20_force_avx512` configuration option") ;
192192 type Tokens = ( ) ;
193193 } else if #[ cfg( chacha20_force_avx2) ] {
@@ -201,10 +201,14 @@ cfg_if! {
201201 `chacha20_force_sse2` configuration option") ;
202202 type Tokens = ( ) ;
203203 } else {
204+ #[ cfg( chacha20_avx512) ]
204205 cpufeatures:: new!( avx512_cpuid, "avx512f" , "avx512vl" ) ;
205206 cpufeatures:: new!( avx2_cpuid, "avx2" ) ;
206207 cpufeatures:: new!( sse2_cpuid, "sse2" ) ;
208+ #[ cfg( chacha20_avx512) ]
207209 type Tokens = ( avx512_cpuid:: InitToken , avx2_cpuid:: InitToken , sse2_cpuid:: InitToken ) ;
210+ #[ cfg( not( chacha20_avx512) ) ]
211+ type Tokens = ( avx2_cpuid:: InitToken , sse2_cpuid:: InitToken ) ;
208212 }
209213 }
210214 } else {
@@ -259,8 +263,10 @@ impl<R: Rounds, V: Variant> ChaChaCore<R, V> {
259263 let tokens = ( ) ;
260264 } else if #[ cfg( chacha20_force_sse2) ] {
261265 let tokens = ( ) ;
262- } else {
266+ } else if # [ cfg ( chacha20_avx512 ) ] {
263267 let tokens = ( avx512_cpuid:: init( ) , avx2_cpuid:: init( ) , sse2_cpuid:: init( ) ) ;
268+ } else {
269+ let tokens = ( avx2_cpuid:: init( ) , sse2_cpuid:: init( ) ) ;
264270 }
265271 }
266272 } else {
@@ -306,7 +312,7 @@ impl<R: Rounds, V: Variant> StreamCipherCore for ChaChaCore<R, V> {
306312 f. call( & mut backends:: soft:: Backend ( self ) ) ;
307313 } else if #[ cfg( any( target_arch = "x86" , target_arch = "x86_64" ) ) ] {
308314 cfg_if! {
309- if #[ cfg( chacha20_force_avx512) ] {
315+ if #[ cfg( all ( chacha20_avx512 , chacha20_force_avx512) ) ] {
310316 unsafe {
311317 backends:: avx512:: inner:: <R , _, V >( & mut self . state, f) ;
312318 }
@@ -319,12 +325,19 @@ impl<R: Rounds, V: Variant> StreamCipherCore for ChaChaCore<R, V> {
319325 backends:: sse2:: inner:: <R , _, V >( & mut self . state, f) ;
320326 }
321327 } else {
328+ #[ cfg( chacha20_avx512) ]
322329 let ( avx512_token, avx2_token, sse2_token) = self . tokens;
330+ #[ cfg( not( chacha20_avx512) ) ]
331+ let ( avx2_token, sse2_token) = self . tokens;
332+
333+ #[ cfg( chacha20_avx512) ]
323334 if avx512_token. get( ) {
324335 unsafe {
325336 backends:: avx512:: inner:: <R , _, V >( & mut self . state, f) ;
326337 }
327- } else if avx2_token. get( ) {
338+ return ;
339+ }
340+ if avx2_token. get( ) {
328341 unsafe {
329342 backends:: avx2:: inner:: <R , _, V >( & mut self . state, f) ;
330343 }
0 commit comments