entity
Entity/Component System for C++
for_each.hpp
Go to the documentation of this file.
1 // ****************************************************************************
2 // entity/algotithm/simd/sse/for_each.hpp
3 //
4 // Algorithm to call a functor for an entity with the supplied component
5 // types. If the entity does not have all of the supplied compnent types
6 // f is not called.
7 // This version is optimized for sse such that the functor f will be supplied
8 // _m128s filled with floats. Clearly, this implies float components.
9 //
10 // Copyright Chris Glover 2014-2015
11 //
12 // Distributed under the Boost Software License, Version 1.0.
13 // See accompanying file LICENSE_1_0.txt or copy at
14 // http://www.boost.org/LICENSE_1_0.txt
15 //
16 // ****************************************************************************
17 #ifndef _ENTITY_ALGORITHM_SIMD_SSE_FOREACH_H_INCLUDED_
18 #define _ENTITY_ALGORITHM_SIMD_SSE_FOREACH_H_INCLUDED_
19 
20 #include <boost/fusion/container/vector.hpp>
21 #include <boost/fusion/sequence/intrinsic/at.hpp>
22 #include <xmmintrin.h>
23 
25 #include "entity/config.hpp" // IWYU pragma: keep
26 
27 // ----------------------------------------------------------------------------
28 //
29 namespace entity { namespace simd { namespace sse
30 {
31  namespace detail
32  {
33  struct loadu_ps
34  {
35  inline void operator()(boost::fusion::vector<float*, __m128&> source_and_v) const
36  {
37  using boost::fusion::at_c;
38  at_c<1>(source_and_v) = _mm_loadu_ps(at_c<0>(source_and_v));
39  }
40  };
41 
42  struct storeu_ps
43  {
44  inline void operator()(boost::fusion::vector<float*, __m128&> dest_and_v) const
45  {
46  using boost::fusion::at_c;
47  _mm_storeu_ps(at_c<0>(dest_and_v), at_c<1>(dest_and_v));
48  }
49  };
50 
52  {
53  template<typename Iterator>
54  float* operator()(Iterator iter) const
55  {
56  return &(*iter);
57  }
58  };
59  }
60 
61  // ------------------------------------------------------------------------
62  //
63  template<typename EntityList, typename ComponentPoolTuple, typename Fn>
64  void for_each(EntityList const& entities, ComponentPoolTuple&& p, Fn f)
65  {
66  //DAILY_AUTO_INSTRUMENT_NODE(for_each);
67  //typedef typename boost::mpl::transform<
68  // ComponentPoolTuple,
69  // simd::detail::make_type<boost::mpl::_1, __m128>
70  //>::type m128_holder;
71 
72  //typedef typename boost::mpl::transform<
73  // m128_holder,
74  // boost::add_reference<boost::mpl::_1>
75  //>::type m128_refs;
76 
77  //m128_holder data;
78  //m128_refs data_refs(data);
79 
80  //auto i = begin(entities, std::forward<ComponentPoolTuple>(p));
81  //auto e = end(entities, std::forward<ComponentPoolTuple>(p));
82 
83  //while(i != e)
84  //{
85  // boost::fusion::for_each(
86  // boost::fusion::zip(
87  // boost::fusion::transform(*i, detail::iterator_to_ptr()),
88  // data_refs
89  // ),
90  // detail::loadu_ps()
91  // );
92 
93  // simd::detail::invoke(f, data_refs);
94 
95  // boost::fusion::for_each(
96  // boost::fusion::zip(
97  // boost::fusion::transform(*i, detail::iterator_to_ptr()),
98  // data_refs
99  // ),
100  // detail::storeu_ps()
101  // );
102 
103  // for(int j = 0; j < 4; ++j)
104  // {
105  // DAILY_AUTO_INSTRUMENT_NODE(for_each_loop);
106  // ++i;
107  // if(i == e)
108  // {
109  // break;
110  // }
111  // }
112  //}
113  }
114 }}} // namespace entity { namespace simd { namespace sse {
115 
116 #endif // _ENTITY_ALGORITHM_SIMD_SSE_FOREACH_H_INCLUDED_
float * operator()(Iterator iter) const
Definition: for_each.hpp:54
void for_each(EntityList const &entities, ComponentPoolTuple &&p, Fn f)
Definition: for_each.hpp:64
void operator()(boost::fusion::vector< float *, __m128 & > dest_and_v) const
Definition: for_each.hpp:44
void operator()(boost::fusion::vector< float *, __m128 & > source_and_v) const
Definition: for_each.hpp:35