commit de0f469edb48f043ba1c64ba2ae99e7442a329bc
parent 237db95b698f5afbe3702feff8531ec00647fd4d
Author: d.levin256@gmail.com <d.levin256@gmail.com>
Date: Wed, 13 Mar 2019 03:11:11 +0000
Move kfr::complex out of arch namespace
Diffstat:
2 files changed, 100 insertions(+), 85 deletions(-)
diff --git a/include/kfr/base/expression.hpp b/include/kfr/base/expression.hpp
@@ -41,6 +41,20 @@ CMT_PRAGMA_GNU(GCC diagnostic ignored "-Wparentheses")
namespace kfr
{
+
+#ifdef KFR_STD_COMPLEX
+
+template <typename T>
+using complex = std::complex<T>;
+
+#else
+#ifndef KFR_CUSTOM_COMPLEX
+
+template <typename>
+struct complex;
+#endif
+#endif
+
inline namespace CMT_ARCH_NAME
{
@@ -62,19 +76,6 @@ using cinput_t = const cinput_context*;
constexpr cinput_t cinput = nullptr;
constexpr coutput_t coutput = nullptr;
-#ifdef KFR_STD_COMPLEX
-
-template <typename T>
-using complex = std::complex<T>;
-
-#else
-#ifndef KFR_CUSTOM_COMPLEX
-
-template <typename>
-struct complex;
-#endif
-#endif
-
constexpr size_t infinite_size = static_cast<size_t>(-1);
CMT_INTRINSIC constexpr size_t size_add(size_t x, size_t y)
@@ -194,21 +195,21 @@ struct expression_lambda : input_expression
KFR_MEM_INTRINSIC expression_lambda(Fn&& fn) : fn(std::move(fn)) {}
template <size_t N, KFR_ENABLE_IF(N&& is_callable<Fn, cinput_t, size_t, vec_shape<T, N>>::value)>
- KFR_INTRINSIC friend vec<T, N> get_elements(const expression_lambda& self, cinput_t cinput,
- size_t index, vec_shape<T, N> y)
+ KFR_INTRINSIC friend vec<T, N> get_elements(const expression_lambda& self, cinput_t cinput, size_t index,
+ vec_shape<T, N> y)
{
return self.fn(cinput, index, y);
}
template <size_t N, KFR_ENABLE_IF(N&& is_callable<Fn, size_t>::value)>
KFR_INTRINSIC friend vec<T, N> get_elements(const expression_lambda& self, cinput_t, size_t index,
- vec_shape<T, N>)
+ vec_shape<T, N>)
{
return apply(self.fn, enumerate<size_t, N>() + index);
}
template <size_t N, KFR_ENABLE_IF(N&& is_callable<Fn>::value)>
KFR_INTRINSIC friend vec<T, N> get_elements(const expression_lambda& self, cinput_t, size_t,
- vec_shape<T, N>)
+ vec_shape<T, N>)
{
return apply<N>(self.fn);
}
@@ -327,7 +328,7 @@ struct expression_scalar : input_expression
template <size_t N>
friend KFR_INTRINSIC vec<T, N> get_elements(const expression_scalar& self, cinput_t, size_t,
- vec_shape<T, N>)
+ vec_shape<T, N>)
{
return resize<N>(self.val);
}
@@ -379,7 +380,7 @@ struct expression_function : expression_with_arguments<arg<Args>...>
}
template <size_t N>
friend KFR_INTRINSIC vec<T, N> get_elements(const expression_function& self, cinput_t cinput,
- size_t index, vec_shape<T, N> x)
+ size_t index, vec_shape<T, N> x)
{
return self.call(cinput, self.fn, index, x);
}
@@ -471,7 +472,7 @@ struct input_expression_base : input_expression
virtual T input(size_t index) const = 0;
template <typename U, size_t N>
friend KFR_INTRINSIC vec<U, N> get_elements(const input_expression_base& self, cinput_t, size_t index,
- vec_shape<U, N>)
+ vec_shape<U, N>)
{
vec<U, N> out;
for (size_t i = 0; i < N; i++)
diff --git a/include/kfr/simd/complex.hpp b/include/kfr/simd/complex.hpp
@@ -37,9 +37,6 @@ CMT_PRAGMA_MSVC(warning(disable : 4814))
namespace kfr
{
-inline namespace CMT_ARCH_NAME
-{
-
#ifdef KFR_STD_COMPLEX
template <typename T>
@@ -85,71 +82,87 @@ struct complex
KFR_MEM_INTRINSIC constexpr void imag(T value) CMT_NOEXCEPT { im = value; }
T re;
T im;
+};
- KFR_MEM_INTRINSIC friend complex operator+(const complex& x, const complex& y)
- {
- return (make_vector(x) + make_vector(y))[0];
- }
- KFR_MEM_INTRINSIC friend complex operator-(const complex& x, const complex& y)
- {
- return (make_vector(x) - make_vector(y))[0];
- }
- KFR_MEM_INTRINSIC friend complex operator*(const complex& x, const complex& y)
- {
- return (make_vector(x) * make_vector(y))[0];
- }
- KFR_MEM_INTRINSIC friend complex operator/(const complex& x, const complex& y)
- {
- return (make_vector(x) / make_vector(y))[0];
- }
+inline namespace CMT_ARCH_NAME
+{
- template <typename U, KFR_ENABLE_IF(is_number<U>::value), typename C = common_type<complex, U>>
- KFR_MEM_INTRINSIC friend C operator+(const complex& x, const U& y)
- {
- return static_cast<C>(x) + static_cast<C>(y);
- }
- template <typename U, KFR_ENABLE_IF(is_number<U>::value), typename C = common_type<complex, U>>
- KFR_MEM_INTRINSIC friend C operator-(const complex& x, const U& y)
- {
- return static_cast<C>(x) - static_cast<C>(y);
- }
- template <typename U, KFR_ENABLE_IF(is_number<U>::value), typename C = common_type<complex, U>>
- KFR_MEM_INTRINSIC friend C operator*(const complex& x, const U& y)
- {
- return static_cast<C>(x) * static_cast<C>(y);
- }
- template <typename U, KFR_ENABLE_IF(is_number<U>::value), typename C = common_type<complex, U>>
- KFR_MEM_INTRINSIC friend C operator/(const complex& x, const U& y)
- {
- return static_cast<C>(x) / static_cast<C>(y);
- }
+template <typename T>
+KFR_INTRINSIC complex<T> operator+(const complex<T>& x, const complex<T>& y)
+{
+ return (make_vector(x) + make_vector(y))[0];
+}
+template <typename T>
+KFR_INTRINSIC complex<T> operator-(const complex<T>& x, const complex<T>& y)
+{
+ return (make_vector(x) - make_vector(y))[0];
+}
+template <typename T>
+KFR_INTRINSIC complex<T> operator*(const complex<T>& x, const complex<T>& y)
+{
+ return (make_vector(x) * make_vector(y))[0];
+}
+template <typename T>
+KFR_INTRINSIC complex<T> operator/(const complex<T>& x, const complex<T>& y)
+{
+ return (make_vector(x) / make_vector(y))[0];
+}
- template <typename U, KFR_ENABLE_IF(is_number<U>::value), typename C = common_type<complex, U>>
- KFR_MEM_INTRINSIC friend C operator+(const U& x, const complex& y)
- {
- return static_cast<C>(x) + static_cast<C>(y);
- }
- template <typename U, KFR_ENABLE_IF(is_number<U>::value), typename C = common_type<complex, U>>
- KFR_MEM_INTRINSIC friend C operator-(const U& x, const complex& y)
- {
- return static_cast<C>(x) - static_cast<C>(y);
- }
- template <typename U, KFR_ENABLE_IF(is_number<U>::value), typename C = common_type<complex, U>>
- KFR_MEM_INTRINSIC friend C operator*(const U& x, const complex& y)
- {
- return static_cast<C>(x) * static_cast<C>(y);
- }
- template <typename U, KFR_ENABLE_IF(is_number<U>::value), typename C = common_type<complex, U>>
- KFR_MEM_INTRINSIC friend C operator/(const U& x, const complex& y)
- {
- return static_cast<C>(x) / static_cast<C>(y);
- }
- KFR_MEM_INTRINSIC friend complex operator-(const complex& x) { return (-make_vector(x))[0]; }
- KFR_MEM_INTRINSIC friend complex operator+(const complex& x) { return x; }
-};
+template <typename T, typename U, KFR_ENABLE_IF(is_number<U>::value), typename C = common_type<complex<T>, U>>
+KFR_INTRINSIC C operator+(const complex<T>& x, const U& y)
+{
+ return static_cast<C>(x) + static_cast<C>(y);
+}
+template <typename T, typename U, KFR_ENABLE_IF(is_number<U>::value), typename C = common_type<complex<T>, U>>
+KFR_INTRINSIC C operator-(const complex<T>& x, const U& y)
+{
+ return static_cast<C>(x) - static_cast<C>(y);
+}
+template <typename T, typename U, KFR_ENABLE_IF(is_number<U>::value), typename C = common_type<complex<T>, U>>
+KFR_INTRINSIC C operator*(const complex<T>& x, const U& y)
+{
+ return static_cast<C>(x) * static_cast<C>(y);
+}
+template <typename T, typename U, KFR_ENABLE_IF(is_number<U>::value), typename C = common_type<complex<T>, U>>
+KFR_INTRINSIC C operator/(const complex<T>& x, const U& y)
+{
+ return static_cast<C>(x) / static_cast<C>(y);
+}
+
+template <typename T, typename U, KFR_ENABLE_IF(is_number<U>::value), typename C = common_type<complex<T>, U>>
+KFR_INTRINSIC C operator+(const U& x, const complex<T>& y)
+{
+ return static_cast<C>(x) + static_cast<C>(y);
+}
+template <typename T, typename U, KFR_ENABLE_IF(is_number<U>::value), typename C = common_type<complex<T>, U>>
+KFR_INTRINSIC C operator-(const U& x, const complex<T>& y)
+{
+ return static_cast<C>(x) - static_cast<C>(y);
+}
+template <typename T, typename U, KFR_ENABLE_IF(is_number<U>::value), typename C = common_type<complex<T>, U>>
+KFR_INTRINSIC C operator*(const U& x, const complex<T>& y)
+{
+ return static_cast<C>(x) * static_cast<C>(y);
+}
+template <typename T, typename U, KFR_ENABLE_IF(is_number<U>::value), typename C = common_type<complex<T>, U>>
+KFR_INTRINSIC C operator/(const U& x, const complex<T>& y)
+{
+ return static_cast<C>(x) / static_cast<C>(y);
+}
+template <typename T>
+KFR_INTRINSIC complex<T> operator-(const complex<T>& x)
+{
+ return (-make_vector(x))[0];
+}
+template <typename T>
+KFR_INTRINSIC complex<T> operator+(const complex<T>& x)
+{
+ return x;
+}
+
+} // namespace CMT_ARCH_NAME
#endif
#endif
-} // namespace CMT_ARCH_NAME
} // namespace kfr
namespace cometa
{
@@ -175,8 +188,6 @@ struct compound_type_traits<kfr::complex<T>>
} // namespace cometa
namespace kfr
{
-inline namespace CMT_ARCH_NAME
-{
/// @brief Alias for complex<f32>
using c32 = complex<f32>;
@@ -187,6 +198,9 @@ using c64 = complex<f64>;
/// @brief Alias for complex<fbase>
using cbase = complex<fbase>;
+inline namespace CMT_ARCH_NAME
+{
+
namespace intrinsics
{
template <typename T>