blob: 0048b4af96f337b9eec9179a05233c579aa9cb9e [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"
37
Eric Anholt22a10632006-08-22 10:15:33 -070038typedef unsigned char GLubyte;
39typedef short GLshort;
40typedef unsigned int GLuint;
41typedef int GLint;
42typedef float GLfloat;
43
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -040044extern long int gen_level;
45
46/* Predicate for Gen X and above */
47#define IS_GENp(x) (gen_level >= (x)*10)
48
49/* Predicate for Gen X exactly */
50#define IS_GENx(x) (gen_level >= (x)*10 && gen_level < ((x)+1)*10)
51
52/* Predicate to match Haswell processors */
53#define IS_HASWELL(x) (gen_level == 75)
54
Xiang, Haihao27b43032010-12-13 16:07:16 +080055#include "brw_defines.h"
Eric Anholt22a10632006-08-22 10:15:33 -070056#include "brw_structs.h"
57
58void yyerror (char *msg);
59
Damien Lespiauc74c80c2013-01-21 22:12:10 +000060#define STRUCT_SIZE_ASSERT(TYPE, SIZE) \
61typedef struct { \
62 char compile_time_assert_ ## TYPE ## _size[ \
63 (sizeof (struct TYPE) == (SIZE)) ? 1 : -1]; \
64 } _ ## TYPE ## SizeCheck
65
66/* ensure nobody changes the size of struct brw_instruction */
67STRUCT_SIZE_ASSERT(brw_instruction, 16);
68
Xiang, Haihao27b43032010-12-13 16:07:16 +080069struct condition {
70 int cond;
Xiang, Haihao3ffbe962012-07-17 15:05:31 +080071 int flag_reg_nr;
Xiang, Haihao2f772dd2012-07-17 14:18:54 +080072 int flag_subreg_nr;
Xiang, Haihao27b43032010-12-13 16:07:16 +080073};
74
75struct region {
76 int vert_stride, width, horiz_stride;
77 int is_default;
78};
79struct regtype {
80 int type;
81 int is_default;
82};
Eric Anholt74c81af2006-08-30 11:10:45 -070083
84/**
Eric Anholt6a88ada2006-08-28 22:11:18 -070085 * This structure is the internal representation of source operands in the
86 * parser.
87 */
88struct src_operand {
89 int reg_file, reg_nr, subreg_nr, reg_type;
90
91 int abs, negate;
92
93 int horiz_stride, width, vert_stride;
Xiang, Haihao27b43032010-12-13 16:07:16 +080094 int default_region;
Eric Anholt6a88ada2006-08-28 22:11:18 -070095
96 int address_mode; /* 0 if direct, 1 if register-indirect */
97 int indirect_offset; /* XXX */
98
99 int swizzle_set;
Damien Lespiaua82722b2013-01-23 21:35:10 +0000100 unsigned swizzle: 8;
Eric Anholt6a88ada2006-08-28 22:11:18 -0700101
Homer Hsinga7b1c092012-09-21 12:33:13 +0800102 uint32_t imm32; /* set if reg_file == BRW_IMMEDIATE_VALUE or it is expressing a branch offset */
Homer Hsingb0b540f2012-09-21 10:06:20 +0800103 char *reloc_target; /* bspec: branching instructions JIP and UIP are source operands */
Eric Anholt6a88ada2006-08-28 22:11:18 -0700104} src_operand;
105
Keith Packard2d4d4012008-03-30 00:58:28 -0700106typedef struct {
107 enum {
108 imm32_d, imm32_f
109 } r;
110 union {
111 uint32_t d;
112 float f;
Xiang, Haihao27b43032010-12-13 16:07:16 +0800113 int32_t signed_d;
Keith Packard2d4d4012008-03-30 00:58:28 -0700114 } u;
115} imm32_t;
116
Damien Lespiaua45a4712013-01-21 19:28:41 +0000117enum assembler_instruction_type {
118 GEN4ASM_INSTRUCTION_GEN,
Damien Lespiau79c62f12013-01-21 21:41:36 +0000119 GEN4ASM_INSTRUCTION_GEN_RELOCATABLE,
Damien Lespiaua45a4712013-01-21 19:28:41 +0000120 GEN4ASM_INSTRUCTION_LABEL,
121};
122
123struct label_instruction {
124 char *name;
125};
126
Damien Lespiau79c62f12013-01-21 21:41:36 +0000127struct relocatable_instruction {
128 struct brw_instruction gen;
129 char *first_reloc_target, *second_reloc_target; // JIP and UIP respectively
130 GLint first_reloc_offset, second_reloc_offset; // in number of instructions
131};
132
Eric Anholt6a88ada2006-08-28 22:11:18 -0700133/**
Eric Anholt22a10632006-08-22 10:15:33 -0700134 * This structure is just the list container for instructions accumulated by
Zou Nanhaibe9bcee2008-12-09 18:38:54 -0800135 * the parser and labels.
Eric Anholt22a10632006-08-22 10:15:33 -0700136 */
137struct brw_program_instruction {
Damien Lespiaua45a4712013-01-21 19:28:41 +0000138 enum assembler_instruction_type type;
139 unsigned inst_offset;
140 union {
141 struct brw_instruction gen;
Damien Lespiau79c62f12013-01-21 21:41:36 +0000142 struct relocatable_instruction reloc;
Damien Lespiaua45a4712013-01-21 19:28:41 +0000143 struct label_instruction label;
144 } instruction;
145 struct brw_program_instruction *next;
Eric Anholt22a10632006-08-22 10:15:33 -0700146};
147
Damien Lespiaua45a4712013-01-21 19:28:41 +0000148static inline bool is_label(struct brw_program_instruction *instruction)
149{
150 return instruction->type == GEN4ASM_INSTRUCTION_LABEL;
151}
152
153static inline char *label_name(struct brw_program_instruction *i)
154{
155 assert(is_label(i));
156 return i->instruction.label.name;
157}
158
Damien Lespiau79c62f12013-01-21 21:41:36 +0000159static inline bool is_relocatable(struct brw_program_instruction *intruction)
160{
161 return intruction->type == GEN4ASM_INSTRUCTION_GEN_RELOCATABLE;
162}
163
Eric Anholt22a10632006-08-22 10:15:33 -0700164/**
165 * This structure is a list of instructions. It is the final output of the
166 * parser.
167 */
168struct brw_program {
169 struct brw_program_instruction *first;
Zou Nan haidb8aedc2010-04-21 11:02:21 +0800170 struct brw_program_instruction *last;
Eric Anholt22a10632006-08-22 10:15:33 -0700171};
172
173extern struct brw_program compiled_program;
Eric Anholtf2f18562006-08-22 12:46:37 -0700174
Xiang, Haihao27b43032010-12-13 16:07:16 +0800175#define TYPE_B_INDEX 0
176#define TYPE_UB_INDEX 1
177#define TYPE_W_INDEX 2
178#define TYPE_UW_INDEX 3
179#define TYPE_D_INDEX 4
180#define TYPE_UD_INDEX 5
181#define TYPE_F_INDEX 6
182
183#define TOTAL_TYPES 7
184
185struct program_defaults {
186 int execute_size;
187 int execute_type[TOTAL_TYPES];
188 int register_type;
189 int register_type_regfile;
190 struct region source_region;
191 struct region source_region_type[TOTAL_TYPES];
192 struct region dest_region;
193 struct region dest_region_type[TOTAL_TYPES];
194};
195extern struct program_defaults program_defaults;
196
197struct declared_register {
198 char *name;
Damien Lespiaucce4fc22013-01-23 15:13:55 +0000199 struct brw_reg reg;
Xiang, Haihao27b43032010-12-13 16:07:16 +0800200 int element_size;
201 struct region src_region;
202 int dst_region;
203 int type;
Xiang, Haihao27b43032010-12-13 16:07:16 +0800204};
205struct declared_register *find_register(char *name);
206void insert_register(struct declared_register *reg);
207
Eric Anholtf2f18562006-08-22 12:46:37 -0700208int yyparse(void);
209int yylex(void);
Homer Hsing31401af2012-09-06 15:55:54 +0800210int yylex_destroy(void);
Eric Anholtf2f18562006-08-22 12:46:37 -0700211
212char *
213lex_text(void);
Damien Lespiaua66cd602013-01-19 22:50:57 +0000214
215#endif /* __GEN4ASM_H__ */