-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);
+ alpha_ptr = alpha_next;
+ }
+ rgb_ptr = rgb_next;
+ }
+
+ if (!s->Opt) {
+ return;
+ }
+
+ /* Full instructions that have RC_OPCODE_REPL_ALPHA in the RGB
+ * slot can be converted into Alpha instructions. */
+ try_convert_and_pair(s, &s->ReadyFullALU);
+
+ /* Try to convert some of the RGB instructions to Alpha and
+ * try to pair it with another RGB. */
+ try_convert_and_pair(s, &s->ReadyRGB);
+}
+
+static void update_max_score(
+ struct schedule_state * s,
+ struct schedule_instruction ** list,
+ int * max_score,
+ struct schedule_instruction ** max_inst_out,
+ struct schedule_instruction *** list_out)
+{
+ struct schedule_instruction * list_ptr;
+ for (list_ptr = *list; list_ptr; list_ptr = list_ptr->NextReady) {
+ int score;
+ s->CalcScore(list_ptr);
+ score = list_ptr->Score;
+ if (!*max_inst_out || score > *max_score) {
+ *max_score = score;
+ *max_inst_out = list_ptr;
+ *list_out = list;
+ }
+ }
+}
+
+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;