Mesa (master): glsl: Implement uaddCarry() built-in for ARB_gpu_shader5.

Matt Turner mattst88 at kemper.freedesktop.org
Mon Oct 7 17:46:20 UTC 2013


Module: Mesa
Branch: master
Commit: 6c125973f31addf903921647e8244abccb944e1a
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=6c125973f31addf903921647e8244abccb944e1a

Author: Matt Turner <mattst88 at gmail.com>
Date:   Tue Sep 17 17:44:03 2013 -0700

glsl: Implement uaddCarry() built-in for ARB_gpu_shader5.

i965 implements this with a single (multiple destination) instruction,
ADDC. Emitting ADDC directly from uaddCarry() would be ideal, but our
optimization passes don't know how to copy with expressions with
side-effects.

Radeon has an ADDC_UINT instruction that only generates the carry
bit. I've chosen to go this route and implement uaddCarry() by doing the
addition and the carry operations separately.

Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>

---

 src/glsl/builtin_functions.cpp |   21 +++++++++++++++++++++
 1 files changed, 21 insertions(+), 0 deletions(-)

diff --git a/src/glsl/builtin_functions.cpp b/src/glsl/builtin_functions.cpp
index b645108..9465ee3 100644
--- a/src/glsl/builtin_functions.cpp
+++ b/src/glsl/builtin_functions.cpp
@@ -531,6 +531,7 @@ private:
    B1(fma)
    B2(ldexp)
    B2(frexp)
+   B1(uaddCarry)
 #undef B0
 #undef B1
 #undef B2
@@ -1947,6 +1948,12 @@ builtin_builder::create_builtins()
                 _frexp(glsl_type::vec3_type,  glsl_type::ivec3_type),
                 _frexp(glsl_type::vec4_type,  glsl_type::ivec4_type),
                 NULL);
+   add_function("uaddCarry",
+                _uaddCarry(glsl_type::uint_type),
+                _uaddCarry(glsl_type::uvec2_type),
+                _uaddCarry(glsl_type::uvec3_type),
+                _uaddCarry(glsl_type::uvec4_type),
+                NULL);
 #undef F
 #undef FI
 #undef FIU
@@ -3720,6 +3727,20 @@ builtin_builder::_frexp(const glsl_type *x_type, const glsl_type *exp_type)
 
    return sig;
 }
+
+ir_function_signature *
+builtin_builder::_uaddCarry(const glsl_type *type)
+{
+   ir_variable *x = in_var(type, "x");
+   ir_variable *y = in_var(type, "y");
+   ir_variable *carry = out_var(type, "carry");
+   MAKE_SIG(type, gpu_shader5, 3, x, y, carry);
+
+   body.emit(assign(carry, ir_builder::carry(x, y)));
+   body.emit(ret(add(x, y)));
+
+   return sig;
+}
 /** @} */
 
 /******************************************************************************/




More information about the mesa-commit mailing list