Skip to content

Commit

Permalink
Simplify core::hint::spin_loop
Browse files Browse the repository at this point in the history
  • Loading branch information
WaffleLapkin committed Sep 4, 2023
1 parent bf1e3f3 commit 1811fe6
Showing 1 changed file with 17 additions and 24 deletions.
41 changes: 17 additions & 24 deletions library/core/src/hint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,34 +175,27 @@ pub fn spin_loop() {
unsafe { crate::arch::x86_64::_mm_pause() };
}

// RISC-V platform spin loop hint implementation
#[cfg(target_arch = "riscv32")]
{
// RISC-V RV32 and RV64 share the same PAUSE instruction, but they are located in different
// modules in `core::arch`.
// In this case, here we call `pause` function in each core arch module.
#[cfg(target_arch = "riscv32")]
{
crate::arch::riscv32::pause();
}
#[cfg(target_arch = "riscv64")]
{
crate::arch::riscv64::pause();
}
crate::arch::riscv32::pause();
}

#[cfg(any(target_arch = "aarch64", all(target_arch = "arm", target_feature = "v6")))]
#[cfg(target_arch = "riscv64")]
{
#[cfg(target_arch = "aarch64")]
{
// SAFETY: the `cfg` attr ensures that we only execute this on aarch64 targets.
unsafe { crate::arch::aarch64::__isb(crate::arch::aarch64::SY) };
}
#[cfg(target_arch = "arm")]
{
// 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::arch::riscv64::pause();
}

#[cfg(target_arch = "aarch64")]
{
// 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() };
}
}

Expand Down

0 comments on commit 1811fe6

Please sign in to comment.