1 | /* Copyright (C) 2013-2014 Povilas Kanapickas <povilas@radix.lt> |
2 | |
3 | Distributed under the Boost Software License, Version 1.0. |
4 | (See accompanying file LICENSE_1_0.txt or copy at |
5 | http://www.boost.org/LICENSE_1_0.txt) |
6 | */ |
7 | |
8 | #ifndef LIBSIMDPP_SIMDPP_DETAIL_INSN_F_RSQRT_E_H |
9 | #define LIBSIMDPP_SIMDPP_DETAIL_INSN_F_RSQRT_E_H |
10 | |
11 | #ifndef LIBSIMDPP_SIMD_H |
12 | #error "This file must be included through simd.h" |
13 | #endif |
14 | |
15 | #include <simdpp/types.h> |
16 | #if SIMDPP_USE_NULL || SIMDPP_USE_NEON || SIMDPP_USE_ALTIVEC |
17 | #include <cmath> |
18 | #include <simdpp/detail/null/math.h> |
19 | #endif |
20 | #include <simdpp/detail/vector_array_macros.h> |
21 | |
22 | namespace simdpp { |
23 | namespace SIMDPP_ARCH_NAMESPACE { |
24 | namespace detail { |
25 | namespace insn { |
26 | |
27 | |
28 | static SIMDPP_INL |
29 | float32x4 i_rsqrt_e(const float32x4& a) |
30 | { |
31 | #if SIMDPP_USE_NULL || SIMDPP_USE_NEON_NO_FLT_SP |
32 | float32x4 r; |
33 | for (unsigned i = 0; i < a.length; i++) { |
34 | r.el(i) = 1.0f / std::sqrt(a.el(i)); |
35 | } |
36 | return r; |
37 | #elif SIMDPP_USE_SSE2 |
38 | return _mm_rsqrt_ps(a.native()); |
39 | #elif SIMDPP_USE_NEON_FLT_SP |
40 | return vrsqrteq_f32(a.native()); |
41 | #elif SIMDPP_USE_ALTIVEC |
42 | return vec_rsqrte(a.native()); |
43 | #elif SIMDPP_USE_MSA |
44 | return __msa_frsqrt_w(a.native()); |
45 | #endif |
46 | } |
47 | |
48 | #if SIMDPP_USE_AVX |
49 | static SIMDPP_INL |
50 | float32x8 i_rsqrt_e(const float32x8& a) |
51 | { |
52 | return _mm256_rsqrt_ps(a.native()); |
53 | } |
54 | #endif |
55 | |
56 | #if SIMDPP_USE_AVX512F |
57 | static SIMDPP_INL |
58 | float32<16> i_rsqrt_e(const float32<16>& a) |
59 | { |
60 | return _mm512_rsqrt14_ps(a.native()); |
61 | } |
62 | #endif |
63 | |
64 | template<unsigned N> SIMDPP_INL |
65 | float32<N> i_rsqrt_e(const float32<N>& a) |
66 | { |
67 | SIMDPP_VEC_ARRAY_IMPL1(float32<N>, i_rsqrt_e, a); |
68 | } |
69 | |
70 | |
71 | } // namespace insn |
72 | } // namespace detail |
73 | } // namespace SIMDPP_ARCH_NAMESPACE |
74 | } // namespace simdpp |
75 | |
76 | #endif |
77 | |
78 | |