blob: 9869f70597ef421b07529d015893a70d94bcd9ca [file] [log] [blame]
Eric Anholtc22c4002010-03-26 18:20:30 -07001/*
2 * Copyright © 2010 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
21 * DEALINGS IN THE SOFTWARE.
22 */
23
24#include <stdlib.h>
Eric Anholtd1e31952010-03-28 01:55:38 -070025#include <math.h>
Eric Anholtc22c4002010-03-26 18:20:30 -070026#include "glsl_symbol_table.h"
27#include "glsl_parser_extras.h"
28#include "glsl_types.h"
29#include "ir.h"
30
31static void
Eric Anholt2eec73f2010-03-27 12:25:20 -070032generate_unop(exec_list *instructions,
33 ir_variable **declarations,
34 const glsl_type *type,
35 enum ir_expression_operation op)
Eric Anholtc22c4002010-03-26 18:20:30 -070036{
Eric Anholtc22c4002010-03-26 18:20:30 -070037 ir_dereference *const arg = new ir_dereference(declarations[0]);
38 ir_rvalue *result;
39
Eric Anholt2eec73f2010-03-27 12:25:20 -070040 result = new ir_expression(op, type, arg, NULL);
Eric Anholtc22c4002010-03-26 18:20:30 -070041
Eric Anholt7e78e072010-04-07 13:34:15 -070042 ir_instruction *inst = new ir_return(result);
Eric Anholtc22c4002010-03-26 18:20:30 -070043 instructions->push_tail(inst);
44}
45
Eric Anholt2eec73f2010-03-27 12:25:20 -070046static void
Eric Anholtbfe380a2010-03-27 12:43:13 -070047generate_binop(exec_list *instructions,
48 ir_variable **declarations,
49 const glsl_type *type,
50 enum ir_expression_operation op)
51{
Eric Anholtbfe380a2010-03-27 12:43:13 -070052 ir_dereference *const arg1 = new ir_dereference(declarations[0]);
53 ir_dereference *const arg2 = new ir_dereference(declarations[1]);
54 ir_rvalue *result;
55
56 result = new ir_expression(op, type, arg1, arg2);
57
Eric Anholt7e78e072010-04-07 13:34:15 -070058 ir_instruction *inst = new ir_return(result);
Eric Anholtbfe380a2010-03-27 12:43:13 -070059 instructions->push_tail(inst);
60}
61
62static void
Eric Anholtd1e31952010-03-28 01:55:38 -070063generate_radians(exec_list *instructions,
64 ir_variable **declarations,
65 const glsl_type *type)
66{
Eric Anholtd1e31952010-03-28 01:55:38 -070067 ir_dereference *const arg = new ir_dereference(declarations[0]);
68 ir_rvalue *result;
69
70 result = new ir_expression(ir_binop_mul, type,
71 arg,
72 new ir_constant((float)(M_PI / 180.0)));
73
Eric Anholt7e78e072010-04-07 13:34:15 -070074 ir_instruction *inst = new ir_return(result);
Eric Anholtd1e31952010-03-28 01:55:38 -070075 instructions->push_tail(inst);
76}
77
78static void
79generate_degrees(exec_list *instructions,
80 ir_variable **declarations,
81 const glsl_type *type)
82{
Eric Anholtd1e31952010-03-28 01:55:38 -070083 ir_dereference *const arg = new ir_dereference(declarations[0]);
84 ir_rvalue *result;
85
86 result = new ir_expression(ir_binop_mul, type,
87 arg,
88 new ir_constant((float)(180.0 / M_PI)));
89
Eric Anholt7e78e072010-04-07 13:34:15 -070090 ir_instruction *inst = new ir_return(result);
Eric Anholtd1e31952010-03-28 01:55:38 -070091 instructions->push_tail(inst);
92}
93
94static void
Eric Anholt2eec73f2010-03-27 12:25:20 -070095generate_exp(exec_list *instructions,
96 ir_variable **declarations,
97 const glsl_type *type)
98{
99 generate_unop(instructions, declarations, type, ir_unop_exp);
100}
101
102static void
103generate_log(exec_list *instructions,
104 ir_variable **declarations,
105 const glsl_type *type)
106{
107 generate_unop(instructions, declarations, type, ir_unop_log);
108}
109
110static void
Eric Anholt01665262010-03-27 13:56:35 -0700111generate_exp2(exec_list *instructions,
112 ir_variable **declarations,
113 const glsl_type *type)
114{
115 generate_unop(instructions, declarations, type, ir_unop_exp2);
116}
117
118static void
119generate_log2(exec_list *instructions,
120 ir_variable **declarations,
121 const glsl_type *type)
122{
123 generate_unop(instructions, declarations, type, ir_unop_log2);
124}
125
126static void
Eric Anholt2eec73f2010-03-27 12:25:20 -0700127generate_rsq(exec_list *instructions,
128 ir_variable **declarations,
129 const glsl_type *type)
130{
131 generate_unop(instructions, declarations, type, ir_unop_rsq);
132}
133
134static void
Eric Anholt44d68fd2010-03-27 13:01:51 -0700135generate_sqrt(exec_list *instructions,
136 ir_variable **declarations,
137 const glsl_type *type)
138{
139 generate_unop(instructions, declarations, type, ir_unop_sqrt);
140}
141
142static void
Eric Anholt2eec73f2010-03-27 12:25:20 -0700143generate_abs(exec_list *instructions,
144 ir_variable **declarations,
145 const glsl_type *type)
146{
147 generate_unop(instructions, declarations, type, ir_unop_abs);
148}
149
150static void
151generate_ceil(exec_list *instructions,
152 ir_variable **declarations,
153 const glsl_type *type)
154{
155 generate_unop(instructions, declarations, type, ir_unop_ceil);
156}
157
158static void
159generate_floor(exec_list *instructions,
160 ir_variable **declarations,
161 const glsl_type *type)
162{
163 generate_unop(instructions, declarations, type, ir_unop_floor);
164}
165
Eric Anholtbfe380a2010-03-27 12:43:13 -0700166static void
167generate_mod(exec_list *instructions,
168 ir_variable **declarations,
169 const glsl_type *type)
170{
171 generate_binop(instructions, declarations, type, ir_binop_mod);
172}
173
174static void
175generate_min(exec_list *instructions,
176 ir_variable **declarations,
177 const glsl_type *type)
178{
179 generate_binop(instructions, declarations, type, ir_binop_min);
180}
181
182static void
183generate_max(exec_list *instructions,
184 ir_variable **declarations,
185 const glsl_type *type)
186{
187 generate_binop(instructions, declarations, type, ir_binop_max);
188}
189
Eric Anholtddd2e832010-03-27 12:59:42 -0700190
191static void
Eric Anholt92575922010-04-08 14:34:38 -0700192generate_normalize(exec_list *instructions,
193 ir_variable **declarations,
194 const glsl_type *type)
195{
196 ir_dereference *const arg = new ir_dereference(declarations[0]);
197 ir_rvalue *temp;
198 ir_rvalue *result;
199
200 temp = new ir_expression(ir_binop_dot, glsl_type::float_type, arg, arg);
201 temp = new ir_expression(ir_unop_rsq, glsl_type::float_type, temp, NULL);
202 result = new ir_expression(ir_binop_mul, type, arg, temp);
203
204 ir_instruction *inst = new ir_return(result);
205 instructions->push_tail(inst);
206}
207
208
209static void
Eric Anholtddd2e832010-03-27 12:59:42 -0700210generate_pow(exec_list *instructions,
211 ir_variable **declarations,
212 const glsl_type *type)
213{
214 generate_binop(instructions, declarations, type, ir_binop_pow);
215}
216
Eric Anholtc22c4002010-03-26 18:20:30 -0700217void
218generate_function_instance(ir_function *f,
219 const char *name,
220 exec_list *instructions,
Eric Anholtbfe380a2010-03-27 12:43:13 -0700221 int n_args,
Eric Anholtc22c4002010-03-26 18:20:30 -0700222 void (*generate)(exec_list *instructions,
223 ir_variable **declarations,
224 const glsl_type *type),
Eric Anholt53afc362010-03-27 13:55:04 -0700225 const glsl_type *ret_type,
Eric Anholtc22c4002010-03-26 18:20:30 -0700226 const glsl_type *type)
227{
Eric Anholt7e78e072010-04-07 13:34:15 -0700228 ir_variable *declarations[16];
Eric Anholtc22c4002010-03-26 18:20:30 -0700229
Eric Anholt7e78e072010-04-07 13:34:15 -0700230 ir_function_signature *const sig = new ir_function_signature(ret_type);
Ian Romanick6a15d5b52010-03-31 16:37:10 -0700231 f->add_signature(sig);
Eric Anholtc22c4002010-03-26 18:20:30 -0700232
Eric Anholt894ea972010-04-07 13:19:11 -0700233 ir_label *const label = new ir_label(name, sig);
Eric Anholtc22c4002010-03-26 18:20:30 -0700234 instructions->push_tail(label);
235 sig->definition = label;
Eric Anholtbfe380a2010-03-27 12:43:13 -0700236 static const char *arg_names[] = {
237 "arg0",
238 "arg1"
239 };
240 int i;
Eric Anholtc22c4002010-03-26 18:20:30 -0700241
Eric Anholtbfe380a2010-03-27 12:43:13 -0700242 for (i = 0; i < n_args; i++) {
243 ir_variable *var = new ir_variable(type, arg_names[i]);
Eric Anholtc22c4002010-03-26 18:20:30 -0700244
Eric Anholtbfe380a2010-03-27 12:43:13 -0700245 var->mode = ir_var_in;
246 sig->parameters.push_tail(var);
Eric Anholtc22c4002010-03-26 18:20:30 -0700247
Eric Anholtbfe380a2010-03-27 12:43:13 -0700248 declarations[i] = var;
249 }
Eric Anholtc22c4002010-03-26 18:20:30 -0700250
Eric Anholt894ea972010-04-07 13:19:11 -0700251 generate(&sig->body, declarations, type);
Eric Anholtc22c4002010-03-26 18:20:30 -0700252}
253
254void
255make_gentype_function(glsl_symbol_table *symtab, exec_list *instructions,
256 const char *name,
Eric Anholtbfe380a2010-03-27 12:43:13 -0700257 int n_args,
Eric Anholtc22c4002010-03-26 18:20:30 -0700258 void (*generate)(exec_list *instructions,
259 ir_variable **declarations,
260 const glsl_type *type))
261{
262 ir_function *const f = new ir_function(name);
Eric Anholt53afc362010-03-27 13:55:04 -0700263 const glsl_type *float_type = glsl_type::float_type;
Eric Anholtc22c4002010-03-26 18:20:30 -0700264 const glsl_type *vec2_type = glsl_type::get_instance(GLSL_TYPE_FLOAT, 2, 1);
265 const glsl_type *vec3_type = glsl_type::get_instance(GLSL_TYPE_FLOAT, 3, 1);
266 const glsl_type *vec4_type = glsl_type::get_instance(GLSL_TYPE_FLOAT, 4, 1);
267
268 bool added = symtab->add_function(name, f);
269 assert(added);
270
Eric Anholtbfe380a2010-03-27 12:43:13 -0700271 generate_function_instance(f, name, instructions, n_args, generate,
Eric Anholt53afc362010-03-27 13:55:04 -0700272 float_type, float_type);
Eric Anholtbfe380a2010-03-27 12:43:13 -0700273 generate_function_instance(f, name, instructions, n_args, generate,
Eric Anholt53afc362010-03-27 13:55:04 -0700274 vec2_type, vec2_type);
Eric Anholtbfe380a2010-03-27 12:43:13 -0700275 generate_function_instance(f, name, instructions, n_args, generate,
Eric Anholt53afc362010-03-27 13:55:04 -0700276 vec3_type, vec3_type);
Eric Anholtbfe380a2010-03-27 12:43:13 -0700277 generate_function_instance(f, name, instructions, n_args, generate,
Eric Anholt53afc362010-03-27 13:55:04 -0700278 vec4_type, vec4_type);
279}
280
281static void
282generate_length(exec_list *instructions,
283 ir_variable **declarations,
284 const glsl_type *type)
285{
Eric Anholt53afc362010-03-27 13:55:04 -0700286 ir_dereference *const arg = new ir_dereference(declarations[0]);
287 ir_rvalue *result, *temp;
288
289 (void)type;
290
291 /* FINISHME: implement the abs(arg) variant for length(float f) */
292
293 temp = new ir_expression(ir_binop_dot, glsl_type::float_type, arg, arg);
294 result = new ir_expression(ir_unop_sqrt, glsl_type::float_type, temp, NULL);
295
Eric Anholt7e78e072010-04-07 13:34:15 -0700296 ir_instruction *inst = new ir_return(result);
Eric Anholt53afc362010-03-27 13:55:04 -0700297 instructions->push_tail(inst);
298}
299
300void
301generate_length_functions(glsl_symbol_table *symtab, exec_list *instructions)
302{
303 const char *name = "length";
304 ir_function *const f = new ir_function(name);
305 const glsl_type *float_type = glsl_type::float_type;
306 const glsl_type *vec2_type = glsl_type::get_instance(GLSL_TYPE_FLOAT, 2, 1);
307 const glsl_type *vec3_type = glsl_type::get_instance(GLSL_TYPE_FLOAT, 3, 1);
308 const glsl_type *vec4_type = glsl_type::get_instance(GLSL_TYPE_FLOAT, 4, 1);
309
310 bool added = symtab->add_function(name, f);
311 assert(added);
312
313 generate_function_instance(f, name, instructions, 1, generate_length,
314 float_type, float_type);
315 generate_function_instance(f, name, instructions, 1, generate_length,
316 float_type, vec2_type);
317 generate_function_instance(f, name, instructions, 1, generate_length,
318 float_type, vec3_type);
319 generate_function_instance(f, name, instructions, 1, generate_length,
320 float_type, vec4_type);
Eric Anholtc22c4002010-03-26 18:20:30 -0700321}
322
Eric Anholt76a91e12010-03-27 14:04:43 -0700323static void
324generate_dot(exec_list *instructions,
325 ir_variable **declarations,
326 const glsl_type *type)
327{
Eric Anholt61733122010-04-07 15:18:37 -0700328 ir_dereference *const arg0 = new ir_dereference(declarations[0]);
329 ir_dereference *const arg1 = new ir_dereference(declarations[1]);
Eric Anholt76a91e12010-03-27 14:04:43 -0700330 ir_rvalue *result;
331
332 (void)type;
333
Eric Anholt61733122010-04-07 15:18:37 -0700334 result = new ir_expression(ir_binop_dot, glsl_type::float_type, arg0, arg1);
Eric Anholt76a91e12010-03-27 14:04:43 -0700335
Eric Anholt7e78e072010-04-07 13:34:15 -0700336 ir_instruction *inst = new ir_return(result);
Eric Anholt76a91e12010-03-27 14:04:43 -0700337 instructions->push_tail(inst);
338}
339
340void
341generate_dot_functions(glsl_symbol_table *symtab, exec_list *instructions)
342{
343 const char *name = "dot";
344 ir_function *const f = new ir_function(name);
345 const glsl_type *float_type = glsl_type::float_type;
346 const glsl_type *vec2_type = glsl_type::get_instance(GLSL_TYPE_FLOAT, 2, 1);
347 const glsl_type *vec3_type = glsl_type::get_instance(GLSL_TYPE_FLOAT, 3, 1);
348 const glsl_type *vec4_type = glsl_type::get_instance(GLSL_TYPE_FLOAT, 4, 1);
349
350 bool added = symtab->add_function(name, f);
351 assert(added);
352
Eric Anholt61733122010-04-07 15:18:37 -0700353 generate_function_instance(f, name, instructions, 2, generate_dot,
Eric Anholt76a91e12010-03-27 14:04:43 -0700354 float_type, float_type);
Eric Anholt61733122010-04-07 15:18:37 -0700355 generate_function_instance(f, name, instructions, 2, generate_dot,
Eric Anholt76a91e12010-03-27 14:04:43 -0700356 float_type, vec2_type);
Eric Anholt61733122010-04-07 15:18:37 -0700357 generate_function_instance(f, name, instructions, 2, generate_dot,
Eric Anholt76a91e12010-03-27 14:04:43 -0700358 float_type, vec3_type);
Eric Anholt61733122010-04-07 15:18:37 -0700359 generate_function_instance(f, name, instructions, 2, generate_dot,
Eric Anholt76a91e12010-03-27 14:04:43 -0700360 float_type, vec4_type);
361}
362
Eric Anholtfeeb43b2010-04-08 15:02:59 -0700363static void
364generate_any_bvec2(exec_list *instructions,
365 ir_variable **declarations,
366 const glsl_type *type)
367{
368 ir_dereference *const arg0 = new ir_dereference(declarations[0]);
369 ir_rvalue *result;
370
371 (void)type;
372
373 result = new ir_expression(ir_binop_logic_or, glsl_type::bool_type,
374 new ir_swizzle(arg0, 0, 0, 0, 0, 1),
375 new ir_swizzle(arg0, 1, 0, 0, 0, 1));
376
377 ir_instruction *inst = new ir_return(result);
378 instructions->push_tail(inst);
379}
380
381static void
382generate_any_bvec3(exec_list *instructions,
383 ir_variable **declarations,
384 const glsl_type *type)
385{
386 ir_dereference *const arg0 = new ir_dereference(declarations[0]);
387 ir_rvalue *result;
388
389 (void)type;
390
391 result = new ir_expression(ir_binop_logic_or, glsl_type::bool_type,
392 new ir_swizzle(arg0, 0, 0, 0, 0, 1),
393 new ir_swizzle(arg0, 1, 0, 0, 0, 1));
394 result = new ir_expression(ir_binop_logic_or, glsl_type::bool_type,
395 result,
396 new ir_swizzle(arg0, 2, 0, 0, 0, 1));
397
398 ir_instruction *inst = new ir_return(result);
399 instructions->push_tail(inst);
400}
401
402static void
403generate_any_bvec4(exec_list *instructions,
404 ir_variable **declarations,
405 const glsl_type *type)
406{
407 ir_dereference *const arg0 = new ir_dereference(declarations[0]);
408 ir_rvalue *result;
409
410 (void)type;
411
412 result = new ir_expression(ir_binop_logic_or, glsl_type::bool_type,
413 new ir_swizzle(arg0, 0, 0, 0, 0, 1),
414 new ir_swizzle(arg0, 1, 0, 0, 0, 1));
415 result = new ir_expression(ir_binop_logic_or, glsl_type::bool_type,
416 result,
417 new ir_swizzle(arg0, 2, 0, 0, 0, 1));
418 result = new ir_expression(ir_binop_logic_or, glsl_type::bool_type,
419 result,
420 new ir_swizzle(arg0, 3, 0, 0, 0, 1));
421
422 ir_instruction *inst = new ir_return(result);
423 instructions->push_tail(inst);
424}
425
426static void
427generate_all_bvec2(exec_list *instructions,
428 ir_variable **declarations,
429 const glsl_type *type)
430{
431 ir_dereference *const arg0 = new ir_dereference(declarations[0]);
432 ir_rvalue *result;
433
434 (void)type;
435
436 result = new ir_expression(ir_binop_logic_and, glsl_type::bool_type,
437 new ir_swizzle(arg0, 0, 0, 0, 0, 1),
438 new ir_swizzle(arg0, 1, 0, 0, 0, 1));
439
440 ir_instruction *inst = new ir_return(result);
441 instructions->push_tail(inst);
442}
443
444static void
445generate_all_bvec3(exec_list *instructions,
446 ir_variable **declarations,
447 const glsl_type *type)
448{
449 ir_dereference *const arg0 = new ir_dereference(declarations[0]);
450 ir_rvalue *result;
451
452 (void)type;
453
454 result = new ir_expression(ir_binop_logic_and, glsl_type::bool_type,
455 new ir_swizzle(arg0, 0, 0, 0, 0, 1),
456 new ir_swizzle(arg0, 1, 0, 0, 0, 1));
457 result = new ir_expression(ir_binop_logic_and, glsl_type::bool_type,
458 result,
459 new ir_swizzle(arg0, 2, 0, 0, 0, 1));
460
461 ir_instruction *inst = new ir_return(result);
462 instructions->push_tail(inst);
463}
464
465static void
466generate_all_bvec4(exec_list *instructions,
467 ir_variable **declarations,
468 const glsl_type *type)
469{
470 ir_dereference *const arg0 = new ir_dereference(declarations[0]);
471 ir_rvalue *result;
472
473 (void)type;
474
475 result = new ir_expression(ir_binop_logic_and, glsl_type::bool_type,
476 new ir_swizzle(arg0, 0, 0, 0, 0, 1),
477 new ir_swizzle(arg0, 1, 0, 0, 0, 1));
478 result = new ir_expression(ir_binop_logic_and, glsl_type::bool_type,
479 result,
480 new ir_swizzle(arg0, 2, 0, 0, 0, 1));
481 result = new ir_expression(ir_binop_logic_and, glsl_type::bool_type,
482 result,
483 new ir_swizzle(arg0, 3, 0, 0, 0, 1));
484
485 ir_instruction *inst = new ir_return(result);
486 instructions->push_tail(inst);
487}
488
489static void
490generate_not(exec_list *instructions,
491 ir_variable **declarations,
492 const glsl_type *type)
493{
494 ir_dereference *const arg0 = new ir_dereference(declarations[0]);
495 ir_rvalue *result;
496
497 result = new ir_expression(ir_unop_logic_not, type, arg0, NULL);
498
499 ir_instruction *inst = new ir_return(result);
500 instructions->push_tail(inst);
501}
502
503void
504generate_any_functions(glsl_symbol_table *symtab, exec_list *instructions)
505{
506 const char *name = "any";
507 ir_function *const f = new ir_function(name);
508 const glsl_type *bvec2_type = glsl_type::get_instance(GLSL_TYPE_BOOL, 2, 1);
509 const glsl_type *bvec3_type = glsl_type::get_instance(GLSL_TYPE_BOOL, 3, 1);
510 const glsl_type *bvec4_type = glsl_type::get_instance(GLSL_TYPE_BOOL, 4, 1);
511
512 bool added = symtab->add_function(name, f);
513 assert(added);
514
515 generate_function_instance(f, name, instructions, 1, generate_any_bvec2,
516 glsl_type::bool_type, bvec2_type);
517 generate_function_instance(f, name, instructions, 1, generate_any_bvec3,
518 glsl_type::bool_type, bvec3_type);
519 generate_function_instance(f, name, instructions, 1, generate_any_bvec4,
520 glsl_type::bool_type, bvec4_type);
521}
522
523void
524generate_all_functions(glsl_symbol_table *symtab, exec_list *instructions)
525{
526 const char *name = "all";
527 ir_function *const f = new ir_function(name);
528 const glsl_type *bvec2_type = glsl_type::get_instance(GLSL_TYPE_BOOL, 2, 1);
529 const glsl_type *bvec3_type = glsl_type::get_instance(GLSL_TYPE_BOOL, 3, 1);
530 const glsl_type *bvec4_type = glsl_type::get_instance(GLSL_TYPE_BOOL, 4, 1);
531
532 bool added = symtab->add_function(name, f);
533 assert(added);
534
535 generate_function_instance(f, name, instructions, 1, generate_all_bvec2,
536 glsl_type::bool_type, bvec2_type);
537 generate_function_instance(f, name, instructions, 1, generate_all_bvec3,
538 glsl_type::bool_type, bvec3_type);
539 generate_function_instance(f, name, instructions, 1, generate_all_bvec4,
540 glsl_type::bool_type, bvec4_type);
541}
542
543void
544generate_not_functions(glsl_symbol_table *symtab, exec_list *instructions)
545{
546 const char *name = "not";
547 ir_function *const f = new ir_function(name);
548 const glsl_type *bvec2_type = glsl_type::get_instance(GLSL_TYPE_BOOL, 2, 1);
549 const glsl_type *bvec3_type = glsl_type::get_instance(GLSL_TYPE_BOOL, 3, 1);
550 const glsl_type *bvec4_type = glsl_type::get_instance(GLSL_TYPE_BOOL, 4, 1);
551
552 bool added = symtab->add_function(name, f);
553 assert(added);
554
555 generate_function_instance(f, name, instructions, 1, generate_not,
556 bvec2_type, bvec2_type);
557 generate_function_instance(f, name, instructions, 1, generate_not,
558 bvec3_type, bvec3_type);
559 generate_function_instance(f, name, instructions, 1, generate_not,
560 bvec4_type, bvec4_type);
561}
562
Eric Anholtc22c4002010-03-26 18:20:30 -0700563void
564generate_110_functions(glsl_symbol_table *symtab, exec_list *instructions)
565{
Eric Anholtd1e31952010-03-28 01:55:38 -0700566 make_gentype_function(symtab, instructions, "radians", 1, generate_radians);
567 make_gentype_function(symtab, instructions, "degrees", 1, generate_degrees);
Eric Anholtc22c4002010-03-26 18:20:30 -0700568 /* FINISHME: sin() */
569 /* FINISHME: cos() */
570 /* FINISHME: tan() */
571 /* FINISHME: asin() */
572 /* FINISHME: acos() */
573 /* FINISHME: atan(y,x) */
574 /* FINISHME: atan(y/x) */
Eric Anholtddd2e832010-03-27 12:59:42 -0700575 make_gentype_function(symtab, instructions, "pow", 2, generate_pow);
Eric Anholtbfe380a2010-03-27 12:43:13 -0700576 make_gentype_function(symtab, instructions, "exp", 1, generate_exp);
577 make_gentype_function(symtab, instructions, "log", 1, generate_log);
Eric Anholt01665262010-03-27 13:56:35 -0700578 make_gentype_function(symtab, instructions, "exp2", 1, generate_exp2);
579 make_gentype_function(symtab, instructions, "log2", 1, generate_log2);
Eric Anholt44d68fd2010-03-27 13:01:51 -0700580 make_gentype_function(symtab, instructions, "sqrt", 1, generate_sqrt);
Eric Anholtbfe380a2010-03-27 12:43:13 -0700581 make_gentype_function(symtab, instructions, "inversesqrt", 1, generate_rsq);
582 make_gentype_function(symtab, instructions, "abs", 1, generate_abs);
Eric Anholtc22c4002010-03-26 18:20:30 -0700583 /* FINISHME: sign() */
Eric Anholtbfe380a2010-03-27 12:43:13 -0700584 make_gentype_function(symtab, instructions, "floor", 1, generate_floor);
585 make_gentype_function(symtab, instructions, "ceil", 1, generate_ceil);
Eric Anholtc22c4002010-03-26 18:20:30 -0700586 /* FINISHME: fract() */
587 /* FINISHME: mod(x, float y) */
Eric Anholtbfe380a2010-03-27 12:43:13 -0700588 make_gentype_function(symtab, instructions, "mod", 2, generate_mod);
589 make_gentype_function(symtab, instructions, "min", 2, generate_min);
590 /* FINISHME: min(x, float y) */
591 make_gentype_function(symtab, instructions, "max", 2, generate_max);
592 /* FINISHME: max(x, float y) */
Eric Anholtc22c4002010-03-26 18:20:30 -0700593 /* FINISHME: clamp() */
594 /* FINISHME: clamp() */
595 /* FINISHME: mix() */
596 /* FINISHME: mix() */
597 /* FINISHME: step() */
598 /* FINISHME: step() */
599 /* FINISHME: smoothstep() */
600 /* FINISHME: smoothstep() */
601 /* FINISHME: floor() */
602 /* FINISHME: step() */
Eric Anholt53afc362010-03-27 13:55:04 -0700603 generate_length_functions(symtab, instructions);
Eric Anholtc22c4002010-03-26 18:20:30 -0700604 /* FINISHME: distance() */
Eric Anholt76a91e12010-03-27 14:04:43 -0700605 generate_dot_functions(symtab, instructions);
Eric Anholtc22c4002010-03-26 18:20:30 -0700606 /* FINISHME: cross() */
Eric Anholt92575922010-04-08 14:34:38 -0700607 make_gentype_function(symtab, instructions, "normalize", 1,
608 generate_normalize);
Eric Anholtc22c4002010-03-26 18:20:30 -0700609 /* FINISHME: normalize() */
610 /* FINISHME: ftransform() */
611 /* FINISHME: faceforward() */
612 /* FINISHME: reflect() */
613 /* FINISHME: refract() */
614 /* FINISHME: matrixCompMult() */
615 /* FINISHME: lessThan() */
616 /* FINISHME: lessThanEqual() */
617 /* FINISHME: greaterThan() */
618 /* FINISHME: greaterThanEqual() */
619 /* FINISHME: equal() */
620 /* FINISHME: notEqual() */
Eric Anholtfeeb43b2010-04-08 15:02:59 -0700621 generate_any_functions(symtab, instructions);
622 generate_all_functions(symtab, instructions);
623 generate_not_functions(symtab, instructions);
Eric Anholtc22c4002010-03-26 18:20:30 -0700624 /* FINISHME: texture*() */
625 /* FINISHME: shadow*() */
626 /* FINISHME: dFd[xy]() */
627 /* FINISHME: fwidth() */
628}
629
630void
631_mesa_glsl_initialize_functions(exec_list *instructions,
632 struct _mesa_glsl_parse_state *state)
633{
634 generate_110_functions(state->symbols, instructions);
635}