[Libclc-dev] [PATCH 3/3] Implement mad24 and mul24 builtins
Aaron Watry
awatry at gmail.com
Sun Jun 30 07:18:05 PDT 2013
On Wed, Jun 26, 2013 at 5:59 PM, Tom Stellard <tom at stellard.net> wrote:
> From: Tom Stellard <thomas.stellard at amd.com>
>
> ---
> generic/include/clc/clc.h | 2 ++
> generic/include/clc/integer/mad24.h | 3 +++
> generic/include/clc/integer/mad24.inc | 1 +
> generic/include/clc/integer/mul24.h | 3 +++
> generic/include/clc/integer/mul24.inc | 1 +
> generic/lib/SOURCES | 2 ++
> generic/lib/integer/mad24.cl | 4 ++++
> generic/lib/integer/mad24.inc | 3 +++
> generic/lib/integer/mul24.cl | 4 ++++
> generic/lib/integer/mul24.inc | 11 +++++++++++
> 10 files changed, 34 insertions(+)
> create mode 100644 generic/include/clc/integer/mad24.h
> create mode 100644 generic/include/clc/integer/mad24.inc
> create mode 100644 generic/include/clc/integer/mul24.h
> create mode 100644 generic/include/clc/integer/mul24.inc
> create mode 100644 generic/lib/integer/mad24.cl
> create mode 100644 generic/lib/integer/mad24.inc
> create mode 100644 generic/lib/integer/mul24.cl
> create mode 100644 generic/lib/integer/mul24.inc
>
> diff --git a/generic/include/clc/clc.h b/generic/include/clc/clc.h
> index 10d30e0..ffa2a24 100644
> --- a/generic/include/clc/clc.h
> +++ b/generic/include/clc/clc.h
> @@ -64,6 +64,8 @@
> #include <clc/integer/abs_diff.h>
> #include <clc/integer/add_sat.h>
> #include <clc/integer/clz.h>
> +#include <clc/integer/mad24.h>
> +#include <clc/integer/mul24.h>
> #include <clc/integer/rotate.h>
> #include <clc/integer/sub_sat.h>
>
> diff --git a/generic/include/clc/integer/mad24.h b/generic/include/clc/integer/mad24.h
> new file mode 100644
> index 0000000..0c120fa
> --- /dev/null
> +++ b/generic/include/clc/integer/mad24.h
> @@ -0,0 +1,3 @@
> +#define __CLC_BODY <clc/integer/mad24.inc>
> +#include <clc/integer/integer-gentype.inc>
> +#undef __CLC_BODY
> diff --git a/generic/include/clc/integer/mad24.inc b/generic/include/clc/integer/mad24.inc
> new file mode 100644
> index 0000000..81fe0c2
> --- /dev/null
> +++ b/generic/include/clc/integer/mad24.inc
> @@ -0,0 +1 @@
> +_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE mad24(__CLC_GENTYPE x, __CLC_GENTYPE y, __CLC_GENTYPE z);
> diff --git a/generic/include/clc/integer/mul24.h b/generic/include/clc/integer/mul24.h
> new file mode 100644
> index 0000000..4f97098
> --- /dev/null
> +++ b/generic/include/clc/integer/mul24.h
> @@ -0,0 +1,3 @@
> +#define __CLC_BODY <clc/integer/mul24.inc>
> +#include <clc/integer/integer-gentype.inc>
> +#undef __CLC_BODY
> diff --git a/generic/include/clc/integer/mul24.inc b/generic/include/clc/integer/mul24.inc
> new file mode 100644
> index 0000000..8cbf7c1
> --- /dev/null
> +++ b/generic/include/clc/integer/mul24.inc
> @@ -0,0 +1 @@
> +_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE mul24(__CLC_GENTYPE x, __CLC_GENTYPE y);
> diff --git a/generic/lib/SOURCES b/generic/lib/SOURCES
> index 8cda14a..c2da3d7 100644
> --- a/generic/lib/SOURCES
> +++ b/generic/lib/SOURCES
> @@ -11,6 +11,8 @@ integer/add_sat_impl.ll
> integer/clz.cl
> integer/clz_if.ll
> integer/clz_impl.ll
> +integer/mad24.cl
> +integer/mul24.cl
> integer/rotate.cl
> integer/sub_sat.cl
> integer/sub_sat_if.ll
> diff --git a/generic/lib/integer/mad24.cl b/generic/lib/integer/mad24.cl
> new file mode 100644
> index 0000000..e29e99f
> --- /dev/null
> +++ b/generic/lib/integer/mad24.cl
> @@ -0,0 +1,4 @@
> +#include <clc/clc.h>
> +
> +#define __CLC_BODY <mad24.inc>
> +#include <clc/integer/integer-gentype.inc>
> diff --git a/generic/lib/integer/mad24.inc b/generic/lib/integer/mad24.inc
> new file mode 100644
> index 0000000..902b0aa
> --- /dev/null
> +++ b/generic/lib/integer/mad24.inc
> @@ -0,0 +1,3 @@
> +_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE mad24(__CLC_GENTYPE x, __CLC_GENTYPE y, __CLC_GENTYPE z){
> + return mul24(x, y) + z;
> +}
> diff --git a/generic/lib/integer/mul24.cl b/generic/lib/integer/mul24.cl
> new file mode 100644
> index 0000000..8aedca6
> --- /dev/null
> +++ b/generic/lib/integer/mul24.cl
> @@ -0,0 +1,4 @@
> +#include <clc/clc.h>
> +
> +#define __CLC_BODY <mul24.inc>
> +#include <clc/integer/integer-gentype.inc>
> diff --git a/generic/lib/integer/mul24.inc b/generic/lib/integer/mul24.inc
> new file mode 100644
> index 0000000..c669029
> --- /dev/null
> +++ b/generic/lib/integer/mul24.inc
> @@ -0,0 +1,11 @@
> +
> +// We need to use shifts here in order to mantain the sign bit for signed
> +// integers. The compiler should optimize this to (x & 0x00FFFFFF) for
> +// unsgined integers.
s/unsgined/unsigned/
With that fixed:
Reviewed-by: Aaron Watry <awatry at gmail.com>
> +#define CONVERT_TO_24BIT(x) (((x) << 8) >> 8)
> +
> +_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE mul24(__CLC_GENTYPE x, __CLC_GENTYPE y){
> + return CONVERT_TO_24BIT(x) * CONVERT_TO_24BIT(y);
> +}
> +
> +#undef CONVERT_TO_24BIT
> --
> 1.7.11.4
>
>
> _______________________________________________
> 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