Eric Anholt | 22a1063 | 2006-08-22 10:15:33 -0700 | [diff] [blame] | 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 | |
Damien Lespiau | a66cd60 | 2013-01-19 22:50:57 +0000 | [diff] [blame] | 29 | #ifndef __GEN4ASM_H__ |
| 30 | #define __GEN4ASM_H__ |
| 31 | |
Eric Anholt | 09d8be4 | 2006-09-01 15:37:00 -0700 | [diff] [blame] | 32 | #include <inttypes.h> |
Damien Lespiau | a45a471 | 2013-01-21 19:28:41 +0000 | [diff] [blame] | 33 | #include <stdbool.h> |
| 34 | #include <assert.h> |
Eric Anholt | 6a88ada | 2006-08-28 22:11:18 -0700 | [diff] [blame] | 35 | |
Damien Lespiau | cce4fc2 | 2013-01-23 15:13:55 +0000 | [diff] [blame] | 36 | #include "brw_reg.h" |
| 37 | |
Eric Anholt | 22a1063 | 2006-08-22 10:15:33 -0700 | [diff] [blame] | 38 | typedef unsigned char GLubyte; |
| 39 | typedef short GLshort; |
| 40 | typedef unsigned int GLuint; |
| 41 | typedef int GLint; |
| 42 | typedef float GLfloat; |
| 43 | |
Gwenole Beauchesne | 8aa9528 | 2012-10-22 16:13:51 -0400 | [diff] [blame] | 44 | extern 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, Haihao | 27b4303 | 2010-12-13 16:07:16 +0800 | [diff] [blame] | 55 | #include "brw_defines.h" |
Eric Anholt | 22a1063 | 2006-08-22 10:15:33 -0700 | [diff] [blame] | 56 | #include "brw_structs.h" |
| 57 | |
| 58 | void yyerror (char *msg); |
| 59 | |
Damien Lespiau | c74c80c | 2013-01-21 22:12:10 +0000 | [diff] [blame] | 60 | #define STRUCT_SIZE_ASSERT(TYPE, SIZE) \ |
| 61 | typedef 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 */ |
| 67 | STRUCT_SIZE_ASSERT(brw_instruction, 16); |
| 68 | |
Xiang, Haihao | 27b4303 | 2010-12-13 16:07:16 +0800 | [diff] [blame] | 69 | struct condition { |
| 70 | int cond; |
Xiang, Haihao | 3ffbe96 | 2012-07-17 15:05:31 +0800 | [diff] [blame] | 71 | int flag_reg_nr; |
Xiang, Haihao | 2f772dd | 2012-07-17 14:18:54 +0800 | [diff] [blame] | 72 | int flag_subreg_nr; |
Xiang, Haihao | 27b4303 | 2010-12-13 16:07:16 +0800 | [diff] [blame] | 73 | }; |
| 74 | |
| 75 | struct region { |
| 76 | int vert_stride, width, horiz_stride; |
| 77 | int is_default; |
| 78 | }; |
| 79 | struct regtype { |
| 80 | int type; |
| 81 | int is_default; |
| 82 | }; |
Eric Anholt | 74c81af | 2006-08-30 11:10:45 -0700 | [diff] [blame] | 83 | |
| 84 | /** |
Eric Anholt | 6a88ada | 2006-08-28 22:11:18 -0700 | [diff] [blame] | 85 | * This structure is the internal representation of source operands in the |
| 86 | * parser. |
| 87 | */ |
| 88 | struct 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, Haihao | 27b4303 | 2010-12-13 16:07:16 +0800 | [diff] [blame] | 94 | int default_region; |
Eric Anholt | 6a88ada | 2006-08-28 22:11:18 -0700 | [diff] [blame] | 95 | |
| 96 | int address_mode; /* 0 if direct, 1 if register-indirect */ |
| 97 | int indirect_offset; /* XXX */ |
| 98 | |
| 99 | int swizzle_set; |
Damien Lespiau | a82722b | 2013-01-23 21:35:10 +0000 | [diff] [blame^] | 100 | unsigned swizzle: 8; |
Eric Anholt | 6a88ada | 2006-08-28 22:11:18 -0700 | [diff] [blame] | 101 | |
Homer Hsing | a7b1c09 | 2012-09-21 12:33:13 +0800 | [diff] [blame] | 102 | uint32_t imm32; /* set if reg_file == BRW_IMMEDIATE_VALUE or it is expressing a branch offset */ |
Homer Hsing | b0b540f | 2012-09-21 10:06:20 +0800 | [diff] [blame] | 103 | char *reloc_target; /* bspec: branching instructions JIP and UIP are source operands */ |
Eric Anholt | 6a88ada | 2006-08-28 22:11:18 -0700 | [diff] [blame] | 104 | } src_operand; |
| 105 | |
Keith Packard | 2d4d401 | 2008-03-30 00:58:28 -0700 | [diff] [blame] | 106 | typedef struct { |
| 107 | enum { |
| 108 | imm32_d, imm32_f |
| 109 | } r; |
| 110 | union { |
| 111 | uint32_t d; |
| 112 | float f; |
Xiang, Haihao | 27b4303 | 2010-12-13 16:07:16 +0800 | [diff] [blame] | 113 | int32_t signed_d; |
Keith Packard | 2d4d401 | 2008-03-30 00:58:28 -0700 | [diff] [blame] | 114 | } u; |
| 115 | } imm32_t; |
| 116 | |
Damien Lespiau | a45a471 | 2013-01-21 19:28:41 +0000 | [diff] [blame] | 117 | enum assembler_instruction_type { |
| 118 | GEN4ASM_INSTRUCTION_GEN, |
Damien Lespiau | 79c62f1 | 2013-01-21 21:41:36 +0000 | [diff] [blame] | 119 | GEN4ASM_INSTRUCTION_GEN_RELOCATABLE, |
Damien Lespiau | a45a471 | 2013-01-21 19:28:41 +0000 | [diff] [blame] | 120 | GEN4ASM_INSTRUCTION_LABEL, |
| 121 | }; |
| 122 | |
| 123 | struct label_instruction { |
| 124 | char *name; |
| 125 | }; |
| 126 | |
Damien Lespiau | 79c62f1 | 2013-01-21 21:41:36 +0000 | [diff] [blame] | 127 | struct 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 Anholt | 6a88ada | 2006-08-28 22:11:18 -0700 | [diff] [blame] | 133 | /** |
Eric Anholt | 22a1063 | 2006-08-22 10:15:33 -0700 | [diff] [blame] | 134 | * This structure is just the list container for instructions accumulated by |
Zou Nanhai | be9bcee | 2008-12-09 18:38:54 -0800 | [diff] [blame] | 135 | * the parser and labels. |
Eric Anholt | 22a1063 | 2006-08-22 10:15:33 -0700 | [diff] [blame] | 136 | */ |
| 137 | struct brw_program_instruction { |
Damien Lespiau | a45a471 | 2013-01-21 19:28:41 +0000 | [diff] [blame] | 138 | enum assembler_instruction_type type; |
| 139 | unsigned inst_offset; |
| 140 | union { |
| 141 | struct brw_instruction gen; |
Damien Lespiau | 79c62f1 | 2013-01-21 21:41:36 +0000 | [diff] [blame] | 142 | struct relocatable_instruction reloc; |
Damien Lespiau | a45a471 | 2013-01-21 19:28:41 +0000 | [diff] [blame] | 143 | struct label_instruction label; |
| 144 | } instruction; |
| 145 | struct brw_program_instruction *next; |
Eric Anholt | 22a1063 | 2006-08-22 10:15:33 -0700 | [diff] [blame] | 146 | }; |
| 147 | |
Damien Lespiau | a45a471 | 2013-01-21 19:28:41 +0000 | [diff] [blame] | 148 | static inline bool is_label(struct brw_program_instruction *instruction) |
| 149 | { |
| 150 | return instruction->type == GEN4ASM_INSTRUCTION_LABEL; |
| 151 | } |
| 152 | |
| 153 | static inline char *label_name(struct brw_program_instruction *i) |
| 154 | { |
| 155 | assert(is_label(i)); |
| 156 | return i->instruction.label.name; |
| 157 | } |
| 158 | |
Damien Lespiau | 79c62f1 | 2013-01-21 21:41:36 +0000 | [diff] [blame] | 159 | static inline bool is_relocatable(struct brw_program_instruction *intruction) |
| 160 | { |
| 161 | return intruction->type == GEN4ASM_INSTRUCTION_GEN_RELOCATABLE; |
| 162 | } |
| 163 | |
Eric Anholt | 22a1063 | 2006-08-22 10:15:33 -0700 | [diff] [blame] | 164 | /** |
| 165 | * This structure is a list of instructions. It is the final output of the |
| 166 | * parser. |
| 167 | */ |
| 168 | struct brw_program { |
| 169 | struct brw_program_instruction *first; |
Zou Nan hai | db8aedc | 2010-04-21 11:02:21 +0800 | [diff] [blame] | 170 | struct brw_program_instruction *last; |
Eric Anholt | 22a1063 | 2006-08-22 10:15:33 -0700 | [diff] [blame] | 171 | }; |
| 172 | |
| 173 | extern struct brw_program compiled_program; |
Eric Anholt | f2f1856 | 2006-08-22 12:46:37 -0700 | [diff] [blame] | 174 | |
Xiang, Haihao | 27b4303 | 2010-12-13 16:07:16 +0800 | [diff] [blame] | 175 | #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 | |
| 185 | struct 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 | }; |
| 195 | extern struct program_defaults program_defaults; |
| 196 | |
| 197 | struct declared_register { |
| 198 | char *name; |
Damien Lespiau | cce4fc2 | 2013-01-23 15:13:55 +0000 | [diff] [blame] | 199 | struct brw_reg reg; |
Xiang, Haihao | 27b4303 | 2010-12-13 16:07:16 +0800 | [diff] [blame] | 200 | int element_size; |
| 201 | struct region src_region; |
| 202 | int dst_region; |
| 203 | int type; |
Xiang, Haihao | 27b4303 | 2010-12-13 16:07:16 +0800 | [diff] [blame] | 204 | }; |
| 205 | struct declared_register *find_register(char *name); |
| 206 | void insert_register(struct declared_register *reg); |
| 207 | |
Eric Anholt | f2f1856 | 2006-08-22 12:46:37 -0700 | [diff] [blame] | 208 | int yyparse(void); |
| 209 | int yylex(void); |
Homer Hsing | 31401af | 2012-09-06 15:55:54 +0800 | [diff] [blame] | 210 | int yylex_destroy(void); |
Eric Anholt | f2f1856 | 2006-08-22 12:46:37 -0700 | [diff] [blame] | 211 | |
| 212 | char * |
| 213 | lex_text(void); |
Damien Lespiau | a66cd60 | 2013-01-19 22:50:57 +0000 | [diff] [blame] | 214 | |
| 215 | #endif /* __GEN4ASM_H__ */ |