[cfe-dev] [OpenCL patch] Half type as native when OpenCL's cl_khr_fp16 extension is enabled

Douglas Gregor dgregor at apple.com
Tue Jul 31 11:24:40 PDT 2012


On Jul 24, 2012, at 3:03 AM, Anton Lokhmotov <Anton.Lokhmotov at arm.com> wrote:

> Hi John,
> 
>> It looks like we have four possibilities. Is this right?
>> 1. half is completely unsupported (C, C++ default)
>> 2. half is storage-only, support half* but no operations on half
>> (OpenCL without cl_khr_fp16)
>> 3. half is storage-only, operations on half automatically promoted to
>> float (__fp16 NEON)
>> 4. half is completely supported (OpenCL with cl_khr_fp16)
>> 
>> HalfTypeNative (or PromoteHalfToFloat) would differentiate between the
>> last two cases in CodeGen; the first two cases are irrelevant in
>> CodeGen because in those cases it should be impossible to pass a half
>> type to EmitScalarConversion.
> 
> I agree.
> 
> We found a problem with our solution addressing your previous comment [1].
> One of the OpenCL conformance tests attempts to do something like this:
> 
> __global half * buffer;
> size_t index;
> ...
> vstore_half(
>    /* float data = */ 1.0f,
>    /* size_t offset = */ 0,
>    /* __global half *p = */ &buffer[index]
> );
> 
> Disallowing 'buffer[index]' as in [2] results in:
> error: dereferencing half pointer ('half *') is not allowed.
> 
> While the conformance tests are not sacred, it can be argued that the
> composition of '&' and '[]' should result in half*, so should not be
> rejected.  Unfortunately, we found no obvious way to implement this in
> Clang, so leave this case as TODO.


One way to handle the "storage-only" version is for buffer[index] to produce a non-modifiable lvalue (so you can't write it) and to ban the lvalue-to-rvalue conversion for such a value (for the latter, see Sema::DefaultLValueConversion).

	- Doug



More information about the cfe-dev mailing list