mbox series

[V3,0/6] Initial support for AVX512FP16

Message ID 20210802063116.999830-1-hongtao.liu@intel.com
Headers show
Series Initial support for AVX512FP16 | expand

Message

liuhongt Aug. 2, 2021, 6:31 a.m. UTC
Update from v2:

1. Support -fexcess-precision=16 which will enable
FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16 when backend supports _Float16. 
2. Update ix86_get_excess_precision, so -fexcess-precision=standard
should not do anything different from -fexcess-precision=fast
 regarding _Float16.
3. Avoiding macroization of HFmode patterns.
4. Allow (subreg:SI (reg:HF)).
5. Update documents corresponding exactly to the code changes in
the same patch.
6. According to 32bit abi, pass vector _Float16 by sse registers
for 32-bit mode, not stack.

Guo, Xuepeng (1):
  AVX512FP16: Initial support for AVX512FP16 feature and scalar _Float16
    instructions.

liuhongt (5):
  Update hf soft-fp from glibc.
  [i386] Enable _Float16 type for TARGET_SSE2 and above.
  [i386] libgcc: Enable hfmode soft-sf/df/xf/tf extensions and
    truncations.
  Support -fexcess-precision=16 which will enable
    FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16 when backend supports _Float16.
  AVX512FP16: Support vector init/broadcast/set/extract for FP16.

 gcc/ada/gcc-interface/misc.c                  |   3 +
 gcc/c-family/c-common.c                       |   6 +-
 gcc/c-family/c-cppbuiltin.c                   |   6 +-
 gcc/common.opt                                |   5 +-
 gcc/common/config/i386/cpuinfo.h              |   2 +
 gcc/common/config/i386/i386-common.c          |  26 +-
 gcc/common/config/i386/i386-cpuinfo.h         |   1 +
 gcc/common/config/i386/i386-isas.h            |   1 +
 gcc/config.gcc                                |   2 +-
 gcc/config/aarch64/aarch64.c                  |   1 +
 gcc/config/arm/arm.c                          |   1 +
 gcc/config/i386/avx512fp16intrin.h            | 225 ++++++++++
 gcc/config/i386/cpuid.h                       |   1 +
 gcc/config/i386/i386-builtin-types.def        |   7 +-
 gcc/config/i386/i386-builtins.c               |  23 +
 gcc/config/i386/i386-c.c                      |   2 +
 gcc/config/i386/i386-expand.c                 | 129 +++++-
 gcc/config/i386/i386-isa.def                  |   1 +
 gcc/config/i386/i386-modes.def                |  13 +-
 gcc/config/i386/i386-options.c                |   4 +-
 gcc/config/i386/i386.c                        | 243 +++++++++--
 gcc/config/i386/i386.h                        |  29 +-
 gcc/config/i386/i386.md                       | 291 ++++++++++++-
 gcc/config/i386/i386.opt                      |   4 +
 gcc/config/i386/immintrin.h                   |   4 +
 gcc/config/i386/sse.md                        | 397 +++++++++++++-----
 gcc/config/m68k/m68k.c                        |   2 +
 gcc/config/s390/s390.c                        |   2 +
 gcc/coretypes.h                               |   3 +-
 gcc/doc/extend.texi                           |  22 +
 gcc/doc/invoke.texi                           |  10 +-
 gcc/doc/tm.texi                               |  14 +-
 gcc/doc/tm.texi.in                            |   3 +
 gcc/emit-rtl.c                                |   5 +
 gcc/flag-types.h                              |   3 +-
 gcc/fortran/options.c                         |   3 +
 gcc/lto/lto-lang.c                            |   3 +
 gcc/target.def                                |  11 +-
 gcc/testsuite/g++.dg/other/i386-2.C           |   2 +-
 gcc/testsuite/g++.dg/other/i386-3.C           |   2 +-
 gcc/testsuite/g++.target/i386/float16-1.C     |   8 +
 gcc/testsuite/g++.target/i386/float16-2.C     |  14 +
 gcc/testsuite/g++.target/i386/float16-3.C     |  10 +
 gcc/testsuite/gcc.target/i386/avx-1.c         |   2 +-
 gcc/testsuite/gcc.target/i386/avx-2.c         |   2 +-
 gcc/testsuite/gcc.target/i386/avx512-check.h  |   3 +
 .../gcc.target/i386/avx512fp16-12a.c          |  21 +
 .../gcc.target/i386/avx512fp16-12b.c          |  27 ++
 gcc/testsuite/gcc.target/i386/float16-3a.c    |  10 +
 gcc/testsuite/gcc.target/i386/float16-3b.c    |  10 +
 gcc/testsuite/gcc.target/i386/float16-4a.c    |  10 +
 gcc/testsuite/gcc.target/i386/float16-4b.c    |  10 +
 gcc/testsuite/gcc.target/i386/float16-5.c     |  12 +
 gcc/testsuite/gcc.target/i386/float16-6.c     |   8 +
 gcc/testsuite/gcc.target/i386/funcspec-56.inc |   2 +
 gcc/testsuite/gcc.target/i386/pr54855-12.c    |  14 +
 gcc/testsuite/gcc.target/i386/sse-13.c        |   2 +-
 gcc/testsuite/gcc.target/i386/sse-14.c        |   2 +-
 gcc/testsuite/gcc.target/i386/sse-22.c        |   4 +-
 gcc/testsuite/gcc.target/i386/sse-23.c        |   2 +-
 .../gcc.target/i386/sse2-float16-1.c          |   8 +
 .../gcc.target/i386/sse2-float16-2.c          |  16 +
 .../gcc.target/i386/sse2-float16-3.c          |  12 +
 gcc/testsuite/lib/target-supports.exp         |  13 +-
 gcc/tree.c                                    |   3 +-
 libgcc/config.host                            |   5 +-
 libgcc/config/i386/32/sfp-machine.h           |   1 +
 libgcc/config/i386/32/t-softfp                |   1 +
 libgcc/config/i386/64/sfp-machine.h           |   1 +
 libgcc/config/i386/64/t-softfp                |   1 +
 libgcc/config/i386/sfp-machine.h              |   1 +
 libgcc/config/i386/t-softfp                   |   5 +
 libgcc/soft-fp/eqhf2.c                        |  49 +++
 libgcc/soft-fp/extendhfdf2.c                  |  53 +++
 libgcc/soft-fp/extendhfsf2.c                  |  49 +++
 libgcc/soft-fp/half.h                         |   1 +
 libgcc/soft-fp/truncdfhf2.c                   |  52 +++
 libgcc/soft-fp/truncsfhf2.c                   |  48 +++
 78 files changed, 1781 insertions(+), 223 deletions(-)
 create mode 100644 gcc/config/i386/avx512fp16intrin.h
 create mode 100644 gcc/testsuite/g++.target/i386/float16-1.C
 create mode 100644 gcc/testsuite/g++.target/i386/float16-2.C
 create mode 100644 gcc/testsuite/g++.target/i386/float16-3.C
 create mode 100644 gcc/testsuite/gcc.target/i386/avx512fp16-12a.c
 create mode 100644 gcc/testsuite/gcc.target/i386/avx512fp16-12b.c
 create mode 100644 gcc/testsuite/gcc.target/i386/float16-3a.c
 create mode 100644 gcc/testsuite/gcc.target/i386/float16-3b.c
 create mode 100644 gcc/testsuite/gcc.target/i386/float16-4a.c
 create mode 100644 gcc/testsuite/gcc.target/i386/float16-4b.c
 create mode 100644 gcc/testsuite/gcc.target/i386/float16-5.c
 create mode 100644 gcc/testsuite/gcc.target/i386/float16-6.c
 create mode 100644 gcc/testsuite/gcc.target/i386/pr54855-12.c
 create mode 100644 gcc/testsuite/gcc.target/i386/sse2-float16-1.c
 create mode 100644 gcc/testsuite/gcc.target/i386/sse2-float16-2.c
 create mode 100644 gcc/testsuite/gcc.target/i386/sse2-float16-3.c
 create mode 100644 libgcc/config/i386/64/t-softfp
 create mode 100644 libgcc/soft-fp/eqhf2.c
 create mode 100644 libgcc/soft-fp/extendhfdf2.c
 create mode 100644 libgcc/soft-fp/extendhfsf2.c
 create mode 100644 libgcc/soft-fp/truncdfhf2.c
 create mode 100644 libgcc/soft-fp/truncsfhf2.c

Comments

Hongtao Liu Sept. 2, 2021, 6:06 a.m. UTC | #1
I'm going to check in the first 3 patches which are already approved.

  Update hf soft-fp from glibc.
  [i386] Enable _Float16 type for TARGET_SSE2 and above.
  [i386] libgcc: Enable hfmode soft-sf/df/xf/tf extensions and
    truncations.

