diff options
author | 2019-02-21 22:59:17 +0100 | |
---|---|---|
committer | 2019-02-22 08:18:01 +0100 | |
commit | cf73ccc764d574284bef4ce95ee5bc3e9089f053 (patch) | |
tree | 1655c2836b200c90d5fe5dd5833159e7e8be1522 /src/lib/netlist/plib/parray.h | |
parent | 6ed352261d40e37887357fe901dc380d6ef79844 (diff) |
netlist: memory management. [Couriersud]
Memory management in plib is now alignment-aware. All allocations
respect c++11 alignas. Selected classes like parray and aligned_vector
also provide hints (__builtin_assume_aligned) to g++ and clang.
The alignment optimizations have little impact on the current use cases.
They only become effective on bigger data processing.
What has a measurable impact is memory pooling. This speeds up netlist
games like breakout and pong by about 5%.
Tested with linux, macosx and windows cross builds. All features are
disabled since I can not rule out they may temporarily break more exotic
builds.
Diffstat (limited to 'src/lib/netlist/plib/parray.h')
-rw-r--r-- | src/lib/netlist/plib/parray.h | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/lib/netlist/plib/parray.h b/src/lib/netlist/plib/parray.h index 662c2e9550e..e09639163f0 100644 --- a/src/lib/netlist/plib/parray.h +++ b/src/lib/netlist/plib/parray.h @@ -10,6 +10,7 @@ #include "pconfig.h" #include "pexception.h" +#include "palloc.h" #include <array> #include <memory> @@ -30,7 +31,7 @@ namespace plib { struct sizeabs<FT, 0> { static constexpr const std::size_t ABS = 0; - using container = typename std::vector<FT> ; + using container = typename std::vector<FT, aligned_allocator<FT, PALIGN_VECTOROPT>>; }; /** @@ -102,11 +103,17 @@ namespace plib { return m_a[i]; } #else - reference operator[](size_type i) noexcept { return m_a[i]; } - constexpr const_reference operator[](size_type i) const noexcept { return m_a[i]; } + reference operator[](size_type i) noexcept + { + return assume_aligned_ptr<FT, PALIGN_VECTOROPT>(&m_a[0])[i]; + } + constexpr const_reference operator[](size_type i) const noexcept + { + return assume_aligned_ptr<FT, PALIGN_VECTOROPT>(&m_a[0])[i]; + } #endif - FT * data() noexcept { return m_a.data(); } - const FT * data() const noexcept { return m_a.data(); } + FT * data() noexcept { return assume_aligned_ptr<FT, PALIGN_VECTOROPT>(m_a.data()); } + const FT * data() const noexcept { return assume_aligned_ptr<FT, PALIGN_VECTOROPT>(m_a.data()); } private: PALIGNAS_VECTOROPT() |