File tree 1 file changed +27
-6
lines changed
1 file changed +27
-6
lines changed Original file line number Diff line number Diff line change 1
1
//! Utility macros.
2
2
3
- // Helper struct used to trigger const eval errors when a const generic immediate value is
4
- // out of range.
5
- pub ( crate ) struct ValidateConstImm8 < const imm8 : i32 > ( ) ;
6
- impl < const imm8 : i32 > ValidateConstImm8 < imm8 > {
3
+ // Helper struct used to trigger const eval errors when the const generic immediate value `imm` is
4
+ // out of `bits`-bit range.
5
+ pub ( crate ) struct ValidateConstImm < const imm : i32 , const bits : i32 > ;
6
+ impl < const imm : i32 , const bits : i32 > ValidateConstImm < imm , bits > {
7
7
pub ( crate ) const VALID : ( ) = {
8
- let _ = 1 / ( ( imm8 >= 0 && imm8 <= 255 ) as usize ) ;
8
+ let _ = 1 / ( ( imm >= 0 && imm < ( 1 << bits) ) as usize ) ;
9
+ } ;
10
+ }
11
+
12
+ #[ allow( unused) ]
13
+ macro_rules! static_assert_imm2 {
14
+ ( $imm: ident) => {
15
+ let _ = $crate:: core_arch:: macros:: ValidateConstImm :: <$imm, 2 >:: VALID ;
16
+ } ;
17
+ }
18
+
19
+ #[ allow( unused) ]
20
+ macro_rules! static_assert_imm3 {
21
+ ( $imm: ident) => {
22
+ let _ = $crate:: core_arch:: macros:: ValidateConstImm :: <$imm, 3 >:: VALID ;
23
+ } ;
24
+ }
25
+
26
+ #[ allow( unused) ]
27
+ macro_rules! static_assert_imm4 {
28
+ ( $imm: ident) => {
29
+ let _ = $crate:: core_arch:: macros:: ValidateConstImm :: <$imm, 4 >:: VALID ;
9
30
} ;
10
31
}
11
32
12
33
#[ allow( unused) ]
13
34
macro_rules! static_assert_imm8 {
14
35
( $imm: ident) => {
15
- let _ = $crate:: core_arch:: macros:: ValidateConstImm8 :: <$imm>:: VALID ;
36
+ let _ = $crate:: core_arch:: macros:: ValidateConstImm :: <$imm, 8 >:: VALID ;
16
37
} ;
17
38
}
18
39
You can’t perform that action at this time.
0 commit comments