Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions cpufeatures/src/x86.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,34 @@ 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),
("sse2", 0, edx, 26),
("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),
Expand All @@ -73,7 +82,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),
Expand Down