Derive-C
Loading...
Searching...
No Matches
cpu_features.h
Go to the documentation of this file.
1#pragma once
2
3#include <stdbool.h>
4#include <stdio.h>
5
8
9#define _DC_CPU_FEATURES(F) \
10 F(SSE, "sse") \
11 F(SSE2, "sse2") \
12 F(SSE3, "sse3") \
13 F(SSSE3, "ssse3") \
14 F(SSE4_1, "sse4.1") \
15 F(SSE4_2, "sse4.2") \
16 F(AVX, "avx") \
17 F(AVX2, "avx2") \
18 F(FMA, "fma") \
19 F(BMI, "bmi") \
20 F(BMI2, "bmi2") \
21 F(AES, "aes") \
22 F(PCLMUL, "pclmul") \
23 F(POPCNT, "popcnt") \
24 F(LZCNT, "lzcnt")
25
26typedef struct {
27 char const* name;
28 bool const compiled_with;
31
32typedef struct {
33#define _DC_FEATURE_DECLARE(name, _) dc_cpu_feature name;
35#undef _DC_FEATURE_DECLARE
37
39 return (dc_cpu_features){
40#define _DC_FEATURE_DETECT(feature_name, runtime_name) \
41 .feature_name = {.name = runtime_name, \
42 .compiled_with = DC_IS_DEFINED(__##feature_name##__), \
43 .runtime_supported = (bool)__builtin_cpu_supports(runtime_name)},
45#undef _DC_FEATURE_DETECT
46 };
47}
48
50 FILE* stream) {
51 (void)fmt;
52 fprintf(stream, "| %-12s | %-8s | %-8s |\n", "feature", "compiler", "runtime");
53 fprintf(stream, "| %-12s | %-8s | %-8s |\n", "------------", "--------", "--------");
54#define _DC_FEATURE_ROW(feature, _) \
55 fprintf(stream, "| %-12s | %-8s | %-8s |\n", self->feature.name, \
56 self->feature.compiled_with ? "yes" : "no", \
57 self->feature.runtime_supported ? "yes" : "no");
59#undef _DC_FEATURE_ROW
60 fprintf(stream, "\n");
61}
62
static dc_cpu_features dc_cpu_features_get()
#define _DC_FEATURE_DETECT(feature_name, runtime_name)
static DC_PUBLIC void dc_cpu_features_dump(FILE *stream)
#define _DC_FEATURE_ROW(feature, _)
static DC_PUBLIC void dc_cpu_features_debug(dc_cpu_features const *self, dc_debug_fmt fmt, FILE *stream)
#define _DC_CPU_FEATURES(F)
Definition cpu_features.h:9
#define _DC_FEATURE_DECLARE(name, _)
static DC_PUBLIC dc_debug_fmt dc_debug_fmt_new()
Definition fmt.h:15
#define DC_PUBLIC
Definition namespace.h:25
char const * name
bool const runtime_supported
bool const compiled_with
Debug format helpers for debug printin data structures.
Definition fmt.h:11
static DC_PUBLIC FILE * stream(SELF *self)
Definition template.h:108