eg_asm.c revision 50526e094f4c66957c7f74c190c35903bc82fb62
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 "eg_sq.h"
27#include "r600_opcodes.h"
28#include <stdio.h>
29#include <errno.h>
30
31int eg_bc_cf_build(struct r600_bc *bc, struct r600_bc_cf *cf)
32{
33	unsigned id = cf->id;
34
35	switch (cf->inst) {
36	case (EG_V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU << 3):
37	case (EG_V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE << 3):
38		bc->bytecode[id++] = S_SQ_CF_ALU_WORD0_ADDR(cf->addr >> 1) |
39		  S_SQ_CF_ALU_WORD0_KCACHE_MODE0(cf->kcache0_mode);
40		bc->bytecode[id++] = S_SQ_CF_ALU_WORD1_CF_INST(cf->inst >> 3) |
41					S_SQ_CF_ALU_WORD1_BARRIER(1) |
42					S_SQ_CF_ALU_WORD1_COUNT((cf->ndw / 2) - 1);
43		break;
44	case EG_V_SQ_CF_WORD1_SQ_CF_INST_TEX:
45	case EG_V_SQ_CF_WORD1_SQ_CF_INST_VTX:
46		bc->bytecode[id++] = S_SQ_CF_WORD0_ADDR(cf->addr >> 1);
47		bc->bytecode[id++] = S_SQ_CF_WORD1_CF_INST(cf->inst) |
48					S_SQ_CF_WORD1_BARRIER(1) |
49					S_SQ_CF_WORD1_COUNT((cf->ndw / 4) - 1);
50		break;
51	case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT:
52	case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT_DONE:
53		bc->bytecode[id++] = S_SQ_CF_ALLOC_EXPORT_WORD0_RW_GPR(cf->output.gpr) |
54			S_SQ_CF_ALLOC_EXPORT_WORD0_ELEM_SIZE(cf->output.elem_size) |
55			S_SQ_CF_ALLOC_EXPORT_WORD0_ARRAY_BASE(cf->output.array_base) |
56			S_SQ_CF_ALLOC_EXPORT_WORD0_TYPE(cf->output.type);
57		bc->bytecode[id++] = S_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_X(cf->output.swizzle_x) |
58			S_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_Y(cf->output.swizzle_y) |
59			S_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_Z(cf->output.swizzle_z) |
60			S_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_W(cf->output.swizzle_w) |
61			S_SQ_CF_ALLOC_EXPORT_WORD1_BARRIER(cf->output.barrier) |
62			S_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST(cf->output.inst) |
63			S_SQ_CF_ALLOC_EXPORT_WORD1_END_OF_PROGRAM(cf->output.end_of_program);
64		break;
65	case EG_V_SQ_CF_WORD1_SQ_CF_INST_JUMP:
66	case EG_V_SQ_CF_WORD1_SQ_CF_INST_ELSE:
67	case EG_V_SQ_CF_WORD1_SQ_CF_INST_POP:
68	case EG_V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START_NO_AL:
69	case EG_V_SQ_CF_WORD1_SQ_CF_INST_LOOP_END:
70	case EG_V_SQ_CF_WORD1_SQ_CF_INST_LOOP_CONTINUE:
71	case EG_V_SQ_CF_WORD1_SQ_CF_INST_LOOP_BREAK:
72		bc->bytecode[id++] = S_SQ_CF_WORD0_ADDR(cf->cf_addr >> 1);
73		bc->bytecode[id++] = S_SQ_CF_WORD1_CF_INST(cf->inst) |
74					S_SQ_CF_WORD1_BARRIER(1) |
75			                S_SQ_CF_WORD1_COND(cf->cond) |
76			                S_SQ_CF_WORD1_POP_COUNT(cf->pop_count);
77
78		break;
79	default:
80		R600_ERR("unsupported CF instruction (0x%X)\n", cf->inst);
81		return -EINVAL;
82	}
83	return 0;
84}
85