kfr

Fast, modern C++ DSP framework, FFT, Sample Rate Conversion, FIR/IIR/Biquad Filters (SSE, AVX, AVX-512, ARM NEON)
Log | Files | Refs | README

commit 0818eec441207286d9896f8d36d859950583f12c
parent 0484cdc51368e0ebe1950b477e7cfb51ebc662a2
Author: d.levin256@gmail.com <d.levin256@gmail.com>
Date:   Tue,  3 Dec 2019 19:16:19 +0000

Build time optimizations

Diffstat:
Minclude/kfr/cometa.hpp | 32+++++++++++++++++++++++++++++++-
Minclude/kfr/simd/shuffle.hpp | 2+-
Minclude/kfr/simd/vec.hpp | 70++++++++++++++++++----------------------------------------------------
Mtests/asm_test.cpp | 4++++
4 files changed, 54 insertions(+), 54 deletions(-)

diff --git a/include/kfr/cometa.hpp b/include/kfr/cometa.hpp @@ -462,6 +462,8 @@ struct cvals_t<T> : ops::empty { using type = cvals_t<T>; constexpr static size_t size() { return 0; } + + static const T* array() { return nullptr; } }; namespace details @@ -768,6 +770,25 @@ template <typename T, T Nstart, ptrdiff_t Nstep> struct cvalseq_impl<T, 2, Nstart, Nstep> : cvals_t<T, static_cast<T>(Nstart), static_cast<T>(Nstart + Nstep)> { }; + +template <typename T, T Nstart, ptrdiff_t Nstep> +struct cvalseq_impl<T, 4, Nstart, Nstep> + : cvals_t<T, static_cast<T>(Nstart), static_cast<T>(Nstart + Nstep), + static_cast<T>(Nstart + Nstep + Nstep), static_cast<T>(Nstart + Nstep + Nstep + Nstep)> +{ +}; + +template <typename T1, typename T2> +struct scale_impl; + +template <size_t... Args1, size_t... Args2> +struct scale_impl<csizes_t<Args1...>, csizes_t<Args2...>> +{ + constexpr static size_t count1 = sizeof...(Args1); + constexpr static size_t count2 = sizeof...(Args2); + using type = csizes_t<>; +}; + } // namespace details template <typename T, size_t size, T start = T(), ptrdiff_t step = 1> @@ -782,7 +803,16 @@ using indicesfor_t = cvalseq_t<size_t, sizeof...(List), 0>; template <size_t group, size_t... indices, size_t N = group * sizeof...(indices)> constexpr inline auto scale(csizes_t<indices...>) CMT_NOEXCEPT { - return cconcat(csizeseq_t<group, group * indices>()...); + return concat_lists<csizeseq_t<group, group * indices>...>{}; + // return i[csizeseq_t<N>() / csize_t<group>()] * csize_t<group>() + csizeseq_t<N>() % + // csize_t<group>(); +} + +template <size_t group, size_t... indices, size_t N = group * sizeof...(indices)> +constexpr inline auto scale() CMT_NOEXCEPT +{ + return concat_lists<csizeseq_t<group, group * indices>...>{}; + // return cconcat(csizeseq_t<group, group * indices>()...); // return i[csizeseq_t<N>() / csize_t<group>()] * csize_t<group>() + csizeseq_t<N>() % // csize_t<group>(); } diff --git a/include/kfr/simd/shuffle.hpp b/include/kfr/simd/shuffle.hpp @@ -330,7 +330,7 @@ namespace internal template <typename T, size_t Nout, typename Fn, size_t... Indices> constexpr KFR_INTRINSIC vec<T, Nout> generate_vector(csizes_t<Indices...>) { - return make_vector(static_cast<T>(Fn()(Indices))...); + return make_vector<T>(static_cast<T>(Fn()(Indices))...); } } // namespace internal diff --git a/include/kfr/simd/vec.hpp b/include/kfr/simd/vec.hpp @@ -467,55 +467,6 @@ KFR_INTRINSIC vec<T, sizeof...(indices)> shufflevectors(const vec<T, N>& x, cons namespace internal { - -#if 0 -constexpr inline size_t scale_get_index(size_t counter, size_t groupsize, size_t index) CMT_NOEXCEPT -{ - return index == index_undefined ? index_undefined : (counter % groupsize + groupsize * index); -} - -#ifdef CMT_COMPILER_MSVC -template <size_t counter, size_t groupsize, size_t... indices> -constexpr inline size_t scale_get_index(csizes_t<indices...>) CMT_NOEXCEPT -{ - return scale_get_index(counter, groupsize, csizes_t<indices...>().get(csize_t<counter / groupsize>())); -} - -template <size_t... indices, size_t... counter, size_t groupsize = sizeof...(counter) / sizeof...(indices)> -constexpr inline auto scale_impl(csizes_t<indices...> ind, csizes_t<counter...> cnt) CMT_NOEXCEPT - -> csizes_t<scale_get_index<counter, groupsize>(ind)...> -{ - return {}; -} -#else - -template <size_t counter, size_t groupsize, size_t... indices> -constexpr inline size_t scale_get_index() CMT_NOEXCEPT -{ - return scale_get_index(counter, groupsize, csizes_t<indices...>().get(csize_t<counter / groupsize>())); -} - -template <size_t... indices, size_t... counter, size_t groupsize = sizeof...(counter) / sizeof...(indices)> -constexpr inline auto scale_impl(csizes_t<indices...>, csizes_t<counter...>) CMT_NOEXCEPT - -> csizes_t<scale_get_index<counter, groupsize, indices...>()...> -{ - return {}; -} - -#endif -#endif - -} // namespace internal - -template <size_t groupsize, size_t... indices> -constexpr inline auto scale() CMT_NOEXCEPT -{ - return cconcat(csizeseq<groupsize, groupsize * indices>...); - // return internal::scale_impl(csizes_t<indices...>(), csizeseq<sizeof...(indices) * groupsize>); -} - -namespace internal -{ template <typename T> struct is_vec_impl : std::false_type { @@ -819,6 +770,22 @@ CMT_GNU_CONSTEXPR KFR_INTRINSIC vec<T, N> make_vector_impl(csizes_t<indices...>, const T list[] = { static_cast<T>(args)... }; return vec<T, N>(list[indices]...); } + +template <bool, typename Tfallback, typename... Args> +struct conditional_common; + +template <typename Tfallback, typename... Args> +struct conditional_common<true, Tfallback, Args...> +{ + using type = common_type<Args...>; +}; + +template <typename Tfallback, typename... Args> +struct conditional_common<false, Tfallback, Args...> +{ + using type = Tfallback; +}; + } // namespace internal /// Create vector from scalar values @@ -826,11 +793,10 @@ CMT_GNU_CONSTEXPR KFR_INTRINSIC vec<T, N> make_vector_impl(csizes_t<indices...>, /// CHECK( make_vector( 1, 2, 3, 4 ) == i32x4{1, 2, 3, 4} ); /// @endcode template <typename Type = void, typename Arg, typename... Args, size_t N = (sizeof...(Args) + 1), - typename SubType = fix_type<conditional<is_void<Type>, common_type<Arg, Args...>, Type>>> + typename SubType = + fix_type<typename internal::conditional_common<is_void<Type>, Type, Arg, Args...>::type>> constexpr KFR_INTRINSIC vec<SubType, N> make_vector(const Arg& x, const Args&... rest) { - // static_assert(! is_same<SubType, unsigned long long>, "!!!--1"); - // static_assert(! is_same<fix_type<SubType>, unsigned long long>, "!!!--2"); return internal::make_vector_impl<SubType>(cvalseq_t<size_t, N>(), static_cast<SubType>(x), static_cast<SubType>(rest)...); } diff --git a/tests/asm_test.cpp b/tests/asm_test.cpp @@ -181,6 +181,8 @@ using namespace kfr; #define TEST_ASM_IF(fn, MACRO) TEST_ASM_I(fn, MACRO) TEST_ASM_F(fn, MACRO) +#if 1 + TEST_ASM_UIF(add, TEST_ASM_VTY2) TEST_ASM_UIF(sub, TEST_ASM_VTY2) @@ -290,6 +292,8 @@ TEST_ASM_F(sin, TEST_ASM_VTY1_F) TEST_ASM_F(cos, TEST_ASM_VTY1_F) +#endif + namespace kfr {