static void try_convert_and_pair( struct schedule_state *s, struct schedule_instruction ** inst_list) { struct schedule_instruction * list_ptr = *inst_list; while (list_ptr && *inst_list && (*inst_list)->NextReady) { int paired = 0; if (list_ptr->Instruction->U.P.Alpha.Opcode != RC_OPCODE_NOP && list_ptr->Instruction->U.P.RGB.Opcode != RC_OPCODE_REPL_ALPHA) { goto next; } if (list_ptr->NumWriteValues == 1 && convert_rgb_to_alpha(s, list_ptr)) { struct schedule_instruction * pair_ptr; remove_inst_from_list(inst_list, list_ptr); add_inst_to_list_score(&s->ReadyAlpha, list_ptr); for (pair_ptr = s->ReadyRGB; pair_ptr; pair_ptr = pair_ptr->NextReady) { if (merge_instructions(&pair_ptr->Instruction->U.P, &list_ptr->Instruction->U.P)) { remove_inst_from_list(&s->ReadyAlpha, list_ptr); remove_inst_from_list(&s->ReadyRGB, pair_ptr); pair_ptr->PairedInst = list_ptr; add_inst_to_list(&s->ReadyFullALU, pair_ptr); list_ptr = *inst_list; paired = 1; break; } } } if (!paired) { next: list_ptr = list_ptr->NextReady; } } }
/** * 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); }