The 11 patches in this set add the initial support for _Float16 (IEEE
754 16-bit floating point) and __bf16 (Google 16-bit brain format
floating point).

At present, these patches will not enable 16-bit floating point by
default.  I hope before GCC 17 stage1 closes that these patches will be
committed and enabled by default.  The option -mfloat16 will enable the
16-bit floating point support.  There is a GCC configuration option
(--with-powerpc-float16) that will enable 16-bit floating point by
default.

For context, the Power9 added scalar instructions to convert between
the 64-bit floating point format and the _Float16 format.  Power9 also
added instructions to convert between partial _Float16 vectors and
float vectors.

Power10 added instructions to convert between partial __b16 vectors and
float vectors.  However there is no support for converting scalar
__bf16 values.  These patches need to work around this limitation.

At the moment the ABI is not completely nailed down.  My patches
currently pass the 16-bit values and return them using the memory
format in floating point registers in bits 48-63 (i.e. where an
unsigned short would be held in the register).  This similar to how the
x86 passes and returns _Float16 and __bf16 values.  The C/C++ standards
allow _Float16 to be passed in a different fashion than the port passes
float and double.

However some folk would prefer that we pass 16-bit floating point by
converting it to the normal 64-bit scalar format.  Likewise some people
would like functions to return 16-bit floating point as the 64-bit
scalar format.

I did some experiments in adding this support.  It looks like we may
need to add target hooks to do this conversion at the call level.  I
will look into this in the future.

If this ABI change goes in, it may mean that __bf16 will need the
Power10 architecture to be enabled and _Float16 will need at least the
Power9 instruction set.  I also have made the libgcc 16-bit floating
point functions have an alternative calling sequence that adds a _gpr
suffix and passes/returns the 16-bit values as unsigned short.  There
is a GCC configuration option (--without-powerpc-float16-libgcc-gpr) to
set the default.  There is also a command line option
(-mfloat16-libgcc-gpr) to change how the libgcc functions are called.
Both versions of the libgcc functions are built.

Due to the fact that the calling sequence may be changed in the future,
a warning is issued by default when you pass 16-bit floating point
scalars or return them.  There is a command line option
(-mno-float16-warn-call-return) that will disable the warning.  There
is also a GCC configuration (--with-powerpc-float16-disable-warning)
that disables the warning by default.

If I configure GCC to enable -mfloat16 by default and disable the
warning on passing or returning 16-bit floating point values, there are
2 tests that now fail:

    gcc.dg/tree-ssa/pow_fold_1.c
    g++.dg/cpp29/ext-floating1.C

There are 11 pathes in this sequence:

Patch #1 adds infrastructure for _Float16 and __bf16 types.

Patch #2 adds initial 16-bit floating point support.

Patch #3 adds the initial HF/BF emulation functions to libgcc.  Note,
these functions do not support the alternative calling sequence passing
and return 16-bit values as unsigned short.  A later patch will add
this support.

Patch #4 adds conversions between _Float16 and float/double.

Patch #5 adds conversions between __bf16 and float/double.

Patch #6 adds conversions between 16-bit floating point and other
scalar modes.

Patch #7 adds 16-bit floating point negation and absolute value
instructions.  The patch also add logical operations on 16-bit floating
point mode to implement negation, absolute value, and negative absolute
value.

Patch #8 adds 16-bit vectorization support.  There is a GCC middle end
issue that there is only one named insn that converts two vectors of a
given mode into one vector of a mode is 1/2 the size of the first mode.
Unfortunately, this means we are limited in the vectorization we can do
for one of the types.  At present, I have chosen __bf16 to be the
favored type.

Patch #9 optimizes __bf16 operations.  Because we do not have scalaar
__bf16 conversions in the Power10, we need to use several instructions
to do each conversion.  I have found if we do the operation using
vector float will improve the speed of some benchamrks.  This patch
does this optimiztion.

Patch #10 updates libgcc to have two sets of 16-bit floating point
support.  One uses the normal names and passes/returns value in
floating point registers.  The other adds a _gpr suffix and
passes/returns 16-bit floating point values as unsigned shorts.

Patch #11 adds 5 __bf16 tests (3 runnable, 2 inspect assembly code) and
3 _Float16 tests (all tests are runnable).

-- 
Michael Meissner, IBM
PO Box 98, Ayer, Massachusetts, USA, 01432
email: [email protected]

Reply via email to