Fix what I think are a few NIR typos
[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 /*@}*/
115
116 /**
117 * \name Floating point pack and unpack operations.
118 */
119 /*@{*/
120 UNOP_HORIZ(pack_snorm_2x16, 1, nir_type_unsigned, 2, nir_type_float)
121 UNOP_HORIZ(pack_snorm_4x8, 1, nir_type_unsigned, 4, nir_type_float)
122 UNOP_HORIZ(pack_unorm_2x16, 1, nir_type_unsigned, 2, nir_type_float)
123 UNOP_HORIZ(pack_unorm_4x8, 1, nir_type_unsigned, 4, nir_type_float)
124 UNOP_HORIZ(pack_half_2x16, 1, nir_type_unsigned, 2, nir_type_float)
125 UNOP_HORIZ(unpack_snorm_2x16, 2, nir_type_float, 1, nir_type_unsigned)
126 UNOP_HORIZ(unpack_snorm_4x8, 4, nir_type_float, 1, nir_type_unsigned)
127 UNOP_HORIZ(unpack_unorm_2x16, 2, nir_type_float, 1, nir_type_unsigned)
128 UNOP_HORIZ(unpack_unorm_4x8, 4, nir_type_float, 1, nir_type_unsigned)
129 UNOP_HORIZ(unpack_half_2x16, 2, nir_type_float, 1, nir_type_unsigned)
130 /*@}*/
131
132 /**
133 * \name Lowered floating point unpacking operations.
134 */
135 /*@{*/
136 UNOP_HORIZ(unpack_half_2x16_split_x, 1, nir_type_float, 1, nir_type_unsigned)
137 UNOP_HORIZ(unpack_half_2x16_split_y, 1, nir_type_float, 1, nir_type_unsigned)
138 /*@}*/
139
140 /**
141 * \name Bit operations, part of ARB_gpu_shader5.
142 */
143 /*@{*/
144 UNOP(bitfield_reverse, nir_type_unsigned)
145 UNOP(bit_count, nir_type_unsigned)
146 UNOP(find_msb, nir_type_unsigned)
147 UNOP(find_lsb, nir_type_unsigned)
148 /*@}*/
149
150 UNOP_HORIZ(fnoise1_1, 1, nir_type_float, 1, nir_type_float)
151 UNOP_HORIZ(fnoise1_2, 1, nir_type_float, 2, nir_type_float)
152 UNOP_HORIZ(fnoise1_3, 1, nir_type_float, 3, nir_type_float)
153 UNOP_HORIZ(fnoise1_4, 1, nir_type_float, 4, nir_type_float)
154 UNOP_HORIZ(fnoise2_1, 2, nir_type_float, 1, nir_type_float)
155 UNOP_HORIZ(fnoise2_2, 2, nir_type_float, 2, nir_type_float)
156 UNOP_HORIZ(fnoise2_3, 2, nir_type_float, 3, nir_type_float)
157 UNOP_HORIZ(fnoise2_4, 2, nir_type_float, 4, nir_type_float)
158 UNOP_HORIZ(fnoise3_1, 3, nir_type_float, 1, nir_type_float)
159 UNOP_HORIZ(fnoise3_2, 3, nir_type_float, 2, nir_type_float)
160 UNOP_HORIZ(fnoise3_3, 3, nir_type_float, 3, nir_type_float)
161 UNOP_HORIZ(fnoise3_4, 3, nir_type_float, 4, nir_type_float)
162 UNOP_HORIZ(fnoise4_1, 4, nir_type_float, 1, nir_type_float)
163 UNOP_HORIZ(fnoise4_2, 4, nir_type_float, 2, nir_type_float)
164 UNOP_HORIZ(fnoise4_3, 4, nir_type_float, 3, nir_type_float)
165 UNOP_HORIZ(fnoise4_4, 4, nir_type_float, 4, nir_type_float)
166
167 #define BINOP(name, type) \
168 OPCODE(name, 2, true, 0, type, ARR(0, 0), ARR(type, type))
169 #define BINOP_CONVERT(name, out_type, in_type) \
170 OPCODE(name, 2, true, 0, out_type, ARR(0, 0), ARR(in_type, in_type))
171 #define BINOP_COMPARE(name, type) BINOP_CONVERT(name, nir_type_bool, type)
172 #define BINOP_HORIZ(name, output_size, output_type, src1_size, src1_type, \
173 src2_size, src2_type) \
174 OPCODE(name, 2, true, output_size, output_type, ARR(src1_size, src2_size), \
175 ARR(src1_type, src2_type))
176 #define BINOP_REDUCE(name, output_size, output_type, src_type) \
177 BINOP_HORIZ(name##2, output_size, output_type, 2, src_type, 2, src_type) \
178 BINOP_HORIZ(name##3, output_size, output_type, 3, src_type, 3, src_type) \
179 BINOP_HORIZ(name##4, output_size, output_type, 4, src_type, 4, src_type) \
180
181 BINOP(fadd, nir_type_float)
182 BINOP(iadd, nir_type_int)
183 BINOP(fsub, nir_type_float)
184 BINOP(isub, nir_type_int)
185
186 BINOP(fmul, nir_type_float)
187 BINOP(imul, nir_type_int) /* low 32-bits of signed/unsigned integer multiply */
188 BINOP(imul_high, nir_type_int) /* high 32-bits of signed integer multiply */
189 BINOP(umul_high, nir_type_unsigned) /* high 32-bits of unsigned integer multiply */
190
191 BINOP(fdiv, nir_type_float)
192 BINOP(idiv, nir_type_int)
193 BINOP(udiv, nir_type_unsigned)
194
195 /**
196 * returns a boolean representing the carry resulting from the addition of
197 * the two unsigned arguments.
198 */
199 BINOP_CONVERT(uadd_carry, nir_type_bool, nir_type_unsigned)
200
201 /**
202 * returns a boolean representing the borrow resulting from the subtraction
203 * of the two unsigned arguments.
204 */
205 BINOP_CONVERT(usub_borrow, nir_type_bool, nir_type_unsigned)
206
207 BINOP(fmod, nir_type_float)
208 BINOP(umod, nir_type_unsigned)
209
210 /**
211 * \name comparisons
212 */
213 /*@{*/
214
215 /**
216 * these integer-aware comparisons return a boolean (0 or ~0)
217 */
218 BINOP_COMPARE(flt, nir_type_float)
219 BINOP_COMPARE(fge, nir_type_float)
220 BINOP_COMPARE(feq, nir_type_float)
221 BINOP_COMPARE(fne, nir_type_float)
222 BINOP_COMPARE(ilt, nir_type_int)
223 BINOP_COMPARE(ige, nir_type_int)
224 BINOP_COMPARE(ieq, nir_type_int)
225 BINOP_COMPARE(ine, nir_type_int)
226 BINOP_COMPARE(ult, nir_type_unsigned)
227 BINOP_COMPARE(uge, nir_type_unsigned)
228
229 /** integer-aware GLSL-style comparisons that compare floats and ints */
230 BINOP_REDUCE(ball_fequal, 1, nir_type_bool, nir_type_float)
231 BINOP_REDUCE(bany_fnequal, 1, nir_type_bool, nir_type_float)
232 BINOP_REDUCE(ball_iequal, 1, nir_type_bool, nir_type_int)
233 BINOP_REDUCE(bany_inequal, 1, nir_type_bool, nir_type_int)
234
235 /** non-integer-aware GLSL-style comparisons that return 0.0 or 1.0 */
236 BINOP_REDUCE(fall_equal, 1, nir_type_float, nir_type_float)
237 BINOP_REDUCE(fany_nequal, 1, nir_type_float, nir_type_float)
238
239 /**
240 * These comparisons for integer-less hardware return 1.0 and 0.0 for true
241 * and false respectively
242 */
243 BINOP(slt, nir_type_float) /* Set on Less Than */
244 BINOP(sge, nir_type_float) /* Set on Greater Than or Equal */
245 BINOP(seq, nir_type_float) /* Set on Equal */
246 BINOP(sne, nir_type_float) /* Set on Not Equal */
247
248 /*@}*/
249
250 BINOP(ishl, nir_type_int)
251 BINOP(ishr, nir_type_int)
252 BINOP(ushr, nir_type_unsigned)
253
254 /**
255 * \name bitwise logic operators
256 *
257 * These are also used as boolean and, or, xor for hardware supporting
258 * integers.
259 */
260 /*@{*/
261 BINOP(iand, nir_type_unsigned)
262 BINOP(ior, nir_type_unsigned)
263 BINOP(ixor, nir_type_unsigned)
264 /*@{*/
265
266 /**
267 * \name floating point logic operators
268 *
269 * These use (src != 0.0) for testing the truth of the input, and output 1.0
270 * for true and 0.0 for false
271 */
272 BINOP(fand, nir_type_float)
273 BINOP(for, nir_type_float)
274 BINOP(fxor, nir_type_float)
275
276 BINOP_REDUCE(fdot, 1, nir_type_float, nir_type_float)
277
278 BINOP(fmin, nir_type_float)
279 BINOP(imin, nir_type_int)
280 BINOP(umin, nir_type_unsigned)
281 BINOP(fmax, nir_type_float)
282 BINOP(imax, nir_type_int)
283 BINOP(umax, nir_type_unsigned)
284
285 BINOP(fpow, nir_type_float)
286
287 BINOP_HORIZ(pack_half_2x16_split, 1, nir_type_unsigned, 1, nir_type_float, 1, nir_type_float)
288
289 BINOP(bfm, nir_type_unsigned)
290
291 BINOP(ldexp, nir_type_unsigned)
292
293 /**
294 * Combines the first component of each input to make a 2-component vector.
295 */
296 BINOP_HORIZ(vec2, 2, nir_type_unsigned, 1, nir_type_unsigned, 1, nir_type_unsigned)
297
298 #define TRIOP(name, type) \
299 OPCODE(name, 3, true, 0, type, ARR(0, 0, 0), ARR(type, type, type))
300 #define TRIOP_HORIZ(name, output_size, src1_size, src2_size, src3_size) \
301 OPCODE(name, 3, false, output_size, nir_type_unsigned, \
302 ARR(src1_size, src2_size, src3_size), \
303 ARR(nir_type_unsigned, nir_type_unsigned, nir_type_unsigned))
304
305 TRIOP(ffma, nir_type_float)
306
307 TRIOP(flrp, nir_type_float)
308
309 /**
310 * \name Conditional Select
311 *
312 * A vector conditional select instruction (like ?:, but operating per-
313 * component on vectors). There are two versions, one for floating point
314 * bools (0.0 vs 1.0) and one for integer bools (0 vs ~0).
315 */
316
317 OPCODE(fcsel, 3, true, 0, nir_type_float, ARR(1, 0, 0),
318 ARR(nir_type_float, nir_type_float, nir_type_float))
319 OPCODE(bcsel, 3, true, 0, nir_type_unsigned, ARR(1, 0, 0),
320 ARR(nir_type_bool, nir_type_unsigned, nir_type_unsigned))
321
322 TRIOP(bfi, nir_type_unsigned)
323
324 TRIOP(ubitfield_extract, nir_type_unsigned)
325 OPCODE(ibitfield_extract, 3, true, 0, nir_type_int, ARR(0, 0, 0),
326 ARR(nir_type_int, nir_type_unsigned, nir_type_unsigned))
327
328 /**
329 * Combines the first component of each input to make a 3-component vector.
330 */
331 TRIOP_HORIZ(vec3, 3, 1, 1, 1)
332
333 #define QUADOP(name) \
334 OPCODE(name, 4, true, 0, nir_type_unsigned, ARR(0, 0, 0, 0), \
335 ARR(nir_type_unsigned, nir_type_unsigned, nir_type_unsigned, nir_type_unsigned))
336 #define QUADOP_HORIZ(name, output_size, src1_size, src2_size, src3_size, \
337 src4_size) \
338 OPCODE(name, 4, false, output_size, nir_type_unsigned, \
339 ARR(src1_size, src2_size, src3_size, src4_size), \
340 ARR(nir_type_unsigned, nir_type_unsigned, nir_type_unsigned, nir_type_unsigned))
341
342 QUADOP(bitfield_insert)
343
344 QUADOP_HORIZ(vec4, 4, 1, 1, 1, 1)
345
346 LAST_OPCODE(vec4)