/** * Find a good ALU instruction or pair of ALU instruction and emit it. * * Prefer emitting full ALU instructions, so that when we reach a point * where no full ALU instruction can be emitted, we have more candidates * for RGB/Alpha pairing. */ static void emit_one_alu(struct schedule_state *s, struct rc_instruction * before) { struct schedule_instruction * sinst; if (s->ReadyFullALU || !(s->ReadyRGB && s->ReadyAlpha)) { if (s->ReadyFullALU) { sinst = s->ReadyFullALU; s->ReadyFullALU = s->ReadyFullALU->NextReady; } else if (s->ReadyRGB) { sinst = s->ReadyRGB; s->ReadyRGB = s->ReadyRGB->NextReady; } else { sinst = s->ReadyAlpha; s->ReadyAlpha = s->ReadyAlpha->NextReady; } rc_insert_instruction(before->Prev, sinst->Instruction); commit_alu_instruction(s, sinst); } else { struct schedule_instruction **prgb; struct schedule_instruction **palpha; /* Some pairings might fail because they require too * many source slots; try all possible pairings if necessary */ for(prgb = &s->ReadyRGB; *prgb; prgb = &(*prgb)->NextReady) { for(palpha = &s->ReadyAlpha; *palpha; palpha = &(*palpha)->NextReady) { struct schedule_instruction * psirgb = *prgb; struct schedule_instruction * psialpha = *palpha; if (!merge_instructions(&psirgb->Instruction->U.P, &psialpha->Instruction->U.P)) continue; *prgb = (*prgb)->NextReady; *palpha = (*palpha)->NextReady; rc_insert_instruction(before->Prev, psirgb->Instruction); commit_alu_instruction(s, psirgb); commit_alu_instruction(s, psialpha); goto success; } } /* No success in pairing; just take the first RGB instruction */ sinst = s->ReadyRGB; s->ReadyRGB = s->ReadyRGB->NextReady; rc_insert_instruction(before->Prev, sinst->Instruction); commit_alu_instruction(s, sinst); success: ; } /* If the instruction we just emitted uses a presubtract value, and * the presubtract sources were written by the previous intstruction, * the previous instruction needs a nop. */ presub_nop(before->Prev); }
static void emit_instruction( struct schedule_state * s, struct rc_instruction * before) { int max_score = -1; struct schedule_instruction * max_inst = NULL; struct schedule_instruction ** max_list = NULL; unsigned tex_count = 0; struct schedule_instruction * tex_ptr; pair_instructions(s); #if VERBOSE fprintf(stderr, "Full:\n"); print_list(s->ReadyFullALU); fprintf(stderr, "RGB:\n"); print_list(s->ReadyRGB); fprintf(stderr, "Alpha:\n"); print_list(s->ReadyAlpha); fprintf(stderr, "TEX:\n"); print_list(s->ReadyTEX); #endif for (tex_ptr = s->ReadyTEX; tex_ptr; tex_ptr = tex_ptr->NextReady) { if (tex_ptr->Instruction->U.I.Opcode == RC_OPCODE_KIL) { emit_all_tex(s, before); return; } tex_count++; } update_max_score(s, &s->ReadyFullALU, &max_score, &max_inst, &max_list); update_max_score(s, &s->ReadyRGB, &max_score, &max_inst, &max_list); update_max_score(s, &s->ReadyAlpha, &max_score, &max_inst, &max_list); if (tex_count >= s->max_tex_group || max_score == -1 || (s->TEXCount > 0 && tex_count == s->TEXCount) || (!s->C->is_r500 && tex_count > 0 && max_score == -1)) { emit_all_tex(s, before); } else { remove_inst_from_list(max_list, max_inst); rc_insert_instruction(before->Prev, max_inst->Instruction); commit_alu_instruction(s, max_inst); presub_nop(before->Prev); } }
/** * Find a good ALU instruction or pair of ALU instruction and emit it. * * Prefer emitting full ALU instructions, so that when we reach a point * where no full ALU instruction can be emitted, we have more candidates * for RGB/Alpha pairing. */ static void emit_one_alu(struct schedule_state *s, struct rc_instruction * before) { struct schedule_instruction * sinst; if (s->ReadyFullALU) { sinst = s->ReadyFullALU; s->ReadyFullALU = s->ReadyFullALU->NextReady; rc_insert_instruction(before->Prev, sinst->Instruction); commit_alu_instruction(s, sinst); } else { struct schedule_instruction **prgb; struct schedule_instruction **palpha; struct schedule_instruction *prev; pair: /* Some pairings might fail because they require too * many source slots; try all possible pairings if necessary */ for(prgb = &s->ReadyRGB; *prgb; prgb = &(*prgb)->NextReady) { for(palpha = &s->ReadyAlpha; *palpha; palpha = &(*palpha)->NextReady) { struct schedule_instruction * psirgb = *prgb; struct schedule_instruction * psialpha = *palpha; if (!merge_instructions(&psirgb->Instruction->U.P, &psialpha->Instruction->U.P)) continue; *prgb = (*prgb)->NextReady; *palpha = (*palpha)->NextReady; rc_insert_instruction(before->Prev, psirgb->Instruction); commit_alu_instruction(s, psirgb); commit_alu_instruction(s, psialpha); goto success; } } prev = NULL; /* No success in pairing, now try to convert one of the RGB * instructions to an Alpha so we can pair it with another RGB. */ if (s->ReadyRGB && s->ReadyRGB->NextReady) { for(prgb = &s->ReadyRGB; *prgb; prgb = &(*prgb)->NextReady) { if ((*prgb)->NumWriteValues == 1) { struct schedule_instruction * prgb_next; if (!convert_rgb_to_alpha(s, *prgb)) goto cont_loop; prgb_next = (*prgb)->NextReady; /* Add instruction to the Alpha ready list. */ (*prgb)->NextReady = s->ReadyAlpha; s->ReadyAlpha = *prgb; /* Remove instruction from the RGB ready list.*/ if (prev) prev->NextReady = prgb_next; else s->ReadyRGB = prgb_next; goto pair; } cont_loop: prev = *prgb; } } /* Still no success in pairing, just take the first RGB * or alpha instruction. */ if (s->ReadyRGB) { sinst = s->ReadyRGB; s->ReadyRGB = s->ReadyRGB->NextReady; } else if (s->ReadyAlpha) { sinst = s->ReadyAlpha; s->ReadyAlpha = s->ReadyAlpha->NextReady; } else { /*XXX Something real bad has happened. */ assert(0); } rc_insert_instruction(before->Prev, sinst->Instruction); commit_alu_instruction(s, sinst); success: ; } /* If the instruction we just emitted uses a presubtract value, and * the presubtract sources were written by the previous intstruction, * the previous instruction needs a nop. */ presub_nop(before->Prev); }