File tree Expand file tree Collapse file tree 6 files changed +15
-15
lines changed Expand file tree Collapse file tree 6 files changed +15
-15
lines changed Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ impl Mcounteren {
30
30
/// Supervisor "hpm\[x\]" Enable (bits 3-31)
31
31
#[ inline]
32
32
pub fn hpm ( & self , index : usize ) -> bool {
33
- assert ! ( 3 <= index && index < 32 ) ;
33
+ assert ! ( ( 3 .. 32 ) . contains ( & index) ) ;
34
34
self . bits . get_bit ( index)
35
35
}
36
36
}
@@ -54,12 +54,12 @@ set_clear_csr!(
54
54
55
55
#[ inline]
56
56
pub unsafe fn set_hpm ( index : usize ) {
57
- assert ! ( 3 <= index && index < 32 ) ;
57
+ assert ! ( ( 3 .. 32 ) . contains ( & index) ) ;
58
58
_set ( 1 << index) ;
59
59
}
60
60
61
61
#[ inline]
62
62
pub unsafe fn clear_hpm ( index : usize ) {
63
- assert ! ( 3 <= index && index < 32 ) ;
63
+ assert ! ( ( 3 .. 32 ) . contains ( & index) ) ;
64
64
_clear ( 1 << index) ;
65
65
}
Original file line number Diff line number Diff line change 8
8
// which would be the best way we implement this using Rust?
9
9
10
10
use bit_field:: BitField ;
11
- use core :: mem :: size_of ;
11
+
12
12
13
13
/// mstatus register
14
14
#[ derive( Clone , Copy , Debug ) ]
@@ -205,7 +205,7 @@ impl Mstatus {
205
205
/// signals the presence of some dirty state
206
206
#[ inline]
207
207
pub fn sd ( & self ) -> bool {
208
- self . bits . get_bit ( size_of :: < usize > ( ) * 8 - 1 )
208
+ self . bits . get_bit ( usize :: BITS as usize - 1 )
209
209
}
210
210
}
211
211
Original file line number Diff line number Diff line change @@ -72,7 +72,7 @@ impl Pmpcsr {
72
72
3 => Range :: NAPOT ,
73
73
_ => unreachable ! ( ) ,
74
74
} ,
75
- locked : byte. get_bit ( 7 ) as bool ,
75
+ locked : byte. get_bit ( 7 ) ,
76
76
}
77
77
}
78
78
}
Original file line number Diff line number Diff line change 1
1
//! scause register
2
2
3
3
use bit_field:: BitField ;
4
- use core :: mem :: size_of ;
4
+
5
5
6
6
/// scause register
7
7
#[ derive( Clone , Copy ) ]
@@ -90,7 +90,7 @@ impl Scause {
90
90
/// Returns the code field
91
91
#[ inline]
92
92
pub fn code ( & self ) -> usize {
93
- let bit = 1 << ( size_of :: < usize > ( ) * 8 - 1 ) ;
93
+ let bit = 1 << ( usize :: BITS as usize - 1 ) ;
94
94
self . bits & !bit
95
95
}
96
96
@@ -107,7 +107,7 @@ impl Scause {
107
107
/// Is trap cause an interrupt.
108
108
#[ inline]
109
109
pub fn is_interrupt ( & self ) -> bool {
110
- self . bits . get_bit ( size_of :: < usize > ( ) * 8 - 1 )
110
+ self . bits . get_bit ( usize :: BITS as usize - 1 )
111
111
}
112
112
113
113
/// Is trap cause an exception.
@@ -139,7 +139,7 @@ pub unsafe fn set(cause: Trap) {
139
139
Interrupt :: UserExternal => 8 ,
140
140
Interrupt :: SupervisorExternal => 9 ,
141
141
Interrupt :: Unknown => panic ! ( "unknown interrupt" ) ,
142
- } | ( 1 << ( size_of :: < usize > ( ) * 8 - 1 ) ) )
142
+ } | ( 1 << ( usize :: BITS as usize - 1 ) ) )
143
143
} // interrupt bit is 1
144
144
Trap :: Exception ( e) => match e {
145
145
Exception :: InstructionMisaligned => 0 ,
Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ impl Scounteren {
30
30
/// User "hpm\[x\]" Enable (bits 3-31)
31
31
#[ inline]
32
32
pub fn hpm ( & self , index : usize ) -> bool {
33
- assert ! ( 3 <= index && index < 32 ) ;
33
+ assert ! ( ( 3 .. 32 ) . contains ( & index) ) ;
34
34
self . bits . get_bit ( index)
35
35
}
36
36
}
@@ -54,12 +54,12 @@ set_clear_csr!(
54
54
55
55
#[ inline]
56
56
pub unsafe fn set_hpm ( index : usize ) {
57
- assert ! ( 3 <= index && index < 32 ) ;
57
+ assert ! ( ( 3 .. 32 ) . contains ( & index) ) ;
58
58
_set ( 1 << index) ;
59
59
}
60
60
61
61
#[ inline]
62
62
pub unsafe fn clear_hpm ( index : usize ) {
63
- assert ! ( 3 <= index && index < 32 ) ;
63
+ assert ! ( ( 3 .. 32 ) . contains ( & index) ) ;
64
64
_clear ( 1 << index) ;
65
65
}
Original file line number Diff line number Diff line change 2
2
3
3
pub use super :: mstatus:: FS ;
4
4
use bit_field:: BitField ;
5
- use core :: mem :: size_of ;
5
+
6
6
7
7
/// Supervisor Status Register
8
8
#[ derive( Clone , Copy , Debug ) ]
@@ -92,7 +92,7 @@ impl Sstatus {
92
92
/// signals the presence of some dirty state
93
93
#[ inline]
94
94
pub fn sd ( & self ) -> bool {
95
- self . bits . get_bit ( size_of :: < usize > ( ) * 8 - 1 )
95
+ self . bits . get_bit ( usize :: BITS as usize - 1 )
96
96
}
97
97
}
98
98
You can’t perform that action at this time.
0 commit comments