diff options
| author | Aaron Watry <awatry@gmail.com> | 2013-08-15 19:21:07 +0000 |
|---|---|---|
| committer | Aaron Watry <awatry@gmail.com> | 2013-08-15 19:21:07 +0000 |
| commit | 7659157f1b926321530a44ce8fc7a39a0360a08e (patch) | |
| tree | 11938d2dda1c9b05ea82dfa1add830f6d0d83e94 /libclc/generic/lib/integer | |
| parent | d18fcc7a227f299f6451e2f630e8a83524ac57b2 (diff) | |
| download | bcm5719-llvm-7659157f1b926321530a44ce8fc7a39a0360a08e.tar.gz bcm5719-llvm-7659157f1b926321530a44ce8fc7a39a0360a08e.zip | |
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@amd.com>
llvm-svn: 188476
Diffstat (limited to 'libclc/generic/lib/integer')
| -rw-r--r-- | libclc/generic/lib/integer/hadd.cl | 4 | ||||
| -rw-r--r-- | libclc/generic/lib/integer/hadd.inc | 6 |
2 files changed, 10 insertions, 0 deletions
diff --git a/libclc/generic/lib/integer/hadd.cl b/libclc/generic/lib/integer/hadd.cl new file mode 100644 index 00000000000..749026e5a8a --- /dev/null +++ b/libclc/generic/lib/integer/hadd.cl @@ -0,0 +1,4 @@ +#include <clc/clc.h> + +#define __CLC_BODY <hadd.inc> +#include <clc/integer/gentype.inc> diff --git a/libclc/generic/lib/integer/hadd.inc b/libclc/generic/lib/integer/hadd.inc new file mode 100644 index 00000000000..ea59d9bd7db --- /dev/null +++ b/libclc/generic/lib/integer/hadd.inc @@ -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); +} |

