1 /* -*- mesa-c++ -*- 2 * 3 * Copyright (c) 2019 Collabora LTD 4 * 5 * Author: Gert Wollny <gert.wollny@collabora.com> 6 * 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: 13 * 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 16 * Software. 17 * 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. 25 */ 26 27 #ifndef sfn_r600_instruction_alu_h 28 #define sfn_r600_instruction_alu_h 29 30 #include "sfn_instruction_base.h" 31 #include "sfn_alu_defines.h" 32 33 namespace r600 { 34 35 enum AluModifiers { 36 alu_src0_neg, 37 alu_src0_abs, 38 alu_src0_rel, 39 alu_src1_neg, 40 alu_src1_abs, 41 alu_src1_rel, 42 alu_src2_neg, 43 alu_src2_rel, 44 alu_dst_clamp, 45 alu_dst_rel, 46 alu_last_instr, 47 alu_update_exec, 48 alu_update_pred, 49 alu_write, 50 alu_op3 51 }; 52 53 enum AluDstModifiers { 54 omod_off = 0, 55 omod_mul2 = 1, 56 omod_mul4 = 2, 57 omod_divl2 = 3 58 }; 59 60 enum AluPredSel { 61 pred_off = 0, 62 pred_zero = 2, 63 pred_one = 3 64 }; 65 66 enum AluBankSwizzle { 67 alu_vec_012 = 0, 68 sq_alu_scl_201 = 0, 69 alu_vec_021 = 1, 70 sq_alu_scl_122 = 1, 71 alu_vec_120 = 2, 72 sq_alu_scl_212 = 2, 73 alu_vec_102 = 3, 74 sq_alu_scl_221 = 3, 75 alu_vec_201 = 4, 76 alu_vec_210 = 5, 77 alu_vec_unknown = 6 78 }; 79 80 class AluInstruction : public Instruction { 81 public: 82 83 static const AluModifiers src_abs_flags[2]; 84 static const AluModifiers src_neg_flags[3]; 85 static const AluModifiers src_rel_flags[3]; 86 87 AluInstruction(EAluOp opcode); 88 AluInstruction(EAluOp opcode, PValue dest, 89 std::vector<PValue> src0, 90 const std::set<AluModifiers>& m_flags); 91 92 AluInstruction(EAluOp opcode, PValue dest, PValue src0, 93 const std::set<AluModifiers>& m_flags); 94 95 AluInstruction(EAluOp opcode, PValue dest, 96 PValue src0, PValue src1, 97 const std::set<AluModifiers>& m_flags); 98 99 AluInstruction(EAluOp opcode, PValue dest, PValue src0, PValue src1, 100 PValue src2, 101 const std::set<AluModifiers>& m_flags); 102 103 104 void set_flag(AluModifiers flag); 105 unsigned n_sources() const; 106 dest()107 PValue dest() {return m_dest;} opcode()108 EAluOp opcode() const {return m_opcode;} dest()109 const Value *dest() const {return m_dest.get();} src(unsigned i)110 Value& src(unsigned i) const {assert(i < m_src.size() && m_src[i]); return *m_src[i];} psrc(unsigned i)111 PValue *psrc(unsigned i) {assert(i < m_src.size()); return &m_src[i];} is_last()112 bool is_last() const {return m_flags.test(alu_last_instr);} write()113 bool write() const {return m_flags.test(alu_write);} flag(AluModifiers f)114 bool flag(AluModifiers f) const {return m_flags.test(f);} 115 void set_bank_swizzle(AluBankSwizzle swz); bank_swizzle()116 int bank_swizzle() const {return m_bank_swizzle;} cf_type()117 ECFAluOpCode cf_type() const {return m_cf_type;} set_cf_type(ECFAluOpCode cf_type)118 void set_cf_type(ECFAluOpCode cf_type){ m_cf_type = cf_type; } 119 120 void replace_values(const ValueSet& candiates, PValue new_value) override; 121 122 private: 123 124 bool is_equal_to(const Instruction& lhs) const override; 125 void do_print(std::ostream& os) const override; 126 PValue remap_one_registers(PValue reg, std::vector<rename_reg_pair>& map, 127 ValueMap &values); 128 129 130 EAluOp m_opcode; 131 PValue m_dest; 132 std::vector<PValue> m_src; 133 AluOpFlags m_flags; 134 AluDstModifiers m_omod; 135 AluPredSel m_pred_sel; 136 AluBankSwizzle m_bank_swizzle; 137 ECFAluOpCode m_cf_type; 138 }; 139 140 } 141 142 #endif 143