On Mon, Aug 2, 2021 at 2:31 PM liuhongt <hongtao.liu@intel.com> wrote:
>
> Update from v2:
>
> 1. Support -fexcess-precision=16 which will enable
> FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16 when backend supports _Float16.
> 2. Update ix86_get_excess_precision, so -fexcess-precision=standard
> should not do anything different from -fexcess-precision=fast
>  regarding _Float16.
> 3. Avoiding macroization of HFmode patterns.
> 4. Allow (subreg:SI (reg:HF)).
> 5. Update documents corresponding exactly to the code changes in
> the same patch.
> 6. According to 32bit abi, pass vector _Float16 by sse registers
> for 32-bit mode, not stack.
>
> Guo, Xuepeng (1):
>   AVX512FP16: Initial support for AVX512FP16 feature and scalar _Float16
>     instructions.
>
> liuhongt (5):
>   Update hf soft-fp from glibc.
>   [i386] Enable _Float16 type for TARGET_SSE2 and above.
>   [i386] libgcc: Enable hfmode soft-sf/df/xf/tf extensions and
>     truncations.
>   Support -fexcess-precision=16 which will enable
>     FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16 when backend supports _Float16.
>   AVX512FP16: Support vector init/broadcast/set/extract for FP16.
>
>  gcc/ada/gcc-interface/misc.c                  |   3 +
>  gcc/c-family/c-common.c                       |   6 +-
>  gcc/c-family/c-cppbuiltin.c                   |   6 +-
>  gcc/common.opt                                |   5 +-
>  gcc/common/config/i386/cpuinfo.h              |   2 +
>  gcc/common/config/i386/i386-common.c          |  26 +-
>  gcc/common/config/i386/i386-cpuinfo.h         |   1 +
>  gcc/common/config/i386/i386-isas.h            |   1 +
>  gcc/config.gcc                                |   2 +-
>  gcc/config/aarch64/aarch64.c                  |   1 +
>  gcc/config/arm/arm.c                          |   1 +
>  gcc/config/i386/avx512fp16intrin.h            | 225 ++++++++++
>  gcc/config/i386/cpuid.h                       |   1 +
>  gcc/config/i386/i386-builtin-types.def        |   7 +-
>  gcc/config/i386/i386-builtins.c               |  23 +
>  gcc/config/i386/i386-c.c                      |   2 +
>  gcc/config/i386/i386-expand.c                 | 129 +++++-
>  gcc/config/i386/i386-isa.def                  |   1 +
>  gcc/config/i386/i386-modes.def                |  13 +-
>  gcc/config/i386/i386-options.c                |   4 +-
>  gcc/config/i386/i386.c                        | 243 +++++++++--
>  gcc/config/i386/i386.h                        |  29 +-
>  gcc/config/i386/i386.md                       | 291 ++++++++++++-
>  gcc/config/i386/i386.opt                      |   4 +
>  gcc/config/i386/immintrin.h                   |   4 +
>  gcc/config/i386/sse.md                        | 397 +++++++++++++-----
>  gcc/config/m68k/m68k.c                        |   2 +
>  gcc/config/s390/s390.c                        |   2 +
>  gcc/coretypes.h                               |   3 +-
>  gcc/doc/extend.texi                           |  22 +
>  gcc/doc/invoke.texi                           |  10 +-
>  gcc/doc/tm.texi                               |  14 +-
>  gcc/doc/tm.texi.in                            |   3 +
>  gcc/emit-rtl.c                                |   5 +
>  gcc/flag-types.h                              |   3 +-
>  gcc/fortran/options.c                         |   3 +
>  gcc/lto/lto-lang.c                            |   3 +
>  gcc/target.def                                |  11 +-
>  gcc/testsuite/g++.dg/other/i386-2.C           |   2 +-
>  gcc/testsuite/g++.dg/other/i386-3.C           |   2 +-
>  gcc/testsuite/g++.target/i386/float16-1.C     |   8 +
>  gcc/testsuite/g++.target/i386/float16-2.C     |  14 +
>  gcc/testsuite/g++.target/i386/float16-3.C     |  10 +
>  gcc/testsuite/gcc.target/i386/avx-1.c         |   2 +-
>  gcc/testsuite/gcc.target/i386/avx-2.c         |   2 +-
>  gcc/testsuite/gcc.target/i386/avx512-check.h  |   3 +
>  .../gcc.target/i386/avx512fp16-12a.c          |  21 +
>  .../gcc.target/i386/avx512fp16-12b.c          |  27 ++
>  gcc/testsuite/gcc.target/i386/float16-3a.c    |  10 +
>  gcc/testsuite/gcc.target/i386/float16-3b.c    |  10 +
>  gcc/testsuite/gcc.target/i386/float16-4a.c    |  10 +
>  gcc/testsuite/gcc.target/i386/float16-4b.c    |  10 +
>  gcc/testsuite/gcc.target/i386/float16-5.c     |  12 +
>  gcc/testsuite/gcc.target/i386/float16-6.c     |   8 +
>  gcc/testsuite/gcc.target/i386/funcspec-56.inc |   2 +
>  gcc/testsuite/gcc.target/i386/pr54855-12.c    |  14 +
>  gcc/testsuite/gcc.target/i386/sse-13.c        |   2 +-
>  gcc/testsuite/gcc.target/i386/sse-14.c        |   2 +-
>  gcc/testsuite/gcc.target/i386/sse-22.c        |   4 +-
>  gcc/testsuite/gcc.target/i386/sse-23.c        |   2 +-
>  .../gcc.target/i386/sse2-float16-1.c          |   8 +
>  .../gcc.target/i386/sse2-float16-2.c          |  16 +
>  .../gcc.target/i386/sse2-float16-3.c          |  12 +
>  gcc/testsuite/lib/target-supports.exp         |  13 +-
>  gcc/tree.c                                    |   3 +-
>  libgcc/config.host                            |   5 +-
>  libgcc/config/i386/32/sfp-machine.h           |   1 +
>  libgcc/config/i386/32/t-softfp                |   1 +
>  libgcc/config/i386/64/sfp-machine.h           |   1 +
>  libgcc/config/i386/64/t-softfp                |   1 +
>  libgcc/config/i386/sfp-machine.h              |   1 +
>  libgcc/config/i386/t-softfp                   |   5 +
>  libgcc/soft-fp/eqhf2.c                        |  49 +++
>  libgcc/soft-fp/extendhfdf2.c                  |  53 +++
>  libgcc/soft-fp/extendhfsf2.c                  |  49 +++
>  libgcc/soft-fp/half.h                         |   1 +
>  libgcc/soft-fp/truncdfhf2.c                   |  52 +++
>  libgcc/soft-fp/truncsfhf2.c                   |  48 +++
>  78 files changed, 1781 insertions(+), 223 deletions(-)
>  create mode 100644 gcc/config/i386/avx512fp16intrin.h
>  create mode 100644 gcc/testsuite/g++.target/i386/float16-1.C
>  create mode 100644 gcc/testsuite/g++.target/i386/float16-2.C
>  create mode 100644 gcc/testsuite/g++.target/i386/float16-3.C
>  create mode 100644 gcc/testsuite/gcc.target/i386/avx512fp16-12a.c
>  create mode 100644 gcc/testsuite/gcc.target/i386/avx512fp16-12b.c
>  create mode 100644 gcc/testsuite/gcc.target/i386/float16-3a.c
>  create mode 100644 gcc/testsuite/gcc.target/i386/float16-3b.c
>  create mode 100644 gcc/testsuite/gcc.target/i386/float16-4a.c
>  create mode 100644 gcc/testsuite/gcc.target/i386/float16-4b.c
>  create mode 100644 gcc/testsuite/gcc.target/i386/float16-5.c
>  create mode 100644 gcc/testsuite/gcc.target/i386/float16-6.c
>  create mode 100644 gcc/testsuite/gcc.target/i386/pr54855-12.c
>  create mode 100644 gcc/testsuite/gcc.target/i386/sse2-float16-1.c
>  create mode 100644 gcc/testsuite/gcc.target/i386/sse2-float16-2.c
>  create mode 100644 gcc/testsuite/gcc.target/i386/sse2-float16-3.c
>  create mode 100644 libgcc/config/i386/64/t-softfp
>  create mode 100644 libgcc/soft-fp/eqhf2.c
>  create mode 100644 libgcc/soft-fp/extendhfdf2.c
>  create mode 100644 libgcc/soft-fp/extendhfsf2.c
>  create mode 100644 libgcc/soft-fp/truncdfhf2.c
>  create mode 100644 libgcc/soft-fp/truncsfhf2.c
>
> --
> 2.27.0
>
Iain Sandoe Sept. 2, 2021, 11:30 a.m. UTC | #2
Hi Hongtao.

> On 2 Sep 2021, at 07:06, Hongtao Liu via Gcc-patches <gcc-patches@gcc.gnu.org> wrote:
> 
> I'm going to check in the first 3 patches which are already approved.
> 
>  Update hf soft-fp from glibc.
>  [i386] Enable _Float16 type for TARGET_SSE2 and above.
>  [i386] libgcc: Enable hfmode soft-sf/df/xf/tf extensions and
>    truncations.

Bootstrap on Darwin x86_64 is broken on at least AVX512 and i5 cpus at revision
r12-3311-g1e6267b33526.

