This is an archive of the discontinued LLVM Phabricator instance.

Adding type info for f16c floating-point type
ClosedPublic

Authored by ygao on Feb 11 2014, 8:30 PM.

Details

Summary

Hi,
The following patch adds support for half-precision floating point type supported by the clang front-end.
Native operations on this type is supported by OpenCL and to a limited extent by f16c (conversions are
supported); otherwise it is a storage-only type.
Could someone take a look whether this is good to go in?

  • Gao.

Diff Detail

Event Timeline

ygao added a comment.Mar 6 2014, 12:27 PM

Ping.

At least for x86-64, the half-precision floating-point type is mentioned in the ia64-abi in 2.9.2 Place of Emission:
Specifically, the run-time support library should contain type_info objects for the types X, X* and X const*, for every X in: void, std::nullptr_t, bool, wchar_t, char, unsigned char, signed char, short, unsigned short, int, unsigned int, long, unsigned long, long long, unsigned long long, float, double, long double, char16_t, char32_t, and the IEEE 754r decimal and half-precision floating point types.
(reference: http://mentorembedded.github.io/cxx-abi/abi.html#rtti)

ygao added a comment.Mar 21 2014, 2:07 PM

Ping again.

Some additional information: Right now, only OpenCL supports this type in terms of language spec (plus
a number of shading languages, but clang does not support them), but AFAIK OpenCL does not support
exceptions. ARM and x86 have this type as an extension: storage-only type, not as argument or return
type. So maybe exception handling is not supported on those targets, i.e., one cannot throw a half-
precision floating point typed object.

It is not clear whether the typeid operator is supposed to work on this type.

__fp16 foo = 1.5f;

#include <typeinfo>
const char *get_type() {
  return typeid(foo).name();
}

Any comments or suggestions?

ygao added a comment.Mar 28 2014, 11:54 AM

ping.

Although the type info object is provided by the runtime library, the runtime library relies
on clang to generate such a type object upon seeing a magic __fundamantal_type_info
struct, so one still has to patch the compiler if this type object is supposed to be there.
Which leads back to the question: should a type info object be generated for the 16-bit
floating-point type, so that the typeid operator will work? Any opinion?

(Reference: http://mentorembedded.github.io/cxx-abi/abi.html)

ygao added a comment.Apr 3 2014, 10:54 AM

A fourth ping...

ygao added a comment.Apr 16 2014, 11:41 AM

A fifth ping...

rnk accepted this revision.Apr 16 2014, 12:55 PM

lgtm

This seems consistent with the ABI document: "Specifically, the run-time support library should contain type_info objects for the types ..., and the IEEE 754r decimal and half-precision floating point types."

ygao closed this revision.May 6 2014, 7:10 PM