1848b8605Smrg/*
2848b8605Smrg * Copyright 2010 Jerome Glisse <glisse@freedesktop.org>
3848b8605Smrg *
4848b8605Smrg * Permission is hereby granted, free of charge, to any person obtaining a
5848b8605Smrg * copy of this software and associated documentation files (the "Software"),
6848b8605Smrg * to deal in the Software without restriction, including without limitation
7848b8605Smrg * on the rights to use, copy, modify, merge, publish, distribute, sub
8848b8605Smrg * license, and/or sell copies of the Software, and to permit persons to whom
9848b8605Smrg * the Software is furnished to do so, subject to the following conditions:
10848b8605Smrg *
11848b8605Smrg * The above copyright notice and this permission notice (including the next
12848b8605Smrg * paragraph) shall be included in all copies or substantial portions of the
13848b8605Smrg * Software.
14848b8605Smrg *
15848b8605Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16848b8605Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17848b8605Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18848b8605Smrg * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19848b8605Smrg * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20848b8605Smrg * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21848b8605Smrg * USE OR OTHER DEALINGS IN THE SOFTWARE.
22848b8605Smrg */
23848b8605Smrg#include "r600_pipe.h"
24848b8605Smrg#include "r600_opcodes.h"
25848b8605Smrg#include "r600_shader.h"
26848b8605Smrg
27848b8605Smrg#include "util/u_memory.h"
28848b8605Smrg#include "eg_sq.h"
29848b8605Smrg#include <errno.h>
30848b8605Smrg
31848b8605Smrgint eg_bytecode_cf_build(struct r600_bytecode *bc, struct r600_bytecode_cf *cf)
32848b8605Smrg{
33848b8605Smrg	unsigned id = cf->id;
34848b8605Smrg
35848b8605Smrg	if (cf->op == CF_NATIVE) {
36848b8605Smrg		bc->bytecode[id++] = cf->isa[0];
37848b8605Smrg		bc->bytecode[id++] = cf->isa[1];
38848b8605Smrg	} else {
39848b8605Smrg		const struct cf_op_info *cfop = r600_isa_cf(cf->op);
40848b8605Smrg		unsigned opcode = r600_isa_cf_opcode(bc->isa->hw_class, cf->op);
41848b8605Smrg		if (cfop->flags & CF_ALU) { /* ALU clauses */
42848b8605Smrg
43848b8605Smrg			/* prepend ALU_EXTENDED if we need more than 2 kcache sets */
44848b8605Smrg			if (cf->eg_alu_extended) {
45848b8605Smrg				bc->bytecode[id++] =
46b8e80941Smrg						S_SQ_CF_ALU_WORD0_EXT_KCACHE_BANK_INDEX_MODE0(cf->kcache[0].index_mode) |
47b8e80941Smrg						S_SQ_CF_ALU_WORD0_EXT_KCACHE_BANK_INDEX_MODE1(cf->kcache[1].index_mode) |
48b8e80941Smrg						S_SQ_CF_ALU_WORD0_EXT_KCACHE_BANK_INDEX_MODE2(cf->kcache[2].index_mode) |
49b8e80941Smrg						S_SQ_CF_ALU_WORD0_EXT_KCACHE_BANK_INDEX_MODE3(cf->kcache[3].index_mode) |
50848b8605Smrg						S_SQ_CF_ALU_WORD0_EXT_KCACHE_BANK2(cf->kcache[2].bank) |
51848b8605Smrg						S_SQ_CF_ALU_WORD0_EXT_KCACHE_BANK3(cf->kcache[3].bank) |
52848b8605Smrg						S_SQ_CF_ALU_WORD0_EXT_KCACHE_MODE2(cf->kcache[2].mode);
53848b8605Smrg				bc->bytecode[id++] =
54848b8605Smrg						S_SQ_CF_ALU_WORD1_EXT_CF_INST(
55848b8605Smrg							r600_isa_cf_opcode(bc->isa->hw_class, CF_OP_ALU_EXT)) |
56848b8605Smrg						S_SQ_CF_ALU_WORD1_EXT_KCACHE_MODE3(cf->kcache[3].mode) |
57848b8605Smrg						S_SQ_CF_ALU_WORD1_EXT_KCACHE_ADDR2(cf->kcache[2].addr) |
58848b8605Smrg						S_SQ_CF_ALU_WORD1_EXT_KCACHE_ADDR3(cf->kcache[3].addr) |
59848b8605Smrg						S_SQ_CF_ALU_WORD1_EXT_BARRIER(1);
60848b8605Smrg			}
61848b8605Smrg			bc->bytecode[id++] = S_SQ_CF_ALU_WORD0_ADDR(cf->addr >> 1) |
62848b8605Smrg					S_SQ_CF_ALU_WORD0_KCACHE_MODE0(cf->kcache[0].mode) |
63848b8605Smrg					S_SQ_CF_ALU_WORD0_KCACHE_BANK0(cf->kcache[0].bank) |
64848b8605Smrg					S_SQ_CF_ALU_WORD0_KCACHE_BANK1(cf->kcache[1].bank);
65848b8605Smrg			bc->bytecode[id++] = S_SQ_CF_ALU_WORD1_CF_INST(opcode) |
66848b8605Smrg					S_SQ_CF_ALU_WORD1_KCACHE_MODE1(cf->kcache[1].mode) |
67848b8605Smrg					S_SQ_CF_ALU_WORD1_KCACHE_ADDR0(cf->kcache[0].addr) |
68848b8605Smrg					S_SQ_CF_ALU_WORD1_KCACHE_ADDR1(cf->kcache[1].addr) |
69848b8605Smrg					S_SQ_CF_ALU_WORD1_BARRIER(1) |
70848b8605Smrg					S_SQ_CF_ALU_WORD1_COUNT((cf->ndw / 2) - 1);
71848b8605Smrg		} else if (cfop->flags & CF_CLAUSE) {
72848b8605Smrg			/* CF_TEX/VTX (CF_ALU already handled above) */
73848b8605Smrg			bc->bytecode[id++] = S_SQ_CF_WORD0_ADDR(cf->addr >> 1);
74b8e80941Smrg			bc->bytecode[id] = S_SQ_CF_WORD1_CF_INST(opcode) |
75848b8605Smrg					S_SQ_CF_WORD1_BARRIER(1) |
76b8e80941Smrg					S_SQ_CF_WORD1_VALID_PIXEL_MODE(cf->vpm) |
77848b8605Smrg					S_SQ_CF_WORD1_COUNT((cf->ndw / 4) - 1);
78b8e80941Smrg			if (bc->chip_class == EVERGREEN) /* no EOP on cayman */
79b8e80941Smrg				bc->bytecode[id] |= S_SQ_CF_ALLOC_EXPORT_WORD1_END_OF_PROGRAM(cf->end_of_program);
80b8e80941Smrg			id++;
81848b8605Smrg		} else if (cfop->flags & CF_EXP) {
82848b8605Smrg			/* EXPORT instructions */
83848b8605Smrg			bc->bytecode[id++] = S_SQ_CF_ALLOC_EXPORT_WORD0_RW_GPR(cf->output.gpr) |
84848b8605Smrg					S_SQ_CF_ALLOC_EXPORT_WORD0_ELEM_SIZE(cf->output.elem_size) |
85848b8605Smrg					S_SQ_CF_ALLOC_EXPORT_WORD0_ARRAY_BASE(cf->output.array_base) |
86848b8605Smrg					S_SQ_CF_ALLOC_EXPORT_WORD0_TYPE(cf->output.type) |
87848b8605Smrg					S_SQ_CF_ALLOC_EXPORT_WORD0_INDEX_GPR(cf->output.index_gpr);
88848b8605Smrg			bc->bytecode[id] =
89848b8605Smrg					S_SQ_CF_ALLOC_EXPORT_WORD1_BURST_COUNT(cf->output.burst_count - 1) |
90848b8605Smrg					S_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_X(cf->output.swizzle_x) |
91848b8605Smrg					S_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_Y(cf->output.swizzle_y) |
92848b8605Smrg					S_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_Z(cf->output.swizzle_z) |
93848b8605Smrg					S_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_W(cf->output.swizzle_w) |
94848b8605Smrg					S_SQ_CF_ALLOC_EXPORT_WORD1_BARRIER(cf->barrier) |
95b8e80941Smrg					S_SQ_CF_ALLOC_EXPORT_WORD1_MARK(cf->mark) |
96848b8605Smrg					S_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST(opcode);
97848b8605Smrg
98848b8605Smrg			if (bc->chip_class == EVERGREEN) /* no EOP on cayman */
99848b8605Smrg				bc->bytecode[id] |= S_SQ_CF_ALLOC_EXPORT_WORD1_END_OF_PROGRAM(cf->end_of_program);
100848b8605Smrg			id++;
101b8e80941Smrg		} else if (cfop->flags & CF_RAT) {
102b8e80941Smrg			bc->bytecode[id++] = S_SQ_CF_ALLOC_EXPORT_WORD0_RAT_RAT_ID(cf->rat.id) |
103b8e80941Smrg					S_SQ_CF_ALLOC_EXPORT_WORD0_RAT_RAT_INST(cf->rat.inst) |
104b8e80941Smrg					S_SQ_CF_ALLOC_EXPORT_WORD0_RAT_RAT_INDEX_MODE(cf->rat.index_mode) |
105b8e80941Smrg					S_SQ_CF_ALLOC_EXPORT_WORD0_RW_GPR(cf->output.gpr) |
106b8e80941Smrg					S_SQ_CF_ALLOC_EXPORT_WORD0_ELEM_SIZE(cf->output.elem_size) |
107b8e80941Smrg					S_SQ_CF_ALLOC_EXPORT_WORD0_TYPE(cf->output.type) |
108b8e80941Smrg					S_SQ_CF_ALLOC_EXPORT_WORD0_INDEX_GPR(cf->output.index_gpr);
109b8e80941Smrg			bc->bytecode[id] = S_SQ_CF_ALLOC_EXPORT_WORD1_BURST_COUNT(cf->output.burst_count - 1) |
110b8e80941Smrg					S_SQ_CF_ALLOC_EXPORT_WORD1_BARRIER(cf->barrier) |
111b8e80941Smrg					S_SQ_CF_ALLOC_EXPORT_WORD1_MARK(cf->mark) |
112b8e80941Smrg			                S_SQ_CF_ALLOC_EXPORT_WORD1_VALID_PIXEL_MODE(cf->vpm) |
113b8e80941Smrg					S_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST(opcode) |
114b8e80941Smrg					S_SQ_CF_ALLOC_EXPORT_WORD1_BUF_COMP_MASK(cf->output.comp_mask) |
115b8e80941Smrg					S_SQ_CF_ALLOC_EXPORT_WORD1_BUF_ARRAY_SIZE(cf->output.array_size) |
116b8e80941Smrg					S_SQ_CF_ALLOC_EXPORT_WORD1_MARK(cf->output.mark);
117b8e80941Smrg			if (bc->chip_class == EVERGREEN) /* no EOP on cayman */
118b8e80941Smrg				bc->bytecode[id] |= S_SQ_CF_ALLOC_EXPORT_WORD1_END_OF_PROGRAM(cf->end_of_program);
119b8e80941Smrg			id++;
120b8e80941Smrg
121848b8605Smrg		} else if (cfop->flags & CF_MEM) {
122848b8605Smrg			/* MEM_STREAM, MEM_RING instructions */
123848b8605Smrg			bc->bytecode[id++] = S_SQ_CF_ALLOC_EXPORT_WORD0_RW_GPR(cf->output.gpr) |
124848b8605Smrg					S_SQ_CF_ALLOC_EXPORT_WORD0_ELEM_SIZE(cf->output.elem_size) |
125848b8605Smrg					S_SQ_CF_ALLOC_EXPORT_WORD0_ARRAY_BASE(cf->output.array_base) |
126848b8605Smrg					S_SQ_CF_ALLOC_EXPORT_WORD0_TYPE(cf->output.type) |
127848b8605Smrg					S_SQ_CF_ALLOC_EXPORT_WORD0_INDEX_GPR(cf->output.index_gpr);
128848b8605Smrg			bc->bytecode[id] = S_SQ_CF_ALLOC_EXPORT_WORD1_BURST_COUNT(cf->output.burst_count - 1) |
129848b8605Smrg					S_SQ_CF_ALLOC_EXPORT_WORD1_BARRIER(cf->barrier) |
130b8e80941Smrg					S_SQ_CF_ALLOC_EXPORT_WORD1_MARK(cf->mark) |
131848b8605Smrg					S_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST(opcode) |
132848b8605Smrg					S_SQ_CF_ALLOC_EXPORT_WORD1_BUF_COMP_MASK(cf->output.comp_mask) |
133848b8605Smrg					S_SQ_CF_ALLOC_EXPORT_WORD1_BUF_ARRAY_SIZE(cf->output.array_size);
134848b8605Smrg			if (bc->chip_class == EVERGREEN) /* no EOP on cayman */
135848b8605Smrg				bc->bytecode[id] |= S_SQ_CF_ALLOC_EXPORT_WORD1_END_OF_PROGRAM(cf->end_of_program);
136848b8605Smrg			id++;
137848b8605Smrg		} else {
138848b8605Smrg			/* other instructions */
139848b8605Smrg			bc->bytecode[id++] = S_SQ_CF_WORD0_ADDR(cf->cf_addr >> 1);
140b8e80941Smrg			bc->bytecode[id] = S_SQ_CF_WORD1_CF_INST(opcode) |
141b8e80941Smrg					S_SQ_CF_WORD1_VALID_PIXEL_MODE(cf->vpm) |
142848b8605Smrg					S_SQ_CF_WORD1_BARRIER(1) |
143848b8605Smrg					S_SQ_CF_WORD1_COND(cf->cond) |
144848b8605Smrg					S_SQ_CF_WORD1_POP_COUNT(cf->pop_count) |
145b8e80941Smrg					S_SQ_CF_WORD1_COUNT(cf->count);
146b8e80941Smrg			if (bc->chip_class == EVERGREEN) /* no EOP on cayman */
147b8e80941Smrg				bc->bytecode[id] |= S_SQ_CF_ALLOC_EXPORT_WORD1_END_OF_PROGRAM(cf->end_of_program);
148b8e80941Smrg			id++;
149848b8605Smrg		}
150848b8605Smrg	}
151848b8605Smrg	return 0;
152848b8605Smrg}
153848b8605Smrg
154848b8605Smrg#if 0
155848b8605Smrgvoid eg_bytecode_export_read(struct r600_bytecode *bc,
156848b8605Smrg		struct r600_bytecode_output *output, uint32_t word0, uint32_t word1)
157848b8605Smrg{
158848b8605Smrg	output->array_base = G_SQ_CF_ALLOC_EXPORT_WORD0_ARRAY_BASE(word0);
159848b8605Smrg	output->type = G_SQ_CF_ALLOC_EXPORT_WORD0_TYPE(word0);
160848b8605Smrg	output->gpr = G_SQ_CF_ALLOC_EXPORT_WORD0_RW_GPR(word0);
161848b8605Smrg	output->elem_size = G_SQ_CF_ALLOC_EXPORT_WORD0_ELEM_SIZE(word0);
162848b8605Smrg
163848b8605Smrg	output->swizzle_x = G_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_X(word1);
164848b8605Smrg	output->swizzle_y = G_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_Y(word1);
165848b8605Smrg	output->swizzle_z = G_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_Z(word1);
166848b8605Smrg	output->swizzle_w = G_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_W(word1);
167848b8605Smrg	output->burst_count = G_SQ_CF_ALLOC_EXPORT_WORD1_BURST_COUNT(word1);
168848b8605Smrg	output->end_of_program = G_SQ_CF_ALLOC_EXPORT_WORD1_END_OF_PROGRAM(word1);
169848b8605Smrg	output->op = r600_isa_cf_by_opcode(bc->isa,
170848b8605Smrg			G_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST(word1), /* is_cf_alu = */ 0 );
171848b8605Smrg	output->barrier = G_SQ_CF_ALLOC_EXPORT_WORD1_BARRIER(word1);
172848b8605Smrg	output->array_size = G_SQ_CF_ALLOC_EXPORT_WORD1_BUF_ARRAY_SIZE(word1);
173848b8605Smrg	output->comp_mask = G_SQ_CF_ALLOC_EXPORT_WORD1_BUF_COMP_MASK(word1);
174848b8605Smrg}
175848b8605Smrg#endif
176b8e80941Smrg
177b8e80941Smrgint egcm_load_index_reg(struct r600_bytecode *bc, unsigned id, bool inside_alu_clause)
178b8e80941Smrg{
179b8e80941Smrg	struct r600_bytecode_alu alu;
180b8e80941Smrg	int r;
181b8e80941Smrg	unsigned type;
182b8e80941Smrg
183b8e80941Smrg	assert(id < 2);
184b8e80941Smrg	assert(bc->chip_class >= EVERGREEN);
185b8e80941Smrg
186b8e80941Smrg	if (bc->index_loaded[id])
187b8e80941Smrg		return 0;
188b8e80941Smrg
189b8e80941Smrg	memset(&alu, 0, sizeof(alu));
190b8e80941Smrg	alu.op = ALU_OP1_MOVA_INT;
191b8e80941Smrg	alu.src[0].sel = bc->index_reg[id];
192b8e80941Smrg	alu.src[0].chan = 0;
193b8e80941Smrg	if (bc->chip_class == CAYMAN)
194b8e80941Smrg		alu.dst.sel = id == 0 ? CM_V_SQ_MOVA_DST_CF_IDX0 : CM_V_SQ_MOVA_DST_CF_IDX1;
195b8e80941Smrg
196b8e80941Smrg	alu.last = 1;
197b8e80941Smrg	r = r600_bytecode_add_alu(bc, &alu);
198b8e80941Smrg	if (r)
199b8e80941Smrg		return r;
200b8e80941Smrg
201b8e80941Smrg	bc->ar_loaded = 0; /* clobbered */
202b8e80941Smrg
203b8e80941Smrg	if (bc->chip_class == EVERGREEN) {
204b8e80941Smrg		memset(&alu, 0, sizeof(alu));
205b8e80941Smrg		alu.op = id == 0 ? ALU_OP0_SET_CF_IDX0 : ALU_OP0_SET_CF_IDX1;
206b8e80941Smrg		alu.last = 1;
207b8e80941Smrg		r = r600_bytecode_add_alu(bc, &alu);
208b8e80941Smrg		if (r)
209b8e80941Smrg			return r;
210b8e80941Smrg	}
211b8e80941Smrg
212b8e80941Smrg	/* Must split ALU group as index only applies to following group */
213b8e80941Smrg	if (inside_alu_clause) {
214b8e80941Smrg		type = bc->cf_last->op;
215b8e80941Smrg		if ((r = r600_bytecode_add_cf(bc))) {
216b8e80941Smrg			return r;
217b8e80941Smrg		}
218b8e80941Smrg		bc->cf_last->op = type;
219b8e80941Smrg	}
220b8e80941Smrg
221b8e80941Smrg	bc->index_loaded[id] = 1;
222b8e80941Smrg
223b8e80941Smrg	return 0;
224b8e80941Smrg}
225b8e80941Smrg
226b8e80941Smrgint eg_bytecode_gds_build(struct r600_bytecode *bc, struct r600_bytecode_gds *gds, unsigned id)
227b8e80941Smrg{
228b8e80941Smrg	unsigned gds_op = (r600_isa_fetch_opcode(bc->isa->hw_class, gds->op) >> 8) & 0x3f;
229b8e80941Smrg	unsigned opcode;
230b8e80941Smrg	if (gds->op == FETCH_OP_TF_WRITE) {
231b8e80941Smrg		opcode = 5;
232b8e80941Smrg		gds_op = 0;
233b8e80941Smrg	} else
234b8e80941Smrg		opcode = 4;
235b8e80941Smrg	bc->bytecode[id++] = S_SQ_MEM_GDS_WORD0_MEM_INST(2) |
236b8e80941Smrg		S_SQ_MEM_GDS_WORD0_MEM_OP(opcode) |
237b8e80941Smrg		S_SQ_MEM_GDS_WORD0_SRC_GPR(gds->src_gpr) |
238b8e80941Smrg		S_SQ_MEM_GDS_WORD0_SRC_REL(gds->src_rel) |
239b8e80941Smrg		S_SQ_MEM_GDS_WORD0_SRC_SEL_X(gds->src_sel_x) |
240b8e80941Smrg		S_SQ_MEM_GDS_WORD0_SRC_SEL_Y(gds->src_sel_y) |
241b8e80941Smrg		S_SQ_MEM_GDS_WORD0_SRC_SEL_Z(gds->src_sel_z);
242b8e80941Smrg
243b8e80941Smrg	bc->bytecode[id++] = S_SQ_MEM_GDS_WORD1_DST_GPR(gds->dst_gpr) |
244b8e80941Smrg		S_SQ_MEM_GDS_WORD1_DST_REL(gds->dst_rel) |
245b8e80941Smrg		S_SQ_MEM_GDS_WORD1_GDS_OP(gds_op) |
246b8e80941Smrg		S_SQ_MEM_GDS_WORD1_SRC_GPR(gds->src_gpr2) |
247b8e80941Smrg		S_SQ_MEM_GDS_WORD1_UAV_INDEX_MODE(gds->uav_index_mode) |
248b8e80941Smrg		S_SQ_MEM_GDS_WORD1_UAV_ID(gds->uav_id) |
249b8e80941Smrg		S_SQ_MEM_GDS_WORD1_ALLOC_CONSUME(gds->alloc_consume) |
250b8e80941Smrg		S_SQ_MEM_GDS_WORD1_BCAST_FIRST_REQ(gds->bcast_first_req);
251b8e80941Smrg
252b8e80941Smrg	bc->bytecode[id++] = S_SQ_MEM_GDS_WORD2_DST_SEL_X(gds->dst_sel_x) |
253b8e80941Smrg		S_SQ_MEM_GDS_WORD2_DST_SEL_Y(gds->dst_sel_y) |
254b8e80941Smrg		S_SQ_MEM_GDS_WORD2_DST_SEL_Z(gds->dst_sel_z) |
255b8e80941Smrg		S_SQ_MEM_GDS_WORD2_DST_SEL_W(gds->dst_sel_w);
256b8e80941Smrg	return 0;
257b8e80941Smrg}
258b8e80941Smrg
259b8e80941Smrgint eg_bytecode_alu_build(struct r600_bytecode *bc, struct r600_bytecode_alu *alu, unsigned id)
260b8e80941Smrg{
261b8e80941Smrg	if (alu->is_lds_idx_op) {
262b8e80941Smrg		assert(!alu->src[0].abs && !alu->src[1].abs && !alu->src[2].abs);
263b8e80941Smrg		assert(!alu->src[0].neg && !alu->src[1].neg && !alu->src[2].neg);
264b8e80941Smrg		bc->bytecode[id++] = S_SQ_ALU_WORD0_SRC0_SEL(alu->src[0].sel) |
265b8e80941Smrg			S_SQ_ALU_WORD0_SRC0_REL(alu->src[0].rel) |
266b8e80941Smrg			S_SQ_ALU_WORD0_SRC0_CHAN(alu->src[0].chan) |
267b8e80941Smrg			S_SQ_ALU_WORD0_LDS_IDX_OP_IDX_OFFSET_4(alu->lds_idx >> 4) |
268b8e80941Smrg			S_SQ_ALU_WORD0_SRC1_SEL(alu->src[1].sel) |
269b8e80941Smrg			S_SQ_ALU_WORD0_SRC1_REL(alu->src[1].rel) |
270b8e80941Smrg			S_SQ_ALU_WORD0_SRC1_CHAN(alu->src[1].chan) |
271b8e80941Smrg			S_SQ_ALU_WORD0_LDS_IDX_OP_IDX_OFFSET_5(alu->lds_idx >> 5) |
272b8e80941Smrg			S_SQ_ALU_WORD0_INDEX_MODE(alu->index_mode) |
273b8e80941Smrg			S_SQ_ALU_WORD0_PRED_SEL(alu->pred_sel) |
274b8e80941Smrg			S_SQ_ALU_WORD0_LAST(alu->last);
275b8e80941Smrg	} else {
276b8e80941Smrg		bc->bytecode[id++] = S_SQ_ALU_WORD0_SRC0_SEL(alu->src[0].sel) |
277b8e80941Smrg			S_SQ_ALU_WORD0_SRC0_REL(alu->src[0].rel) |
278b8e80941Smrg			S_SQ_ALU_WORD0_SRC0_CHAN(alu->src[0].chan) |
279b8e80941Smrg			S_SQ_ALU_WORD0_SRC0_NEG(alu->src[0].neg) |
280b8e80941Smrg			S_SQ_ALU_WORD0_SRC1_SEL(alu->src[1].sel) |
281b8e80941Smrg			S_SQ_ALU_WORD0_SRC1_REL(alu->src[1].rel) |
282b8e80941Smrg			S_SQ_ALU_WORD0_SRC1_CHAN(alu->src[1].chan) |
283b8e80941Smrg			S_SQ_ALU_WORD0_SRC1_NEG(alu->src[1].neg) |
284b8e80941Smrg			S_SQ_ALU_WORD0_PRED_SEL(alu->pred_sel) |
285b8e80941Smrg			S_SQ_ALU_WORD0_LAST(alu->last);
286b8e80941Smrg	}
287b8e80941Smrg
288b8e80941Smrg	/* don't replace gpr by pv or ps for destination register */
289b8e80941Smrg	if (alu->is_lds_idx_op) {
290b8e80941Smrg		unsigned lds_op = r600_isa_alu_opcode(bc->isa->hw_class, alu->op);
291b8e80941Smrg		bc->bytecode[id++] =
292b8e80941Smrg			S_SQ_ALU_WORD1_OP3_SRC2_SEL(alu->src[2].sel) |
293b8e80941Smrg			S_SQ_ALU_WORD1_OP3_SRC2_REL(alu->src[2].rel) |
294b8e80941Smrg			S_SQ_ALU_WORD1_OP3_SRC2_CHAN(alu->src[2].chan) |
295b8e80941Smrg			S_SQ_ALU_WORD1_LDS_IDX_OP_IDX_OFFSET_1(alu->lds_idx >> 1) |
296b8e80941Smrg
297b8e80941Smrg			S_SQ_ALU_WORD1_OP3_ALU_INST(lds_op & 0xff) |
298b8e80941Smrg			S_SQ_ALU_WORD1_BANK_SWIZZLE(alu->bank_swizzle) |
299b8e80941Smrg			S_SQ_ALU_WORD1_LDS_IDX_OP_LDS_OP((lds_op >> 8) & 0xff) |
300b8e80941Smrg			S_SQ_ALU_WORD1_LDS_IDX_OP_IDX_OFFSET_0(alu->lds_idx) |
301b8e80941Smrg			S_SQ_ALU_WORD1_LDS_IDX_OP_IDX_OFFSET_2(alu->lds_idx >> 2) |
302b8e80941Smrg			S_SQ_ALU_WORD1_DST_CHAN(alu->dst.chan) |
303b8e80941Smrg			S_SQ_ALU_WORD1_LDS_IDX_OP_IDX_OFFSET_3(alu->lds_idx >> 3);
304b8e80941Smrg
305b8e80941Smrg	} else if (alu->is_op3) {
306b8e80941Smrg		assert(!alu->src[0].abs && !alu->src[1].abs && !alu->src[2].abs);
307b8e80941Smrg		bc->bytecode[id++] = S_SQ_ALU_WORD1_DST_GPR(alu->dst.sel) |
308b8e80941Smrg					S_SQ_ALU_WORD1_DST_CHAN(alu->dst.chan) |
309b8e80941Smrg			                S_SQ_ALU_WORD1_DST_REL(alu->dst.rel) |
310b8e80941Smrg			                S_SQ_ALU_WORD1_CLAMP(alu->dst.clamp) |
311b8e80941Smrg					S_SQ_ALU_WORD1_OP3_SRC2_SEL(alu->src[2].sel) |
312b8e80941Smrg					S_SQ_ALU_WORD1_OP3_SRC2_REL(alu->src[2].rel) |
313b8e80941Smrg					S_SQ_ALU_WORD1_OP3_SRC2_CHAN(alu->src[2].chan) |
314b8e80941Smrg					S_SQ_ALU_WORD1_OP3_SRC2_NEG(alu->src[2].neg) |
315b8e80941Smrg					S_SQ_ALU_WORD1_OP3_ALU_INST(r600_isa_alu_opcode(bc->isa->hw_class, alu->op)) |
316b8e80941Smrg					S_SQ_ALU_WORD1_BANK_SWIZZLE(alu->bank_swizzle);
317b8e80941Smrg	} else {
318b8e80941Smrg		bc->bytecode[id++] = S_SQ_ALU_WORD1_DST_GPR(alu->dst.sel) |
319b8e80941Smrg					S_SQ_ALU_WORD1_DST_CHAN(alu->dst.chan) |
320b8e80941Smrg			                S_SQ_ALU_WORD1_DST_REL(alu->dst.rel) |
321b8e80941Smrg			                S_SQ_ALU_WORD1_CLAMP(alu->dst.clamp) |
322b8e80941Smrg					S_SQ_ALU_WORD1_OP2_SRC0_ABS(alu->src[0].abs) |
323b8e80941Smrg					S_SQ_ALU_WORD1_OP2_SRC1_ABS(alu->src[1].abs) |
324b8e80941Smrg					S_SQ_ALU_WORD1_OP2_WRITE_MASK(alu->dst.write) |
325b8e80941Smrg					S_SQ_ALU_WORD1_OP2_OMOD(alu->omod) |
326b8e80941Smrg					S_SQ_ALU_WORD1_OP2_ALU_INST(r600_isa_alu_opcode(bc->isa->hw_class, alu->op)) |
327b8e80941Smrg					S_SQ_ALU_WORD1_BANK_SWIZZLE(alu->bank_swizzle) |
328b8e80941Smrg			                S_SQ_ALU_WORD1_OP2_UPDATE_EXECUTE_MASK(alu->execute_mask) |
329b8e80941Smrg			                S_SQ_ALU_WORD1_OP2_UPDATE_PRED(alu->update_pred);
330b8e80941Smrg	}
331b8e80941Smrg	return 0;
332b8e80941Smrg}
333