aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Роман Кривенков <qwerty19106@gmail.com> 2020-03-17 13:38:04 +0400
committerGravatar Роман Кривенков <qwerty19106@gmail.com> 2020-03-17 22:08:35 +0400
commit536575c843068e59761570d5c800f3619a284b25 (patch)
tree53c5555d98f04e4bba93b6915dbd3d2bab6394d9 /src
parent12f11d29afabfb0149a660589f59bb8ba0f02161 (diff)
downloadcortex-m-536575c843068e59761570d5c800f3619a284b25.tar.gz
cortex-m-536575c843068e59761570d5c800f3619a284b25.tar.zst
cortex-m-536575c843068e59761570d5c800f3619a284b25.zip
Prevent unnecessary bounds check in SCB::{get_priority, set_priority}
Diffstat (limited to 'src')
-rw-r--r--src/peripheral/scb.rs26
1 files changed, 22 insertions, 4 deletions
diff --git a/src/peripheral/scb.rs b/src/peripheral/scb.rs
index faebea1..d2aacd7 100644
--- a/src/peripheral/scb.rs
+++ b/src/peripheral/scb.rs
@@ -949,13 +949,23 @@ impl SCB {
#[cfg(not(armv6m))]
{
// NOTE(unsafe) atomic read with no side effects
- unsafe { (*Self::ptr()).shpr[usize::from(index - 4)].read() }
+
+ // NOTE(unsafe): prevent unnecessary bounds check! Index of shpr array is
+ // true by SystemHandler design.
+ let priority_ref = unsafe {(*Self::ptr()).shpr.get_unchecked(usize::from(index - 4))};
+
+ priority_ref.read()
}
#[cfg(armv6m)]
{
// NOTE(unsafe) atomic read with no side effects
- let shpr = unsafe { (*Self::ptr()).shpr[usize::from((index - 8) / 4)].read() };
+
+ // NOTE(unsafe): prevent unnecessary bounds check! Index of shpr array is
+ // true by SystemHandler design.
+ let priority_ref = unsafe {(*Self::ptr()).shpr.get_unchecked(usize::from((index - 8) / 4))};
+
+ let shpr = priority_ref.read();
let prio = (shpr >> (8 * (index % 4))) & 0x0000_00ff;
prio as u8
}
@@ -979,12 +989,20 @@ impl SCB {
#[cfg(not(armv6m))]
{
- self.shpr[usize::from(index - 4)].write(prio)
+ // NOTE(unsafe): prevent unnecessary bounds check! Index of shpr array is
+ // true by SystemHandler design.
+ let priority_ref = (*Self::ptr()).shpr.get_unchecked(usize::from(index - 4));
+
+ priority_ref.write(prio)
}
#[cfg(armv6m)]
{
- self.shpr[usize::from((index - 8) / 4)].modify(|value| {
+ // NOTE(unsafe): prevent unnecessary bounds check! Index of shpr array is
+ // true by SystemHandler design.
+ let priority_ref = (*Self::ptr()).shpr.get_unchecked(usize::from((index - 8) / 4));
+
+ priority_ref.modify(|value| {
let shift = 8 * (index % 4);
let mask = 0x0000_00ff << shift;
let prio = u32::from(prio) << shift;