summaryrefslogtreecommitdiffstats
path: root/vendor/cpufeatures/src/x86.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:18:25 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:18:25 +0000
commit5363f350887b1e5b5dd21a86f88c8af9d7fea6da (patch)
tree35ca005eb6e0e9a1ba3bb5dbc033209ad445dc17 /vendor/cpufeatures/src/x86.rs
parentAdding debian version 1.66.0+dfsg1-1. (diff)
downloadrustc-5363f350887b1e5b5dd21a86f88c8af9d7fea6da.tar.xz
rustc-5363f350887b1e5b5dd21a86f88c8af9d7fea6da.zip
Merging upstream version 1.67.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/cpufeatures/src/x86.rs')
-rw-r--r--vendor/cpufeatures/src/x86.rs38
1 files changed, 31 insertions, 7 deletions
diff --git a/vendor/cpufeatures/src/x86.rs b/vendor/cpufeatures/src/x86.rs
index 37e20ef6a..c973b7446 100644
--- a/vendor/cpufeatures/src/x86.rs
+++ b/vendor/cpufeatures/src/x86.rs
@@ -33,12 +33,27 @@ macro_rules! __unless_target_features {
macro_rules! __detect_target_features {
($($tf:tt),+) => {{
#[cfg(target_arch = "x86")]
- use core::arch::x86::{__cpuid, __cpuid_count};
+ use core::arch::x86::{__cpuid, __cpuid_count, CpuidResult};
#[cfg(target_arch = "x86_64")]
- use core::arch::x86_64::{__cpuid, __cpuid_count};
+ use core::arch::x86_64::{__cpuid, __cpuid_count, CpuidResult};
+
+ // These wrappers are workarounds around
+ // https://github.com/rust-lang/rust/issues/101346
+ //
+ // DO NOT remove it until MSRV is bumped to a version
+ // with the issue fix (at least 1.64).
+ #[inline(never)]
+ unsafe fn cpuid(leaf: u32) -> CpuidResult {
+ __cpuid(leaf)
+ }
+
+ #[inline(never)]
+ unsafe fn cpuid_count(leaf: u32, sub_leaf: u32) -> CpuidResult {
+ __cpuid_count(leaf, sub_leaf)
+ }
let cr = unsafe {
- [__cpuid(1), __cpuid_count(7, 0)]
+ [cpuid(1), cpuid_count(7, 0)]
};
$($crate::check!(cr, $tf) & )+ true
@@ -46,17 +61,26 @@ macro_rules! __detect_target_features {
}
macro_rules! __expand_check_macro {
- ($(($name:tt, $i:expr, $reg:ident, $offset:expr)),* $(,)?) => {
+ ($(($name:tt $(, $i:expr, $reg:ident, $offset:expr)*)),* $(,)?) => {
#[macro_export]
#[doc(hidden)]
macro_rules! check {
$(
- ($cr:expr, $name) => { ($cr[$i].$reg & (1 << $offset) != 0) };
+ ($cr:expr, $name) => {
+ true
+ $(
+ & ($cr[$i].$reg & (1 << $offset) != 0)
+ )*
+ };
)*
}
};
}
+// Note that according to the [Intel manual][0] AVX2 and FMA require
+// that we check availability of AVX before using them.
+//
+// [0]: https://www.intel.com/content/dam/develop/external/us/en/documents/36945
__expand_check_macro! {
("mmx", 0, edx, 23),
("sse", 0, edx, 25),
@@ -64,7 +88,7 @@ __expand_check_macro! {
("sse3", 0, ecx, 0),
("pclmulqdq", 0, ecx, 1),
("ssse3", 0, ecx, 9),
- ("fma", 0, ecx, 12),
+ ("fma", 0, ecx, 28, 0, ecx, 12),
("sse4.1", 0, ecx, 19),
("sse4.2", 0, ecx, 20),
("popcnt", 0, ecx, 23),
@@ -73,7 +97,7 @@ __expand_check_macro! {
("rdrand", 0, ecx, 30),
("sgx", 1, ebx, 2),
("bmi1", 1, ebx, 3),
- ("avx2", 1, ebx, 5),
+ ("avx2", 0, ecx, 28, 1, ebx, 5),
("bmi2", 1, ebx, 8),
("rdseed", 1, ebx, 18),
("adx", 1, ebx, 19),