2 * Copyright (C) 2008-2009 Nicolai Haehnle.
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sublicense, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial
16 * portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
22 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 #include "radeon_program_pair.h"
32 * Return the source slot where we installed the given register access,
33 * or -1 if no slot was free anymore.
35 int rc_pair_alloc_source(struct rc_pair_instruction
*pair
,
36 unsigned int rgb
, unsigned int alpha
,
37 rc_register_file file
, unsigned int index
)
40 int candidate_quality
= -1;
43 if ((!rgb
&& !alpha
) || file
== RC_FILE_NONE
)
46 for(i
= 0; i
< 3; ++i
) {
49 if (pair
->RGB
.Src
[i
].Used
) {
50 if (pair
->RGB
.Src
[i
].File
!= file
||
51 pair
->RGB
.Src
[i
].Index
!= index
)
57 if (pair
->Alpha
.Src
[i
].Used
) {
58 if (pair
->Alpha
.Src
[i
].File
!= file
||
59 pair
->Alpha
.Src
[i
].Index
!= index
)
64 if (q
> candidate_quality
) {
65 candidate_quality
= q
;
72 pair
->RGB
.Src
[candidate
].Used
= 1;
73 pair
->RGB
.Src
[candidate
].File
= file
;
74 pair
->RGB
.Src
[candidate
].Index
= index
;
77 pair
->Alpha
.Src
[candidate
].Used
= 1;
78 pair
->Alpha
.Src
[candidate
].File
= file
;
79 pair
->Alpha
.Src
[candidate
].Index
= index
;