From cbf82e2b7375becd99b9564f2d6dfc33508abd71 Mon Sep 17 00:00:00 2001 From: Myles Busig Date: Sat, 27 Jul 2024 17:52:39 -0600 Subject: [PATCH] Add architecture specific target option macros These macros are defined in target.hpp. This commit adds the macros: NOINLINE - Never inline the function ALWAYS_INLINE - Force the function to be inlined (also adds the inline attribute to the function) TARGET_ARM_MODE - Compile all future functions in ARM mode until TARGET_END_MODE is reached. No-op if not compiling for ARM. TARGET_THUMB_MODE - Compile all future functions in thumb mode until TARGET_END_MODE is reached. No-op if not compiling for ARM. TARGET_END_MODE - Undo the last TARGET_*_MODE option. ARM_MODE - Compile this function in ARM mode. THUMB_MODE - Compile this function in thumb mode. --- include/mtl/target.hpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 include/mtl/target.hpp diff --git a/include/mtl/target.hpp b/include/mtl/target.hpp new file mode 100644 index 0000000..9a186df --- /dev/null +++ b/include/mtl/target.hpp @@ -0,0 +1,27 @@ +#pragma once + +#ifndef __GNUC__ +#error Failed to create target macros. Compiler is not GCC. +#endif + +#define NOINLINE [[gnu::noinline]] +#define ALWAYS_INLINE [[gnu::always_inline]] inline + +#ifdef __arm__ + +#define TARGET_ARM_MODE _Pragma("GCC push_options") _Pragma("GCC target(\"arm\")") +#define TARGET_THUMB_MODE _Pragma("GCC push_options") _Pragma("GCC target(\"thumb\")") +#define TARGET_END_MODE _Pragma("GCC pop_options") +#define ARM_MODE [[gnu::target("arm")]] +#define THUMB_MODE [[gnu::target("thumb")]] + +#else + +#define TARGET_ARM_MODE +#define TARGET_THUMB_MODE +#define TARGET_END_MODE +#define ARM_MODE +#define THUMB_MODE + +#endif +