Skip to content

Commit 92e1e83

Browse files
committed
riscv: use bits helper for mcounteren
Uses the new `bf_extract` helper for the `mcounteren` register.
1 parent ee84d85 commit 92e1e83

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

riscv/src/register/mcounteren.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! mcounteren register
22
3+
use crate::bits::bf_extract;
4+
35
/// mcounteren register
46
#[derive(Clone, Copy, Debug)]
57
pub struct Mcounteren {
@@ -10,26 +12,26 @@ impl Mcounteren {
1012
/// Supervisor "cycle\[h\]" Enable
1113
#[inline]
1214
pub fn cy(&self) -> bool {
13-
self.bits & (1 << 0) != 0
15+
bf_extract(self.bits, 0, 1) != 0
1416
}
1517

1618
/// Supervisor "time\[h\]" Enable
1719
#[inline]
1820
pub fn tm(&self) -> bool {
19-
self.bits & (1 << 1) != 0
21+
bf_extract(self.bits, 1, 1) != 0
2022
}
2123

2224
/// Supervisor "instret\[h\]" Enable
2325
#[inline]
2426
pub fn ir(&self) -> bool {
25-
self.bits & (1 << 2) != 0
27+
bf_extract(self.bits, 2, 1) != 0
2628
}
2729

2830
/// Supervisor "hpm\[x\]" Enable (bits 3-31)
2931
#[inline]
3032
pub fn hpm(&self, index: usize) -> bool {
3133
assert!((3..32).contains(&index));
32-
self.bits & (1 << index) != 0
34+
bf_extract(self.bits, index, 1) != 0
3335
}
3436
}
3537

0 commit comments

Comments
 (0)