Skip to content

Commit 3188915

Browse files
committed
Optimize config item test a bit.
I used `any(armv6m, armv7m, ...)` in many places where I could have said `cortex_m` instead for the cfg macro calls. Let's change that.
1 parent 1ef6c56 commit 3188915

File tree

9 files changed

+26
-24
lines changed

9 files changed

+26
-24
lines changed

cortex-m/src/interrupt.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
//! Interrupts
22
3+
#[cfg(cortex_m)]
34
use core::arch::asm;
5+
#[cfg(cortex_m)]
46
use core::sync::atomic::{Ordering, compiler_fence};
57

68
pub use bare_metal::{CriticalSection, Mutex, Nr};
@@ -37,6 +39,7 @@ unsafe impl<T: Nr + Copy> InterruptNumber for T {
3739

3840
/// Disables all interrupts
3941
#[inline]
42+
#[cortex_m_macros::asm_wrapper(cortex_m)]
4043
pub fn disable() {
4144
unsafe { asm!("cpsid i", options(nomem, nostack, preserves_flags)) };
4245

@@ -50,7 +53,7 @@ pub fn disable() {
5053
///
5154
/// - Do not call this function inside an `interrupt::free` critical section
5255
#[inline]
53-
#[cortex_m_macros::asm_wrapper(any(armv6m, armv7m, armv7em, armv8m))]
56+
#[cortex_m_macros::asm_wrapper(cortex_m)]
5457
pub unsafe fn enable() {
5558
// Ensure no preceeding memory accesses are reordered to after interrupts are enabled.
5659
compiler_fence(Ordering::SeqCst);

cortex-m/src/peripheral/scb.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ impl SCB {
308308
///
309309
/// This operation first invalidates the entire I-cache.
310310
#[inline]
311-
#[cortex_m_macros::asm_wrapper(any(armv7m, armv7em, armv8m))]
311+
#[cortex_m_macros::asm_wrapper(cortex_m)]
312312
pub fn enable_icache(&mut self) {
313313
// Don't do anything if I-cache is already enabled
314314
if Self::icache_enabled() {
@@ -380,7 +380,6 @@ impl SCB {
380380

381381
/// Invalidates the entire I-cache.
382382
#[inline]
383-
#[cortex_m_macros::asm_wrapper(any(armv6m, armv7m, armv7em, armv8m))]
384383
pub fn invalidate_icache(&mut self) {
385384
// NOTE(unsafe): No races as all CBP registers are write-only and stateless
386385
let mut cbp = unsafe { CBP::new() };
@@ -397,7 +396,7 @@ impl SCB {
397396
/// This operation first invalidates the entire D-cache, ensuring it does
398397
/// not contain stale values before being enabled.
399398
#[inline]
400-
#[cortex_m_macros::asm_wrapper(any(armv6m, armv7m, armv7em, armv8m))]
399+
#[cortex_m_macros::asm_wrapper(cortex_m)]
401400
pub fn enable_dcache(&mut self, cpuid: &mut CPUID) {
402401
// Don't do anything if D-cache is already enabled
403402
if Self::dcache_enabled() {
@@ -467,7 +466,7 @@ impl SCB {
467466
///
468467
/// It's used immediately before enabling the dcache, but not exported publicly.
469468
#[inline]
470-
#[cortex_m_macros::asm_wrapper(any(armv6m, armv7m, armv7em, armv8m))]
469+
#[cfg(cortex_m)]
471470
unsafe fn invalidate_dcache(&mut self, cpuid: &mut CPUID) {
472471
unsafe {
473472
// NOTE(unsafe): No races as all CBP registers are write-only and stateless

cortex-m/src/register/apsr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Application Program Status Register
22
3-
#[cfg(any(armv6m, armv7m, armv7em, armv8m))]
3+
#[cfg(cortex_m)]
44
use core::arch::asm;
55

66
/// Application Program Status Register
@@ -51,7 +51,7 @@ impl Apsr {
5151
///
5252
/// **NOTE** This function is available if `cortex-m` is built with the `"inline-asm"` feature.
5353
#[inline]
54-
#[cortex_m_macros::asm_wrapper(any(armv6m, armv7m, armv7em, armv8m))]
54+
#[cortex_m_macros::asm_wrapper(cortex_m)]
5555
pub fn read() -> Apsr {
5656
let bits;
5757
unsafe { asm!("mrs {}, APSR", out(reg) bits, options(nomem, nostack, preserves_flags)) };

cortex-m/src/register/control.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
//! Control register
22
3-
#[cfg(any(armv6m, armv7m, armv7em, armv8m))]
3+
#[cfg(cortex_m)]
44
use core::arch::asm;
5-
#[cfg(any(armv6m, armv7m, armv7em, armv8m))]
5+
#[cfg(cortex_m)]
66
use core::sync::atomic::{Ordering, compiler_fence};
77

88
/// Control register
@@ -178,7 +178,7 @@ impl Fpca {
178178

179179
/// Reads the CPU register
180180
#[inline]
181-
#[cortex_m_macros::asm_wrapper(any(armv6m, armv7m, armv7em, armv8m))]
181+
#[cortex_m_macros::asm_wrapper(cortex_m)]
182182
pub fn read() -> Control {
183183
let bits;
184184
unsafe { asm!("mrs {}, CONTROL", out(reg) bits, options(nomem, nostack, preserves_flags)) };
@@ -187,7 +187,7 @@ pub fn read() -> Control {
187187

188188
/// Writes to the CPU register.
189189
#[inline]
190-
#[cortex_m_macros::asm_wrapper(any(armv6m, armv7m, armv7em, armv8m))]
190+
#[cortex_m_macros::asm_wrapper(cortex_m)]
191191
pub unsafe fn write(control: Control) {
192192
let control = control.bits();
193193

cortex-m/src/register/faultmask.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Fault Mask Register
22
3-
#[cfg(any(armv6m, armv7m, armv7em, armv8m))]
3+
#[cfg(cortex_m)]
44
use core::arch::asm;
55

66
/// All exceptions are ...

cortex-m/src/register/lr.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
//! Link register
22
3-
#[cfg(any(armv6m, armv7m, armv7em, armv8m))]
3+
#[cfg(cortex_m)]
44
use core::arch::asm;
55

66
/// Reads the CPU register
77
///
88
/// **NOTE** This function is available if `cortex-m` is built with the `"inline-asm"` feature.
99
#[inline]
10-
#[cortex_m_macros::asm_wrapper(any(armv6m, armv7m, armv7em, armv8m))]
10+
#[cortex_m_macros::asm_wrapper(cortex_m)]
1111
pub fn read() -> u32 {
1212
let r;
1313
unsafe { asm!("mov {}, lr", out(reg) r, options(nomem, nostack, preserves_flags)) };
@@ -22,7 +22,7 @@ pub fn read() -> u32 {
2222
/// This function can't be used soundly.
2323
#[inline]
2424
#[deprecated = "This function can't be used soundly."]
25-
#[cortex_m_macros::asm_wrapper(any(armv6m, armv7m, armv7em, armv8m))]
25+
#[cortex_m_macros::asm_wrapper(cortex_m)]
2626
pub unsafe fn write(bits: u32) {
2727
unsafe { asm!("mov lr, {}", in(reg) bits, options(nomem, nostack, preserves_flags)) };
2828
}

cortex-m/src/register/msp.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
//! Main Stack Pointer
22
3-
#[cfg(any(armv6m, armv7m, armv7em, armv8m))]
3+
#[cfg(cortex_m)]
44
use core::arch::asm;
55

66
/// Reads the CPU register
77
#[inline]
8-
#[cortex_m_macros::asm_wrapper(any(armv6m, armv7m, armv7em, armv8m))]
8+
#[cortex_m_macros::asm_wrapper(cortex_m)]
99
pub fn read() -> u32 {
1010
let r;
1111
unsafe { asm!("mrs {}, MSP", out(reg) r, options(nomem, nostack, preserves_flags)) };
@@ -15,7 +15,7 @@ pub fn read() -> u32 {
1515
/// Writes `bits` to the CPU register
1616
#[inline]
1717
#[deprecated = "calling this function invokes Undefined Behavior, consider asm::bootstrap as an alternative"]
18-
#[cortex_m_macros::asm_wrapper(any(armv6m, armv7m, armv7em, armv8m))]
18+
#[cortex_m_macros::asm_wrapper(cortex_m)]
1919
pub unsafe fn write(bits: u32) {
2020
// Technically is writing to the stack pointer "not pushing any data to the stack"?
2121
// In any event, if we don't set `nostack` here, this method is useless as the new

cortex-m/src/register/pc.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
//! Program counter
22
3-
#[cfg(any(armv6m, armv7m, armv7em, armv8m))]
3+
#[cfg(cortex_m)]
44
use core::arch::asm;
55

66
/// Reads the CPU register
77
///
88
/// **NOTE** This function is available if `cortex-m` is built with the `"inline-asm"` feature.
99
#[inline]
10-
#[cortex_m_macros::asm_wrapper(any(armv6m, armv7m, armv7em, armv8m))]
10+
#[cortex_m_macros::asm_wrapper(cortex_m)]
1111
pub fn read() -> u32 {
1212
let r;
1313
unsafe { asm!("mov {}, pc", out(reg) r, options(nomem, nostack, preserves_flags)) };
@@ -18,7 +18,7 @@ pub fn read() -> u32 {
1818
///
1919
/// **NOTE** This function is available if `cortex-m` is built with the `"inline-asm"` feature.
2020
#[inline]
21-
#[cortex_m_macros::asm_wrapper(any(armv6m, armv7m, armv7em, armv8m))]
21+
#[cortex_m_macros::asm_wrapper(cortex_m)]
2222
pub unsafe fn write(bits: u32) {
2323
unsafe { asm!("mov pc, {}", in(reg) bits, options(nomem, nostack, preserves_flags)) };
2424
}

cortex-m/src/register/psp.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
//! Process Stack Pointer
22
3-
#[cfg(any(armv6m, armv7m, armv7em, armv8m))]
3+
#[cfg(cortex_m)]
44
use core::arch::asm;
55

66
/// Reads the CPU register
77
#[inline]
8-
#[cortex_m_macros::asm_wrapper(any(armv6m, armv7m, armv7em, armv8m))]
8+
#[cortex_m_macros::asm_wrapper(cortex_m)]
99
pub fn read() -> u32 {
1010
let r;
1111
unsafe { asm!("mrs {}, PSP", out(reg) r, options(nomem, nostack, preserves_flags)) };
@@ -14,7 +14,7 @@ pub fn read() -> u32 {
1414

1515
/// Writes `bits` to the CPU register
1616
#[inline]
17-
#[cortex_m_macros::asm_wrapper(any(armv6m, armv7m, armv7em, armv8m))]
17+
#[cortex_m_macros::asm_wrapper(cortex_m)]
1818
pub unsafe fn write(bits: u32) {
1919
// See comment on __msp_w. Unlike MSP, there are legitimate use-cases for modifying PSP
2020
// if MSP is currently being used as the stack pointer.

0 commit comments

Comments
 (0)