"fp-machine.h:81:22: error: unknown type name 'TFtype'; did you mean 'HFtype’?”

any immediate ideas on what might be the issue?
thanks
Iain

> 
> On Mon, Aug 2, 2021 at 2:31 PM liuhongt <hongtao.liu@intel.com> wrote:
>> 
>> Update from v2:
>> 
>> 1. Support -fexcess-precision=16 which will enable
>> FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16 when backend supports _Float16.
>> 2. Update ix86_get_excess_precision, so -fexcess-precision=standard
>> should not do anything different from -fexcess-precision=fast
>> regarding _Float16.
>> 3. Avoiding macroization of HFmode patterns.
>> 4. Allow (subreg:SI (reg:HF)).
>> 5. Update documents corresponding exactly to the code changes in
>> the same patch.
>> 6. According to 32bit abi, pass vector _Float16 by sse registers
>> for 32-bit mode, not stack.
>> 
>> Guo, Xuepeng (1):
>>  AVX512FP16: Initial support for AVX512FP16 feature and scalar _Float16
>>    instructions.
>> 
>> liuhongt (5):
>>  Update hf soft-fp from glibc.
>>  [i386] Enable _Float16 type for TARGET_SSE2 and above.
>>  [i386] libgcc: Enable hfmode soft-sf/df/xf/tf extensions and
>>    truncations.
>>  Support -fexcess-precision=16 which will enable
>>    FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16 when backend supports _Float16.
>>  AVX512FP16: Support vector init/broadcast/set/extract for FP16.
>> 
>> gcc/ada/gcc-interface/misc.c                  |   3 +
>> gcc/c-family/c-common.c                       |   6 +-
>> gcc/c-family/c-cppbuiltin.c                   |   6 +-
>> gcc/common.opt                                |   5 +-
>> gcc/common/config/i386/cpuinfo.h              |   2 +
>> gcc/common/config/i386/i386-common.c          |  26 +-
>> gcc/common/config/i386/i386-cpuinfo.h         |   1 +
>> gcc/common/config/i386/i386-isas.h            |   1 +
>> gcc/config.gcc                                |   2 +-
>> gcc/config/aarch64/aarch64.c                  |   1 +
>> gcc/config/arm/arm.c                          |   1 +
>> gcc/config/i386/avx512fp16intrin.h            | 225 ++++++++++
>> gcc/config/i386/cpuid.h                       |   1 +
>> gcc/config/i386/i386-builtin-types.def        |   7 +-
>> gcc/config/i386/i386-builtins.c               |  23 +
>> gcc/config/i386/i386-c.c                      |   2 +
>> gcc/config/i386/i386-expand.c                 | 129 +++++-
>> gcc/config/i386/i386-isa.def                  |   1 +
>> gcc/config/i386/i386-modes.def                |  13 +-
>> gcc/config/i386/i386-options.c                |   4 +-
>> gcc/config/i386/i386.c                        | 243 +++++++++--
>> gcc/config/i386/i386.h                        |  29 +-
>> gcc/config/i386/i386.md                       | 291 ++++++++++++-
>> gcc/config/i386/i386.opt                      |   4 +
>> gcc/config/i386/immintrin.h                   |   4 +
>> gcc/config/i386/sse.md                        | 397 +++++++++++++-----
>> gcc/config/m68k/m68k.c                        |   2 +
>> gcc/config/s390/s390.c                        |   2 +
>> gcc/coretypes.h                               |   3 +-
>> gcc/doc/extend.texi                           |  22 +
>> gcc/doc/invoke.texi                           |  10 +-
>> gcc/doc/tm.texi                               |  14 +-
>> gcc/doc/tm.texi.in                            |   3 +
>> gcc/emit-rtl.c                                |   5 +
>> gcc/flag-types.h                              |   3 +-
>> gcc/fortran/options.c                         |   3 +
>> gcc/lto/lto-lang.c                            |   3 +
>> gcc/target.def                                |  11 +-
>> gcc/testsuite/g++.dg/other/i386-2.C           |   2 +-
>> gcc/testsuite/g++.dg/other/i386-3.C           |   2 +-
>> gcc/testsuite/g++.target/i386/float16-1.C     |   8 +
>> gcc/testsuite/g++.target/i386/float16-2.C     |  14 +
>> gcc/testsuite/g++.target/i386/float16-3.C     |  10 +
>> gcc/testsuite/gcc.target/i386/avx-1.c         |   2 +-
>> gcc/testsuite/gcc.target/i386/avx-2.c         |   2 +-
>> gcc/testsuite/gcc.target/i386/avx512-check.h  |   3 +
>> .../gcc.target/i386/avx512fp16-12a.c          |  21 +
>> .../gcc.target/i386/avx512fp16-12b.c          |  27 ++
>> gcc/testsuite/gcc.target/i386/float16-3a.c    |  10 +
>> gcc/testsuite/gcc.target/i386/float16-3b.c    |  10 +
>> gcc/testsuite/gcc.target/i386/float16-4a.c    |  10 +
>> gcc/testsuite/gcc.target/i386/float16-4b.c    |  10 +
>> gcc/testsuite/gcc.target/i386/float16-5.c     |  12 +
>> gcc/testsuite/gcc.target/i386/float16-6.c     |   8 +
>> gcc/testsuite/gcc.target/i386/funcspec-56.inc |   2 +
>> gcc/testsuite/gcc.target/i386/pr54855-12.c    |  14 +
>> gcc/testsuite/gcc.target/i386/sse-13.c        |   2 +-
>> gcc/testsuite/gcc.target/i386/sse-14.c        |   2 +-
>> gcc/testsuite/gcc.target/i386/sse-22.c        |   4 +-
>> gcc/testsuite/gcc.target/i386/sse-23.c        |   2 +-
>> .../gcc.target/i386/sse2-float16-1.c          |   8 +
>> .../gcc.target/i386/sse2-float16-2.c          |  16 +
>> .../gcc.target/i386/sse2-float16-3.c          |  12 +
>> gcc/testsuite/lib/target-supports.exp         |  13 +-
>> gcc/tree.c                                    |   3 +-
>> libgcc/config.host                            |   5 +-
>> libgcc/config/i386/32/sfp-machine.h           |   1 +
>> libgcc/config/i386/32/t-softfp                |   1 +
>> libgcc/config/i386/64/sfp-machine.h           |   1 +
>> libgcc/config/i386/64/t-softfp                |   1 +
>> libgcc/config/i386/sfp-machine.h              |   1 +
>> libgcc/config/i386/t-softfp                   |   5 +
>> libgcc/soft-fp/eqhf2.c                        |  49 +++
>> libgcc/soft-fp/extendhfdf2.c                  |  53 +++
>> libgcc/soft-fp/extendhfsf2.c                  |  49 +++
>> libgcc/soft-fp/half.h                         |   1 +
>> libgcc/soft-fp/truncdfhf2.c                   |  52 +++
>> libgcc/soft-fp/truncsfhf2.c                   |  48 +++
>> 78 files changed, 1781 insertions(+), 223 deletions(-)
>> create mode 100644 gcc/config/i386/avx512fp16intrin.h
>> create mode 100644 gcc/testsuite/g++.target/i386/float16-1.C
>> create mode 100644 gcc/testsuite/g++.target/i386/float16-2.C
>> create mode 100644 gcc/testsuite/g++.target/i386/float16-3.C
>> create mode 100644 gcc/testsuite/gcc.target/i386/avx512fp16-12a.c
>> create mode 100644 gcc/testsuite/gcc.target/i386/avx512fp16-12b.c
>> create mode 100644 gcc/testsuite/gcc.target/i386/float16-3a.c
>> create mode 100644 gcc/testsuite/gcc.target/i386/float16-3b.c
>> create mode 100644 gcc/testsuite/gcc.target/i386/float16-4a.c
>> create mode 100644 gcc/testsuite/gcc.target/i386/float16-4b.c
>> create mode 100644 gcc/testsuite/gcc.target/i386/float16-5.c
>> create mode 100644 gcc/testsuite/gcc.target/i386/float16-6.c
>> create mode 100644 gcc/testsuite/gcc.target/i386/pr54855-12.c
>> create mode 100644 gcc/testsuite/gcc.target/i386/sse2-float16-1.c
>> create mode 100644 gcc/testsuite/gcc.target/i386/sse2-float16-2.c
>> create mode 100644 gcc/testsuite/gcc.target/i386/sse2-float16-3.c
>> create mode 100644 libgcc/config/i386/64/t-softfp
>> create mode 100644 libgcc/soft-fp/eqhf2.c
>> create mode 100644 libgcc/soft-fp/extendhfdf2.c
>> create mode 100644 libgcc/soft-fp/extendhfsf2.c
>> create mode 100644 libgcc/soft-fp/truncdfhf2.c
>> create mode 100644 libgcc/soft-fp/truncsfhf2.c
>> 
>> --
>> 2.27.0
>> 
> 
> 
> -- 
> BR,
> Hongtao
Hongtao Liu Sept. 2, 2021, 3:18 p.m. UTC | #3
On Thursday, September 2, 2021, Iain Sandoe <idsandoe@googlemail.com> wrote:

