2 * Copyright © 2015 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 /** @file brw_eu_validate.c
26 * This file implements a pass that validates shader assembly.
31 /* We're going to do lots of string concatenation, so this should help. */
38 cat(struct string
*dest
, const struct string src
)
40 dest
->str
= realloc(dest
->str
, dest
->len
+ src
.len
+ 1);
41 memcpy(dest
->str
+ dest
->len
, src
.str
, src
.len
);
42 dest
->str
[dest
->len
+ src
.len
] = '\0';
43 dest
->len
= dest
->len
+ src
.len
;
45 #define CAT(dest, src) cat(&dest, (struct string){src, strlen(src)})
47 #define error(str) "\tERROR: " str "\n"
49 #define ERROR_IF(cond, msg) \
52 CAT(error_msg, error(msg)); \
58 src0_is_null(const struct brw_device_info
*devinfo
, const brw_inst
*inst
)
60 return brw_inst_src0_reg_file(devinfo
, inst
) == BRW_ARCHITECTURE_REGISTER_FILE
&&
61 brw_inst_src0_da_reg_nr(devinfo
, inst
) == BRW_ARF_NULL
;
65 src1_is_null(const struct brw_device_info
*devinfo
, const brw_inst
*inst
)
67 return brw_inst_src1_reg_file(devinfo
, inst
) == BRW_ARCHITECTURE_REGISTER_FILE
&&
68 brw_inst_src1_da_reg_nr(devinfo
, inst
) == BRW_ARF_NULL
;
83 #define GEN_GE(gen) (~((gen) - 1) | gen)
84 #define GEN_LE(gen) (((gen) - 1) | gen)
90 static const struct inst_info inst_info
[128] = {
91 [BRW_OPCODE_ILLEGAL
] = {
100 [BRW_OPCODE_MOVI
] = {
101 .gen
= GEN_GE(GEN45
),
121 /* BRW_OPCODE_DIM / BRW_OPCODE_SMOV */
126 /* Reserved - 13-15 */
130 [BRW_OPCODE_CMPN
] = {
133 [BRW_OPCODE_CSEL
] = {
136 [BRW_OPCODE_F32TO16
] = {
139 [BRW_OPCODE_F16TO32
] = {
142 /* Reserved - 21-22 */
143 [BRW_OPCODE_BFREV
] = {
149 [BRW_OPCODE_BFI1
] = {
152 [BRW_OPCODE_BFI2
] = {
155 /* Reserved - 27-31 */
156 [BRW_OPCODE_JMPI
] = {
163 [BRW_OPCODE_IFF
] = { /* also BRW_OPCODE_BRC */
166 [BRW_OPCODE_ELSE
] = {
169 [BRW_OPCODE_ENDIF
] = {
172 [BRW_OPCODE_DO
] = { /* also BRW_OPCODE_CASE */
175 [BRW_OPCODE_WHILE
] = {
178 [BRW_OPCODE_BREAK
] = {
181 [BRW_OPCODE_CONTINUE
] = {
184 [BRW_OPCODE_HALT
] = {
187 /* BRW_OPCODE_CALLA */
188 /* BRW_OPCODE_MSAVE / BRW_OPCODE_CALL */
189 /* BRW_OPCODE_MREST / BRW_OPCODE_RET */
190 /* BRW_OPCODE_PUSH / BRW_OPCODE_FORK / BRW_OPCODE_GOTO */
192 [BRW_OPCODE_WAIT
] = {
195 [BRW_OPCODE_SEND
] = {
198 [BRW_OPCODE_SENDC
] = {
201 [BRW_OPCODE_SENDS
] = {
204 [BRW_OPCODE_SENDSC
] = {
208 [BRW_OPCODE_MATH
] = {
224 [BRW_OPCODE_RNDU
] = {
227 [BRW_OPCODE_RNDD
] = {
230 [BRW_OPCODE_RNDE
] = {
233 [BRW_OPCODE_RNDZ
] = {
239 [BRW_OPCODE_MACH
] = {
251 [BRW_OPCODE_CBIT
] = {
254 [BRW_OPCODE_ADDC
] = {
257 [BRW_OPCODE_SUBB
] = {
260 [BRW_OPCODE_SAD2
] = {
263 [BRW_OPCODE_SADA2
] = {
280 [BRW_OPCODE_LINE
] = {
284 .gen
= GEN_GE(GEN45
),
292 /* Reserved 93-124 */
293 /* BRW_OPCODE_NENOP */
300 num_sources_from_inst(const struct brw_device_info
*devinfo
,
301 const brw_inst
*inst
)
303 unsigned math_function
;
305 if (brw_inst_opcode(devinfo
, inst
) == BRW_OPCODE_MATH
) {
306 math_function
= brw_inst_math_function(devinfo
, inst
);
307 } else if (devinfo
->gen
< 6 &&
308 brw_inst_opcode(devinfo
, inst
) == BRW_OPCODE_SEND
) {
309 if (brw_inst_sfid(devinfo
, inst
) == BRW_SFID_MATH
) {
310 math_function
= brw_inst_math_msg_function(devinfo
, inst
);
312 /* Send instructions are allowed to have null sources since they use
313 * the base_mrf field to specify which message register source.
318 return opcode_descs
[brw_inst_opcode(devinfo
, inst
)].nsrc
;
321 switch (math_function
) {
322 case BRW_MATH_FUNCTION_INV
:
323 case BRW_MATH_FUNCTION_LOG
:
324 case BRW_MATH_FUNCTION_EXP
:
325 case BRW_MATH_FUNCTION_SQRT
:
326 case BRW_MATH_FUNCTION_RSQ
:
327 case BRW_MATH_FUNCTION_SIN
:
328 case BRW_MATH_FUNCTION_COS
:
329 case BRW_MATH_FUNCTION_SINCOS
:
330 case GEN8_MATH_FUNCTION_INVM
:
331 case GEN8_MATH_FUNCTION_RSQRTM
:
333 case BRW_MATH_FUNCTION_FDIV
:
334 case BRW_MATH_FUNCTION_POW
:
335 case BRW_MATH_FUNCTION_INT_DIV_QUOTIENT_AND_REMAINDER
:
336 case BRW_MATH_FUNCTION_INT_DIV_QUOTIENT
:
337 case BRW_MATH_FUNCTION_INT_DIV_REMAINDER
:
340 unreachable("not reached");
345 gen_from_devinfo(const struct brw_device_info
*devinfo
)
347 switch (devinfo
->gen
) {
348 case 4: return devinfo
->is_g4x
? GEN45
: GEN4
;
351 case 7: return devinfo
->is_haswell
? GEN75
: GEN7
;
355 unreachable("not reached");
360 is_unsupported_inst(const struct brw_device_info
*devinfo
,
361 const brw_inst
*inst
)
363 enum gen gen
= gen_from_devinfo(devinfo
);
364 return (inst_info
[brw_inst_opcode(devinfo
, inst
)].gen
& gen
) == 0;
368 brw_validate_instructions(const struct brw_codegen
*p
, int start_offset
,
369 struct annotation_info
*annotation
)
371 const struct brw_device_info
*devinfo
= p
->devinfo
;
372 const void *store
= p
->store
+ start_offset
/ 16;
375 for (int src_offset
= 0; src_offset
< p
->next_insn_offset
- start_offset
;
376 src_offset
+= sizeof(brw_inst
)) {
377 struct string error_msg
= { .str
= NULL
, .len
= 0 };
378 const brw_inst
*inst
= store
+ src_offset
;
380 switch (num_sources_from_inst(devinfo
, inst
)) {
382 /* Nothing to test. 3-src instructions can only have GRF sources, and
383 * there's no bit to control the file.
387 ERROR_IF(src1_is_null(devinfo
, inst
), "src1 is null");
390 ERROR_IF(src0_is_null(devinfo
, inst
), "src0 is null");
397 ERROR_IF(is_unsupported_inst(devinfo
, inst
),
398 "Instruction not supported on this Gen");
400 if (error_msg
.str
&& annotation
) {
401 annotation_insert_error(annotation
, src_offset
, error_msg
.str
);