Derive-C
Loading...
Searching...
No Matches
cpu_features.h File Reference
#include <stdbool.h>
#include <stdio.h>
#include <derive-c/core/debug/fmt.h>
#include <derive-c/core/traits/debug.h>

Go to the source code of this file.

Data Structures

struct  dc_cpu_feature
struct  dc_cpu_features

Macros

#define _DC_CPU_FEATURES(F)
#define _DC_FEATURE_DECLARE(name, _)
#define _DC_FEATURE_DETECT(feature_name, runtime_name)
#define _DC_FEATURE_ROW(feature, _)

Functions

static dc_cpu_features dc_cpu_features_get ()
static DC_PUBLIC void dc_cpu_features_debug (dc_cpu_features const *self, dc_debug_fmt fmt, FILE *stream)
static DC_PUBLIC void dc_cpu_features_dump (FILE *stream)

Macro Definition Documentation

◆ _DC_CPU_FEATURES

#define _DC_CPU_FEATURES ( F)
Value:
F(SSE, "sse") \
F(SSE2, "sse2") \
F(SSE3, "sse3") \
F(SSSE3, "ssse3") \
F(SSE4_1, "sse4.1") \
F(SSE4_2, "sse4.2") \
F(AVX, "avx") \
F(AVX2, "avx2") \
F(FMA, "fma") \
F(BMI, "bmi") \
F(BMI2, "bmi2") \
F(AES, "aes") \
F(PCLMUL, "pclmul") \
F(POPCNT, "popcnt") \
F(LZCNT, "lzcnt")

Definition at line 9 of file cpu_features.h.

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")

◆ _DC_FEATURE_DECLARE

#define _DC_FEATURE_DECLARE ( name,
_ )
Value:

Definition at line 33 of file cpu_features.h.

◆ _DC_FEATURE_DETECT

#define _DC_FEATURE_DETECT ( feature_name,
runtime_name )
Value:
.feature_name = {.name = runtime_name, \
.compiled_with = DC_IS_DEFINED(__##feature_name##__), \
.runtime_supported = (bool)__builtin_cpu_supports(runtime_name)},
#define DC_IS_DEFINED(MACRO)
Definition namespace.h:8

◆ _DC_FEATURE_ROW

#define _DC_FEATURE_ROW ( feature,
_ )
Value:
fprintf(stream, "| %-12s | %-8s | %-8s |\n", self->feature.name, \
self->feature.compiled_with ? "yes" : "no", \
self->feature.runtime_supported ? "yes" : "no");
static DC_PUBLIC FILE * stream(SELF *self)
Definition template.h:108

Function Documentation

◆ dc_cpu_features_debug()

DC_PUBLIC void dc_cpu_features_debug ( dc_cpu_features const * self,
dc_debug_fmt fmt,
FILE * stream )
static

Definition at line 49 of file cpu_features.h.

50 {
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}
#define _DC_FEATURE_ROW(feature, _)
#define _DC_CPU_FEATURES(F)
Definition cpu_features.h:9

◆ dc_cpu_features_dump()

DC_PUBLIC void dc_cpu_features_dump ( FILE * stream)
static
Examples
complex/prime_sieve.c.

Definition at line 63 of file cpu_features.h.

63 {
66}
static dc_cpu_features dc_cpu_features_get()
static DC_PUBLIC void dc_cpu_features_debug(dc_cpu_features const *self, dc_debug_fmt fmt, FILE *stream)
static DC_PUBLIC dc_debug_fmt dc_debug_fmt_new()
Definition fmt.h:15

◆ dc_cpu_features_get()

dc_cpu_features dc_cpu_features_get ( )
static

Definition at line 38 of file cpu_features.h.

38 {
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}
#define _DC_FEATURE_DETECT(feature_name, runtime_name)