> Hi Hongtao.
>
> > On 2 Sep 2021, at 07:06, Hongtao Liu via Gcc-patches <
> gcc-patches@gcc.gnu.org> wrote:
> >
> > I'm going to check in the first 3 patches which are already approved.
> >
> >  Update hf soft-fp from glibc.
> >  [i386] Enable _Float16 type for TARGET_SSE2 and above.
> >  [i386] libgcc: Enable hfmode soft-sf/df/xf/tf extensions and
> >    truncations.
>
> Bootstrap on Darwin x86_64 is broken on at least AVX512 and i5 cpus at
> revision
> r12-3311-g1e6267b33526.
>
> "fp-machine.h:81:22: error: unknown type name 'TFtype'; did you mean
> 'HFtype’?”
>
> any immediate ideas on what might be the issue?
> thanks


Seems to be related to the belowpart which is not changed by my patch, and
TFtype is defined in quad.h

76
<https://gcc.gnu.org/git?p=gcc.git;a=blob;f=libgcc/config/i386/sfp-machine.h;h=f15d29d37550936c060c4caed4182c58c43ee221;hb=f15d29d37550936c060c4caed4182c58c43ee221#l76>
/*
Define ALIASNAME as a strong alias for NAME. */
77
<https://gcc.gnu.org/git?p=gcc.git;a=blob;f=libgcc/config/i386/sfp-machine.h;h=f15d29d37550936c060c4caed4182c58c43ee221;hb=f15d29d37550936c060c4caed4182c58c43ee221#l77>
#if
defined __MACH__
78
<https://gcc.gnu.org/git?p=gcc.git;a=blob;f=libgcc/config/i386/sfp-machine.h;h=f15d29d37550936c060c4caed4182c58c43ee221;hb=f15d29d37550936c060c4caed4182c58c43ee221#l78>
/*
Mach-O doesn't support aliasing. If these functions ever return
79
<https://gcc.gnu.org/git?p=gcc.git;a=blob;f=libgcc/config/i386/sfp-machine.h;h=f15d29d37550936c060c4caed4182c58c43ee221;hb=f15d29d37550936c060c4caed4182c58c43ee221#l79>
anything
but CMPtype we need to revisit this... */
80
<https://gcc.gnu.org/git?p=gcc.git;a=blob;f=libgcc/config/i386/sfp-machine.h;h=f15d29d37550936c060c4caed4182c58c43ee221;hb=f15d29d37550936c060c4caed4182c58c43ee221#l80>
#define
strong_alias(name, aliasname) \
81
<https://gcc.gnu.org/git?p=gcc.git;a=blob;f=libgcc/config/i386/sfp-machine.h;h=f15d29d37550936c060c4caed4182c58c43ee221;hb=f15d29d37550936c060c4caed4182c58c43ee221#l81>
CMPtype
aliasname (TFtype a, TFtype b) { return name(a, b); }
82
<https://gcc.gnu.org/git?p=gcc.git;a=blob;f=libgcc/config/i386/sfp-machine.h;h=f15d29d37550936c060c4caed4182c58c43ee221;hb=f15d29d37550936c060c4caed4182c58c43ee221#l82>
#else

Would you try to add
typedef float TFtype __attribute__ ((mode (TF)));
Here to see if it fixes the issue.

Iain
>
>

> >
> > On Mon, Aug 2, 2021 at 2:31 PM liuhongt <hongtao.liu@intel.com> wrote:
> >>
> >> Update from v2:
> >>
> >> 1. Support -fexcess-precision=16 which will enable
> >> FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16 when backend supports _Float16.
> >> 2. Update ix86_get_excess_precision, so -fexcess-precision=standard
> >> should not do anything different from -fexcess-precision=fast
> >> regarding _Float16.
> >> 3. Avoiding macroization of HFmode patterns.
> >> 4. Allow (subreg:SI (reg:HF)).
> >> 5. Update documents corresponding exactly to the code changes in
> >> the same patch.
> >> 6. According to 32bit abi, pass vector _Float16 by sse registers
> >> for 32-bit mode, not stack.
> >>
> >> Guo, Xuepeng (1):
> >>  AVX512FP16: Initial support for AVX512FP16 feature and scalar _Float16
> >>    instructions.
> >>
> >> liuhongt (5):
> >>  Update hf soft-fp from glibc.
> >>  [i386] Enable _Float16 type for TARGET_SSE2 and above.
> >>  [i386] libgcc: Enable hfmode soft-sf/df/xf/tf extensions and
> >>    truncations.
> >>  Support -fexcess-precision=16 which will enable
> >>    FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16 when backend supports _Float16.
> >>  AVX512FP16: Support vector init/broadcast/set/extract for FP16.
> >>
> >> gcc/ada/gcc-interface/misc.c                  |   3 +
> >> gcc/c-family/c-common.c                       |   6 +-
> >> gcc/c-family/c-cppbuiltin.c                   |   6 +-
> >> gcc/common.opt                                |   5 +-
> >> gcc/common/config/i386/cpuinfo.h              |   2 +
> >> gcc/common/config/i386/i386-common.c          |  26 +-
> >> gcc/common/config/i386/i386-cpuinfo.h         |   1 +
> >> gcc/common/config/i386/i386-isas.h            |   1 +
> >> gcc/config.gcc                                |   2 +-
> >> gcc/config/aarch64/aarch64.c                  |   1 +
> >> gcc/config/arm/arm.c                          |   1 +
> >> gcc/config/i386/avx512fp16intrin.h            | 225 ++++++++++
> >> gcc/config/i386/cpuid.h                       |   1 +
> >> gcc/config/i386/i386-builtin-types.def        |   7 +-
> >> gcc/config/i386/i386-builtins.c               |  23 +
> >> gcc/config/i386/i386-c.c                      |   2 +
> >> gcc/config/i386/i386-expand.c                 | 129 +++++-
> >> gcc/config/i386/i386-isa.def                  |   1 +
> >> gcc/config/i386/i386-modes.def                |  13 +-
> >> gcc/config/i386/i386-options.c                |   4 +-
> >> gcc/config/i386/i386.c                        | 243 +++++++++--
> >> gcc/config/i386/i386.h                        |  29 +-
> >> gcc/config/i386/i386.md                       | 291 ++++++++++++-
> >> gcc/config/i386/i386.opt                      |   4 +
> >> gcc/config/i386/immintrin.h                   |   4 +
> >> gcc/config/i386/sse.md                        | 397 +++++++++++++-----
> >> gcc/config/m68k/m68k.c                        |   2 +
> >> gcc/config/s390/s390.c                        |   2 +
> >> gcc/coretypes.h                               |   3 +-
> >> gcc/doc/extend.texi                           |  22 +
> >> gcc/doc/invoke.texi                           |  10 +-
> >> gcc/doc/tm.texi                               |  14 +-
> >> gcc/doc/tm.texi.in                            |   3 +
> >> gcc/emit-rtl.c                                |   5 +
> >> gcc/flag-types.h                              |   3 +-
> >> gcc/fortran/options.c                         |   3 +
> >> gcc/lto/lto-lang.c                            |   3 +
> >> gcc/target.def                                |  11 +-
> >> gcc/testsuite/g++.dg/other/i386-2.C           |   2 +-
> >> gcc/testsuite/g++.dg/other/i386-3.C           |   2 +-
> >> gcc/testsuite/g++.target/i386/float16-1.C     |   8 +
> >> gcc/testsuite/g++.target/i386/float16-2.C     |  14 +
> >> gcc/testsuite/g++.target/i386/float16-3.C     |  10 +
> >> gcc/testsuite/gcc.target/i386/avx-1.c         |   2 +-
> >> gcc/testsuite/gcc.target/i386/avx-2.c         |   2 +-
> >> gcc/testsuite/gcc.target/i386/avx512-check.h  |   3 +
> >> .../gcc.target/i386/avx512fp16-12a.c          |  21 +
> >> .../gcc.target/i386/avx512fp16-12b.c          |  27 ++
> >> gcc/testsuite/gcc.target/i386/float16-3a.c    |  10 +
> >> gcc/testsuite/gcc.target/i386/float16-3b.c    |  10 +
> >> gcc/testsuite/gcc.target/i386/float16-4a.c    |  10 +
> >> gcc/testsuite/gcc.target/i386/float16-4b.c    |  10 +
> >> gcc/testsuite/gcc.target/i386/float16-5.c     |  12 +
> >> gcc/testsuite/gcc.target/i386/float16-6.c     |   8 +
> >> gcc/testsuite/gcc.target/i386/funcspec-56.inc |   2 +
> >> gcc/testsuite/gcc.target/i386/pr54855-12.c    |  14 +
> >> gcc/testsuite/gcc.target/i386/sse-13.c        |   2 +-
> >> gcc/testsuite/gcc.target/i386/sse-14.c        |   2 +-
> >> gcc/testsuite/gcc.target/i386/sse-22.c        |   4 +-
> >> gcc/testsuite/gcc.target/i386/sse-23.c        |   2 +-
> >> .../gcc.target/i386/sse2-float16-1.c          |   8 +
> >> .../gcc.target/i386/sse2-float16-2.c          |  16 +
> >> .../gcc.target/i386/sse2-float16-3.c          |  12 +
> >> gcc/testsuite/lib/target-supports.exp         |  13 +-
> >> gcc/tree.c                                    |   3 +-
> >> libgcc/config.host                            |   5 +-
> >> libgcc/config/i386/32/sfp-machine.h           |   1 +
> >> libgcc/config/i386/32/t-softfp                |   1 +
> >> libgcc/config/i386/64/sfp-machine.h           |   1 +
> >> libgcc/config/i386/64/t-softfp                |   1 +
> >> libgcc/config/i386/sfp-machine.h              |   1 +
> >> libgcc/config/i386/t-softfp                   |   5 +
> >> libgcc/soft-fp/eqhf2.c                        |  49 +++
> >> libgcc/soft-fp/extendhfdf2.c                  |  53 +++
> >> libgcc/soft-fp/extendhfsf2.c                  |  49 +++
> >> libgcc/soft-fp/half.h                         |   1 +
> >> libgcc/soft-fp/truncdfhf2.c                   |  52 +++
> >> libgcc/soft-fp/truncsfhf2.c                   |  48 +++
> >> 78 files changed, 1781 insertions(+), 223 deletions(-)
> >> create mode 100644 gcc/config/i386/avx512fp16intrin.h
> >> create mode 100644 gcc/testsuite/g++.target/i386/float16-1.C
> >> create mode 100644 gcc/testsuite/g++.target/i386/float16-2.C
> >> create mode 100644 gcc/testsuite/g++.target/i386/float16-3.C
> >> create mode 100644 gcc/testsuite/gcc.target/i386/avx512fp16-12a.c
> >> create mode 100644 gcc/testsuite/gcc.target/i386/avx512fp16-12b.c
> >> create mode 100644 gcc/testsuite/gcc.target/i386/float16-3a.c
> >> create mode 100644 gcc/testsuite/gcc.target/i386/float16-3b.c
> >> create mode 100644 gcc/testsuite/gcc.target/i386/float16-4a.c
> >> create mode 100644 gcc/testsuite/gcc.target/i386/float16-4b.c
> >> create mode 100644 gcc/testsuite/gcc.target/i386/float16-5.c
> >> create mode 100644 gcc/testsuite/gcc.target/i386/float16-6.c
> >> create mode 100644 gcc/testsuite/gcc.target/i386/pr54855-12.c
> >> create mode 100644 gcc/testsuite/gcc.target/i386/sse2-float16-1.c
> >> create mode 100644 gcc/testsuite/gcc.target/i386/sse2-float16-2.c
> >> create mode 100644 gcc/testsuite/gcc.target/i386/sse2-float16-3.c
> >> create mode 100644 libgcc/config/i386/64/t-softfp
> >> create mode 100644 libgcc/soft-fp/eqhf2.c
> >> create mode 100644 libgcc/soft-fp/extendhfdf2.c
> >> create mode 100644 libgcc/soft-fp/extendhfsf2.c
> >> create mode 100644 libgcc/soft-fp/truncdfhf2.c
> >> create mode 100644 libgcc/soft-fp/truncsfhf2.c
> >>
> >> --
> >> 2.27.0
> >>
> >
> >
> > --
> > BR,
> > Hongtao
>
>
H.J. Lu Sept. 2, 2021, 3:30 p.m. UTC | #4
On Wed, Sep 1, 2021 at 11:00 PM Hongtao Liu <crazylht@gmail.com> wrote:
>
> I'm going to check in the first 3 patches which are already approved.
>
>   Update hf soft-fp from glibc.
>   [i386] Enable _Float16 type for TARGET_SSE2 and above.
>   [i386] libgcc: Enable hfmode soft-sf/df/xf/tf extensions and
>     truncations.
>
> On Mon, Aug 2, 2021 at 2:31 PM liuhongt <hongtao.liu@intel.com> wrote:
> >
> > Update from v2:
> >
> > 1. Support -fexcess-precision=16 which will enable
> > FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16 when backend supports _Float16.
> > 2. Update ix86_get_excess_precision, so -fexcess-precision=standard
> > should not do anything different from -fexcess-precision=fast
> >  regarding _Float16.
> > 3. Avoiding macroization of HFmode patterns.
> > 4. Allow (subreg:SI (reg:HF)).
> > 5. Update documents corresponding exactly to the code changes in
> > the same patch.
> > 6. According to 32bit abi, pass vector _Float16 by sse registers
> > for 32-bit mode, not stack.
> >
> > Guo, Xuepeng (1):
> >   AVX512FP16: Initial support for AVX512FP16 feature and scalar _Float16
> >     instructions.
> >
> > liuhongt (5):
> >   Update hf soft-fp from glibc.
> >   [i386] Enable _Float16 type for TARGET_SSE2 and above.
> >   [i386] libgcc: Enable hfmode soft-sf/df/xf/tf extensions and
> >     truncations.
> >   Support -fexcess-precision=16 which will enable
> >     FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16 when backend supports _Float16.
> >   AVX512FP16: Support vector init/broadcast/set/extract for FP16.
> >

