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:
Nathaniel Filardo
2020-11-20 12:56:03 +00:00
committed by Matthew Parkinson
parent a6d18f842a
commit db0ca64ff3
5 changed files with 92 additions and 34 deletions

View File

@@ -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
View 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
View 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

View File

@@ -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