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" |
Damien Lespiau | d9afa5b | 2013-02-04 12:12:29 +0000 | [diff] [blame] | 37 | #include "brw_defines.h" |
| 38 | #include "brw_structs.h" |
Damien Lespiau | af4d37d | 2013-01-31 02:16:08 +0000 | [diff] [blame] | 39 | #include "gen8_instruction.h" |
Damien Lespiau | cce4fc2 | 2013-01-23 15:13:55 +0000 | [diff] [blame] | 40 | |
Gwenole Beauchesne | 8aa9528 | 2012-10-22 16:13:51 -0400 | [diff] [blame] | 41 | extern long int gen_level; |
Damien Lespiau | 1d53e18 | 2013-01-27 11:05:50 +0000 | [diff] [blame] | 42 | extern int advanced_flag; |
| 43 | extern int errors; |
Gwenole Beauchesne | 8aa9528 | 2012-10-22 16:13:51 -0400 | [diff] [blame] | 44 | |
Damien Lespiau | d70e9f8 | 2013-01-26 23:09:42 +0000 | [diff] [blame] | 45 | #define WARN_ALWAYS (1 << 0) |
| 46 | #define WARN_ALL (1 << 31) |
| 47 | extern unsigned int warning_flags; |
| 48 | |
Damien Lespiau | 1eb622a | 2013-01-27 01:32:52 +0000 | [diff] [blame] | 49 | extern char *input_filename; |
| 50 | |
Damien Lespiau | 9fcc1bd | 2013-01-24 16:16:35 +0000 | [diff] [blame] | 51 | extern struct brw_context genasm_context; |
| 52 | extern struct brw_compile genasm_compile; |
| 53 | |
Gwenole Beauchesne | 8aa9528 | 2012-10-22 16:13:51 -0400 | [diff] [blame] | 54 | /* 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 Anholt | 22a1063 | 2006-08-22 10:15:33 -0700 | [diff] [blame] | 63 | void yyerror (char *msg); |
| 64 | |
Damien Lespiau | c74c80c | 2013-01-21 22:12:10 +0000 | [diff] [blame] | 65 | #define STRUCT_SIZE_ASSERT(TYPE, SIZE) \ |
| 66 | typedef 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 */ |
| 72 | STRUCT_SIZE_ASSERT(brw_instruction, 16); |
| 73 | |
Damien Lespiau | e9172aa | 2013-01-26 22:44:45 +0000 | [diff] [blame] | 74 | #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) |
| 75 | |
Xiang, Haihao | 27b4303 | 2010-12-13 16:07:16 +0800 | [diff] [blame] | 76 | struct condition { |
| 77 | int cond; |
Xiang, Haihao | 3ffbe96 | 2012-07-17 15:05:31 +0800 | [diff] [blame] | 78 | int flag_reg_nr; |
Xiang, Haihao | 2f772dd | 2012-07-17 14:18:54 +0800 | [diff] [blame] | 79 | int flag_subreg_nr; |
Xiang, Haihao | 27b4303 | 2010-12-13 16:07:16 +0800 | [diff] [blame] | 80 | }; |
| 81 | |
Damien Lespiau | dfe6ada | 2013-01-30 22:32:07 +0000 | [diff] [blame] | 82 | struct 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 Lespiau | 6bf3aa8 | 2013-01-30 23:25:19 +0000 | [diff] [blame] | 89 | struct 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, Haihao | 27b4303 | 2010-12-13 16:07:16 +0800 | [diff] [blame] | 101 | struct region { |
| 102 | int vert_stride, width, horiz_stride; |
Damien Lespiau | 2d8b92a | 2013-02-01 14:54:46 +0000 | [diff] [blame] | 103 | int is_default; |
Xiang, Haihao | 27b4303 | 2010-12-13 16:07:16 +0800 | [diff] [blame] | 104 | }; |
| 105 | struct regtype { |
| 106 | int type; |
| 107 | int is_default; |
| 108 | }; |
Eric Anholt | 74c81af | 2006-08-30 11:10:45 -0700 | [diff] [blame] | 109 | |
| 110 | /** |
Damien Lespiau | 2d8b92a | 2013-02-01 14:54:46 +0000 | [diff] [blame] | 111 | * This structure is the internal representation of source operands in the |
Eric Anholt | 6a88ada | 2006-08-28 22:11:18 -0700 | [diff] [blame] | 112 | * parser. |
| 113 | */ |
| 114 | struct src_operand { |
Damien Lespiau | 9d5a87a | 2013-01-23 22:29:23 +0000 | [diff] [blame] | 115 | struct brw_reg reg; |
Xiang, Haihao | 27b4303 | 2010-12-13 16:07:16 +0800 | [diff] [blame] | 116 | int default_region; |
Damien Lespiau | 9c72beb | 2013-01-25 15:48:58 +0000 | [diff] [blame] | 117 | uint32_t imm32; /* set if src_operand is expressing a branch offset */ |
Homer Hsing | b0b540f | 2012-09-21 10:06:20 +0800 | [diff] [blame] | 118 | char *reloc_target; /* bspec: branching instructions JIP and UIP are source operands */ |
Eric Anholt | 6a88ada | 2006-08-28 22:11:18 -0700 | [diff] [blame] | 119 | } src_operand; |
| 120 | |
Keith Packard | 2d4d401 | 2008-03-30 00:58:28 -0700 | [diff] [blame] | 121 | typedef struct { |
| 122 | enum { |
| 123 | imm32_d, imm32_f |
| 124 | } r; |
| 125 | union { |
| 126 | uint32_t d; |
| 127 | float f; |
Xiang, Haihao | 27b4303 | 2010-12-13 16:07:16 +0800 | [diff] [blame] | 128 | int32_t signed_d; |
Keith Packard | 2d4d401 | 2008-03-30 00:58:28 -0700 | [diff] [blame] | 129 | } u; |
| 130 | } imm32_t; |
| 131 | |
Damien Lespiau | a45a471 | 2013-01-21 19:28:41 +0000 | [diff] [blame] | 132 | enum assembler_instruction_type { |
| 133 | GEN4ASM_INSTRUCTION_GEN, |
Damien Lespiau | 79c62f1 | 2013-01-21 21:41:36 +0000 | [diff] [blame] | 134 | GEN4ASM_INSTRUCTION_GEN_RELOCATABLE, |
Damien Lespiau | af4d37d | 2013-01-31 02:16:08 +0000 | [diff] [blame] | 135 | GEN4ASM_INSTRUCTION_GEN8, |
| 136 | GEN4ASM_INSTRUCTION_GEN8_RELOCATABLE, |
Damien Lespiau | a45a471 | 2013-01-21 19:28:41 +0000 | [diff] [blame] | 137 | GEN4ASM_INSTRUCTION_LABEL, |
| 138 | }; |
| 139 | |
| 140 | struct label_instruction { |
| 141 | char *name; |
| 142 | }; |
| 143 | |
Damien Lespiau | 9b78f74 | 2013-01-30 17:09:17 +0000 | [diff] [blame] | 144 | struct relocation { |
Damien Lespiau | 79c62f1 | 2013-01-21 21:41:36 +0000 | [diff] [blame] | 145 | char *first_reloc_target, *second_reloc_target; // JIP and UIP respectively |
Damien Lespiau | f0365d4 | 2013-02-04 12:02:18 +0000 | [diff] [blame] | 146 | int first_reloc_offset, second_reloc_offset; // in number of instructions |
Damien Lespiau | 79c62f1 | 2013-01-21 21:41:36 +0000 | [diff] [blame] | 147 | }; |
| 148 | |
Eric Anholt | 6a88ada | 2006-08-28 22:11:18 -0700 | [diff] [blame] | 149 | /** |
Eric Anholt | 22a1063 | 2006-08-22 10:15:33 -0700 | [diff] [blame] | 150 | * This structure is just the list container for instructions accumulated by |
Zou Nanhai | be9bcee | 2008-12-09 18:38:54 -0800 | [diff] [blame] | 151 | * the parser and labels. |
Eric Anholt | 22a1063 | 2006-08-22 10:15:33 -0700 | [diff] [blame] | 152 | */ |
| 153 | struct brw_program_instruction { |
Damien Lespiau | a45a471 | 2013-01-21 19:28:41 +0000 | [diff] [blame] | 154 | enum assembler_instruction_type type; |
| 155 | unsigned inst_offset; |
| 156 | union { |
| 157 | struct brw_instruction gen; |
Damien Lespiau | af4d37d | 2013-01-31 02:16:08 +0000 | [diff] [blame] | 158 | struct gen8_instruction gen8; |
Damien Lespiau | a45a471 | 2013-01-21 19:28:41 +0000 | [diff] [blame] | 159 | struct label_instruction label; |
Damien Lespiau | d008064 | 2013-01-30 12:31:45 +0000 | [diff] [blame] | 160 | } insn; |
Damien Lespiau | 9b78f74 | 2013-01-30 17:09:17 +0000 | [diff] [blame] | 161 | struct relocation reloc; |
Damien Lespiau | a45a471 | 2013-01-21 19:28:41 +0000 | [diff] [blame] | 162 | struct brw_program_instruction *next; |
Eric Anholt | 22a1063 | 2006-08-22 10:15:33 -0700 | [diff] [blame] | 163 | }; |
| 164 | |
Damien Lespiau | a45a471 | 2013-01-21 19:28:41 +0000 | [diff] [blame] | 165 | static inline bool is_label(struct brw_program_instruction *instruction) |
| 166 | { |
| 167 | return instruction->type == GEN4ASM_INSTRUCTION_LABEL; |
| 168 | } |
| 169 | |
| 170 | static inline char *label_name(struct brw_program_instruction *i) |
| 171 | { |
| 172 | assert(is_label(i)); |
Damien Lespiau | d008064 | 2013-01-30 12:31:45 +0000 | [diff] [blame] | 173 | return i->insn.label.name; |
Damien Lespiau | a45a471 | 2013-01-21 19:28:41 +0000 | [diff] [blame] | 174 | } |
| 175 | |
Damien Lespiau | 79c62f1 | 2013-01-21 21:41:36 +0000 | [diff] [blame] | 176 | static inline bool is_relocatable(struct brw_program_instruction *intruction) |
| 177 | { |
| 178 | return intruction->type == GEN4ASM_INSTRUCTION_GEN_RELOCATABLE; |
| 179 | } |
| 180 | |
Eric Anholt | 22a1063 | 2006-08-22 10:15:33 -0700 | [diff] [blame] | 181 | /** |
| 182 | * This structure is a list of instructions. It is the final output of the |
| 183 | * parser. |
| 184 | */ |
| 185 | struct brw_program { |
| 186 | struct brw_program_instruction *first; |
Zou Nan hai | db8aedc | 2010-04-21 11:02:21 +0800 | [diff] [blame] | 187 | struct brw_program_instruction *last; |
Eric Anholt | 22a1063 | 2006-08-22 10:15:33 -0700 | [diff] [blame] | 188 | }; |
| 189 | |
| 190 | extern struct brw_program compiled_program; |
Eric Anholt | f2f1856 | 2006-08-22 12:46:37 -0700 | [diff] [blame] | 191 | |
Xiang, Haihao | 27b4303 | 2010-12-13 16:07:16 +0800 | [diff] [blame] | 192 | #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 | |
| 202 | struct 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 | }; |
| 212 | extern struct program_defaults program_defaults; |
| 213 | |
| 214 | struct declared_register { |
| 215 | char *name; |
Damien Lespiau | cce4fc2 | 2013-01-23 15:13:55 +0000 | [diff] [blame] | 216 | struct brw_reg reg; |
Xiang, Haihao | 27b4303 | 2010-12-13 16:07:16 +0800 | [diff] [blame] | 217 | int element_size; |
| 218 | struct region src_region; |
| 219 | int dst_region; |
Xiang, Haihao | 27b4303 | 2010-12-13 16:07:16 +0800 | [diff] [blame] | 220 | }; |
| 221 | struct declared_register *find_register(char *name); |
| 222 | void insert_register(struct declared_register *reg); |
| 223 | |
Eric Anholt | f2f1856 | 2006-08-22 12:46:37 -0700 | [diff] [blame] | 224 | int yyparse(void); |
| 225 | int yylex(void); |
Homer Hsing | 31401af | 2012-09-06 15:55:54 +0800 | [diff] [blame] | 226 | int yylex_destroy(void); |
Eric Anholt | f2f1856 | 2006-08-22 12:46:37 -0700 | [diff] [blame] | 227 | |
| 228 | char * |
| 229 | lex_text(void); |
Damien Lespiau | a66cd60 | 2013-01-19 22:50:57 +0000 | [diff] [blame] | 230 | |
| 231 | #endif /* __GEN4ASM_H__ */ |