intel/compiler: Make decision based on source type instead of opcode
This patch restructure code a little bit to check if source can be represented as immediate operand. This is a foundation for next patch which add checks for integer operand as well. Suggested-by: Jason Ekstrand <jason@jlekstrand.net> Signed-off-by: Sagar Ghuge <sagar.ghuge@intel.com> Reviewed-by: Jason Ekstrand <jason@jlekstrand.net> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11596>
This commit is contained in:
@@ -336,20 +336,41 @@ representable_as_hf(float f, uint16_t *hf)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
represent_src_as_imm(const struct intel_device_info *devinfo,
|
supports_src_as_imm(const struct intel_device_info *devinfo, enum opcode op)
|
||||||
fs_reg *src)
|
|
||||||
{
|
{
|
||||||
|
switch (op) {
|
||||||
|
case BRW_OPCODE_MAD:
|
||||||
|
return devinfo->ver == 12 && devinfo->verx10 < 125;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
can_promote_src_as_imm(const struct intel_device_info *devinfo, fs_inst *inst,
|
||||||
|
unsigned src_idx)
|
||||||
|
{
|
||||||
|
/* Experiment shows that we can only support src0 as immediate */
|
||||||
|
if (src_idx != 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!supports_src_as_imm(devinfo, inst->opcode))
|
||||||
|
return false;
|
||||||
|
|
||||||
/* TODO - Fix the codepath below to use a bfloat16 immediate on XeHP,
|
/* TODO - Fix the codepath below to use a bfloat16 immediate on XeHP,
|
||||||
* since HF/F mixed mode has been removed from the hardware.
|
* since HF/F mixed mode has been removed from the hardware.
|
||||||
*/
|
*/
|
||||||
if (devinfo->ver == 12 && devinfo->verx10 < 125) {
|
switch(inst->src[src_idx].type) {
|
||||||
|
case BRW_REGISTER_TYPE_F: {
|
||||||
uint16_t hf;
|
uint16_t hf;
|
||||||
if (representable_as_hf(src->f, &hf)) {
|
if (representable_as_hf(inst->src[src_idx].f, &hf)) {
|
||||||
*src = retype(brw_imm_uw(hf), BRW_REGISTER_TYPE_HF);
|
inst->src[src_idx] = retype(brw_imm_uw(hf), BRW_REGISTER_TYPE_HF);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
@@ -375,17 +396,12 @@ fs_visitor::opt_combine_constants()
|
|||||||
if (!could_coissue(devinfo, inst) && !must_promote_imm(devinfo, inst))
|
if (!could_coissue(devinfo, inst) && !must_promote_imm(devinfo, inst))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
bool represented_as_imm = false;
|
|
||||||
for (int i = 0; i < inst->sources; i++) {
|
for (int i = 0; i < inst->sources; i++) {
|
||||||
if (inst->src[i].file != IMM)
|
if (inst->src[i].file != IMM)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!represented_as_imm && i == 0 &&
|
if (can_promote_src_as_imm(devinfo, inst, i))
|
||||||
inst->opcode == BRW_OPCODE_MAD &&
|
|
||||||
represent_src_as_imm(devinfo, &inst->src[i])) {
|
|
||||||
represented_as_imm = true;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
char data[8];
|
char data[8];
|
||||||
brw_reg_type type;
|
brw_reg_type type;
|
||||||
|
Reference in New Issue
Block a user