From: Rusty Russell Date: Tue, 11 Jun 2019 04:54:11 +0000 (+0930) Subject: ccan/compiler: add cpu_supports() macro. X-Git-Url: http://git.ozlabs.org/?p=ccan;a=commitdiff_plain;h=2c77e8bd8c05825b779b14a6d5c7ab302c12a361 ccan/compiler: add cpu_supports() macro. Signed-off-by: Rusty Russell --- 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 */