1
- use proc_bitfield:: { bitfield, ConvRaw } ;
1
+ use proc_bitfield:: { bitfield} ;
2
2
3
- #[ derive( Debug , Clone , Copy , PartialEq , Default , ConvRaw ) ]
3
+ #[ derive( Debug , Clone , Copy , PartialEq , Default ) ]
4
4
#[ repr( u8 ) ]
5
5
pub enum Mode {
6
6
#[ default]
@@ -18,6 +18,32 @@ pub enum Mode {
18
18
ShiftRight
19
19
}
20
20
21
+ impl From < u8 > for Mode {
22
+ fn from ( code : u8 ) -> Self {
23
+ match code {
24
+ 0 => Self :: And ,
25
+ 1 => Self :: Nand ,
26
+ 2 => Self :: Or ,
27
+ 3 => Self :: Nor ,
28
+ 4 => Self :: Xor ,
29
+ 5 => Self :: XNor ,
30
+ 6 => Self :: Add ,
31
+ 7 => Self :: Subtract ,
32
+ 8 => Self :: Multiply ,
33
+ 9 => Self :: Divide ,
34
+ 10 => Self :: ShiftLeft ,
35
+ 11 => Self :: ShiftRight ,
36
+ _ => Self :: default ( )
37
+ }
38
+ }
39
+ }
40
+
41
+ impl From < Mode > for u8 {
42
+ fn from ( mode : Mode ) -> Self {
43
+ mode as Self
44
+ }
45
+ }
46
+
21
47
bitfield ! {
22
48
#[ derive( Clone , Copy , PartialEq , Eq ) ]
23
49
pub struct Operation ( pub u32 ) : Debug , FromRaw , IntoRaw {
@@ -33,13 +59,29 @@ bitfield! {
33
59
}
34
60
}
35
61
36
- #[ derive( Debug , Clone , Copy , PartialEq , ConvRaw ) ]
62
+ #[ derive( Debug , Clone , Copy , PartialEq , Default ) ]
37
63
#[ repr( u8 ) ]
38
64
pub enum RegroupingBinaryMode {
65
+ #[ default]
39
66
Add ,
40
67
Subtract
41
68
}
42
69
70
+ impl From < bool > for RegroupingBinaryMode {
71
+ fn from ( flag : bool ) -> Self {
72
+ match flag {
73
+ false => Self :: Add ,
74
+ true => Self :: Subtract ,
75
+ }
76
+ }
77
+ }
78
+
79
+ impl From < RegroupingBinaryMode > for bool {
80
+ fn from ( mode : RegroupingBinaryMode ) -> Self {
81
+ mode as u8 != 0
82
+ }
83
+ }
84
+
43
85
bitfield ! {
44
86
#[ derive( Clone , Copy , PartialEq , Eq ) ]
45
87
pub struct RegroupingBinaryOperation ( pub u32 ) : Debug , FromRaw , IntoRaw {
@@ -51,13 +93,29 @@ bitfield! {
51
93
}
52
94
}
53
95
54
- #[ derive( Debug , Clone , Copy , PartialEq , ConvRaw ) ]
96
+ #[ derive( Debug , Clone , Copy , PartialEq , Default ) ]
55
97
#[ repr( u8 ) ]
56
98
pub enum RegroupingQuaternaryMode {
99
+ #[ default]
57
100
Multiply ,
58
101
Divide
59
102
}
60
103
104
+ impl From < bool > for RegroupingQuaternaryMode {
105
+ fn from ( flag : bool ) -> Self {
106
+ match flag {
107
+ false => Self :: Multiply ,
108
+ true => Self :: Divide ,
109
+ }
110
+ }
111
+ }
112
+
113
+ impl From < RegroupingQuaternaryMode > for bool {
114
+ fn from ( mode : RegroupingQuaternaryMode ) -> Self {
115
+ mode as u8 != 0
116
+ }
117
+ }
118
+
61
119
bitfield ! {
62
120
#[ derive( Clone , Copy , PartialEq , Eq ) ]
63
121
pub struct RegroupingQuaternaryOperation ( pub u32 ) : Debug , FromRaw , IntoRaw {
0 commit comments