-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
xtensa: Support load/store (experimental)
- Loading branch information
Showing
15 changed files
with
463 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
||
#![allow(missing_docs)] | ||
|
||
#[macro_export] | ||
macro_rules! cfg_has_atomic_8 { | ||
($($tt:tt)*) => { $($tt)* }; | ||
} | ||
#[macro_export] | ||
macro_rules! cfg_no_atomic_8 { | ||
($($tt:tt)*) => {}; | ||
} | ||
#[macro_export] | ||
macro_rules! cfg_has_atomic_16 { | ||
($($tt:tt)*) => { $($tt)* }; | ||
} | ||
#[macro_export] | ||
macro_rules! cfg_no_atomic_16 { | ||
($($tt:tt)*) => {}; | ||
} | ||
#[macro_export] | ||
macro_rules! cfg_has_atomic_32 { | ||
($($tt:tt)*) => { $($tt)* }; | ||
} | ||
#[macro_export] | ||
macro_rules! cfg_no_atomic_32 { | ||
($($tt:tt)*) => {}; | ||
} | ||
#[macro_export] | ||
macro_rules! cfg_has_atomic_64 { | ||
($($tt:tt)*) => {}; | ||
} | ||
#[macro_export] | ||
macro_rules! cfg_no_atomic_64 { | ||
($($tt:tt)*) => { $($tt)* }; | ||
} | ||
#[macro_export] | ||
macro_rules! cfg_has_atomic_128 { | ||
($($tt:tt)*) => {}; | ||
} | ||
#[macro_export] | ||
macro_rules! cfg_no_atomic_128 { | ||
($($tt:tt)*) => { $($tt)* }; | ||
} | ||
#[macro_export] | ||
macro_rules! cfg_has_atomic_cas { | ||
($($tt:tt)*) => {}; | ||
} | ||
#[macro_export] | ||
macro_rules! cfg_no_atomic_cas { | ||
($($tt:tt)*) => { $($tt)* }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
||
/* | ||
Xtensa | ||
Refs: | ||
- Xtensa Instruction Set Architecture (ISA) Reference Manual https://web.archive.org/web/20241005102231/https://0x04.net/~mwk/doc/xtensa.pdf | ||
- https://github.com/espressif/llvm-project/blob/xtensa_release_18.1.2/llvm/test/CodeGen/Xtensa/atomic-load-store.ll | ||
*/ | ||
|
||
#[path = "cfgs/xtensa.rs"] | ||
mod cfgs; | ||
|
||
use core::{arch::asm, mem::MaybeUninit, sync::atomic::Ordering}; | ||
|
||
use crate::raw::{AtomicLoad, AtomicStore}; | ||
|
||
macro_rules! atomic { | ||
($int_type:ident, $asm_size:tt, $asm_suffix:tt, $asm_load_ext:tt) => { | ||
impl AtomicLoad for $int_type { | ||
#[inline] | ||
unsafe fn atomic_load( | ||
src: *const MaybeUninit<Self>, | ||
order: Ordering, | ||
) -> MaybeUninit<Self> { | ||
let out: MaybeUninit<Self>; | ||
|
||
// SAFETY: the caller must uphold the safety contract. | ||
unsafe { | ||
macro_rules! atomic_load { | ||
($acquire:tt) => { | ||
asm!( | ||
concat!("l", $asm_size, $asm_load_ext, "i", $asm_suffix, " {out}, {src}, 0"), | ||
$acquire, | ||
src = in(reg) ptr_reg!(src), | ||
out = lateout(reg) out, | ||
options(nostack, preserves_flags), | ||
) | ||
}; | ||
} | ||
match order { | ||
Ordering::Relaxed => atomic_load!(""), | ||
Ordering::Acquire | Ordering::SeqCst => atomic_load!("memw"), | ||
_ => unreachable!(), | ||
} | ||
} | ||
out | ||
} | ||
} | ||
impl AtomicStore for $int_type { | ||
#[inline] | ||
unsafe fn atomic_store( | ||
dst: *mut MaybeUninit<Self>, | ||
val: MaybeUninit<Self>, | ||
order: Ordering, | ||
) { | ||
// SAFETY: the caller must uphold the safety contract. | ||
unsafe { | ||
macro_rules! atomic_store { | ||
($acquire:tt, $release:tt) => { | ||
asm!( | ||
$release, | ||
concat!("s", $asm_size, "i", $asm_suffix, " {val}, {dst}, 0"), | ||
$acquire, | ||
dst = in(reg) ptr_reg!(dst), | ||
val = in(reg) val, | ||
options(nostack, preserves_flags), | ||
) | ||
}; | ||
} | ||
match order { | ||
Ordering::Relaxed => atomic_store!("", ""), | ||
Ordering::Release => atomic_store!("", "memw"), | ||
Ordering::SeqCst => atomic_store!("memw", "memw"), | ||
_ => unreachable!(), | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
} | ||
|
||
atomic!(i8, "8", "", "u"); | ||
atomic!(u8, "8", "", "u"); | ||
atomic!(i16, "16", "", "u"); | ||
atomic!(u16, "16", "", "u"); | ||
atomic!(i32, "32", ".n", ""); | ||
atomic!(u32, "32", ".n", ""); | ||
atomic!(isize, "32", ".n", ""); | ||
atomic!(usize, "32", ".n", ""); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[target.xtensa-esp32-none-elf] | ||
runner = "wokwi-server --chip esp32" | ||
[target.xtensa-esp32s2-none-elf] | ||
runner = "wokwi-server --chip esp32s2" | ||
[target.xtensa-esp32s3-none-elf] | ||
runner = "wokwi-server --chip esp32s3" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
[package] | ||
name = "xtensa-test" | ||
version = "0.0.0" | ||
edition = "2021" | ||
publish = false | ||
|
||
[dependencies] | ||
atomic-maybe-uninit = { path = "../.." } | ||
|
||
paste = "1" | ||
|
||
[target.xtensa-esp32-none-elf.dependencies] | ||
esp-println = { version = "0.12", default-features = false, features = ["uart", "esp32"] } | ||
esp-hal = { version = "0.21", features = ["esp32"] } | ||
[target.xtensa-esp32s2-none-elf.dependencies] | ||
esp-println = { version = "0.12", default-features = false, features = ["uart", "esp32s2"] } | ||
esp-hal = { version = "0.21", features = ["esp32s2"] } | ||
[target.xtensa-esp32s3-none-elf.dependencies] | ||
esp-println = { version = "0.12", default-features = false, features = ["uart", "esp32s3"] } | ||
esp-hal = { version = "0.21", features = ["esp32s3"] } | ||
|
||
[workspace] | ||
resolver = "2" | ||
|
||
[lints.rust] | ||
rust_2018_idioms = "warn" | ||
single_use_lifetimes = "warn" | ||
# unsafe_op_in_unsafe_fn = "warn" # Set at crate-level instead since https://github.com/rust-lang/rust/pull/100081 is not available on MSRV | ||
|
||
[profile.dev] | ||
opt-level = 'z' | ||
|
||
[profile.release] | ||
opt-level = 'z' |
Oops, something went wrong.