Merge remote branch 'origin/7.8'
[mesa.git] / src / mesa / drivers / dri / r300 / compiler / radeon_program_pair.c
1 /*
2 * Copyright (C) 2008-2009 Nicolai Haehnle.
3 *
4 * All Rights Reserved.
5 *
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:
13 *
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.
17 *
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.
25 *
26 */
27
28 #include "radeon_program_pair.h"
29
30
31 /**
32 * Return the source slot where we installed the given register access,
33 * or -1 if no slot was free anymore.
34 */
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)
38 {
39 int candidate = -1;
40 int candidate_quality = -1;
41 int i;
42
43 if ((!rgb && !alpha) || file == RC_FILE_NONE)
44 return 0;
45
46 for(i = 0; i < 3; ++i) {
47 int q = 0;
48 if (rgb) {
49 if (pair->RGB.Src[i].Used) {
50 if (pair->RGB.Src[i].File != file ||
51 pair->RGB.Src[i].Index != index)
52 continue;
53 q++;
54 }
55 }
56 if (alpha) {
57 if (pair->Alpha.Src[i].Used) {
58 if (pair->Alpha.Src[i].File != file ||
59 pair->Alpha.Src[i].Index != index)
60 continue;
61 q++;
62 }
63 }
64 if (q > candidate_quality) {
65 candidate_quality = q;
66 candidate = i;
67 }
68 }
69
70 if (candidate >= 0) {
71 if (rgb) {
72 pair->RGB.Src[candidate].Used = 1;
73 pair->RGB.Src[candidate].File = file;
74 pair->RGB.Src[candidate].Index = index;
75 }
76 if (alpha) {
77 pair->Alpha.Src[candidate].Used = 1;
78 pair->Alpha.Src[candidate].File = file;
79 pair->Alpha.Src[candidate].Index = index;
80 }
81 }
82
83 return candidate;
84 }