2 * Copyright 2010 Tom Stellard <tstellar@gmail.com>
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.
32 #include "radeon_compiler_util.h"
34 #include "radeon_compiler.h"
35 #include "radeon_dataflow.h"
38 unsigned int rc_swizzle_to_writemask(unsigned int swz
)
40 unsigned int mask
= 0;
43 for(i
= 0; i
< 4; i
++) {
44 mask
|= 1 << GET_SWZ(swz
, i
);
51 unsigned int rc_src_reads_dst_mask(
52 rc_register_file src_file
,
55 rc_register_file dst_file
,
57 unsigned int dst_mask
)
59 if (src_file
!= dst_file
|| src_idx
!= dst_idx
) {
62 return dst_mask
& rc_swizzle_to_writemask(src_swz
);
65 unsigned int rc_source_type_swz(unsigned int swizzle
, unsigned int channels
)
68 unsigned int swz
= RC_SWIZZLE_UNUSED
;
69 unsigned int ret
= RC_SOURCE_NONE
;
71 for(chan
= 0; chan
< channels
; chan
++) {
72 swz
= GET_SWZ(swizzle
, chan
);
73 if (swz
== RC_SWIZZLE_W
) {
74 ret
|= RC_SOURCE_ALPHA
;
75 } else if (swz
== RC_SWIZZLE_X
|| swz
== RC_SWIZZLE_Y
76 || swz
== RC_SWIZZLE_Z
) {
83 unsigned int rc_source_type_mask(unsigned int mask
)
85 unsigned int ret
= RC_SOURCE_NONE
;
87 if (mask
& RC_MASK_XYZ
)
91 ret
|= RC_SOURCE_ALPHA
;
96 struct can_use_presub_data
{
97 struct rc_src_register RemoveSrcs
[3];
98 unsigned int RGBCount
;
99 unsigned int AlphaCount
;
102 static void can_use_presub_read_cb(
104 struct rc_instruction
* inst
,
105 rc_register_file file
,
109 struct can_use_presub_data
* d
= userdata
;
110 unsigned int src_type
= rc_source_type_mask(mask
);
113 if (file
== RC_FILE_NONE
)
116 for(i
= 0; i
< 3; i
++) {
117 if (d
->RemoveSrcs
[i
].File
== file
118 && d
->RemoveSrcs
[i
].Index
== index
) {
120 ~rc_source_type_swz(d
->RemoveSrcs
[i
].Swizzle
, 4);
124 if (src_type
& RC_SOURCE_RGB
)
127 if (src_type
& RC_SOURCE_ALPHA
)
131 unsigned int rc_inst_can_use_presub(
132 struct rc_instruction
* inst
,
133 rc_presubtract_op presub_op
,
134 unsigned int presub_writemask
,
135 struct rc_src_register replace_reg
,
136 struct rc_src_register presub_src0
,
137 struct rc_src_register presub_src1
)
139 struct can_use_presub_data d
;
140 unsigned int num_presub_srcs
;
141 unsigned int presub_src_type
= rc_source_type_mask(presub_writemask
);
142 const struct rc_opcode_info
* info
=
143 rc_get_opcode_info(inst
->U
.I
.Opcode
);
145 if (presub_op
== RC_PRESUB_NONE
) {
149 if (info
->HasTexture
) {
153 /* We can't use more than one presubtract value in an
154 * instruction, unless the two prsubtract operations
155 * are the same and read from the same registers.
156 * XXX For now we will limit instructions to only one presubtract
158 if (inst
->U
.I
.PreSub
.Opcode
!= RC_PRESUB_NONE
) {
162 memset(&d
, 0, sizeof(d
));
163 d
.RemoveSrcs
[0] = replace_reg
;
164 d
.RemoveSrcs
[1] = presub_src0
;
165 d
.RemoveSrcs
[2] = presub_src1
;
167 rc_for_all_reads_mask(inst
, can_use_presub_read_cb
, &d
);
169 num_presub_srcs
= rc_presubtract_src_reg_count(presub_op
);
171 if ((presub_src_type
& RC_SOURCE_RGB
)
172 && d
.RGBCount
+ num_presub_srcs
> 3) {
176 if ((presub_src_type
& RC_SOURCE_ALPHA
)
177 && d
.AlphaCount
+ num_presub_srcs
> 3) {