1
- use crate :: instruction:: { Format , Instruction , operation, RegisterCode , SegmentCode } ;
1
+ use crate :: instruction:: { Format , Instruction , operation, RegisterCode , SegmentCode , vector} ;
2
+ use crate :: num:: MaskedU32 ;
2
3
3
4
pub const OPERATION_MASK : u32 = 0x0000007F ;
4
5
5
- pub const LOAD_IMMEDIATE_DESTINATION : u32 = 0b00000000_00000000_00000000_00001111 ;
6
- pub const LOAD_IMMEDIATE_SEGMENT : ( u32 , u32 ) = ( 4 , 0b00000000_00000000_00000000_00110000 ) ;
7
- pub const LOAD_IMMEDIATE_IMMEDIATE : ( u32 , u32 ) = ( 6 , 0b00000000_00111111_11111111_11000000 ) ;
6
+ pub const LOAD_IMMEDIATE_DESTINATION : u32 = 0b0_00000000_00000000_00001111 ;
7
+ pub const LOAD_IMMEDIATE_SEGMENT : ( u32 , u32 ) = ( 4 , 0b0_00000000_00000000_00110000 ) ;
8
+ pub const LOAD_IMMEDIATE_IMMEDIATE : ( u32 , u32 ) = ( 6 , 0b0_00111111_11111111_11000000 ) ;
9
+ pub const LOAD_VECTOR_DESTINATION : u32 = 0b0_00000000_00000000_00001111 ;
10
+ pub const LOAD_VECTOR_COMPONENT_ENABLE_0 : ( u32 , u32 ) = ( 4 , 0b0_00000000_00000000_00010000 ) ;
11
+ pub const LOAD_VECTOR_COMPONENT_ENABLE_1 : ( u32 , u32 ) = ( 5 , 0b0_00000000_00000000_00100000 ) ;
12
+ pub const LOAD_VECTOR_COMPONENT_ENABLE_2 : ( u32 , u32 ) = ( 6 , 0b0_00000000_00000000_01000000 ) ;
13
+ pub const LOAD_VECTOR_COMPONENT_ENABLE_3 : ( u32 , u32 ) = ( 7 , 0b0_00000000_00000000_10000000 ) ;
14
+ pub const LOAD_VECTOR_COMPONENT_0 : ( u32 , u32 ) = ( 8 , 0b0_00000000_00001111_00000000 ) ;
15
+ pub const LOAD_VECTOR_COMPONENT_1 : ( u32 , u32 ) = ( 12 , 0b0_00000000_11110000_00000000 ) ;
16
+ pub const LOAD_VECTOR_COMPONENT_2 : ( u32 , u32 ) = ( 16 , 0b0_00001111_00000000_00000000 ) ;
17
+ pub const LOAD_VECTOR_COMPONENT_3 : ( u32 , u32 ) = ( 20 , 0b0_11110000_00000000_00000000 ) ;
18
+
19
+ pub type EncodedOperands = MaskedU32 < 0x1FFFFFF > ;
8
20
9
21
impl Instruction {
10
- const fn decode_load_immediate ( operands : u32 ) -> ( RegisterCode , SegmentCode , u16 ) {
22
+ const fn decode_load_immediate ( operands : EncodedOperands ) -> ( RegisterCode , SegmentCode , u16 ) {
23
+ let operands = operands. get ( ) ;
11
24
let destination = RegisterCode :: new ( ( operands & LOAD_IMMEDIATE_DESTINATION ) as u8 ) ;
12
25
let segment = SegmentCode :: new ( ( ( operands & LOAD_IMMEDIATE_SEGMENT . 1 ) >> LOAD_IMMEDIATE_SEGMENT . 0 ) as u8 ) ;
13
26
let immediate = ( ( operands & LOAD_IMMEDIATE_IMMEDIATE . 1 ) >> LOAD_IMMEDIATE_IMMEDIATE . 0 ) as u16 ;
14
27
( destination, segment, immediate)
15
28
}
16
-
29
+
30
+ fn decode_load_vector ( operands : EncodedOperands ) -> ( RegisterCode , [ Option < vector:: ComponentCode > ; vector:: SIZE ] ) {
31
+ let operands = operands. get ( ) ;
32
+ let destination = RegisterCode :: new ( ( operands & LOAD_VECTOR_DESTINATION ) as u8 ) ;
33
+
34
+ let enable_0 = ( ( operands & LOAD_VECTOR_COMPONENT_ENABLE_0 . 1 ) >> LOAD_VECTOR_COMPONENT_ENABLE_0 . 0 ) > 0 ;
35
+ let enable_1 = ( ( operands & LOAD_VECTOR_COMPONENT_ENABLE_1 . 1 ) >> LOAD_VECTOR_COMPONENT_ENABLE_1 . 0 ) > 0 ;
36
+ let enable_2 = ( ( operands & LOAD_VECTOR_COMPONENT_ENABLE_2 . 1 ) >> LOAD_VECTOR_COMPONENT_ENABLE_2 . 0 ) > 0 ;
37
+ let enable_3 = ( ( operands & LOAD_VECTOR_COMPONENT_ENABLE_3 . 1 ) >> LOAD_VECTOR_COMPONENT_ENABLE_3 . 0 ) > 0 ;
38
+
39
+ let component_0 = vector:: ComponentCode :: new ( ( ( operands & LOAD_VECTOR_COMPONENT_0 . 1 ) >> LOAD_VECTOR_COMPONENT_0 . 0 ) as u8 ) ;
40
+ let component_1 = vector:: ComponentCode :: new ( ( ( operands & LOAD_VECTOR_COMPONENT_1 . 1 ) >> LOAD_VECTOR_COMPONENT_1 . 0 ) as u8 ) ;
41
+ let component_2 = vector:: ComponentCode :: new ( ( ( operands & LOAD_VECTOR_COMPONENT_2 . 1 ) >> LOAD_VECTOR_COMPONENT_2 . 0 ) as u8 ) ;
42
+ let component_3 = vector:: ComponentCode :: new ( ( ( operands & LOAD_VECTOR_COMPONENT_3 . 1 ) >> LOAD_VECTOR_COMPONENT_3 . 0 ) as u8 ) ;
43
+
44
+ ( destination, [
45
+ enable_0. then_some ( component_0) ,
46
+ enable_1. then_some ( component_1) ,
47
+ enable_2. then_some ( component_2) ,
48
+ enable_3. then_some ( component_3)
49
+ ] )
50
+ }
51
+
17
52
pub fn decode ( encoded : u32 ) -> Self {
18
53
let operation = encoded & OPERATION_MASK ;
19
54
@@ -22,15 +57,18 @@ impl Instruction {
22
57
. unwrap_or ( & operation:: MAPPINGS [ 0 ] )
23
58
. format ;
24
59
25
- let operands = ( encoded & !OPERATION_MASK ) >> 7 ;
60
+ let operands = EncodedOperands :: new ( ( encoded & !OPERATION_MASK ) >> 7 ) ;
26
61
27
62
match format {
28
63
Format :: WaitForInterrupt => Self :: WaitForInterrupt ,
29
64
Format :: LoadImmediate => {
30
65
let ( destination, segment, immediate) = Self :: decode_load_immediate ( operands) ;
31
66
Self :: LoadImmediate { destination, segment, immediate }
32
67
} ,
33
- Format :: LoadVectorComponents => todo ! ( ) ,
68
+ Format :: LoadVectorComponents => {
69
+ let ( destination, components) = Self :: decode_load_vector ( operands) ;
70
+ Self :: LoadVectorComponents { destination, components}
71
+ } ,
34
72
Format :: ExtractVectorComponents => todo ! ( ) ,
35
73
Format :: FlagVectorComponents => todo ! ( ) ,
36
74
Format :: MapVector => todo ! ( ) ,
0 commit comments