From 0237d2a191a4a41b0f273b8e114b4bf71b878dd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D1=91=D0=BC=20=D0=9F=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=BE=D0=B2?= Date: Tue, 16 Aug 2022 19:38:12 +0300 Subject: [PATCH 1/3] cpufeatures: check AVX availability when detecting AVX2 and FMA --- cpufeatures/src/x86.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/cpufeatures/src/x86.rs b/cpufeatures/src/x86.rs index 37e20ef6..e21131bf 100644 --- a/cpufeatures/src/x86.rs +++ b/cpufeatures/src/x86.rs @@ -46,17 +46,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 +73,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 +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), From c54e7177e30c4fd8947efd3b55ab305a95dc2917 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D1=91=D0=BC=20=D0=9F=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=BE=D0=B2?= Date: Thu, 18 Aug 2022 12:44:29 +0300 Subject: [PATCH 2/3] Bump version to v0.2.3 --- Cargo.lock | 2 +- cpufeatures/CHANGELOG.md | 6 ++++++ cpufeatures/Cargo.toml | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d40503ef..55dca974 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -33,7 +33,7 @@ version = "0.0.2" [[package]] name = "cpufeatures" -version = "0.2.2" +version = "0.2.3" dependencies = [ "libc", ] diff --git a/cpufeatures/CHANGELOG.md b/cpufeatures/CHANGELOG.md index e2961e71..c1f30767 100644 --- a/cpufeatures/CHANGELOG.md +++ b/cpufeatures/CHANGELOG.md @@ -5,6 +5,12 @@ 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 +- Check AVX availability when detecting AVX2 and FMA ([#792]) + +[#792]: https://github.com/RustCrypto/utils/pull/792 + ## 0.2.2 (2022-03-18) ### Added - Support for Android on `aarch64` ([#752]) diff --git a/cpufeatures/Cargo.toml b/cpufeatures/Cargo.toml index 31b328c8..3bd70f0b 100644 --- a/cpufeatures/Cargo.toml +++ b/cpufeatures/Cargo.toml @@ -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 From 97b464cd66bde6deae5b445bc02e18b678f4aac0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D1=91=D0=BC=20=D0=9F=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=BE=D0=B2?= Date: Thu, 18 Aug 2022 12:48:54 +0300 Subject: [PATCH 3/3] Update changelog --- cpufeatures/CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cpufeatures/CHANGELOG.md b/cpufeatures/CHANGELOG.md index c1f30767..2a401c6b 100644 --- a/cpufeatures/CHANGELOG.md +++ b/cpufeatures/CHANGELOG.md @@ -7,8 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## 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)