I got

FAIL: gcc.dg/torture/fp-int-convert-float16.c   -Os  execution test
FAIL: gcc.dg/torture/fp-int-convert-float16-timode.c   -Os  execution test

with -m32:

[hjl@gnu-skx-1 gcc]$ ./xgcc -B./ -m32
/export/gnu/import/git/gitlab/x86-gcc/gcc/testsuite/gcc.dg/torture/fp-int-convert-float16.c
 -m32  -Os -march=i686 -mfpmath=sse -msse2
[hjl@gnu-skx-1 gcc]$ ./a.out
Aborted (core dumped)
[hjl@gnu-skx-1 gcc]$

H.J.
Hongtao Liu Sept. 2, 2021, 3:50 p.m. UTC | #5
On Thursday, September 2, 2021, H.J. Lu <hjl.tools@gmail.com> wrote:

> On Wed, Sep 1, 2021 at 11:00 PM Hongtao Liu <crazylht@gmail.com> wrote:
> >
> > I'm going to check in the first 3 patches which are already approved.
> >
> >   Update hf soft-fp from glibc.
> >   [i386] Enable _Float16 type for TARGET_SSE2 and above.
> >   [i386] libgcc: Enable hfmode soft-sf/df/xf/tf extensions and
> >     truncations.
> >
> > On Mon, Aug 2, 2021 at 2:31 PM liuhongt <hongtao.liu@intel.com> wrote:
> > >
> > > Update from v2:
> > >
> > > 1. Support -fexcess-precision=16 which will enable
> > > FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16 when backend supports _Float16.
> > > 2. Update ix86_get_excess_precision, so -fexcess-precision=standard
> > > should not do anything different from -fexcess-precision=fast
> > >  regarding _Float16.
> > > 3. Avoiding macroization of HFmode patterns.
> > > 4. Allow (subreg:SI (reg:HF)).
> > > 5. Update documents corresponding exactly to the code changes in
> > > the same patch.
> > > 6. According to 32bit abi, pass vector _Float16 by sse registers
> > > for 32-bit mode, not stack.
> > >
> > > Guo, Xuepeng (1):
> > >   AVX512FP16: Initial support for AVX512FP16 feature and scalar
> _Float16
> > >     instructions.
> > >
> > > liuhongt (5):
> > >   Update hf soft-fp from glibc.
> > >   [i386] Enable _Float16 type for TARGET_SSE2 and above.
> > >   [i386] libgcc: Enable hfmode soft-sf/df/xf/tf extensions and
> > >     truncations.
> > >   Support -fexcess-precision=16 which will enable
> > >     FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16 when backend supports _Float16.
> > >   AVX512FP16: Support vector init/broadcast/set/extract for FP16.
> > >
>
> I got
>
> FAIL: gcc.dg/torture/fp-int-convert-float16.c   -Os  execution test
> FAIL: gcc.dg/torture/fp-int-convert-float16-timode.c   -Os  execution test
>
> with -m32:

Guess it hit some precess excession issue w/ x87 fpu.

>
> [hjl@gnu-skx-1 gcc]$ ./xgcc -B./ -m32
> /export/gnu/import/git/gitlab/x86-gcc/gcc/testsuite/gcc.dg/
> torture/fp-int-convert-float16.c
>  -m32  -Os -march=i686 -mfpmath=sse -msse2
> [hjl@gnu-skx-1 gcc]$ ./a.out
> Aborted (core dumped)
> [hjl@gnu-skx-1 gcc]$
>
> H.J.
>
Iain Sandoe Sept. 2, 2021, 4:44 p.m. UTC | #6
Patch below fixes bootstrap,

OK if it passes testing on x86_64 darwin/linux?
(if !OK .. then suggestions welcome)

thanks
Iain

