glsl: Delete spurious comment about mod not taking integer operands
[mesa.git] / src / compiler / glsl / ir_expression_operation.py
1 #! /usr/bin/env python
2 #
3 # Copyright (C) 2015 Intel Corporation
4 #
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:
11 #
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
14 # Software.
15 #
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
22 # IN THE SOFTWARE.
23
24 import mako.template
25 import sys
26
27 ir_expression_operation = [
28 # Name operands string
29 ("bit_not", 1, "~"),
30 ("logic_not", 1, "!"),
31 ("neg", 1, None),
32 ("abs", 1, None),
33 ("sign", 1, None),
34 ("rcp", 1, None),
35 ("rsq", 1, None),
36 ("sqrt", 1, None),
37 ("exp", 1, None), # Log base e on gentype
38 ("log", 1, None), # Natural log on gentype
39 ("exp2", 1, None),
40 ("log2", 1, 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"
62
63 # Unary floating-point rounding operations.
64 ("trunc", 1, None),
65 ("ceil", 1, None),
66 ("floor", 1, None),
67 ("fract", 1, None),
68 ("round_even", 1, None),
69
70 # Trigonometric operations.
71 ("sin", 1, None),
72 ("cos", 1, None),
73
74 # Partial derivatives.
75 ("dFdx", 1, None),
76 ("dFdx_coarse", 1, "dFdxCoarse"),
77 ("dFdx_fine", 1, "dFdxFine"),
78 ("dFdy", 1, None),
79 ("dFdy_coarse", 1, "dFdyCoarse"),
80 ("dFdy_fine", 1, "dFdyFine"),
81
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"),
93
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),
99
100 ("saturate", 1, "sat"),
101
102 # Double packing, part of ARB_gpu_shader_fp64.
103 ("pack_double_2x32", 1, "packDouble2x32"),
104 ("unpack_double_2x32", 1, "unpackDouble2x32"),
105
106 ("frexp_sig", 1, None),
107 ("frexp_exp", 1, None),
108
109 ("noise", 1, None),
110
111 ("subroutine_to_int", 1, None),
112
113 # Interpolate fs input at centroid
114 #
115 # operand0 is the fs input.
116 ("interpolate_at_centroid", 1, None),
117
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),
121
122 # Calculate length of an unsized array inside a buffer block.
123 # This opcode is going to be replaced in a lowering pass inside
124 # the linker.
125 #
126 # operand0 is the unsized array's ir_value for the calculation
127 # of its length.
128 ("ssbo_unsized_array_length", 1, None),
129
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),
134
135 ("add", 2, "+"),
136 ("sub", 2, "-"),
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.
139 ("div", 2, "/"),
140
141 # Returns the carry resulting from the addition of the two arguments.
142 ("carry", 2, None),
143
144 # Returns the borrow resulting from the subtraction of the second argument
145 # from the first argument.
146 ("borrow", 2, None),
147
148 # Either (vector % vector) or (vector % scalar)
149 ("mod", 2, "%"),
150
151 # Binary comparison operators which return a boolean vector.
152 # The type of both operands must be equal.
153 ("less", 2, "<"),
154 ("greater", 2, ">"),
155 ("lequal", 2, "<="),
156 ("gequal", 2, ">="),
157 ("equal", 2, "=="),
158 ("nequal", 2, "!="),
159
160 # Returns single boolean for whether all components of operands[0]
161 # equal the components of operands[1].
162 ("all_equal", 2, None),
163
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),
167
168 # Bit-wise binary operations.
169 ("lshift", 2, "<<"),
170 ("rshift", 2, ">>"),
171 ("bit_and", 2, "&"),
172 ("bit_xor", 2, "^"),
173 ("bit_or", 2, "|"),
174
175 ("logic_and", 2, "&&"),
176 ("logic_xor", 2, "^^"),
177 ("logic_or", 2, "||"),
178
179 ("dot", 2, None),
180 ("min", 2, None),
181 ("max", 2, None),
182
183 ("pow", 2, None),
184
185 # Load a value the size of a given GLSL type from a uniform block.
186 #
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),
190
191 # Multiplies a number by two to a power, part of ARB_gpu_shader5.
192 ("ldexp", 2, None),
193
194 # Extract a scalar from a vector
195 #
196 # operand0 is the vector
197 # operand1 is the index of the field to read from operand0
198 ("vector_extract", 2, None),
199
200 # Interpolate fs input at offset
201 #
202 # operand0 is the fs input
203 # operand1 is the offset from the pixel center
204 ("interpolate_at_offset", 2, None),
205
206 # Interpolate fs input at sample position
207 #
208 # operand0 is the fs input
209 # operand1 is the sample ID
210 ("interpolate_at_sample", 2, None),
211
212 # Fused floating-point multiply-add, part of ARB_gpu_shader5.
213 ("fma", 3, None),
214
215 ("lrp", 3, None),
216
217 # Conditional Select
218 #
219 # A vector conditional select instruction (like ?:, but operating per-
220 # component on vectors).
221 #
222 # See also lower_instructions_visitor::ldexp_to_arith
223 ("csel", 3, None),
224
225 ("bitfield_extract", 3, None),
226
227 # Generate a value with one field of a vector changed
228 #
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),
233
234 ("bitfield_insert", 4, None),
235
236 ("vector", 4, None),
237 ]
238
239 def name_from_item(item):
240 return "ir_{}op_{}".format(("un", "bin", "tri", "quad")[item[1]-1], item[0])
241
242 if __name__ == "__main__":
243 copyright = """/*
244 * Copyright (C) 2010 Intel Corporation
245 *
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:
252 *
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
255 * Software.
256 *
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.
264 */
265 """
266 enum_template = mako.template.Template(copyright + """
267 enum ir_expression_operation {
268 % for item in values:
269 ${name_from_item(item)},
270 % endfor
271
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))},
275 % endfor
276 ir_last_opcode = ir_quadop_${lasts[3][0]}
277 };""")
278
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]}",
283 % endfor
284 };""")
285
286 if sys.argv[1] == "enum":
287 lasts = [None, None, None, None]
288 for item in reversed(ir_expression_operation):
289 i = item[1] - 1
290 if lasts[i] is None:
291 lasts[i] = (item[0], i)
292
293 print(enum_template.render(values=ir_expression_operation,
294 lasts=lasts,
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))