static bool skip_bit(const struct brw_context *brw, brw_inst *src, int bit) { /* pad bit */ if (bit == 7) return true; /* The compact bit -- uncompacted can't have it set. */ if (bit == 29) return true; /* pad bit */ if (bit == 47) return true; /* pad bits */ if (bit >= 90 && bit <= 95) return true; /* sometimes these are pad bits. */ if (brw_inst_opcode(brw, src) != BRW_OPCODE_SEND && brw_inst_opcode(brw, src) != BRW_OPCODE_SENDC && brw_inst_opcode(brw, src) != BRW_OPCODE_BREAK && brw_inst_opcode(brw, src) != BRW_OPCODE_CONTINUE && brw_inst_src0_reg_file(brw, src) != BRW_IMMEDIATE_VALUE && brw_inst_src1_reg_file(brw, src) != BRW_IMMEDIATE_VALUE && bit >= 121) { return true; } return false; }
static bool skip_bit(const struct gen_device_info *devinfo, brw_inst *src, int bit) { /* pad bit */ if (bit == 7) return true; /* The compact bit -- uncompacted can't have it set. */ if (bit == 29) return true; if (is_3src(devinfo, (opcode)brw_inst_opcode(devinfo, src))) { if (devinfo->gen >= 9 || devinfo->is_cherryview) { if (bit == 127) return true; } else { if (bit >= 126 && bit <= 127) return true; if (bit == 105) return true; if (bit == 84) return true; if (bit >= 35 && bit <= 36) return true; } } else { if (bit == 47) return true; if (devinfo->gen >= 8) { if (bit == 11) return true; if (bit == 95) return true; } else { if (devinfo->gen < 7 && bit == 90) return true; if (bit >= 91 && bit <= 95) return true; } } /* sometimes these are pad bits. */ if (brw_inst_opcode(devinfo, src) != BRW_OPCODE_SEND && brw_inst_opcode(devinfo, src) != BRW_OPCODE_SENDC && brw_inst_src0_reg_file(devinfo, src) != BRW_IMMEDIATE_VALUE && brw_inst_src1_reg_file(devinfo, src) != BRW_IMMEDIATE_VALUE && bit >= 121) { return true; } return false; }
/** * When doing fuzz testing, pad bits won't round-trip. * * This sort of a superset of skip_bit, which is testing for changing bits that * aren't worth testing for fuzzing. We also just want to clear bits that * become meaningless once fuzzing twiddles a related bit. */ static void clear_pad_bits(const struct brw_context *brw, brw_inst *inst) { if (brw_inst_opcode(brw, inst) != BRW_OPCODE_SEND && brw_inst_opcode(brw, inst) != BRW_OPCODE_SENDC && brw_inst_opcode(brw, inst) != BRW_OPCODE_BREAK && brw_inst_opcode(brw, inst) != BRW_OPCODE_CONTINUE && brw_inst_src0_reg_file(brw, inst) != BRW_IMMEDIATE_VALUE && brw_inst_src1_reg_file(brw, inst) != BRW_IMMEDIATE_VALUE) { brw_inst_set_bits(inst, 127, 111, 0); } }
static unsigned num_sources_from_inst(const struct brw_device_info *devinfo, const brw_inst *inst) { const struct opcode_desc *desc = brw_opcode_desc(devinfo, brw_inst_opcode(devinfo, inst)); unsigned math_function; if (brw_inst_opcode(devinfo, inst) == BRW_OPCODE_MATH) { math_function = brw_inst_math_function(devinfo, inst); } else if (devinfo->gen < 6 && brw_inst_opcode(devinfo, inst) == BRW_OPCODE_SEND) { if (brw_inst_sfid(devinfo, inst) == BRW_SFID_MATH) { math_function = brw_inst_math_msg_function(devinfo, inst); } else { /* Send instructions are allowed to have null sources since they use * the base_mrf field to specify which message register source. */ return 0; } } else if (desc) { return desc->nsrc; } else { return 0; } switch (math_function) { case BRW_MATH_FUNCTION_INV: case BRW_MATH_FUNCTION_LOG: case BRW_MATH_FUNCTION_EXP: case BRW_MATH_FUNCTION_SQRT: case BRW_MATH_FUNCTION_RSQ: case BRW_MATH_FUNCTION_SIN: case BRW_MATH_FUNCTION_COS: case BRW_MATH_FUNCTION_SINCOS: case GEN8_MATH_FUNCTION_INVM: case GEN8_MATH_FUNCTION_RSQRTM: return 1; case BRW_MATH_FUNCTION_FDIV: case BRW_MATH_FUNCTION_POW: case BRW_MATH_FUNCTION_INT_DIV_QUOTIENT_AND_REMAINDER: case BRW_MATH_FUNCTION_INT_DIV_QUOTIENT: case BRW_MATH_FUNCTION_INT_DIV_REMAINDER: return 2; default: unreachable("not reached"); } }
/** * When doing fuzz testing, pad bits won't round-trip. * * This sort of a superset of skip_bit, which is testing for changing bits that * aren't worth testing for fuzzing. We also just want to clear bits that * become meaningless once fuzzing twiddles a related bit. */ static void clear_pad_bits(const struct gen_device_info *devinfo, brw_inst *inst) { if (brw_inst_opcode(devinfo, inst) != BRW_OPCODE_SEND && brw_inst_opcode(devinfo, inst) != BRW_OPCODE_SENDC && brw_inst_src0_reg_file(devinfo, inst) != BRW_IMMEDIATE_VALUE && brw_inst_src1_reg_file(devinfo, inst) != BRW_IMMEDIATE_VALUE) { brw_inst_set_bits(inst, 127, 111, 0); } if (devinfo->gen == 8 && !devinfo->is_cherryview && is_3src(devinfo, (opcode)brw_inst_opcode(devinfo, inst))) { brw_inst_set_bits(inst, 105, 105, 0); brw_inst_set_bits(inst, 84, 84, 0); brw_inst_set_bits(inst, 36, 35, 0); } }
bool brw_validate_instructions(const struct brw_codegen *p, int start_offset, struct annotation_info *annotation) { const struct brw_device_info *devinfo = p->devinfo; const void *store = p->store + start_offset / 16; bool valid = true; for (int src_offset = 0; src_offset < p->next_insn_offset - start_offset; src_offset += sizeof(brw_inst)) { struct string error_msg = { .str = NULL, .len = 0 }; const brw_inst *inst = store + src_offset; switch (num_sources_from_inst(devinfo, inst)) { case 3: /* Nothing to test. 3-src instructions can only have GRF sources, and * there's no bit to control the file. */ break; case 2: ERROR_IF(src1_is_null(devinfo, inst), "src1 is null"); /* fallthrough */ case 1: ERROR_IF(src0_is_null(devinfo, inst), "src0 is null"); break; case 0: default: break; } ERROR_IF(is_unsupported_inst(devinfo, inst), "Instruction not supported on this Gen"); if (brw_inst_opcode(devinfo, inst) == BRW_OPCODE_SEND) { ERROR_IF(brw_inst_src0_address_mode(devinfo, inst) != BRW_ADDRESS_DIRECT, "send must use direct addressing"); if (devinfo->gen >= 7) { ERROR_IF(!src0_is_grf(devinfo, inst), "send from non-GRF"); ERROR_IF(brw_inst_eot(devinfo, inst) && brw_inst_src0_da_reg_nr(devinfo, inst) < 112, "send with EOT must use g112-g127"); } } if (error_msg.str && annotation) { annotation_insert_error(annotation, src_offset, error_msg.str); } free(error_msg.str); } return valid; }
static bool is_unsupported_inst(const struct brw_device_info *devinfo, const brw_inst *inst) { return brw_opcode_desc(devinfo, brw_inst_opcode(devinfo, inst)) == NULL; }