16 bit floats

I need to support 16 bit floats for some operations, outside of
datatypes.td and the constants class, is there anything else I will need
to modify to add f16 support?

Thanks,

Micah Villmow

Systems Engineer

Advanced Technology & Performance

Advanced Micro Devices Inc.

S1-609 One AMD Place

Sunnyvale, CA. 94085

P: 408-749-3966

I need to support 16 bit floats for some operations, outside of datatypes.td and the constants class, is there anything else I will need to modify to add f16 support?

probably also code generation (can't give specifics, no real expert on the LLVM codebase).

this would be because, even if the core typesystem knows of the type, the codegen might not know how to emit operations on that type.

now, of note:

in my project (not LLVM based), float16 had not been supported directly (since it is not known to the CPU), rather, some loader and saver thunks were used which converted to/from float32 (this used as the 'internal' representation of the type). in most cases, I would think this would be faster than directly operating on the float16, since the CPU supports float32, but float16 would have to be emulated.

(unless of course newer CPUs are adding native float16 support or similar?...).

  Thanks,

  Micah Villmow

  Systems Engineer

  Advanced Technology & Performance

  Advanced Micro Devices Inc.

  S1-609 One AMD Place

  Sunnyvale, CA. 94085

  P: 408-749-3966

Right. Micah, does your CPU support float16 operations like add/sub etc natively?

-Chirs

BGB/Chris,

I need to do a similar where I convert the 16bit floats to 32bit floats on memory operations for both scalar and vector formats. So can these operations be implemented without adding 16 bit float support natively to LLVM? If so, how?

In this case, you only really need two currently unsupported
instructions: one that does f16->f32, and one that does f32->f16;
adding target intrinsics to do that should be easy. You can make the
instrinsics take an i16 so that the type system doesn't have to be
aware of f16 values.

-Eli

Eli,
This is similar to what I was originally thinking, but I also need to
support i16 data type and conversions between it and floating point
values. So would there be a way for me to distinguish between a half and
a short?
For example, I have the
short a = load_from_memory(short_ptr, index);
and
half a = load_from_memory(half_ptr, index);

if I force it to use i16 wouldn't the function be the sam in the IR?

i.e.
declare i16 @load_from_memory(i16*, i32)?

Thanks,
Micah

Just codegen them as i16 in LLVM IR, and use a library function to convert the i16 into a 32-bit float doing the necessary unpacking. Similarly for store.

-Chris

Thanks for the clarification. This is probably what I will end up doing.

I was suggesting something more like the following pseudo-C:
short a = load_from_memory(short_ptr, index);
float a = convert_f16_f32(load_from_memory(half_ptr, index));

-Eli