[03/10,i386] libgcc: Enable hfmode soft-sf/df/xf/tf extensions and truncations.

Message ID 20210721074347.7689-4-hongtao.liu@intel.com
State New
Headers show
Series
  • Initial support for AVX512FP16
Related show

Commit Message

Jason Merrill via Gcc-patches July 21, 2021, 7:43 a.m.
gcc/ChangeLog:

	* optabs-query.c (get_best_extraction_insn): Use word_mode for
	HF field.

libgcc/ChangeLog:

	* config/i386/32/sfp-machine.h (_FP_NANFRAC_H): New macro.
	* config/i386/64/sfp-machine.h (_FP_NANFRAC_H): Ditto.
	* config/i386/sfp-machine.h (_FP_NANSIGN_H): Ditto.
	* config/i386/t-softfp: Add hf soft-fp.
	* config.host: Add i386/64/t-softfp.
	* config/i386/64/t-softfp: New file.
---
 gcc/optabs-query.c                  | 10 +++++++++-
 libgcc/config.host                  |  5 +----
 libgcc/config/i386/32/sfp-machine.h |  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 +++++
 7 files changed, 19 insertions(+), 5 deletions(-)
 create mode 100644 libgcc/config/i386/64/t-softfp

-- 
2.18.1

Comments

Jason Merrill via Gcc-patches July 21, 2021, 10:51 a.m. | #1
On Wed, Jul 21, 2021 at 9:43 AM liuhongt <hongtao.liu@intel.com> wrote:
>

> gcc/ChangeLog:

>

>         * optabs-query.c (get_best_extraction_insn): Use word_mode for

>         HF field.

>

> libgcc/ChangeLog:

>

>         * config/i386/32/sfp-machine.h (_FP_NANFRAC_H): New macro.

>         * config/i386/64/sfp-machine.h (_FP_NANFRAC_H): Ditto.

>         * config/i386/sfp-machine.h (_FP_NANSIGN_H): Ditto.

>         * config/i386/t-softfp: Add hf soft-fp.

>         * config.host: Add i386/64/t-softfp.

>         * config/i386/64/t-softfp: New file.


OK for the x86 part, but please take care of newline at the end of
files to avoid:

> \ No newline at end of file


Thanks,
Uros.

> ---

>  gcc/optabs-query.c                  | 10 +++++++++-

>  libgcc/config.host                  |  5 +----

>  libgcc/config/i386/32/sfp-machine.h |  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 +++++

>  7 files changed, 19 insertions(+), 5 deletions(-)

>  create mode 100644 libgcc/config/i386/64/t-softfp

>

> diff --git a/gcc/optabs-query.c b/gcc/optabs-query.c

> index 05ee5f517da..0438e451474 100644

> --- a/gcc/optabs-query.c

> +++ b/gcc/optabs-query.c

> @@ -205,7 +205,15 @@ 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/config.host b/libgcc/config.host

> index 50f00062232..96da9ef1cce 100644

> --- a/libgcc/config.host

> +++ b/libgcc/config.host

> @@ -1540,10 +1540,7 @@ i[34567]86-*-elfiamcu | i[34567]86-*-rtems*)

>         ;;

>  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} 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..d812bb120bd

> --- /dev/null

> +++ b/libgcc/config/i386/64/t-softfp

> @@ -0,0 +1 @@

> +softfp_extras := fixhfti fixunshfti floattihf floatuntihf

> \ No newline at end of file

> 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..4ac214eb0ce 100644

> --- a/libgcc/config/i386/t-softfp

> +++ b/libgcc/config/i386/t-softfp

> @@ -1 +1,6 @@

>  LIB2ADD += $(srcdir)/config/i386/sfp-exceptions.c

> +

> +softfp_extensions := hfsf hfdf hftf hfxf sfdf sftf dftf xftf

> +softfp_truncations := tfhf xfhf dfhf sfhf tfsf dfsf tfdf tfxf

> +

> +softfp_extras += eqhf2

> \ No newline at end of file

> --

> 2.18.1

>
Jason Merrill via Gcc-patches July 22, 2021, 12:14 p.m. | #2
On Wed, Jul 21, 2021 at 9:43 AM liuhongt <hongtao.liu@intel.com> wrote:
>

> gcc/ChangeLog:

>

>         * optabs-query.c (get_best_extraction_insn): Use word_mode for

>         HF field.

>

> libgcc/ChangeLog:

>

>         * config/i386/32/sfp-machine.h (_FP_NANFRAC_H): New macro.

>         * config/i386/64/sfp-machine.h (_FP_NANFRAC_H): Ditto.

>         * config/i386/sfp-machine.h (_FP_NANSIGN_H): Ditto.

>         * config/i386/t-softfp: Add hf soft-fp.

>         * config.host: Add i386/64/t-softfp.

>         * config/i386/64/t-softfp: New file.

> ---

>  gcc/optabs-query.c                  | 10 +++++++++-

>  libgcc/config.host                  |  5 +----

>  libgcc/config/i386/32/sfp-machine.h |  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 +++++

>  7 files changed, 19 insertions(+), 5 deletions(-)

