diff options
| author | Aaron Watry <awatry@gmail.com> | 2013-08-15 19:21:10 +0000 |
|---|---|---|
| committer | Aaron Watry <awatry@gmail.com> | 2013-08-15 19:21:10 +0000 |
| commit | 8548725f290ddae3feef2a15fc672010087c939b (patch) | |
| tree | 95383b79784807889e58b6e3e453faafd9ab07ff /libclc/generic/lib/integer | |
| parent | 7659157f1b926321530a44ce8fc7a39a0360a08e (diff) | |
| download | bcm5719-llvm-8548725f290ddae3feef2a15fc672010087c939b.tar.gz bcm5719-llvm-8548725f290ddae3feef2a15fc672010087c939b.zip | |
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@amd.com>
llvm-svn: 188477
Diffstat (limited to 'libclc/generic/lib/integer')
| -rw-r--r-- | libclc/generic/lib/integer/rhadd.cl | 4 | ||||
| -rw-r--r-- | libclc/generic/lib/integer/rhadd.inc | 6 |
2 files changed, 10 insertions, 0 deletions
diff --git a/libclc/generic/lib/integer/rhadd.cl b/libclc/generic/lib/integer/rhadd.cl new file mode 100644 index 00000000000..c985870f7c7 --- /dev/null +++ b/libclc/generic/lib/integer/rhadd.cl @@ -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 index 00000000000..3d607687480 --- /dev/null +++ b/libclc/generic/lib/integer/rhadd.inc @@ -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)); +} |

