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