diff options
author | Mateusz Chudyk <mateuszchudyk@gmail.com> | 2019-05-31 17:25:22 +0300 |
---|---|---|
committer | Mateusz Chudyk <mateuszchudyk@gmail.com> | 2019-06-18 16:38:54 +0300 |
commit | fa03a070794bcea667129a160dc3da1bf690a592 (patch) | |
tree | df700eecec3f416ffe587ed9d9d097eac7fad516 | |
parent | 425e774b87f0db0a0919a1348898167d0cc98cd3 (diff) |
Rewrite compile-time sequence and place it in a separated header
-rw-r--r-- | postprocess_pipeline.h | 20 | ||||
-rw-r--r-- | utils.h | 39 |
2 files changed, 45 insertions, 14 deletions
diff --git a/postprocess_pipeline.h b/postprocess_pipeline.h index f0e2214..ad525ac 100644 --- a/postprocess_pipeline.h +++ b/postprocess_pipeline.h @@ -2,6 +2,7 @@ #include "intrinsics.h" #include "types.h" +#include "utils.h" #include <tuple> @@ -20,17 +21,8 @@ class PostprocessImpl; namespace { // anonymous namespace -template <std::size_t... I> -struct integer_seq {}; - -template <std::size_t N, std::size_t... I> -struct integer_seq_from_one_s : integer_seq_from_one_s<N - 1, N - 1, I...> {}; - -template <std::size_t... I> -struct integer_seq_from_one_s<1, I...> : integer_seq<I...> {}; - -template <typename... Types> -using integer_seq_from_one = integer_seq_from_one_s<sizeof...(Types) + 1>; +template <unsigned N> +using make_sequence_from_one = sequence_popfront<make_sequence<N>>; template <typename Stage> struct remove_first_stage_type_s { using type = std::tuple<>;}; @@ -65,14 +57,14 @@ using input_register_type = typename first_stage_type<Stages...>::InputRegister; template <typename... Stages> using output_register_type = typename last_stage_type<Stages...>::OutputRegister; -template <typename Tuple, typename std::size_t...I> -constexpr remove_first_stage_type<Tuple> ShiftPostprocessPipelineImpl(const Tuple& pipeline, integer_seq<I...>) { +template <typename Tuple, unsigned...I> +constexpr remove_first_stage_type<Tuple> ShiftPostprocessPipelineImpl(const Tuple& pipeline, sequence<I...>) { return CreatePostprocessPipeline(std::get<I>(pipeline)...); } template <typename FirstStage, typename... RestStages> constexpr std::tuple<RestStages...> ShiftPostprocessPipeline(const std::tuple<FirstStage, RestStages...>& pipeline) { - return ShiftPostprocessPipelineImpl(pipeline, integer_seq_from_one<std::tuple<FirstStage, RestStages...>>()); + return ShiftPostprocessPipelineImpl(pipeline, make_sequence_from_one<sizeof...(RestStages) + 1>()); } template <CPUType CpuType, typename Stage> @@ -0,0 +1,39 @@ +#pragma once + +namespace intgemm { + +/* + * Sequence of unsigned integers + * + * Examples: + * sequence<1, 2, 3>() + * sequence_pushback<4, sequence<1, 2, 3>>() = sequence<1, 2, 3, 4>() + * sequence_popfront<sequence<1, 2, 3>>() = sequence<2, 3, 4>() + * make_sequence<3>() = sequence<1, 2, 3>() + */ +template <unsigned... Indices> +struct sequence { using type = sequence; }; + +template <unsigned I, typename Sequence> +struct sequence_pushback; + +template <unsigned I, unsigned... Indices> +struct sequence_pushback<I, sequence<Indices...>> : sequence<Indices..., I> {}; + +template <typename Sequence> +struct sequence_popfront; + +template <unsigned FirstIndex, unsigned... RestIndices> +struct sequence_popfront<sequence<FirstIndex, RestIndices...>> : sequence<RestIndices...> {}; + +namespace { // anonymous namespace +template <unsigned N> +struct make_sequence_impl : sequence_pushback<N - 1, typename make_sequence_impl<N - 1>::type> {}; +template <> +struct make_sequence_impl<0> : sequence<> {}; +} // anonymous namespace + +template <unsigned N> +using make_sequence = typename make_sequence_impl<N>::type; + +} |