[Mesa-dev] [RFC 01/11] glsl: Add "built-in" function to do abs(fp64)
Elie Tournier
tournier.elie at gmail.com
Fri Mar 3 16:22:57 UTC 2017
Signed-off-by: Elie Tournier <elie.tournier at collabora.com>
---
src/compiler/Makefile.sources | 1 +
src/compiler/glsl/builtin_float64.h | 19 +++++++++++++++++++
src/compiler/glsl/builtin_functions.cpp | 4 ++++
src/compiler/glsl/builtin_functions.h | 3 +++
src/compiler/glsl/float64.glsl | 28 ++++++++++++++++++++++++++++
src/compiler/glsl/generate_ir.cpp | 1 +
6 files changed, 56 insertions(+)
create mode 100644 src/compiler/glsl/builtin_float64.h
create mode 100644 src/compiler/glsl/float64.glsl
diff --git a/src/compiler/Makefile.sources b/src/compiler/Makefile.sources
index 643a0181d8..b67834246f 100644
--- a/src/compiler/Makefile.sources
+++ b/src/compiler/Makefile.sources
@@ -22,6 +22,7 @@ LIBGLSL_FILES = \
glsl/builtin_functions.cpp \
glsl/builtin_functions.h \
glsl/builtin_int64.h \
+ glsl/builtin_float64.h \
glsl/builtin_types.cpp \
glsl/builtin_variables.cpp \
glsl/generate_ir.cpp \
diff --git a/src/compiler/glsl/builtin_float64.h b/src/compiler/glsl/builtin_float64.h
new file mode 100644
index 0000000000..c1ec89d210
--- /dev/null
+++ b/src/compiler/glsl/builtin_float64.h
@@ -0,0 +1,19 @@
+ir_function_signature *
+fabs64(void *mem_ctx, builtin_available_predicate avail)
+{
+ ir_function_signature *const sig =
+ new(mem_ctx) ir_function_signature(glsl_type::uvec2_type, avail);
+ ir_factory body(&sig->body, mem_ctx);
+ sig->is_defined = true;
+
+ exec_list sig_parameters;
+
+ ir_variable *const r000B = new(mem_ctx) ir_variable(glsl_type::uvec2_type, "a", ir_var_function_in);
+ sig_parameters.push_tail(r000B);
+ body.emit(assign(r000B, bit_and(swizzle_x(r000B), body.constant(2147483647u)), 0x01));
+
+ body.emit(ret(r000B));
+
+ sig->replace_parameters(&sig_parameters);
+ return sig;
+}
diff --git a/src/compiler/glsl/builtin_functions.cpp b/src/compiler/glsl/builtin_functions.cpp
index e03a50c843..b0b1781725 100644
--- a/src/compiler/glsl/builtin_functions.cpp
+++ b/src/compiler/glsl/builtin_functions.cpp
@@ -3129,6 +3129,10 @@ builtin_builder::create_builtins()
generate_ir::umul64(mem_ctx, integer_functions_supported),
NULL);
+ add_function("__builtin_fabs64",
+ generate_ir::fabs64(mem_ctx, integer_functions_supported),
+ NULL);
+
#undef F
#undef FI
#undef FIUD_VEC
diff --git a/src/compiler/glsl/builtin_functions.h b/src/compiler/glsl/builtin_functions.h
index 7ae211b48a..abe02d97b6 100644
--- a/src/compiler/glsl/builtin_functions.h
+++ b/src/compiler/glsl/builtin_functions.h
@@ -63,6 +63,9 @@ umul64(void *mem_ctx, builtin_available_predicate avail);
ir_function_signature *
sign64(void *mem_ctx, builtin_available_predicate avail);
+ir_function_signature *
+fabs64(void *mem_ctx, builtin_available_predicate avail);
+
}
#endif /* BULITIN_FUNCTIONS_H */
diff --git a/src/compiler/glsl/float64.glsl b/src/compiler/glsl/float64.glsl
new file mode 100644
index 0000000000..b8f0c2e444
--- /dev/null
+++ b/src/compiler/glsl/float64.glsl
@@ -0,0 +1,28 @@
+/* Compile with:
+ *
+ * glsl_compiler --version 130 --dump-builder float64.glsl > builtin_float64.h
+ *
+ */
+
+#version 130
+
+/* Software IEEE floating-point rounding mode.
+ * GLSL spec section "4.7.1 Range and Precision":
+ * The rounding mode cannot be set and is undefined.
+ * But here, we are able to define the rounding mode at the compilation time.
+ */
+#define FLOAT_ROUND_NEAREST_EVEN 0
+#define FLOAT_ROUND_TO_ZERO 1
+#define FLOAT_ROUND_DOWN 2
+#define FLOAT_ROUND_UP 3
+#define FLOAT_ROUNDING_MODE FLOAT_ROUND_NEAREST_EVEN
+
+/* Absolute value of a Float64 :
+ * Clear the sign bit
+ */
+uvec2
+fabs64( uvec2 a )
+{
+ a.x &= 0x7FFFFFFFu;
+ return a;
+}
diff --git a/src/compiler/glsl/generate_ir.cpp b/src/compiler/glsl/generate_ir.cpp
index 255b0484f2..e6ece4860f 100644
--- a/src/compiler/glsl/generate_ir.cpp
+++ b/src/compiler/glsl/generate_ir.cpp
@@ -29,5 +29,6 @@ using namespace ir_builder;
namespace generate_ir {
#include "builtin_int64.h"
+#include "builtin_float64.h"
}
--
2.11.0
More information about the mesa-dev
mailing list