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