1 // Copyright 2016 Brian Smith.
2 //
3 // Permission to use, copy, modify, and/or distribute this software for any
4 // purpose with or without fee is hereby granted, provided that the above
5 // copyright notice and this permission notice appear in all copies.
6 //
7 // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
8 // WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9 // MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
10 // SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11 // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12 // OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
13 // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14
15 /// A witness indicating that CPU features have been detected and cached.
16 ///
17 /// TODO: Eventually all feature detection logic should be done through
18 /// functions that accept a `Features` parameter, to guarantee that nothing
19 /// tries to read the cached values before they are written.
20 ///
21 /// This is a zero-sized type so that it can be "stored" wherever convenient.
22 #[derive(Copy, Clone)]
23 pub(crate) struct Features(());
24
25 #[inline(always)]
features() -> Features26 pub(crate) fn features() -> Features {
27 // We don't do runtime feature detection on aarch64-apple-* as all AAarch64
28 // features we use are available on every device since the first devices.
29 #[cfg(any(
30 target_arch = "x86",
31 target_arch = "x86_64",
32 all(
33 any(target_arch = "aarch64", target_arch = "arm"),
34 any(
35 target_os = "android",
36 target_os = "fuchsia",
37 target_os = "linux",
38 target_os = "windows"
39 )
40 )
41 ))]
42 {
43 static INIT: spin::Once<()> = spin::Once::new();
44 let () = INIT.call_once(|| {
45 #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
46 {
47 prefixed_extern! {
48 fn OPENSSL_cpuid_setup();
49 }
50 unsafe {
51 OPENSSL_cpuid_setup();
52 }
53 }
54
55 #[cfg(all(
56 any(target_arch = "aarch64", target_arch = "arm"),
57 any(
58 target_os = "android",
59 target_os = "fuchsia",
60 target_os = "linux",
61 target_os = "windows"
62 )
63 ))]
64 {
65 unsafe { arm::initialize_OPENSSL_armcap_P() }
66 }
67 });
68 }
69
70 Features(())
71 }
72
73 pub mod arm;
74 pub mod intel;
75