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];
59
mov->U.I.PreSub = inst->U.I.PreSub;
62
for(unsigned int chan = 0; chan < 4; ++chan) {
63
if (!GET_BIT(split.Phase[phase], chan))
64
SET_SWZ(mov->U.I.SrcReg[0].Swizzle, chan, RC_SWIZZLE_UNUSED);
66
phase_refmask |= 1 << GET_SWZ(mov->U.I.SrcReg[0].Swizzle, chan);
69
phase_refmask &= RC_MASK_XYZW;
71
masked_negate = split.Phase[phase] & mov->U.I.SrcReg[0].Negate;
72
if (masked_negate == 0)
73
mov->U.I.SrcReg[0].Negate = 0;
74
else if (masked_negate == split.Phase[phase])
75
mov->U.I.SrcReg[0].Negate = RC_MASK_XYZW;
79
inst->U.I.SrcReg[src].File = RC_FILE_TEMPORARY;
80
inst->U.I.SrcReg[src].Index = tempreg;
81
inst->U.I.SrcReg[src].Swizzle = 0;
82
inst->U.I.SrcReg[src].Negate = RC_MASK_NONE;
83
inst->U.I.SrcReg[src].Abs = 0;
84
for(unsigned int chan = 0; chan < 4; ++chan) {
85
SET_SWZ(inst->U.I.SrcReg[src].Swizzle, chan,
86
GET_BIT(usemask, chan) ? chan : RC_SWIZZLE_UNUSED);
90
void rc_dataflow_swizzles(struct radeon_compiler * c, void *user)
92
struct rc_instruction * inst;
94
for(inst = c->Program.Instructions.Next; inst != &c->Program.Instructions; inst = inst->Next) {
95
const struct rc_opcode_info * opcode = rc_get_opcode_info(inst->U.I.Opcode);
98
for(src = 0; src < opcode->NumSrcRegs; ++src) {
99
if (!c->SwizzleCaps->IsNative(inst->U.I.Opcode, inst->U.I.SrcReg[src]))
100
rewrite_source(c, inst, src);