Skip to content

Commit

Permalink
Merge pull request #4235 from msimberg/cacheline-no-alignas
Browse files Browse the repository at this point in the history
Don't use alignas in cache_{aligned,line}_data
  • Loading branch information
msimberg committed Nov 25, 2019
2 parents d4c6d54 + 84404ea commit 23bdb6c
Showing 1 changed file with 25 additions and 32 deletions.
57 changes: 25 additions & 32 deletions libs/concurrency/include/hpx/concurrency/cache_line_data.hpp
Expand Up @@ -11,6 +11,7 @@
#include <hpx/config.hpp>

#include <cstddef>
#include <utility>

namespace hpx {

Expand Down Expand Up @@ -41,55 +42,47 @@ namespace hpx {
}
} // namespace detail

// NOTE: We do not use alignas here because asking for overaligned
// memory is significantly more expensive than asking for unaligned
// memory. Padding the struct is cheaper and enough for internal
// purposes.

// NOTE: The implementations below are currently identical because of
// the above issue. Both names are kept for compatibility.

///////////////////////////////////////////////////////////////////////////
// special struct to ensure cache line alignment of a data type
#if defined(HPX_HAVE_CXX11_ALIGNAS) && defined(HPX_HAVE_CXX17_ALIGNED_NEW) && \
!defined(__NVCC__)
template <typename Data>
struct alignas(threads::get_cache_line_size()) cache_aligned_data
{
Data data_;
};
#else
template <typename Data>
struct cache_aligned_data
{
cache_aligned_data()
: data_{}
{
}

cache_aligned_data(Data&& data)
: data_{std::move(data)}
{
}

cache_aligned_data(Data const& data)
: data_{data}
{
}

// pad to cache line size bytes
Data data_;

// cppcheck-suppress unusedVariable
char cacheline_pad[detail::get_cache_line_padding_size(
sizeof(Data))];
};
#endif

///////////////////////////////////////////////////////////////////////////
// special struct to data type is cache line aligned and fully occupies a
// cache line
#if defined(HPX_HAVE_CXX11_ALIGNAS) && defined(HPX_HAVE_CXX17_ALIGNED_NEW) && \
!defined(__NVCC__)
template <typename Data>
struct alignas(threads::get_cache_line_size()) cache_line_data
{
Data data_;

// cppcheck-suppress unusedVariable
char cacheline_pad[detail::get_cache_line_padding_size(
sizeof(Data))];
};
#else
template <typename Data>
struct cache_line_data
{
// pad to cache line size bytes
Data data_;

// cppcheck-suppress unusedVariable
char cacheline_pad[detail::get_cache_line_padding_size(
sizeof(Data))];
};
#endif

using cache_line_data = cache_aligned_data<Data>;
} // namespace util

} // namespace hpx
Expand Down

0 comments on commit 23bdb6c

Please sign in to comment.