intel/compiler: Factor out brw_validate_instruction()
In order to fuzz test instructions, we first need to do some sanity checking first. Factoring out this function allows us an easy way to validate a single instruction. Reviewed-by: Caio Marcelo de Oliveira Filho <caio.oliveira@intel.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/2635>
This commit is contained in:
@@ -1867,24 +1867,12 @@ instruction_restrictions(const struct gen_device_info *devinfo,
|
|||||||
return error_msg;
|
return error_msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
static bool
|
||||||
brw_validate_instructions(const struct gen_device_info *devinfo,
|
brw_validate_instruction(const struct gen_device_info *devinfo,
|
||||||
const void *assembly, int start_offset, int end_offset,
|
const brw_inst *inst, int offset,
|
||||||
struct disasm_info *disasm)
|
struct disasm_info *disasm)
|
||||||
{
|
{
|
||||||
bool valid = true;
|
|
||||||
|
|
||||||
for (int src_offset = start_offset; src_offset < end_offset;) {
|
|
||||||
struct string error_msg = { .str = NULL, .len = 0 };
|
struct string error_msg = { .str = NULL, .len = 0 };
|
||||||
const brw_inst *inst = assembly + src_offset;
|
|
||||||
bool is_compact = brw_inst_cmpt_control(devinfo, inst);
|
|
||||||
brw_inst uncompacted;
|
|
||||||
|
|
||||||
if (is_compact) {
|
|
||||||
brw_compact_inst *compacted = (void *)inst;
|
|
||||||
brw_uncompact_instruction(devinfo, &uncompacted, compacted);
|
|
||||||
inst = &uncompacted;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_unsupported_inst(devinfo, inst)) {
|
if (is_unsupported_inst(devinfo, inst)) {
|
||||||
ERROR("Instruction not supported on this Gen");
|
ERROR("Instruction not supported on this Gen");
|
||||||
@@ -1902,16 +1890,37 @@ brw_validate_instructions(const struct gen_device_info *devinfo,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (error_msg.str && disasm) {
|
if (error_msg.str && disasm) {
|
||||||
disasm_insert_error(disasm, src_offset, error_msg.str);
|
disasm_insert_error(disasm, offset, error_msg.str);
|
||||||
}
|
}
|
||||||
valid = valid && error_msg.len == 0;
|
|
||||||
free(error_msg.str);
|
free(error_msg.str);
|
||||||
|
|
||||||
|
return error_msg.len == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
brw_validate_instructions(const struct gen_device_info *devinfo,
|
||||||
|
const void *assembly, int start_offset, int end_offset,
|
||||||
|
struct disasm_info *disasm)
|
||||||
|
{
|
||||||
|
bool valid = true;
|
||||||
|
|
||||||
|
for (int src_offset = start_offset; src_offset < end_offset;) {
|
||||||
|
const brw_inst *inst = assembly + src_offset;
|
||||||
|
bool is_compact = brw_inst_cmpt_control(devinfo, inst);
|
||||||
|
unsigned inst_size = is_compact ? sizeof(brw_compact_inst)
|
||||||
|
: sizeof(brw_inst);
|
||||||
|
brw_inst uncompacted;
|
||||||
|
|
||||||
if (is_compact) {
|
if (is_compact) {
|
||||||
src_offset += sizeof(brw_compact_inst);
|
brw_compact_inst *compacted = (void *)inst;
|
||||||
} else {
|
brw_uncompact_instruction(devinfo, &uncompacted, compacted);
|
||||||
src_offset += sizeof(brw_inst);
|
inst = &uncompacted;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool v = brw_validate_instruction(devinfo, inst, src_offset, disasm);
|
||||||
|
valid = valid && v;
|
||||||
|
|
||||||
|
src_offset += inst_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
return valid;
|
return valid;
|
||||||
|
Reference in New Issue
Block a user