r600g: always create reverse lookup isa tables
[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 int r600_isa_init(struct r600_context *ctx, struct r600_isa *isa) {
31 unsigned i;
32
33 assert(ctx->chip_class >= R600 && ctx->chip_class <= CAYMAN);
34 isa->hw_class = ctx->chip_class - R600;
35
36 /* reverse lookup maps are required for bytecode parsing */
37
38 isa->alu_op2_map = calloc(256, sizeof(unsigned));
39 if (!isa->alu_op2_map)
40 return -1;
41 isa->alu_op3_map = calloc(256, sizeof(unsigned));
42 if (!isa->alu_op3_map)
43 return -1;
44 isa->fetch_map = calloc(256, sizeof(unsigned));
45 if (!isa->fetch_map)
46 return -1;
47 isa->cf_map = calloc(256, sizeof(unsigned));
48 if (!isa->cf_map)
49 return -1;
50
51 for (i = 0; i < TABLE_SIZE(alu_op_table); ++i) {
52 const struct alu_op_info *op = &alu_op_table[i];
53 unsigned opc;
54 if (op->flags & AF_LDS || op->slots[isa->hw_class] == 0)
55 continue;
56 opc = op->opcode[isa->hw_class >> 1];
57 assert(opc != -1);
58 if (op->src_count == 3)
59 isa->alu_op3_map[opc] = i + 1;
60 else
61 isa->alu_op2_map[opc] = i + 1;
62 }
63
64 for (i = 0; i < TABLE_SIZE(fetch_op_table); ++i) {
65 const struct fetch_op_info *op = &fetch_op_table[i];
66 unsigned opc = op->opcode[isa->hw_class];
67 if ((op->flags & FF_GDS) || ((opc & 0xFF) != opc))
68 continue; /* ignore GDS ops and INST_MOD versions for now */
69 isa->fetch_map[opc] = i + 1;
70 }
71
72 for (i = 0; i < TABLE_SIZE(cf_op_table); ++i) {
73 const struct cf_op_info *op = &cf_op_table[i];
74 unsigned opc = op->opcode[isa->hw_class];
75 if (opc == -1)
76 continue;
77 /* using offset for CF_ALU_xxx opcodes because they overlap with other
78 * CF opcodes (they use different encoding in hw) */
79 if (op->flags & CF_ALU)
80 opc += 0x80;
81 isa->cf_map[opc] = i + 1;
82 }
83
84 return 0;
85 }
86
87 int r600_isa_destroy(struct r600_isa *isa) {
88
89 if (!isa)
90 return 0;
91
92 if (isa->alu_op2_map)
93 free(isa->alu_op2_map);
94 if (isa->alu_op3_map)
95 free(isa->alu_op3_map);
96 if (isa->fetch_map)
97 free(isa->fetch_map);
98 if (isa->cf_map)
99 free(isa->cf_map);
100
101 free(isa);
102 return 0;
103 }
104
105
106