[cfe-commits] RFC: Half floating point support

John McCall rjmccall at apple.com
Wed Oct 5 01:40:30 PDT 2011

On Oct 5, 2011, at 1:04 AM, Anton Korobeynikov wrote:
>> The RTTI for 'half' is not, in fact, in the standard library.
> So, it should not be here, right?

Right.  I'm not sure what we should do about it, but "emit an external reference and assume it resolves" is probably not it.

>> +    // Now perform any other conversion remaining.
>> +    ICS.Standard.setFromType(Context.FloatTy);
>> +    ICS.Standard.First = ICK_Identity;
>> +    ICS.Standard.setToType(0, Context.FloatTy);
>> +    AddConversionSequenceStep(ICS, Entity.getType());
>> This should be modeled in the standard-conversion logic.
> What do you mean?

I mean that adding a single implicit conversion step should be sufficient, and then PerformImplicitConversion should generate the AST you want from that.

>> +      if (FromBuiltin->getKind() == BuiltinType::Half &&
>> +          ToBuiltin->getKind() == BuiltinType::Float)
>> +        return true;
>> Half can also be promoted to double.
> No, it cannot. At least not here. Consider we have:
> int foo(float);
> int foo(double);
> int bar(void) {
>  return foo((__fp16)1.0);
> }
> Here foo(float) should be selected.

Okay, but if foo(float) doesn't exist, foo(double) should be selected.  So there's at least a floating-point conversion from half to double.

>> +  // Half FP is a bit different: it's a storage-only type, meaning that any
>> +  // "use" of it should involve promotion to float.
>> +  if (From->getType()->isHalfType())
>> +    From = ImpCastExprToType(From, Context.FloatTy, CK_FloatingCast).take();
>> This clearly doesn't belong here.
> Ok, where should be it then? Consider we have:
> __fp16 foo, bar, baz;
> baz = (foo ? : bar : 42.0);
> I C mode UsualUnaryConversions are performed on lhs, rhs and
> condition, thus everything works. However, in C++ mode it's called
> only on lhs and rhs, but not on condition (so, neither
> lvalue-to-rvalue nor unary conversions are done), instead direct cast
> to _Bool is inserted.

If you really think it's important, the appropriate thing to do would be to make PerformImplicitConversion do it in ICK_BooleanConversion.  But I would note that, for example, we don't promote 'char' before converting it to bool.


More information about the cfe-commits mailing list