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
;
72 num_sources_from_inst(const struct brw_device_info
*devinfo
,
75 const struct opcode_desc
*desc
=
76 brw_opcode_desc(devinfo
, brw_inst_opcode(devinfo
, inst
));
77 unsigned math_function
;
79 if (brw_inst_opcode(devinfo
, inst
) == BRW_OPCODE_MATH
) {
80 math_function
= brw_inst_math_function(devinfo
, inst
);
81 } else if (devinfo
->gen
< 6 &&
82 brw_inst_opcode(devinfo
, inst
) == BRW_OPCODE_SEND
) {
83 if (brw_inst_sfid(devinfo
, inst
) == BRW_SFID_MATH
) {
84 math_function
= brw_inst_math_msg_function(devinfo
, inst
);
86 /* Send instructions are allowed to have null sources since they use
87 * the base_mrf field to specify which message register source.
97 switch (math_function
) {
98 case BRW_MATH_FUNCTION_INV
:
99 case BRW_MATH_FUNCTION_LOG
:
100 case BRW_MATH_FUNCTION_EXP
:
101 case BRW_MATH_FUNCTION_SQRT
:
102 case BRW_MATH_FUNCTION_RSQ
:
103 case BRW_MATH_FUNCTION_SIN
:
104 case BRW_MATH_FUNCTION_COS
:
105 case BRW_MATH_FUNCTION_SINCOS
:
106 case GEN8_MATH_FUNCTION_INVM
:
107 case GEN8_MATH_FUNCTION_RSQRTM
:
109 case BRW_MATH_FUNCTION_FDIV
:
110 case BRW_MATH_FUNCTION_POW
:
111 case BRW_MATH_FUNCTION_INT_DIV_QUOTIENT_AND_REMAINDER
:
112 case BRW_MATH_FUNCTION_INT_DIV_QUOTIENT
:
113 case BRW_MATH_FUNCTION_INT_DIV_REMAINDER
:
116 unreachable("not reached");
121 is_unsupported_inst(const struct brw_device_info
*devinfo
,
122 const brw_inst
*inst
)
124 int gen
= gen_from_devinfo(devinfo
);
125 return (opcode_descs
[brw_inst_opcode(devinfo
, inst
)].gens
& gen
) == 0;
129 brw_validate_instructions(const struct brw_codegen
*p
, int start_offset
,
130 struct annotation_info
*annotation
)
132 const struct brw_device_info
*devinfo
= p
->devinfo
;
133 const void *store
= p
->store
+ start_offset
/ 16;
136 for (int src_offset
= 0; src_offset
< p
->next_insn_offset
- start_offset
;
137 src_offset
+= sizeof(brw_inst
)) {
138 struct string error_msg
= { .str
= NULL
, .len
= 0 };
139 const brw_inst
*inst
= store
+ src_offset
;
141 switch (num_sources_from_inst(devinfo
, inst
)) {
143 /* Nothing to test. 3-src instructions can only have GRF sources, and
144 * there's no bit to control the file.
148 ERROR_IF(src1_is_null(devinfo
, inst
), "src1 is null");
151 ERROR_IF(src0_is_null(devinfo
, inst
), "src0 is null");
158 ERROR_IF(is_unsupported_inst(devinfo
, inst
),
159 "Instruction not supported on this Gen");
161 if (error_msg
.str
&& annotation
) {
162 annotation_insert_error(annotation
, src_offset
, error_msg
.str
);