assembler: Put struct opcode_desc back in brw_context.h
[platform/upstream/intel-gpu-tools.git] / assembler / gen4asm.h
1 /* -*- c-basic-offset: 8 -*- */
2 /*
3  * Copyright © 2006 Intel Corporation
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice (including the next
13  * paragraph) shall be included in all copies or substantial portions of the
14  * Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  *
24  * Authors:
25  *    Eric Anholt <eric@anholt.net>
26  *
27  */
28
29 #ifndef __GEN4ASM_H__
30 #define __GEN4ASM_H__
31
32 #include <inttypes.h>
33 #include <stdbool.h>
34 #include <assert.h>
35
36 #include "brw_reg.h"
37
38 typedef unsigned char GLubyte;
39 typedef short GLshort;
40 typedef unsigned int GLuint;
41 typedef int GLint;
42 typedef float GLfloat;
43
44 extern long int gen_level;
45 extern int advanced_flag;
46 extern int errors;
47
48 #define WARN_ALWAYS     (1 << 0)
49 #define WARN_ALL        (1 << 31)
50 extern unsigned int warning_flags;
51
52 extern char *input_filename;
53
54 extern struct brw_context genasm_context;
55 extern struct brw_compile genasm_compile;
56
57 /* Predicate for Gen X and above */
58 #define IS_GENp(x) (gen_level >= (x)*10)
59
60 /* Predicate for Gen X exactly */
61 #define IS_GENx(x) (gen_level >= (x)*10 && gen_level < ((x)+1)*10)
62
63 /* Predicate to match Haswell processors */
64 #define IS_HASWELL(x) (gen_level == 75)
65
66 #include "brw_defines.h"
67 #include "brw_structs.h"
68
69 void yyerror (char *msg);
70
71 #define STRUCT_SIZE_ASSERT(TYPE, SIZE) \
72 typedef struct { \
73           char compile_time_assert_ ## TYPE ## _size[ \
74               (sizeof (struct TYPE) == (SIZE)) ? 1 : -1]; \
75         } _ ## TYPE ## SizeCheck
76
77 /* ensure nobody changes the size of struct brw_instruction */
78 STRUCT_SIZE_ASSERT(brw_instruction, 16);
79
80 #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
81
82 struct condition {
83         int cond;
84         int flag_reg_nr;
85         int flag_subreg_nr;
86 };
87
88 struct predicate {
89     unsigned pred_control:4;
90     unsigned pred_inverse:1;
91     unsigned flag_reg_nr:1;
92     unsigned flag_subreg_nr:1;
93 };
94
95 struct options {
96     unsigned access_mode:1;
97     unsigned compression_control:2; /* gen6: quater control */
98     unsigned thread_control:2;
99     unsigned dependency_control:2;
100     unsigned mask_control:1;
101     unsigned debug_control:1;
102     unsigned acc_wr_control:1;
103
104     unsigned end_of_thread:1;
105 };
106
107 struct region {
108     int vert_stride, width, horiz_stride;
109     int is_default;        
110 };
111 struct regtype {
112     int type;
113     int is_default;
114 };
115
116 /**
117  * This structure is the internal representation of source operands in the 
118  * parser.
119  */
120 struct src_operand {
121         struct brw_reg reg;
122         int default_region;
123         uint32_t imm32; /* set if src_operand is expressing a branch offset */
124         char *reloc_target; /* bspec: branching instructions JIP and UIP are source operands */
125 } src_operand;
126
127 typedef struct {
128     enum {
129         imm32_d, imm32_f
130     } r;
131     union {
132         uint32_t    d;
133         float       f;
134         int32_t     signed_d;
135     } u;
136 } imm32_t;
137
138 enum assembler_instruction_type {
139     GEN4ASM_INSTRUCTION_GEN,
140     GEN4ASM_INSTRUCTION_GEN_RELOCATABLE,
141     GEN4ASM_INSTRUCTION_LABEL,
142 };
143
144 struct label_instruction {
145     char   *name;
146 };
147
148 struct relocation {
149     char *first_reloc_target, *second_reloc_target; // JIP and UIP respectively
150     GLint first_reloc_offset, second_reloc_offset; // in number of instructions
151 };
152
153 /**
154  * This structure is just the list container for instructions accumulated by
155  * the parser and labels.
156  */
157 struct brw_program_instruction {
158     enum assembler_instruction_type type;
159     unsigned inst_offset;
160     union {
161         struct brw_instruction gen;
162         struct label_instruction label;
163     } insn;
164     struct relocation reloc;
165     struct brw_program_instruction *next;
166 };
167
168 static inline bool is_label(struct brw_program_instruction *instruction)
169 {
170     return instruction->type == GEN4ASM_INSTRUCTION_LABEL;
171 }
172
173 static inline char *label_name(struct brw_program_instruction *i)
174 {
175     assert(is_label(i));
176     return i->insn.label.name;
177 }
178
179 static inline bool is_relocatable(struct brw_program_instruction *intruction)
180 {
181     return intruction->type == GEN4ASM_INSTRUCTION_GEN_RELOCATABLE;
182 }
183
184 /**
185  * This structure is a list of instructions.  It is the final output of the
186  * parser.
187  */
188 struct brw_program {
189         struct brw_program_instruction *first;
190         struct brw_program_instruction *last;
191 };
192
193 extern struct brw_program compiled_program;
194
195 #define TYPE_B_INDEX            0
196 #define TYPE_UB_INDEX           1
197 #define TYPE_W_INDEX            2
198 #define TYPE_UW_INDEX           3
199 #define TYPE_D_INDEX            4
200 #define TYPE_UD_INDEX           5
201 #define TYPE_F_INDEX            6
202
203 #define TOTAL_TYPES             7
204
205 struct program_defaults {
206     int execute_size;
207     int execute_type[TOTAL_TYPES];
208     int register_type;
209     int register_type_regfile;
210     struct region source_region;
211     struct region source_region_type[TOTAL_TYPES];
212     struct region dest_region;
213     struct region dest_region_type[TOTAL_TYPES];
214 };
215 extern struct program_defaults program_defaults;
216
217 struct declared_register {
218     char *name;
219     struct brw_reg reg;
220     int element_size;
221     struct region src_region;
222     int dst_region;
223     int type;
224 };
225 struct declared_register *find_register(char *name);
226 void insert_register(struct declared_register *reg);
227
228 int yyparse(void);
229 int yylex(void);
230 int yylex_destroy(void);
231
232 char *
233 lex_text(void);
234
235 #endif /* __GEN4ASM_H__ */