| 1 | // Licensed to the .NET Foundation under one or more agreements. |
| 2 | // The .NET Foundation licenses this file to you under the MIT license. |
| 3 | // See the LICENSE file in the project root for more information. |
| 4 | // |
| 5 | // File: FloatSingle.cpp |
| 6 | // |
| 7 | |
| 8 | #include <common.h> |
| 9 | |
| 10 | #include "floatsingle.h" |
| 11 | |
| 12 | // Windows x86 and Windows ARM/ARM64 may not define _isnanf() or _copysignf() but they do |
| 13 | // define _isnan() and _copysign(). We will redirect the macros to these other functions if |
| 14 | // the macro is not defined for the platform. This has the side effect of a possible implicit |
| 15 | // upcasting for arguments passed in and an explicit downcasting for the _copysign() call. |
| 16 | #if (defined(_TARGET_X86_) || defined(_TARGET_ARM_) || defined(_TARGET_ARM64_)) && !defined(FEATURE_PAL) |
| 17 | |
| 18 | #if !defined(_copysignf) |
| 19 | #define _copysignf (float)_copysign |
| 20 | #endif |
| 21 | |
| 22 | #endif |
| 23 | |
| 24 | // The default compilation mode is /fp:precise, which disables floating-point intrinsics. This |
| 25 | // default compilation mode has previously caused performance regressions in floating-point code. |
| 26 | // We enable /fp:fast semantics for the majority of the math functions, as it will speed up performance |
| 27 | // and is really unlikely to cause any other code regressions. |
| 28 | |
| 29 | //////////////////////////////////////////////////////////////////////////////////// |
| 30 | //////////////////////////////////////////////////////////////////////////////////// |
| 31 | //////////////////////////////////////////////////////////////////////////////////// |
| 32 | /// |
| 33 | /// beginning of /fp:fast scope |
| 34 | /// |
| 35 | //////////////////////////////////////////////////////////////////////////////////// |
| 36 | //////////////////////////////////////////////////////////////////////////////////// |
| 37 | //////////////////////////////////////////////////////////////////////////////////// |
| 38 | |
| 39 | #ifdef _MSC_VER |
| 40 | #pragma float_control(push) |
| 41 | #pragma float_control(precise, off) |
| 42 | #endif |
| 43 | |
| 44 | /*=====================================Abs===================================== |
| 45 | ** |
| 46 | ==============================================================================*/ |
| 47 | FCIMPL1_V(float, COMSingle::Abs, float x) |
| 48 | FCALL_CONTRACT; |
| 49 | |
| 50 | return (float)fabsf(x); |
| 51 | FCIMPLEND |
| 52 | |
| 53 | /*=====================================Acos===================================== |
| 54 | ** |
| 55 | ==============================================================================*/ |
| 56 | FCIMPL1_V(float, COMSingle::Acos, float x) |
| 57 | FCALL_CONTRACT; |
| 58 | |
| 59 | return (float)acosf(x); |
| 60 | FCIMPLEND |
| 61 | |
| 62 | /*=====================================Acosh==================================== |
| 63 | ** |
| 64 | ==============================================================================*/ |
| 65 | FCIMPL1_V(float, COMSingle::Acosh, float x) |
| 66 | FCALL_CONTRACT; |
| 67 | |
| 68 | return (float)acoshf(x); |
| 69 | FCIMPLEND |
| 70 | |
| 71 | /*=====================================Asin===================================== |
| 72 | ** |
| 73 | ==============================================================================*/ |
| 74 | FCIMPL1_V(float, COMSingle::Asin, float x) |
| 75 | FCALL_CONTRACT; |
| 76 | |
| 77 | return (float)asinf(x); |
| 78 | FCIMPLEND |
| 79 | |
| 80 | /*=====================================Asinh==================================== |
| 81 | ** |
| 82 | ==============================================================================*/ |
| 83 | FCIMPL1_V(float, COMSingle::Asinh, float x) |
| 84 | FCALL_CONTRACT; |
| 85 | |
| 86 | return (float)asinhf(x); |
| 87 | FCIMPLEND |
| 88 | |
| 89 | /*=====================================Atan===================================== |
| 90 | ** |
| 91 | ==============================================================================*/ |
| 92 | FCIMPL1_V(float, COMSingle::Atan, float x) |
| 93 | FCALL_CONTRACT; |
| 94 | |
| 95 | return (float)atanf(x); |
| 96 | FCIMPLEND |
| 97 | |
| 98 | /*=====================================Atanh==================================== |
| 99 | ** |
| 100 | ==============================================================================*/ |
| 101 | FCIMPL1_V(float, COMSingle::Atanh, float x) |
| 102 | FCALL_CONTRACT; |
| 103 | |
| 104 | return (float)atanhf(x); |
| 105 | FCIMPLEND |
| 106 | |
| 107 | /*=====================================Atan2==================================== |
| 108 | ** |
| 109 | ==============================================================================*/ |
| 110 | FCIMPL2_VV(float, COMSingle::Atan2, float y, float x) |
| 111 | FCALL_CONTRACT; |
| 112 | |
| 113 | return (float)atan2f(y, x); |
| 114 | FCIMPLEND |
| 115 | |
| 116 | /*====================================Cbrt====================================== |
| 117 | ** |
| 118 | ==============================================================================*/ |
| 119 | FCIMPL1_V(float, COMSingle::Cbrt, float x) |
| 120 | FCALL_CONTRACT; |
| 121 | |
| 122 | return (float)cbrtf(x); |
| 123 | FCIMPLEND |
| 124 | |
| 125 | #if defined(_MSC_VER) && defined(_TARGET_AMD64_) |
| 126 | // The /fp:fast form of `ceilf` for AMD64 does not correctly handle: `-1.0 < value <= -0.0` |
| 127 | // https://github.com/dotnet/coreclr/issues/19739 |
| 128 | #pragma float_control(push) |
| 129 | #pragma float_control(precise, on) |
| 130 | #endif |
| 131 | |
| 132 | /*====================================Ceil====================================== |
| 133 | ** |
| 134 | ==============================================================================*/ |
| 135 | FCIMPL1_V(float, COMSingle::Ceil, float x) |
| 136 | FCALL_CONTRACT; |
| 137 | |
| 138 | return (float)ceilf(x); |
| 139 | FCIMPLEND |
| 140 | |
| 141 | #if defined(_MSC_VER) && defined(_TARGET_AMD64_) |
| 142 | #pragma float_control(pop) |
| 143 | #endif |
| 144 | |
| 145 | /*=====================================Cos====================================== |
| 146 | ** |
| 147 | ==============================================================================*/ |
| 148 | FCIMPL1_V(float, COMSingle::Cos, float x) |
| 149 | FCALL_CONTRACT; |
| 150 | |
| 151 | return (float)cosf(x); |
| 152 | FCIMPLEND |
| 153 | |
| 154 | /*=====================================Cosh===================================== |
| 155 | ** |
| 156 | ==============================================================================*/ |
| 157 | FCIMPL1_V(float, COMSingle::Cosh, float x) |
| 158 | FCALL_CONTRACT; |
| 159 | |
| 160 | return (float)coshf(x); |
| 161 | FCIMPLEND |
| 162 | |
| 163 | /*=====================================Exp====================================== |
| 164 | ** |
| 165 | ==============================================================================*/ |
| 166 | FCIMPL1_V(float, COMSingle::Exp, float x) |
| 167 | FCALL_CONTRACT; |
| 168 | |
| 169 | return (float)expf(x); |
| 170 | FCIMPLEND |
| 171 | |
| 172 | /*====================================Floor===================================== |
| 173 | ** |
| 174 | ==============================================================================*/ |
| 175 | FCIMPL1_V(float, COMSingle::Floor, float x) |
| 176 | FCALL_CONTRACT; |
| 177 | |
| 178 | return (float)floorf(x); |
| 179 | FCIMPLEND |
| 180 | |
| 181 | /*=====================================FMod===================================== |
| 182 | ** |
| 183 | ==============================================================================*/ |
| 184 | FCIMPL2_VV(float, COMSingle::FMod, float x, float y) |
| 185 | FCALL_CONTRACT; |
| 186 | |
| 187 | return (float)fmodf(x, y); |
| 188 | FCIMPLEND |
| 189 | |
| 190 | /*=====================================FusedMultiplyAdd========================== |
| 191 | ** |
| 192 | ==============================================================================*/ |
| 193 | FCIMPL3_VVV(float, COMSingle::FusedMultiplyAdd, float x, float y, float z) |
| 194 | FCALL_CONTRACT; |
| 195 | |
| 196 | return (float)fmaf(x, y, z); |
| 197 | FCIMPLEND |
| 198 | |
| 199 | /*=====================================Ilog2==================================== |
| 200 | ** |
| 201 | ==============================================================================*/ |
| 202 | FCIMPL1_V(int, COMSingle::ILogB, float x) |
| 203 | FCALL_CONTRACT; |
| 204 | |
| 205 | return (int)ilogbf(x); |
| 206 | FCIMPLEND |
| 207 | |
| 208 | /*=====================================Log====================================== |
| 209 | ** |
| 210 | ==============================================================================*/ |
| 211 | FCIMPL1_V(float, COMSingle::Log, float x) |
| 212 | FCALL_CONTRACT; |
| 213 | |
| 214 | return (float)logf(x); |
| 215 | FCIMPLEND |
| 216 | |
| 217 | /*=====================================Log2===================================== |
| 218 | ** |
| 219 | ==============================================================================*/ |
| 220 | FCIMPL1_V(float, COMSingle::Log2, float x) |
| 221 | FCALL_CONTRACT; |
| 222 | |
| 223 | return (float)log2f(x); |
| 224 | FCIMPLEND |
| 225 | |
| 226 | /*====================================Log10===================================== |
| 227 | ** |
| 228 | ==============================================================================*/ |
| 229 | FCIMPL1_V(float, COMSingle::Log10, float x) |
| 230 | FCALL_CONTRACT; |
| 231 | |
| 232 | return (float)log10f(x); |
| 233 | FCIMPLEND |
| 234 | |
| 235 | /*=====================================ModF===================================== |
| 236 | ** |
| 237 | ==============================================================================*/ |
| 238 | FCIMPL2_VI(float, COMSingle::ModF, float x, float* intptr) |
| 239 | FCALL_CONTRACT; |
| 240 | |
| 241 | return (float)modff(x, intptr); |
| 242 | FCIMPLEND |
| 243 | |
| 244 | /*=====================================Pow====================================== |
| 245 | ** |
| 246 | ==============================================================================*/ |
| 247 | FCIMPL2_VV(float, COMSingle::Pow, float x, float y) |
| 248 | FCALL_CONTRACT; |
| 249 | |
| 250 | return (float)powf(x, y); |
| 251 | FCIMPLEND |
| 252 | |
| 253 | /*=====================================ScaleB=================================== |
| 254 | ** |
| 255 | ==============================================================================*/ |
| 256 | FCIMPL2_VI(float, COMSingle::ScaleB, float x, int n) |
| 257 | FCALL_CONTRACT; |
| 258 | |
| 259 | return (float)scalbnf(x, n); |
| 260 | FCIMPLEND |
| 261 | |
| 262 | /*=====================================Sin====================================== |
| 263 | ** |
| 264 | ==============================================================================*/ |
| 265 | FCIMPL1_V(float, COMSingle::Sin, float x) |
| 266 | FCALL_CONTRACT; |
| 267 | |
| 268 | return (float)sinf(x); |
| 269 | FCIMPLEND |
| 270 | |
| 271 | /*=====================================Sinh===================================== |
| 272 | ** |
| 273 | ==============================================================================*/ |
| 274 | FCIMPL1_V(float, COMSingle::Sinh, float x) |
| 275 | FCALL_CONTRACT; |
| 276 | |
| 277 | return (float)sinhf(x); |
| 278 | FCIMPLEND |
| 279 | |
| 280 | /*=====================================Sqrt===================================== |
| 281 | ** |
| 282 | ==============================================================================*/ |
| 283 | FCIMPL1_V(float, COMSingle::Sqrt, float x) |
| 284 | FCALL_CONTRACT; |
| 285 | |
| 286 | return (float)sqrtf(x); |
| 287 | FCIMPLEND |
| 288 | |
| 289 | /*=====================================Tan====================================== |
| 290 | ** |
| 291 | ==============================================================================*/ |
| 292 | FCIMPL1_V(float, COMSingle::Tan, float x) |
| 293 | FCALL_CONTRACT; |
| 294 | |
| 295 | return (float)tanf(x); |
| 296 | FCIMPLEND |
| 297 | |
| 298 | /*=====================================Tanh===================================== |
| 299 | ** |
| 300 | ==============================================================================*/ |
| 301 | FCIMPL1_V(float, COMSingle::Tanh, float x) |
| 302 | FCALL_CONTRACT; |
| 303 | |
| 304 | return (float)tanhf(x); |
| 305 | FCIMPLEND |
| 306 | |
| 307 | #ifdef _MSC_VER |
| 308 | #pragma float_control(pop) |
| 309 | #endif |
| 310 | |
| 311 | //////////////////////////////////////////////////////////////////////////////////// |
| 312 | //////////////////////////////////////////////////////////////////////////////////// |
| 313 | //////////////////////////////////////////////////////////////////////////////////// |
| 314 | /// |
| 315 | /// End of /fp:fast scope |
| 316 | /// |
| 317 | //////////////////////////////////////////////////////////////////////////////////// |
| 318 | //////////////////////////////////////////////////////////////////////////////////// |
| 319 | //////////////////////////////////////////////////////////////////////////////////// |
| 320 | |