1
- pub mod branch;
2
- pub mod memory;
3
- pub mod register;
4
- pub mod flag;
1
+ pub mod operation;
5
2
6
- use crate :: num;
7
- use flag:: Flag ;
8
- use register:: Register ;
3
+ use crate :: num:: { MaskedU16 , MaskedU32 , MaskedU8 } ;
4
+
5
+ pub type SegmentCode = MaskedU8 < 0x3 >
6
+ pub type RegisterCode = MaskedU8 < 0xF > ;
7
+ pub type FlagCode = MaskedU8 < 0x07 > ;
8
+ pub type BranchHintCode = MaskedU8 < 0x3 > ;
9
+ pub type OperandCode = MaskedU8 < 0x3 > ;
10
+ pub type VectorComponentCode = MaskedU8 < 0x3 > ;
11
+ pub const VECTOR_SIZE : usize = 4 ;
9
12
10
13
#[ derive( Debug , Clone , Copy , PartialEq ) ]
11
- pub enum RegisterOperation {
12
- ReleaseMemory
14
+ pub struct VectorComponentMapping {
15
+ operand : OperandCode ,
16
+ components : [ VectorComponentCode ; 2 ]
13
17
}
14
18
15
19
#[ derive( Debug , Clone , Copy , PartialEq ) ]
16
- pub enum SizedRegisterOperation {
17
-
20
+ pub struct VectorComponentFlags {
21
+ operand : OperandCode ,
22
+ negate : bool ,
23
+ zero : bool
18
24
}
19
25
26
+ pub type AddressImmediate = MaskedU32 < 0x1FFFF > ;
27
+ pub type ScaleCode = MaskedU8 < 0x3 > ;
28
+
20
29
#[ derive( Debug , Clone , Copy , PartialEq ) ]
21
- pub enum DualSizedRegisterOperation {
30
+ pub enum AddressMode {
31
+ Absolute ,
32
+ Relative
33
+ }
34
+
35
+ pub type BaseOffset = MaskedU16 < 0x1FFF > ;
36
+ pub type IndexedBaseOffset = MaskedU16 < 0x1FF > ;
22
37
38
+ #[ derive( Debug , Clone , Copy , PartialEq ) ]
39
+ pub enum IndexedBaseOffsetMode {
40
+ Immediate ( IndexedBaseOffset ) ,
41
+ Register ( RegisterCode )
23
42
}
24
43
25
44
#[ derive( Debug , Clone , Copy , PartialEq ) ]
26
- pub enum TriArithmetic { }
45
+ pub enum BaseMode {
46
+ Offset ( BaseOffset ) ,
47
+ RegisterOffset ( RegisterCode ) ,
48
+ Indexed {
49
+ index : RegisterCode ,
50
+ offset : IndexedBaseOffsetMode
51
+ }
52
+ }
27
53
28
54
#[ derive( Debug , Clone , Copy , PartialEq ) ]
29
- pub enum QuadArithmetic { }
55
+ pub enum Address {
56
+ Immediate {
57
+ immediate : AddressImmediate ,
58
+ mode : AddressMode
59
+ } ,
60
+ Register {
61
+ register : RegisterCode ,
62
+ mode : AddressMode
63
+ } ,
64
+ Base {
65
+ base : RegisterCode ,
66
+ mode : BaseMode
67
+ }
68
+ }
30
69
31
70
#[ derive( Debug , Clone , Copy , PartialEq ) ]
32
71
pub enum Instruction {
33
- Nothing ,
34
- WaitForInterrupt ,
35
- Register { operation : RegisterOperation , register : Register } ,
36
- SizedRegister {
37
- operation : SizedRegisterOperation ,
38
- size : num:: Size , register : Register } ,
39
- DualSizedRegister {
40
- operation : DualSizedRegisterOperation ,
41
- size : num:: Size , registers : [ Register ; 2 ] } ,
42
- TriArithmetic {
43
- operation : TriArithmetic ,
44
- vector : bool , size : num:: Size ,
45
- registers : [ Register ; 3 ] } ,
46
- QuadArithmetic {
47
- operation : QuadArithmetic ,
48
- vector : bool , size : num:: Size ,
49
- registers : [ Register ; 4 ] } ,
50
72
LoadImmediate {
51
- immediate : u16 ,
52
- segment : num:: MaskedU8 < 0x03 > } ,
53
- Branch {
54
- operation : branch:: Operation ,
55
- condition : Option < Flag > , hint : branch:: Hint ,
56
- address : branch:: Address } ,
73
+ segment : SegmentCode ,
74
+ immediate : u16
75
+ } ,
76
+ DualSource {
77
+ operation : operation:: DualSource ,
78
+ source : [ RegisterCode ; 2 ]
79
+ } ,
80
+ Destination {
81
+ operation : operation:: Destination ,
82
+ destination : RegisterCode
83
+ } ,
84
+ DestinationSource {
85
+ operation : operation:: DestinationSource ,
86
+ destination : RegisterCode ,
87
+ source : RegisterCode
88
+ } ,
89
+ DestinationDualSource {
90
+ operation : operation:: DestinationDualSource ,
91
+ destination : RegisterCode ,
92
+ sources : [ RegisterCode ; 2 ]
93
+ } ,
94
+ DestinationTripleSource {
95
+ operation : operation:: DestinationTripleSource ,
96
+ destination : RegisterCode ,
97
+ sources : [ RegisterCode ; 3 ]
98
+ } ,
99
+ DualDestinationDualSource {
100
+ operation : operation:: DualDestinationDualSource ,
101
+ destinations : [ RegisterCode ; 2 ] ,
102
+ sources : [ RegisterCode ; 2 ]
103
+ } ,
104
+ LoadVectorComponents {
105
+ destination : RegisterCode ,
106
+ /// Having [None] means that the component corresponding to the index should be 0.
107
+ components : [ Option < VectorComponentCode > ; VECTOR_SIZE ]
108
+ } ,
109
+ ExtractVectorComponents {
110
+ vector : RegisterCode ,
111
+ /// Having [None] means that the component corresponding to the index should not be extracted into a register.
112
+ components : [ Option < RegisterCode > ; VECTOR_SIZE ]
113
+ } ,
114
+ FlagVectorComponents {
115
+ flags : [ VectorComponentFlags ; VECTOR_SIZE ] ,
116
+ temporary : bool
117
+ } ,
118
+ /// Only supports 2 operands due to the size constrain of an instruction.
119
+ MapVector {
120
+ mappings : [ VectorComponentMapping ; 2 ] ,
121
+ temporary : bool
122
+ } ,
57
123
Memory {
58
- operation : memory:: Operation ,
59
- size : num:: Size , register : Register ,
60
- address : memory:: Address } ,
61
- LoadVector {
62
- vector : Register ,
63
- components : [ Option < Register > ; 4 ] ,
64
- persist : bool } ,
65
- ReorderVector {
66
- vector : Register ,
67
- components : [ num:: MaskedU8 < 0x03 > ; 4 ] ,
68
- persist : bool } ,
69
- SplitVector {
70
- vector : Register ,
71
- components : [ Option < Register > ; 4 ] }
72
- }
124
+ operation : operation:: Memory ,
125
+ address : Address
126
+ } ,
127
+ SourceMemory {
128
+ operation : operation:: SourceMemory ,
129
+ destination : RegisterCode ,
130
+ source : Address
131
+ } ,
132
+ DestinationMemory {
133
+ operation : operation:: DestinationMemory ,
134
+ destination : Address ,
135
+ source : RegisterCode
136
+ } ,
137
+ Branch {
138
+ condition : FlagCode ,
139
+ hint : Option < bool > ,
140
+ address : Address
141
+ }
142
+ }
0 commit comments