[cfe-commits] RFC: Half floating point support

Anton Korobeynikov anton at korobeynikov.info
Wed Oct 5 01:04:17 PDT 2011


Hello John,

> The RTTI for 'half' is not, in fact, in the standard library.
So, it should not be here, right?

> I think this should be modeled as a promotion and performed during
> UsualUnaryConversions, not during DefaultLvalueConversion.
Ok.

> +    // 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?

> +      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.

>
> +  // 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.

-- 
With best regards, Anton Korobeynikov
Faculty of Mathematics and Mechanics, Saint Petersburg State University




More information about the cfe-commits mailing list