>  create mode 100644 libgcc/config/i386/64/t-softfp

>

> diff --git a/gcc/optabs-query.c b/gcc/optabs-query.c

> index 05ee5f517da..0438e451474 100644

> --- a/gcc/optabs-query.c

> +++ b/gcc/optabs-query.c

> @@ -205,7 +205,15 @@ 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). */


I think that needs "fixing" then, or alternatively the caller should care.

> +  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/config.host b/libgcc/config.host

> index 50f00062232..96da9ef1cce 100644

> --- a/libgcc/config.host

> +++ b/libgcc/config.host

> @@ -1540,10 +1540,7 @@ i[34567]86-*-elfiamcu | i[34567]86-*-rtems*)

>         ;;

>  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} 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..d812bb120bd

> --- /dev/null

> +++ b/libgcc/config/i386/64/t-softfp

> @@ -0,0 +1 @@

> +softfp_extras := fixhfti fixunshfti floattihf floatuntihf

> \ No newline at end of file

> 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..4ac214eb0ce 100644

> --- a/libgcc/config/i386/t-softfp

> +++ b/libgcc/config/i386/t-softfp

> @@ -1 +1,6 @@

>  LIB2ADD += $(srcdir)/config/i386/sfp-exceptions.c

> +

> +softfp_extensions := hfsf hfdf hftf hfxf sfdf sftf dftf xftf

> +softfp_truncations := tfhf xfhf dfhf sfhf tfsf dfsf tfdf tfxf

> +

> +softfp_extras += eqhf2

> \ No newline at end of file

> --

> 2.18.1

>
Jason Merrill via Gcc-patches July 27, 2021, 5:32 a.m. | #3
On Thu, Jul 22, 2021 at 8:14 PM Richard Biener
<richard.guenther@gmail.com> wrote:
>

> On Wed, Jul 21, 2021 at 9:43 AM liuhongt <hongtao.liu@intel.com> wrote:

> >

> > gcc/ChangeLog:

> >

> >         * optabs-query.c (get_best_extraction_insn): Use word_mode for

> >         HF field.

> >

> > libgcc/ChangeLog:

> >

> >         * config/i386/32/sfp-machine.h (_FP_NANFRAC_H): New macro.

> >         * config/i386/64/sfp-machine.h (_FP_NANFRAC_H): Ditto.

> >         * config/i386/sfp-machine.h (_FP_NANSIGN_H): Ditto.

> >         * config/i386/t-softfp: Add hf soft-fp.

> >         * config.host: Add i386/64/t-softfp.

> >         * config/i386/64/t-softfp: New file.

> > ---

> >  gcc/optabs-query.c                  | 10 +++++++++-

> >  libgcc/config.host                  |  5 +----

> >  libgcc/config/i386/32/sfp-machine.h |  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 +++++

> >  7 files changed, 19 insertions(+), 5 deletions(-)

> >  create mode 100644 libgcc/config/i386/64/t-softfp

> >

> > diff --git a/gcc/optabs-query.c b/gcc/optabs-query.c

> > index 05ee5f517da..0438e451474 100644

> > --- a/gcc/optabs-query.c

> > +++ b/gcc/optabs-query.c

> > @@ -205,7 +205,15 @@ 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). */

>

> I think that needs "fixing" then, or alternatively the caller should care.

>

How about this

modified   gcc/emit-rtl.c
@@ -928,6 +928,10 @@ validate_subreg (machine_mode omode, machine_mode imode,
      fix them all.  */
   if (omode == word_mode)
     ;
+  /* ???Similarly like (subreg:DI (reg:SF), also allow (subreg:SI (reg:HF))
+     here. Though extract_bit_field is the culprit here, not the backends.  */
+  else if (imode == HFmode && omode == SImode)
+    ;
   /* ??? Similarly, e.g. with (subreg:DF (reg:TI)).  Though store_bit_field
      is the culprit here, and not the backends.  */
   else if (known_ge (osize, regsize) && known_ge (isize, osize))
new file   gcc/testsuite/gcc.target/i386/float16-5.c
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-options "-msse2 -O2" } */
+_Float16
+foo (int a)
+{
+  union {
+    int a;
+    _Float16 b;
+  }c;
+  c.a = a;
+  return c.b;
+}

If it's ok, I'll merge the upper change to the former commit:
"[PATCH 02/10] [i386] Enable _Float16 type for TARGET_SSE2 and above."

> > +  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/config.host b/libgcc/config.host

> > index 50f00062232..96da9ef1cce 100644

> > --- a/libgcc/config.host

> > +++ b/libgcc/config.host

> > @@ -1540,10 +1540,7 @@ i[34567]86-*-elfiamcu | i[34567]86-*-rtems*)

> >         ;;

> >  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} 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..d812bb120bd

> > --- /dev/null

> > +++ b/libgcc/config/i386/64/t-softfp

> > @@ -0,0 +1 @@

> > +softfp_extras := fixhfti fixunshfti floattihf floatuntihf

> > \ No newline at end of file

> > 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..4ac214eb0ce 100644

> > --- a/libgcc/config/i386/t-softfp

> > +++ b/libgcc/config/i386/t-softfp

