136ac495dSmrg /* Automatic switching between software and hardware IEEE 128-bit
236ac495dSmrg floating-point emulation for PowerPC.
336ac495dSmrg
4*8feb0f0bSmrg Copyright (C) 2016-2020 Free Software Foundation, Inc.
536ac495dSmrg This file is part of the GNU C Library.
636ac495dSmrg Contributed by Michael Meissner (meissner@linux.vnet.ibm.com)
736ac495dSmrg Code is based on the main soft-fp library written by:
836ac495dSmrg Richard Henderson (rth@cygnus.com) and
936ac495dSmrg Jakub Jelinek (jj@ultra.linux.cz).
1036ac495dSmrg
1136ac495dSmrg The GNU C Library is free software; you can redistribute it and/or
1236ac495dSmrg modify it under the terms of the GNU Lesser General Public
1336ac495dSmrg License as published by the Free Software Foundation; either
1436ac495dSmrg version 2.1 of the License, or (at your option) any later version.
1536ac495dSmrg
1636ac495dSmrg In addition to the permissions in the GNU Lesser General Public
1736ac495dSmrg License, the Free Software Foundation gives you unlimited
1836ac495dSmrg permission to link the compiled version of this file into
1936ac495dSmrg combinations with other programs, and to distribute those
2036ac495dSmrg combinations without any restriction coming from the use of this
2136ac495dSmrg file. (The Lesser General Public License restrictions do apply in
2236ac495dSmrg other respects; for example, they cover modification of the file,
2336ac495dSmrg and distribution when not linked into a combine executable.)
2436ac495dSmrg
2536ac495dSmrg The GNU C Library is distributed in the hope that it will be useful,
2636ac495dSmrg but WITHOUT ANY WARRANTY; without even the implied warranty of
2736ac495dSmrg MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2836ac495dSmrg Lesser General Public License for more details.
2936ac495dSmrg
3036ac495dSmrg You should have received a copy of the GNU Lesser General Public
3136ac495dSmrg License along with the GNU C Library; if not, see
3236ac495dSmrg <http://www.gnu.org/licenses/>. */
3336ac495dSmrg
3436ac495dSmrg #include <soft-fp.h>
3536ac495dSmrg #include <quad-float128.h>
3636ac495dSmrg #include <string.h>
3736ac495dSmrg #include <stdlib.h>
3836ac495dSmrg #include <ctype.h>
3936ac495dSmrg
4036ac495dSmrg #ifndef FLOAT128_HW_INSNS
4136ac495dSmrg #error "float128-ifunc.c needs access to ISA 3.0 instructions and ifunc"
4236ac495dSmrg #endif
4336ac495dSmrg
4436ac495dSmrg #ifdef __FLOAT128_HARDWARE__
4536ac495dSmrg #error "This module must not be compiled with IEEE 128-bit hardware support"
4636ac495dSmrg #endif
4736ac495dSmrg
4836ac495dSmrg #define SW_OR_HW(SW, HW) (__builtin_cpu_supports ("ieee128") ? HW : SW)
4936ac495dSmrg
5036ac495dSmrg /* Resolvers. */
5136ac495dSmrg
5236ac495dSmrg /* We do not provide ifunc resolvers for __fixkfti, __fixunskfti, __floattikf,
5336ac495dSmrg and __floatuntikf. There is no ISA 3.0 instruction that converts between
5436ac495dSmrg 128-bit integer types and 128-bit IEEE floating point, or vice versa. So
5536ac495dSmrg use the emulator functions for these conversions. */
5636ac495dSmrg
57a2dc1f3fSmrg static __typeof__ (__addkf3_sw) *
__addkf3_resolve(void)5836ac495dSmrg __addkf3_resolve (void)
5936ac495dSmrg {
60a2dc1f3fSmrg return SW_OR_HW (__addkf3_sw, __addkf3_hw);
6136ac495dSmrg }
6236ac495dSmrg
63a2dc1f3fSmrg static __typeof__ (__subkf3_sw) *
__subkf3_resolve(void)6436ac495dSmrg __subkf3_resolve (void)
6536ac495dSmrg {
66a2dc1f3fSmrg return SW_OR_HW (__subkf3_sw, __subkf3_hw);
6736ac495dSmrg }
6836ac495dSmrg
69a2dc1f3fSmrg static __typeof__ (__mulkf3_sw) *
__mulkf3_resolve(void)7036ac495dSmrg __mulkf3_resolve (void)
7136ac495dSmrg {
72a2dc1f3fSmrg return SW_OR_HW (__mulkf3_sw, __mulkf3_hw);
7336ac495dSmrg }
7436ac495dSmrg
75a2dc1f3fSmrg static __typeof__ (__divkf3_sw) *
__divkf3_resolve(void)7636ac495dSmrg __divkf3_resolve (void)
7736ac495dSmrg {
78a2dc1f3fSmrg return SW_OR_HW (__divkf3_sw, __divkf3_hw);
7936ac495dSmrg }
8036ac495dSmrg
81a2dc1f3fSmrg static __typeof__ (__negkf2_sw) *
__negkf2_resolve(void)8236ac495dSmrg __negkf2_resolve (void)
8336ac495dSmrg {
84a2dc1f3fSmrg return SW_OR_HW (__negkf2_sw, __negkf2_hw);
8536ac495dSmrg }
8636ac495dSmrg
87a2dc1f3fSmrg static __typeof__ (__powikf2_sw) *
__powikf2_resolve(void)88a2dc1f3fSmrg __powikf2_resolve (void)
89a2dc1f3fSmrg {
90a2dc1f3fSmrg return SW_OR_HW (__powikf2_sw, __powikf2_hw);
91a2dc1f3fSmrg }
92a2dc1f3fSmrg
93a2dc1f3fSmrg static __typeof__ (__floatsikf_sw) *
__floatsikf_resolve(void)9436ac495dSmrg __floatsikf_resolve (void)
9536ac495dSmrg {
96a2dc1f3fSmrg return SW_OR_HW (__floatsikf_sw, __floatsikf_hw);
9736ac495dSmrg }
9836ac495dSmrg
99a2dc1f3fSmrg static __typeof__ (__floatdikf_sw) *
__floatdikf_resolve(void)10036ac495dSmrg __floatdikf_resolve (void)
10136ac495dSmrg {
102a2dc1f3fSmrg return SW_OR_HW (__floatdikf_sw, __floatdikf_hw);
10336ac495dSmrg }
10436ac495dSmrg
105a2dc1f3fSmrg static __typeof__ (__floatunsikf_sw) *
__floatunsikf_resolve(void)10636ac495dSmrg __floatunsikf_resolve (void)
10736ac495dSmrg {
108a2dc1f3fSmrg return SW_OR_HW (__floatunsikf_sw, __floatunsikf_hw);
10936ac495dSmrg }
11036ac495dSmrg
111a2dc1f3fSmrg static __typeof__ (__floatundikf_sw) *
__floatundikf_resolve(void)11236ac495dSmrg __floatundikf_resolve (void)
11336ac495dSmrg {
114a2dc1f3fSmrg return SW_OR_HW (__floatundikf_sw, __floatundikf_hw);
11536ac495dSmrg }
11636ac495dSmrg
117a2dc1f3fSmrg static __typeof__ (__fixkfsi_sw) *
__fixkfsi_resolve(void)11836ac495dSmrg __fixkfsi_resolve (void)
11936ac495dSmrg {
120a2dc1f3fSmrg return SW_OR_HW (__fixkfsi_sw, __fixkfsi_hw);
12136ac495dSmrg }
12236ac495dSmrg
123a2dc1f3fSmrg static __typeof__ (__fixkfdi_sw) *
__fixkfdi_resolve(void)12436ac495dSmrg __fixkfdi_resolve (void)
12536ac495dSmrg {
126a2dc1f3fSmrg return SW_OR_HW (__fixkfdi_sw, __fixkfdi_hw);
12736ac495dSmrg }
12836ac495dSmrg
129a2dc1f3fSmrg static __typeof__ (__fixunskfsi_sw) *
__fixunskfsi_resolve(void)13036ac495dSmrg __fixunskfsi_resolve (void)
13136ac495dSmrg {
132a2dc1f3fSmrg return SW_OR_HW (__fixunskfsi_sw, __fixunskfsi_hw);
13336ac495dSmrg }
13436ac495dSmrg
135a2dc1f3fSmrg static __typeof__ (__fixunskfdi_sw) *
__fixunskfdi_resolve(void)13636ac495dSmrg __fixunskfdi_resolve (void)
13736ac495dSmrg {
138a2dc1f3fSmrg return SW_OR_HW (__fixunskfdi_sw, __fixunskfdi_hw);
13936ac495dSmrg }
14036ac495dSmrg
141a2dc1f3fSmrg static __typeof__ (__extendsfkf2_sw) *
__extendsfkf2_resolve(void)14236ac495dSmrg __extendsfkf2_resolve (void)
14336ac495dSmrg {
144a2dc1f3fSmrg return SW_OR_HW (__extendsfkf2_sw, __extendsfkf2_hw);
14536ac495dSmrg }
14636ac495dSmrg
147a2dc1f3fSmrg static __typeof__ (__extenddfkf2_sw) *
__extenddfkf2_resolve(void)14836ac495dSmrg __extenddfkf2_resolve (void)
14936ac495dSmrg {
150a2dc1f3fSmrg return SW_OR_HW (__extenddfkf2_sw, __extenddfkf2_hw);
15136ac495dSmrg }
15236ac495dSmrg
153a2dc1f3fSmrg static __typeof__ (__trunckfsf2_sw) *
__trunckfsf2_resolve(void)15436ac495dSmrg __trunckfsf2_resolve (void)
15536ac495dSmrg {
156a2dc1f3fSmrg return SW_OR_HW (__trunckfsf2_sw, __trunckfsf2_hw);
15736ac495dSmrg }
15836ac495dSmrg
159a2dc1f3fSmrg static __typeof__ (__trunckfdf2_sw) *
__trunckfdf2_resolve(void)16036ac495dSmrg __trunckfdf2_resolve (void)
16136ac495dSmrg {
16236ac495dSmrg return (void *) SW_OR_HW (__trunckfdf2_sw, __trunckfdf2_hw);
16336ac495dSmrg }
16436ac495dSmrg
165a2dc1f3fSmrg static __typeof__ (__extendkftf2_sw) *
__extendkftf2_resolve(void)16636ac495dSmrg __extendkftf2_resolve (void)
16736ac495dSmrg {
168a2dc1f3fSmrg return SW_OR_HW (__extendkftf2_sw, __extendkftf2_hw);
16936ac495dSmrg }
17036ac495dSmrg
171a2dc1f3fSmrg static __typeof__ (__trunctfkf2_sw) *
__trunctfkf2_resolve(void)17236ac495dSmrg __trunctfkf2_resolve (void)
17336ac495dSmrg {
174a2dc1f3fSmrg return SW_OR_HW (__trunctfkf2_sw, __trunctfkf2_hw);
17536ac495dSmrg }
17636ac495dSmrg
177a2dc1f3fSmrg static __typeof__ (__mulkc3_sw) *
__mulkc3_resolve(void)178a2dc1f3fSmrg __mulkc3_resolve (void)
179a2dc1f3fSmrg {
180a2dc1f3fSmrg return SW_OR_HW (__mulkc3_sw, __mulkc3_hw);
181a2dc1f3fSmrg }
182a2dc1f3fSmrg
183a2dc1f3fSmrg static __typeof__ (__divkc3_sw) *
__divkc3_resolve(void)184a2dc1f3fSmrg __divkc3_resolve (void)
185a2dc1f3fSmrg {
186a2dc1f3fSmrg return SW_OR_HW (__divkc3_sw, __divkc3_hw);
187a2dc1f3fSmrg }
188a2dc1f3fSmrg
189a2dc1f3fSmrg static __typeof__ (__eqkf2_sw) *
__eqkf2_resolve(void)19036ac495dSmrg __eqkf2_resolve (void)
19136ac495dSmrg {
192a2dc1f3fSmrg return SW_OR_HW (__eqkf2_sw, __eqkf2_hw);
19336ac495dSmrg }
19436ac495dSmrg
195a2dc1f3fSmrg static __typeof__ (__gekf2_sw) *
__gekf2_resolve(void)19636ac495dSmrg __gekf2_resolve (void)
19736ac495dSmrg {
198a2dc1f3fSmrg return SW_OR_HW (__gekf2_sw, __gekf2_hw);
19936ac495dSmrg }
20036ac495dSmrg
201a2dc1f3fSmrg static __typeof__ (__lekf2_sw) *
__lekf2_resolve(void)20236ac495dSmrg __lekf2_resolve (void)
20336ac495dSmrg {
204a2dc1f3fSmrg return SW_OR_HW (__lekf2_sw, __lekf2_hw);
20536ac495dSmrg }
20636ac495dSmrg
207a2dc1f3fSmrg static __typeof__ (__unordkf2_sw) *
__unordkf2_resolve(void)20836ac495dSmrg __unordkf2_resolve (void)
20936ac495dSmrg {
210a2dc1f3fSmrg return SW_OR_HW (__unordkf2_sw, __unordkf2_hw);
21136ac495dSmrg }
21236ac495dSmrg
21336ac495dSmrg /* Resolve __nekf2, __gtkf2, __ltkf2 like __eqkf2, __gekf2, and __lekf2, since
21436ac495dSmrg the functions return the same values. */
21536ac495dSmrg
216a2dc1f3fSmrg static __typeof__ (__eqkf2_sw) *
__nekf2_resolve(void)21736ac495dSmrg __nekf2_resolve (void)
21836ac495dSmrg {
219a2dc1f3fSmrg return SW_OR_HW (__eqkf2_sw, __eqkf2_hw);
22036ac495dSmrg }
22136ac495dSmrg
222a2dc1f3fSmrg static __typeof__ (__eqkf2_sw) *
__gtkf2_resolve(void)22336ac495dSmrg __gtkf2_resolve (void)
22436ac495dSmrg {
225a2dc1f3fSmrg return SW_OR_HW (__gekf2_sw, __gekf2_hw);
22636ac495dSmrg }
22736ac495dSmrg
228a2dc1f3fSmrg static __typeof__ (__eqkf2_sw) *
__ltkf2_resolve(void)22936ac495dSmrg __ltkf2_resolve (void)
23036ac495dSmrg {
231a2dc1f3fSmrg return SW_OR_HW (__lekf2_sw, __lekf2_hw);
23236ac495dSmrg }
23336ac495dSmrg
23436ac495dSmrg
23536ac495dSmrg
23636ac495dSmrg /* Ifunc definitions. */
23736ac495dSmrg TFtype __addkf3 (TFtype, TFtype)
23836ac495dSmrg __attribute__ ((__ifunc__ ("__addkf3_resolve")));
23936ac495dSmrg
24036ac495dSmrg TFtype __subkf3 (TFtype, TFtype)
24136ac495dSmrg __attribute__ ((__ifunc__ ("__subkf3_resolve")));
24236ac495dSmrg
24336ac495dSmrg TFtype __mulkf3 (TFtype, TFtype)
24436ac495dSmrg __attribute__ ((__ifunc__ ("__mulkf3_resolve")));
24536ac495dSmrg
24636ac495dSmrg TFtype __divkf3 (TFtype, TFtype)
24736ac495dSmrg __attribute__ ((__ifunc__ ("__divkf3_resolve")));
24836ac495dSmrg
24936ac495dSmrg TFtype __negkf2 (TFtype)
25036ac495dSmrg __attribute__ ((__ifunc__ ("__negkf2_resolve")));
25136ac495dSmrg
252a2dc1f3fSmrg TFtype __powikf2 (TFtype, SItype_ppc)
253a2dc1f3fSmrg __attribute__ ((__ifunc__ ("__powikf2_resolve")));
254a2dc1f3fSmrg
25536ac495dSmrg CMPtype __eqkf2 (TFtype, TFtype)
25636ac495dSmrg __attribute__ ((__ifunc__ ("__eqkf2_resolve")));
25736ac495dSmrg
25836ac495dSmrg CMPtype __nekf2 (TFtype, TFtype)
25936ac495dSmrg __attribute__ ((__ifunc__ ("__nekf2_resolve")));
26036ac495dSmrg
26136ac495dSmrg CMPtype __gekf2 (TFtype, TFtype)
26236ac495dSmrg __attribute__ ((__ifunc__ ("__gekf2_resolve")));
26336ac495dSmrg
26436ac495dSmrg CMPtype __gtkf2 (TFtype, TFtype)
26536ac495dSmrg __attribute__ ((__ifunc__ ("__gtkf2_resolve")));
26636ac495dSmrg
26736ac495dSmrg CMPtype __lekf2 (TFtype, TFtype)
26836ac495dSmrg __attribute__ ((__ifunc__ ("__lekf2_resolve")));
26936ac495dSmrg
27036ac495dSmrg CMPtype __ltkf2 (TFtype, TFtype)
27136ac495dSmrg __attribute__ ((__ifunc__ ("__ltkf2_resolve")));
27236ac495dSmrg
27336ac495dSmrg CMPtype __unordkf2 (TFtype, TFtype)
27436ac495dSmrg __attribute__ ((__ifunc__ ("__unordkf2_resolve")));
27536ac495dSmrg
27636ac495dSmrg TFtype __extendsfkf2 (float)
27736ac495dSmrg __attribute__ ((__ifunc__ ("__extendsfkf2_resolve")));
27836ac495dSmrg
27936ac495dSmrg TFtype __extenddfkf2 (double)
28036ac495dSmrg __attribute__ ((__ifunc__ ("__extenddfkf2_resolve")));
28136ac495dSmrg
28236ac495dSmrg float __trunckfsf2 (TFtype)
28336ac495dSmrg __attribute__ ((__ifunc__ ("__trunckfsf2_resolve")));
28436ac495dSmrg
28536ac495dSmrg double __trunckfdf2 (TFtype)
28636ac495dSmrg __attribute__ ((__ifunc__ ("__trunckfdf2_resolve")));
28736ac495dSmrg
28836ac495dSmrg SItype_ppc __fixkfsi (TFtype)
28936ac495dSmrg __attribute__ ((__ifunc__ ("__fixkfsi_resolve")));
29036ac495dSmrg
29136ac495dSmrg DItype_ppc __fixkfdi (TFtype)
29236ac495dSmrg __attribute__ ((__ifunc__ ("__fixkfdi_resolve")));
29336ac495dSmrg
29436ac495dSmrg USItype_ppc __fixunskfsi (TFtype)
29536ac495dSmrg __attribute__ ((__ifunc__ ("__fixunskfsi_resolve")));
29636ac495dSmrg
29736ac495dSmrg UDItype_ppc __fixunskfdi (TFtype)
29836ac495dSmrg __attribute__ ((__ifunc__ ("__fixunskfdi_resolve")));
29936ac495dSmrg
30036ac495dSmrg TFtype __floatsikf (SItype_ppc)
30136ac495dSmrg __attribute__ ((__ifunc__ ("__floatsikf_resolve")));
30236ac495dSmrg
30336ac495dSmrg TFtype __floatdikf (DItype_ppc)
30436ac495dSmrg __attribute__ ((__ifunc__ ("__floatdikf_resolve")));
30536ac495dSmrg
30636ac495dSmrg TFtype __floatunsikf (USItype_ppc)
30736ac495dSmrg __attribute__ ((__ifunc__ ("__floatunsikf_resolve")));
30836ac495dSmrg
30936ac495dSmrg TFtype __floatundikf (UDItype_ppc)
31036ac495dSmrg __attribute__ ((__ifunc__ ("__floatundikf_resolve")));
31136ac495dSmrg
31236ac495dSmrg IBM128_TYPE __extendkftf2 (TFtype)
31336ac495dSmrg __attribute__ ((__ifunc__ ("__extendkftf2_resolve")));
31436ac495dSmrg
31536ac495dSmrg TFtype __trunctfkf2 (IBM128_TYPE)
31636ac495dSmrg __attribute__ ((__ifunc__ ("__trunctfkf2_resolve")));
317a2dc1f3fSmrg
318a2dc1f3fSmrg TCtype __mulkc3 (TFtype, TFtype, TFtype, TFtype)
319a2dc1f3fSmrg __attribute__ ((__ifunc__ ("__mulkc3_resolve")));
320a2dc1f3fSmrg
321a2dc1f3fSmrg TCtype __divkc3 (TFtype, TFtype, TFtype, TFtype)
322a2dc1f3fSmrg __attribute__ ((__ifunc__ ("__divkc3_resolve")));
323