[cfe-commits] RFC: Half floating point support

Anton Korobeynikov anton at korobeynikov.info
Tue Oct 4 14:08:38 PDT 2011

Hello Everyone

Attached is a preliminary patch for storage-only half floating point
support in clang. Basically, lack of such support is a regression now,
because llvm-gcc supported it.

The key idea of the patch is the following: when building AST for new
'half' type implicit conversion to float is performed (the opposite
conversion thus will be done automatically). Such a conversion,
fortunately, should be done only in few places:

1. During lvalue-to-rvalue conversion
2. During building initializer sequence
3. For some unary ops where no lvalue-to-rvalue conversion is
performed (e.g. ++foo).

Later these promotions can be turned off depending on whether the
target wants half fp to be native or storage only type.

During the codegen I just turn such float<->half conversion into
appropriate intrinsic calls plus some other minor stuff for

What is missed in the patch:

1. Sema checks.
2. Testsuite (I have extensive one, but I don't have for sema checks)
3. (Maybe) Some C++ bits.... Most probably RTTI?

So, I just wanted thoughts and comments on this patch.

Answering the very first question: why this is not done entirely in
codegen phase? Answer is pretty simple: there are a lot of EmitFoo()
methods, so I'd need to modify all of them and this looked pretty
fragile and inconvenient. Also, I thought it's pretty important to
have everything in AST (implicit conversions to float) instead of
codegen phase magic.

With best regards, Anton Korobeynikov
Faculty of Mathematics and Mechanics, Saint Petersburg State University
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fp16.diff
Type: application/octet-stream
Size: 30021 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20111005/ecf13216/attachment.obj>

More information about the cfe-commits mailing list