/rust/registry/src/index.crates.io-1949cf8c6b5b557f/httparse-1.10.1/src/simd/runtime.rs
Line  | Count  | Source  | 
1  |  | use std::sync::atomic::{AtomicU8, Ordering}; | 
2  |  | use crate::iter::Bytes;  | 
3  |  | use super::avx2;  | 
4  |  | use super::sse42;  | 
5  |  |  | 
6  |  | const AVX2: u8 = 1;  | 
7  |  | const SSE42: u8 = 2;  | 
8  |  | const NOP: u8 = 3;  | 
9  |  |  | 
10  | 0  | fn detect_runtime_feature() -> u8 { | 
11  | 0  |     if is_x86_feature_detected!("avx2") { | 
12  | 0  |         AVX2  | 
13  | 0  |     } else if is_x86_feature_detected!("sse4.2") { | 
14  | 0  |         SSE42  | 
15  |  |     } else { | 
16  | 0  |         NOP  | 
17  |  |     }  | 
18  | 0  | }  | 
19  |  |  | 
20  |  | static RUNTIME_FEATURE: AtomicU8 = AtomicU8::new(0);  | 
21  |  |  | 
22  |  | #[inline]  | 
23  | 0  | fn get_runtime_feature() -> u8 { | 
24  | 0  |     let mut feature = RUNTIME_FEATURE.load(Ordering::Relaxed);  | 
25  | 0  |     if feature == 0 { | 
26  | 0  |         feature = detect_runtime_feature();  | 
27  | 0  |         RUNTIME_FEATURE.store(feature, Ordering::Relaxed);  | 
28  | 0  |     }  | 
29  |  |  | 
30  | 0  |     feature  | 
31  | 0  | }  | 
32  |  |  | 
33  | 0  | pub fn match_header_name_vectored(bytes: &mut Bytes) { | 
34  | 0  |     super::swar::match_header_name_vectored(bytes);  | 
35  | 0  | }  | 
36  |  |  | 
37  | 0  | pub fn match_uri_vectored(bytes: &mut Bytes) { | 
38  |  |     // SAFETY: calls are guarded by a feature check  | 
39  |  |     unsafe { | 
40  | 0  |         match get_runtime_feature() { | 
41  | 0  |             AVX2 => avx2::match_uri_vectored(bytes),  | 
42  | 0  |             SSE42 => sse42::match_uri_vectored(bytes),  | 
43  | 0  |             _ /* NOP */ => super::swar::match_uri_vectored(bytes),  | 
44  |  |         }  | 
45  |  |     }  | 
46  | 0  | }  | 
47  |  |  | 
48  | 0  | pub fn match_header_value_vectored(bytes: &mut Bytes) { | 
49  |  |     // SAFETY: calls are guarded by a feature check  | 
50  |  |     unsafe { | 
51  | 0  |         match get_runtime_feature() { | 
52  | 0  |             AVX2 => avx2::match_header_value_vectored(bytes),  | 
53  | 0  |             SSE42 => sse42::match_header_value_vectored(bytes),  | 
54  | 0  |             _ /* NOP */ => super::swar::match_header_value_vectored(bytes),  | 
55  |  |         }  | 
56  |  |     }  | 
57  | 0  | }  |