| 1 |
/* Automatic switching between software and hardware IEEE 128-bit |
| 2 |
floating-point emulation for PowerPC. |
| 3 |
|
| 4 |
Copyright (C) 2016-2025 Free Software Foundation, Inc. |
| 5 |
This file is part of the GNU C Library. |
| 6 |
Contributed by Michael Meissner ([email protected]) |
| 7 |
Code is based on the main soft-fp library written by: |
| 8 |
Richard Henderson ([email protected]) and |
| 9 |
Jakub Jelinek ([email protected]). |
| 10 |
|
| 11 |
The GNU C Library is free software; you can redistribute it and/or |
| 12 |
modify it under the terms of the GNU Lesser General Public |
| 13 |
License as published by the Free Software Foundation; either |
| 14 |
version 2.1 of the License, or (at your option) any later version. |
| 15 |
|
| 16 |
In addition to the permissions in the GNU Lesser General Public |
| 17 |
License, the Free Software Foundation gives you unlimited |
| 18 |
permission to link the compiled version of this file into |
| 19 |
combinations with other programs, and to distribute those |
| 20 |
combinations without any restriction coming from the use of this |
| 21 |
file. (The Lesser General Public License restrictions do apply in |
| 22 |
other respects; for example, they cover modification of the file, |
| 23 |
and distribution when not linked into a combine executable.) |
| 24 |
|
| 25 |
The GNU C Library is distributed in the hope that it will be useful, |
| 26 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 27 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 28 |
Lesser General Public License for more details. |
| 29 |
|
| 30 |
You should have received a copy of the GNU Lesser General Public |
| 31 |
License along with the GNU C Library; if not, see |
| 32 |
<http://www.gnu.org/licenses/>. */ |
| 33 |
|
| 34 |
#include <soft-fp.h> |
| 35 |
#include <quad-float128.h> |
| 36 |
|
| 37 |
#ifndef __FLOAT128_HARDWARE__ |
| 38 |
#error "This module must be compiled with IEEE 128-bit hardware support" |
| 39 |
#endif |
| 40 |
|
| 41 |
TFtype |
| 42 |
__addkf3_hw (TFtype a, TFtype b) |
| 43 |
{ |
| 44 |
return a + b; |
| 45 |
} |
| 46 |
|
| 47 |
TFtype |
| 48 |
__subkf3_hw (TFtype a, TFtype b) |
| 49 |
{ |
| 50 |
return a - b; |
| 51 |
} |
| 52 |
|
| 53 |
TFtype |
| 54 |
__mulkf3_hw (TFtype a, TFtype b) |
| 55 |
{ |
| 56 |
return a * b; |
| 57 |
} |
| 58 |
|
| 59 |
TFtype |
| 60 |
__divkf3_hw (TFtype a, TFtype b) |
| 61 |
{ |
| 62 |
return a / b; |
| 63 |
} |
| 64 |
|
| 65 |
TFtype |
| 66 |
__negkf2_hw (TFtype a) |
| 67 |
{ |
| 68 |
return -a; |
| 69 |
} |
| 70 |
|
| 71 |
TFtype |
| 72 |
__floatsikf_hw (SItype_ppc a) |
| 73 |
{ |
| 74 |
return (TFtype) a; |
| 75 |
} |
| 76 |
|
| 77 |
TFtype |
| 78 |
__floatunsikf_hw (USItype_ppc a) |
| 79 |
{ |
| 80 |
return (TFtype) a; |
| 81 |
} |
| 82 |
|
| 83 |
TFtype |
| 84 |
__floatdikf_hw (DItype_ppc a) |
| 85 |
{ |
| 86 |
return (TFtype) a; |
| 87 |
} |
| 88 |
|
| 89 |
TFtype |
| 90 |
__floatundikf_hw (UDItype_ppc a) |
| 91 |
{ |
| 92 |
return (TFtype) a; |
| 93 |
} |
| 94 |
|
| 95 |
SItype_ppc |
| 96 |
__fixkfsi_hw (TFtype a) |
| 97 |
{ |
| 98 |
return (SItype_ppc) a; |
| 99 |
} |
| 100 |
|
| 101 |
USItype_ppc |
| 102 |
__fixunskfsi_hw (TFtype a) |
| 103 |
{ |
| 104 |
return (USItype_ppc) a; |
| 105 |
} |
| 106 |
|
| 107 |
DItype_ppc |
| 108 |
__fixkfdi_hw (TFtype a) |
| 109 |
{ |
| 110 |
return (DItype_ppc) a; |
| 111 |
} |
| 112 |
|
| 113 |
UDItype_ppc |
| 114 |
__fixunskfdi_hw (TFtype a) |
| 115 |
{ |
| 116 |
return (UDItype_ppc) a; |
| 117 |
} |
| 118 |
|
| 119 |
TFtype |
| 120 |
__extendsfkf2_hw (float a) |
| 121 |
{ |
| 122 |
return (TFtype) a; |
| 123 |
} |
| 124 |
|
| 125 |
TFtype |
| 126 |
__extenddfkf2_hw (double a) |
| 127 |
{ |
| 128 |
return (TFtype) a; |
| 129 |
} |
| 130 |
|
| 131 |
float |
| 132 |
__trunckfsf2_hw (TFtype a) |
| 133 |
{ |
| 134 |
return (float) a; |
| 135 |
} |
| 136 |
|
| 137 |
double |
| 138 |
__trunckfdf2_hw (TFtype a) |
| 139 |
{ |
| 140 |
return (double) a; |
| 141 |
} |
| 142 |
|
| 143 |
/* __eqkf2 returns 0 if equal, or 1 if not equal or NaN. */ |
| 144 |
CMPtype |
| 145 |
__eqkf2_hw (TFtype a, TFtype b) |
| 146 |
{ |
| 147 |
return (a != b); |
| 148 |
} |
| 149 |
|
| 150 |
/* __gekf2 returns -1 if a < b, 0 if a == b, +1 if a > b, or -2 if NaN. */ |
| 151 |
CMPtype |
| 152 |
__gekf2_hw (TFtype a, TFtype b) |
| 153 |
{ |
| 154 |
if (a < b) |
| 155 |
return -1; |
| 156 |
|
| 157 |
else if (__builtin_isunordered (a, b)) |
| 158 |
return -2; |
| 159 |
|
| 160 |
else if (a == b) |
| 161 |
return 0; |
| 162 |
|
| 163 |
return 1; |
| 164 |
} |
| 165 |
|
| 166 |
/* __lekf2 returns -1 if a < b, 0 if a == b, +1 if a > b, or +2 if NaN. */ |
| 167 |
CMPtype |
| 168 |
__lekf2_hw (TFtype a, TFtype b) |
| 169 |
{ |
| 170 |
if (a < b) |
| 171 |
return -1; |
| 172 |
|
| 173 |
else if (__builtin_isunordered (a, b)) |
| 174 |
return 2; |
| 175 |
|
| 176 |
else if (a == b) |
| 177 |
return 0; |
| 178 |
|
| 179 |
return 1; |
| 180 |
} |
| 181 |
|
| 182 |
/* __unordkf2 returns 1 if NaN or 0 otherwise. */ |
| 183 |
CMPtype |
| 184 |
__unordkf2_hw (TFtype a, TFtype b) |
| 185 |
{ |
| 186 |
return (__builtin_isunordered (a, b)) ? 1 : 0; |
| 187 |
} |
| 188 |
|
| 189 |
/* Convert __float128 to __ibm128. */ |
| 190 |
IBM128_TYPE |
| 191 |
__extendkftf2_hw (TFtype value) |
| 192 |
{ |
| 193 |
IBM128_TYPE ret; |
| 194 |
|
| 195 |
CVT_FLOAT128_TO_IBM128 (ret, value); |
| 196 |
return ret; |
| 197 |
} |
| 198 |
|
| 199 |
/* Convert __ibm128 to __float128. */ |
| 200 |
TFtype |
| 201 |
__trunctfkf2_hw (IBM128_TYPE value) |
| 202 |
{ |
| 203 |
TFtype ret; |
| 204 |
|
| 205 |
CVT_IBM128_TO_FLOAT128 (ret, value); |
| 206 |
return ret; |
| 207 |
} |