3 # Copyright (C) 2015 Intel Corporation
5 # Permission is hereby granted, free of charge, to any person obtaining a
6 # copy of this software and associated documentation files (the "Software"),
7 # to deal in the Software without restriction, including without limitation
8 # the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 # and/or sell copies of the Software, and to permit persons to whom the
10 # Software is furnished to do so, subject to the following conditions:
12 # The above copyright notice and this permission notice (including the next
13 # paragraph) shall be included in all copies or substantial portions of the
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
27 ir_expression_operation
= [
28 # Name operands string comment
29 ("bit_not", 1, "~", None),
30 ("logic_not", 1, "!", None),
31 ("neg", 1, None, None),
32 ("abs", 1, None, None),
33 ("sign", 1, None, None),
34 ("rcp", 1, None, None),
35 ("rsq", 1, None, None),
36 ("sqrt", 1, None, None),
37 ("exp", 1, None, "Log base e on gentype"),
38 ("log", 1, None, "Natural log on gentype"),
39 ("exp2", 1, None, None),
40 ("log2", 1, None, None),
41 ("f2i", 1, None, "Float-to-integer conversion."),
42 ("f2u", 1, None, "Float-to-unsigned conversion."),
43 ("i2f", 1, None, "Integer-to-float conversion."),
44 ("f2b", 1, None, "Float-to-boolean conversion"),
45 ("b2f", 1, None, "Boolean-to-float conversion"),
46 ("i2b", 1, None, "int-to-boolean conversion"),
47 ("b2i", 1, None, "Boolean-to-int conversion"),
48 ("u2f", 1, None, "Unsigned-to-float conversion."),
49 ("i2u", 1, None, "Integer-to-unsigned conversion."),
50 ("u2i", 1, None, "Unsigned-to-integer conversion."),
51 ("d2f", 1, None, "Double-to-float conversion."),
52 ("f2d", 1, None, "Float-to-double conversion."),
53 ("d2i", 1, None, "Double-to-integer conversion."),
54 ("i2d", 1, None, "Integer-to-double conversion."),
55 ("d2u", 1, None, "Double-to-unsigned conversion."),
56 ("u2d", 1, None, "Unsigned-to-double conversion."),
57 ("d2b", 1, None, "Double-to-boolean conversion."),
58 ("bitcast_i2f", 1, None, 'Bit-identical int-to-float "conversion"'),
59 ("bitcast_f2i", 1, None, 'Bit-identical float-to-int "conversion"'),
60 ("bitcast_u2f", 1, None, 'Bit-identical uint-to-float "conversion"'),
61 ("bitcast_f2u", 1, None, 'Bit-identical float-to-uint "conversion"'),
64 * \\name Unary floating-point rounding operations.
67 ("trunc", 1, None, None),
68 ("ceil", 1, None, None),
69 ("floor", 1, None, None),
70 ("fract", 1, None, None),
71 ("round_even", 1, None, None),
75 * \\name Trigonometric operations.
78 ("sin", 1, None, None),
79 ("cos", 1, None, None),
83 * \\name Partial derivatives.
86 ("dFdx", 1, None, None),
87 ("dFdx_coarse", 1, "dFdxCoarse", None),
88 ("dFdx_fine", 1, "dFdxFine", None),
89 ("dFdy", 1, None, None),
90 ("dFdy_coarse", 1, "dFdyCoarse", None),
91 ("dFdy_fine", 1, "dFdyFine", None),
95 * \\name Floating point pack and unpack operations.
98 ("pack_snorm_2x16", 1, "packSnorm2x16", None),
99 ("pack_snorm_4x8", 1, "packSnorm4x8", None),
100 ("pack_unorm_2x16", 1, "packUnorm2x16", None),
101 ("pack_unorm_4x8", 1, "packUnorm4x8", None),
102 ("pack_half_2x16", 1, "packHalf2x16", None),
103 ("unpack_snorm_2x16", 1, "unpackSnorm2x16", None),
104 ("unpack_snorm_4x8", 1, "unpackSnorm4x8", None),
105 ("unpack_unorm_2x16", 1, "unpackUnorm2x16", None),
106 ("unpack_unorm_4x8", 1, "unpackUnorm4x8", None),
107 ("unpack_half_2x16", 1, "unpackHalf2x16", None),
111 * \\name Bit operations, part of ARB_gpu_shader5.
114 ("bitfield_reverse", 1, None, None),
115 ("bit_count", 1, None, None),
116 ("find_msb", 1, None, None),
117 ("find_lsb", 1, None, None),
120 ("saturate", 1, "sat", None),
123 * \\name Double packing, part of ARB_gpu_shader_fp64.
126 ("pack_double_2x32", 1, "packDouble2x32", None),
127 ("unpack_double_2x32", 1, "unpackDouble2x32", None),
130 ("frexp_sig", 1, None, None),
131 ("frexp_exp", 1, None, None),
133 ("noise", 1, None, None),
135 ("subroutine_to_int", 1, None, None),
137 * Interpolate fs input at centroid
139 * operand0 is the fs input.
141 ("interpolate_at_centroid", 1, None, None),
144 * Ask the driver for the total size of a buffer block.
146 * operand0 is the ir_constant buffer block index in the linked shader.
148 ("get_buffer_size", 1, None, None),
151 * Calculate length of an unsized array inside a buffer block.
152 * This opcode is going to be replaced in a lowering pass inside
155 * operand0 is the unsized array's ir_value for the calculation
158 ("ssbo_unsized_array_length", 1, None, None),
161 * Vote among threads on the value of the boolean argument.
163 ("vote_any", 1, None, None),
164 ("vote_all", 1, None, None),
165 ("vote_eq", 1, None, None),
167 ("add", 2, "+", None),
168 ("sub", 2, "-", None),
169 ("mul", 2, "*", "Floating-point or low 32-bit integer multiply."),
170 ("imul_high", 2, None, "Calculates the high 32-bits of a 64-bit multiply."),
171 ("div", 2, "/", None),
174 * Returns the carry resulting from the addition of the two arguments.
177 ("carry", 2, None, None),
181 * Returns the borrow resulting from the subtraction of the second argument
182 * from the first argument.
185 ("borrow", 2, None, None),
189 * Takes one of two combinations of arguments:
194 * Does not take integer types.
196 ("mod", 2, "%", None),
199 * \\name Binary comparison operators which return a boolean vector.
200 * The type of both operands must be equal.
203 ("less", 2, "<", None),
204 ("greater", 2, ">", None),
205 ("lequal", 2, "<=", None),
206 ("gequal", 2, ">=", None),
207 ("equal", 2, "==", None),
208 ("nequal", 2, "!=", None),
210 * Returns single boolean for whether all components of operands[0]
211 * equal the components of operands[1].
213 ("all_equal", 2, None, None),
215 * Returns single boolean for whether any component of operands[0]
216 * is not equal to the corresponding component of operands[1].
218 ("any_nequal", 2, None, None),
222 * \\name Bit-wise binary operations.
225 ("lshift", 2, "<<", None),
226 ("rshift", 2, ">>", None),
227 ("bit_and", 2, "&", None),
228 ("bit_xor", 2, "^", None),
229 ("bit_or", 2, "|", None),
232 ("logic_and", 2, "&&", None),
233 ("logic_xor", 2, "^^", None),
234 ("logic_or", 2, "||", None),
236 ("dot", 2, None, None),
237 ("min", 2, None, None),
238 ("max", 2, None, None),
240 ("pow", 2, None, None),
243 * Load a value the size of a given GLSL type from a uniform block.
245 * operand0 is the ir_constant uniform block index in the linked shader.
246 * operand1 is a byte offset within the uniform block.
248 ("ubo_load", 2, None, None),
251 * \\name Multiplies a number by two to a power, part of ARB_gpu_shader5.
254 ("ldexp", 2, None, None),
258 * Extract a scalar from a vector
260 * operand0 is the vector
261 * operand1 is the index of the field to read from operand0
263 ("vector_extract", 2, None, None),
266 * Interpolate fs input at offset
268 * operand0 is the fs input
269 * operand1 is the offset from the pixel center
271 ("interpolate_at_offset", 2, None, None),
274 * Interpolate fs input at sample position
276 * operand0 is the fs input
277 * operand1 is the sample ID
279 ("interpolate_at_sample", 2, None, None),
282 * \\name Fused floating-point multiply-add, part of ARB_gpu_shader5.
285 ("fma", 3, None, None),
288 ("lrp", 3, None, None),
291 * \\name Conditional Select
293 * A vector conditional select instruction (like ?:, but operating per-
294 * component on vectors).
296 * \\see lower_instructions_visitor::ldexp_to_arith
299 ("csel", 3, None, None),
302 ("bitfield_extract", 3, None, None),
305 * Generate a value with one field of a vector changed
307 * operand0 is the vector
308 * operand1 is the value to write into the vector result
309 * operand2 is the index in operand0 to be modified
311 ("vector_insert", 3, None, None),
313 ("bitfield_insert", 4, None, None),
315 ("vector", 4, None, None),
318 def name_from_item(item
):
319 return "ir_{}op_{}".format(("un", "bin", "tri", "quad")[item
[1]-1], item
[0])
321 if __name__
== "__main__":
323 * Copyright (C) 2010 Intel Corporation
325 * Permission is hereby granted, free of charge, to any person obtaining a
326 * copy of this software and associated documentation files (the "Software"),
327 * to deal in the Software without restriction, including without limitation
328 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
329 * and/or sell copies of the Software, and to permit persons to whom the
330 * Software is furnished to do so, subject to the following conditions:
332 * The above copyright notice and this permission notice (including the next
333 * paragraph) shall be included in all copies or substantial portions of the
336 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
337 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
338 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
339 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
340 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
341 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
342 * DEALINGS IN THE SOFTWARE.
345 enum_template
= mako
.template
.Template(copyright
+ """
346 /* Update ir_expression::get_num_operands() and operator_strs when
347 * updating this list.
349 enum ir_expression_operation {
350 % for item in values:
351 % if isinstance(item, str):
354 ${name_from_item(item)},${"" if item[3] is None else " /**< {} */".format(item[3])}
359 * Sentinels marking the last of each kind of operation;
361 % for (name, i) in lasts:
362 ir_last_${("un", "bin", "tri", "quad")[i]}op = ${name_from_item((name, i+1))},
364 ir_last_opcode = ir_quadop_${lasts[3][0]}
367 strings_template
= mako
.template
.Template(copyright
+ """
368 static const char *const operator_strs[] = {
369 % for item in values:
370 % if not isinstance(item, str):
371 "${item[2] if item[2] is not None else item[0]}",
376 if sys
.argv
[1] == "enum":
377 lasts
= [None, None, None, None]
378 for item
in reversed(ir_expression_operation
):
379 if isinstance(item
, str):
384 lasts
[i
] = (item
[0], i
)
386 print(enum_template
.render(values
=ir_expression_operation
,
388 name_from_item
=name_from_item
))
389 elif sys
.argv
[1] == "strings":
390 print(strings_template
.render(values
=ir_expression_operation
,
391 name_from_item
=name_from_item
))