-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathportability_arch.hpp
61 lines (51 loc) · 2.25 KB
/
portability_arch.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright 2022-2025 Laurynas Biveinis
#ifndef UNODB_DETAIL_PORTABILITY_ARCH_HPP
#define UNODB_DETAIL_PORTABILITY_ARCH_HPP
/// \file
/// Definitions to abstract differences between architectures.
/// \ingroup internal
//
// CAUTION: [global.hpp] MUST BE THE FIRST INCLUDE IN ALL SOURCE AND
// HEADER FILES !!!
//
// This header defines _GLIBCXX_DEBUG and _GLIBCXX_DEBUG_PEDANTIC for
// DEBUG builds. If some standard headers are included before and
// after those symbols are defined, then that results in different
// container internal structure layouts and that is Not Good.
#include "global.hpp" // IWYU pragma: keep
#include <cstddef>
namespace unodb::detail {
/// \var hardware_constructive_interference_size
/// The maximum size in bytes where multiple variables will be guaranteed to be
/// shared for the purposes of true sharing.
/// \hideinitializer
/// Use this instead of
/// `std::hardware_constructive_interference_size` even if the latter is
/// available, because it is used in public headers and its value may vary,
/// for example, by GCC 12 or later `--param` or `-mtune` flag.
/// \var hardware_destructive_interference_size
/// The minimum size in bytes where multiple variables will be guaranteed to be
/// separated for the purposes of false sharing.
/// \hideinitializer
/// Use this instead of
/// `std::hardware_destructive_interference_size` even if the latter is
/// available, because it is used in public headers and its value may vary,
/// for example, by GCC 12 or later `--param` or `-mtune` flag.
#ifdef UNODB_DETAIL_X86_64
inline constexpr std::size_t hardware_constructive_interference_size = 64;
// Two cache lines for destructive interference due to Intel fetching cache
// lines in pairs
inline constexpr std::size_t hardware_destructive_interference_size = 128;
#elif defined(__aarch64__)
inline constexpr std::size_t hardware_constructive_interference_size = 64;
// Value stolen from GCC 12 implementation
inline constexpr std::size_t hardware_destructive_interference_size = 256;
#else
#error Needs porting
#endif
static_assert(hardware_constructive_interference_size >=
alignof(std::max_align_t));
static_assert(hardware_destructive_interference_size >=
alignof(std::max_align_t));
} // namespace unodb::detail
#endif