From 2c77e8bd8c05825b779b14a6d5c7ab302c12a361 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 11 Jun 2019 14:24:11 +0930 Subject: [PATCH] ccan/compiler: add cpu_supports() macro. Signed-off-by: Rusty Russell --- ccan/compiler/compiler.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/ccan/compiler/compiler.h b/ccan/compiler/compiler.h index 624474b7..1bbb3b8b 100644 --- a/ccan/compiler/compiler.h +++ b/ccan/compiler/compiler.h @@ -286,4 +286,19 @@ #define LAST_ARG_NULL #endif +#if HAVE_BUILTIN_CPU_SUPPORTS +/** + * cpu_supports - test if current CPU supports the named feature. + * + * This takes a literal string, and currently only works on glibc platforms. + * + * Example: + * if (cpu_supports("mmx")) + * printf("MMX support engaged!\n"); + */ +#define cpu_supports(x) __builtin_cpu_supports(x) +#else +#define cpu_supports(x) 0 +#endif /* HAVE_BUILTIN_CPU_SUPPORTS */ + #endif /* CCAN_COMPILER_H */ -- 2.39.2