57 #ifdef Vc_COMMON_MATH_H_INTERNAL
65 template <
typename T,
typename Abi>
66 using Const =
typename std::conditional<std::is_same<Abi, VectorAbi::Avx>::value,
67 AVX::Const<T>, SSE::Const<T>>::type;
69 template<LogarithmBase Base>
72 template<
typename T,
typename Abi>
static Vc_ALWAYS_INLINE
void log_series(Vector<T, Abi> &Vc_RESTRICT x,
typename Vector<T, Abi>::AsArg exponent) {
73 typedef Vector<T, Abi> V;
74 typedef Detail::Const<T, Abi> C;
89 V y2 = (C::P(6) * x2 + C::P(7) * x) + C::P(8);
90 V y0 = (C::P(0) * x2 + C::P(1) * x) + C::P(2);
91 V y1 = (C::P(3) * x2 + C::P(4) * x) + C::P(5);
95 V y = (y0 * x9 + y1 * x6) + y2 * x3;
96 #elif defined Vc_LOG_ILP2
129 const V x4 = x2 * x2;
130 const V x5 = x2 * x3;
131 const V x6 = x3 * x3;
132 const V x7 = x4 * x3;
133 const V x8 = x4 * x4;
134 const V x9 = x5 * x4;
135 const V x10 = x5 * x5;
136 const V x11 = x5 * x6;
137 V y = C::P(0) * x11 + C::P(1) * x10 + C::P(2) * x9 + C::P(3) * x8 + C::P(4) * x7
138 + C::P(5) * x6 + C::P(6) * x5 + C::P(7) * x4 + C::P(8) * x3;
141 Vc::Common::unrolled_loop<int, 1, 9>([&](
int i) { y = y * x + C::P(i); });
147 y += exponent * C::ln2_small();
150 x += exponent * C::ln2_large();
153 y += exponent * C::ln2_small();
156 x += exponent * C::ln2_large();
164 y -= x_ * x * C::_1_2();
172 template <
typename Abi>
173 static Vc_ALWAYS_INLINE
void log_series(Vector<double, Abi> &Vc_RESTRICT x,
174 typename Vector<double, Abi>::AsArg exponent)
176 typedef Vector<double, Abi> V;
177 typedef Detail::Const<double, Abi> C;
181 Vc::Common::unrolled_loop<int, 1, 5>([&](
int i) {
183 y2 = y2 * x + C::Q(i);
192 y += exponent * C::ln2_small();
195 x += exponent * C::ln2_large();
198 y += exponent * C::ln2_small();
201 x += exponent * C::ln2_large();
209 y -= x_ * x * C::_1_2();
217 template <
typename T,
typename Abi,
typename V = Vector<T, Abi>>
218 static inline Vector<T, Abi> calc(Vc_ALIGNED_PARAMETER(V) _x)
220 typedef typename V::Mask M;
221 typedef Detail::Const<T, Abi> C;
225 const M invalidMask = x <
V::Zero();
226 const M infinityMask = x ==
V::Zero();
227 const M denormal = x <=
C::min();
229 x(denormal) *= V(Vc::Detail::doubleConstant<1, 0, 54>());
230 V exponent = Detail::exponent(x.data());
231 exponent(denormal) -= 54;
233 x.setZero(C::exponentMask());
242 const M smallX = x < C::_1_sqrt2();
245 exponent(!smallX) +=
V::One();
247 log_series(x, exponent);
249 x.setQnan(invalidMask);
250 x(infinityMask) = C::neginf();
257 template <
typename T,
typename Abi>
258 Vc_INTRINSIC Vc_CONST Vector<T, Abi>
log(
const Vector<T, Abi> &x)
260 return Detail::LogImpl<BaseE>::calc<T, Abi>(x);
262 template <
typename T,
typename Abi>
263 Vc_INTRINSIC Vc_CONST Vector<T, Abi>
log10(
const Vector<T, Abi> &x)
265 return Detail::LogImpl<Base10>::calc<T, Abi>(x);
267 template <
typename T,
typename Abi>
268 Vc_INTRINSIC Vc_CONST Vector<T, Abi>
log2(
const Vector<T, Abi> &x)
270 return Detail::LogImpl<Base2>::calc<T, Abi>(x);
273 #endif // Vc_COMMON_MATH_H_INTERNAL
Vc::Vector< T > log2(const Vc::Vector< T > &v)
Vc::Vector< T > min(const Vc::Vector< T > &x, const Vc::Vector< T > &y)
Vc::Vector< T > log(const Vc::Vector< T > &v)
Vc::Vector< T > log10(const Vc::Vector< T > &v)
constexpr VectorSpecialInitializerZero Zero
The special object Vc::Zero can be used to construct Vector and Mask objects initialized to zero/fals...
constexpr VectorSpecialInitializerOne One
The special object Vc::One can be used to construct Vector and Mask objects initialized to one/true...