Skip to content

Commit dfe2046

Browse files
authored
Rename the wasm atomic intrinsics (#617)
This commit renames the atomic intrinsics for wasm and tweaks them to match the new naming convention of the memory intrinsics. Apart from naming the `wake` intrinsic was renamed to `atomic_notify` (reflecting the upstream rename) as well as updating to take/return unsigned arguments, also reflecting the upstream spec changes.
1 parent 04bb793 commit dfe2046

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

coresimd/wasm32/atomic.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ extern "C" {
5353
/// [instr]: https://github.com/WebAssembly/threads/blob/master/proposals/threads/Overview.md#wait
5454
#[inline]
5555
#[cfg_attr(test, assert_instr("i32.atomic.wait"))]
56-
pub unsafe fn wait_i32(
56+
pub unsafe fn i32_atomic_wait(
5757
ptr: *mut i32, expression: i32, timeout_ns: i64,
5858
) -> i32 {
5959
llvm_atomic_wait_i32(ptr, expression, timeout_ns)
@@ -90,25 +90,24 @@ pub unsafe fn wait_i32(
9090
/// [instr]: https://github.com/WebAssembly/threads/blob/master/proposals/threads/Overview.md#wait
9191
#[inline]
9292
#[cfg_attr(test, assert_instr("i64.atomic.wait"))]
93-
pub unsafe fn wait_i64(
93+
pub unsafe fn i64_atomic_wait(
9494
ptr: *mut i64, expression: i64, timeout_ns: i64,
9595
) -> i32 {
9696
llvm_atomic_wait_i64(ptr, expression, timeout_ns)
9797
}
9898

99-
/// Corresponding intrinsic to wasm's [`atomic.wake` instruction][instr]
99+
/// Corresponding intrinsic to wasm's [`atomic.notify` instruction][instr]
100100
///
101-
/// This function will wake up a number of threads blocked on the address
102-
/// indicated by `ptr`. Threads previously blocked with the `wait_i32` and
103-
/// `wait_i64` functions above will be woken up.
101+
/// This function will notify a number of threads blocked on the address
102+
/// indicated by `ptr`. Threads previously blocked with the `i32_atomic_wait`
103+
/// and `i64_atomic_wait` functions above will be woken up.
104104
///
105105
/// The `waiters` argument indicates how many waiters should be woken up (a
106-
/// maximum). If the value is negative all waiters are woken up, and if the
107-
/// value is zero no waiters are woken up.
106+
/// maximum). If the value is zero no waiters are woken up.
108107
///
109108
/// # Return value
110109
///
111-
/// Returns the number of waiters which were actually woken up.
110+
/// Returns the number of waiters which were actually notified.
112111
///
113112
/// # Availability
114113
///
@@ -120,6 +119,6 @@ pub unsafe fn wait_i64(
120119
/// [instr]: https://github.com/WebAssembly/threads/blob/master/proposals/threads/Overview.md#wake
121120
#[inline]
122121
#[cfg_attr(test, assert_instr("atomic.wake"))]
123-
pub unsafe fn wake(ptr: *mut i32, waiters: i32) -> i32 {
124-
llvm_atomic_notify(ptr, waiters)
122+
pub unsafe fn atomic_notify(ptr: *mut i32, waiters: u32) -> u32 {
123+
llvm_atomic_notify(ptr, waiters as i32) as u32
125124
}

coresimd/wasm32/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ use stdsimd_test::assert_instr;
1616
#[cfg(test)]
1717
use wasm_bindgen_test::wasm_bindgen_test;
1818

19-
pub mod atomic;
19+
#[cfg(any(target_feature = "atomics", dox))]
20+
mod atomic;
21+
#[cfg(any(target_feature = "atomics", dox))]
22+
pub use self::atomic::*;
2023

2124
mod memory;
2225
pub use self::memory::*;

0 commit comments

Comments
 (0)