> On 2 Sep 2021, at 16:18, Hongtao Liu <crazylht@gmail.com> wrote:
> 
> 
> 
> On Thursday, September 2, 2021, Iain Sandoe <idsandoe@googlemail.com> wrote:
> Hi Hongtao.
> 
> > On 2 Sep 2021, at 07:06, Hongtao Liu via Gcc-patches <gcc-patches@gcc.gnu.org> wrote:
> > 
> > I'm going to check in the first 3 patches which are already approved.
> > 
> >  Update hf soft-fp from glibc.
> >  [i386] Enable _Float16 type for TARGET_SSE2 and above.
> >  [i386] libgcc: Enable hfmode soft-sf/df/xf/tf extensions and
> >    truncations.
> 
> Bootstrap on Darwin x86_64 is broken on at least AVX512 and i5 cpus at revision
> r12-3311-g1e6267b33526.
> 
> "fp-machine.h:81:22: error: unknown type name 'TFtype'; did you mean 'HFtype’?”
> 
> any immediate ideas on what might be the issue?
> thanks
>  
> Seems to be related to the belowpart which is not changed by my patch, and TFtype is defined in quad.h
> 
>  76 /* Define ALIASNAME as a strong alias for NAME.  */
>   77 #if defined __MACH__
>   78 /* Mach-O doesn't support aliasing.  If these functions ever return
>   79    anything but CMPtype we need to revisit this... */
>   80 #define strong_alias(name, aliasname) \
>   81   CMPtype aliasname (TFtype a, TFtype b) { return name(a, b); }
>   82 #else
> 
> Would you try to add
> typedef float TFtype __attribute__ ((mode (TF))); 
> Here to see if it fixes the issue.

I don’t think it’s  quite as simple as that - this is what I’m testing:

[PATCH] libgcc, soft-float: Fix strong_alias macro use for Darwin.

Darwin does not support strong symbol aliases and a work-
around is provided in sfp-machine.h where a second function
is created that simply calls the original.  However this
needs the arguments to the synthesized function to track
the mode of the original function.

So the fix here is to adjust the macro to allow the mode to
be provided and then to set it as needed before the header
is included.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>

libgcc/ChangeLog:

	* config/i386/sfp-exceptions.c (DarwinMode): Set
	arbitrarily to DF mode (the strong_alias macros is
	not used here).
	* config/i386/sfp-machine.h: Adjust strong_alias macro
	so that the type can be provided per case.
	* soft-fp/eqdf2.c (DarwinMode): Set to DF mode.
	* soft-fp/eqhf2.c (DarwinMode): Set to HF mode.
	* soft-fp/eqsf2.c (DarwinMode): Set to SF mode.
	* soft-fp/eqtf2.c (DarwinMode): Set to TF mode.
	* soft-fp/gedf2.c (DarwinMode): Set to DF mode.
	* soft-fp/gesf2.c (DarwinMode): Set to SF mode.
	* soft-fp/getf2.c (DarwinMode): Set to TF mode.
	* soft-fp/ledf2.c (DarwinMode): Set to DF mode.
	* soft-fp/lesf2.c (DarwinMode): Set to SF mode.
	* soft-fp/letf2.c (DarwinMode): Set to TF mode.
---
 libgcc/config/i386/sfp-exceptions.c | 1 +
 libgcc/config/i386/sfp-machine.h    | 9 ++++++---
 libgcc/soft-fp/eqdf2.c              | 1 +
 libgcc/soft-fp/eqhf2.c              | 1 +
 libgcc/soft-fp/eqsf2.c              | 1 +
 libgcc/soft-fp/eqtf2.c              | 1 +
 libgcc/soft-fp/gedf2.c              | 1 +
 libgcc/soft-fp/gesf2.c              | 1 +
 libgcc/soft-fp/getf2.c              | 1 +
 libgcc/soft-fp/ledf2.c              | 1 +
 libgcc/soft-fp/lesf2.c              | 1 +
 libgcc/soft-fp/letf2.c              | 1 +
 12 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/libgcc/config/i386/sfp-exceptions.c b/libgcc/config/i386/sfp-exceptions.c
index edb6a57bb35..7431cf93e33 100644
--- a/libgcc/config/i386/sfp-exceptions.c
+++ b/libgcc/config/i386/sfp-exceptions.c
@@ -22,6 +22,7 @@
  */
 
 #ifndef _SOFT_FLOAT
+#define DarwinMode DF
 #include "sfp-machine.h"
 
 struct fenv
diff --git a/libgcc/config/i386/sfp-machine.h b/libgcc/config/i386/sfp-machine.h
index f15d29d3755..2cb6119b8f8 100644
--- a/libgcc/config/i386/sfp-machine.h
+++ b/libgcc/config/i386/sfp-machine.h
@@ -75,10 +75,13 @@ void __sfp_handle_exceptions (int);
 
 /* Define ALIASNAME as a strong alias for NAME.  */
 #if defined __MACH__
-/* Mach-O doesn't support aliasing.  If these functions ever return
-   anything but CMPtype we need to revisit this... */
+/* Mach-O doesn't support aliasing, so we build a secondary function for
+   the alias - this needs the type of the arguments to be provided as
+   DarwinFtype.  If these functions ever return anything but CMPtype
+   we need to revisit this... */
 #define strong_alias(name, aliasname) \
-  CMPtype aliasname (TFtype a, TFtype b) { return name(a, b); }
+  typedef float DarwinFtype __attribute__((mode (DarwinMode))); \
+  CMPtype aliasname (DarwinFtype a, DarwinFtype b) { return name(a, b); }
 #else
 # define strong_alias(name, aliasname) _strong_alias(name, aliasname)
 # define _strong_alias(name, aliasname) \
diff --git a/libgcc/soft-fp/eqdf2.c b/libgcc/soft-fp/eqdf2.c
index 2a44ee377ce..a3bb664f5f1 100644
--- a/libgcc/soft-fp/eqdf2.c
+++ b/libgcc/soft-fp/eqdf2.c
@@ -28,6 +28,7 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#define DarwinMode DF
 #include "soft-fp.h"
 #include "double.h"
 
diff --git a/libgcc/soft-fp/eqhf2.c b/libgcc/soft-fp/eqhf2.c
index 6d6634e5c54..73a3b0a13d8 100644
--- a/libgcc/soft-fp/eqhf2.c
+++ b/libgcc/soft-fp/eqhf2.c
@@ -26,6 +26,7 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#define DarwinMode HF
 #include "soft-fp.h"
 #include "half.h"
 
diff --git a/libgcc/soft-fp/eqsf2.c b/libgcc/soft-fp/eqsf2.c
index c515044d7bf..84f3ba63958 100644
--- a/libgcc/soft-fp/eqsf2.c
+++ b/libgcc/soft-fp/eqsf2.c
@@ -28,6 +28,7 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#define DarwinMode SF
 #include "soft-fp.h"
 #include "single.h"
 
diff --git a/libgcc/soft-fp/eqtf2.c b/libgcc/soft-fp/eqtf2.c
index 5feac41a0de..3a44e006943 100644
--- a/libgcc/soft-fp/eqtf2.c
+++ b/libgcc/soft-fp/eqtf2.c
@@ -28,6 +28,7 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#define DarwinMode TF
 #include "soft-fp.h"
 #include "quad.h"
 
diff --git a/libgcc/soft-fp/gedf2.c b/libgcc/soft-fp/gedf2.c
index bcefb61aa80..551356a0ea4 100644
--- a/libgcc/soft-fp/gedf2.c
+++ b/libgcc/soft-fp/gedf2.c
@@ -28,6 +28,7 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#define DarwinMode DF
 #include "soft-fp.h"
 #include "double.h"
 
diff --git a/libgcc/soft-fp/gesf2.c b/libgcc/soft-fp/gesf2.c
index 22f0b6a24be..57cae4c3fd7 100644
--- a/libgcc/soft-fp/gesf2.c
+++ b/libgcc/soft-fp/gesf2.c
@@ -28,6 +28,7 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#define DarwinMode SF
 #include "soft-fp.h"
 #include "single.h"
 
diff --git a/libgcc/soft-fp/getf2.c b/libgcc/soft-fp/getf2.c
index 6c7e38f36fc..3b23c17322e 100644
--- a/libgcc/soft-fp/getf2.c
+++ b/libgcc/soft-fp/getf2.c
@@ -28,6 +28,7 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#define DarwinMode TF
 #include "soft-fp.h"
 #include "quad.h"
 
diff --git a/libgcc/soft-fp/ledf2.c b/libgcc/soft-fp/ledf2.c
index c36148e2f12..ecf05ce1554 100644
--- a/libgcc/soft-fp/ledf2.c
+++ b/libgcc/soft-fp/ledf2.c
@@ -28,6 +28,7 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#define DarwinMode DF
 #include "soft-fp.h"
 #include "double.h"
 
diff --git a/libgcc/soft-fp/lesf2.c b/libgcc/soft-fp/lesf2.c
index e3233535c8f..e0105600592 100644
--- a/libgcc/soft-fp/lesf2.c
+++ b/libgcc/soft-fp/lesf2.c
@@ -28,6 +28,7 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#define DarwinMode SF
 #include "soft-fp.h"
 #include "single.h"
 
