On Thu, Jul 1, 2021 at 1:48 PM liuhongt <hongtao....@intel.com> wrote:
>
> 1. Add extendhftf2, extendhfxf2, truncxfhf2, trunctfhf2, fixhfti,
> fixunshfti, floattihf and floatuntihf.
> 2. Always add _divhc3.c and _mulhc3.c.  If assembler doesn't support
> AVX512FP16, they are empty.
>
> 2019-01-01  H.J. Lu <hongjiu...@intel.com>
> gcc/ChangeLog:
>
>         * optabs-query.c (get_best_extraction_insn): Adjust smallest_int_mode
>         for HFmode.
>
> libgcc/ChangeLog:
>
>         * Makefile.in: Adjust to support avx512fp16.
>         * config.host: Adjust tmake_file to omit host_address value.
>         * config/i386/32/sfp-machine.h (_FP_NANFRAC_H): Add for _Float16.
>         * config/i386/64/sfp-machine.h (_FP_NANFRAC_H): Likewise.
>         * config/i386/sfp-machine.h (_FP_NANSIGN_H): Define.
>         * config/i386/t-softfp: Add divhc3, mulhc3, extendhftf2, extendhfxf2,
>         truncxfhf2 and trunctfhf2.
>         * configure: Regenerate.
>         * configure.ac: Add check for AVX512FP16.
>         * config/i386/64/t-softfp: New file to add fixhfti, fixunshfti,
>         floattihf and floatuntihf,
>         * config/i386/_divhc3.c: New file to add divhc3.
>         * config/i386/_mulhc3.c: New file to add mulhc3.
>         * soft-fp/extendhfxf2.c: New file to add extendhfxf2.
>         * soft-fp/truncxfhf2.c: New file to add truncxfhf2.
> ---
>  gcc/optabs-query.c                  |  9 ++++-
>  libgcc/Makefile.in                  |  4 ++-
>  libgcc/config.host                  |  6 +---
>  libgcc/config/i386/32/sfp-machine.h |  1 +
>  libgcc/config/i386/64/sfp-machine.h |  1 +
>  libgcc/config/i386/64/t-softfp      |  9 +++++
>  libgcc/config/i386/_divhc3.c        |  4 +++
>  libgcc/config/i386/_mulhc3.c        |  4 +++
>  libgcc/config/i386/sfp-machine.h    |  1 +
>  libgcc/config/i386/t-softfp         | 20 +++++++++++
>  libgcc/configure                    | 33 ++++++++++++++++++
>  libgcc/configure.ac                 | 13 +++++++
>  libgcc/soft-fp/extendhfxf2.c        | 53 +++++++++++++++++++++++++++++
>  libgcc/soft-fp/truncxfhf2.c         | 52 ++++++++++++++++++++++++++++
>  14 files changed, 203 insertions(+), 7 deletions(-)
>  create mode 100644 libgcc/config/i386/64/t-softfp
>  create mode 100644 libgcc/config/i386/_divhc3.c
>  create mode 100644 libgcc/config/i386/_mulhc3.c
>  create mode 100644 libgcc/soft-fp/extendhfxf2.c
>  create mode 100644 libgcc/soft-fp/truncxfhf2.c
>
> diff --git a/gcc/optabs-query.c b/gcc/optabs-query.c
> index 3248ce2c06e..a59cb5607d1 100644
> --- a/gcc/optabs-query.c
> +++ b/gcc/optabs-query.c
> @@ -205,7 +205,14 @@ get_best_extraction_insn (extraction_insn *insn,
>                           machine_mode field_mode)
>  {
>    opt_scalar_int_mode mode_iter;
> -  FOR_EACH_MODE_FROM (mode_iter, smallest_int_mode_for_size (struct_bits))
> +  scalar_int_mode smallest_int_mode;
> +  /* FIXME: validate_subreg only allows (subreg:WORD_MODE (reg:HF) 0). */
> +  if (FLOAT_MODE_P (field_mode)
> +      && known_eq (GET_MODE_SIZE (field_mode), 2))
> +    smallest_int_mode = word_mode;
> +  else
> +    smallest_int_mode = smallest_int_mode_for_size (struct_bits);
> +  FOR_EACH_MODE_FROM (mode_iter, smallest_int_mode)
>      {
>        scalar_int_mode mode = mode_iter.require ();
>        if (get_extraction_insn (insn, pattern, type, mode))
> diff --git a/libgcc/Makefile.in b/libgcc/Makefile.in
> index 2c8be561eb5..4452b821a5e 100644
> --- a/libgcc/Makefile.in
> +++ b/libgcc/Makefile.in
> @@ -51,6 +51,8 @@ md_unwind_header = @md_unwind_header@
>  sfp_machine_header = @sfp_machine_header@
>  thread_header = @thread_header@
>
> +have_as_avx512fp16 = @have_as_avx512fp16@
> +
>  host_noncanonical = @host_noncanonical@
>  real_host_noncanonical = @real_host_noncanonical@
>  target_noncanonical = @target_noncanonical@
> @@ -314,7 +316,7 @@ MULTIOSSUBDIR := $(shell if test $(MULTIOSDIR) != .; then 
> echo /$(MULTIOSDIR); f
>  inst_libdir = $(libsubdir)$(MULTISUBDIR)
>  inst_slibdir = $(slibdir)$(MULTIOSSUBDIR)
>
> -gcc_compile_bare = $(CC) $(INTERNAL_CFLAGS)
> +gcc_compile_bare = $(CC) $(INTERNAL_CFLAGS) $(CFLAGS-$(<F))
>  compile_deps = -MT $@ -MD -MP -MF $(basename $@).dep
>  gcc_compile = $(gcc_compile_bare) -o $@ $(compile_deps)
>  gcc_s_compile = $(gcc_compile) -DSHARED
> diff --git a/libgcc/config.host b/libgcc/config.host
> index 50f00062232..3f16b547810 100644
> --- a/libgcc/config.host
> +++ b/libgcc/config.host
> @@ -1539,11 +1539,7 @@ i[34567]86-*-elfiamcu | i[34567]86-*-rtems*)
>         # These use soft-fp for SFmode and DFmode, not just TFmode.
>         ;;
>  i[34567]86-*-* | x86_64-*-*)
> -       tmake_file="${tmake_file} t-softfp-tf"
> -       if test "${host_address}" = 32; then
> -               tmake_file="${tmake_file} i386/${host_address}/t-softfp"
> -       fi
> -       tmake_file="${tmake_file} i386/t-softfp t-softfp"
> +       tmake_file="${tmake_file} t-softfp-tf i386/${host_address}/t-softfp 
> i386/t-softfp t-softfp"
>         ;;
>  esac
>
> diff --git a/libgcc/config/i386/32/sfp-machine.h 
> b/libgcc/config/i386/32/sfp-machine.h
> index 1fa282d7afe..e24cbc8d180 100644
> --- a/libgcc/config/i386/32/sfp-machine.h
> +++ b/libgcc/config/i386/32/sfp-machine.h
> @@ -86,6 +86,7 @@
>  #define _FP_DIV_MEAT_D(R,X,Y)   _FP_DIV_MEAT_2_udiv(D,R,X,Y)
>  #define _FP_DIV_MEAT_Q(R,X,Y)   _FP_DIV_MEAT_4_udiv(Q,R,X,Y)
>
> +#define _FP_NANFRAC_H          _FP_QNANBIT_H
>  #define _FP_NANFRAC_S          _FP_QNANBIT_S
>  #define _FP_NANFRAC_D          _FP_QNANBIT_D, 0
>  /* Even if XFmode is 12byte,  we have to pad it to
> diff --git a/libgcc/config/i386/64/sfp-machine.h 
> b/libgcc/config/i386/64/sfp-machine.h
> index 1ff94c23ea4..e1c616699bb 100644
> --- a/libgcc/config/i386/64/sfp-machine.h
> +++ b/libgcc/config/i386/64/sfp-machine.h
> @@ -13,6 +13,7 @@ typedef unsigned int UTItype __attribute__ ((mode (TI)));
>
>  #define _FP_DIV_MEAT_Q(R,X,Y)   _FP_DIV_MEAT_2_udiv(Q,R,X,Y)
>
> +#define _FP_NANFRAC_H          _FP_QNANBIT_H
>  #define _FP_NANFRAC_S          _FP_QNANBIT_S
>  #define _FP_NANFRAC_D          _FP_QNANBIT_D
>  #define _FP_NANFRAC_E          _FP_QNANBIT_E, 0
> diff --git a/libgcc/config/i386/64/t-softfp b/libgcc/config/i386/64/t-softfp
> new file mode 100644
> index 00000000000..44db2e5aebe
> --- /dev/null
> +++ b/libgcc/config/i386/64/t-softfp
> @@ -0,0 +1,9 @@
> +ifeq ($(have_as_avx512fp16),yes)
> +# Add the following HFmode functions to static libgcc2.
> +hf-extras := fixhfti.c fixunshfti.c floattihf.c floatuntihf.c
> +
> +CFLAGS-fixhfti.c += -mavx512fp16
> +CFLAGS-fixunshfti.c += -mavx512fp16
> +CFLAGS-floattihf.c += -mavx512fp16
> +CFLAGS-floatuntihf.c += -mavx512fp16
> +endif
> diff --git a/libgcc/config/i386/_divhc3.c b/libgcc/config/i386/_divhc3.c
> new file mode 100644
> index 00000000000..b2e5b0cfc7d
> --- /dev/null
> +++ b/libgcc/config/i386/_divhc3.c
> @@ -0,0 +1,4 @@
> +#ifdef __AVX512FP16__
> +#define L_divhc3
> +#include "libgcc2.c"
> +#endif
> diff --git a/libgcc/config/i386/_mulhc3.c b/libgcc/config/i386/_mulhc3.c
> new file mode 100644
> index 00000000000..90af0ead882
> --- /dev/null
> +++ b/libgcc/config/i386/_mulhc3.c
> @@ -0,0 +1,4 @@
> +#ifdef __AVX512FP16__
> +#define L_mulhc3
> +#include "libgcc2.c"
> +#endif
> diff --git a/libgcc/config/i386/sfp-machine.h 
> b/libgcc/config/i386/sfp-machine.h
> index 8319f0550bc..f15d29d3755 100644
> --- a/libgcc/config/i386/sfp-machine.h
> +++ b/libgcc/config/i386/sfp-machine.h
> @@ -17,6 +17,7 @@ typedef int __gcc_CMPtype __attribute__ ((mode 
> (__libgcc_cmp_return__)));
>  #define _FP_KEEPNANFRACP       1
>  #define _FP_QNANNEGATEDP 0
>
> +#define _FP_NANSIGN_H          1
>  #define _FP_NANSIGN_S          1
>  #define _FP_NANSIGN_D          1
>  #define _FP_NANSIGN_E          1
> diff --git a/libgcc/config/i386/t-softfp b/libgcc/config/i386/t-softfp
> index 685d9cf8502..d9cfa36ca90 100644
> --- a/libgcc/config/i386/t-softfp
> +++ b/libgcc/config/i386/t-softfp
> @@ -1 +1,21 @@
>  LIB2ADD += $(srcdir)/config/i386/sfp-exceptions.c
> +
> +# Replace _divhc3 and _mulhc3.
> +libgcc2-hf-functions = _divhc3 _mulhc3
> +LIB2FUNCS_EXCLUDE += $(libgcc2-hf-functions)
> +libgcc2-hf-extras = $(addsuffix .c, $(libgcc2-hf-functions))
> +LIB2ADD_ST += $(addprefix $(srcdir)/config/i386/, $(libgcc2-hf-extras))
> +
> +ifeq ($(have_as_avx512fp16),yes)
> +# Add the following HFmode functions to static libgcc2.
> +hf-extras += extendhfxf2.c extendhftf2.c truncxfhf2.c trunctfhf2.c
> +LIB2ADD_ST += $(addprefix $(srcdir)/soft-fp/, $(hf-extras))
> +
> +CFLAGS-extendhfxf2.c += -mavx512fp16
> +CFLAGS-extendhftf2.c += -mavx512fp16
> +CFLAGS-truncxfhf2.c += -mavx512fp16
> +CFLAGS-trunctfhf2.c += -mavx512fp16
> +
> +CFLAGS-_divhc3.c += -mavx512fp16
> +CFLAGS-_mulhc3.c += -mavx512fp16
> +endif
> diff --git a/libgcc/configure b/libgcc/configure
> index 4919a56f518..503019f020c 100755
> --- a/libgcc/configure
> +++ b/libgcc/configure
> @@ -605,6 +605,7 @@ solaris_ld_v2_maps
>  real_host_noncanonical
>  accel_dir_suffix
>  use_tm_clone_registry
> +have_as_avx512fp16
>  force_explicit_eh_registry
>  CET_FLAGS
>  fixed_point
> @@ -5302,6 +5303,38 @@ $as_echo "$libgcc_cv_powerpc_3_1_float128_hw" >&6; }
>    CFLAGS="$saved_CFLAGS"
>  esac
>
> +case "${target}" in
> +i[34567]86-*-* | x86_64-*-*)
> +  { $as_echo "$as_me:${as_lineno-$LINENO}: checking if the assembler 
> supports AVX512FP16" >&5
> +$as_echo_n "checking if the assembler supports AVX512FP16... " >&6; }
> +if ${libgcc_cv_as_avx512fp16+:} false; then :
> +  $as_echo_n "(cached) " >&6
> +else
> +  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
> +/* end confdefs.h.  */
> +
> +int
> +main ()
> +{
> +asm("vmovsh %xmm0, %xmm0, %xmm1");
> +  ;
> +  return 0;
> +}
> +_ACEOF
> +if ac_fn_c_try_compile "$LINENO"; then :
> +  libgcc_cv_as_avx512fp16=yes
> +else
> +  libgcc_cv_as_avx512fp16=no
> +fi
> +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
> +fi
> +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libgcc_cv_as_avx512fp16" 
> >&5
> +$as_echo "$libgcc_cv_as_avx512fp16" >&6; }
> +  ;;
> +esac
> +have_as_avx512fp16=$libgcc_cv_as_avx512fp16
> +
> +
>  # Collect host-machine-specific information.
>  . ${srcdir}/config.host
>
> diff --git a/libgcc/configure.ac b/libgcc/configure.ac
> index 13a80b2551b..a45374891df 100644
> --- a/libgcc/configure.ac
> +++ b/libgcc/configure.ac
> @@ -485,6 +485,19 @@ powerpc*-*-linux*)
>    CFLAGS="$saved_CFLAGS"
>  esac
>
> +case "${target}" in
> +dnl Check if as supports AVX512FP16 instructions.
> +i[[34567]]86-*-* | x86_64-*-*)
> +  AC_CACHE_CHECK([if the assembler supports AVX512FP16],
> +                [libgcc_cv_as_avx512fp16],
> +                [AC_TRY_COMPILE([], [asm("vmovsh %xmm0, %xmm0, %xmm1");],
> +                [libgcc_cv_as_avx512fp16=yes],
> +                [libgcc_cv_as_avx512fp16=no])])
> +  ;;
> +esac
> +have_as_avx512fp16=$libgcc_cv_as_avx512fp16
> +AC_SUBST(have_as_avx512fp16)
> +
>  # Collect host-machine-specific information.
>  . ${srcdir}/config.host
>
> diff --git a/libgcc/soft-fp/extendhfxf2.c b/libgcc/soft-fp/extendhfxf2.c
> new file mode 100644
> index 00000000000..2a11e109dc5
> --- /dev/null
> +++ b/libgcc/soft-fp/extendhfxf2.c
> @@ -0,0 +1,53 @@
> +/* Software floating-point emulation.
> +   Return an IEEE half converted to IEEE extended.
> +   Copyright (C) 2019 Free Software Foundation, Inc.
> +   This file is part of the GNU C Library.
> +
> +   The GNU C Library is free software; you can redistribute it and/or
> +   modify it under the terms of the GNU Lesser General Public
> +   License as published by the Free Software Foundation; either
> +   version 2.1 of the License, or (at your option) any later version.
> +
> +   In addition to the permissions in the GNU Lesser General Public
> +   License, the Free Software Foundation gives you unlimited
> +   permission to link the compiled version of this file into
> +   combinations with other programs, and to distribute those
> +   combinations without any restriction coming from the use of this
> +   file.  (The Lesser General Public License restrictions do apply in
> +   other respects; for example, they cover modification of the file,
> +   and distribution when not linked into a combine executable.)
> +
> +   The GNU C Library is distributed in the hope that it will be useful,
> +   but WITHOUT ANY WARRANTY; without even the implied warranty of
> +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> +   Lesser General Public License for more details.
> +
> +   You should have received a copy of the GNU Lesser General Public
> +   License along with the GNU C Library; if not, see
> +   <http://www.gnu.org/licenses/>.  */
> +
> +#define FP_NO_EXACT_UNDERFLOW
> +#include "soft-fp.h"
> +#include "half.h"
> +#include "extended.h"
> +
> +XFtype
> +__extendhfxf2 (HFtype a)
> +{
> +  FP_DECL_EX;
> +  FP_DECL_H (A);
> +  FP_DECL_E (R);
> +  XFtype r;
> +
> +  FP_INIT_EXCEPTIONS;
> +  FP_UNPACK_RAW_H (A, a);
> +#if _FP_W_TYPE_SIZE < 64
> +  FP_EXTEND (E, H, 4, 1, R, A);
> +#else
> +  FP_EXTEND (E, H, 2, 1, R, A);
> +#endif
> +  FP_PACK_RAW_E (r, R);
> +  FP_HANDLE_EXCEPTIONS;
> +
> +  return r;
> +}
> diff --git a/libgcc/soft-fp/truncxfhf2.c b/libgcc/soft-fp/truncxfhf2.c
> new file mode 100644
> index 00000000000..8d80a1f5129
> --- /dev/null
> +++ b/libgcc/soft-fp/truncxfhf2.c
> @@ -0,0 +1,52 @@
> +/* Software floating-point emulation.
> +   Truncate IEEE extended into IEEE half.
> +   Copyright (C) 2019 Free Software Foundation, Inc.
> +   This file is part of the GNU C Library.
> +
> +   The GNU C Library is free software; you can redistribute it and/or
> +   modify it under the terms of the GNU Lesser General Public
> +   License as published by the Free Software Foundation; either
> +   version 2.1 of the License, or (at your option) any later version.
> +
> +   In addition to the permissions in the GNU Lesser General Public
> +   License, the Free Software Foundation gives you unlimited
> +   permission to link the compiled version of this file into
> +   combinations with other programs, and to distribute those
> +   combinations without any restriction coming from the use of this
> +   file.  (The Lesser General Public License restrictions do apply in
> +   other respects; for example, they cover modification of the file,
> +   and distribution when not linked into a combine executable.)
> +
> +   The GNU C Library is distributed in the hope that it will be useful,
> +   but WITHOUT ANY WARRANTY; without even the implied warranty of
> +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> +   Lesser General Public License for more details.
> +
> +   You should have received a copy of the GNU Lesser General Public
> +   License along with the GNU C Library; if not, see
> +   <http://www.gnu.org/licenses/>.  */
> +
> +#include "soft-fp.h"
> +#include "half.h"
> +#include "extended.h"
> +
> +HFtype
> +__truncxfhf2 (XFtype a)
> +{
> +  FP_DECL_EX;
> +  FP_DECL_E (A);
> +  FP_DECL_H (R);
> +  HFtype r;
> +
> +  FP_INIT_ROUNDMODE;
> +  FP_UNPACK_SEMIRAW_E (A, a);
> +#if _FP_W_TYPE_SIZE < 64
> +  FP_TRUNC (H, E, 1, 4, R, A);
> +#else
> +  FP_TRUNC (H, E, 1, 2, R, A);
> +#endif
> +  FP_PACK_SEMIRAW_H (r, R);
> +  FP_HANDLE_EXCEPTIONS;
> +
> +  return r;
> +}
> --
> 2.18.1
>


-- 
BR,
Hongtao

Reply via email to