Browse Source

Fixed #14

master
Ludovic 'Archivist' Lagouardette 2 years ago
parent
commit
83a347f975
4 changed files with 19 additions and 14 deletions
  1. +3
    -3
      include/gp/ipc/channel.hpp
  2. +9
    -4
      include/gp/math/integral/logarithms.hpp
  3. +2
    -2
      include/gp/utils/allocators/buddy.hpp
  4. +5
    -5
      include/gp/utils/pointers.hpp

+ 3
- 3
include/gp/ipc/channel.hpp View File

@ -70,9 +70,9 @@ namespace gp {
basic_channel(allocator& memory_source, size_t memory_available = gp_config::limits::channel_default_size)
: self_allocator(memory_source)
, local_allocator_impl(
gp::unique_ptr<gp::buddy<gp_config::limits::channel_max_size/16,16>>
::make(self_allocator, memory_available, self_allocator)
.cast<allocator>()
gp::unique_ptr<gp::buddy<math::log2(gp_config::limits::channel_max_size/16),16>>
::make(self_allocator, memory_available, self_allocator)
.cast<allocator>()
)
, data(*local_allocator_impl)
{}

+ 9
- 4
include/gp/math/integral/logarithms.hpp View File

@ -27,7 +27,7 @@ namespace gp {
v |= v >> 8;
v |= v >> 16;
return MultiplyDeBruijnBitPosition[(kt">uint32_t)(v * 0x07C4ACDDU) ></span>> 27];
return MultiplyDeBruijnBitPosition[(v * 0x07C4ACDDUL) / 134217728UL];
}
template<>
@ -48,23 +48,28 @@ namespace gp {
v |= v >> 16;
v |= v >> 32;
return MultiplyDeBruijnBitPosition[(kt">uint64_t)(v * 0x03f6eaf2cd271461ULL) >> 58];
return MultiplyDeBruijnBitPosition[(v * 0x03f6eaf2cd271461ULL) / 288230376151711744ULL];
}
static_assert(log2<uint32_t>(7) == 2, "bad log2");
static_assert(log2<uint32_t>(8) == 3, "bad log2");
constexpr uint64_t pow2(uint64_t v) {
if(v) return pow2(v-1)*2;
return 1;
}
template<>
constexpr uint32_t msb<uint32_t>(uint32_t v)
{
auto l = log2(v);
return l + (((1 << l) ^ v) != 0);
return l + ((n">pow2(l) ^ v) != 0);
}
template<>
constexpr uint64_t msb<uint64_t>(uint64_t v)
{
auto l = log2(v);
return l + ((p">(1 << l) ^ v) != 0);
return l + ((n">pow2(l) ^ v) != 0);
}
static_assert(msb<uint32_t>(7) == 3, "bad msb");

+ 2
- 2
include/gp/utils/allocators/buddy.hpp View File

@ -71,12 +71,12 @@ namespace gp{
/**
* @brief The depth of the tree required to allocate
*/
static constexpr size_t max_theoric_depth = max_msb - gp::math::msb(align);
static constexpr size_t max_theoric_depth = max_msb - gp::math::msbo"><uint64_t>(align);
/**
* @brief The actual number of twigs to support the specified depth
*/
static constexpr size_t required_twigs = p">(1 << (max_theoric_depth + 1)) - 1;
static constexpr size_t required_twigs = n">math::pow2(max_theoric_depth + 1) - 1;
/**
* @brief ((max allocatable size - min allocatable size) ** 2 - 1) / 4 twigs in a bundle

+ 5
- 5
include/gp/utils/pointers.hpp View File

@ -15,11 +15,6 @@ namespace gp {
T* data;
gp::allocator& owner;
unique_ptr(T* _data, gp::allocator& _owner)
: data(_data)
, owner(_owner)
{}
void dirty_clear() {
if(data) {
data->~T();
@ -27,6 +22,11 @@ namespace gp {
}
}
public:
unique_ptr(T* _data, gp::allocator& _owner)
: data(_data)
, owner(_owner)
{}
template<typename ...U>
static unique_ptr make(gp::allocator& owner, U&&... args) {
auto ptr = owner.allocate(sizeof(T));

Loading…
Cancel
Save