(root)/
gcc-13.2.0/
libgcc/
config/
rs6000/
_mulkc3.c
       1  /* Copyright (C) 1989-2023 Free Software Foundation, Inc.
       2  
       3  This file is part of GCC.
       4  
       5  GCC is free software; you can redistribute it and/or modify it under
       6  the terms of the GNU General Public License as published by the Free
       7  Software Foundation; either version 3, or (at your option) any later
       8  version.
       9  
      10  GCC is distributed in the hope that it will be useful, but WITHOUT ANY
      11  WARRANTY; without even the implied warranty of MERCHANTABILITY or
      12  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
      13  for more details.
      14  
      15  Under Section 7 of GPL version 3, you are granted additional
      16  permissions described in the GCC Runtime Library Exception, version
      17  3.1, as published by the Free Software Foundation.
      18  
      19  You should have received a copy of the GNU General Public License and
      20  a copy of the GCC Runtime Library Exception along with this program;
      21  see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
      22  <http://www.gnu.org/licenses/>.  */
      23  
      24  /* This is a temporary specialization of code from libgcc/libgcc2.c.  */
      25  
      26  #include "soft-fp.h"
      27  #include "quad-float128.h"
      28  
      29  /* Use the correct built-in function based on whether TFmode is _Float128 or
      30     long double.  See quad-float128.h for more details.  */
      31  #ifndef __LONG_DOUBLE_IEEE128__
      32  #define COPYSIGN(x,y) __builtin_copysignf128 (x, y)
      33  #define INFINITY __builtin_inff128 ()
      34  
      35  #else
      36  #define COPYSIGN(x,y) __builtin_copysignl (x, y)
      37  #define INFINITY __builtin_infl ()
      38  #endif
      39  
      40  #define isnan __builtin_isnan
      41  #define isinf __builtin_isinf
      42  
      43  #if defined(FLOAT128_HW_INSNS) && !defined(__mulkc3)
      44  #define __mulkc3 __mulkc3_sw
      45  #endif
      46  
      47  TCtype
      48  __mulkc3 (TFtype a, TFtype b, TFtype c, TFtype d)
      49  {
      50    TFtype ac, bd, ad, bc, x, y;
      51    TCtype res;
      52  
      53    ac = a * c;
      54    bd = b * d;
      55    ad = a * d;
      56    bc = b * c;
      57  
      58    x = ac - bd;
      59    y = ad + bc;
      60  
      61    if (isnan (x) && isnan (y))
      62      {
      63        /* Recover infinities that computed as NaN + iNaN.  */
      64        _Bool recalc = 0;
      65        if (isinf (a) || isinf (b))
      66  	{
      67  	  /* z is infinite.  "Box" the infinity and change NaNs in
      68  	     the other factor to 0.  */
      69  	  a = COPYSIGN (isinf (a) ? 1 : 0, a);
      70  	  b = COPYSIGN (isinf (b) ? 1 : 0, b);
      71  	  if (isnan (c)) c = COPYSIGN (0, c);
      72  	  if (isnan (d)) d = COPYSIGN (0, d);
      73            recalc = 1;
      74  	}
      75       if (isinf (c) || isinf (d))
      76  	{
      77  	  /* w is infinite.  "Box" the infinity and change NaNs in
      78  	     the other factor to 0.  */
      79  	  c = COPYSIGN (isinf (c) ? 1 : 0, c);
      80  	  d = COPYSIGN (isinf (d) ? 1 : 0, d);
      81  	  if (isnan (a)) a = COPYSIGN (0, a);
      82  	  if (isnan (b)) b = COPYSIGN (0, b);
      83  	  recalc = 1;
      84  	}
      85       if (!recalc
      86  	  && (isinf (ac) || isinf (bd)
      87  	      || isinf (ad) || isinf (bc)))
      88  	{
      89  	  /* Recover infinities from overflow by changing NaNs to 0.  */
      90  	  if (isnan (a)) a = COPYSIGN (0, a);
      91  	  if (isnan (b)) b = COPYSIGN (0, b);
      92  	  if (isnan (c)) c = COPYSIGN (0, c);
      93  	  if (isnan (d)) d = COPYSIGN (0, d);
      94  	  recalc = 1;
      95  	}
      96        if (recalc)
      97  	{
      98  	  x = INFINITY * (a * c - b * d);
      99  	  y = INFINITY * (a * d + b * c);
     100  	}
     101      }
     102  
     103    __real__ res = x;
     104    __imag__ res = y;
     105    return res;
     106  }
     107