File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
21
21
- Use CSR helper macros to define ` mcounteren ` register
22
22
- Use CSR helper macros to define ` mie ` register
23
23
- Use CSR helper macros to define ` mimpid ` register
24
+ - Use CSR helper macros to define ` misa ` register
24
25
25
26
## [ v0.12.1] - 2024-10-20
26
27
Original file line number Diff line number Diff line change @@ -65,3 +65,35 @@ impl Misa {
65
65
const fn ext_char_to_bit ( extension : char ) -> u8 {
66
66
( extension as u8 ) . saturating_sub ( b'A' )
67
67
}
68
+
69
+ #[ cfg( test) ]
70
+ mod tests {
71
+ use super :: * ;
72
+ use crate :: result:: Error ;
73
+
74
+ #[ test]
75
+ fn test_misa ( ) {
76
+ ( 1 ..=3 )
77
+ . zip ( [ XLEN :: XLEN32 , XLEN :: XLEN64 , XLEN :: XLEN128 ] )
78
+ . for_each ( |( raw, exp_xlen) | {
79
+ assert_eq ! ( XLEN :: try_from( raw) , Ok ( exp_xlen) ) ;
80
+ assert_eq ! ( usize :: from( exp_xlen) , raw) ;
81
+
82
+ let misa = Misa :: from_bits ( raw << ( usize:: BITS - 2 ) ) ;
83
+ assert_eq ! ( misa. try_mxl( ) , Ok ( exp_xlen) ) ;
84
+ assert_eq ! ( misa. mxl( ) , exp_xlen) ;
85
+ } ) ;
86
+
87
+ ( 0 ..62 ) . map ( |b| 1 << b) . for_each ( |invalid_mxl| {
88
+ assert_eq ! (
89
+ Misa :: from_bits( invalid_mxl) . try_mxl( ) ,
90
+ Err ( Error :: InvalidVariant ( 0 ) )
91
+ ) ;
92
+ } ) ;
93
+
94
+ ( 'A' ..='Z' ) . for_each ( |ext| {
95
+ assert ! ( !Misa :: from_bits( 0 ) . has_extension( ext) ) ;
96
+ assert ! ( Misa :: from_bits( 1 << ext_char_to_bit( ext) ) . has_extension( ext) ) ;
97
+ } ) ;
98
+ }
99
+ }
You can’t perform that action at this time.
0 commit comments