diff --git a/doc/corrade-singles.dox b/doc/corrade-singles.dox index 4b59f7cc4..a0dceb7db 100644 --- a/doc/corrade-singles.dox +++ b/doc/corrade-singles.dox @@ -53,6 +53,7 @@ Class, library or header | Single-header version @ref Containers::Pointer | [CorradePointer.h](https://github.com/mosra/magnum-singles/tree/master/CorradePointer.h) @ref Containers::Reference | [CorradeReference.h](https://github.com/mosra/magnum-singles/tree/master/CorradeReference.h) @ref Containers::ScopeGuard | [CorradeScopeGuard.h](https://github.com/mosra/magnum-singles/tree/master/CorradeScopeGuard.h) +@ref Corrade::Cpu | [CorradeCpu.h](https://github.com/mosra/magnum-singles/tree/master/CorradeCpu.h) @ref Corrade/Utility/StlForwardArray.h | [CorradeStlForwardArray.h](https://github.com/mosra/magnum-singles/tree/master/CorradeStlForwardArray.h) @ref Corrade/Utility/StlForwardString.h | [CorradeStlForwardString.h](https://github.com/mosra/magnum-singles/tree/master/CorradeStlForwardString.h) @ref Corrade/Utility/StlForwardTuple.h | [CorradeStlForwardTuple.h](https://github.com/mosra/magnum-singles/tree/master/CorradeStlForwardTuple.h) diff --git a/src/Corrade/Cpu.h b/src/Corrade/Cpu.h index 241a2e255..32d62d128 100644 --- a/src/Corrade/Cpu.h +++ b/src/Corrade/Cpu.h @@ -74,6 +74,10 @@ find_package(Corrade REQUIRED Utility) target_link_libraries(your-app PRIVATE Corrade::Utility) @endcode +This namespace together with all related macros is additionally available in a +form of a @ref Cpu-single-header "single-header library". See also +@ref building-corrade and @ref corrade-cmake for more information. + @section Cpu-usage Usage The @ref Cpu namespace contains tags such as @ref Cpu::Avx2, @ref Cpu::Sse2, @@ -397,6 +401,32 @@ Finally, when exposed in a header as appropriate, both the function and the function pointer variant can be then called the same way: @snippet Corrade.cpp Cpu-usage-automatic-cached-dispatch-call + +@anchor Cpu-single-header + + + +@m_class{m-block m-success} + +@par Single-header version + This namespace together with all related macros is also available as a + single-header, dependency-less [CorradeCpu.h](https://github.com/mosra/magnum-singles/tree/master/CorradeCpu.h) + library in the Magnum Singles repository for easier integration into your + projects. See @ref corrade-singles for more information. +@par + To avoid bloat from OS-specific headers, this library contains a deinlined + implementation part, in particular for runtime feature detection on ARM. + Dedicate *exactly one* file in your project and add the following to it: +@par + @code{.cpp} + #define CORRADE_CPU_IMPLEMENTATION + #include "CorradeCpu.h" + @endcode +@par + If you need the deinlined symbols to be exported from a shared library, + @cpp #define CORRADE_UTILITY_EXPORT @ce as appropriate. To enable the + IFUNC functionality, @cpp #define CORRADE_CPU_USE_IFUNC @ce before + including the file. */ namespace Cpu { diff --git a/src/singles/CorradeCpu.h b/src/singles/CorradeCpu.h new file mode 100644 index 000000000..675d7d2e8 --- /dev/null +++ b/src/singles/CorradeCpu.h @@ -0,0 +1,88 @@ +/* + Corrade::Cpu + — compile-time and runtime CPU feature detection and dispatch + + https://doc.magnum.graphics/corrade/namespaceCorrade_1_1Cpu.html + + This is a single-header library generated from the Corrade project. With + the goal being easy integration, it's deliberately free of all comments + to keep the file size small. More info, detailed changelogs and docs here: + + - Project homepage — https://magnum.graphics/corrade/ + - Documentation — https://doc.magnum.graphics/corrade/ + - GitHub project page — https://github.com/mosra/corrade + - GitHub Singles repository — https://github.com/mosra/magnum-singles + + To avoid bloat from OS-specific headers, this library contains a deinlined + implementation part, in particular for runtime feature detection on ARM. + Dedicate *exactly one* file in your project and add the following to it: + + #define CORRADE_CPU_IMPLEMENTATION + #include "CorradeCpu.h" + + If you need the deinlined symbols to be exported from a shared library, + #define CORRADE_UTILITY_EXPORT as appropriate. To enable the IFUNC + functionality, #define CORRADE_CPU_USE_IFUNC before including the file. + + v2020.06-1015-g8cbd6 (2022-08-02) + - Initial release + + Generated from Corrade {{revision}}, {{stats:loc}} / {{stats:preprocessed}} LoC +*/ + +#include "base.h" + +/* Detect platforms based on preprocessor defines. Corrade itself does that + through CMake and bakes that into configure.h, which we can't do here. */ +/* https://stackoverflow.com/a/8249232 */ +#ifdef __ANDROID__ +#define CORRADE_TARGET_ANDROID +#endif +/* https://stackoverflow.com/a/41508246 */ +#ifdef __EMSCRIPTEN__ +#define CORRADE_TARGET_EMSCRIPTEN +#endif +/* https://stackoverflow.com/a/8249232 */ +#ifdef __APPLE__ +#define CORRADE_TARGET_APPLE +#endif + +/* Supply the configure.h template instead to avoid using baked-in defines */ +#include "Corrade/configure.h.cmake" +#pragma ACME enable Corrade_configure_h + +/* Contains just Cpu::Features forward declaration, which we don't need */ +#pragma ACME enable Corrade_Corrade_h + +/* We need just the INLINE macros and _CORRADE_HELPER_PASTE2 */ +#pragma ACME enable Corrade_Utility_Macros_h +#ifndef CorradeCpu_h +#define CorradeCpu_h +#ifdef CORRADE_TARGET_GCC +#define CORRADE_ALWAYS_INLINE __attribute__((always_inline)) inline +#elif defined(CORRADE_TARGET_MSVC) +#define CORRADE_ALWAYS_INLINE __forceinline +#else +#define CORRADE_ALWAYS_INLINE inline +#endif + +#ifdef CORRADE_TARGET_GCC +#define CORRADE_NEVER_INLINE __attribute__((noinline)) +#elif defined(CORRADE_TARGET_MSVC) +#define CORRADE_NEVER_INLINE __declspec(noinline) +#else +#define CORRADE_NEVER_INLINE +#endif + +#define _CORRADE_HELPER_PASTE2(a, b) a ## b + +/* For the deinlined runtimeFeatures() implementation on ARM */ +#ifndef CORRADE_UTILITY_EXPORT +#define CORRADE_UTILITY_EXPORT +#endif +#endif +#include "Corrade/Cpu.h" +#ifdef CORRADE_CPU_IMPLEMENTATION +// {{includes}} +#include "Corrade/Cpu.cpp" +#endif diff --git a/src/singles/generate.sh b/src/singles/generate.sh index 5b5077a88..2762d2b15 100755 --- a/src/singles/generate.sh +++ b/src/singles/generate.sh @@ -13,3 +13,5 @@ set -e ../acme/acme.py CorradeStlForwardTuple.h --output ../../../magnum-singles ../acme/acme.py CorradeStlForwardVector.h --output ../../../magnum-singles ../acme/acme.py CorradeStlMath.h --output ../../../magnum-singles + +../acme/acme.py CorradeCpu.h --output ../../../magnum-singles