[libclc] r188477 - Add rhadd builtin
Aaron Watry
awatry at gmail.com
Thu Aug 15 12:21:10 PDT 2013
Author: awatry
Date: Thu Aug 15 14:21:10 2013
New Revision: 188477
URL: http://llvm.org/viewvc/llvm-project?rev=188477&view=rev
Log:
Add rhadd builtin
rhadd = (x+y+1)>>1
Implemented as:
(x>>1) + (y>>1) + ((x&1)|(y&1))
This prevents us having to do assembly addition and overflow detection
Reviewed-by: Tom Stellard <thomas.stellard at amd.com>
Added:
libclc/trunk/generic/include/clc/integer/rhadd.h
libclc/trunk/generic/include/clc/integer/rhadd.inc
libclc/trunk/generic/lib/integer/rhadd.cl
libclc/trunk/generic/lib/integer/rhadd.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=188477&r1=188476&r2=188477&view=diff
==============================================================================
--- libclc/trunk/generic/include/clc/clc.h (original)
+++ libclc/trunk/generic/include/clc/clc.h Thu Aug 15 14:21:10 2013
@@ -68,6 +68,7 @@
#include <clc/integer/hadd.h>
#include <clc/integer/mad24.h>
#include <clc/integer/mul24.h>
+#include <clc/integer/rhadd.h>
#include <clc/integer/rotate.h>
#include <clc/integer/sub_sat.h>
#include <clc/integer/upsample.h>
Added: libclc/trunk/generic/include/clc/integer/rhadd.h
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/integer/rhadd.h?rev=188477&view=auto
==============================================================================
--- libclc/trunk/generic/include/clc/integer/rhadd.h (added)
+++ libclc/trunk/generic/include/clc/integer/rhadd.h Thu Aug 15 14:21:10 2013
@@ -0,0 +1,2 @@
+#define __CLC_BODY <clc/integer/rhadd.inc>
+#include <clc/integer/gentype.inc>
Added: libclc/trunk/generic/include/clc/integer/rhadd.inc
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/integer/rhadd.inc?rev=188477&view=auto
==============================================================================
--- libclc/trunk/generic/include/clc/integer/rhadd.inc (added)
+++ libclc/trunk/generic/include/clc/integer/rhadd.inc Thu Aug 15 14:21:10 2013
@@ -0,0 +1 @@
+_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE rhadd(__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=188477&r1=188476&r2=188477&view=diff
==============================================================================
--- libclc/trunk/generic/lib/SOURCES (original)
+++ libclc/trunk/generic/lib/SOURCES Thu Aug 15 14:21:10 2013
@@ -14,6 +14,7 @@ integer/clz_impl.ll
integer/hadd.cl
integer/mad24.cl
integer/mul24.cl
+integer/rhadd.cl
integer/rotate.cl
integer/sub_sat.cl
integer/sub_sat_if.ll
Added: libclc/trunk/generic/lib/integer/rhadd.cl
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/integer/rhadd.cl?rev=188477&view=auto
==============================================================================
--- libclc/trunk/generic/lib/integer/rhadd.cl (added)
+++ libclc/trunk/generic/lib/integer/rhadd.cl Thu Aug 15 14:21:10 2013
@@ -0,0 +1,4 @@
+#include <clc/clc.h>
+
+#define __CLC_BODY <rhadd.inc>
+#include <clc/integer/gentype.inc>
Added: libclc/trunk/generic/lib/integer/rhadd.inc
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/integer/rhadd.inc?rev=188477&view=auto
==============================================================================
--- libclc/trunk/generic/lib/integer/rhadd.inc (added)
+++ libclc/trunk/generic/lib/integer/rhadd.inc Thu Aug 15 14:21:10 2013
@@ -0,0 +1,6 @@
+//rhadd = (x+y+1)>>1
+//This can be simplified to x>>1 + y>>1 + (1 if either x or y have the 1s bit set)
+//This saves us having to do any checks for overflow in the addition sums
+_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE rhadd(__CLC_GENTYPE x, __CLC_GENTYPE y) {
+ return (x>>(__CLC_GENTYPE)1)+(y>>(__CLC_GENTYPE)1)+((x&(__CLC_GENTYPE)1)|(y&(__CLC_GENTYPE)1));
+}
More information about the cfe-commits
mailing list