1
+ use proc_bitfield:: { bitfield, ConvRaw } ;
1
2
use crate :: num:: MaskedU8 ;
2
3
3
- pub mod address;
4
- pub mod vector;
5
- pub mod branch;
6
- pub mod encoding;
7
- pub mod register;
8
- pub mod arithmetic;
9
4
pub mod load_immediate;
5
+ pub mod memory;
6
+ pub mod mnemonic;
7
+ pub mod vector;
10
8
11
- pub type SegmentCode = MaskedU8 < 0x3 > ;
12
- pub type ScaleCode = MaskedU8 < 0x03 > ;
13
-
14
- pub const STACK_SOURCE_MASK : ( u8 , u32 ) = ( 0 , 0b0000000000000000000000011111 ) ;
15
- pub const UNSTACK_DEST_MASK : ( u8 , u32 ) = ( 0 , 0b0000000000000000000000011111 ) ;
16
-
17
- pub const LOAD_IMMEDIATE_DESTINATION_MASK : ( u8 , u32 ) = ( 0 , 0b0000000000000000000000011111 ) ;
18
- pub const LOAD_IMMEDIATE_SEGMENT_MASK : ( u8 , u32 ) = ( 5 , 0b0000000000000000000001100000 ) ;
19
- pub const LOAD_IMMEDIATE_OFFSET_MASK : ( u8 , u32 ) = ( 7 , 0b1111111111111111111110000000 ) ;
20
-
21
- pub const BUILD_VECTOR_DESTINATION_MASK : ( u8 , u32 ) = ( 0 , 0b0000000000000000000000011111 ) ;
22
- pub const BUILD_VECTOR_COMPONENT_0_MASK : ( u8 , u32 ) = ( 5 , 0b0000000000000000001111100000 ) ;
23
- pub const BUILD_VECTOR_COMPONENT_1_MASK : ( u8 , u32 ) = ( 10 , 0b0000000000000111110000000000 ) ;
24
- pub const BUILD_VECTOR_COMPONENT_2_MASK : ( u8 , u32 ) = ( 15 , 0b0000000011111000000000000000 ) ;
25
- pub const BUILD_VECTOR_COMPONENT_3_MASK : ( u8 , u32 ) = ( 20 , 0b0001111100000000000000000000 ) ;
26
-
27
- pub const UNBUILD_VECTOR_SOURCE_MASK : ( u8 , u32 ) = ( 0 , 0b0000000000000000000000011111 ) ;
28
- pub const UNBUILD_VECTOR_DESTINATION_0_MASK : ( u8 , u32 ) = ( 5 , 0b0000000000000000001111100000 ) ;
29
- pub const UNBUILD_VECTOR_DESTINATION_1_MASK : ( u8 , u32 ) = ( 10 , 0b0000000000000111110000000000 ) ;
30
- pub const UNBUILD_VECTOR_DESTINATION_2_MASK : ( u8 , u32 ) = ( 15 , 0b0000000011111000000000000000 ) ;
31
- pub const UNBUILD_VECTOR_DESTINATION_3_MASK : ( u8 , u32 ) = ( 20 , 0b0001111100000000000000000000 ) ;
9
+ bitfield ! {
10
+ /// A bitfield showcasing how to specify bit ranges.
11
+ #[ derive( Clone , Copy , PartialEq , Eq ) ]
12
+ struct Format ( pub u32 ) : Debug , FromRaw , IntoRaw { operation: u8 @ 0 ..=4 }
13
+ }
32
14
33
- pub const COPY_REGISTER_DESTINATION_FILE_MASK : ( u8 , u32 ) = ( 0 , 0b0000000000000000000000000011 ) ;
34
- pub const COPY_REGISTER_DESTINATION_MASK : ( u8 , u32 ) = ( 0 , 0b0000000000000000000001111100 ) ;
35
- pub const COPY_REGISTER_SOURCE_FILE_MASK : ( u8 , u32 ) = ( 0 , 0b0000000000000000000110000000 ) ;
36
- pub const COPY_REGISTER_SOURCE_MASK : ( u8 , u32 ) = ( 0 , 0b0000000000000011111000000000 ) ;
15
+ #[ derive( Debug , Clone , Copy , PartialEq , ConvRaw ) ]
16
+ pub enum Scale { X8 , X16 , X32 , X64 }
37
17
38
18
#[ derive( Debug , Clone , Copy , PartialEq ) ]
19
+ #[ repr( u8 ) ]
39
20
pub enum Instruction {
40
- None ,
41
- Wait ,
42
-
43
- End ,
44
- EndInterrupt ,
45
- Interrupt ,
46
-
47
- Stack { source : register:: Code } ,
48
- Unstack { destination : register:: Code } ,
49
-
50
- LoadImmediate {
51
- destination : register:: Code ,
52
- segment : load_immediate:: Segment
53
- } ,
54
- BuildVector {
55
- destination : register:: Code ,
56
- components : [ register:: Code ; vector:: SIZE ]
57
- } ,
58
- UnBuildVector {
59
- source : register:: Code ,
60
- destinations : [ register:: Code ; vector:: SIZE ]
61
- } ,
62
-
63
- CopyRegister {
64
- destination : register:: Code ,
65
- destination_file : register:: FileName ,
66
- source : register:: Code ,
67
- source_file : register:: FileName
68
- } ,
21
+ Mnemonic ( mnemonic:: Operation ) ,
22
+
23
+ LoadImmediate ( load_immediate:: Operation ) ,
24
+ BuildVector ( vector:: BuildVectorOperation ) ,
25
+ UnBuildVector ( vector:: UnBuildVectorOperation ) ,
69
26
70
- Arithmetic {
71
- operation : arithmetic:: Operation ,
72
- vector : bool ,
73
- atomic : bool ,
74
- destination : register:: Code ,
75
- sources : [ register:: Code ; 2 ]
76
- } ,
77
- Address {
78
- operation : address:: Operation ,
79
- data : address:: Meta ,
80
- offset : address:: LargeOffset
81
- } ,
82
- AddressWithBase {
83
- operation : address:: OperationWithBase ,
84
- data : address:: Meta ,
85
- base : register:: Code ,
86
- offset : address:: SmallOffset
87
- } ,
88
- Branch {
89
- operation : branch:: Operation ,
90
- data : branch:: Meta ,
91
- offset : branch:: LargeOffset
92
- } ,
93
- BranchWithBase {
94
- operation : branch:: OperationWithBase ,
95
- data : branch:: Meta ,
96
- base : register:: Code ,
97
- offset : branch:: SmallOffset
98
- } ,
27
+ ReadMemory ( memory:: ReadOperation ) ,
28
+ WriteMemory ( memory:: WriteOperation ) ,
29
+ Stack ( memory:: StackOperation ) ,
30
+ UnStack ( memory:: UnStackOperation ) ,
31
+ Lock ( memory:: LockOperation ) ,
32
+ Branch ( memory:: BranchOperation ) ,
99
33
100
- Timer ,
34
+ Copy ,
101
35
102
- Lock ,
103
- UnLock ,
36
+ Unary ,
37
+ Negate ,
38
+ SignExtend ,
39
+ Binary ,
40
+ RegroupingBinary ,
41
+ RegroupingQuaternary
42
+ }
43
+
44
+ impl Instruction {
45
+ pub const MNEMONIC_CODE : u8 = 0 ;
46
+ pub const LOAD_IMMEDIATE_CODE : u8 = 1 ;
47
+ pub const BUILD_VECTOR_CODE : u8 = 2 ;
48
+ pub const UNBUILD_VECTOR_CODE : u8 = 3 ;
49
+ pub const READ_MEMORY_CODE : u8 = 4 ;
50
+ pub const WRITE_MEMORY_CODE : u8 = 5 ;
51
+ pub const STACK_CODE : u8 = 6 ;
52
+ pub const UNSTACK_CODE : u8 = 7 ;
53
+ pub const LOCK_CODE : u8 = 8 ;
54
+ pub const BRANCH_CODE : u8 = 9 ;
104
55
105
- Free2 ,
106
- Free3 ,
107
- Free4
56
+ pub fn decode ( encoded : u32 ) -> Self {
57
+ let operation = Format :: from ( encoded) ;
58
+ match operation. operation ( ) {
59
+ Self :: MNEMONIC_CODE => Self :: Mnemonic ( mnemonic:: Format :: from ( encoded) . operation ( ) ) ,
60
+ Self :: LOAD_IMMEDIATE_CODE => Self :: LoadImmediate ( load_immediate:: Operation :: from ( encoded) ) ,
61
+ Self :: BUILD_VECTOR_CODE => Self :: BuildVector ( vector:: BuildVectorOperation :: from ( encoded) ) ,
62
+ Self :: UNBUILD_VECTOR_CODE => Self :: UnBuildVector ( vector:: UnBuildVectorOperation :: from ( encoded) ) ,
63
+ Self :: READ_MEMORY_CODE => Self :: ReadMemory ( memory:: ReadOperation :: from ( encoded) ) ,
64
+ Self :: WRITE_MEMORY_CODE => Self :: WriteMemory ( memory:: WriteOperation :: from ( encoded) ) ,
65
+ Self :: STACK_CODE => Self :: Stack ( memory:: StackOperation :: from ( encoded) ) ,
66
+ Self :: UNSTACK_CODE => Self :: UnStack ( memory:: UnStackOperation :: from ( encoded) ) ,
67
+ Self :: LOCK_CODE => Self :: Lock ( memory:: LockOperation :: from ( encoded) ) ,
68
+ Self :: BRANCH_CODE => Self :: Branch ( memory:: BranchOperation :: from ( encoded) ) ,
69
+
70
+ _ => unimplemented ! ( )
71
+ }
72
+ }
73
+ }
74
+
75
+ impl Default for Instruction {
76
+ fn default ( ) -> Self {
77
+ Self :: Mnemonic ( mnemonic:: Operation :: default ( ) )
78
+ }
108
79
}
0 commit comments