Skip to content

Commit b637d94

Browse files
authored
cpufeatures: check AVX availability when detecting AVX2 and FMA (#792)
1 parent 8e74aa5 commit b637d94

File tree

4 files changed

+25
-6
lines changed

4 files changed

+25
-6
lines changed

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cpufeatures/CHANGELOG.md

+10
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## 0.2.3 (2022-08-18)
9+
### Changed
10+
- Update `libc` version to v0.2.95 ([#789])
11+
- Disable all target features under MIRI ([#779])
12+
- Check AVX availability when detecting AVX2 and FMA ([#792])
13+
14+
[#779]: https://github.com/RustCrypto/utils/pull/779
15+
[#789]: https://github.com/RustCrypto/utils/pull/789
16+
[#792]: https://github.com/RustCrypto/utils/pull/792
17+
818
## 0.2.2 (2022-03-18)
919
### Added
1020
- Support for Android on `aarch64` ([#752])

cpufeatures/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cpufeatures"
3-
version = "0.2.2"
3+
version = "0.2.3"
44
description = """
55
Lightweight runtime CPU feature detection for x86/x86_64 and aarch64 with
66
no_std support and support for mobile targets including Android and iOS

cpufeatures/src/x86.rs

+13-4
Original file line numberDiff line numberDiff line change
@@ -46,25 +46,34 @@ macro_rules! __detect_target_features {
4646
}
4747

4848
macro_rules! __expand_check_macro {
49-
($(($name:tt, $i:expr, $reg:ident, $offset:expr)),* $(,)?) => {
49+
($(($name:tt $(, $i:expr, $reg:ident, $offset:expr)*)),* $(,)?) => {
5050
#[macro_export]
5151
#[doc(hidden)]
5252
macro_rules! check {
5353
$(
54-
($cr:expr, $name) => { ($cr[$i].$reg & (1 << $offset) != 0) };
54+
($cr:expr, $name) => {
55+
true
56+
$(
57+
& ($cr[$i].$reg & (1 << $offset) != 0)
58+
)*
59+
};
5560
)*
5661
}
5762
};
5863
}
5964

65+
// Note that according to the [Intel manual][0] AVX2 and FMA require
66+
// that we check availability of AVX before using them.
67+
//
68+
// [0]: https://www.intel.com/content/dam/develop/external/us/en/documents/36945
6069
__expand_check_macro! {
6170
("mmx", 0, edx, 23),
6271
("sse", 0, edx, 25),
6372
("sse2", 0, edx, 26),
6473
("sse3", 0, ecx, 0),
6574
("pclmulqdq", 0, ecx, 1),
6675
("ssse3", 0, ecx, 9),
67-
("fma", 0, ecx, 12),
76+
("fma", 0, ecx, 28, 0, ecx, 12),
6877
("sse4.1", 0, ecx, 19),
6978
("sse4.2", 0, ecx, 20),
7079
("popcnt", 0, ecx, 23),
@@ -73,7 +82,7 @@ __expand_check_macro! {
7382
("rdrand", 0, ecx, 30),
7483
("sgx", 1, ebx, 2),
7584
("bmi1", 1, ebx, 3),
76-
("avx2", 1, ebx, 5),
85+
("avx2", 0, ecx, 28, 1, ebx, 5),
7786
("bmi2", 1, ebx, 8),
7887
("rdseed", 1, ebx, 18),
7988
("adx", 1, ebx, 19),

0 commit comments

Comments
 (0)