From db0ca64ff3d8f6ea3e1c0a8dcd6d5387bbc1a4d2 Mon Sep 17 00:00:00 2001 From: Nathaniel Filardo Date: Fri, 20 Nov 2020 12:56:03 +0000 Subject: [PATCH] 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. --- CMakeLists.txt | 2 +- src/aal/aal.h | 37 ++++----------------------------- src/aal/aal_concept.h | 48 +++++++++++++++++++++++++++++++++++++++++++ src/aal/aal_consts.h | 37 +++++++++++++++++++++++++++++++++ src/ds/concept.h | 2 ++ 5 files changed, 92 insertions(+), 34 deletions(-) create mode 100644 src/aal/aal_concept.h create mode 100644 src/aal/aal_consts.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 693b82a..df91b70 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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} diff --git a/src/aal/aal.h b/src/aal/aal.h index 69d5480..471b460 100644 --- a/src/aal/aal.h +++ b/src/aal/aal.h @@ -1,5 +1,8 @@ #pragma once +#include "../ds/concept.h" #include "../ds/defines.h" +#include "aal_concept.h" +#include "aal_consts.h" #include #include @@ -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; - template + template constexpr static bool aal_supports = (AAL::aal_features & F) == F; } // namespace snmalloc diff --git a/src/aal/aal_concept.h b/src/aal/aal_concept.h new file mode 100644 index 0000000..e199e07 --- /dev/null +++ b/src/aal/aal_concept.h @@ -0,0 +1,48 @@ +#pragma once + +#ifdef __cpp_concepts +# include "../ds/concept.h" +# include "aal_consts.h" + +# include +# include + +namespace snmalloc +{ + /** + * AALs must advertise the bit vector of supported features, their name, + * + */ + template + concept ConceptAAL_static_members = requires() + { + typename std::integral_constant; + typename std::integral_constant; + }; + + /** + * AALs provide a prefetch operation. + */ + template + concept ConceptAAL_prefetch = requires(void *ptr) + { + { AAL::prefetch(ptr) } noexcept -> ConceptSame; + }; + + /** + * AALs provide a notion of high-precision timing. + */ + template + concept ConceptAAL_tick = requires() + { + { AAL::tick() } noexcept -> ConceptSame; + }; + + template + concept ConceptAAL = + ConceptAAL_static_members && + ConceptAAL_prefetch && + ConceptAAL_tick; + +} // namespace snmalloc +#endif diff --git a/src/aal/aal_consts.h b/src/aal/aal_consts.h new file mode 100644 index 0000000..24b31ff --- /dev/null +++ b/src/aal/aal_consts.h @@ -0,0 +1,37 @@ +#pragma once +#include + +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 diff --git a/src/ds/concept.h b/src/ds/concept.h index d935417..4e489ed 100644 --- a/src/ds/concept.h +++ b/src/ds/concept.h @@ -1,5 +1,7 @@ #pragma once +#include + /** * C++20 concepts are referenced as if they were types in declarations within * template parameters (e.g. "template ..."). That is, they