33acbd30f44116e67ae1abf5018a1f076ac8206c
2 * Copyright (C) 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_dataflow.h"
30 #include "radeon_compiler.h"
31 #include "radeon_swizzle.h"
34 static void rewrite_source(struct radeon_compiler
* c
,
35 struct rc_instruction
* inst
, unsigned src
)
37 struct rc_swizzle_split split
;
38 unsigned int tempreg
= rc_find_free_temporary(c
);
42 for(unsigned int chan
= 0; chan
< 4; ++chan
) {
43 if (GET_SWZ(inst
->U
.I
.SrcReg
[src
].Swizzle
, chan
) != RC_SWIZZLE_UNUSED
)
47 c
->SwizzleCaps
->Split(inst
->U
.I
.SrcReg
[src
], usemask
, &split
);
49 for(unsigned int phase
= 0; phase
< split
.NumPhases
; ++phase
) {
50 struct rc_instruction
* mov
= rc_insert_new_instruction(c
, inst
->Prev
);
51 unsigned int phase_refmask
;
52 unsigned int masked_negate
;
54 mov
->U
.I
.Opcode
= RC_OPCODE_MOV
;
55 mov
->U
.I
.DstReg
.File
= RC_FILE_TEMPORARY
;
56 mov
->U
.I
.DstReg
.Index
= tempreg
;
57 mov
->U
.I
.DstReg
.WriteMask
= split
.Phase
[phase
];
58 mov
->U
.I
.SrcReg
[0] = inst
->U
.I
.SrcReg
[src
];
61 for(unsigned int chan
= 0; chan
< 4; ++chan
) {
62 if (!GET_BIT(split
.Phase
[phase
], chan
))
63 SET_SWZ(mov
->U
.I
.SrcReg
[0].Swizzle
, chan
, RC_SWIZZLE_UNUSED
);
65 phase_refmask
|= 1 << GET_SWZ(mov
->U
.I
.SrcReg
[0].Swizzle
, chan
);
68 phase_refmask
&= RC_MASK_XYZW
;
70 masked_negate
= split
.Phase
[phase
] & mov
->U
.I
.SrcReg
[0].Negate
;
71 if (masked_negate
== 0)
72 mov
->U
.I
.SrcReg
[0].Negate
= 0;
73 else if (masked_negate
== split
.Phase
[phase
])
74 mov
->U
.I
.SrcReg
[0].Negate
= RC_MASK_XYZW
;
78 inst
->U
.I
.SrcReg
[src
].File
= RC_FILE_TEMPORARY
;
79 inst
->U
.I
.SrcReg
[src
].Index
= tempreg
;
80 inst
->U
.I
.SrcReg
[src
].Swizzle
= 0;
81 inst
->U
.I
.SrcReg
[src
].Negate
= RC_MASK_NONE
;
82 inst
->U
.I
.SrcReg
[src
].Abs
= 0;
83 for(unsigned int chan
= 0; chan
< 4; ++chan
) {
84 SET_SWZ(inst
->U
.I
.SrcReg
[src
].Swizzle
, chan
,
85 GET_BIT(usemask
, chan
) ? chan
: RC_SWIZZLE_UNUSED
);
89 void rc_dataflow_swizzles(struct radeon_compiler
* c
)
91 struct rc_instruction
* inst
;
93 for(inst
= c
->Program
.Instructions
.Next
; inst
!= &c
->Program
.Instructions
; inst
= inst
->Next
) {
94 const struct rc_opcode_info
* opcode
= rc_get_opcode_info(inst
->U
.I
.Opcode
);
97 for(src
= 0; src
< opcode
->NumSrcRegs
; ++src
) {
98 if (!c
->SwizzleCaps
->IsNative(inst
->U
.I
.Opcode
, inst
->U
.I
.SrcReg
[src
]))
99 rewrite_source(c
, inst
, src
);