1 /* Copyright (C) 1989-2018 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 #include "soft-fp.h"
25 #include "quad-float128.h"
26 
27 /* __powikf3 can be compiled 3 different ways:
28 
29    1) If the assembler does not have support for the IEEE 128-bit insns
30    (xsaddqp, etc.) it is just compiled as __powikf2.
31 
32    2) If the assembler has IEEE 128-bit floating point support, and __powikf2
33    is not previously defined, it is defined as __powikf2_sw.
34 
35    3) If the assembler has IEEE 128-bit floating point support, and __powikf2
36    is included by _powikf2-hw.c, which defines __powikf2 as __powikf2_hw.  The
37    __powikf2_hw.c is compiled with -mcpu=power9 and it automatically uses the
38    IEEE 128-bit instructions.
39 
40    For #2/#3, float128-ifunc.c defines an ifunc function for __powikf2, that
41    will use the software version on power7/power8 systems, and the hardware
42    version on power9 systems.
43 
44    The code is cloned from the code in libgcc2.c (which handles the standard
45    SF, DF, TF, and XF types).  */
46 
47 #if defined(FLOAT128_HW_INSNS) && !defined(__powikf2)
48 #define __powikf2 __powikf2_sw
49 #endif
50 
51 TFtype
__powikf2(TFtype x,SItype_ppc m)52 __powikf2 (TFtype x, SItype_ppc m)
53 {
54   unsigned int n = m < 0 ? -m : m;
55   TFtype y = n % 2 ? x : 1;
56   while (n >>= 1)
57     {
58       x = x * x;
59       if (n % 2)
60 	y = y * x;
61     }
62   return m < 0 ? 1/y : y;
63 }
64