Add gentype1 in addition to gentype to complete gentypen

It would be useful if gentypen were extended to include gentype1 as an alternative to the scalar gentype. I found myself in need of the swizzle properties for scalar datatypes when trying to generalize kernels for all vector lengths–including scalars. For example,


__kernel void kernel(__global gentypen *x)
{
   // vector length is sizeof(*x) / sizeof((*x).s0)
    ...
}

The problem with the above code is that gentype doesn’t have .s0 in cl_platform.h. I propose adding something like the following:


typedef union
{
    cl_float  CL_ALIGNED(4) s[1];
#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ )
   __extension__ struct{ cl_float  x; };
   __extension__ struct{ cl_float  s0; };
   __extension__ struct{ cl_float  lo; };
   __extension__ struct{ cl_float  hi; };
#endif
#if defined( __CL_FLOAT1__) 
    __cl_float1     v1;
#endif
}cl_float1;

Maybe including the last “#if defined” isn’t correct; I’m not sure.

I fully agree with you, and this was actually discussed in the past: allowing scalars to be treated as 1-component vectors in general. I don’t remember why it was turned down… I will try asking again; there must be a reason.

Hi David,

If you found out more info on this topic could you share it and maybe the opposing argument?