summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Turner <[email protected]>2014-04-05 22:03:04 -0700
committerMatt Turner <[email protected]>2014-04-15 09:24:09 -0700
commitd877c643bea7a40e37d13d8a967c06fd006d1622 (patch)
tree344a9b51785bab1ccd9442f00e2c82c057ebe6a2
parent4f20b7d3ddaac1d9f7822ef1b9cbed07b3ef35fe (diff)
glsl: Use M_PI_* macros.
Notice our multiple values for M_PI_2, which rounded ...32 up to ...4 and ...5.
-rw-r--r--src/glsl/builtin_functions.cpp20
1 files changed, 13 insertions, 7 deletions
diff --git a/src/glsl/builtin_functions.cpp b/src/glsl/builtin_functions.cpp
index 26ea9231f73..3991f9d8d8c 100644
--- a/src/glsl/builtin_functions.cpp
+++ b/src/glsl/builtin_functions.cpp
@@ -62,6 +62,12 @@
#include "program/prog_instruction.h"
#include <limits>
+#define f(x) join(x)
+#define join(x) x ## f
+#define M_PIf f(M_PI)
+#define M_PI_2f f(M_PI_2)
+#define M_PI_4f f(M_PI_4)
+
using namespace ir_builder;
/**
@@ -2538,11 +2544,11 @@ ir_expression *
builtin_builder::asin_expr(ir_variable *x)
{
return mul(sign(x),
- sub(imm(1.5707964f),
+ sub(imm(M_PI_2f),
mul(sqrt(sub(imm(1.0f), abs(x))),
- add(imm(1.5707964f),
+ add(imm(M_PI_2f),
mul(abs(x),
- add(imm(-0.21460183f),
+ add(imm(M_PI_4f - 1.0f),
mul(abs(x),
add(imm(0.086566724f),
mul(abs(x), imm(-0.03102955f))))))))));
@@ -2586,7 +2592,7 @@ builtin_builder::_acos(const glsl_type *type)
ir_variable *x = in_var(type, "x");
MAKE_SIG(type, always_available, 1, x);
- body.emit(ret(sub(imm(1.5707964f), asin_expr(x))));
+ body.emit(ret(sub(imm(M_PI_2f), asin_expr(x))));
return sig;
}
@@ -2623,13 +2629,13 @@ builtin_builder::_atan2(const glsl_type *type)
ir_if *inner_if = new(mem_ctx) ir_if(less(x, imm(0.0f)));
inner_if->then_instructions.push_tail(
if_tree(gequal(y, imm(0.0f)),
- assign(r, add(r, imm(3.141593f))),
- assign(r, sub(r, imm(3.141593f)))));
+ assign(r, add(r, imm(M_PIf))),
+ assign(r, sub(r, imm(M_PIf)))));
outer_then.emit(inner_if);
/* Else... */
outer_if->else_instructions.push_tail(
- assign(r, mul(sign(y), imm(1.5707965f))));
+ assign(r, mul(sign(y), imm(M_PI_2f))));
body.emit(outer_if);