eg_asm.c revision d1acb920163ab0f39ff2fc72b85fc7bf16c37262
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 <stdio.h>
24#include <errno.h>
25#include "util/u_memory.h"
26#include "r600_pipe.h"
27#include "r600_asm.h"
28#include "eg_sq.h"
29#include "r600_opcodes.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			S_SQ_CF_ALU_WORD0_KCACHE_BANK0(cf->kcache0_bank) |
41			S_SQ_CF_ALU_WORD0_KCACHE_BANK1(cf->kcache1_bank);
42		bc->bytecode[id++] = S_SQ_CF_ALU_WORD1_CF_INST(cf->inst >> 3) |
43			S_SQ_CF_ALU_WORD1_KCACHE_MODE1(cf->kcache1_mode) |
44			S_SQ_CF_ALU_WORD1_KCACHE_ADDR0(cf->kcache0_addr) |
45			S_SQ_CF_ALU_WORD1_KCACHE_ADDR1(cf->kcache1_addr) |
46					S_SQ_CF_ALU_WORD1_BARRIER(1) |
47					S_SQ_CF_ALU_WORD1_COUNT((cf->ndw / 2) - 1);
48		break;
49	case EG_V_SQ_CF_WORD1_SQ_CF_INST_TEX:
50	case EG_V_SQ_CF_WORD1_SQ_CF_INST_VTX:
51		bc->bytecode[id++] = S_SQ_CF_WORD0_ADDR(cf->addr >> 1);
52		bc->bytecode[id++] = S_SQ_CF_WORD1_CF_INST(cf->inst) |
53					S_SQ_CF_WORD1_BARRIER(1) |
54					S_SQ_CF_WORD1_COUNT((cf->ndw / 4) - 1);
55		break;
56	case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT:
57	case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT_DONE:
58		bc->bytecode[id++] = S_SQ_CF_ALLOC_EXPORT_WORD0_RW_GPR(cf->output.gpr) |
59			S_SQ_CF_ALLOC_EXPORT_WORD0_ELEM_SIZE(cf->output.elem_size) |
60			S_SQ_CF_ALLOC_EXPORT_WORD0_ARRAY_BASE(cf->output.array_base) |
61			S_SQ_CF_ALLOC_EXPORT_WORD0_TYPE(cf->output.type);
62		bc->bytecode[id++] = S_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_X(cf->output.swizzle_x) |
63			S_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_Y(cf->output.swizzle_y) |
64			S_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_Z(cf->output.swizzle_z) |
65			S_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_W(cf->output.swizzle_w) |
66			S_SQ_CF_ALLOC_EXPORT_WORD1_BARRIER(cf->output.barrier) |
67			S_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST(cf->output.inst) |
68			S_SQ_CF_ALLOC_EXPORT_WORD1_END_OF_PROGRAM(cf->output.end_of_program);
69		break;
70	case EG_V_SQ_CF_WORD1_SQ_CF_INST_JUMP:
71	case EG_V_SQ_CF_WORD1_SQ_CF_INST_ELSE:
72	case EG_V_SQ_CF_WORD1_SQ_CF_INST_POP:
73	case EG_V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START_NO_AL:
74	case EG_V_SQ_CF_WORD1_SQ_CF_INST_LOOP_END:
75	case EG_V_SQ_CF_WORD1_SQ_CF_INST_LOOP_CONTINUE:
76	case EG_V_SQ_CF_WORD1_SQ_CF_INST_LOOP_BREAK:
77		bc->bytecode[id++] = S_SQ_CF_WORD0_ADDR(cf->cf_addr >> 1);
78		bc->bytecode[id++] = S_SQ_CF_WORD1_CF_INST(cf->inst) |
79					S_SQ_CF_WORD1_BARRIER(1) |
80					S_SQ_CF_WORD1_COND(cf->cond) |
81					S_SQ_CF_WORD1_POP_COUNT(cf->pop_count);
82
83		break;
84	default:
85		R600_ERR("unsupported CF instruction (0x%X)\n", cf->inst);
86		return -EINVAL;
87	}
88	return 0;
89}
90