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_RCP_E_H
9#define LIBSIMDPP_SIMDPP_DETAIL_INSN_F_RCP_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
22namespace simdpp {
23namespace SIMDPP_ARCH_NAMESPACE {
24namespace detail {
25namespace insn {
26
27
28static SIMDPP_INL
29float32x4 i_rcp_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 / (a.el(i));
35 }
36 return r;
37#elif SIMDPP_USE_SSE2
38 return _mm_rcp_ps(a.native());
39#elif SIMDPP_USE_NEON_FLT_SP
40 return vrecpeq_f32(a.native());
41#elif SIMDPP_USE_ALTIVEC
42 return vec_re(a.native());
43#elif SIMDPP_USE_MSA
44 return __msa_frcp_w(a.native());
45#endif
46}
47
48#if SIMDPP_USE_AVX
49static SIMDPP_INL
50float32x8 i_rcp_e(const float32x8& a)
51{
52 return _mm256_rcp_ps(a.native());
53}
54#endif
55
56#if SIMDPP_USE_AVX512F
57static SIMDPP_INL
58float32<16> i_rcp_e(const float32<16>& a)
59{
60 // TODO: document precision
61 return _mm512_rcp14_ps(a.native());
62}
63#endif
64
65template<unsigned N> SIMDPP_INL
66float32<N> i_rcp_e(const float32<N>& a)
67{
68 SIMDPP_VEC_ARRAY_IMPL1(float32<N>, i_rcp_e, a);
69}
70
71} // namespace insn
72} // namespace detail
73} // namespace SIMDPP_ARCH_NAMESPACE
74} // namespace simdpp
75
76#endif
77
78