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_EMITALUINSTRUCTION_H
28 #define SFN_EMITALUINSTRUCTION_H
29
30 #include "sfn_emitinstruction.h"
31
32 #include "sfn_alu_defines.h"
33 #include "sfn_instruction_alu.h"
34 #include "sfn_instruction_tex.h"
35
36 namespace r600 {
37
38
39 class EmitAluInstruction : public EmitInstruction
40 {
41 public:
42 EmitAluInstruction(ShaderFromNirProcessor& processor);
43
44 private:
45
46 enum AluOp2Opts {
47 op2_opt_none = 0,
48 op2_opt_reverse = 1,
49 op2_opt_neg_src1 = 1 << 1
50 };
51
52 bool do_emit(nir_instr* instr) override;
53
54 void split_constants(const nir_alu_instr& instr, unsigned nsrc_comp);
55
56 bool emit_mov(const nir_alu_instr& instr);
57 bool emit_alu_op1(const nir_alu_instr& instr, EAluOp opcode, const AluOpFlags &flags = 0);
58 bool emit_alu_op2(const nir_alu_instr& instr, EAluOp opcode, AluOp2Opts ops = op2_opt_none);
59
60 bool emit_alu_trans_op2(const nir_alu_instr& instr, EAluOp opcode);
61 bool emit_alu_cm_trig(const nir_alu_instr& instr, EAluOp opcode);
62
63 bool emit_alu_inot(const nir_alu_instr& instr);
64 bool emit_alu_ineg(const nir_alu_instr& instr);
65 bool emit_alu_op2_int(const nir_alu_instr& instr, EAluOp opcode, AluOp2Opts ops = op2_opt_none);
66
67 bool emit_alu_op3(const nir_alu_instr& instr, EAluOp opcode, std::array<uint8_t, 3> reorder={0,1,2});
68 bool emit_alu_trans_op1(const nir_alu_instr& instr, EAluOp opcode, bool absolute = false);
69
70 bool emit_alu_b2f(const nir_alu_instr& instr);
71 bool emit_alu_i2orf2_b1(const nir_alu_instr& instr, EAluOp op);
72 bool emit_dot(const nir_alu_instr& instr, int n);
73 bool emit_create_vec(const nir_alu_instr& instr, unsigned nc);
74 bool emit_any_all_icomp(const nir_alu_instr& instr, EAluOp op, unsigned nc, bool all);
75 bool emit_any_iequal(const nir_alu_instr& instr, unsigned nc);
76
77 bool emit_any_all_fcomp(const nir_alu_instr& instr, EAluOp op, unsigned nc, bool all);
78 bool emit_any_all_fcomp2(const nir_alu_instr& instr, EAluOp op, bool all);
79
80 bool emit_fdph(const nir_alu_instr &instr);
81 bool emit_discard_if(const nir_intrinsic_instr *instr);
82
83 bool emit_alu_f2b32(const nir_alu_instr& instr);
84 bool emit_b2i32(const nir_alu_instr& instr);
85 bool emit_alu_f2i32_or_u32(const nir_alu_instr& instr, EAluOp op);
86 bool emit_pack_64_2x32_split(const nir_alu_instr& instr);
87 bool emit_unpack_64_2x32_split(const nir_alu_instr& instr, unsigned comp);
88
89 bool emit_tex_fdd(const nir_alu_instr& instr, TexInstruction::Opcode op, bool fine);
90 bool emit_unpack_32_2x16_split_y(const nir_alu_instr& instr);
91 bool emit_unpack_32_2x16_split_x(const nir_alu_instr& instr);
92 bool emit_pack_32_2x16_split(const nir_alu_instr& instr);
93
94 bool emit_cube(const nir_alu_instr& instr);
95 private:
96 void make_last(AluInstruction *ir) const;
97 void split_alu_modifiers(const nir_alu_src &src, const GPRVector::Values& v,
98 GPRVector::Values& out, int ncomp);
99
100 void preload_src(const nir_alu_instr& instr);
101 unsigned num_src_comp(const nir_alu_instr& instr);
102
103 using vreg = std::array<PValue, 4>;
104
105 std::array<PValue, 4> m_src[4];
106 };
107
make_last(AluInstruction * ir)108 inline void EmitAluInstruction::make_last(AluInstruction *ir) const
109 {
110 if (ir)
111 ir->set_flag(alu_last_instr);
112 }
113
114 }
115
116 #endif // SFN_EMITALUINSTRUCTION_H
117