Commit 509e1094 authored by Alyssa Rosenzweig's avatar Alyssa Rosenzweig 💜

Refactor get_lookahead_type

parent 2411b900
......@@ -171,6 +171,24 @@ emit_instr(compiler_context *ctx, struct nir_instr *instr)
}
}
/* Midgard prefetches instruction types, so during emission we need to
* lookahead too. Unless this is the last instruction, in which we return 1. Or
* if this is the second to last and the last is an ALU, then it's also 1... */
#define IN_ARRAY(n, arr) ((void*)n < (void*)(arr.data + arr.size))
static int
get_lookahead_type(struct util_dynarray block, midgard_instruction *ins)
{
midgard_instruction *n = ins + 1;
if (IN_ARRAY(n , block) &&
(IN_ARRAY(n + 1, block) || n->type != midgard_word_type_alu))
return n->type;
else
return 1;
}
static int
midgard_compile_shader_nir(nir_shader *nir)
{
......@@ -190,27 +208,6 @@ midgard_compile_shader_nir(nir_shader *nir)
}
util_dynarray_foreach(&ctx.current_block, midgard_instruction, ins) {
unsigned lookahead_type;
/* Midgard prefetches instruction types, so during emission we need to lookahead too */
midgard_instruction *next = (ins + 1);
/* Ensure that next is valid */
if (next < (midgard_instruction *)((char *)ctx.current_block.data + ctx.current_block.size)) {
/* There is a next instruction; use its tag, unless this is the second to last before an ALU. TODO: Test this special case */
midgard_instruction *next2 = (next + 1);
if (next2 >= (midgard_instruction *)((char *)ctx.current_block.data + ctx.current_block.size) && next->type == midgard_word_type_alu) {
lookahead_type = 1;
} else {
lookahead_type = next->type;
}
} else {
/* Last instruction, so default to one */
lookahead_type = 1;
}
switch(ins->type) {
case midgard_word_type_alu:
printf("ALU instruction\n");
......@@ -220,7 +217,7 @@ midgard_compile_shader_nir(nir_shader *nir)
break;
}
printf("Lookahead: %d\n", lookahead_type);
printf("Lookahead: %d\n", get_lookahead_type(ctx.current_block, ins));
}
util_dynarray_fini(&ctx.current_block);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment