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