diff options
| author | WANG Rui <wangrui@loongson.cn> | 2025-08-27 11:45:42 +0800 |
|---|---|---|
| committer | WANG Rui <wangrui@loongson.cn> | 2025-08-27 16:40:54 +0800 |
| commit | 0da328b2c61d39da1e0458ac528b667ae9055eb6 (patch) | |
| tree | 721e6ecf8397cf6d8b41ec65d7db29fd2c6d5038 | |
| parent | 176d8dbce6a7a7a4541d1c980d4a85dfb76ce1f1 (diff) | |
| download | rust-0da328b2c61d39da1e0458ac528b667ae9055eb6.tar.gz rust-0da328b2c61d39da1e0458ac528b667ae9055eb6.zip | |
Add spin_loop hint for LoongArch
| -rw-r--r-- | library/core/src/hint.rs | 56 |
1 files changed, 23 insertions, 33 deletions
diff --git a/library/core/src/hint.rs b/library/core/src/hint.rs index c72eeb9a9c9..535c5a8e77b 100644 --- a/library/core/src/hint.rs +++ b/library/core/src/hint.rs @@ -267,39 +267,29 @@ pub const unsafe fn assert_unchecked(cond: bool) { #[inline(always)] #[stable(feature = "renamed_spin_loop", since = "1.49.0")] pub fn spin_loop() { - #[cfg(target_arch = "x86")] - { - // SAFETY: the `cfg` attr ensures that we only execute this on x86 targets. - unsafe { crate::arch::x86::_mm_pause() }; - } - - #[cfg(target_arch = "x86_64")] - { - // SAFETY: the `cfg` attr ensures that we only execute this on x86_64 targets. - unsafe { crate::arch::x86_64::_mm_pause() }; - } - - #[cfg(target_arch = "riscv32")] - { - crate::arch::riscv32::pause(); - } - - #[cfg(target_arch = "riscv64")] - { - crate::arch::riscv64::pause(); - } - - #[cfg(any(target_arch = "aarch64", target_arch = "arm64ec"))] - { - // SAFETY: the `cfg` attr ensures that we only execute this on aarch64 targets. - unsafe { crate::arch::aarch64::__isb(crate::arch::aarch64::SY) }; - } - - #[cfg(all(target_arch = "arm", target_feature = "v6"))] - { - // SAFETY: the `cfg` attr ensures that we only execute this on arm targets - // with support for the v6 feature. - unsafe { crate::arch::arm::__yield() }; + crate::cfg_select! { + target_arch = "x86" => { + // SAFETY: the `cfg` attr ensures that we only execute this on x86 targets. + unsafe { crate::arch::x86::_mm_pause() } + } + target_arch = "x86_64" => { + // SAFETY: the `cfg` attr ensures that we only execute this on x86_64 targets. + unsafe { crate::arch::x86_64::_mm_pause() } + } + target_arch = "riscv32" => crate::arch::riscv32::pause(), + target_arch = "riscv64" => crate::arch::riscv64::pause(), + any(target_arch = "aarch64", target_arch = "arm64ec") => { + // SAFETY: the `cfg` attr ensures that we only execute this on aarch64 targets. + unsafe { crate::arch::aarch64::__isb(crate::arch::aarch64::SY) } + } + all(target_arch = "arm", target_feature = "v6") => { + // SAFETY: the `cfg` attr ensures that we only execute this on arm targets + // with support for the v6 feature. + unsafe { crate::arch::arm::__yield() } + } + target_arch = "loongarch32" => crate::arch::loongarch32::ibar::<0>(), + target_arch = "loongarch64" => crate::arch::loongarch64::ibar::<0>(), + _ => { /* do nothing */ } } } |
