From 57e7da173e8d38bf0c95ded535cdf1b12a00a1a2 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Mon, 3 May 2010 22:11:17 -0700 Subject: [PATCH] Implement "sin" and "cos" builtins via new expression operators. --- builtins/110/cos | 21 +++++++++++++++++++++ builtins/110/sin | 21 +++++++++++++++++++++ ir.cpp | 5 +++++ ir.h | 8 ++++++++ 4 files changed, 55 insertions(+) create mode 100644 builtins/110/cos create mode 100644 builtins/110/sin diff --git a/builtins/110/cos b/builtins/110/cos new file mode 100644 index 00000000000..88f266eccbe --- /dev/null +++ b/builtins/110/cos @@ -0,0 +1,21 @@ +((function cos + (signature float + (parameters + (declare (in) float angle)) + ((return (expression float cos (var_ref angle))))) + + (signature vec2 + (parameters + (declare (in) vec2 angle)) + ((return (expression vec2 cos (var_ref angle))))) + + (signature vec3 + (parameters + (declare (in) vec3 angle)) + ((return (expression vec3 cos (var_ref angle))))) + + (signature vec4 + (parameters + (declare (in) vec4 angle)) + ((return (expression vec4 cos (var_ref angle))))) +)) diff --git a/builtins/110/sin b/builtins/110/sin new file mode 100644 index 00000000000..e6009d8ef12 --- /dev/null +++ b/builtins/110/sin @@ -0,0 +1,21 @@ +((function sin + (signature float + (parameters + (declare (in) float angle)) + ((return (expression float sin (var_ref angle))))) + + (signature vec2 + (parameters + (declare (in) vec2 angle)) + ((return (expression vec2 sin (var_ref angle))))) + + (signature vec3 + (parameters + (declare (in) vec3 angle)) + ((return (expression vec3 sin (var_ref angle))))) + + (signature vec4 + (parameters + (declare (in) vec4 angle)) + ((return (expression vec4 sin (var_ref angle))))) +)) diff --git a/ir.cpp b/ir.cpp index b927c73ccb6..eb12b5fe77f 100644 --- a/ir.cpp +++ b/ir.cpp @@ -73,6 +73,9 @@ ir_expression::get_num_operands(ir_expression_operation op) 1, /* ir_unop_ceil */ 1, /* ir_unop_floor */ + 1, /* ir_unop_sin */ + 1, /* ir_unop_cos */ + 2, /* ir_binop_add */ 2, /* ir_binop_sub */ 2, /* ir_binop_mul */ @@ -131,6 +134,8 @@ static const char *const operator_strs[] = { "trunc", "ceil", "floor", + "sin", + "cos", "+", "-", "*", diff --git a/ir.h b/ir.h index 55a67733fe7..df9a8c4174d 100644 --- a/ir.h +++ b/ir.h @@ -449,6 +449,14 @@ enum ir_expression_operation { ir_unop_floor, /*@}*/ + /** + * \name Trigonometric operations. + */ + /*@{*/ + ir_unop_sin, + ir_unop_cos, + /*@}*/ + ir_binop_add, ir_binop_sub, ir_binop_mul, -- 2.30.2