]> gcc.gnu.org Git - gcc.git/commit
Make __float128 use the _Float128 type, PR target/107299.
authorMichael Meissner <meissner@linux.ibm.com>
Wed, 9 Nov 2022 05:37:37 +0000 (00:37 -0500)
committerMichael Meissner <meissner@linux.ibm.com>
Thu, 17 Nov 2022 21:49:37 +0000 (16:49 -0500)
commitf95e05f7f6a08eab88230aa851f3bc82358b0f14
treeeef28d5935c44a156b3d456c9d7d7333855941ed
parentca41137547d9361f00a2bdafdf1c8dbe6068e1cc
Make __float128 use the _Float128 type, PR target/107299.

This patch fixes the issue that GCC cannot build when the default long double
is IEEE 128-bit.  It fails in building libgcc, specifically when it is trying
to buld the __mulkc3 function in libgcc.  It is failing in gimple-range-fold.cc
during the evrp pass.  Ultimately it is failing because the code declared the
type to use TFmode but it used F128 functions (i.e. KFmode).

typedef float TFtype __attribute__((mode (TF)));
typedef __complex float TCtype __attribute__((mode (TC)));

TCtype
__mulkc3_sw (TFtype a, TFtype b, TFtype c, TFtype d)
{
  TFtype ac, bd, ad, bc, x, y;
  TCtype res;

  ac = a * c;
  bd = b * d;
  ad = a * d;
  bc = b * c;

  x = ac - bd;
  y = ad + bc;

  if (__builtin_isnan (x) && __builtin_isnan (y))
    {
      _Bool recalc = 0;
      if (__builtin_isinf (a) || __builtin_isinf (b))
{

  a = __builtin_copysignf128 (__builtin_isinf (a) ? 1 : 0, a);
  b = __builtin_copysignf128 (__builtin_isinf (b) ? 1 : 0, b);
  if (__builtin_isnan (c))
    c = __builtin_copysignf128 (0, c);
  if (__builtin_isnan (d))
    d = __builtin_copysignf128 (0, d);
  recalc = 1;
}
      if (__builtin_isinf (c) || __builtin_isinf (d))
{

  c = __builtin_copysignf128 (__builtin_isinf (c) ? 1 : 0, c);
  d = __builtin_copysignf128 (__builtin_isinf (d) ? 1 : 0, d);
  if (__builtin_isnan (a))
    a = __builtin_copysignf128 (0, a);
  if (__builtin_isnan (b))
    b = __builtin_copysignf128 (0, b);
  recalc = 1;
}
      if (!recalc
  && (__builtin_isinf (ac) || __builtin_isinf (bd)
      || __builtin_isinf (ad) || __builtin_isinf (bc)))
{

  if (__builtin_isnan (a))
    a = __builtin_copysignf128 (0, a);
  if (__builtin_isnan (b))
    b = __builtin_copysignf128 (0, b);
  if (__builtin_isnan (c))
    c = __builtin_copysignf128 (0, c);
  if (__builtin_isnan (d))
    d = __builtin_copysignf128 (0, d);
  recalc = 1;
}
      if (recalc)
{
  x = __builtin_inff128 () * (a * c - b * d);
  y = __builtin_inff128 () * (a * d + b * c);
}
    }

  __real__ res = x;
  __imag__ res = y;
  return res;
}

Currently GCC uses the long double type node for __float128 if long double is
IEEE 128-bit.  It did not use the node for _Float128.

Originally this was noticed if you call the nansq function to make a signaling
NaN (nansq is mapped to nansf128).  Because the type node for _Float128 is
different from __float128, the machine independent code converts signaling NaNs
to quiet NaNs if the types are not compatible.  The following tests used to
fail when run on a system where long double is IEEE 128-bit:

gcc.dg/torture/float128-nan.c
gcc.target/powerpc/nan128-1.c

This patch makes both __float128 and _Float128 use the same type node.

One side effect of not using the long double type node for __float128 is that we
must only use KFmode for _Float128/__float128.  The libstdc++ library won't
build if we use TFmode for _Float128 and __float128 when long double is IEEE
128-bit.

Another minor side effect is that the f128 round to odd fused multiply-add
function will not merge negatition with the FMA operation when the type is long
double.  If the type is __float128 or _Float128, then it will continue to do the
optimization.  The round to odd functions are defined in terms of __float128
arguments.  For example:

long double
do_fms (long double a, long double b, long double c)
{
    return __builtin_fmaf128_round_to_odd (a, b, -c);
}

will generate (assuming -mabi=ieeelongdouble):

xsnegqp 4,4
xsmaddqpo 4,2,3
xxlor 34,36,36

while:

__float128
do_fms (__float128 a, __float128 b, __float128 c)
{
    return __builtin_fmaf128_round_to_odd (a, b, -c);
}

will generate:

xsmsubqpo 4,2,3
xxlor 34,36,36

I tested all 3 patchs for PR target/107299 on:

    1) LE Power10 using --with-cpu=power10 --with-long-double-format=ieee
    2) LE Power10 using --with-cpu=power10 --with-long-double-format=ibm
    3) LE Power9  using --with-cpu=power9  --with-long-double-format=ibm
    4) BE Power8  using --with-cpu=power8  --with-long-double-format=ibm

Once all 3 patches have been applied, we can once again build GCC when long
double is IEEE 128-bit.  There were no other regressions with these patches.
Can I check these patches into the trunk?

2022-11-09   Michael Meissner  <meissner@linux.ibm.com>

gcc/

PR target/107299
* config/rs6000/rs6000-builtin.cc (rs6000_init_builtins): Always use the
_Float128 type for __float128.
(rs6000_expand_builtin): Only change a KFmode built-in to TFmode, if the
built-in passes or returns TFmode.  If the predicate failed because the
modes were different, use convert_move to load up the value instead of
copy_to_mode_reg.
* config/rs6000/rs6000.cc (rs6000_translate_mode_attribute): Don't
translate IEEE 128-bit floating point modes to explicit IEEE 128-bit
modes (KFmode or KCmode), even if long double is IEEE 128-bit.
(rs6000_libgcc_floating_mode_supported_p): Support KFmode all of the
time if we support IEEE 128-bit floating point.
(rs6000_floatn_mode): _Float128 and _Float128x always uses KFmode.

gcc/testsuite/

PR target/107299
* gcc.target/powerpc/float128-hw12.c: New test.
* gcc.target/powerpc/float128-hw13.c: Likewise.
* gcc.target/powerpc/float128-hw4.c: Update insns.
gcc/config/rs6000/rs6000-builtin.cc
gcc/config/rs6000/rs6000.cc
gcc/testsuite/gcc.target/powerpc/float128-hw12.c [new file with mode: 0644]
gcc/testsuite/gcc.target/powerpc/float128-hw13.c [new file with mode: 0644]
gcc/testsuite/gcc.target/powerpc/float128-hw4.c
This page took 0.069869 seconds and 6 git commands to generate.