Skip to content

Commit

Permalink
cpufeatures: check AVX availability when detecting AVX2 and FMA (#792)
Browse files Browse the repository at this point in the history
  • Loading branch information
newpavlov committed Aug 18, 2022
1 parent 8e74aa5 commit b637d94
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions cpufeatures/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 0.2.3 (2022-08-18)
### Changed
- Update `libc` version to v0.2.95 ([#789])
- Disable all target features under MIRI ([#779])
- Check AVX availability when detecting AVX2 and FMA ([#792])

[#779]: https://github.com/RustCrypto/utils/pull/779
[#789]: https://github.com/RustCrypto/utils/pull/789
[#792]: https://github.com/RustCrypto/utils/pull/792

## 0.2.2 (2022-03-18)
### Added
- Support for Android on `aarch64` ([#752])
Expand Down
2 changes: 1 addition & 1 deletion cpufeatures/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cpufeatures"
version = "0.2.2"
version = "0.2.3"
description = """
Lightweight runtime CPU feature detection for x86/x86_64 and aarch64 with
no_std support and support for mobile targets including Android and iOS
Expand Down
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

0 comments on commit b637d94

Please sign in to comment.