> > @@ -1 +1,6 @@

> >  LIB2ADD += $(srcdir)/config/i386/sfp-exceptions.c

> > +

> > +softfp_extensions := hfsf hfdf hftf hfxf sfdf sftf dftf xftf

> > +softfp_truncations := tfhf xfhf dfhf sfhf tfsf dfsf tfdf tfxf

> > +

> > +softfp_extras += eqhf2

> > \ No newline at end of file

> > --

> > 2.18.1

> >




-- 
BR,
Hongtao
Joseph Myers July 29, 2021, 8:57 p.m. | #4
On Tue, 27 Jul 2021, Hongtao Liu via Gcc-patches wrote:

> modified   gcc/emit-rtl.c

> @@ -928,6 +928,10 @@ validate_subreg (machine_mode omode, machine_mode imode,

>       fix them all.  */

>    if (omode == word_mode)

>      ;

> +  /* ???Similarly like (subreg:DI (reg:SF), also allow (subreg:SI (reg:HF))

> +     here. Though extract_bit_field is the culprit here, not the backends.  */

> +  else if (imode == HFmode && omode == SImode)

> +    ;


You can't reference HFmode by name at all in any target-independent file, 
outside of a #ifdef HAVE_HFmode conditional.  It's only defined in 
architecture-specific <arch>-modes.def for those architectures supporting 
that mode, so you'll have an undefined identifier building for other 
targets if you reference it in a generic source file.  You have to 
condition things on the logical properties of the mode that are relevant, 
not on the target-specific name (or use a HAVE_HFmode conditional, but 
basing things on logical properties is clearly better where possible).

-- 
Joseph S. Myers
joseph@codesourcery.com
Jason Merrill via Gcc-patches Aug. 2, 2021, 5:10 a.m. | #5
On Fri, Jul 30, 2021 at 4:58 AM Joseph Myers <joseph@codesourcery.com> wrote:
>

> On Tue, 27 Jul 2021, Hongtao Liu via Gcc-patches wrote:

>

> > modified   gcc/emit-rtl.c

> > @@ -928,6 +928,10 @@ validate_subreg (machine_mode omode, machine_mode imode,

> >       fix them all.  */

> >    if (omode == word_mode)

> >      ;

> > +  /* ???Similarly like (subreg:DI (reg:SF), also allow (subreg:SI (reg:HF))

> > +     here. Though extract_bit_field is the culprit here, not the backends.  */

> > +  else if (imode == HFmode && omode == SImode)

> > +    ;

>

> You can't reference HFmode by name at all in any target-independent file,

> outside of a #ifdef HAVE_HFmode conditional.  It's only defined in

> architecture-specific <arch>-modes.def for those architectures supporting

> that mode, so you'll have an undefined identifier building for other

> targets if you reference it in a generic source file.  You have to

> condition things on the logical properties of the mode that are relevant,

> not on the target-specific name (or use a HAVE_HFmode conditional, but

> basing things on logical properties is clearly better where possible).

>

Yes, I didn't notice that, thanks for the explanation.
And I guess the same logic is also applies to BFmode(or other 16bit
float mode) if it existed, so add something like

modified   gcc/emit-rtl.c
@@ -928,6 +928,11 @@ validate_subreg (machine_mode omode, machine_mode imode,
      fix them all.  */
   if (omode == word_mode)
     ;
+  /* ???Similarly like (subreg:DI (reg:SF), also allow (subreg:SI (reg:HF))
+     here. Though extract_bit_field is the culprit here, not the backends.  */
+  else if (known_gt (regsize, osize) && known_gt (osize, isize)
+    && FLOAT_MODE_P (imode) && INTEGRAL_MODE_P (omode))
+    ;
> --

> Joseph S. Myers

> joseph@codesourcery.com




-- 
BR,
Hongtao

Patch

diff --git a/gcc/optabs-query.c b/gcc/optabs-query.c
index 05ee5f517da..0438e451474 100644
--- a/gcc/optabs-query.c
+++ b/gcc/optabs-query.c
@@ -205,7 +205,15 @@  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/config.host b/libgcc/config.host
index 50f00062232..96da9ef1cce 100644
--- a/libgcc/config.host
+++ b/libgcc/config.host
@@ -1540,10 +1540,7 @@  i[34567]86-*-elfiamcu | i[34567]86-*-rtems*)
 	;;
 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} 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..d812bb120bd
--- /dev/null
+++ b/libgcc/config/i386/64/t-softfp
@@ -0,0 +1 @@ 
+softfp_extras := fixhfti fixunshfti floattihf floatuntihf
\ No newline at end of file
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..4ac214eb0ce 100644
--- a/libgcc/config/i386/t-softfp
+++ b/libgcc/config/i386/t-softfp
@@ -1 +1,6 @@ 
 LIB2ADD += $(srcdir)/config/i386/sfp-exceptions.c
+
+softfp_extensions := hfsf hfdf hftf hfxf sfdf sftf dftf xftf
+softfp_truncations := tfhf xfhf dfhf sfhf tfsf dfsf tfdf tfxf
+
+softfp_extras += eqhf2
\ No newline at end of file