Rollup merge of #126792 - wooden-worm:master, r=Mark-Simulacrum

wasm64 build with target-feature=+simd128,+atomics

Fixes https://github.com/rust-lang/rust/issues/126778
This commit is contained in:
Jacob Pratt 2024-07-04 04:09:49 -04:00 committed by GitHub
commit 6cf34c0cfd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 18 additions and 10 deletions

View File

@ -30,6 +30,8 @@ where
use core::arch::arm::{uint8x8_t, vtbl1_u8}; use core::arch::arm::{uint8x8_t, vtbl1_u8};
#[cfg(target_arch = "wasm32")] #[cfg(target_arch = "wasm32")]
use core::arch::wasm32 as wasm; use core::arch::wasm32 as wasm;
#[cfg(target_arch = "wasm64")]
use core::arch::wasm64 as wasm;
#[cfg(target_arch = "x86")] #[cfg(target_arch = "x86")]
use core::arch::x86; use core::arch::x86;
#[cfg(target_arch = "x86_64")] #[cfg(target_arch = "x86_64")]

View File

@ -266,6 +266,7 @@
)] )]
#![cfg_attr(any(windows, target_os = "uefi"), feature(round_char_boundary))] #![cfg_attr(any(windows, target_os = "uefi"), feature(round_char_boundary))]
#![cfg_attr(target_family = "wasm", feature(stdarch_wasm_atomic_wait))] #![cfg_attr(target_family = "wasm", feature(stdarch_wasm_atomic_wait))]
#![cfg_attr(target_arch = "wasm64", feature(simd_wasm64))]
#![cfg_attr( #![cfg_attr(
all(any(target_arch = "x86_64", target_arch = "x86"), target_os = "uefi"), all(any(target_arch = "x86_64", target_arch = "x86"), target_os = "uefi"),
feature(stdarch_x86_has_cpuid) feature(stdarch_x86_has_cpuid)

View File

@ -1,4 +1,8 @@
use crate::arch::wasm32; #[cfg(target_arch = "wasm32")]
use core::arch::wasm32 as wasm;
#[cfg(target_arch = "wasm64")]
use core::arch::wasm64 as wasm;
use crate::sync::atomic::AtomicU32; use crate::sync::atomic::AtomicU32;
use crate::time::Duration; use crate::time::Duration;
@ -10,11 +14,8 @@ use crate::time::Duration;
pub fn futex_wait(futex: &AtomicU32, expected: u32, timeout: Option<Duration>) -> bool { pub fn futex_wait(futex: &AtomicU32, expected: u32, timeout: Option<Duration>) -> bool {
let timeout = timeout.and_then(|t| t.as_nanos().try_into().ok()).unwrap_or(-1); let timeout = timeout.and_then(|t| t.as_nanos().try_into().ok()).unwrap_or(-1);
unsafe { unsafe {
wasm32::memory_atomic_wait32( wasm::memory_atomic_wait32(futex as *const AtomicU32 as *mut i32, expected as i32, timeout)
futex as *const AtomicU32 as *mut i32, < 2
expected as i32,
timeout,
) < 2
} }
} }
@ -23,12 +24,12 @@ pub fn futex_wait(futex: &AtomicU32, expected: u32, timeout: Option<Duration>) -
/// Returns true if this actually woke up such a thread, /// Returns true if this actually woke up such a thread,
/// or false if no thread was waiting on this futex. /// or false if no thread was waiting on this futex.
pub fn futex_wake(futex: &AtomicU32) -> bool { pub fn futex_wake(futex: &AtomicU32) -> bool {
unsafe { wasm32::memory_atomic_notify(futex as *const AtomicU32 as *mut i32, 1) > 0 } unsafe { wasm::memory_atomic_notify(futex as *const AtomicU32 as *mut i32, 1) > 0 }
} }
/// Wake up all threads that are waiting on futex_wait on this futex. /// Wake up all threads that are waiting on futex_wait on this futex.
pub fn futex_wake_all(futex: &AtomicU32) { pub fn futex_wake_all(futex: &AtomicU32) {
unsafe { unsafe {
wasm32::memory_atomic_notify(futex as *const AtomicU32 as *mut i32, i32::MAX as u32); wasm::memory_atomic_notify(futex as *const AtomicU32 as *mut i32, i32::MAX as u32);
} }
} }

View File

@ -19,7 +19,11 @@ impl Thread {
pub fn set_name(_name: &CStr) {} pub fn set_name(_name: &CStr) {}
pub fn sleep(dur: Duration) { pub fn sleep(dur: Duration) {
use crate::arch::wasm32; #[cfg(target_arch = "wasm32")]
use core::arch::wasm32 as wasm;
#[cfg(target_arch = "wasm64")]
use core::arch::wasm64 as wasm;
use crate::cmp; use crate::cmp;
// Use an atomic wait to block the current thread artificially with a // Use an atomic wait to block the current thread artificially with a
@ -31,7 +35,7 @@ impl Thread {
while nanos > 0 { while nanos > 0 {
let amt = cmp::min(i64::MAX as u128, nanos); let amt = cmp::min(i64::MAX as u128, nanos);
let mut x = 0; let mut x = 0;
let val = unsafe { wasm32::memory_atomic_wait32(&mut x, 0, amt as i64) }; let val = unsafe { wasm::memory_atomic_wait32(&mut x, 0, amt as i64) };
debug_assert_eq!(val, 2); debug_assert_eq!(val, 2);
nanos -= amt; nanos -= amt;
} }