r600: move fetch_op_table to .c file
[mesa.git] / src / gallium / drivers / r600 / r600_isa.c
1 /*
2 * Copyright 2012 Vadim Girlin <vadimgirlin@gmail.com>
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 * Authors:
24 * Vadim Girlin
25 */
26
27 #include "r600_pipe.h"
28 #include "r600_isa.h"
29
30 static const struct fetch_op_info fetch_op_table[] = {
31 {"VFETCH", { 0x000000, 0x000000, 0x000000, 0x000000 }, FF_VTX },
32 {"SEMFETCH", { 0x000001, 0x000001, 0x000001, 0x000001 }, FF_VTX },
33
34 {"READ_SCRATCH", { -1, 0x000002, 0x000002, 0x000002 }, FF_VTX | FF_MEM },
35 {"READ_REDUCT", { -1, 0x000102, -1, -1 }, FF_VTX | FF_MEM },
36 {"READ_MEM", { -1, 0x000202, 0x000202, 0x000202 }, FF_VTX | FF_MEM },
37 {"DS_LOCAL_WRITE", { -1, 0x000402, -1, -1 }, FF_VTX | FF_MEM },
38 {"DS_LOCAL_READ", { -1, 0x000502, -1, -1 }, FF_VTX | FF_MEM },
39
40 {"GDS_ADD", { -1, -1, 0x020002, 0x020002 }, FF_GDS },
41 {"GDS_SUB", { -1, -1, 0x020102, 0x020102 }, FF_GDS },
42 {"GDS_RSUB", { -1, -1, 0x020202, 0x020202 }, FF_GDS },
43 {"GDS_INC", { -1, -1, 0x020302, 0x020302 }, FF_GDS },
44 {"GDS_DEC", { -1, -1, 0x020402, 0x020402 }, FF_GDS },
45 {"GDS_MIN_INT", { -1, -1, 0x020502, 0x020502 }, FF_GDS },
46 {"GDS_MAX_INT", { -1, -1, 0x020602, 0x020602 }, FF_GDS },
47 {"GDS_MIN_UINT", { -1, -1, 0x020702, 0x020702 }, FF_GDS },
48 {"GDS_MAX_UINT", { -1, -1, 0x020802, 0x020802 }, FF_GDS },
49 {"GDS_AND", { -1, -1, 0x020902, 0x020902 }, FF_GDS },
50 {"GDS_OR", { -1, -1, 0x020A02, 0x020A02 }, FF_GDS },
51 {"GDS_XOR", { -1, -1, 0x020B02, 0x020B02 }, FF_GDS },
52 {"GDS_MSKOR", { -1, -1, 0x030C02, 0x030C02 }, FF_GDS },
53 {"GDS_WRITE", { -1, -1, 0x020D02, 0x020D02 }, FF_GDS },
54 {"GDS_WRITE_REL", { -1, -1, 0x030E02, 0x030E02 }, FF_GDS },
55 {"GDS_WRITE2", { -1, -1, 0x030F02, 0x030F02 }, FF_GDS },
56 {"GDS_CMP_STORE", { -1, -1, 0x031002, 0x031002 }, FF_GDS },
57 {"GDS_CMP_STORE_SPF", { -1, -1, 0x031102, 0x031102 }, FF_GDS },
58 {"GDS_BYTE_WRITE", { -1, -1, 0x021202, 0x021202 }, FF_GDS },
59 {"GDS_SHORT_WRITE", { -1, -1, 0x021302, 0x021302 }, FF_GDS },
60 {"GDS_ADD_RET", { -1, -1, 0x122002, 0x122002 }, FF_GDS },
61 {"GDS_SUB_RET", { -1, -1, 0x122102, 0x122102 }, FF_GDS },
62 {"GDS_RSUB_RET", { -1, -1, 0x122202, 0x122202 }, FF_GDS },
63 {"GDS_INC_RET", { -1, -1, 0x122302, 0x122302 }, FF_GDS },
64 {"GDS_DEC_RET", { -1, -1, 0x122402, 0x122402 }, FF_GDS },
65 {"GDS_MIN_INT_RET", { -1, -1, 0x122502, 0x122502 }, FF_GDS },
66 {"GDS_MAX_INT_RET", { -1, -1, 0x122602, 0x122602 }, FF_GDS },
67 {"GDS_MIN_UINT_RET", { -1, -1, 0x122702, 0x122702 }, FF_GDS },
68 {"GDS_MAX_UINT_RET", { -1, -1, 0x122802, 0x122802 }, FF_GDS },
69 {"GDS_AND_RET", { -1, -1, 0x122902, 0x122902 }, FF_GDS },
70 {"GDS_OR_RET", { -1, -1, 0x122A02, 0x122A02 }, FF_GDS },
71 {"GDS_XOR_RET", { -1, -1, 0x122B02, 0x122B02 }, FF_GDS },
72 {"GDS_MSKOR_RET", { -1, -1, 0x132C02, 0x132C02 }, FF_GDS },
73 {"GDS_XCHG_RET", { -1, -1, 0x122D02, 0x122D02 }, FF_GDS },
74 {"GDS_XCHG_REL_RET", { -1, -1, 0x232E02, 0x232E02 }, FF_GDS },
75 {"GDS_XCHG2_RET", { -1, -1, 0x232F02, 0x232F02 }, FF_GDS },
76 {"GDS_CMP_XCHG_RET", { -1, -1, 0x133002, 0x133002 }, FF_GDS },
77 {"GDS_CMP_XCHG_SPF_RET", { -1, -1, 0x133102, 0x133102 }, FF_GDS },
78 {"GDS_READ_RET", { -1, -1, 0x113202, 0x113202 }, FF_GDS },
79 {"GDS_READ_REL_RET", { -1, -1, 0x213302, 0x213302 }, FF_GDS },
80 {"GDS_READ2_RET", { -1, -1, 0x223402, 0x223402 }, FF_GDS },
81 {"GDS_READWRITE_RET", { -1, -1, 0x133502, 0x133502 }, FF_GDS },
82 {"GDS_BYTE_READ_RET", { -1, -1, 0x113602, 0x113602 }, FF_GDS },
83 {"GDS_UBYTE_READ_RET", { -1, -1, 0x113702, 0x113702 }, FF_GDS },
84 {"GDS_SHORT_READ_RET", { -1, -1, 0x113802, 0x113802 }, FF_GDS },
85 {"GDS_USHORT_READ_RET", { -1, -1, 0x113902, 0x113902 }, FF_GDS },
86 {"GDS_ATOMIC_ORDERED_ALLOC", { -1, -1, 0x113F02, 0x113F02 }, FF_GDS },
87
88 {"TF_WRITE", { -1, -1, 0x020502, 0x020502 }, FF_GDS },
89
90 {"DS_GLOBAL_WRITE", { -1, 0x000602, -1, -1 }, 0 },
91 {"DS_GLOBAL_READ", { -1, 0x000702, -1, -1 }, 0 },
92
93 {"LD", { 0x000003, 0x000003, 0x000003, 0x000003 }, 0 },
94 {"LDFPTR", { -1, -1, 0x000103, 0x000103 }, 0 },
95 {"GET_TEXTURE_RESINFO", { 0x000004, 0x000004, 0x000004, 0x000004 }, 0 },
96 {"GET_NUMBER_OF_SAMPLES", { 0x000005, 0x000005, 0x000005, 0x000005 }, 0 },
97 {"GET_LOD", { 0x000006, 0x000006, 0x000006, 0x000006 }, 0 },
98 {"GET_GRADIENTS_H", { 0x000007, 0x000007, 0x000007, 0x000007 }, FF_GETGRAD },
99 {"GET_GRADIENTS_V", { 0x000008, 0x000008, 0x000008, 0x000008 }, FF_GETGRAD },
100 {"GET_GRADIENTS_H_FINE", { -1, -1, 0x000107, 0x000107 }, FF_GETGRAD },
101 {"GET_GRADIENTS_V_FINE", { -1, -1, 0x000108, 0x000108 }, FF_GETGRAD },
102 {"GET_LERP", { 0x000009, 0x000009, -1, -1 }, 0 },
103 {"SET_TEXTURE_OFFSETS", { -1, -1, 0x000009, 0x000009 }, FF_SET_TEXTURE_OFFSETS },
104 {"KEEP_GRADIENTS", { -1, 0x00000A, 0x00000A, 0x00000A }, 0 },
105 {"SET_GRADIENTS_H", { 0x00000B, 0x00000B, 0x00000B, 0x00000B }, FF_SETGRAD },
106 {"SET_GRADIENTS_V", { 0x00000C, 0x00000C, 0x00000C, 0x00000C }, FF_SETGRAD },
107 {"SET_GRADIENTS_H_COARSE", { -1, -1, -1, 0x00010B }, FF_SETGRAD },
108 {"SET_GRADIENTS_V_COARSE", { -1, -1, -1, 0x00010C }, FF_SETGRAD },
109 {"SET_GRADIENTS_H_PACKED_FINE", { -1, -1, -1, 0x00020B }, FF_SETGRAD },
110 {"SET_GRADIENTS_V_PACKED_FINE", { -1, -1, -1, 0x00020C }, FF_SETGRAD },
111 {"SET_GRADIENTS_H_PACKED_COARSE", { -1, -1, -1, 0x00030B }, FF_SETGRAD },
112 {"SET_GRADIENTS_V_PACKED_COARSE", { -1, -1, -1, 0x00030C }, FF_SETGRAD },
113 {"PASS", { 0x00000D, 0x00000D, 0x00000D, 0x00000D }, 0 }, /* ???? 700, eg, cm docs - marked as reserved */
114 {"PASS1", { -1, -1, 0x00010D, 0x00010D }, 0 },
115 {"PASS2", { -1, -1, 0x00020D, 0x00020D }, 0 },
116 {"PASS3", { -1, -1, 0x00030D, 0x00030D }, 0 },
117 {"SET_CUBEMAP_INDEX", { 0x00000E, 0x00000E, -1, -1 }, 0 },
118 {"GET_BUFFER_RESINFO", { -1, -1, 0x00000E, 0x00000E }, FF_VTX },
119 {"FETCH4", { 0x00000F, 0x00000F, -1, -1 }, 0 },
120
121 {"SAMPLE", { 0x000010, 0x000010, 0x000010, 0x000010 }, FF_TEX },
122 {"SAMPLE_L", { 0x000011, 0x000011, 0x000011, 0x000011 }, FF_TEX },
123 {"SAMPLE_LB", { 0x000012, 0x000012, 0x000012, 0x000012 }, FF_TEX },
124 {"SAMPLE_LZ", { 0x000013, 0x000013, 0x000013, 0x000013 }, FF_TEX },
125 {"SAMPLE_G", { 0x000014, 0x000014, 0x000014, 0x000014 }, FF_TEX | FF_USEGRAD },
126 {"SAMPLE_G_L", { 0x000015, 0x000015, -1, -1 }, FF_TEX | FF_USEGRAD},
127 {"GATHER4", { -1, -1, 0x000015, 0x000015 }, FF_TEX },
128 {"SAMPLE_G_LB", { 0x000016, 0x000016, 0x000016, 0x000016 }, FF_TEX | FF_USEGRAD},
129 {"SAMPLE_G_LZ", { 0x000017, 0x000017, -1, -1 }, FF_TEX | FF_USEGRAD},
130 {"GATHER4_O", { -1, -1, 0x000017, 0x000017 }, FF_TEX | FF_USE_TEXTURE_OFFSETS},
131 {"SAMPLE_C", { 0x000018, 0x000018, 0x000018, 0x000018 }, FF_TEX },
132 {"SAMPLE_C_L", { 0x000019, 0x000019, 0x000019, 0x000019 }, FF_TEX },
133 {"SAMPLE_C_LB", { 0x00001A, 0x00001A, 0x00001A, 0x00001A }, FF_TEX },
134 {"SAMPLE_C_LZ", { 0x00001B, 0x00001B, 0x00001B, 0x00001B }, FF_TEX },
135 {"SAMPLE_C_G", { 0x00001C, 0x00001C, 0x00001C, 0x00001C }, FF_TEX | FF_USEGRAD},
136 {"SAMPLE_C_G_L", { 0x00001D, 0x00001D, -1, -1 }, FF_TEX | FF_USEGRAD},
137 {"GATHER4_C", { -1, -1, 0x00001D, 0x00001D }, FF_TEX },
138 {"SAMPLE_C_G_LB", { 0x00001E, 0x00001E, 0x00001E, 0x00001E }, FF_TEX | FF_USEGRAD},
139 {"SAMPLE_C_G_LZ", { 0x00001F, 0x00001F, -1, -1 }, FF_TEX | FF_USEGRAD},
140 {"GATHER4_C_O", { -1, -1, 0x00001F, 0x00001F }, FF_TEX | FF_USE_TEXTURE_OFFSETS}
141 };
142
143 const struct fetch_op_info *
144 r600_isa_fetch(unsigned op) {
145 assert (op < ARRAY_SIZE(fetch_op_table));
146 return &fetch_op_table[op];
147 }
148
149 int r600_isa_init(struct r600_context *ctx, struct r600_isa *isa) {
150 unsigned i;
151
152 assert(ctx->b.chip_class >= R600 && ctx->b.chip_class <= CAYMAN);
153 isa->hw_class = ctx->b.chip_class - R600;
154
155 /* reverse lookup maps are required for bytecode parsing */
156
157 isa->alu_op2_map = calloc(256, sizeof(unsigned));
158 if (!isa->alu_op2_map)
159 return -1;
160 isa->alu_op3_map = calloc(256, sizeof(unsigned));
161 if (!isa->alu_op3_map)
162 return -1;
163 isa->fetch_map = calloc(256, sizeof(unsigned));
164 if (!isa->fetch_map)
165 return -1;
166 isa->cf_map = calloc(256, sizeof(unsigned));
167 if (!isa->cf_map)
168 return -1;
169
170 for (i = 0; i < TABLE_SIZE(alu_op_table); ++i) {
171 const struct alu_op_info *op = &alu_op_table[i];
172 unsigned opc;
173 if (op->flags & AF_LDS || op->slots[isa->hw_class] == 0)
174 continue;
175 opc = op->opcode[isa->hw_class >> 1];
176 assert(opc != -1);
177 if (op->src_count == 3)
178 isa->alu_op3_map[opc] = i + 1;
179 else
180 isa->alu_op2_map[opc] = i + 1;
181 }
182
183 for (i = 0; i < TABLE_SIZE(fetch_op_table); ++i) {
184 const struct fetch_op_info *op = &fetch_op_table[i];
185 unsigned opc = op->opcode[isa->hw_class];
186 if ((op->flags & FF_GDS) || ((opc & 0xFF) != opc))
187 continue; /* ignore GDS ops and INST_MOD versions for now */
188 isa->fetch_map[opc] = i + 1;
189 }
190
191 for (i = 0; i < TABLE_SIZE(cf_op_table); ++i) {
192 const struct cf_op_info *op = &cf_op_table[i];
193 unsigned opc = op->opcode[isa->hw_class];
194 if (opc == -1)
195 continue;
196 /* using offset for CF_ALU_xxx opcodes because they overlap with other
197 * CF opcodes (they use different encoding in hw) */
198 if (op->flags & CF_ALU)
199 opc += 0x80;
200 isa->cf_map[opc] = i + 1;
201 }
202
203 return 0;
204 }
205
206 int r600_isa_destroy(struct r600_isa *isa) {
207
208 if (!isa)
209 return 0;
210
211 free(isa->alu_op2_map);
212 free(isa->alu_op3_map);
213 free(isa->fetch_map);
214 free(isa->cf_map);
215
216 free(isa);
217 return 0;
218 }
219
220
221