1 /* -*- mesa-c++  -*-
2  *
3  * Copyright (c) 2018-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_GDSINSTR_H
28 #define SFN_GDSINSTR_H
29 
30 #include "sfn_instruction_base.h"
31 
32 #include <bitset>
33 
34 namespace r600 {
35 
36 class GDSInstr : public Instruction
37 {
38 public:
39    GDSInstr(ESDOp op, const GPRVector& dest,  const PValue& value,
40             const PValue &uav_id, int uav_base);
41    GDSInstr(ESDOp op, const GPRVector& dest,  const PValue& value,
42             const PValue& value2, const PValue &uav_id, int uav_base);
43    GDSInstr(ESDOp op, const GPRVector& dest,  const PValue &uav_id, int uav_base);
44 
op()45    ESDOp op() const {return m_op;}
46 
src_sel()47    int src_sel() const {
48       if (!m_src)
49          return 0;
50 
51       assert(m_src->type() == Value::gpr);
52       return m_src->sel();
53    }
54 
src2_chan()55    int src2_chan() const {
56       if (!m_src2)
57          return 0;
58 
59       assert(m_src->type() == Value::gpr);
60       return m_src->chan();
61    }
62 
src_swizzle(int idx)63    int src_swizzle(int idx) const {assert(idx < 3); return m_src_swizzle[idx];}
64 
dest_sel()65    int dest_sel() const {
66       return m_dest.sel();
67    }
68 
dest_swizzle(int i)69    int dest_swizzle(int i) const {
70       if (i < 4)
71          return m_dest_swizzle[i];
72       return 7;
73    }
74 
set_dest_swizzle(const std::array<int,4> & swz)75    void set_dest_swizzle(const std::array<int,4>& swz) {
76       m_dest_swizzle = swz;
77    }
78 
uav_id()79    PValue uav_id() const {return m_uav_id;}
uav_base()80    int uav_base() const {return m_uav_base;}
81 
accept(InstructionVisitor & visitor)82    bool accept(InstructionVisitor& visitor) override {return visitor.visit(*this);}
accept(ConstInstructionVisitor & visitor)83    bool accept(ConstInstructionVisitor& visitor) const override {return visitor.visit(*this);}
84 
85 private:
86 
87    bool is_equal_to(const Instruction& lhs) const override;
88    void do_print(std::ostream& os) const override;
89 
90    ESDOp m_op;
91 
92    PValue m_src;
93    PValue m_src2;
94    GPRVector m_dest;
95    std::array <int, 4> m_dest_swizzle;
96    std::array <int, 3> m_src_swizzle;
97 
98    EBufferIndexMode m_buffer_index_mode;
99    PValue m_uav_id;
100    int m_uav_base;
101    std::bitset<8> m_flags;
102 
103 };
104 
105 class RatInstruction : public Instruction {
106 
107 public:
108    enum ERatOp {
109       NOP,
110       STORE_TYPED,
111       STORE_RAW,
112       STORE_RAW_FDENORM,
113       CMPXCHG_INT,
114       CMPXCHG_FLT,
115       CMPXCHG_FDENORM,
116       ADD,
117       SUB,
118       RSUB,
119       MIN_INT,
120       MIN_UINT,
121       MAX_INT,
122       MAX_UINT,
123       AND,
124       OR,
125       XOR,
126       MSKOR,
127       INC_UINT,
128       DEC_UINT,
129       NOP_RTN = 32,
130       XCHG_RTN = 34,
131       XCHG_FDENORM_RTN,
132       CMPXCHG_INT_RTN,
133       CMPXCHG_FLT_RTN,
134       CMPXCHG_FDENORM_RTN,
135       ADD_RTN,
136       SUB_RTN,
137       RSUB_RTN,
138       MIN_INT_RTN,
139       MIN_UINT_RTN,
140       MAX_INT_RTN,
141       MAX_UINT_RTN,
142       AND_RTN,
143       OR_RTN,
144       XOR_RTN,
145       MSKOR_RTN,
146       UINT_RTN,
147       UNSUPPORTED
148    };
149 
150    RatInstruction(ECFOpCode cf_opcode, ERatOp rat_op,
151                   const GPRVector& data, const GPRVector& index,
152                   int rat_id, const PValue& rat_id_offset,
153                   int burst_count, int comp_mask, int element_size,
154                   bool ack);
155 
rat_id_offset()156    PValue rat_id_offset() const { return m_rat_id_offset;}
rat_id()157    int  rat_id() const { return m_rat_id;}
158 
rat_op()159    ERatOp rat_op() const {return m_rat_op;}
160 
data_gpr()161    int data_gpr() const {return m_data.sel();}
index_gpr()162    int index_gpr() const {return m_index.sel();}
elm_size()163    int elm_size() const {return m_element_size;}
164 
comp_mask()165    int comp_mask() const {return m_comp_mask;}
166 
need_ack()167    bool need_ack() const {return m_need_ack;}
burst_count()168    int burst_count() const {return m_burst_count;}
169 
170    static ERatOp opcode(nir_intrinsic_op opcode);
171 
data_swz(int chan)172    int data_swz(int chan) const {return m_data.chan_i(chan);}
173 
cf_opcode()174    ECFOpCode cf_opcode() const { return m_cf_opcode;}
175 
set_ack()176    void set_ack() {m_need_ack = true; }
177 
accept(InstructionVisitor & visitor)178    bool accept(InstructionVisitor& visitor) override {return visitor.visit(*this);}
accept(ConstInstructionVisitor & visitor)179    bool accept(ConstInstructionVisitor& visitor) const override {return visitor.visit(*this);}
180 
181 
182 private:
183 
184    bool is_equal_to(const Instruction& lhs) const override;
185    void do_print(std::ostream& os) const override;
186 
187    ECFOpCode m_cf_opcode;
188    ERatOp m_rat_op;
189 
190    GPRVector m_data;
191    GPRVector m_index;
192 
193    int m_rat_id;
194    PValue m_rat_id_offset;
195    int m_burst_count;
196    int m_comp_mask;
197    int m_element_size;
198 
199    std::bitset<8> m_flags;
200 
201    bool m_need_ack;
202 
203 };
204 
205 class GDSStoreTessFactor : public Instruction {
206 public:
207       GDSStoreTessFactor(GPRVector& value);
sel()208       int sel() const {return m_value.sel();}
chan(int i)209       int chan(int i ) const {return m_value.chan_i(i);}
210 
211       void replace_values(const ValueSet& candiates, PValue new_value) override;
212 
accept(InstructionVisitor & visitor)213       bool accept(InstructionVisitor& visitor) override {return visitor.visit(*this);}
accept(ConstInstructionVisitor & visitor)214       bool accept(ConstInstructionVisitor& visitor) const override {return visitor.visit(*this);}
215 
216 private:
217       bool is_equal_to(const Instruction& lhs) const override;
218       void do_print(std::ostream& os) const override;
219 
220       GPRVector m_value;
221 };
222 
223 }
224 
225 #endif // SFN_GDSINSTR_H
226