diff --git a/libgcc/soft-fp/letf2.c b/libgcc/soft-fp/letf2.c
index 43d9f77bca9..80bfa085e70 100644
--- a/libgcc/soft-fp/letf2.c
+++ b/libgcc/soft-fp/letf2.c
@@ -28,6 +28,7 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#define DarwinMode TF
 #include "soft-fp.h"
 #include "quad.h"
 
--
Joseph Myers Sept. 2, 2021, 7:45 p.m. UTC | #7
One of the committed changes breaks the build of libgcc for 32-bit x86 
configurations without SSE2 enabled by default:

In file included from /scratch/jmyers/glibc-bot/src/gcc/libgcc/soft-fp/extendhfsf2.c:31:
/scratch/jmyers/glibc-bot/src/gcc/libgcc/soft-fp/half.h:62:1: error: unable to emulate 'HF'
   62 | typedef float HFtype __attribute__ ((mode (HF)));
      | ^~~~~~~

(this showed up with my glibc bot building for i686-gnu).

Such a configuration should still support HFmode when you build user code 
with appropriate options.  I.e., the functions in question do need to be 
built into libgcc, so that user code can link against them, so you need to 
arrange for an explicit -msse2 to be used when building the HFmode libgcc 
functions (but not any other libgcc functions).
Joseph Myers Sept. 2, 2021, 8:03 p.m. UTC | #8
On Thu, 2 Sep 2021, Iain Sandoe via Gcc-patches wrote:

> diff --git a/libgcc/soft-fp/eqdf2.c b/libgcc/soft-fp/eqdf2.c
> index 2a44ee377ce..a3bb664f5f1 100644
> --- a/libgcc/soft-fp/eqdf2.c
> +++ b/libgcc/soft-fp/eqdf2.c
> @@ -28,6 +28,7 @@
>     License along with the GNU C Library; if not, see
>     <http://www.gnu.org/licenses/>.  */
>  
> +#define DarwinMode DF
>  #include "soft-fp.h"
>  #include "double.h"

All these files are supposed to be taken unmodified from glibc.  They 
shouldn't contain any OS-specific code, such as a define of DarwinMode.  
sfp-machine.h, however, is libgcc-local, hence putting the definition of 
strong_alias there.

So you need some other way to extract the argument type of name in order 
to use it in a declaration of aliasname.  E.g.

__typeof (_Generic (name,
                    CMPtype (*) (HFtype, HFtype): (HFtype) 0,
                    CMPtype (*) (SFtype, SFtype): (SFtype) 0,
                    CMPtype (*) (DFtype, DFtype): (DFtype) 0,
                    CMPtype (*) (TFtype, TFtype): (TFtype) 0))

Now in fact I think the include ordering means none of the *type macros 
are defined here.  But if you do e.g.

typedef float alias_SFtype __attribute__ ((mode (SF)));

and similar, you could use alias_SFtype in the above.  And so keep the 
changes to the Darwin-specific parts of the libgcc-local sfp-machine.h.
Iain Sandoe Sept. 3, 2021, 7:51 a.m. UTC | #9
Hi Joseph,

> On 2 Sep 2021, at 21:03, Joseph Myers <joseph@codesourcery.com> wrote:
> 
> On Thu, 2 Sep 2021, Iain Sandoe via Gcc-patches wrote:
> 
>> diff --git a/libgcc/soft-fp/eqdf2.c b/libgcc/soft-fp/eqdf2.c
>> index 2a44ee377ce..a3bb664f5f1 100644
>> --- a/libgcc/soft-fp/eqdf2.c
>> +++ b/libgcc/soft-fp/eqdf2.c
>> @@ -28,6 +28,7 @@
>>    License along with the GNU C Library; if not, see
>>    <http://www.gnu.org/licenses/>.  */
>> 
>> +#define DarwinMode DF
>> #include "soft-fp.h"
>> #include "double.h"
> 
> All these files are supposed to be taken unmodified from glibc.  They 
> shouldn't contain any OS-specific code, such as a define of DarwinMode.  
> sfp-machine.h, however, is libgcc-local, hence putting the definition of 
> strong_alias there.

OK, that makes sense.
> 
> So you need some other way to extract the argument type of name in order 
> to use it in a declaration of aliasname.  E.g.
> 
> __typeof (_Generic (name,
>                    CMPtype (*) (HFtype, HFtype): (HFtype) 0,
>                    CMPtype (*) (SFtype, SFtype): (SFtype) 0,
>                    CMPtype (*) (DFtype, DFtype): (DFtype) 0,
>                    CMPtype (*) (TFtype, TFtype): (TFtype) 0))

thanks for the suggestion

> Now in fact I think the include ordering means none of the *type macros 
> are defined here.  But if you do e.g.
> 
> typedef float alias_SFtype __attribute__ ((mode (SF)));
> 
> and similar, you could use alias_SFtype in the above.  And so keep the 
> changes to the Darwin-specific parts of the libgcc-local sfp-machine.h.

this is what I’m testing - OK if it bootstraps on x86_64-darwin, linux?

thanks
Iain


[PATCH] libgcc, soft-float: Fix strong_alias macro use for Darwin.

Darwin does not support strong symbol aliases and a work-
around is provided in sfp-machine.h where a second function
is created that simply calls the original.  However this
needs the arguments to the synthesized function to track
the mode of the original function.

So the fix here is to match known floating point modes from
the incoming function and apply the one found to the new
function args.

The matching is highly specific to the current set of modes
and will need adjusting should more cases be added.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>

libgcc/ChangeLog:

	* config/i386/sfp-machine.h (alias_HFtype, alias_SFtype
	alias_DFtype, alias_TFtype): New.
	(ALIAS_SELECTOR): New.
	(strong_alias): Use __typeof and a _Generic selector to
	provide the type to the synthesized function.
---
 libgcc/config/i386/sfp-machine.h | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/libgcc/config/i386/sfp-machine.h b/libgcc/config/i386/sfp-machine.h
index f15d29d3755..172ebc70c8d 100644
--- a/libgcc/config/i386/sfp-machine.h
+++ b/libgcc/config/i386/sfp-machine.h
@@ -75,10 +75,24 @@ void __sfp_handle_exceptions (int);
 
 /* Define ALIASNAME as a strong alias for NAME.  */
 #if defined __MACH__
-/* Mach-O doesn't support aliasing.  If these functions ever return
-   anything but CMPtype we need to revisit this... */
+/* Mach-O doesn't support aliasing, so we build a secondary function for
+   the alias - we need to do a bit of a dance to find out what the type of
+   the arguments is and then apply that to the secondary function.
+   If these functions ever return anything but CMPtype we need to revisit
+   this... */
+typedef float alias_HFtype __attribute__ ((mode (HF)));
+typedef float alias_SFtype __attribute__ ((mode (SF)));
+typedef float alias_DFtype __attribute__ ((mode (DF)));
+typedef float alias_TFtype __attribute__ ((mode (TF)));
+#define ALIAS_SELECTOR \
+  CMPtype (*) (alias_HFtype, alias_HFtype): (alias_HFtype) 0, \
+  CMPtype (*) (alias_SFtype, alias_SFtype): (alias_SFtype) 0, \
+  CMPtype (*) (alias_DFtype, alias_DFtype): (alias_DFtype) 0, \
+  CMPtype (*) (alias_TFtype, alias_TFtype): (alias_TFtype) 0
 #define strong_alias(name, aliasname) \
-  CMPtype aliasname (TFtype a, TFtype b) { return name(a, b); }
+  CMPtype aliasname (__typeof (_Generic (name, ALIAS_SELECTOR)) a, \
+		     __typeof (_Generic (name, ALIAS_SELECTOR)) b) \
+		    { return name (a, b); }
 #else
 # define strong_alias(name, aliasname) _strong_alias(name, aliasname)
 # define _strong_alias(name, aliasname) \
--
Iain Sandoe Sept. 3, 2021, 3:33 p.m. UTC | #10
> On 3 Sep 2021, at 08:51, Iain Sandoe <idsandoe@googlemail.com> wrote:
> 
> 
>> On 2 Sep 2021, at 21:03, Joseph Myers <joseph@codesourcery.com> wrote:
>> 
>> On Thu, 2 Sep 2021, Iain Sandoe via Gcc-patches wrote:
>> 
>>> diff --git a/libgcc/soft-fp/eqdf2.c b/libgcc/soft-fp/eqdf2.c
>>> index 2a44ee377ce..a3bb664f5f1 100644
>>> --- a/libgcc/soft-fp/eqdf2.c
>>> +++ b/libgcc/soft-fp/eqdf2.c
>>> @@ -28,6 +28,7 @@
>>>   License along with the GNU C Library; if not, see
>>>   <http://www.gnu.org/licenses/>.  */
>>> 
>>> +#define DarwinMode DF
>>> #include "soft-fp.h"
>>> #include "double.h"
>> 
>> All these files are supposed to be taken unmodified from glibc.  They 
>> shouldn't contain any OS-specific code, such as a define of DarwinMode.  
>> sfp-machine.h, however, is libgcc-local, hence putting the definition of 
>> strong_alias there.
> 
> OK, that makes sense.
>> 
>> So you need some other way to extract the argument type of name in order 
>> to use it in a declaration of aliasname.  E.g.
>> 
>> __typeof (_Generic (name,
>>                   CMPtype (*) (HFtype, HFtype): (HFtype) 0,
>>                   CMPtype (*) (SFtype, SFtype): (SFtype) 0,
>>                   CMPtype (*) (DFtype, DFtype): (DFtype) 0,
>>                   CMPtype (*) (TFtype, TFtype): (TFtype) 0))
> 
> thanks for the suggestion
> 
>> Now in fact I think the include ordering means none of the *type macros 
>> are defined here.  But if you do e.g.
>> 
>> typedef float alias_SFtype __attribute__ ((mode (SF)));
>> 
>> and similar, you could use alias_SFtype in the above.  And so keep the 
>> changes to the Darwin-specific parts of the libgcc-local sfp-machine.h.
> 
> this is what I’m testing - OK if it bootstraps on x86_64-darwin, linux?

