Vendor asic-rs 0.8.1 (280 crates, offline builds) + wxWidgets 3.3.3 (pristine + patch queue); UI spec + ADR-0003; M1 on asic-rs
This commit is contained in:
Vendored
+113
@@ -0,0 +1,113 @@
|
||||
// Copyright 2016-2024 Brian Smith.
|
||||
//
|
||||
// Permission to use, copy, modify, and/or distribute this software for any
|
||||
// purpose with or without fee is hereby granted, provided that the above
|
||||
// copyright notice and this permission notice appear in all copies.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
// SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||||
// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
use super::{Aes, Neon, PMull, Sha256, Sha512, CAPS_STATIC};
|
||||
use crate::polyfill::cstr;
|
||||
|
||||
// ```
|
||||
// $ rustc +1.61.0 --print cfg --target=aarch64-apple-ios | grep -E "neon|aes|sha|pmull"
|
||||
// target_feature="aes"
|
||||
// target_feature="neon"
|
||||
// target_feature="sha2"
|
||||
// $ rustc +1.61.0 --print cfg --target=aarch64-apple-darwin | grep -E "neon|aes|sha|pmull"
|
||||
// target_feature="aes"
|
||||
// target_feature="neon"
|
||||
// target_feature="sha2"
|
||||
// target_feature="sha3"
|
||||
// ```
|
||||
//
|
||||
// XXX/TODO(coverage)/TODO(size): aarch64-apple-darwin is statically guaranteed to have "sha3" but
|
||||
// other aarch64-apple-* targets require dynamic detection. Since we don't have test coverage for
|
||||
// the other targets yet, we wouldn't have a way of testing the dynamic detection if we statically
|
||||
// enabled `Sha512` for -darwin. So instead, temporarily, we statically ignore the static
|
||||
// availability of the feature on -darwin so that it runs the dynamic detection.
|
||||
pub const MIN_STATIC_FEATURES: u32 = Neon::mask() | Aes::mask() | Sha256::mask() | PMull::mask();
|
||||
pub const FORCE_DYNAMIC_DETECTION: u32 = !MIN_STATIC_FEATURES;
|
||||
|
||||
// MSRV: Enforce 1.61.0 onaarch64-apple-*, in particular) prior to. Earlier
|
||||
// versions of Rust before did not report the AAarch64 CPU features correctly
|
||||
// for these targets. Cargo.toml specifies `rust-version` but versions before
|
||||
// Rust 1.56 don't know about it.
|
||||
#[allow(clippy::assertions_on_constants)]
|
||||
const _AARCH64_APPLE_TARGETS_EXPECTED_FEATURES: () =
|
||||
assert!((CAPS_STATIC & MIN_STATIC_FEATURES) == MIN_STATIC_FEATURES);
|
||||
|
||||
// Ensure we don't accidentally allow features statically beyond
|
||||
// `MIN_STATIC_FEATURES` so that dynamic detection is done uniformly for
|
||||
// all of these targets.
|
||||
#[allow(clippy::assertions_on_constants)]
|
||||
const _AARCH64_APPLE_DARWIN_TARGETS_EXPECTED_FEATURES: () =
|
||||
assert!(CAPS_STATIC == MIN_STATIC_FEATURES);
|
||||
|
||||
pub fn detect_features() -> u32 {
|
||||
fn detect_feature(name: cstr::Ref) -> bool {
|
||||
use crate::polyfill;
|
||||
use core::mem;
|
||||
use libc::{c_int, c_void};
|
||||
|
||||
let mut value: c_int = 0;
|
||||
let mut len = mem::size_of_val(&value);
|
||||
let value_ptr = polyfill::ptr::from_mut(&mut value).cast::<c_void>();
|
||||
// SAFETY: `value_ptr` is a valid pointer to `value` and `len` is the size of `value`.
|
||||
let rc = unsafe {
|
||||
libc::sysctlbyname(name.as_ptr(), value_ptr, &mut len, core::ptr::null_mut(), 0)
|
||||
};
|
||||
// All the conditions are separated so we can observe them in code coverage.
|
||||
if rc != 0 {
|
||||
return false;
|
||||
}
|
||||
debug_assert_eq!(len, mem::size_of_val(&value));
|
||||
if len != mem::size_of_val(&value) {
|
||||
return false;
|
||||
}
|
||||
value != 0
|
||||
}
|
||||
|
||||
// We do not need to check for the presence of NEON, as Armv8-A always has it
|
||||
const _ASSERT_NEON_DETECTED: () = assert!((CAPS_STATIC & Neon::mask()) == Neon::mask());
|
||||
|
||||
let mut features = 0;
|
||||
|
||||
// TODO(MSRV 1.77): Use c"..." literal.
|
||||
const SHA512_NAME: cstr::Ref =
|
||||
cstr::unwrap_const_from_bytes_with_nul(b"hw.optional.armv8_2_sha512\0");
|
||||
if detect_feature(SHA512_NAME) {
|
||||
features |= Sha512::mask();
|
||||
}
|
||||
|
||||
features
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::cpu;
|
||||
|
||||
#[test]
|
||||
fn sha512_detection() {
|
||||
// We intentionally disable static feature detection for SHA-512.
|
||||
const _SHA512_NOT_STATICALLY_DETECTED: () = assert!((CAPS_STATIC & Sha512::mask()) == 0);
|
||||
|
||||
if cfg!(target_os = "macos") {
|
||||
use crate::cpu::{arm::Sha512, GetFeature as _};
|
||||
|
||||
// All aarch64-apple-darwin targets have SHA3 enabled statically...
|
||||
assert!(cfg!(target_feature = "sha3"));
|
||||
|
||||
// ...so we should detect it.
|
||||
let cpu = cpu::features();
|
||||
assert!(matches!(cpu.get_feature(), Some(Sha512 { .. })));
|
||||
}
|
||||
}
|
||||
}
|
||||
Vendored
+58
@@ -0,0 +1,58 @@
|
||||
// Copyright 2016-2024 Brian Smith.
|
||||
//
|
||||
// Permission to use, copy, modify, and/or distribute this software for any
|
||||
// purpose with or without fee is hereby granted, provided that the above
|
||||
// copyright notice and this permission notice appear in all copies.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
// SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||||
// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
use super::{Aes, Neon, PMull, Sha256, Sha512, CAPS_STATIC};
|
||||
|
||||
pub const FORCE_DYNAMIC_DETECTION: u32 = 0;
|
||||
|
||||
pub fn detect_features() -> u32 {
|
||||
type zx_status_t = i32;
|
||||
|
||||
#[link(name = "zircon")]
|
||||
extern "C" {
|
||||
fn zx_system_get_features(kind: u32, features: *mut u32) -> zx_status_t;
|
||||
}
|
||||
|
||||
const ZX_OK: i32 = 0;
|
||||
const ZX_FEATURE_KIND_CPU: u32 = 0;
|
||||
const ZX_ARM64_FEATURE_ISA_AES: u32 = 1 << 3;
|
||||
const ZX_ARM64_FEATURE_ISA_PMULL: u32 = 1 << 4;
|
||||
const ZX_ARM64_FEATURE_ISA_SHA256: u32 = 1 << 6;
|
||||
const ZX_ARM64_FEATURE_ISA_SHA512: u32 = 1 << 18;
|
||||
|
||||
let mut caps = 0;
|
||||
let rc = unsafe { zx_system_get_features(ZX_FEATURE_KIND_CPU, &mut caps) };
|
||||
|
||||
let mut features = 0;
|
||||
|
||||
// We do not need to check for the presence of NEON, as Armv8-A always has it
|
||||
const _ASSERT_NEON_DETECTED: () = assert!((CAPS_STATIC & Neon::mask()) == Neon::mask());
|
||||
|
||||
if rc == ZX_OK {
|
||||
if caps & ZX_ARM64_FEATURE_ISA_AES == ZX_ARM64_FEATURE_ISA_AES {
|
||||
features |= Aes::mask();
|
||||
}
|
||||
if caps & ZX_ARM64_FEATURE_ISA_PMULL == ZX_ARM64_FEATURE_ISA_PMULL {
|
||||
features |= PMull::mask();
|
||||
}
|
||||
if caps & ZX_ARM64_FEATURE_ISA_SHA256 == ZX_ARM64_FEATURE_ISA_SHA256 {
|
||||
features |= Sha256::mask();
|
||||
}
|
||||
if caps & ZX_ARM64_FEATURE_ISA_SHA512 == ZX_ARM64_FEATURE_ISA_SHA512 {
|
||||
features |= Sha512::mask();
|
||||
}
|
||||
}
|
||||
|
||||
features
|
||||
}
|
||||
Vendored
+107
@@ -0,0 +1,107 @@
|
||||
// Copyright 2016-2024 Brian Smith.
|
||||
//
|
||||
// Permission to use, copy, modify, and/or distribute this software for any
|
||||
// purpose with or without fee is hereby granted, provided that the above
|
||||
// copyright notice and this permission notice appear in all copies.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
// SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||||
// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
use super::Neon;
|
||||
|
||||
// Work around a bug in LLVM/rustc where `-C target_cpu=cortex-a72`--
|
||||
// and `-C target_cpu=native` on Cortex-A72 Raspberry PI devices in
|
||||
// particular--enables crypto features even though not all Cortex-A72
|
||||
// CPUs have crypto features:
|
||||
//
|
||||
// ```
|
||||
// $ rustc --print cfg --target=aarch64-unknown-linux-gnu | grep feature
|
||||
// target_feature="neon"
|
||||
// $ rustc --print cfg --target=aarch64-unknown-linux-gnu -C target_cpu=cortex-a72 | grep feature
|
||||
// target_feature="aes"
|
||||
// target_feature="crc"
|
||||
// target_feature="neon"
|
||||
// target_feature="pmuv3"
|
||||
// target_feature="sha2"
|
||||
// ```
|
||||
//
|
||||
// XXX/TODO(MSRV https://github.com/llvm/llvm-project/issues/90365): This
|
||||
// workaround is heavy-handed since it forces extra branches for devices that
|
||||
// have correctly-modeled feature sets, so it should be removed.
|
||||
pub const FORCE_DYNAMIC_DETECTION: u32 = !Neon::mask();
|
||||
|
||||
// `uclibc` does not provide `getauxval` so just use static feature detection
|
||||
// for it.
|
||||
#[cfg(target_env = "uclibc")]
|
||||
pub fn detect_features() -> u32 {
|
||||
0
|
||||
}
|
||||
|
||||
#[cfg(all(
|
||||
not(target_env = "uclibc"),
|
||||
all(target_arch = "aarch64", target_endian = "little")
|
||||
))]
|
||||
pub fn detect_features() -> u32 {
|
||||
use super::{Aes, PMull, Sha256, Sha512, CAPS_STATIC};
|
||||
use libc::{getauxval, AT_HWCAP, HWCAP_AES, HWCAP_PMULL, HWCAP_SHA2, HWCAP_SHA512};
|
||||
|
||||
let mut features = 0;
|
||||
|
||||
// We do not need to check for the presence of NEON, as Armv8-A always has it
|
||||
const _ASSERT_NEON_DETECTED: () = assert!((CAPS_STATIC & Neon::mask()) == Neon::mask());
|
||||
|
||||
let caps = unsafe { getauxval(AT_HWCAP) };
|
||||
|
||||
if caps & HWCAP_AES == HWCAP_AES {
|
||||
features |= Aes::mask();
|
||||
}
|
||||
if caps & HWCAP_PMULL == HWCAP_PMULL {
|
||||
features |= PMull::mask();
|
||||
}
|
||||
if caps & HWCAP_SHA2 == HWCAP_SHA2 {
|
||||
features |= Sha256::mask();
|
||||
}
|
||||
if caps & HWCAP_SHA512 == HWCAP_SHA512 {
|
||||
features |= Sha512::mask();
|
||||
}
|
||||
|
||||
features
|
||||
}
|
||||
|
||||
#[cfg(all(
|
||||
not(target_env = "uclibc"),
|
||||
all(target_arch = "arm", target_endian = "little")
|
||||
))]
|
||||
pub fn detect_features() -> u32 {
|
||||
use super::CAPS_STATIC;
|
||||
|
||||
// The `libc` crate doesn't provide this functionality on all
|
||||
// 32-bit Linux targets, like Android or -musl. Use this polyfill
|
||||
// for all 32-bit ARM targets so that testing on one of them will
|
||||
// be more meaningful to the others.
|
||||
use libc::c_ulong;
|
||||
extern "C" {
|
||||
pub fn getauxval(type_: c_ulong) -> c_ulong;
|
||||
}
|
||||
const AT_HWCAP: c_ulong = 16;
|
||||
const HWCAP_NEON: c_ulong = 1 << 12;
|
||||
|
||||
let mut features = 0;
|
||||
|
||||
if CAPS_STATIC & Neon::mask() != Neon::mask() {
|
||||
let caps = unsafe { getauxval(AT_HWCAP) };
|
||||
|
||||
// OpenSSL and BoringSSL don't enable any other features if NEON isn't
|
||||
// available. We don't enable any hardware implementations for 32-bit ARM.
|
||||
if caps & HWCAP_NEON == HWCAP_NEON {
|
||||
features |= Neon::mask();
|
||||
}
|
||||
}
|
||||
|
||||
features
|
||||
}
|
||||
Vendored
+38
@@ -0,0 +1,38 @@
|
||||
// Copyright 2016-2024 Brian Smith.
|
||||
//
|
||||
// Permission to use, copy, modify, and/or distribute this software for any
|
||||
// purpose with or without fee is hereby granted, provided that the above
|
||||
// copyright notice and this permission notice appear in all copies.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
// SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||||
// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
use super::{Aes, Neon, PMull, Sha256, CAPS_STATIC};
|
||||
use windows_sys::Win32::System::Threading::{
|
||||
IsProcessorFeaturePresent, PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE,
|
||||
};
|
||||
|
||||
pub const FORCE_DYNAMIC_DETECTION: u32 = 0;
|
||||
|
||||
pub fn detect_features() -> u32 {
|
||||
// We do not need to check for the presence of NEON, as Armv8-A always has it
|
||||
const _ASSERT_NEON_DETECTED: () = assert!((CAPS_STATIC & Neon::mask()) == Neon::mask());
|
||||
|
||||
let mut features = 0;
|
||||
|
||||
let result = unsafe { IsProcessorFeaturePresent(PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE) };
|
||||
|
||||
if result != 0 {
|
||||
// These are all covered by one call in Windows
|
||||
features |= Aes::mask();
|
||||
features |= PMull::mask();
|
||||
features |= Sha256::mask();
|
||||
}
|
||||
|
||||
features
|
||||
}
|
||||
Reference in New Issue
Block a user