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

Anton Lokhmotov Anton.Lokhmotov at arm.com
Tue Jul 24 03:03:43 PDT 2012

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;
    /* 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.

Please review the updated patch.

Many thanks,

[1] http://lists.cs.uiuc.edu/pipermail/cfe-dev/2012-June/022001.html
[2] http://lists.cs.uiuc.edu/pipermail/cfe-dev/2012-June/022079.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: half_type.patch
Type: application/octet-stream
Size: 18452 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20120724/93f190d2/attachment.obj>

More information about the cfe-dev mailing list