(those bootstraps were sucessful)

given that:

a) this fixes Darwin x86-64 bootstrap which has been broken for more than 24h
b) the patch is now Darwin-local.

I’ve pushed the patch below to fix the bootstrap break - but if there are any futher 
recommendations I’m happy to apply a follow-on.  It seems that there will be more
changes for the half-float support anyway,

thanks
Iain

> 
> thanks
> Iain
> 
> 
> [PATCH] libgcc, soft-float: Fix strong_alias macro use for Darwin.
> 
> Darwin does not support strong symbol aliases and a work-
> around is provided in sfp-machine.h where a second function
> is created that simply calls the original.  However this
> needs the arguments to the synthesized function to track
> the mode of the original function.
> 
> So the fix here is to match known floating point modes from
> the incoming function and apply the one found to the new
> function args.
> 
> The matching is highly specific to the current set of modes
> and will need adjusting should more cases be added.
> 
> Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
> 
> libgcc/ChangeLog:
> 
> 	* config/i386/sfp-machine.h (alias_HFtype, alias_SFtype
> 	alias_DFtype, alias_TFtype): New.
> 	(ALIAS_SELECTOR): New.
> 	(strong_alias): Use __typeof and a _Generic selector to
> 	provide the type to the synthesized function.
> ---
> libgcc/config/i386/sfp-machine.h | 20 +++++++++++++++++---
> 1 file changed, 17 insertions(+), 3 deletions(-)
> 
> diff --git a/libgcc/config/i386/sfp-machine.h b/libgcc/config/i386/sfp-machine.h
> index f15d29d3755..172ebc70c8d 100644
> --- a/libgcc/config/i386/sfp-machine.h
> +++ b/libgcc/config/i386/sfp-machine.h
> @@ -75,10 +75,24 @@ void __sfp_handle_exceptions (int);
> 
> /* Define ALIASNAME as a strong alias for NAME.  */
> #if defined __MACH__
> -/* Mach-O doesn't support aliasing.  If these functions ever return
> -   anything but CMPtype we need to revisit this... */
> +/* Mach-O doesn't support aliasing, so we build a secondary function for
> +   the alias - we need to do a bit of a dance to find out what the type of
> +   the arguments is and then apply that to the secondary function.
> +   If these functions ever return anything but CMPtype we need to revisit
> +   this... */
> +typedef float alias_HFtype __attribute__ ((mode (HF)));
> +typedef float alias_SFtype __attribute__ ((mode (SF)));
> +typedef float alias_DFtype __attribute__ ((mode (DF)));
> +typedef float alias_TFtype __attribute__ ((mode (TF)));
> +#define ALIAS_SELECTOR \
> +  CMPtype (*) (alias_HFtype, alias_HFtype): (alias_HFtype) 0, \
> +  CMPtype (*) (alias_SFtype, alias_SFtype): (alias_SFtype) 0, \
> +  CMPtype (*) (alias_DFtype, alias_DFtype): (alias_DFtype) 0, \
> +  CMPtype (*) (alias_TFtype, alias_TFtype): (alias_TFtype) 0
> #define strong_alias(name, aliasname) \
> -  CMPtype aliasname (TFtype a, TFtype b) { return name(a, b); }
> +  CMPtype aliasname (__typeof (_Generic (name, ALIAS_SELECTOR)) a, \
> +		     __typeof (_Generic (name, ALIAS_SELECTOR)) b) \
> +		    { return name (a, b); }
> #else
> # define strong_alias(name, aliasname) _strong_alias(name, aliasname)
> # define _strong_alias(name, aliasname) \
> -- 
>
Joseph Myers Sept. 21, 2021, 8:11 p.m. UTC | #11
On Fri, 3 Sep 2021, Iain Sandoe wrote:

> given that:
> 
> a) this fixes Darwin x86-64 bootstrap which has been broken for more than 24h
> b) the patch is now Darwin-local.

Actually, it's not Darwin-local.  It uses __MACH__, which is also defined 
for Hurd.  And because sfp-machine.h gets included in files that aren't 
specific to HFmode (and so aren't built with explicit -msse2), the build 
for i686-gnu fails with:

In file included from /scratch/jmyers/glibc-bot/src/gcc/libgcc/config/i386/sfp-exceptions.c:25:
/scratch/jmyers/glibc-bot/src/gcc/libgcc/config/i386/sfp-machine.h:83:1: error: unable to emulate 'HF'
   83 | typedef float alias_HFtype __attribute__ ((mode (HF)));
      | ^~~~~~~

I think some conditional that is genuinely Darwin-specific should be used, 
so that Hurd keeps using normal ELF aliases and doesn't get these HFmode 
references in sfp-machine.h at all.
Iain Sandoe Sept. 21, 2021, 8:25 p.m. UTC | #12
Hello Joseph,

> On 21 Sep 2021, at 21:11, Joseph Myers <joseph@codesourcery.com> wrote:
> 
> On Fri, 3 Sep 2021, Iain Sandoe wrote:
> 
>> given that:
>> 
>> a) this fixes Darwin x86-64 bootstrap which has been broken for more than 24h
>> b) the patch is now Darwin-local.
> 
> Actually, it's not Darwin-local.  It uses __MACH__, which is also defined 
> for Hurd.  And because sfp-machine.h gets included in files that aren't 
> specific to HFmode (and so aren't built with explicit -msse2), the build 
> for i686-gnu fails with:
> 
> In file included from /scratch/jmyers/glibc-bot/src/gcc/libgcc/config/i386/sfp-exceptions.c:25:
> /scratch/jmyers/glibc-bot/src/gcc/libgcc/config/i386/sfp-machine.h:83:1: error: unable to emulate 'HF'
>   83 | typedef float alias_HFtype __attribute__ ((mode (HF)));
>      | ^~~~~~~
> 
> I think some conditional that is genuinely Darwin-specific should be used, 
> so that Hurd keeps using normal ELF aliases and doesn't get these HFmode 
> references in sfp-machine.h at all.

Sorry about this, (I usually use __APPLE__ as the flag, but the __MACH__ was already there
in this case, I think).

I’ll fix this by s/__MACH__/__APPLE__/ 
since in this case we definitely mean Mach-O rather than anything to do with the micro-kernel...
(tomorrow now).

Note, that I have a suspicion that there are (maybe a small number of) other places in the code where __MACH__ has been taken to mean mach-o is in use.

thanks
Iain
Iain Sandoe Sept. 22, 2021, 7:08 a.m. UTC | #13
Hi Joseph, Thomas,

> On 21 Sep 2021, at 21:11, Joseph Myers <joseph@codesourcery.com> wrote:
> 
> On Fri, 3 Sep 2021, Iain Sandoe wrote:
> 
>> given that:
>> 
>> a) this fixes Darwin x86-64 bootstrap which has been broken for more than 24h
>> b) the patch is now Darwin-local.
> 
> Actually, it's not Darwin-local.  It uses __MACH__, which is also defined 
> for Hurd.  And because sfp-machine.h gets included in files that aren't 
> specific to HFmode (and so aren't built with explicit -msse2), the build 
> for i686-gnu fails with:

Fixed for master with:

https://gcc.gnu.org/pipermail/gcc-cvs/2021-September/353935.html

However, note that the use of __MACH__ to guard the Mach-O code has been
there for a long time (it is present in all open branches).  So it's possible that has
been silently doing the wrong thing for some time,

So maybe the fix at r12-3777-g578b7687338 should be back-ported?

thanks
Iain
Joseph Myers Sept. 22, 2021, 7:50 p.m. UTC | #14
On Wed, 22 Sep 2021, Iain Sandoe wrote:

> However, note that the use of __MACH__ to guard the Mach-O code has been
> there for a long time (it is present in all open branches).  So it's possible that has
> been silently doing the wrong thing for some time,

That's "wrong thing" as in having previously been suboptimal; the 
semantics of the function aliases would still have been correct (until the 
HFmode changes introduced a build failure), it would just have been less 
efficient for them to be wrappers rather than proper aliases.