src/lima/pp_lir/instr_combine.c
/* tries to combine two instructions with no dependencies, i.e. individual
 * unscheduled instructions can go in any order
 */
tries to combine two instructions with no dependencies, i.e. individual
unscheduled instructions can go in any order
tries to combine two instructions with no dependencies i . e . individual unscheduled instructions can go in any order
bool lima_pp_lir_instr_combine_indep(lima_pp_lir_scheduled_instr_t* instr,
									 lima_pp_lir_scheduled_instr_t* other)
{
	int i;
	unsigned const_map[8];
	unsigned alu_map[5];
	if (!try_create_const_map(instr, other, const_map))
		return false;
	if (other->varying_instr)
	{
		if (instr->varying_instr)
			return false;
	}
	if (other->texld_instr)
	{
		if (other->texld_instr)
			return false;
	}
	if (other->uniform_instr)
	{
		if (instr->uniform_instr)
			return false;
	}
	unsigned cur_alu_pos = 5;
	for (i = 4; i >= 0; i--)
	{
		if (!other->alu_instrs[i])
			continue;
		unsigned cur_index = cur_alu_pos;
		if (cur_index == 0)
			return false;
		cur_index--;
		if ((i == 0 || i == 1) && other->alu_instrs[0] && other->alu_instrs[1] &&
			!lima_pp_lir_instr_can_swap(other->alu_instrs[0], other->alu_instrs[1]))
		{
			if (cur_index < i || instr->alu_instrs[i])
				return false;
			alu_map[i] = i;
			cur_alu_pos = i;
			continue;
		}
		if ((i == 2 || i == 3) && other->alu_instrs[2] && other->alu_instrs[3] &&
			!lima_pp_lir_instr_can_swap(other->alu_instrs[2], other->alu_instrs[3]))
		{
			if (cur_index < i || instr->alu_instrs[i])
				return false;
			alu_map[i] = i;
			cur_alu_pos = i;
			continue;
		}
		while (true)
		{
			while (instr->alu_instrs[cur_index])
			{
				if (cur_index == 0)
					return false;
				cur_index--;
			}
			if (other->possible_alu_instr_pos[i][cur_index])
				break;
			if (cur_index == 0)
				return false;
			cur_index--;
		}
		alu_map[i] = cur_index;
		cur_alu_pos = cur_index;
	}
	if (other->temp_store_instr && !instr->temp_store_instr)
	{
		if (instr->temp_store_instr)
			return false;
	}
	if (other->branch_instr && !instr->branch_instr)
	{
		if (instr->branch_instr)
			return false;
	}
	apply_const_map(instr, other, const_map);
	if (other->varying_instr)
	{
		rewrite_consts(other->varying_instr, const_map);
		instr->varying_instr = other->varying_instr;
		other->varying_instr = NULL;
		instr->varying_instr->sched_instr = instr;
	}
	if (other->texld_instr)
	{
		rewrite_consts(other->texld_instr, const_map);
		instr->texld_instr = other->texld_instr;
		other->texld_instr = NULL;
		instr->texld_instr->sched_instr = instr;
	}
	if (other->uniform_instr)
	{
		rewrite_consts(other->uniform_instr, const_map);
		instr->uniform_instr = other->uniform_instr;
		other->uniform_instr = NULL;
		instr->uniform_instr->sched_instr = instr;
	}
	for (i = 0; i < 5; i++)
	{
		if (other->alu_instrs[i])
		{
			rewrite_consts(other->alu_instrs[i], const_map);
			instr->alu_instrs[alu_map[i]] = other->alu_instrs[i];
			other->alu_instrs[i] = NULL;
			instr->alu_instrs[alu_map[i]]->sched_instr = instr;
		}
	}
	if (other->temp_store_instr)
	{
		rewrite_consts(other->temp_store_instr, const_map);
		instr->temp_store_instr = other->temp_store_instr;
		other->temp_store_instr = NULL;
		instr->temp_store_instr->sched_instr = instr;
	}
	if (other->branch_instr)
	{
		rewrite_consts(other->branch_instr, const_map);
		instr->branch_instr = other->branch_instr;
		other->branch_instr = NULL;
		instr->branch_instr->sched_instr = instr;
	}
	combine_deps(instr, other);
	return true;
}
bool lima_pp_lir_instr_combine_indep ( lima_pp_lir_scheduled_instr_t * instr , lima_pp_lir_scheduled_instr_t * other ) { int i ; unsigned const_map [ 8 ] ; unsigned alu_map [ 5 ] ; if ( ! try_create_const_map ( instr , other , const_map ) ) return false ; if ( other -> varying_instr ) { if ( instr -> varying_instr ) return false ; } if ( other -> texld_instr ) { if ( other -> texld_instr ) return false ; } if ( other -> uniform_instr ) { if ( instr -> uniform_instr ) return false ; } unsigned cur_alu_pos = 5 ; for ( i = 4 ; i >= 0 ; i -- ) { if ( ! other -> alu_instrs [ i ] ) continue ; unsigned cur_index = cur_alu_pos ; if ( cur_index == 0 ) return false ; cur_index -- ; if ( ( i == 0 || i == 1 ) && other -> alu_instrs [ 0 ] && other -> alu_instrs [ 1 ] && ! lima_pp_lir_instr_can_swap ( other -> alu_instrs [ 0 ] , other -> alu_instrs [ 1 ] ) ) { if ( cur_index < i || instr -> alu_instrs [ i ] ) return false ; alu_map [ i ] = i ; cur_alu_pos = i ; continue ; } if ( ( i == 2 || i == 3 ) && other -> alu_instrs [ 2 ] && other -> alu_instrs [ 3 ] && ! lima_pp_lir_instr_can_swap ( other -> alu_instrs [ 2 ] , other -> alu_instrs [ 3 ] ) ) { if ( cur_index < i || instr -> alu_instrs [ i ] ) return false ; alu_map [ i ] = i ; cur_alu_pos = i ; continue ; } while ( true ) { while ( instr -> alu_instrs [ cur_index ] ) { if ( cur_index == 0 ) return false ; cur_index -- ; } if ( other -> possible_alu_instr_pos [ i ] [ cur_index ] ) break ; if ( cur_index == 0 ) return false ; cur_index -- ; } alu_map [ i ] = cur_index ; cur_alu_pos = cur_index ; } if ( other -> temp_store_instr && ! instr -> temp_store_instr ) { if ( instr -> temp_store_instr ) return false ; } if ( other -> branch_instr && ! instr -> branch_instr ) { if ( instr -> branch_instr ) return false ; } apply_const_map ( instr , other , const_map ) ; if ( other -> varying_instr ) { rewrite_consts ( other -> varying_instr , const_map ) ; instr -> varying_instr = other -> varying_instr ; other -> varying_instr = NULL ; instr -> varying_instr -> sched_instr = instr ; } if ( other -> texld_instr ) { rewrite_consts ( other -> texld_instr , const_map ) ; instr -> texld_instr = other -> texld_instr ; other -> texld_instr = NULL ; instr -> texld_instr -> sched_instr = instr ; } if ( other -> uniform_instr ) { rewrite_consts ( other -> uniform_instr , const_map ) ; instr -> uniform_instr = other -> uniform_instr ; other -> uniform_instr = NULL ; instr -> uniform_instr -> sched_instr = instr ; } for ( i = 0 ; i < 5 ; i ++ ) { if ( other -> alu_instrs [ i ] ) { rewrite_consts ( other -> alu_instrs [ i ] , const_map ) ; instr -> alu_instrs [ alu_map [ i ] ] = other -> alu_instrs [ i ] ; other -> alu_instrs [ i ] = NULL ; instr -> alu_instrs [ alu_map [ i ] ] -> sched_instr = instr ; } } if ( other -> temp_store_instr ) { rewrite_consts ( other -> temp_store_instr , const_map ) ; instr -> temp_store_instr = other -> temp_store_instr ; other -> temp_store_instr = NULL ; instr -> temp_store_instr -> sched_instr = instr ; } if ( other -> branch_instr ) { rewrite_consts ( other -> branch_instr , const_map ) ; instr -> branch_instr = other -> branch_instr ; other -> branch_instr = NULL ; instr -> branch_instr -> sched_instr = instr ; } combine_deps ( instr , other ) ; return true ; }
tries to combine two instructions with no dependencies, i.e.
tries to combine two instructions with no dependencies i . e .
//Try to find a slot for the ALU instruction