1/* Copyright (C) 2013-2017 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_ADD_H
9#define LIBSIMDPP_SIMDPP_DETAIL_INSN_F_ADD_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#include <simdpp/detail/null/math.h>
17#include <simdpp/detail/vector_array_macros.h>
18
19namespace simdpp {
20namespace SIMDPP_ARCH_NAMESPACE {
21namespace detail {
22namespace insn {
23
24static SIMDPP_INL
25float32<4> i_fadd(const float32<4>& a, const float32<4>& b)
26{
27#if SIMDPP_USE_NULL || SIMDPP_USE_NEON_NO_FLT_SP
28 return detail::null::add(a, b);
29#elif SIMDPP_USE_SSE2
30 return _mm_add_ps(a.native(), b.native());
31#elif SIMDPP_USE_NEON_FLT_SP
32 return vaddq_f32(a.native(), b.native());
33#elif SIMDPP_USE_ALTIVEC
34 return vec_add(a.native(), b.native());
35#elif SIMDPP_USE_MSA
36 return __msa_fadd_w(a.native(), b.native());
37#endif
38}
39
40#if SIMDPP_USE_AVX
41static SIMDPP_INL
42float32<8> i_fadd(const float32<8>& a, const float32<8>& b)
43{
44 return _mm256_add_ps(a.native(), b.native());
45}
46#endif
47
48#if SIMDPP_USE_AVX512F
49static SIMDPP_INL
50float32<16> i_fadd(const float32<16>& a, const float32<16>& b)
51{
52 return _mm512_add_ps(a.native(), b.native());
53}
54#endif
55
56// -----------------------------------------------------------------------------
57
58static SIMDPP_INL
59float64<2> i_fadd(const float64<2>& a, const float64<2>& b)
60{
61#if SIMDPP_USE_SSE2
62 return _mm_add_pd(a.native(), b.native());
63#elif SIMDPP_USE_NEON64
64 return vaddq_f64(a.native(), b.native());
65#elif SIMDPP_USE_VSX_206
66 return vec_add(a.native(), b.native());
67#elif SIMDPP_USE_MSA
68 return __msa_fadd_d(a.native(), b.native());
69#elif SIMDPP_USE_NULL || SIMDPP_USE_NEON32 || SIMDPP_USE_ALTIVEC
70 return detail::null::add(a, b);
71#endif
72}
73
74#if SIMDPP_USE_AVX
75static SIMDPP_INL
76float64<4> i_fadd(const float64<4>& a, const float64<4>& b)
77{
78 return _mm256_add_pd(a.native(), b.native());
79}
80#endif
81
82#if SIMDPP_USE_AVX512F
83static SIMDPP_INL
84float64<8> i_fadd(const float64<8>& a, const float64<8>& b)
85{
86 return _mm512_add_pd(a.native(), b.native());
87}
88#endif
89
90// -----------------------------------------------------------------------------
91
92template<class V> SIMDPP_INL
93V i_fadd(const V& a, const V& b)
94{
95 SIMDPP_VEC_ARRAY_IMPL2(V, i_fadd, a, b)
96}
97
98} // namespace insn
99} // namespace detail
100} // namespace SIMDPP_ARCH_NAMESPACE
101} // namespace simdpp
102
103#endif
104
105