Implement "sign" builtin via a new expression operator.
This commit is contained in:

committed by
Ian Romanick

parent
c2de187523
commit
a4b7b5a654
34
builtins/110/sign
Normal file
34
builtins/110/sign
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
((function sign
|
||||||
|
(signature float
|
||||||
|
(parameters
|
||||||
|
(declare (in) float x))
|
||||||
|
((return (expression float sign (var_ref x)))))
|
||||||
|
|
||||||
|
(signature vec2
|
||||||
|
(parameters
|
||||||
|
(declare (in) vec2 x))
|
||||||
|
((declare () vec2 t)
|
||||||
|
(assign (constant bool (1)) (swiz x (var_ref t)) (expression float sign (swiz x (var_ref x))))
|
||||||
|
(assign (constant bool (1)) (swiz y (var_ref t)) (expression float sign (swiz y (var_ref x))))
|
||||||
|
(return (var_ref t))))
|
||||||
|
|
||||||
|
(signature vec3
|
||||||
|
(parameters
|
||||||
|
(declare (in) vec3 x))
|
||||||
|
((declare () vec3 t)
|
||||||
|
(assign (constant bool (1)) (swiz x (var_ref t)) (expression float sign (swiz x (var_ref x))))
|
||||||
|
(assign (constant bool (1)) (swiz y (var_ref t)) (expression float sign (swiz y (var_ref x))))
|
||||||
|
(assign (constant bool (1)) (swiz z (var_ref t)) (expression float sign (swiz z (var_ref x))))
|
||||||
|
(return (var_ref t))))
|
||||||
|
|
||||||
|
(signature vec4
|
||||||
|
(parameters
|
||||||
|
(declare (in) vec4 x))
|
||||||
|
((declare () vec4 t)
|
||||||
|
(assign (constant bool (1)) (swiz x (var_ref t)) (expression float sign (swiz x (var_ref x))))
|
||||||
|
(assign (constant bool (1)) (swiz y (var_ref t)) (expression float sign (swiz y (var_ref x))))
|
||||||
|
(assign (constant bool (1)) (swiz z (var_ref t)) (expression float sign (swiz z (var_ref x))))
|
||||||
|
(assign (constant bool (1)) (swiz w (var_ref t)) (expression float sign (swiz w (var_ref x))))
|
||||||
|
(return (var_ref t))))
|
||||||
|
))
|
||||||
|
|
34
builtins/130/sign
Normal file
34
builtins/130/sign
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
((function sign
|
||||||
|
(signature int
|
||||||
|
(parameters
|
||||||
|
(declare (in) int x))
|
||||||
|
((return (expression int / (var_ref x) (expression int abs (var_ref x))))))
|
||||||
|
|
||||||
|
(signature ivec2
|
||||||
|
(parameters
|
||||||
|
(declare (in) ivec2 x))
|
||||||
|
((declare () ivec2 t)
|
||||||
|
(assign (constant bool (1)) (swiz x (var_ref t)) (expression int sign (swiz x (var_ref x))))
|
||||||
|
(assign (constant bool (1)) (swiz y (var_ref t)) (expression int sign (swiz y (var_ref x))))
|
||||||
|
(return (var_ref t))))
|
||||||
|
|
||||||
|
(signature ivec3
|
||||||
|
(parameters
|
||||||
|
(declare (in) ivec3 x))
|
||||||
|
((declare () ivec3 t)
|
||||||
|
(assign (constant bool (1)) (swiz x (var_ref t)) (expression int sign (swiz x (var_ref x))))
|
||||||
|
(assign (constant bool (1)) (swiz y (var_ref t)) (expression int sign (swiz y (var_ref x))))
|
||||||
|
(assign (constant bool (1)) (swiz z (var_ref t)) (expression int sign (swiz z (var_ref x))))
|
||||||
|
(return (var_ref t))))
|
||||||
|
|
||||||
|
(signature ivec4
|
||||||
|
(parameters
|
||||||
|
(declare (in) ivec4 x))
|
||||||
|
((declare () ivec4 t)
|
||||||
|
(assign (constant bool (1)) (swiz x (var_ref t)) (expression int sign (swiz x (var_ref x))))
|
||||||
|
(assign (constant bool (1)) (swiz y (var_ref t)) (expression int sign (swiz y (var_ref x))))
|
||||||
|
(assign (constant bool (1)) (swiz z (var_ref t)) (expression int sign (swiz z (var_ref x))))
|
||||||
|
(assign (constant bool (1)) (swiz w (var_ref t)) (expression int sign (swiz w (var_ref x))))
|
||||||
|
(return (var_ref t))))
|
||||||
|
))
|
||||||
|
|
2
ir.cpp
2
ir.cpp
@@ -53,6 +53,7 @@ ir_expression::get_num_operands(ir_expression_operation op)
|
|||||||
1, /* ir_unop_logic_not */
|
1, /* ir_unop_logic_not */
|
||||||
1, /* ir_unop_neg */
|
1, /* ir_unop_neg */
|
||||||
1, /* ir_unop_abs */
|
1, /* ir_unop_abs */
|
||||||
|
1, /* ir_unop_sign */
|
||||||
1, /* ir_unop_rcp */
|
1, /* ir_unop_rcp */
|
||||||
1, /* ir_unop_rsq */
|
1, /* ir_unop_rsq */
|
||||||
1, /* ir_unop_sqrt */
|
1, /* ir_unop_sqrt */
|
||||||
@@ -112,6 +113,7 @@ static const char *const operator_strs[] = {
|
|||||||
"!",
|
"!",
|
||||||
"neg",
|
"neg",
|
||||||
"abs",
|
"abs",
|
||||||
|
"sign",
|
||||||
"rcp",
|
"rcp",
|
||||||
"rsq",
|
"rsq",
|
||||||
"sqrt",
|
"sqrt",
|
||||||
|
Reference in New Issue
Block a user