On 18/11/12 12:21, Manu wrote:
I've often wondered about having an official 'half' type.
It's very common in rendering/image processing, supported by most video
cards (so compression routines interacting with this type are common),
and it's also supported in hardware by some cpu's.

ARM for instance supports 'half's in hardware, and GCC has an __fp16
type which would map nicely if D supported the type in the front end.

The alternative us to use ushort everywhere, which is awkward, because
it is neither unsigned, nor is it an integer, and it's not typesafe
(allows direct assignment to ints and stuff)...
It would be nice if: cast(half)someFloat would yield the proper value,
even if it is performed in software in most architectures, it could be
mapped to hardware for those that do it.

It could be done in a library, but then GCC couldn't map it properly to
the hardware type, and since D has no way to describe implicit casts
(that I know of?) it becomes awkward to use.
someFloat = someHalf <- doesn't work, because a cast operator expects an
explicit cast, even though this is a lossless conversion and should be
exactly the same as someDouble = someFloat.

Thoughts?

I suspect that what you want in nearly all cases is conversion from

half[] <-> float[]

ie, a pack/unpack operation. I think it would be quite rare to want to operate on a single half.

Although it's supported natively on GPUs, for D's purposes it is more natural to view it as compressed data.

Reply via email to