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
30 ("logic_not", 1, "!"),
37 ("exp", 1, None), # Log base e on gentype
38 ("log", 1, None), # Natural log on gentype
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"
63 # Unary floating-point rounding operations.
68 ("round_even", 1, None),
70 # Trigonometric operations.
74 # Partial derivatives.
76 ("dFdx_coarse", 1, "dFdxCoarse"),
77 ("dFdx_fine", 1, "dFdxFine"),
79 ("dFdy_coarse", 1, "dFdyCoarse"),
80 ("dFdy_fine", 1, "dFdyFine"),
82 # Floating point pack and unpack operations.
83 ("pack_snorm_2x16", 1, "packSnorm2x16"),
84 ("pack_snorm_4x8", 1, "packSnorm4x8"),
85 ("pack_unorm_2x16", 1, "packUnorm2x16"),
86 ("pack_unorm_4x8", 1, "packUnorm4x8"),
87 ("pack_half_2x16", 1, "packHalf2x16"),
88 ("unpack_snorm_2x16", 1, "unpackSnorm2x16"),
89 ("unpack_snorm_4x8", 1, "unpackSnorm4x8"),
90 ("unpack_unorm_2x16", 1, "unpackUnorm2x16"),
91 ("unpack_unorm_4x8", 1, "unpackUnorm4x8"),
92 ("unpack_half_2x16", 1, "unpackHalf2x16"),
94 # Bit operations, part of ARB_gpu_shader5.
95 ("bitfield_reverse", 1, None),
96 ("bit_count", 1, None),
97 ("find_msb", 1, None),
98 ("find_lsb", 1, None),
100 ("saturate", 1, "sat"),
102 # Double packing, part of ARB_gpu_shader_fp64.
103 ("pack_double_2x32", 1, "packDouble2x32"),
104 ("unpack_double_2x32", 1, "unpackDouble2x32"),
106 ("frexp_sig", 1, None),
107 ("frexp_exp", 1, None),
111 ("subroutine_to_int", 1, None),
113 # Interpolate fs input at centroid
115 # operand0 is the fs input.
116 ("interpolate_at_centroid", 1, None),
118 # Ask the driver for the total size of a buffer block.
119 # operand0 is the ir_constant buffer block index in the linked shader.
120 ("get_buffer_size", 1, None),
122 # Calculate length of an unsized array inside a buffer block.
123 # This opcode is going to be replaced in a lowering pass inside
126 # operand0 is the unsized array's ir_value for the calculation
128 ("ssbo_unsized_array_length", 1, None),
130 # Vote among threads on the value of the boolean argument.
131 ("vote_any", 1, None),
132 ("vote_all", 1, None),
133 ("vote_eq", 1, None),
137 ("mul", 2, "*"), # "Floating-point or low 32-bit integer multiply."
138 ("imul_high", 2, None), # Calculates the high 32-bits of a 64-bit multiply.
141 # Returns the carry resulting from the addition of the two arguments.
144 # Returns the borrow resulting from the subtraction of the second argument
145 # from the first argument.
148 # Either (vector % vector) or (vector % scalar)
151 # Binary comparison operators which return a boolean vector.
152 # The type of both operands must be equal.
160 # Returns single boolean for whether all components of operands[0]
161 # equal the components of operands[1].
162 ("all_equal", 2, None),
164 # Returns single boolean for whether any component of operands[0]
165 # is not equal to the corresponding component of operands[1].
166 ("any_nequal", 2, None),
168 # Bit-wise binary operations.
175 ("logic_and", 2, "&&"),
176 ("logic_xor", 2, "^^"),
177 ("logic_or", 2, "||"),
185 # Load a value the size of a given GLSL type from a uniform block.
187 # operand0 is the ir_constant uniform block index in the linked shader.
188 # operand1 is a byte offset within the uniform block.
189 ("ubo_load", 2, None),
191 # Multiplies a number by two to a power, part of ARB_gpu_shader5.
194 # Extract a scalar from a vector
196 # operand0 is the vector
197 # operand1 is the index of the field to read from operand0
198 ("vector_extract", 2, None),
200 # Interpolate fs input at offset
202 # operand0 is the fs input
203 # operand1 is the offset from the pixel center
204 ("interpolate_at_offset", 2, None),
206 # Interpolate fs input at sample position
208 # operand0 is the fs input
209 # operand1 is the sample ID
210 ("interpolate_at_sample", 2, None),
212 # Fused floating-point multiply-add, part of ARB_gpu_shader5.
219 # A vector conditional select instruction (like ?:, but operating per-
220 # component on vectors).
222 # See also lower_instructions_visitor::ldexp_to_arith
225 ("bitfield_extract", 3, None),
227 # Generate a value with one field of a vector changed
229 # operand0 is the vector
230 # operand1 is the value to write into the vector result
231 # operand2 is the index in operand0 to be modified
232 ("vector_insert", 3, None),
234 ("bitfield_insert", 4, None),
239 def name_from_item(item
):
240 return "ir_{}op_{}".format(("un", "bin", "tri", "quad")[item
[1]-1], item
[0])
242 if __name__
== "__main__":
244 * Copyright (C) 2010 Intel Corporation
246 * Permission is hereby granted, free of charge, to any person obtaining a
247 * copy of this software and associated documentation files (the "Software"),
248 * to deal in the Software without restriction, including without limitation
249 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
250 * and/or sell copies of the Software, and to permit persons to whom the
251 * Software is furnished to do so, subject to the following conditions:
253 * The above copyright notice and this permission notice (including the next
254 * paragraph) shall be included in all copies or substantial portions of the
257 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
258 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
259 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
260 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
261 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
262 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
263 * DEALINGS IN THE SOFTWARE.
266 enum_template
= mako
.template
.Template(copyright
+ """
267 enum ir_expression_operation {
268 % for item in values:
269 ${name_from_item(item)},
272 /* Sentinels marking the last of each kind of operation. */
273 % for (name, i) in lasts:
274 ir_last_${("un", "bin", "tri", "quad")[i]}op = ${name_from_item((name, i+1))},
276 ir_last_opcode = ir_quadop_${lasts[3][0]}
279 strings_template
= mako
.template
.Template(copyright
+ """
280 const char *const ir_expression_operation_strings[] = {
281 % for item in values:
282 "${item[2] if item[2] is not None else item[0]}",
286 if sys
.argv
[1] == "enum":
287 lasts
= [None, None, None, None]
288 for item
in reversed(ir_expression_operation
):
291 lasts
[i
] = (item
[0], i
)
293 print(enum_template
.render(values
=ir_expression_operation
,
295 name_from_item
=name_from_item
))
296 elif sys
.argv
[1] == "strings":
297 print(strings_template
.render(values
=ir_expression_operation
,
298 name_from_item
=name_from_item
))