Skip to content

Commit

Permalink
Support L1 cache line size up to 256 bytes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxim Egorushkin committed Oct 21, 2021
1 parent f2a36a3 commit e50e567
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
14 changes: 8 additions & 6 deletions include/atomic_queue/atomic_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ namespace details {
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

template<size_t elements_per_cache_line> struct GetCacheLineIndexBits { static int constexpr value = 0; };
template<> struct GetCacheLineIndexBits<64> { static int constexpr value = 6; };
template<> struct GetCacheLineIndexBits<32> { static int constexpr value = 5; };
template<> struct GetCacheLineIndexBits<16> { static int constexpr value = 4; };
template<> struct GetCacheLineIndexBits< 8> { static int constexpr value = 3; };
template<> struct GetCacheLineIndexBits< 4> { static int constexpr value = 2; };
template<> struct GetCacheLineIndexBits< 2> { static int constexpr value = 1; };
template<> struct GetCacheLineIndexBits<256> { static int constexpr value = 8; };
template<> struct GetCacheLineIndexBits<128> { static int constexpr value = 7; };
template<> struct GetCacheLineIndexBits< 64> { static int constexpr value = 6; };
template<> struct GetCacheLineIndexBits< 32> { static int constexpr value = 5; };
template<> struct GetCacheLineIndexBits< 16> { static int constexpr value = 4; };
template<> struct GetCacheLineIndexBits< 8> { static int constexpr value = 3; };
template<> struct GetCacheLineIndexBits< 4> { static int constexpr value = 2; };
template<> struct GetCacheLineIndexBits< 2> { static int constexpr value = 1; };

template<bool minimize_contention, unsigned array_size, size_t elements_per_cache_line>
struct GetIndexShuffleBits {
Expand Down
4 changes: 2 additions & 2 deletions src/tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ BOOST_AUTO_TEST_CASE(try_push) {
/* SPSC = */ true
>;

constexpr unsigned CAPACITY = 4096;
constexpr unsigned CAPACITY = CACHE_LINE_SIZE * CACHE_LINE_SIZE;
Queue q(CAPACITY);
BOOST_CHECK_EQUAL(q.capacity(), CAPACITY);
BOOST_CHECK(q.was_empty());
Expand All @@ -177,7 +177,7 @@ BOOST_AUTO_TEST_CASE(try_push) {

BOOST_AUTO_TEST_CASE(size) {
atomic_queue::RetryDecorator<atomic_queue::AtomicQueueB2<float>> q(10);
BOOST_CHECK_EQUAL(q.capacity(), 4096);
BOOST_CHECK_EQUAL(q.capacity(), CACHE_LINE_SIZE * CACHE_LINE_SIZE);
}

BOOST_AUTO_TEST_CASE(power_of_2) {
Expand Down

0 comments on commit e50e567

Please sign in to comment.