blob: 6b957e2875e48c1528611d42021f9847440b5469 [file] [log] [blame]
Eric Anholt22a10632006-08-22 10:15:33 -07001/* -*- 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
Damien Lespiaua66cd602013-01-19 22:50:57 +000029#ifndef __GEN4ASM_H__
30#define __GEN4ASM_H__
31
Eric Anholt09d8be42006-09-01 15:37:00 -070032#include <inttypes.h>
Damien Lespiaua45a4712013-01-21 19:28:41 +000033#include <stdbool.h>
34#include <assert.h>
Eric Anholt6a88ada2006-08-28 22:11:18 -070035
Damien Lespiaucce4fc22013-01-23 15:13:55 +000036#include "brw_reg.h"
Damien Lespiaud9afa5b2013-02-04 12:12:29 +000037#include "brw_defines.h"
38#include "brw_structs.h"
Damien Lespiauaf4d37d2013-01-31 02:16:08 +000039#include "gen8_instruction.h"
Damien Lespiaucce4fc22013-01-23 15:13:55 +000040
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -040041extern long int gen_level;
Damien Lespiau1d53e182013-01-27 11:05:50 +000042extern int advanced_flag;
43extern int errors;
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -040044
Damien Lespiaud70e9f82013-01-26 23:09:42 +000045#define WARN_ALWAYS (1 << 0)
46#define WARN_ALL (1 << 31)
47extern unsigned int warning_flags;
48
Damien Lespiau1eb622a2013-01-27 01:32:52 +000049extern char *input_filename;
50
Damien Lespiau9fcc1bd2013-01-24 16:16:35 +000051extern struct brw_context genasm_context;
52extern struct brw_compile genasm_compile;
53
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -040054/* Predicate for Gen X and above */
55#define IS_GENp(x) (gen_level >= (x)*10)
56
57/* Predicate for Gen X exactly */
58#define IS_GENx(x) (gen_level >= (x)*10 && gen_level < ((x)+1)*10)
59
60/* Predicate to match Haswell processors */
61#define IS_HASWELL(x) (gen_level == 75)
62
Eric Anholt22a10632006-08-22 10:15:33 -070063void yyerror (char *msg);
64
Damien Lespiauc74c80c2013-01-21 22:12:10 +000065#define STRUCT_SIZE_ASSERT(TYPE, SIZE) \
66typedef struct { \
67 char compile_time_assert_ ## TYPE ## _size[ \
68 (sizeof (struct TYPE) == (SIZE)) ? 1 : -1]; \
69 } _ ## TYPE ## SizeCheck
70
71/* ensure nobody changes the size of struct brw_instruction */
72STRUCT_SIZE_ASSERT(brw_instruction, 16);
73
Damien Lespiaue9172aa2013-01-26 22:44:45 +000074#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
75
Xiang, Haihao27b43032010-12-13 16:07:16 +080076struct condition {
77 int cond;
Xiang, Haihao3ffbe962012-07-17 15:05:31 +080078 int flag_reg_nr;
Xiang, Haihao2f772dd2012-07-17 14:18:54 +080079 int flag_subreg_nr;
Xiang, Haihao27b43032010-12-13 16:07:16 +080080};
81
Damien Lespiaudfe6ada2013-01-30 22:32:07 +000082struct predicate {
83 unsigned pred_control:4;
84 unsigned pred_inverse:1;
85 unsigned flag_reg_nr:1;
86 unsigned flag_subreg_nr:1;
87};
88
Damien Lespiau6bf3aa82013-01-30 23:25:19 +000089struct options {
90 unsigned access_mode:1;
91 unsigned compression_control:2; /* gen6: quater control */
92 unsigned thread_control:2;
93 unsigned dependency_control:2;
94 unsigned mask_control:1;
95 unsigned debug_control:1;
96 unsigned acc_wr_control:1;
97
98 unsigned end_of_thread:1;
99};
100
Xiang, Haihao27b43032010-12-13 16:07:16 +0800101struct region {
102 int vert_stride, width, horiz_stride;
Damien Lespiau2d8b92a2013-02-01 14:54:46 +0000103 int is_default;
Xiang, Haihao27b43032010-12-13 16:07:16 +0800104};
105struct regtype {
106 int type;
107 int is_default;
108};
Eric Anholt74c81af2006-08-30 11:10:45 -0700109
110/**
Damien Lespiau2d8b92a2013-02-01 14:54:46 +0000111 * This structure is the internal representation of source operands in the
Eric Anholt6a88ada2006-08-28 22:11:18 -0700112 * parser.
113 */
114struct src_operand {
Damien Lespiau9d5a87a2013-01-23 22:29:23 +0000115 struct brw_reg reg;
Xiang, Haihao27b43032010-12-13 16:07:16 +0800116 int default_region;
Damien Lespiau9c72beb2013-01-25 15:48:58 +0000117 uint32_t imm32; /* set if src_operand is expressing a branch offset */
Homer Hsingb0b540f2012-09-21 10:06:20 +0800118 char *reloc_target; /* bspec: branching instructions JIP and UIP are source operands */
Eric Anholt6a88ada2006-08-28 22:11:18 -0700119} src_operand;
120
Keith Packard2d4d4012008-03-30 00:58:28 -0700121typedef struct {
122 enum {
123 imm32_d, imm32_f
124 } r;
125 union {
126 uint32_t d;
127 float f;
Xiang, Haihao27b43032010-12-13 16:07:16 +0800128 int32_t signed_d;
Keith Packard2d4d4012008-03-30 00:58:28 -0700129 } u;
130} imm32_t;
131
Damien Lespiaua45a4712013-01-21 19:28:41 +0000132enum assembler_instruction_type {
133 GEN4ASM_INSTRUCTION_GEN,
Damien Lespiau79c62f12013-01-21 21:41:36 +0000134 GEN4ASM_INSTRUCTION_GEN_RELOCATABLE,
Damien Lespiauaf4d37d2013-01-31 02:16:08 +0000135 GEN4ASM_INSTRUCTION_GEN8,
136 GEN4ASM_INSTRUCTION_GEN8_RELOCATABLE,
Damien Lespiaua45a4712013-01-21 19:28:41 +0000137 GEN4ASM_INSTRUCTION_LABEL,
138};
139
140struct label_instruction {
141 char *name;
142};
143
Damien Lespiau9b78f742013-01-30 17:09:17 +0000144struct relocation {
Damien Lespiau79c62f12013-01-21 21:41:36 +0000145 char *first_reloc_target, *second_reloc_target; // JIP and UIP respectively
Damien Lespiauf0365d42013-02-04 12:02:18 +0000146 int first_reloc_offset, second_reloc_offset; // in number of instructions
Damien Lespiau79c62f12013-01-21 21:41:36 +0000147};
148
Eric Anholt6a88ada2006-08-28 22:11:18 -0700149/**
Eric Anholt22a10632006-08-22 10:15:33 -0700150 * This structure is just the list container for instructions accumulated by
Zou Nanhaibe9bcee2008-12-09 18:38:54 -0800151 * the parser and labels.
Eric Anholt22a10632006-08-22 10:15:33 -0700152 */
153struct brw_program_instruction {
Damien Lespiaua45a4712013-01-21 19:28:41 +0000154 enum assembler_instruction_type type;
155 unsigned inst_offset;
156 union {
157 struct brw_instruction gen;
Damien Lespiauaf4d37d2013-01-31 02:16:08 +0000158 struct gen8_instruction gen8;
Damien Lespiaua45a4712013-01-21 19:28:41 +0000159 struct label_instruction label;
Damien Lespiaud0080642013-01-30 12:31:45 +0000160 } insn;
Damien Lespiau9b78f742013-01-30 17:09:17 +0000161 struct relocation reloc;
Damien Lespiaua45a4712013-01-21 19:28:41 +0000162 struct brw_program_instruction *next;
Eric Anholt22a10632006-08-22 10:15:33 -0700163};
164
Damien Lespiaua45a4712013-01-21 19:28:41 +0000165static inline bool is_label(struct brw_program_instruction *instruction)
166{
167 return instruction->type == GEN4ASM_INSTRUCTION_LABEL;
168}
169
170static inline char *label_name(struct brw_program_instruction *i)
171{
172 assert(is_label(i));
Damien Lespiaud0080642013-01-30 12:31:45 +0000173 return i->insn.label.name;
Damien Lespiaua45a4712013-01-21 19:28:41 +0000174}
175
Damien Lespiau79c62f12013-01-21 21:41:36 +0000176static inline bool is_relocatable(struct brw_program_instruction *intruction)
177{
178 return intruction->type == GEN4ASM_INSTRUCTION_GEN_RELOCATABLE;
179}
180
Eric Anholt22a10632006-08-22 10:15:33 -0700181/**
182 * This structure is a list of instructions. It is the final output of the
183 * parser.
184 */
185struct brw_program {
186 struct brw_program_instruction *first;
Zou Nan haidb8aedc2010-04-21 11:02:21 +0800187 struct brw_program_instruction *last;
Eric Anholt22a10632006-08-22 10:15:33 -0700188};
189
190extern struct brw_program compiled_program;
Eric Anholtf2f18562006-08-22 12:46:37 -0700191
Xiang, Haihao27b43032010-12-13 16:07:16 +0800192#define TYPE_B_INDEX 0
193#define TYPE_UB_INDEX 1
194#define TYPE_W_INDEX 2
195#define TYPE_UW_INDEX 3
196#define TYPE_D_INDEX 4
197#define TYPE_UD_INDEX 5
198#define TYPE_F_INDEX 6
199
200#define TOTAL_TYPES 7
201
202struct program_defaults {
203 int execute_size;
204 int execute_type[TOTAL_TYPES];
205 int register_type;
206 int register_type_regfile;
207 struct region source_region;
208 struct region source_region_type[TOTAL_TYPES];
209 struct region dest_region;
210 struct region dest_region_type[TOTAL_TYPES];
211};
212extern struct program_defaults program_defaults;
213
214struct declared_register {
215 char *name;
Damien Lespiaucce4fc22013-01-23 15:13:55 +0000216 struct brw_reg reg;
Xiang, Haihao27b43032010-12-13 16:07:16 +0800217 int element_size;
218 struct region src_region;
219 int dst_region;
Xiang, Haihao27b43032010-12-13 16:07:16 +0800220};
221struct declared_register *find_register(char *name);
222void insert_register(struct declared_register *reg);
223
Eric Anholtf2f18562006-08-22 12:46:37 -0700224int yyparse(void);
225int yylex(void);
Homer Hsing31401af2012-09-06 15:55:54 +0800226int yylex_destroy(void);
Eric Anholtf2f18562006-08-22 12:46:37 -0700227
228char *
229lex_text(void);
Damien Lespiaua66cd602013-01-19 22:50:57 +0000230
231#endif /* __GEN4ASM_H__ */