summaryrefslogtreecommitdiffstats
path: root/src/lib/netlist/plib/parray.h
diff options
context:
space:
mode:
author Roberto Fresca <robbie@robertofresca.com>2020-06-13 15:58:27 +0200
committer Roberto Fresca <robbie@robertofresca.com>2020-06-13 15:58:27 +0200
commit284f196df1c65a91eb38a5a9f31a2da7fb86a1ac (patch)
treed29473e4024dce305d0ee3bb957a663420417312 /src/lib/netlist/plib/parray.h
parent52b8d5fd2b656c317e589da93467c33be74e76ea (diff)
parente949e9c29de82ee7c32692e7b65da05dd22bdc9d (diff)
Merge branch 'master' of https://github.com/mamedev/mame
Diffstat (limited to 'src/lib/netlist/plib/parray.h')
-rw-r--r--src/lib/netlist/plib/parray.h39
1 files changed, 21 insertions, 18 deletions
diff --git a/src/lib/netlist/plib/parray.h b/src/lib/netlist/plib/parray.h
index 0d89a56195c..2c2b0fc4270 100644
--- a/src/lib/netlist/plib/parray.h
+++ b/src/lib/netlist/plib/parray.h
@@ -21,19 +21,20 @@
namespace plib {
- template <typename FT, int SIZE>
+ template <typename FT, int SIZE, typename ARENA>
struct sizeabs
{
- static constexpr std::size_t ABS() noexcept { return (SIZE < 0) ? static_cast<std::size_t>(0 - SIZE) : static_cast<std::size_t>(SIZE); }
+ static constexpr std::size_t ABS() noexcept { return (SIZE < 0) ? narrow_cast<std::size_t>(0 - SIZE) : narrow_cast<std::size_t>(SIZE); }
using container = typename std::array<FT, ABS()> ;
};
- template <typename FT>
- struct sizeabs<FT, 0>
+ template <typename FT, typename ARENA>
+ struct sizeabs<FT, 0, ARENA>
{
static constexpr std::size_t ABS() noexcept { return 0; }
+ using allocator_type = typename ARENA::template allocator_type<FT, PALIGN_VECTOROPT>;
//using container = typename std::vector<FT, arena_allocator<mempool, FT, 64>>;
- using container = typename std::vector<FT, aligned_allocator<FT, PALIGN_VECTOROPT>>;
+ using container = typename std::vector<FT, allocator_type>;
};
/// \brief Array with preallocated or dynamic allocation.
@@ -51,17 +52,20 @@ namespace plib {
/// I consider > 10% performance difference to be a use case.
///
- template <typename FT, int SIZE>
+ template <typename FT, int SIZE, typename ARENA = aligned_arena>
struct parray
{
public:
- static constexpr std::size_t SIZEABS() noexcept { return sizeabs<FT, SIZE>::ABS(); }
+ static constexpr std::size_t SIZEABS() noexcept { return sizeabs<FT, SIZE, ARENA>::ABS(); }
- using base_type = typename sizeabs<FT, SIZE>::container;
+ using base_type = typename sizeabs<FT, SIZE, ARENA>::container;
using size_type = typename base_type::size_type;
- using reference = typename base_type::reference;
- using const_reference = typename base_type::const_reference;
- using value_type = typename base_type::value_type;
+ using value_type = FT;
+ using reference = FT &;
+ using const_reference = const FT &;
+
+ using pointer = FT *;
+ using const_pointer = const FT *;
template <int X = SIZE >
parray(size_type size, std::enable_if_t<(X==0), int> = 0)
@@ -70,7 +74,7 @@ namespace plib {
}
template <int X = SIZE >
- parray(size_type size, FT val, std::enable_if_t<(X==0), int> = 0)
+ parray(size_type size, const FT &val, std::enable_if_t<(X==0), int> = 0)
: m_a(size, val), m_size(size)
{
}
@@ -85,7 +89,7 @@ namespace plib {
}
template <int X = SIZE >
- parray(size_type size, FT val, std::enable_if_t<(X != 0), int> = 0) noexcept(false)
+ parray(size_type size, const FT &val, std::enable_if_t<(X != 0), int> = 0) noexcept(false)
: m_size(size)
{
if ((SIZE < 0 && size > SIZEABS())
@@ -131,20 +135,19 @@ namespace plib {
constexpr reference operator[](size_type i) noexcept
{
- return assume_aligned_ptr<FT, PALIGN_VECTOROPT>(&m_a[0])[i];
+ return data()[i];
}
constexpr const_reference operator[](size_type i) const noexcept
{
- return assume_aligned_ptr<FT, PALIGN_VECTOROPT>(&m_a[0])[i];
+ return data()[i];
}
- 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()); }
+ pointer data() noexcept { return m_a.data(); }
+ const_pointer data() const noexcept { return m_a.data(); }
private:
PALIGNAS_VECTOROPT()
base_type m_a;
- PALIGNAS_CACHELINE()
size_type m_size;
};