1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18#include "qemu/osdep.h"
19#include "decode.h"
20#include "opcodes.h"
21#include "insn.h"
22#include "iclass.h"
23#include "mmvec/mmvec.h"
24#include "mmvec/decode_ext_mmvec.h"
25
26static void
27check_new_value(Packet *pkt)
28{
29
30 int i, j;
31 const char *reginfo;
32 const char *destletters;
33 const char *dststr = NULL;
34 uint16_t def_opcode;
35 char letter;
36 int def_regnum;
37
38 for (i = 1; i < pkt->num_insns; i++) {
39 uint16_t use_opcode = pkt->insn[i].opcode;
40 if (GET_ATTRIB(use_opcode, A_DOTNEWVALUE) &&
41 GET_ATTRIB(use_opcode, A_CVI) &&
42 GET_ATTRIB(use_opcode, A_STORE)) {
43 int use_regidx = strchr(opcode_reginfo[use_opcode], 's') -
44 opcode_reginfo[use_opcode];
45
46
47
48
49
50 int def_off = ((pkt->insn[i].regno[use_regidx]) >> 1);
51 int def_oreg = pkt->insn[i].regno[use_regidx] & 1;
52 int def_idx = -1;
53 for (j = i - 1; (j >= 0) && (def_off >= 0); j--) {
54 if (!GET_ATTRIB(pkt->insn[j].opcode, A_CVI)) {
55 continue;
56 }
57 def_off--;
58 if (def_off == 0) {
59 def_idx = j;
60 break;
61 }
62 }
63
64
65
66
67 g_assert(!((def_off != 0) || (def_idx < 0) ||
68 (def_idx > (pkt->num_insns - 1))));
69
70
71 def_opcode = pkt->insn[def_idx].opcode;
72 reginfo = opcode_reginfo[def_opcode];
73 destletters = "dexy";
74 for (j = 0; (letter = destletters[j]) != 0; j++) {
75 dststr = strchr(reginfo, letter);
76 if (dststr != NULL) {
77 break;
78 }
79 }
80 if ((dststr == NULL) && GET_ATTRIB(def_opcode, A_CVI_GATHER)) {
81 def_regnum = 0;
82 pkt->insn[i].regno[use_regidx] = def_oreg;
83 pkt->insn[i].new_value_producer_slot = pkt->insn[def_idx].slot;
84 } else {
85 if (dststr == NULL) {
86
87 g_assert_not_reached();
88 }
89 def_regnum = pkt->insn[def_idx].regno[dststr - reginfo];
90
91 pkt->insn[i].regno[use_regidx] = def_regnum ^ def_oreg;
92
93 dststr = strchr(reginfo, 'y');
94 if (def_oreg && strchr(reginfo, 'x') && dststr) {
95 def_regnum = pkt->insn[def_idx].regno[dststr - reginfo];
96 pkt->insn[i].regno[use_regidx] = def_regnum;
97 }
98
99
100
101
102 pkt->insn[i].new_value_producer_slot = pkt->insn[def_idx].slot;
103 }
104 }
105 }
106}
107
108
109
110
111
112
113
114
115
116static void
117decode_mmvec_move_cvi_to_end(Packet *pkt, int max)
118{
119 int i;
120 for (i = 0; i < max; i++) {
121 if (GET_ATTRIB(pkt->insn[i].opcode, A_CVI)) {
122 int last_inst = pkt->num_insns - 1;
123 uint16_t last_opcode = pkt->insn[last_inst].opcode;
124
125
126
127
128
129 if ((last_opcode == J2_endloop0) ||
130 (last_opcode == J2_endloop1) ||
131 (last_opcode == J2_endloop01)) {
132 last_inst--;
133 }
134
135 decode_send_insn_to(pkt, i, last_inst);
136 max--;
137 i--;
138 }
139 }
140}
141
142static void
143decode_shuffle_for_execution_vops(Packet *pkt)
144{
145
146
147
148 int i;
149 for (i = 0; i < pkt->num_insns; i++) {
150 uint16_t opcode = pkt->insn[i].opcode;
151 if (GET_ATTRIB(opcode, A_LOAD) &&
152 (GET_ATTRIB(opcode, A_CVI_NEW) ||
153 GET_ATTRIB(opcode, A_CVI_TMP))) {
154
155
156
157
158 decode_mmvec_move_cvi_to_end(pkt, i);
159 break;
160 }
161 }
162
163
164 for (i = 0; i < pkt->num_insns - 1; i++) {
165 uint16_t opcode = pkt->insn[i].opcode;
166 if (GET_ATTRIB(opcode, A_STORE) &&
167 GET_ATTRIB(opcode, A_CVI_NEW) &&
168 !GET_ATTRIB(opcode, A_CVI_SCATTER_RELEASE)) {
169 int last_inst = pkt->num_insns - 1;
170 uint16_t last_opcode = pkt->insn[last_inst].opcode;
171
172
173
174
175
176 if ((last_opcode == J2_endloop0) ||
177 (last_opcode == J2_endloop1) ||
178 (last_opcode == J2_endloop01)) {
179 last_inst--;
180 }
181
182 decode_send_insn_to(pkt, i, last_inst);
183 break;
184 }
185 }
186}
187
188static void
189check_for_vhist(Packet *pkt)
190{
191 pkt->vhist_insn = NULL;
192 for (int i = 0; i < pkt->num_insns; i++) {
193 Insn *insn = &pkt->insn[i];
194 int opcode = insn->opcode;
195 if (GET_ATTRIB(opcode, A_CVI) && GET_ATTRIB(opcode, A_CVI_4SLOT)) {
196 pkt->vhist_insn = insn;
197 return;
198 }
199 }
200}
201
202
203
204
205
206SlotMask mmvec_ext_decode_find_iclass_slots(int opcode)
207{
208 if (GET_ATTRIB(opcode, A_CVI_VM)) {
209
210 if (GET_ATTRIB(opcode, A_RESTRICT_SLOT0ONLY)) {
211 return SLOTS_0;
212 } else if (GET_ATTRIB(opcode, A_RESTRICT_SLOT1ONLY)) {
213 return SLOTS_1;
214 }
215 return SLOTS_01;
216 } else if (GET_ATTRIB(opcode, A_RESTRICT_SLOT2ONLY)) {
217 return SLOTS_2;
218 } else if (GET_ATTRIB(opcode, A_CVI_VX)) {
219
220 return SLOTS_23;
221 } else if (GET_ATTRIB(opcode, A_CVI_VS_VX)) {
222
223 return SLOTS_23;
224 } else {
225 return SLOTS_0123;
226 }
227}
228
229void mmvec_ext_decode_checks(Packet *pkt, bool disas_only)
230{
231 check_new_value(pkt);
232 if (!disas_only) {
233 decode_shuffle_for_execution_vops(pkt);
234 }
235 check_for_vhist(pkt);
236}
237