Add rhadd builtin
authorAaron Watry <awatry@gmail.com>
Thu, 15 Aug 2013 19:21:10 +0000 (19:21 +0000)
committerAaron Watry <awatry@gmail.com>
Thu, 15 Aug 2013 19:21:10 +0000 (19:21 +0000)
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@amd.com>
llvm-svn: 188477

libclc/generic/include/clc/clc.h
libclc/generic/include/clc/integer/rhadd.h [new file with mode: 0644]
libclc/generic/include/clc/integer/rhadd.inc [new file with mode: 0644]
libclc/generic/lib/SOURCES
libclc/generic/lib/integer/rhadd.cl [new file with mode: 0644]
libclc/generic/lib/integer/rhadd.inc [new file with mode: 0644]

index 38f71dbdee0c5b8185069c917cbf7da566721b33..ae212eddef53ed1b997d9153b160f1d15a590bcc 100644 (file)
@@ -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>
diff --git a/libclc/generic/include/clc/integer/rhadd.h b/libclc/generic/include/clc/integer/rhadd.h
new file mode 100644 (file)
index 0000000..69b43fa
--- /dev/null
@@ -0,0 +1,2 @@
+#define __CLC_BODY <clc/integer/rhadd.inc>
+#include <clc/integer/gentype.inc>
diff --git a/libclc/generic/include/clc/integer/rhadd.inc b/libclc/generic/include/clc/integer/rhadd.inc
new file mode 100644 (file)
index 0000000..88ccaf0
--- /dev/null
@@ -0,0 +1 @@
+_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE rhadd(__CLC_GENTYPE x, __CLC_GENTYPE y);
index e936fbc6d94bd9d1b5e616d789344d6e5eb178ae..5a68d07a402ca928627032db5d320704dccd64d4 100644 (file)
@@ -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
diff --git a/libclc/generic/lib/integer/rhadd.cl b/libclc/generic/lib/integer/rhadd.cl
new file mode 100644 (file)
index 0000000..c985870
--- /dev/null
@@ -0,0 +1,4 @@
+#include <clc/clc.h>
+
+#define __CLC_BODY <rhadd.inc>
+#include <clc/integer/gentype.inc>
diff --git a/libclc/generic/lib/integer/rhadd.inc b/libclc/generic/lib/integer/rhadd.inc
new file mode 100644 (file)
index 0000000..3d60768
--- /dev/null
@@ -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));
+}