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

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


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

Author: Matt Turner <mattst88 at gmail.com>
Date:   Tue Sep 17 18:02:05 2013 -0700

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

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

Radeon has an SUBB_UINT instruction that only generates the borrow
bit. I've chosen to go this route and implement usubBorrow() by doing the
subtraction and the borrow 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 9465ee3..5b1b9c3 100644
--- a/src/glsl/builtin_functions.cpp
+++ b/src/glsl/builtin_functions.cpp
@@ -532,6 +532,7 @@ private:
    B2(ldexp)
    B2(frexp)
    B1(uaddCarry)
+   B1(usubBorrow)
 #undef B0
 #undef B1
 #undef B2
@@ -1954,6 +1955,12 @@ builtin_builder::create_builtins()
                 _uaddCarry(glsl_type::uvec3_type),
                 _uaddCarry(glsl_type::uvec4_type),
                 NULL);
+   add_function("usubBorrow",
+                _usubBorrow(glsl_type::uint_type),
+                _usubBorrow(glsl_type::uvec2_type),
+                _usubBorrow(glsl_type::uvec3_type),
+                _usubBorrow(glsl_type::uvec4_type),
+                NULL);
 #undef F
 #undef FI
 #undef FIU
@@ -3741,6 +3748,20 @@ builtin_builder::_uaddCarry(const glsl_type *type)
 
    return sig;
 }
+
+ir_function_signature *
+builtin_builder::_usubBorrow(const glsl_type *type)
+{
+   ir_variable *x = in_var(type, "x");
+   ir_variable *y = in_var(type, "y");
+   ir_variable *borrow = out_var(type, "borrow");
+   MAKE_SIG(type, gpu_shader5, 3, x, y, borrow);
+
+   body.emit(assign(borrow, ir_builder::borrow(x, y)));
+   body.emit(ret(sub(x, y)));
+
+   return sig;
+}
 /** @} */
 
 /******************************************************************************/




More information about the mesa-commit mailing list