[libclc] r188476 - Add hadd builtin

Aaron Watry awatry at gmail.com
Thu Aug 15 12:21:07 PDT 2013


Author: awatry
Date: Thu Aug 15 14:21:07 2013
New Revision: 188476

URL: http://llvm.org/viewvc/llvm-project?rev=188476&view=rev
Log:
Add hadd builtin

(x + y) >> 1 gets changed to:
(x>>1) + (y>>1) + (x&y&1)

Saves us having to do any llvm assembly and overflow checking in the addition.

Reviewed-by: Tom Stellard <thomas.stellard at amd.com>

Added:
    libclc/trunk/generic/include/clc/integer/hadd.h
    libclc/trunk/generic/include/clc/integer/hadd.inc
    libclc/trunk/generic/lib/integer/hadd.cl
    libclc/trunk/generic/lib/integer/hadd.inc
Modified:
    libclc/trunk/generic/include/clc/clc.h
    libclc/trunk/generic/lib/SOURCES

Modified: libclc/trunk/generic/include/clc/clc.h
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/clc.h?rev=188476&r1=188475&r2=188476&view=diff
==============================================================================
--- libclc/trunk/generic/include/clc/clc.h (original)
+++ libclc/trunk/generic/include/clc/clc.h Thu Aug 15 14:21:07 2013
@@ -65,6 +65,7 @@
 #include <clc/integer/abs_diff.h>
 #include <clc/integer/add_sat.h>
 #include <clc/integer/clz.h>
+#include <clc/integer/hadd.h>
 #include <clc/integer/mad24.h>
 #include <clc/integer/mul24.h>
 #include <clc/integer/rotate.h>

Added: libclc/trunk/generic/include/clc/integer/hadd.h
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/integer/hadd.h?rev=188476&view=auto
==============================================================================
--- libclc/trunk/generic/include/clc/integer/hadd.h (added)
+++ libclc/trunk/generic/include/clc/integer/hadd.h Thu Aug 15 14:21:07 2013
@@ -0,0 +1,2 @@
+#define __CLC_BODY <clc/integer/hadd.inc>
+#include <clc/integer/gentype.inc>

Added: libclc/trunk/generic/include/clc/integer/hadd.inc
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/integer/hadd.inc?rev=188476&view=auto
==============================================================================
--- libclc/trunk/generic/include/clc/integer/hadd.inc (added)
+++ libclc/trunk/generic/include/clc/integer/hadd.inc Thu Aug 15 14:21:07 2013
@@ -0,0 +1 @@
+_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE hadd(__CLC_GENTYPE x, __CLC_GENTYPE y);

Modified: libclc/trunk/generic/lib/SOURCES
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/SOURCES?rev=188476&r1=188475&r2=188476&view=diff
==============================================================================
--- libclc/trunk/generic/lib/SOURCES (original)
+++ libclc/trunk/generic/lib/SOURCES Thu Aug 15 14:21:07 2013
@@ -11,6 +11,7 @@ integer/add_sat_impl.ll
 integer/clz.cl
 integer/clz_if.ll
 integer/clz_impl.ll
+integer/hadd.cl
 integer/mad24.cl
 integer/mul24.cl
 integer/rotate.cl

Added: libclc/trunk/generic/lib/integer/hadd.cl
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/integer/hadd.cl?rev=188476&view=auto
==============================================================================
--- libclc/trunk/generic/lib/integer/hadd.cl (added)
+++ libclc/trunk/generic/lib/integer/hadd.cl Thu Aug 15 14:21:07 2013
@@ -0,0 +1,4 @@
+#include <clc/clc.h>
+
+#define __CLC_BODY <hadd.inc>
+#include <clc/integer/gentype.inc>

Added: libclc/trunk/generic/lib/integer/hadd.inc
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/integer/hadd.inc?rev=188476&view=auto
==============================================================================
--- libclc/trunk/generic/lib/integer/hadd.inc (added)
+++ libclc/trunk/generic/lib/integer/hadd.inc Thu Aug 15 14:21:07 2013
@@ -0,0 +1,6 @@
+//hadd = (x+y)>>1
+//This can be simplified to x>>1 + y>>1 + (1 if both x and y have the 1s bit set)
+//This saves us having to do any checks for overflow in the addition sum
+_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE hadd(__CLC_GENTYPE x, __CLC_GENTYPE y) {
+    return (x>>(__CLC_GENTYPE)1)+(y>>(__CLC_GENTYPE)1)+(x&y&(__CLC_GENTYPE)1);
+}





More information about the cfe-commits mailing list