Commit 71417409 authored by Alyssa Rosenzweig's avatar Alyssa Rosenzweig 💜

Continue ALU combining work

parent 2b1f6f5f
......@@ -269,6 +269,7 @@ m_alu_br_compact_cond(midgard_jmp_writeout_op_e op, unsigned tag, signed offset,
midgard_instruction ins = {
.type = TAG_ALU_4,
.unit = ALU_ENAB_BR_COMPACT ,
.unused = false,
.uses_ssa = false,
......@@ -593,10 +594,8 @@ get_lookahead_type(struct util_dynarray block, midgard_instruction *ins)
static int
emit_binary_instruction(compiler_context *ctx, midgard_instruction *ins, struct util_dynarray *emission)
{
/* TODO: Handle this with pairing */
if (ins->type == TAG_ALU_4 && ins->has_constants) ins->type = TAG_ALU_8;
int instructions_emitted = 0;
printf("Emit\n");
uint8_t lookahead_tag = get_lookahead_type(ctx->current_block, ins);
uint8_t tag = ins->type | (lookahead_tag << 4);
......@@ -606,8 +605,8 @@ emit_binary_instruction(compiler_context *ctx, midgard_instruction *ins, struct
case TAG_ALU_8:
case TAG_ALU_12:
case TAG_ALU_16: {
uint32_t control = tag;
size_t bytes_emitted = 0;
uint32_t control = get_lookahead_type(ctx->current_block, ins) << 4;
size_t bytes_emitted = sizeof(control);
uint16_t register_words[8];
int register_words_count = 0;
......@@ -620,17 +619,22 @@ emit_binary_instruction(compiler_context *ctx, midgard_instruction *ins, struct
int index = 0, last_unit = 0;
printf("u: %d\n", ins->unit);
printf("t: %d\n", ins->type);
while ((ins + index) &&
(ins + index)->type == TAG_ALU_4 &&
(ins + index)->unit > last_unit) {
printf("...");
midgard_instruction *ains = ins + index;
control |= ains->unit;
last_unit = ains->unit;
if (ins->vector) {
/* TODO */
printf("Vector\n");
memcpy(&register_words[register_words_count++], &ins->registers, sizeof(ins->registers));
bytes_emitted += sizeof(alu_register_word);
......@@ -639,24 +643,41 @@ emit_binary_instruction(compiler_context *ctx, midgard_instruction *ins, struct
bytes_emitted += sizeof(midgard_vector_alu_t);
} else if (ins->compact_branch) {
printf("Compact\n");
body_size[body_words_count] = sizeof(ins->br_compact);
memcpy(&body_words[body_words_count++], &ins->br_compact, sizeof(ins->br_compact));
bytes_emitted += sizeof(ins->br_compact);
} else {
/* TODO: Scalar ops */
printf("Scalar the huh?\n");
}
++index;
break;
}
/* Bubble up the number of instructions for skipping */
instructions_emitted = index;
instructions_emitted = index - 1;
//EMIT_AND_COUNT(alu_register_word, ins->registers);
//EMIT_AND_COUNT(midgard_vector_alu_t, ins->vector_alu);
int padding = 0;
/* Actually emit each component */
/* Pad ALU op to nearest word */
if (bytes_emitted & 15) {
printf("Bytes %d\n", bytes_emitted);
padding = 16 - (bytes_emitted & 15);
bytes_emitted += padding;
}
/* Constants must always be quadwords */
if (ins->has_constants) {
bytes_emitted += 16;
}
/* Size ALU instruction for tag */
control |= (TAG_ALU_4) + (bytes_emitted / 16) - 1;
/* Actually emit each component */
EMIT_AND_COUNT(uint32_t, control);
for (int i = 0; i < register_words_count; ++i)
......@@ -665,12 +686,6 @@ emit_binary_instruction(compiler_context *ctx, midgard_instruction *ins, struct
for (int i = 0; i < body_words_count; ++i)
memcpy(util_dynarray_grow(emission, body_size[i]), &body_words[i], body_size[i]);
int padding = 0;
/* Pad ALU op to nearest word */
if (bytes_emitted & 15)
padding = 16 - (bytes_emitted & 15);
/* Emit padding */
util_dynarray_grow(emission, padding);
......@@ -746,6 +761,7 @@ emit_binary_instruction(compiler_context *ctx, midgard_instruction *ins, struct
break;
}
printf("emitted %d\n", instructions_emitted);
return instructions_emitted;
}
......@@ -869,6 +885,7 @@ midgard_compile_shader_nir(nir_shader *nir, struct util_dynarray *compiled)
EMIT(fmov, 0, blank_alu_src, 0, true);
EMIT(alu_br_compact_cond, midgard_jmp_writeout_op_writeout, TAG_ALU_4, -1, COND_FBWRITE);
break; /* TODO: Multi-block shaders */
}
......@@ -877,7 +894,12 @@ midgard_compile_shader_nir(nir_shader *nir, struct util_dynarray *compiled)
util_dynarray_init(compiled, NULL);
util_dynarray_foreach(&ctx->current_block, midgard_instruction, ins) {
printf("instructions\n");
}
util_dynarray_foreach(&ctx->current_block, midgard_instruction, ins) {
printf("EMM\n");
if (!ins->unused)
ins += emit_binary_instruction(ctx, ins, compiled);
}
......
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