Skip to content

Commit

Permalink
singles: new CorradeCpu library.
Browse files Browse the repository at this point in the history
  • Loading branch information
mosra committed Aug 2, 2022
1 parent 8cbd631 commit 6386a97
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 0 deletions.
1 change: 1 addition & 0 deletions doc/corrade-singles.dox
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
30 changes: 30 additions & 0 deletions src/Corrade/Cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
<b></b>
@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 {

Expand Down
88 changes: 88 additions & 0 deletions src/singles/CorradeCpu.h
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions src/singles/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 6386a97

Please sign in to comment.