NFC: Add an AAL Concept, too
While here, pull out some constants to their own header. Eventually we'll want to match on AalFeatures in the AAL Concept.
This commit is contained in:
committed by
Matthew Parkinson
parent
a6d18f842a
commit
db0ca64ff3
@@ -82,7 +82,7 @@ macro(clangformat_targets)
|
||||
file(GLOB_RECURSE ALL_SOURCE_FILES *.cc *.h *.hh)
|
||||
# clangformat does not yet understand concepts well; for the moment, don't
|
||||
# ask it to format them. See https://reviews.llvm.org/D79773
|
||||
list(FILTER ALL_SOURCE_FILES EXCLUDE REGEX "src/pal/pal_concept\.h$")
|
||||
list(FILTER ALL_SOURCE_FILES EXCLUDE REGEX "src/[^/]*/[^/]*_concept\.h$")
|
||||
add_custom_target(
|
||||
clangformat
|
||||
COMMAND ${CLANG_FORMAT}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
#pragma once
|
||||
#include "../ds/concept.h"
|
||||
#include "../ds/defines.h"
|
||||
#include "aal_concept.h"
|
||||
#include "aal_consts.h"
|
||||
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
@@ -29,38 +32,6 @@
|
||||
|
||||
namespace snmalloc
|
||||
{
|
||||
/**
|
||||
* Flags in a bitfield of attributes of this architecture, much like
|
||||
* PalFeatures.
|
||||
*/
|
||||
enum AalFeatures : uint64_t
|
||||
{
|
||||
/**
|
||||
* This architecture does not discriminate between integers and pointers,
|
||||
* and so may use bit operations on pointer values.
|
||||
*/
|
||||
IntegerPointers = (1 << 0),
|
||||
/**
|
||||
* This architecture cannot access cpu cycles counters.
|
||||
*/
|
||||
NoCpuCycleCounters = (1 << 1),
|
||||
/**
|
||||
* This architecture enforces strict pointer provenance; we bound the
|
||||
* pointers given out on malloc() and friends and must, therefore retain
|
||||
* internal high-privilege pointers for recycling memory on free().
|
||||
*/
|
||||
StrictProvenance = (1 << 2),
|
||||
};
|
||||
|
||||
enum AalName : int
|
||||
{
|
||||
ARM,
|
||||
PowerPC,
|
||||
X86,
|
||||
X86_SGX,
|
||||
Sparc,
|
||||
};
|
||||
|
||||
/**
|
||||
* Architecture Abstraction Layer. Includes default implementations of some
|
||||
* functions using compiler builtins. Falls back to the definitions in the
|
||||
@@ -160,7 +131,7 @@ namespace snmalloc
|
||||
{
|
||||
using Aal = AAL_Generic<AAL_Arch>;
|
||||
|
||||
template<AalFeatures F, typename AAL = Aal>
|
||||
template<AalFeatures F, SNMALLOC_CONCEPT(ConceptAAL) AAL = Aal>
|
||||
constexpr static bool aal_supports = (AAL::aal_features & F) == F;
|
||||
} // namespace snmalloc
|
||||
|
||||
|
||||
48
src/aal/aal_concept.h
Normal file
48
src/aal/aal_concept.h
Normal file
@@ -0,0 +1,48 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef __cpp_concepts
|
||||
# include "../ds/concept.h"
|
||||
# include "aal_consts.h"
|
||||
|
||||
# include <cstdint>
|
||||
# include <utility>
|
||||
|
||||
namespace snmalloc
|
||||
{
|
||||
/**
|
||||
* AALs must advertise the bit vector of supported features, their name,
|
||||
*
|
||||
*/
|
||||
template<typename AAL>
|
||||
concept ConceptAAL_static_members = requires()
|
||||
{
|
||||
typename std::integral_constant<uint64_t, AAL::aal_features>;
|
||||
typename std::integral_constant<int, AAL::aal_name>;
|
||||
};
|
||||
|
||||
/**
|
||||
* AALs provide a prefetch operation.
|
||||
*/
|
||||
template<typename AAL>
|
||||
concept ConceptAAL_prefetch = requires(void *ptr)
|
||||
{
|
||||
{ AAL::prefetch(ptr) } noexcept -> ConceptSame<void>;
|
||||
};
|
||||
|
||||
/**
|
||||
* AALs provide a notion of high-precision timing.
|
||||
*/
|
||||
template<typename AAL>
|
||||
concept ConceptAAL_tick = requires()
|
||||
{
|
||||
{ AAL::tick() } noexcept -> ConceptSame<uint64_t>;
|
||||
};
|
||||
|
||||
template<typename AAL>
|
||||
concept ConceptAAL =
|
||||
ConceptAAL_static_members<AAL> &&
|
||||
ConceptAAL_prefetch<AAL> &&
|
||||
ConceptAAL_tick<AAL>;
|
||||
|
||||
} // namespace snmalloc
|
||||
#endif
|
||||
37
src/aal/aal_consts.h
Normal file
37
src/aal/aal_consts.h
Normal file
@@ -0,0 +1,37 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
|
||||
namespace snmalloc
|
||||
{
|
||||
/**
|
||||
* Flags in a bitfield of attributes of this architecture, much like
|
||||
* PalFeatures.
|
||||
*/
|
||||
enum AalFeatures : uint64_t
|
||||
{
|
||||
/**
|
||||
* This architecture does not discriminate between integers and pointers,
|
||||
* and so may use bit operations on pointer values.
|
||||
*/
|
||||
IntegerPointers = (1 << 0),
|
||||
/**
|
||||
* This architecture cannot access cpu cycles counters.
|
||||
*/
|
||||
NoCpuCycleCounters = (1 << 1),
|
||||
/**
|
||||
* This architecture enforces strict pointer provenance; we bound the
|
||||
* pointers given out on malloc() and friends and must, therefore retain
|
||||
* internal high-privilege pointers for recycling memory on free().
|
||||
*/
|
||||
StrictProvenance = (1 << 2),
|
||||
};
|
||||
|
||||
enum AalName : int
|
||||
{
|
||||
ARM,
|
||||
PowerPC,
|
||||
X86,
|
||||
X86_SGX,
|
||||
Sparc,
|
||||
};
|
||||
} // namespace snmalloc
|
||||
@@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
/**
|
||||
* C++20 concepts are referenced as if they were types in declarations within
|
||||
* template parameters (e.g. "template<FooConcept Foo> ..."). That is, they
|
||||
|
||||
Reference in New Issue
Block a user