Krita Source Code Documentation
Loading...
Searching...
No Matches
vc_extra_math.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2018 Iván Santa María <ghevan@gmail.com>
3 * SPDX-FileCopyrightText: 2022 L. E. Segovia <amy@amyspark.me>
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 */
7
8#ifndef VC_ADDITIONAL_MATH_H
9#define VC_ADDITIONAL_MATH_H
10
12
13#if !defined(XSIMD_NO_SUPPORTED_ARCHITECTURE)
14
16{
17public:
18
19 // vectorized erf function, precision 1e-5
20 template<typename A>
21 static inline xsimd::batch<float, A> erf(const xsimd::batch<float, A> x)
22 {
29 using float_v = xsimd::batch<float, A>;
30 using float_m = typename float_v::batch_bool_type;
31 float_v xa = xsimd::abs(x);
32 float_m precisionLimit = xa >= float_v(9.3f); // wrong result for any number beyond this
33 xa = xsimd::set_zero(xa, precisionLimit);
34 float_v sign(1.0f);
35 float_m invertMask = x < float_v(0.f);
36 sign = xsimd::select(invertMask, float_v(-1.f), sign);
37
38 // CONSTANTS
39 float a1 = 0.254829592f;
40 float a2 = -0.284496736f;
41 float a3 = 1.421413741f;
42 float a4 = -1.453152027f;
43 float a5 = 1.061405429f;
44 float p = 0.3275911f;
45
46 float_v t = 1.0f / (1.0f + p * xa);
47 float_v y = 1.0f - (((((a5 * t + a4) * t) + a3) * t + a2) * t + a1) * t * exp(-xa * xa);
48 y = xsimd::set_one(y, precisionLimit);
49 return sign * y;
50 }
51};
52#endif /* !defined XSIMD_NO_SUPPORTED_ARCHITECTURE */
53
54
55#endif // VC_ADDITIONAL_MATH_H
const Params2D p
static xsimd::batch< float, A > erf(const xsimd::batch< float, A > x)
auto set_one(const batch< T, A > &src, const batch_bool< T, A > &mask) noexcept
auto set_zero(const batch< T, A > &src, const batch_bool< T, A > &mask) noexcept