nir: Add a parallel copy instruction type
[mesa.git] / src / glsl / nir / nir_opcodes.h
1 /*
2 * Copyright © 2014 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 *
23 * Authors:
24 * Connor Abbott (cwabbott0@gmail.com)
25 *
26 */
27
28 /**
29 * This header file defines all the available opcodes in one place. It expands
30 * to a list of macros of the form:
31 *
32 * OPCODE(name, num_inputs, per_component, output_size, output_type,
33 * input_sizes, input_types)
34 *
35 * Which should correspond one-to-one with the nir_op_info structure. It is
36 * included in both ir.h to create the nir_op enum (with members of the form
37 * nir_op_(name)) and and in opcodes.c to create nir_op_infos, which is a
38 * const array of nir_op_info structures for each opcode.
39 */
40
41 #define ARR(...) { __VA_ARGS__ }
42
43 #define UNOP(name, type) OPCODE(name, 1, false, 0, type, ARR(0), ARR(type))
44 #define UNOP_CONVERT(name, in_type, out_type) \
45 OPCODE(name, 1, false, 0, out_type, ARR(0), ARR(in_type))
46 #define UNOP_HORIZ(name, output_size, output_type, input_size, input_type) \
47 OPCODE(name, 1, true, output_size, output_type, ARR(input_size), \
48 ARR(input_type))
49
50 #define UNOP_REDUCE(name, output_size, output_type, input_type) \
51 UNOP_HORIZ(name##2, output_size, output_type, 2, input_type) \
52 UNOP_HORIZ(name##3, output_size, output_type, 3, input_type) \
53 UNOP_HORIZ(name##4, output_size, output_type, 4, input_type)
54
55 /**
56 * These two move instructions differ in what modifiers they support and what
57 * the negate modifier means. Otherwise, they are identical.
58 */
59 UNOP(fmov, nir_type_float)
60 UNOP(imov, nir_type_int)
61
62 UNOP(inot, nir_type_int) /* invert every bit of the integer */
63 UNOP(fnot, nir_type_float) /* (src == 0.0) ? 1.0 : 0.0 */
64 UNOP(fsign, nir_type_float)
65 UNOP(isign, nir_type_int)
66 UNOP(frcp, nir_type_float)
67 UNOP(frsq, nir_type_float)
68 UNOP(fsqrt, nir_type_float)
69 UNOP(fexp, nir_type_float) /* < e^x */
70 UNOP(flog, nir_type_float) /* log base e */
71 UNOP(fexp2, nir_type_float)
72 UNOP(flog2, nir_type_float)
73 UNOP_CONVERT(f2i, nir_type_float, nir_type_int) /**< Float-to-integer conversion. */
74 UNOP_CONVERT(f2u, nir_type_float, nir_type_unsigned) /**< Float-to-unsigned conversion. */
75 UNOP_CONVERT(i2f, nir_type_int, nir_type_float) /**< Integer-to-float conversion. */
76 UNOP_CONVERT(f2b, nir_type_float, nir_type_bool) /**< Float-to-boolean conversion */
77 UNOP_CONVERT(b2f, nir_type_bool, nir_type_float) /**< Boolean-to-float conversion */
78 UNOP_CONVERT(i2b, nir_type_int, nir_type_bool) /**< int-to-boolean conversion */
79 UNOP_CONVERT(b2i, nir_type_bool, nir_type_int) /**< Boolean-to-int conversion */
80 UNOP_CONVERT(u2f, nir_type_unsigned, nir_type_float) /**< Unsigned-to-float conversion. */
81
82 UNOP_REDUCE(bany, 1, nir_type_bool, nir_type_bool) /* returns ~0 if any component of src[0] != 0 */
83 UNOP_REDUCE(ball, 1, nir_type_bool, nir_type_bool) /* returns ~0 if all components of src[0] != 0 */
84 UNOP_REDUCE(fany, 1, nir_type_float, nir_type_float) /* returns 1.0 if any component of src[0] != 0 */
85 UNOP_REDUCE(fall, 1, nir_type_float, nir_type_float) /* returns 1.0 if all components of src[0] != 0 */
86
87 /**
88 * \name Unary floating-point rounding operations.
89 */
90 /*@{*/
91 UNOP(ftrunc, nir_type_float)
92 UNOP(fceil, nir_type_float)
93 UNOP(ffloor, nir_type_float)
94 UNOP(ffract, nir_type_float)
95 UNOP(fround_even, nir_type_float)
96 /*@}*/
97
98 /**
99 * \name Trigonometric operations.
100 */
101 /*@{*/
102 UNOP(fsin, nir_type_float)
103 UNOP(fcos, nir_type_float)
104 UNOP(fsin_reduced, nir_type_float)
105 UNOP(fcos_reduced, nir_type_float)
106 /*@}*/
107
108 /**
109 * \name Partial derivatives.
110 */
111 /*@{*/
112 UNOP(fddx, nir_type_float)
113 UNOP(fddy, nir_type_float)
114 UNOP(fddx_fine, nir_type_float)
115 UNOP(fddy_fine, nir_type_float)
116 UNOP(fddx_coarse, nir_type_float)
117 UNOP(fddy_coarse, nir_type_float)
118 /*@}*/
119
120 /**
121 * \name Floating point pack and unpack operations.
122 */
123 /*@{*/
124 UNOP_HORIZ(pack_snorm_2x16, 1, nir_type_unsigned, 2, nir_type_float)
125 UNOP_HORIZ(pack_snorm_4x8, 1, nir_type_unsigned, 4, nir_type_float)
126 UNOP_HORIZ(pack_unorm_2x16, 1, nir_type_unsigned, 2, nir_type_float)
127 UNOP_HORIZ(pack_unorm_4x8, 1, nir_type_unsigned, 4, nir_type_float)
128 UNOP_HORIZ(pack_half_2x16, 1, nir_type_unsigned, 2, nir_type_float)
129 UNOP_HORIZ(unpack_snorm_2x16, 2, nir_type_float, 1, nir_type_unsigned)
130 UNOP_HORIZ(unpack_snorm_4x8, 4, nir_type_float, 1, nir_type_unsigned)
131 UNOP_HORIZ(unpack_unorm_2x16, 2, nir_type_float, 1, nir_type_unsigned)
132 UNOP_HORIZ(unpack_unorm_4x8, 4, nir_type_float, 1, nir_type_unsigned)
133 UNOP_HORIZ(unpack_half_2x16, 2, nir_type_float, 1, nir_type_unsigned)
134 /*@}*/
135
136 /**
137 * \name Lowered floating point unpacking operations.
138 */
139 /*@{*/
140 UNOP_HORIZ(unpack_half_2x16_split_x, 1, nir_type_float, 1, nir_type_unsigned)
141 UNOP_HORIZ(unpack_half_2x16_split_y, 1, nir_type_float, 1, nir_type_unsigned)
142 /*@}*/
143
144 /**
145 * \name Bit operations, part of ARB_gpu_shader5.
146 */
147 /*@{*/
148 UNOP(bitfield_reverse, nir_type_unsigned)
149 UNOP(bit_count, nir_type_unsigned)
150 UNOP(find_msb, nir_type_unsigned)
151 UNOP(find_lsb, nir_type_unsigned)
152 /*@}*/
153
154 UNOP_HORIZ(fnoise1_1, 1, nir_type_float, 1, nir_type_float)
155 UNOP_HORIZ(fnoise1_2, 1, nir_type_float, 2, nir_type_float)
156 UNOP_HORIZ(fnoise1_3, 1, nir_type_float, 3, nir_type_float)
157 UNOP_HORIZ(fnoise1_4, 1, nir_type_float, 4, nir_type_float)
158 UNOP_HORIZ(fnoise2_1, 2, nir_type_float, 1, nir_type_float)
159 UNOP_HORIZ(fnoise2_2, 2, nir_type_float, 2, nir_type_float)
160 UNOP_HORIZ(fnoise2_3, 2, nir_type_float, 3, nir_type_float)
161 UNOP_HORIZ(fnoise2_4, 2, nir_type_float, 4, nir_type_float)
162 UNOP_HORIZ(fnoise3_1, 3, nir_type_float, 1, nir_type_float)
163 UNOP_HORIZ(fnoise3_2, 3, nir_type_float, 2, nir_type_float)
164 UNOP_HORIZ(fnoise3_3, 3, nir_type_float, 3, nir_type_float)
165 UNOP_HORIZ(fnoise3_4, 3, nir_type_float, 4, nir_type_float)
166 UNOP_HORIZ(fnoise4_1, 4, nir_type_float, 1, nir_type_float)
167 UNOP_HORIZ(fnoise4_2, 4, nir_type_float, 2, nir_type_float)
168 UNOP_HORIZ(fnoise4_3, 4, nir_type_float, 3, nir_type_float)
169 UNOP_HORIZ(fnoise4_4, 4, nir_type_float, 4, nir_type_float)
170
171 #define BINOP(name, type) \
172 OPCODE(name, 2, true, 0, type, ARR(0, 0), ARR(type, type))
173 #define BINOP_CONVERT(name, out_type, in_type) \
174 OPCODE(name, 2, true, 0, out_type, ARR(0, 0), ARR(in_type, in_type))
175 #define BINOP_COMPARE(name, type) BINOP_CONVERT(name, nir_type_bool, type)
176 #define BINOP_HORIZ(name, output_size, output_type, src1_size, src1_type, \
177 src2_size, src2_type) \
178 OPCODE(name, 2, true, output_size, output_type, ARR(src1_size, src2_size), \
179 ARR(src1_type, src2_type))
180 #define BINOP_REDUCE(name, output_size, output_type, src_type) \
181 BINOP_HORIZ(name##2, output_size, output_type, 2, src_type, 2, src_type) \
182 BINOP_HORIZ(name##3, output_size, output_type, 3, src_type, 3, src_type) \
183 BINOP_HORIZ(name##4, output_size, output_type, 4, src_type, 4, src_type) \
184
185 BINOP(fadd, nir_type_float)
186 BINOP(iadd, nir_type_int)
187 BINOP(fsub, nir_type_float)
188 BINOP(isub, nir_type_int)
189
190 BINOP(fmul, nir_type_float)
191 BINOP(imul, nir_type_int) /* low 32-bits of signed/unsigned integer multiply */
192 BINOP(imul_high, nir_type_int) /* high 32-bits of signed integer multiply */
193 BINOP(umul_high, nir_type_unsigned) /* high 32-bits of unsigned integer multiply */
194
195 BINOP(fdiv, nir_type_float)
196 BINOP(idiv, nir_type_int)
197 BINOP(udiv, nir_type_unsigned)
198
199 /**
200 * returns a boolean representing the carry resulting from the addition of
201 * the two unsigned arguments.
202 */
203 BINOP_CONVERT(uadd_carry, nir_type_bool, nir_type_unsigned)
204
205 /**
206 * returns a boolean representing the borrow resulting from the subtraction
207 * of the two unsigned arguments.
208 */
209 BINOP_CONVERT(usub_borrow, nir_type_bool, nir_type_unsigned)
210
211 BINOP(fmod, nir_type_float)
212 BINOP(umod, nir_type_unsigned)
213
214 /**
215 * \name comparisons
216 */
217 /*@{*/
218
219 /**
220 * these integer-aware comparisons return a boolean (0 or ~0)
221 */
222 BINOP_COMPARE(flt, nir_type_float)
223 BINOP_COMPARE(fge, nir_type_float)
224 BINOP_COMPARE(feq, nir_type_float)
225 BINOP_COMPARE(fne, nir_type_float)
226 BINOP_COMPARE(ilt, nir_type_int)
227 BINOP_COMPARE(ige, nir_type_int)
228 BINOP_COMPARE(ieq, nir_type_int)
229 BINOP_COMPARE(ine, nir_type_int)
230 BINOP_COMPARE(ult, nir_type_unsigned)
231 BINOP_COMPARE(uge, nir_type_unsigned)
232
233 /** integer-aware GLSL-style comparisons that compare floats and ints */
234 BINOP_REDUCE(ball_fequal, 1, nir_type_bool, nir_type_float)
235 BINOP_REDUCE(bany_fnequal, 1, nir_type_bool, nir_type_float)
236 BINOP_REDUCE(ball_iequal, 1, nir_type_bool, nir_type_int)
237 BINOP_REDUCE(bany_inequal, 1, nir_type_bool, nir_type_int)
238
239 /** non-integer-aware GLSL-style comparisons that return 0.0 or 1.0 */
240 BINOP_REDUCE(fall_equal, 1, nir_type_float, nir_type_float)
241 BINOP_REDUCE(fany_nequal, 1, nir_type_float, nir_type_float)
242
243 /**
244 * These comparisons for integer-less hardware return 1.0 and 0.0 for true
245 * and false respectively
246 */
247 BINOP(slt, nir_type_float) /* Set on Less Than */
248 BINOP(sge, nir_type_float) /* Set on Greater Than or Equal */
249 BINOP(seq, nir_type_float) /* Set on Equal */
250 BINOP(sne, nir_type_float) /* Set on Not Equal */
251
252 /*@}*/
253
254 BINOP(ishl, nir_type_int)
255 BINOP(ishr, nir_type_int)
256 BINOP(ushr, nir_type_unsigned)
257
258 /**
259 * \name bitwise logic operators
260 *
261 * These are also used as boolean and, or, xor for hardware supporting
262 * integers.
263 */
264 /*@{*/
265 BINOP(iand, nir_type_unsigned)
266 BINOP(ior, nir_type_unsigned)
267 BINOP(ixor, nir_type_unsigned)
268 /*@{*/
269
270 /**
271 * \name floating point logic operators
272 *
273 * These use (src != 0.0) for testing the truth of the input, and output 1.0
274 * for true and 0.0 for false
275 */
276 BINOP(fand, nir_type_float)
277 BINOP(for, nir_type_float)
278 BINOP(fxor, nir_type_float)
279
280 BINOP_REDUCE(fdot, 1, nir_type_float, nir_type_float)
281
282 BINOP(fmin, nir_type_float)
283 BINOP(imin, nir_type_int)
284 BINOP(umin, nir_type_unsigned)
285 BINOP(fmax, nir_type_float)
286 BINOP(imax, nir_type_int)
287 BINOP(umax, nir_type_unsigned)
288
289 BINOP(fpow, nir_type_float)
290
291 BINOP_HORIZ(pack_half_2x16_split, 1, nir_type_unsigned, 1, nir_type_float, 1, nir_type_float)
292
293 BINOP(bfm, nir_type_unsigned)
294
295 BINOP(ldexp, nir_type_unsigned)
296
297 /**
298 * Combines the first component of each input to make a 2-component vector.
299 */
300 BINOP_HORIZ(vec2, 2, nir_type_unsigned, 1, nir_type_unsigned, 1, nir_type_unsigned)
301
302 #define TRIOP(name, type) \
303 OPCODE(name, 3, true, 0, type, ARR(0, 0, 0), ARR(type, type, type))
304 #define TRIOP_HORIZ(name, output_size, src1_size, src2_size, src3_size) \
305 OPCODE(name, 3, false, output_size, nir_type_unsigned, \
306 ARR(src1_size, src2_size, src3_size), \
307 ARR(nir_type_unsigned, nir_type_unsigned, nir_type_unsigned))
308
309 TRIOP(ffma, nir_type_float)
310
311 TRIOP(flrp, nir_type_float)
312
313 /**
314 * \name Conditional Select
315 *
316 * A vector conditional select instruction (like ?:, but operating per-
317 * component on vectors). There are two versions, one for floating point
318 * bools (0.0 vs 1.0) and one for integer bools (0 vs ~0).
319 */
320
321 OPCODE(fcsel, 3, true, 0, nir_type_float, ARR(1, 0, 0),
322 ARR(nir_type_float, nir_type_float, nir_type_float))
323 OPCODE(bcsel, 3, true, 0, nir_type_unsigned, ARR(1, 0, 0),
324 ARR(nir_type_bool, nir_type_unsigned, nir_type_unsigned))
325
326 TRIOP(bfi, nir_type_unsigned)
327
328 TRIOP(ubitfield_extract, nir_type_unsigned)
329 OPCODE(ibitfield_extract, 3, true, 0, nir_type_int, ARR(0, 0, 0),
330 ARR(nir_type_int, nir_type_unsigned, nir_type_unsigned))
331
332 /**
333 * Combines the first component of each input to make a 3-component vector.
334 */
335 TRIOP_HORIZ(vec3, 3, 1, 1, 1)
336
337 #define QUADOP(name) \
338 OPCODE(name, 4, true, 0, nir_type_unsigned, ARR(0, 0, 0, 0), \
339 ARR(nir_type_unsigned, nir_type_unsigned, nir_type_unsigned, nir_type_unsigned))
340 #define QUADOP_HORIZ(name, output_size, src1_size, src2_size, src3_size, \
341 src4_size) \
342 OPCODE(name, 4, false, output_size, nir_type_unsigned, \
343 ARR(src1_size, src2_size, src3_size, src4_size), \
344 ARR(nir_type_unsigned, nir_type_unsigned, nir_type_unsigned, nir_type_unsigned))
345
346 QUADOP(bitfield_insert)
347
348 QUADOP_HORIZ(vec4, 4, 1, 1, 1, 1)
349
350 LAST_OPCODE(vec4)