2 * Copyright © 2014 Intel Corporation
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:
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
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
24 * Connor Abbott (cwabbott0@gmail.com)
29 * This header file defines all the available opcodes in one place. It expands
30 * to a list of macros of the form:
32 * OPCODE(name, num_inputs, per_component, output_size, output_type,
33 * input_sizes, input_types)
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.
41 #define ARR(...) { __VA_ARGS__ }
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), \
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)
56 * These two move instructions differ in what modifiers they support and what
57 * the negate modifier means. Otherwise, they are identical.
59 UNOP(fmov
, nir_type_float
)
60 UNOP(imov
, nir_type_int
)
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. */
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 */
88 * \name Unary floating-point rounding operations.
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
)
99 * \name Trigonometric operations.
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
)
109 * \name Partial derivatives.
112 UNOP(fddx
, nir_type_float
)
113 UNOP(fddy
, nir_type_float
)
117 * \name Floating point pack and unpack operations.
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
)
133 * \name Lowered floating point unpacking operations.
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
)
141 * \name Bit operations, part of ARB_gpu_shader5.
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
)
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
)
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) \
181 BINOP(fadd, nir_type_float)
182 BINOP(iadd
, nir_type_int
)
183 BINOP(fsub
, nir_type_float
)
184 BINOP(isub
, nir_type_int
)
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 */
191 BINOP(fdiv
, nir_type_float
)
192 BINOP(idiv
, nir_type_int
)
193 BINOP(udiv
, nir_type_unsigned
)
196 * returns a boolean representing the carry resulting from the addition of
197 * the two unsigned arguments.
199 BINOP_CONVERT(uadd_carry
, nir_type_bool
, nir_type_unsigned
)
202 * returns a boolean representing the borrow resulting from the subtraction
203 * of the two unsigned arguments.
205 BINOP_CONVERT(usub_borrow
, nir_type_bool
, nir_type_unsigned
)
207 BINOP(fmod
, nir_type_float
)
208 BINOP(umod
, nir_type_unsigned
)
216 * these integer-aware comparisons return a boolean (0 or ~0)
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
)
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
)
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
)
240 * These comparisons for integer-less hardware return 1.0 and 0.0 for true
241 * and false respectively
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 */
250 BINOP(ishl
, nir_type_int
)
251 BINOP(ishr
, nir_type_int
)
252 BINOP(ushr
, nir_type_unsigned
)
255 * \name bitwise logic operators
257 * These are also used as boolean and, or, xor for hardware supporting
261 BINOP(iand
, nir_type_unsigned
)
262 BINOP(ior
, nir_type_unsigned
)
263 BINOP(ixor
, nir_type_unsigned
)
267 * \name floating point logic operators
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
272 BINOP(fand
, nir_type_float
)
273 BINOP(for, nir_type_float
)
274 BINOP(fxor
, nir_type_float
)
276 BINOP_REDUCE(fdot
, 1, nir_type_float
, nir_type_float
)
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
)
285 BINOP(fpow
, nir_type_float
)
287 BINOP_HORIZ(pack_half_2x16_split
, 1, nir_type_unsigned
, 1, nir_type_float
, 1, nir_type_float
)
289 BINOP(bfm
, nir_type_unsigned
)
291 BINOP(ldexp
, nir_type_unsigned
)
294 * Combines the first component of each input to make a 2-component vector.
296 BINOP_HORIZ(vec2
, 2, nir_type_unsigned
, 1, nir_type_unsigned
, 1, nir_type_unsigned
)
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))
305 TRIOP(ffma
, nir_type_float
)
307 TRIOP(flrp
, nir_type_float
)
310 * \name Conditional Select
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).
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
))
322 TRIOP(bfi
, nir_type_unsigned
)
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
))
329 * Combines the first component of each input to make a 3-component vector.
331 TRIOP_HORIZ(vec3
, 3, 1, 1, 1)
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, \
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))
342 QUADOP(bitfield_insert
)
344 QUADOP_HORIZ(vec4
, 4, 1, 1, 1, 1)