r600g: add missing printf operand
[mesa.git] / src / gallium / drivers / r600 / r600_asm.c
1 /*
2 * Copyright 2010 Jerome Glisse <glisse@freedesktop.org>
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23 #include "r600_asm.h"
24 #include "r600_context.h"
25 #include "util/u_memory.h"
26 #include "r600_sq.h"
27 #include <stdio.h>
28 #include <errno.h>
29
30 int r700_bc_alu_build(struct r600_bc *bc, struct r600_bc_alu *alu, unsigned id);
31
32 static struct r600_bc_cf *r600_bc_cf(void)
33 {
34 struct r600_bc_cf *cf = CALLOC_STRUCT(r600_bc_cf);
35
36 if (cf == NULL)
37 return NULL;
38 LIST_INITHEAD(&cf->list);
39 LIST_INITHEAD(&cf->alu);
40 LIST_INITHEAD(&cf->vtx);
41 LIST_INITHEAD(&cf->tex);
42 return cf;
43 }
44
45 static struct r600_bc_alu *r600_bc_alu(void)
46 {
47 struct r600_bc_alu *alu = CALLOC_STRUCT(r600_bc_alu);
48
49 if (alu == NULL)
50 return NULL;
51 LIST_INITHEAD(&alu->list);
52 return alu;
53 }
54
55 static struct r600_bc_vtx *r600_bc_vtx(void)
56 {
57 struct r600_bc_vtx *vtx = CALLOC_STRUCT(r600_bc_vtx);
58
59 if (vtx == NULL)
60 return NULL;
61 LIST_INITHEAD(&vtx->list);
62 return vtx;
63 }
64
65 static struct r600_bc_tex *r600_bc_tex(void)
66 {
67 struct r600_bc_tex *tex = CALLOC_STRUCT(r600_bc_tex);
68
69 if (tex == NULL)
70 return NULL;
71 LIST_INITHEAD(&tex->list);
72 return tex;
73 }
74
75 int r600_bc_init(struct r600_bc *bc, enum radeon_family family)
76 {
77 LIST_INITHEAD(&bc->cf);
78 bc->family = family;
79 switch (bc->family) {
80 case CHIP_R600:
81 case CHIP_RV610:
82 case CHIP_RV630:
83 case CHIP_RV670:
84 case CHIP_RV620:
85 case CHIP_RV635:
86 case CHIP_RS780:
87 case CHIP_RS880:
88 bc->chiprev = 0;
89 break;
90 case CHIP_RV770:
91 case CHIP_RV730:
92 case CHIP_RV710:
93 case CHIP_RV740:
94 bc->chiprev = 1;
95 break;
96 default:
97 R600_ERR("unknown family %d\n", bc->family);
98 return -EINVAL;
99 }
100 return 0;
101 }
102
103 static int r600_bc_add_cf(struct r600_bc *bc)
104 {
105 struct r600_bc_cf *cf = r600_bc_cf();
106
107 if (cf == NULL)
108 return -ENOMEM;
109 LIST_ADDTAIL(&cf->list, &bc->cf);
110 if (bc->cf_last)
111 cf->id = bc->cf_last->id + 2;
112 bc->cf_last = cf;
113 bc->ncf++;
114 bc->ndw += 2;
115 bc->force_add_cf = 0;
116 return 0;
117 }
118
119 int r600_bc_add_output(struct r600_bc *bc, const struct r600_bc_output *output)
120 {
121 int r;
122
123 r = r600_bc_add_cf(bc);
124 if (r)
125 return r;
126 bc->cf_last->inst = output->inst;
127 memcpy(&bc->cf_last->output, output, sizeof(struct r600_bc_output));
128 return 0;
129 }
130
131 int r600_bc_add_alu_type(struct r600_bc *bc, const struct r600_bc_alu *alu, int type)
132 {
133 struct r600_bc_alu *nalu = r600_bc_alu();
134 struct r600_bc_alu *lalu;
135 int i, r;
136
137 if (nalu == NULL)
138 return -ENOMEM;
139 memcpy(nalu, alu, sizeof(struct r600_bc_alu));
140 nalu->nliteral = 0;
141
142 /* cf can contains only alu or only vtx or only tex */
143 if (bc->cf_last == NULL || bc->cf_last->inst != (type << 3) ||
144 bc->force_add_cf) {
145 /* at most 128 slots, one add alu can add 4 slots + 4 constant worst case */
146 r = r600_bc_add_cf(bc);
147 if (r) {
148 free(nalu);
149 return r;
150 }
151 bc->cf_last->inst = (type << 3);
152 }
153 if (alu->last && (bc->cf_last->ndw >> 1) >= 124) {
154 bc->force_add_cf = 1;
155 }
156 /* number of gpr == the last gpr used in any alu */
157 for (i = 0; i < 3; i++) {
158 if (alu->src[i].sel >= bc->ngpr && alu->src[i].sel < 128) {
159 bc->ngpr = alu->src[i].sel + 1;
160 }
161 /* compute how many literal are needed
162 * either 2 or 4 literals
163 */
164 if (alu->src[i].sel == 253) {
165 if (((alu->src[i].chan + 2) & 0x6) > nalu->nliteral) {
166 nalu->nliteral = (alu->src[i].chan + 2) & 0x6;
167 }
168 }
169 }
170 if (!LIST_IS_EMPTY(&bc->cf_last->alu)) {
171 lalu = LIST_ENTRY(struct r600_bc_alu, bc->cf_last->alu.prev, list);
172 if (!lalu->last && lalu->nliteral > nalu->nliteral) {
173 nalu->nliteral = lalu->nliteral;
174 }
175 }
176 if (alu->dst.sel >= bc->ngpr) {
177 bc->ngpr = alu->dst.sel + 1;
178 }
179 LIST_ADDTAIL(&nalu->list, &bc->cf_last->alu);
180 /* each alu use 2 dwords */
181 bc->cf_last->ndw += 2;
182 bc->ndw += 2;
183 return 0;
184 }
185
186 int r600_bc_add_alu(struct r600_bc *bc, const struct r600_bc_alu *alu)
187 {
188 return r600_bc_add_alu_type(bc, alu, V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU);
189 }
190
191 int r600_bc_add_literal(struct r600_bc *bc, const u32 *value)
192 {
193 struct r600_bc_alu *alu;
194
195 if (bc->cf_last == NULL) {
196 return 0;
197 }
198 if (bc->cf_last->inst == V_SQ_CF_WORD1_SQ_CF_INST_TEX) {
199 return 0;
200 }
201 if (bc->cf_last->inst == V_SQ_CF_WORD1_SQ_CF_INST_JUMP ||
202 bc->cf_last->inst == V_SQ_CF_WORD1_SQ_CF_INST_ELSE ||
203 bc->cf_last->inst == V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START_NO_AL ||
204 bc->cf_last->inst == V_SQ_CF_WORD1_SQ_CF_INST_LOOP_BREAK ||
205 bc->cf_last->inst == V_SQ_CF_WORD1_SQ_CF_INST_LOOP_CONTINUE ||
206 bc->cf_last->inst == V_SQ_CF_WORD1_SQ_CF_INST_LOOP_END ||
207 bc->cf_last->inst == V_SQ_CF_WORD1_SQ_CF_INST_POP) {
208 return 0;
209 }
210 if (((bc->cf_last->inst != (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU << 3)) &&
211 (bc->cf_last->inst != (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE << 3))) ||
212 LIST_IS_EMPTY(&bc->cf_last->alu)) {
213 R600_ERR("last CF is not ALU (%p)\n", bc->cf_last);
214 return -EINVAL;
215 }
216 alu = LIST_ENTRY(struct r600_bc_alu, bc->cf_last->alu.prev, list);
217 if (!alu->last || !alu->nliteral || alu->literal_added) {
218 return 0;
219 }
220 memcpy(alu->value, value, 4 * 4);
221 bc->cf_last->ndw += alu->nliteral;
222 bc->ndw += alu->nliteral;
223 alu->literal_added = 1;
224 return 0;
225 }
226
227 int r600_bc_add_vtx(struct r600_bc *bc, const struct r600_bc_vtx *vtx)
228 {
229 struct r600_bc_vtx *nvtx = r600_bc_vtx();
230 int r;
231
232 if (nvtx == NULL)
233 return -ENOMEM;
234 memcpy(nvtx, vtx, sizeof(struct r600_bc_vtx));
235
236 /* cf can contains only alu or only vtx or only tex */
237 if (bc->cf_last == NULL ||
238 (bc->cf_last->inst != V_SQ_CF_WORD1_SQ_CF_INST_VTX &&
239 bc->cf_last->inst != V_SQ_CF_WORD1_SQ_CF_INST_VTX_TC)) {
240 r = r600_bc_add_cf(bc);
241 if (r) {
242 free(nvtx);
243 return r;
244 }
245 bc->cf_last->inst = V_SQ_CF_WORD1_SQ_CF_INST_VTX;
246 }
247 LIST_ADDTAIL(&nvtx->list, &bc->cf_last->vtx);
248 /* each fetch use 4 dwords */
249 bc->cf_last->ndw += 4;
250 bc->ndw += 4;
251 return 0;
252 }
253
254 int r600_bc_add_tex(struct r600_bc *bc, const struct r600_bc_tex *tex)
255 {
256 struct r600_bc_tex *ntex = r600_bc_tex();
257 int r;
258
259 if (ntex == NULL)
260 return -ENOMEM;
261 memcpy(ntex, tex, sizeof(struct r600_bc_tex));
262
263 /* cf can contains only alu or only vtx or only tex */
264 if (bc->cf_last == NULL ||
265 bc->cf_last->inst != V_SQ_CF_WORD1_SQ_CF_INST_TEX) {
266 r = r600_bc_add_cf(bc);
267 if (r) {
268 free(ntex);
269 return r;
270 }
271 bc->cf_last->inst = V_SQ_CF_WORD1_SQ_CF_INST_TEX;
272 }
273 LIST_ADDTAIL(&ntex->list, &bc->cf_last->tex);
274 /* each texture fetch use 4 dwords */
275 bc->cf_last->ndw += 4;
276 bc->ndw += 4;
277 return 0;
278 }
279
280 int r600_bc_add_cfinst(struct r600_bc *bc, int inst)
281 {
282 int r;
283 r = r600_bc_add_cf(bc);
284 if (r)
285 return r;
286
287 bc->cf_last->cond = V_SQ_CF_COND_ACTIVE;
288 bc->cf_last->inst = inst;
289 return 0;
290 }
291
292 static int r600_bc_vtx_build(struct r600_bc *bc, struct r600_bc_vtx *vtx, unsigned id)
293 {
294 bc->bytecode[id++] = S_SQ_VTX_WORD0_BUFFER_ID(vtx->buffer_id) |
295 S_SQ_VTX_WORD0_SRC_GPR(vtx->src_gpr) |
296 S_SQ_VTX_WORD0_SRC_SEL_X(vtx->src_sel_x) |
297 S_SQ_VTX_WORD0_MEGA_FETCH_COUNT(vtx->mega_fetch_count);
298 bc->bytecode[id++] = S_SQ_VTX_WORD1_DST_SEL_X(vtx->dst_sel_x) |
299 S_SQ_VTX_WORD1_DST_SEL_Y(vtx->dst_sel_y) |
300 S_SQ_VTX_WORD1_DST_SEL_Z(vtx->dst_sel_z) |
301 S_SQ_VTX_WORD1_DST_SEL_W(vtx->dst_sel_w) |
302 S_SQ_VTX_WORD1_USE_CONST_FIELDS(1) |
303 S_SQ_VTX_WORD1_GPR_DST_GPR(vtx->dst_gpr);
304 bc->bytecode[id++] = S_SQ_VTX_WORD2_MEGA_FETCH(1);
305 bc->bytecode[id++] = 0;
306 return 0;
307 }
308
309 static int r600_bc_tex_build(struct r600_bc *bc, struct r600_bc_tex *tex, unsigned id)
310 {
311 bc->bytecode[id++] = S_SQ_TEX_WORD0_TEX_INST(tex->inst) |
312 S_SQ_TEX_WORD0_RESOURCE_ID(tex->resource_id) |
313 S_SQ_TEX_WORD0_SRC_GPR(tex->src_gpr) |
314 S_SQ_TEX_WORD0_SRC_REL(tex->src_rel);
315 bc->bytecode[id++] = S_SQ_TEX_WORD1_DST_GPR(tex->dst_gpr) |
316 S_SQ_TEX_WORD1_DST_REL(tex->dst_rel) |
317 S_SQ_TEX_WORD1_DST_SEL_X(tex->dst_sel_x) |
318 S_SQ_TEX_WORD1_DST_SEL_Y(tex->dst_sel_y) |
319 S_SQ_TEX_WORD1_DST_SEL_Z(tex->dst_sel_z) |
320 S_SQ_TEX_WORD1_DST_SEL_W(tex->dst_sel_w) |
321 S_SQ_TEX_WORD1_LOD_BIAS(tex->lod_bias) |
322 S_SQ_TEX_WORD1_COORD_TYPE_X(tex->coord_type_x) |
323 S_SQ_TEX_WORD1_COORD_TYPE_Y(tex->coord_type_y) |
324 S_SQ_TEX_WORD1_COORD_TYPE_Z(tex->coord_type_z) |
325 S_SQ_TEX_WORD1_COORD_TYPE_W(tex->coord_type_w);
326 bc->bytecode[id++] = S_SQ_TEX_WORD2_OFFSET_X(tex->offset_x) |
327 S_SQ_TEX_WORD2_OFFSET_Y(tex->offset_y) |
328 S_SQ_TEX_WORD2_OFFSET_Z(tex->offset_z) |
329 S_SQ_TEX_WORD2_SAMPLER_ID(tex->sampler_id) |
330 S_SQ_TEX_WORD2_SRC_SEL_X(tex->src_sel_x) |
331 S_SQ_TEX_WORD2_SRC_SEL_Y(tex->src_sel_y) |
332 S_SQ_TEX_WORD2_SRC_SEL_Z(tex->src_sel_z) |
333 S_SQ_TEX_WORD2_SRC_SEL_W(tex->src_sel_w);
334 bc->bytecode[id++] = 0;
335 return 0;
336 }
337
338 static int r600_bc_alu_build(struct r600_bc *bc, struct r600_bc_alu *alu, unsigned id)
339 {
340 unsigned i;
341
342 /* don't replace gpr by pv or ps for destination register */
343 bc->bytecode[id++] = S_SQ_ALU_WORD0_SRC0_SEL(alu->src[0].sel) |
344 S_SQ_ALU_WORD0_SRC0_REL(alu->src[0].rel) |
345 S_SQ_ALU_WORD0_SRC0_CHAN(alu->src[0].chan) |
346 S_SQ_ALU_WORD0_SRC0_NEG(alu->src[0].neg) |
347 S_SQ_ALU_WORD0_SRC1_SEL(alu->src[1].sel) |
348 S_SQ_ALU_WORD0_SRC1_REL(alu->src[1].rel) |
349 S_SQ_ALU_WORD0_SRC1_CHAN(alu->src[1].chan) |
350 S_SQ_ALU_WORD0_SRC1_NEG(alu->src[1].neg) |
351 S_SQ_ALU_WORD0_LAST(alu->last);
352
353 if (alu->is_op3) {
354 bc->bytecode[id++] = S_SQ_ALU_WORD1_DST_GPR(alu->dst.sel) |
355 S_SQ_ALU_WORD1_DST_CHAN(alu->dst.chan) |
356 S_SQ_ALU_WORD1_DST_REL(alu->dst.rel) |
357 S_SQ_ALU_WORD1_CLAMP(alu->dst.clamp) |
358 S_SQ_ALU_WORD1_OP3_SRC2_SEL(alu->src[2].sel) |
359 S_SQ_ALU_WORD1_OP3_SRC2_REL(alu->src[2].rel) |
360 S_SQ_ALU_WORD1_OP3_SRC2_CHAN(alu->src[2].chan) |
361 S_SQ_ALU_WORD1_OP3_SRC2_NEG(alu->src[2].neg) |
362 S_SQ_ALU_WORD1_OP3_ALU_INST(alu->inst) |
363 S_SQ_ALU_WORD1_BANK_SWIZZLE(0);
364 } else {
365 bc->bytecode[id++] = S_SQ_ALU_WORD1_DST_GPR(alu->dst.sel) |
366 S_SQ_ALU_WORD1_DST_CHAN(alu->dst.chan) |
367 S_SQ_ALU_WORD1_DST_REL(alu->dst.rel) |
368 S_SQ_ALU_WORD1_CLAMP(alu->dst.clamp) |
369 S_SQ_ALU_WORD1_OP2_SRC0_ABS(alu->src[0].abs) |
370 S_SQ_ALU_WORD1_OP2_SRC1_ABS(alu->src[1].abs) |
371 S_SQ_ALU_WORD1_OP2_WRITE_MASK(alu->dst.write) |
372 S_SQ_ALU_WORD1_OP2_ALU_INST(alu->inst) |
373 S_SQ_ALU_WORD1_BANK_SWIZZLE(0) |
374 S_SQ_ALU_WORD1_OP2_UPDATE_EXECUTE_MASK(alu->predicate) |
375 S_SQ_ALU_WORD1_OP2_UPDATE_PRED(alu->predicate);
376 }
377 if (alu->last) {
378 if (alu->nliteral && !alu->literal_added) {
379 R600_ERR("Bug in ALU processing for instruction 0x%08x, literal not added correctly\n", alu->inst);
380 }
381 for (i = 0; i < alu->nliteral; i++) {
382 bc->bytecode[id++] = alu->value[i];
383 }
384 }
385 return 0;
386 }
387
388 static int r600_bc_cf_build(struct r600_bc *bc, struct r600_bc_cf *cf)
389 {
390 unsigned id = cf->id;
391
392 switch (cf->inst) {
393 case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU << 3):
394 case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE << 3):
395 bc->bytecode[id++] = S_SQ_CF_ALU_WORD0_ADDR(cf->addr >> 1);
396 bc->bytecode[id++] = S_SQ_CF_ALU_WORD1_CF_INST(cf->inst >> 3) |
397 S_SQ_CF_ALU_WORD1_BARRIER(1) |
398 S_SQ_CF_ALU_WORD1_COUNT((cf->ndw / 2) - 1);
399 break;
400 case V_SQ_CF_WORD1_SQ_CF_INST_TEX:
401 case V_SQ_CF_WORD1_SQ_CF_INST_VTX:
402 case V_SQ_CF_WORD1_SQ_CF_INST_VTX_TC:
403 bc->bytecode[id++] = S_SQ_CF_WORD0_ADDR(cf->addr >> 1);
404 bc->bytecode[id++] = S_SQ_CF_WORD1_CF_INST(cf->inst) |
405 S_SQ_CF_WORD1_BARRIER(1) |
406 S_SQ_CF_WORD1_COUNT((cf->ndw / 4) - 1);
407 break;
408 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT:
409 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT_DONE:
410 bc->bytecode[id++] = S_SQ_CF_ALLOC_EXPORT_WORD0_RW_GPR(cf->output.gpr) |
411 S_SQ_CF_ALLOC_EXPORT_WORD0_ELEM_SIZE(cf->output.elem_size) |
412 S_SQ_CF_ALLOC_EXPORT_WORD0_ARRAY_BASE(cf->output.array_base) |
413 S_SQ_CF_ALLOC_EXPORT_WORD0_TYPE(cf->output.type);
414 bc->bytecode[id++] = S_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_X(cf->output.swizzle_x) |
415 S_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_Y(cf->output.swizzle_y) |
416 S_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_Z(cf->output.swizzle_z) |
417 S_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_W(cf->output.swizzle_w) |
418 S_SQ_CF_ALLOC_EXPORT_WORD1_BARRIER(cf->output.barrier) |
419 S_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST(cf->output.inst) |
420 S_SQ_CF_ALLOC_EXPORT_WORD1_END_OF_PROGRAM(cf->output.end_of_program);
421 break;
422 case V_SQ_CF_WORD1_SQ_CF_INST_JUMP:
423 case V_SQ_CF_WORD1_SQ_CF_INST_ELSE:
424 case V_SQ_CF_WORD1_SQ_CF_INST_POP:
425 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START_NO_AL:
426 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_END:
427 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_CONTINUE:
428 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_BREAK:
429 bc->bytecode[id++] = S_SQ_CF_WORD0_ADDR(cf->cf_addr >> 1);
430 bc->bytecode[id++] = S_SQ_CF_WORD1_CF_INST(cf->inst) |
431 S_SQ_CF_WORD1_BARRIER(1) |
432 S_SQ_CF_WORD1_COND(cf->cond) |
433 S_SQ_CF_WORD1_POP_COUNT(cf->pop_count);
434
435 break;
436 default:
437 R600_ERR("unsupported CF instruction (0x%X)\n", cf->inst);
438 return -EINVAL;
439 }
440 return 0;
441 }
442
443 int r600_bc_build(struct r600_bc *bc)
444 {
445 struct r600_bc_cf *cf;
446 struct r600_bc_alu *alu;
447 struct r600_bc_vtx *vtx;
448 struct r600_bc_tex *tex;
449 unsigned addr;
450 int r;
451
452 if (bc->callstack[0].max > 0)
453 bc->nstack = ((bc->callstack[0].max + 3) >> 2) + 2;
454
455 /* first path compute addr of each CF block */
456 /* addr start after all the CF instructions */
457 addr = bc->cf_last->id + 2;
458 LIST_FOR_EACH_ENTRY(cf, &bc->cf, list) {
459 switch (cf->inst) {
460 case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU << 3):
461 case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE << 3):
462 break;
463 case V_SQ_CF_WORD1_SQ_CF_INST_TEX:
464 case V_SQ_CF_WORD1_SQ_CF_INST_VTX:
465 case V_SQ_CF_WORD1_SQ_CF_INST_VTX_TC:
466 /* fetch node need to be 16 bytes aligned*/
467 addr += 3;
468 addr &= 0xFFFFFFFCUL;
469 break;
470 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT:
471 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT_DONE:
472 break;
473 case V_SQ_CF_WORD1_SQ_CF_INST_JUMP:
474 case V_SQ_CF_WORD1_SQ_CF_INST_ELSE:
475 case V_SQ_CF_WORD1_SQ_CF_INST_POP:
476 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START_NO_AL:
477 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_END:
478 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_CONTINUE:
479 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_BREAK:
480 break;
481 default:
482 R600_ERR("unsupported CF instruction (0x%X)\n", cf->inst);
483 return -EINVAL;
484 }
485 cf->addr = addr;
486 addr += cf->ndw;
487 bc->ndw = cf->addr + cf->ndw;
488 }
489 free(bc->bytecode);
490 bc->bytecode = calloc(1, bc->ndw * 4);
491 if (bc->bytecode == NULL)
492 return -ENOMEM;
493 LIST_FOR_EACH_ENTRY(cf, &bc->cf, list) {
494 addr = cf->addr;
495 r = r600_bc_cf_build(bc, cf);
496 if (r)
497 return r;
498 switch (cf->inst) {
499 case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU << 3):
500 case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE << 3):
501 LIST_FOR_EACH_ENTRY(alu, &cf->alu, list) {
502 switch(bc->chiprev) {
503 case 0:
504 r = r600_bc_alu_build(bc, alu, addr);
505 break;
506 case 1:
507 r = r700_bc_alu_build(bc, alu, addr);
508 break;
509 default:
510 R600_ERR("unknown family %d\n", bc->family);
511 return -EINVAL;
512 }
513 if (r)
514 return r;
515 addr += 2;
516 if (alu->last) {
517 addr += alu->nliteral;
518 }
519 }
520 break;
521 case V_SQ_CF_WORD1_SQ_CF_INST_VTX:
522 case V_SQ_CF_WORD1_SQ_CF_INST_VTX_TC:
523 LIST_FOR_EACH_ENTRY(vtx, &cf->vtx, list) {
524 r = r600_bc_vtx_build(bc, vtx, addr);
525 if (r)
526 return r;
527 addr += 4;
528 }
529 break;
530 case V_SQ_CF_WORD1_SQ_CF_INST_TEX:
531 LIST_FOR_EACH_ENTRY(tex, &cf->tex, list) {
532 r = r600_bc_tex_build(bc, tex, addr);
533 if (r)
534 return r;
535 addr += 4;
536 }
537 break;
538 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT:
539 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT_DONE:
540 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START_NO_AL:
541 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_END:
542 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_CONTINUE:
543 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_BREAK:
544 case V_SQ_CF_WORD1_SQ_CF_INST_JUMP:
545 case V_SQ_CF_WORD1_SQ_CF_INST_ELSE:
546 case V_SQ_CF_WORD1_SQ_CF_INST_POP:
547 break;
548 default:
549 R600_ERR("unsupported CF instruction (0x%X)\n", cf->inst);
550 return -EINVAL;
551 }
552 }
553 return 0;
554 }