3 * Copyright (c) 2018 Collabora LTD
5 * Author: Gert Wollny <gert.wollny@collabora.com>
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * on the rights to use, copy, modify, merge, publish, distribute, sub
11 * license, and/or sell copies of the Software, and to permit persons to whom
12 * the Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice (including the next
15 * paragraph) shall be included in all copies or substantial portions of the
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
22 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24 * USE OR OTHER DEALINGS IN THE SOFTWARE.
27 #include "sfn_instruction_alu.h"
28 #include "sfn_valuepool.h"
32 const AluModifiers
AluInstruction::src_abs_flags
[2] =
33 {alu_src0_abs
, alu_src1_abs
};
34 const AluModifiers
AluInstruction::src_neg_flags
[3] =
35 {alu_src0_neg
, alu_src1_neg
, alu_src2_neg
};
36 const AluModifiers
AluInstruction::src_rel_flags
[3] =
37 {alu_src0_rel
, alu_src1_rel
, alu_src2_rel
};
39 AluInstruction::AluInstruction(EAluOp opcode
):
40 Instruction (Instruction::alu
),
42 m_src(alu_ops
.at(opcode
).nsrc
),
43 m_bank_swizzle(alu_vec_unknown
),
46 if (alu_ops
.at(opcode
).nsrc
== 3)
50 AluInstruction::AluInstruction(EAluOp opcode
, PValue dest
,
51 std::vector
<PValue
> src
,
52 const std::set
<AluModifiers
>& flags
):
53 Instruction (Instruction::alu
),
56 m_bank_swizzle(alu_vec_unknown
),
64 if (alu_ops
.at(opcode
).nsrc
== 3)
68 add_remappable_src_value(&s
);
70 add_remappable_dst_value(&m_dest
);
73 AluInstruction::AluInstruction(EAluOp opcode
, PValue dest
, PValue src0
,
74 const std::set
<AluModifiers
>& flags
):
75 AluInstruction(opcode
, dest
, std::vector
<PValue
>{src0
}, flags
)
79 AluInstruction::AluInstruction(EAluOp opcode
, PValue dest
,
80 PValue src0
, PValue src1
,
81 const std::set
<AluModifiers
> &m_flags
):
82 AluInstruction(opcode
, dest
, {src0
, src1
}, m_flags
)
86 AluInstruction::AluInstruction(EAluOp opcode
, PValue dest
, PValue src0
,
87 PValue src1
, PValue src2
,
88 const std::set
<AluModifiers
> &flags
):
89 AluInstruction(opcode
, dest
, {src0
, src1
, src2
}, flags
)
93 bool AluInstruction::is_equal_to(const Instruction
& lhs
) const
95 assert(lhs
.type() == alu
);
96 const auto& oth
= static_cast<const AluInstruction
&>(lhs
);
98 if (m_opcode
!= oth
.m_opcode
) {
102 if (*m_dest
!= *oth
.m_dest
)
105 if (m_src
.size() != oth
.m_src
.size())
108 for (unsigned i
= 0; i
< m_src
.size(); ++i
)
109 if (*m_src
[i
] != *oth
.m_src
[i
]) {
112 return (m_flags
== oth
.m_flags
&& m_cf_type
== oth
.m_cf_type
);
115 void AluInstruction::replace_values(const ValueSet
& candiates
, PValue new_value
)
117 for (auto c
: candiates
) {
121 for (auto& s
: m_src
) {
128 PValue
AluInstruction::remap_one_registers(PValue reg
, std::vector
<rename_reg_pair
>& map
,
131 auto new_index
= map
[reg
->sel()];
133 reg
= values
.get_or_inject(new_index
.new_reg
, reg
->chan());
134 map
[reg
->sel()].used
= true;
139 void AluInstruction::set_flag(AluModifiers flag
)
144 void AluInstruction::set_bank_swizzle(AluBankSwizzle bswz
)
146 m_bank_swizzle
= bswz
;
149 unsigned AluInstruction::n_sources() const
154 void AluInstruction::do_print(std::ostream
& os
) const
156 os
<< "ALU " << alu_ops
.at(m_opcode
).name
;
157 if (m_flags
.test(alu_dst_clamp
))
160 os
<< ' ' << *m_dest
<< " : " ;
162 for (unsigned i
= 0; i
< m_src
.size(); ++i
) {
166 if (m_flags
.test(src_neg_flags
[i
])) pflags
|= Value::PrintFlags::has_neg
;
167 if (m_flags
.test(src_rel_flags
[i
])) pflags
|= Value::PrintFlags::is_rel
;
169 if (m_flags
.test(src_abs_flags
[i
])) pflags
|= Value::PrintFlags::has_abs
;
170 m_src
[i
]->print(os
, Value::PrintFlags(0, pflags
));
173 os
<< (m_flags
.test(alu_write
) ? 'W' : ' ');
174 os
<< (m_flags
.test(alu_last_instr
) ? 'L' : ' ');
175 os
<< (m_flags
.test(alu_update_exec
) ? 'E' : ' ');
176 os
<< (m_flags
.test(alu_update_pred
) ? 'P' : ' ');
179 os
<< " BS:" << m_bank_swizzle
;
180 os
<< " CF:" << m_cf_type
;