Skip to content

Commit 61c8da7

Browse files
bors[bot]luojia65
andauthored
Merge #94
94: csr: inline register reads and type conversations r=dkhayes117 a=luojia65 This pull request adds missing `#[inline]` flags on field read functions and type conversations. Field `#[inline]` marks to enable inline function optimization which speed up the code when used to build kernels and hypervisors. Please hint me if there are more missing `#[inline]` flags in project `riscv` so I may include them in this fix too. Off topic: would it be the time to release a 0.7.1 version now? Then we do not need to pin to commit numbers when developing risc-v projects. r? `@Disasm` Co-authored-by: luojia65 <[email protected]>
2 parents dc0bc37 + f62fddc commit 61c8da7

File tree

13 files changed

+28
-0
lines changed

13 files changed

+28
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1414
- Add delay structure and methods using embedded-hal traits and `mcycle` register
1515
- Add `asm::delay()` function for assembly-based busy-loops
1616
- Add `asm::nop()`, a wrapper for implementing a `nop` instruction
17+
- Add missing `#[inline]` attribute to register reads, type conversations and `interrupt::free`
1718

1819
### Changed
1920

src/delay.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ pub struct McycleDelay {
99

1010
impl McycleDelay {
1111
/// Constructs the delay provider
12+
#[inline(always)]
1213
pub fn new(ticks_second: u32) -> Self {
1314
Self { ticks_second }
1415
}
1516
}
1617

1718
impl DelayUs<u64> for McycleDelay {
19+
#[inline]
1820
fn delay_us(&mut self, us: u64) {
1921
let t0 = mcycle::read64();
2022
let clock = (us * (self.ticks_second as u64)) / 1_000_000;
@@ -53,6 +55,7 @@ impl DelayUs<u8> for McycleDelay {
5355
}
5456

5557
impl DelayMs<u32> for McycleDelay {
58+
#[inline]
5659
fn delay_ms(&mut self, ms: u32) {
5760
self.delay_us((ms as u64) * 1000)
5861
}

src/interrupt.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ pub unsafe fn enable() {
3333
/// Execute closure `f` in an interrupt-free context.
3434
///
3535
/// This as also known as a "critical section".
36+
#[inline]
3637
pub fn free<F, R>(f: F) -> R
3738
where
3839
F: FnOnce(&CriticalSection) -> R,

src/register/fcsr.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ pub enum RoundingMode {
7676

7777
impl FCSR {
7878
/// Returns the contents of the register as raw bits
79+
#[inline]
7980
pub fn bits(&self) -> u32 {
8081
self.bits
8182
}

src/register/marchid.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub struct Marchid {
1010

1111
impl Marchid {
1212
/// Returns the contents of the register as raw bits
13+
#[inline]
1314
pub fn bits(&self) -> usize {
1415
self.bits.get()
1516
}

src/register/mcause.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ pub enum Exception {
4949
}
5050

5151
impl Interrupt {
52+
#[inline]
5253
pub fn from(nr: usize) -> Self {
5354
match nr {
5455
0 => Interrupt::UserSoft,
@@ -66,6 +67,7 @@ impl Interrupt {
6667
}
6768

6869
impl Exception {
70+
#[inline]
6971
pub fn from(nr: usize) -> Self {
7072
match nr {
7173
0 => Exception::InstructionMisaligned,
@@ -94,6 +96,7 @@ impl Mcause {
9496
}
9597

9698
/// Returns the code field
99+
#[inline]
97100
pub fn code(&self) -> usize {
98101
match () {
99102
#[cfg(target_pointer_width = "32")]

src/register/mimpid.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub struct Mimpid {
1010

1111
impl Mimpid {
1212
/// Returns the contents of the register as raw bits
13+
#[inline]
1314
pub fn bits(&self) -> usize {
1415
self.bits.get()
1516
}

src/register/misa.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@ pub enum MXL {
1818

1919
impl Misa {
2020
/// Returns the contents of the register as raw bits
21+
#[inline]
2122
pub fn bits(&self) -> usize {
2223
self.bits.get()
2324
}
2425

2526
/// Returns the machine xlen.
27+
#[inline]
2628
pub fn mxl(&self) -> MXL {
2729
let value = match () {
2830
#[cfg(target_pointer_width = "32")]
@@ -39,6 +41,7 @@ impl Misa {
3941
}
4042

4143
/// Returns true when the atomic extension is implemented.
44+
#[inline]
4245
pub fn has_extension(&self, extension: char) -> bool {
4346
let bit = extension as u8 - 65;
4447
if bit > 25 {

src/register/mtvec.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,19 @@ pub enum TrapMode {
1515

1616
impl Mtvec {
1717
/// Returns the contents of the register as raw bits
18+
#[inline]
1819
pub fn bits(&self) -> usize {
1920
self.bits
2021
}
2122

2223
/// Returns the trap-vector base-address
24+
#[inline]
2325
pub fn address(&self) -> usize {
2426
self.bits - (self.bits & 0b11)
2527
}
2628

2729
/// Returns the trap-vector mode
30+
#[inline]
2831
pub fn trap_mode(&self) -> Option<TrapMode> {
2932
let mode = self.bits & 0b11;
3033
match mode {

src/register/mvendorid.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ pub struct Mvendorid {
1010

1111
impl Mvendorid {
1212
/// Returns the contents of the register as raw bits
13+
#[inline]
1314
pub fn bits(&self) -> usize {
1415
self.bits.get()
1516
}
1617

1718
/// Returns the JEDEC manufacturer ID
19+
#[inline]
1820
pub fn jedec_manufacturer(&self) -> usize {
1921
self.bits() >> 7
2022
}

0 commit comments

Comments
 (0)