[Libclc-dev] [PATCH 4/6] select: add vector implementation

Jan Vesely via Libclc-dev libclc-dev at lists.llvm.org
Fri Mar 16 11:22:20 PDT 2018


On Thu, 2018-03-15 at 22:20 +0100, Jeroen Ketema via Libclc-dev wrote:
> Hi Jan,
> 
> Sorry for being a bit late with this. Why was this change to select
> needed? The ternary operator should behave like select in the case of
> vectors and is implemented in Clang as such.

Ah, right. The specs explicitly states that vector ?: is equivalent to
select. Even if it's counter-intuitive (both in terms of truth
evaluation, and the fact that it evaluates both expressions).
I'd still prefer to have a function rather than macro, but the #else
path definitely redundant.

thanks,
Jan

> 
> Jeroen
> 
> > On 28 Feb 2018, at 20:50, Jan Vesely via Libclc-dev <libclc-dev at lists.llvm.org> wrote:
> > 
> > Passes CTS on Carrizo
> > 
> > Signed-off-by: Jan Vesely <jan.vesely at rutgers.edu>
> > ---
> > generic/include/clc/relational/select.h   | 12 +++++++-
> > generic/include/clc/relational/select.inc | 25 ++++++++++++++++
> > generic/lib/SOURCES                       |  1 +
> > generic/lib/relational/select.cl          |  7 +++++
> > generic/lib/relational/select.inc         | 47 +++++++++++++++++++++++++++++++
> > 5 files changed, 91 insertions(+), 1 deletion(-)
> > create mode 100644 generic/include/clc/relational/select.inc
> > create mode 100644 generic/lib/relational/select.cl
> > create mode 100644 generic/lib/relational/select.inc
> > 
> > diff --git a/generic/include/clc/relational/select.h b/generic/include/clc/relational/select.h
> > index 33a6909..d20deae 100644
> > --- a/generic/include/clc/relational/select.h
> > +++ b/generic/include/clc/relational/select.h
> > @@ -1 +1,11 @@
> > -#define select(a, b, c) ((c) ? (b) : (a))
> > +/* Duplciate these so we don't have to distribute utils.h */
> > +#define __CLC_CONCAT(x, y) x ## y
> > +#define __CLC_XCONCAT(x, y) __CLC_CONCAT(x, y)
> > +
> > +#define __CLC_BODY <clc/relational/select.inc>
> > +#include <clc/math/gentype.inc>
> > +#define __CLC_BODY <clc/relational/select.inc>
> > +#include <clc/integer/gentype.inc>
> > +
> > +#undef __CLC_CONCAT
> > +#undef __CLC_XCONCAT
> > diff --git a/generic/include/clc/relational/select.inc b/generic/include/clc/relational/select.inc
> > new file mode 100644
> > index 0000000..2911009
> > --- /dev/null
> > +++ b/generic/include/clc/relational/select.inc
> > @@ -0,0 +1,25 @@
> > +#ifdef __CLC_SCALAR
> > +#define __CLC_VECSIZE
> > +#endif
> > +
> > +#if __CLC_FPSIZE == 64
> > +#define __CLC_S_GENTYPE __CLC_XCONCAT(long, __CLC_VECSIZE) 
> > +#define __CLC_U_GENTYPE __CLC_XCONCAT(ulong, __CLC_VECSIZE) 
> > +#elif __CLC_FPSIZE == 32
> > +#define __CLC_S_GENTYPE __CLC_XCONCAT(int, __CLC_VECSIZE) 
> > +#define __CLC_U_GENTYPE __CLC_XCONCAT(uint, __CLC_VECSIZE) 
> > +#elif __CLC_FPSIZE == 16
> > +#define __CLC_S_GENTYPE __CLC_XCONCAT(char, __CLC_VECSIZE) 
> > +#define __CLC_U_GENTYPE __CLC_XCONCAT(uchar, __CLC_VECSIZE) 
> > +#endif
> > +
> > +_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE select(__CLC_GENTYPE x, __CLC_GENTYPE y, __CLC_S_GENTYPE z);
> > +_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE select(__CLC_GENTYPE x, __CLC_GENTYPE y, __CLC_U_GENTYPE z);
> > +
> > +#ifdef __CLC_FPSIZE
> > +#undef __CLC_S_GENTYPE
> > +#undef __CLC_U_GENTYPE
> > +#endif
> > +#ifdef __CLC_SCALAR
> > +#undef __CLC_VECSIZE
> > +#endif
> > diff --git a/generic/lib/SOURCES b/generic/lib/SOURCES
> > index 13fe4fa..f9104a3 100644
> > --- a/generic/lib/SOURCES
> > +++ b/generic/lib/SOURCES
> > @@ -189,6 +189,7 @@ relational/isnormal.cl
> > relational/isnotequal.cl
> > relational/isordered.cl
> > relational/isunordered.cl
> > +relational/select.cl
> > relational/signbit.cl
> > shared/clamp.cl
> > shared/max.cl
> > diff --git a/generic/lib/relational/select.cl b/generic/lib/relational/select.cl
> > new file mode 100644
> > index 0000000..dc2e273
> > --- /dev/null
> > +++ b/generic/lib/relational/select.cl
> > @@ -0,0 +1,7 @@
> > +#include <clc/clc.h>
> > +#include <utils.h>
> > +
> > +#define __CLC_BODY <select.inc>
> > +#include <clc/math/gentype.inc>
> > +#define __CLC_BODY <select.inc>
> > +#include <clc/integer/gentype.inc>
> > diff --git a/generic/lib/relational/select.inc b/generic/lib/relational/select.inc
> > new file mode 100644
> > index 0000000..b990d26
> > --- /dev/null
> > +++ b/generic/lib/relational/select.inc
> > @@ -0,0 +1,47 @@
> > +#ifdef __CLC_SCALAR
> > +#define __CLC_VECSIZE
> > +#endif
> > +
> > +#if __CLC_FPSIZE == 64
> > +#define __CLC_S_GENTYPE __CLC_XCONCAT(long, __CLC_VECSIZE) 
> > +#define __CLC_U_GENTYPE __CLC_XCONCAT(ulong, __CLC_VECSIZE) 
> > +#elif __CLC_FPSIZE == 32
> > +#define __CLC_S_GENTYPE __CLC_XCONCAT(int, __CLC_VECSIZE) 
> > +#define __CLC_U_GENTYPE __CLC_XCONCAT(uint, __CLC_VECSIZE) 
> > +#elif __CLC_FPSIZE == 16
> > +#define __CLC_S_GENTYPE __CLC_XCONCAT(char, __CLC_VECSIZE) 
> > +#define __CLC_U_GENTYPE __CLC_XCONCAT(uchar, __CLC_VECSIZE) 
> > +#endif
> > +#ifdef __CLC_FPSIZE
> > +#define __CLC_GENSIZE   __CLC_FPSIZE
> > +#endif
> > +
> > +#define __CLC_AS_S_GENTYPE __CLC_XCONCAT(as_, __CLC_S_GENTYPE)
> > +#define __CLC_AS_GENTYPE __CLC_XCONCAT(as_, __CLC_GENTYPE)
> > +
> > +_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE select(__CLC_GENTYPE x, __CLC_GENTYPE y, __CLC_S_GENTYPE z)
> > +{
> > +#ifdef __CLC_SCALAR
> > +	return z ? y : x;
> > +#else
> > +	__CLC_S_GENTYPE bitmask = z >> (__CLC_GENSIZE - 1);
> > +	return __CLC_AS_GENTYPE(bitselect(__CLC_AS_S_GENTYPE(x), __CLC_AS_S_GENTYPE(y), bitmask));
> > +#endif
> > +}
> > +
> > +_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE select(__CLC_GENTYPE x, __CLC_GENTYPE y, __CLC_U_GENTYPE z)
> > +{
> > +	return select(x, y, __CLC_AS_S_GENTYPE(z));
> > +}
> > +
> > +#undef __CLC_AS_S_GENTYPE
> > +#undef __CLC_AS_GENTYPE
> > +
> > +#ifdef __CLC_FPSIZE
> > +#undef __CLC_S_GENTYPE
> > +#undef __CLC_U_GENTYPE
> > +#undef __CLC_GENSIZE
> > +#endif
> > +#ifdef __CLC_SCALAR
> > +#undef __CLC_VECSIZE
> > +#endif
> > -- 
> > 2.14.3
> > 
> > _______________________________________________
> > Libclc-dev mailing list
> > Libclc-dev at lists.llvm.org
> > http://lists.llvm.org/cgi-bin/mailman/listinfo/libclc-dev
> 
> _______________________________________________
> Libclc-dev mailing list
> Libclc-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/libclc-dev

-- 
Jan Vesely <jan.vesely at rutgers.edu>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part
URL: <http://lists.llvm.org/pipermail/libclc-dev/attachments/20180316/59b8e8ac/attachment.sig>


More information about the Libclc-dev mailing list