[Libclc-dev] [PATCH 2/2] Add rhadd builtin
Tom Stellard
tom at stellard.net
Wed Aug 14 15:08:41 PDT 2013
On Wed, Aug 14, 2013 at 11:38:18AM -0500, Aaron Watry wrote:
> 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>
> ---
> generic/include/clc/clc.h | 1 +
> generic/include/clc/integer/rhadd.h | 2 ++
> generic/include/clc/integer/rhadd.inc | 1 +
> generic/lib/SOURCES | 1 +
> generic/lib/integer/rhadd.cl | 4 ++++
> generic/lib/integer/rhadd.inc | 6 ++++++
> 6 files changed, 15 insertions(+)
> create mode 100644 generic/include/clc/integer/rhadd.h
> create mode 100644 generic/include/clc/integer/rhadd.inc
> create mode 100644 generic/lib/integer/rhadd.cl
> create mode 100644 generic/lib/integer/rhadd.inc
>
> diff --git a/generic/include/clc/clc.h b/generic/include/clc/clc.h
> index f9b2c38..305f058 100644
> --- a/generic/include/clc/clc.h
> +++ b/generic/include/clc/clc.h
> @@ -69,6 +69,7 @@
> #include <clc/integer/mad24.h>
> #include <clc/integer/mul24.h>
> #include <clc/integer/mul_hi.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/generic/include/clc/integer/rhadd.h b/generic/include/clc/integer/rhadd.h
> new file mode 100644
> index 0000000..69b43fa
> --- /dev/null
> +++ b/generic/include/clc/integer/rhadd.h
> @@ -0,0 +1,2 @@
> +#define __CLC_BODY <clc/integer/rhadd.inc>
> +#include <clc/integer/gentype.inc>
> diff --git a/generic/include/clc/integer/rhadd.inc b/generic/include/clc/integer/rhadd.inc
> new file mode 100644
> index 0000000..88ccaf0
> --- /dev/null
> +++ b/generic/include/clc/integer/rhadd.inc
> @@ -0,0 +1 @@
> +_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE rhadd(__CLC_GENTYPE x, __CLC_GENTYPE y);
> diff --git a/generic/lib/SOURCES b/generic/lib/SOURCES
> index 0e66d71..d6e2d8c 100644
> --- a/generic/lib/SOURCES
> +++ b/generic/lib/SOURCES
> @@ -15,6 +15,7 @@ integer/hadd.cl
> integer/mad24.cl
> integer/mul24.cl
> integer/mul_hi.cl
> +integer/rhadd.cl
> integer/rotate.cl
> integer/sub_sat.cl
> integer/sub_sat_if.ll
> diff --git a/generic/lib/integer/rhadd.cl b/generic/lib/integer/rhadd.cl
> new file mode 100644
> index 0000000..c985870
> --- /dev/null
> +++ b/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/generic/lib/integer/rhadd.inc b/generic/lib/integer/rhadd.inc
> new file mode 100644
> index 0000000..3d60768
> --- /dev/null
> +++ b/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));
> +}
> --
> 1.8.1.2
>
>
> _______________________________________________
> Libclc-dev mailing list
> Libclc-dev at pcc.me.uk
> http://www.pcc.me.uk/cgi-bin/mailman/listinfo/libclc-dev
More information about the Libclc-dev
mailing list