1
- use crate :: instruction:: { Format , Instruction , operation, RegisterCode , SegmentCode , vector} ;
1
+ use crate :: instruction:: { Format , Instruction , OperandCode , operation, RegisterCode , SegmentCode , vector} ;
2
+ use crate :: instruction:: vector:: ComponentCode ;
2
3
use crate :: num:: MaskedU32 ;
3
4
4
5
pub const OPERATION_MASK : u32 = 0x0000007F ;
@@ -7,58 +8,69 @@ pub const LOAD_IMMEDIATE_DESTINATION_FIELD : u32 = 0b0_00000000
7
8
pub const LOAD_IMMEDIATE_SEGMENT_FIELD : ( u32 , u32 ) = ( 4 , 0b0_00000000_00000000_00110000 ) ;
8
9
pub const LOAD_IMMEDIATE_IMMEDIATE_FIELD : ( u32 , u32 ) = ( 6 , 0b0_00111111_11111111_11000000 ) ;
9
10
pub const DECODE_VECTOR_DESTINATION_FIELD : u32 = 0b0_00000000_00000000_00001111 ;
10
- pub const DECODE_VECTOR_COMPONENT_ENABLE_0_FIELD : ( u32 , u32 ) = ( 4 , 0b0_00000000_00000000_00010000 ) ;
11
- pub const DECODE_VECTOR_COMPONENT_ENABLE_1_FIELD : ( u32 , u32 ) = ( 5 , 0b0_00000000_00000000_00100000 ) ;
12
- pub const DECODE_VECTOR_COMPONENT_ENABLE_2_FIELD : ( u32 , u32 ) = ( 6 , 0b0_00000000_00000000_01000000 ) ;
13
- pub const DECODE_VECTOR_COMPONENT_ENABLE_3_FIELD : ( u32 , u32 ) = ( 7 , 0b0_00000000_00000000_10000000 ) ;
11
+ pub const ENABLE_0_FIELD : ( u32 , u32 ) = ( 4 , 0b0_00000000_00000000_00010000 ) ;
12
+ pub const ENABLE_1_FIELD : ( u32 , u32 ) = ( 5 , 0b0_00000000_00000000_00100000 ) ;
13
+ pub const ENABLE_2_FIELD : ( u32 , u32 ) = ( 6 , 0b0_00000000_00000000_01000000 ) ;
14
+ pub const ENABLE_3_FIELD : ( u32 , u32 ) = ( 7 , 0b0_00000000_00000000_10000000 ) ;
14
15
pub const DECODE_VECTOR_COMPONENT_0_FIELD : ( u32 , u32 ) = ( 8 , 0b0_00000000_00001111_00000000 ) ;
15
16
pub const DECODE_VECTOR_COMPONENT_1_FIELD : ( u32 , u32 ) = ( 12 , 0b0_00000000_11110000_00000000 ) ;
16
17
pub const DECODE_VECTOR_COMPONENT_2_FIELD : ( u32 , u32 ) = ( 16 , 0b0_00001111_00000000_00000000 ) ;
17
18
pub const DECODE_VECTOR_COMPONENT_3_FIELD : ( u32 , u32 ) = ( 20 , 0b0_11110000_00000000_00000000 ) ;
18
- pub const FLAG_VECTOR_TEMPORARY_FIELD : u32 = 0b0_00000000_00000000_00000001 ;
19
- pub const FLAG_VECTOR_OPERAND_0_FIELD : ( u32 , u32 ) = ( 1 , 0b0_00000000_00000000_00000110 ) ;
20
- pub const FLAG_VECTOR_OPERAND_1_FIELD : ( u32 , u32 ) = ( 3 , 0b0_00000000_00000000_00011000 ) ;
21
- pub const FLAG_VECTOR_OPERAND_2_FIELD : ( u32 , u32 ) = ( 5 , 0b0_00000000_00000000_01100000 ) ;
22
- pub const FLAG_VECTOR_OPERAND_3_FIELD : ( u32 , u32 ) = ( 7 , 0b0_00000000_00000001_10000000 ) ;
23
- pub const FLAG_VECTOR_OPERAND_0_NEGATE_FIELD : ( u32 , u32 ) = ( 9 , 0b0_00000000_00000010_00000000 ) ;
24
- pub const FLAG_VECTOR_OPERAND_1_NEGATE_FIELD : ( u32 , u32 ) = ( 10 , 0b0_00000000_00000100_00000000 ) ;
25
- pub const FLAG_VECTOR_OPERAND_2_NEGATE_FIELD : ( u32 , u32 ) = ( 11 , 0b0_00000000_00001000_00000000 ) ;
26
- pub const FLAG_VECTOR_OPERAND_3_NEGATE_FIELD : ( u32 , u32 ) = ( 12 , 0b0_00000000_00010000_00000000 ) ;
27
- pub const FLAG_VECTOR_OPERAND_0_ZERO_FIELD : ( u32 , u32 ) = ( 13 , 0b0_00000000_00100000_00000000 ) ;
28
- pub const FLAG_VECTOR_OPERAND_1_ZERO_FIELD : ( u32 , u32 ) = ( 14 , 0b0_00000000_01000000_00000000 ) ;
29
- pub const FLAG_VECTOR_OPERAND_2_ZERO_FIELD : ( u32 , u32 ) = ( 15 , 0b0_00000000_10000000_00000000 ) ;
30
- pub const FLAG_VECTOR_OPERAND_3_ZERO_FIELD : ( u32 , u32 ) = ( 16 , 0b0_00000001_00000000_00000000 ) ;
31
-
32
- pub type EncodedOperands = MaskedU32 < 0x1FFFFFF > ;
19
+ pub const MAP_VECTOR_TEMPORARY_FIELD : u32 = 0b0_00000000_00000000_00000001 ;
20
+ pub const MAP_VECTOR_OPERAND_FIELD : ( u32 , u32 ) = ( 1 , 0b0_00000000_00000000_00000110 ) ;
21
+ pub const MAP_VECTOR_COMPONENT_0_FIELD : ( u32 , u32 ) = ( 3 , 0b0_00000000_00000000_00011000 ) ;
22
+ pub const MAP_VECTOR_COMPONENT_1_FIELD : ( u32 , u32 ) = ( 5 , 0b0_00000000_00000000_01100000 ) ;
23
+ pub const MAP_VECTOR_COMPONENT_2_FIELD : ( u32 , u32 ) = ( 7 , 0b0_00000000_00000001_10000000 ) ;
24
+ pub const MAP_VECTOR_COMPONENT_3_FIELD : ( u32 , u32 ) = ( 9 , 0b0_00000000_00000110_00000000 ) ;
33
25
34
26
impl Instruction {
35
- const fn decode_load_immediate ( operands : EncodedOperands ) -> ( RegisterCode , SegmentCode , u16 ) {
36
- let operands = operands. get ( ) ;
27
+ const fn decode_load_immediate_instruction_operands ( operands : u32 ) -> ( RegisterCode , SegmentCode , u16 ) {
37
28
let destination = RegisterCode :: new ( ( operands & LOAD_IMMEDIATE_DESTINATION_FIELD ) as u8 ) ;
38
29
let segment = SegmentCode :: new ( ( ( operands & LOAD_IMMEDIATE_SEGMENT_FIELD . 1 ) >> LOAD_IMMEDIATE_SEGMENT_FIELD . 0 ) as u8 ) ;
39
30
let immediate = ( ( operands & LOAD_IMMEDIATE_IMMEDIATE_FIELD . 1 ) >> LOAD_IMMEDIATE_IMMEDIATE_FIELD . 0 ) as u16 ;
40
31
( destination, segment, immediate)
41
32
}
33
+
34
+ fn decode_enable_fields ( operands : u32 ) -> [ bool ; 4 ] {
35
+ let enable_0 = ( ( operands & ENABLE_0_FIELD . 1 ) >> ENABLE_0_FIELD . 0 ) > 0 ;
36
+ let enable_1 = ( ( operands & ENABLE_1_FIELD . 1 ) >> ENABLE_1_FIELD . 0 ) > 0 ;
37
+ let enable_2 = ( ( operands & ENABLE_2_FIELD . 1 ) >> ENABLE_2_FIELD . 0 ) > 0 ;
38
+ let enable_3 = ( ( operands & ENABLE_3_FIELD . 1 ) >> ENABLE_3_FIELD . 0 ) > 0 ;
39
+ [ enable_0, enable_1, enable_2, enable_3]
40
+ }
42
41
43
- fn decode_vector_components ( operands : EncodedOperands ) -> ( RegisterCode , [ Option < RegisterCode > ; vector:: SIZE ] ) {
44
- let operands = operands. get ( ) ;
42
+ fn decode_vector_components_instruction_operands ( operands : u32 ) -> ( RegisterCode , [ Option < RegisterCode > ; vector:: SIZE ] ) {
45
43
let primary = RegisterCode :: new ( ( operands & DECODE_VECTOR_DESTINATION_FIELD ) as u8 ) ;
46
44
47
- let enable_0 = ( ( operands & DECODE_VECTOR_COMPONENT_ENABLE_0_FIELD . 1 ) >> DECODE_VECTOR_COMPONENT_ENABLE_0_FIELD . 0 ) > 0 ;
48
- let enable_1 = ( ( operands & DECODE_VECTOR_COMPONENT_ENABLE_1_FIELD . 1 ) >> DECODE_VECTOR_COMPONENT_ENABLE_1_FIELD . 0 ) > 0 ;
49
- let enable_2 = ( ( operands & DECODE_VECTOR_COMPONENT_ENABLE_2_FIELD . 1 ) >> DECODE_VECTOR_COMPONENT_ENABLE_2_FIELD . 0 ) > 0 ;
50
- let enable_3 = ( ( operands & DECODE_VECTOR_COMPONENT_ENABLE_3_FIELD . 1 ) >> DECODE_VECTOR_COMPONENT_ENABLE_3_FIELD . 0 ) > 0 ;
51
-
52
45
let component_1 = RegisterCode :: new ( ( ( operands & DECODE_VECTOR_COMPONENT_1_FIELD . 1 ) >> DECODE_VECTOR_COMPONENT_1_FIELD . 0 ) as u8 ) ;
53
46
let component_2 = RegisterCode :: new ( ( ( operands & DECODE_VECTOR_COMPONENT_2_FIELD . 1 ) >> DECODE_VECTOR_COMPONENT_2_FIELD . 0 ) as u8 ) ;
54
47
let component_3 = RegisterCode :: new ( ( ( operands & DECODE_VECTOR_COMPONENT_3_FIELD . 1 ) >> DECODE_VECTOR_COMPONENT_3_FIELD . 0 ) as u8 ) ;
55
48
let component_0 = RegisterCode :: new ( ( ( operands & DECODE_VECTOR_COMPONENT_0_FIELD . 1 ) >> DECODE_VECTOR_COMPONENT_0_FIELD . 0 ) as u8 ) ;
56
49
50
+ let enable = Self :: decode_enable_fields ( operands) ;
51
+
57
52
( primary, [
58
- enable_0. then_some ( component_0) ,
59
- enable_1. then_some ( component_1) ,
60
- enable_2. then_some ( component_2) ,
61
- enable_3. then_some ( component_3)
53
+ enable[ 0 ] . then_some ( component_0) ,
54
+ enable[ 1 ] . then_some ( component_1) ,
55
+ enable[ 2 ] . then_some ( component_2) ,
56
+ enable[ 3 ] . then_some ( component_3)
57
+ ] )
58
+ }
59
+
60
+ fn decode_map_vector_instruction_operands ( operands : u32 ) -> ( bool , OperandCode , [ ComponentCode ; vector:: SIZE ] ) {
61
+ let temporary = operands & MAP_VECTOR_TEMPORARY_FIELD > 0 ;
62
+ let operand = OperandCode :: new ( ( ( operands & MAP_VECTOR_OPERAND_FIELD . 1 ) >> MAP_VECTOR_OPERAND_FIELD . 0 ) as u8 ) ;
63
+
64
+ let component_0 = ComponentCode :: new ( ( ( operands & MAP_VECTOR_COMPONENT_0_FIELD . 1 ) >> MAP_VECTOR_COMPONENT_0_FIELD . 0 ) as u8 ) ;
65
+ let component_1 = ComponentCode :: new ( ( ( operands & MAP_VECTOR_COMPONENT_1_FIELD . 1 ) >> MAP_VECTOR_COMPONENT_1_FIELD . 0 ) as u8 ) ;
66
+ let component_2 = ComponentCode :: new ( ( ( operands & MAP_VECTOR_COMPONENT_2_FIELD . 1 ) >> MAP_VECTOR_COMPONENT_2_FIELD . 0 ) as u8 ) ;
67
+ let component_3 = ComponentCode :: new ( ( ( operands & MAP_VECTOR_COMPONENT_3_FIELD . 1 ) >> MAP_VECTOR_COMPONENT_3_FIELD . 0 ) as u8 ) ;
68
+
69
+ ( temporary, operand, [
70
+ component_0,
71
+ component_1,
72
+ component_2,
73
+ component_3
62
74
] )
63
75
}
64
76
@@ -70,27 +82,26 @@ impl Instruction {
70
82
. unwrap_or ( & operation:: MAPPINGS [ 0 ] )
71
83
. format ;
72
84
73
- let operands = EncodedOperands :: new ( ( encoded & !OPERATION_MASK ) >> 7 ) ;
85
+ let operands = ( encoded & !OPERATION_MASK ) >> 7 ;
74
86
75
87
match format {
76
88
Format :: WaitForInterrupt => Self :: WaitForInterrupt ,
77
89
Format :: LoadImmediate => {
78
- let ( destination, segment, immediate) = Self :: decode_load_immediate ( operands) ;
90
+ let ( destination, segment, immediate) = Self :: decode_load_immediate_instruction_operands ( operands) ;
79
91
Self :: LoadImmediate { destination, segment, immediate }
80
92
} ,
81
93
Format :: LoadVectorComponents => {
82
- let ( destination, components) = Self :: decode_vector_components ( operands) ;
94
+ let ( destination, components) = Self :: decode_vector_components_instruction_operands ( operands) ;
83
95
Self :: LoadVectorComponents { destination, components}
84
96
} ,
85
97
Format :: ExtractVectorComponents => {
86
- let ( source, destinations) = Self :: decode_vector_components ( operands) ;
98
+ let ( source, destinations) = Self :: decode_vector_components_instruction_operands ( operands) ;
87
99
Self :: ExtractVectorComponents { source, destinations }
88
100
} ,
89
- Format :: FlagVectorComponents => {
90
- let operand_0 =
91
- todo ! ( )
101
+ Format :: MapVector => {
102
+ let ( temporary , operand , components ) = Self :: decode_map_vector_instruction_operands ( operands ) ;
103
+ Self :: MapVector { temporary , operand , mappings : components , }
92
104
} ,
93
- Format :: MapVector => todo ! ( ) ,
94
105
Format :: Branch => todo ! ( ) ,
95
106
Format :: DualSource => todo ! ( ) ,
96
107
Format :: Destination => todo ! ( ) ,
0 commit comments