FFmpeg
cpu.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2018-2022, VideoLAN and dav1d authors
3  * Copyright © 2018-2022, Two Orioles, LLC
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright notice, this
10  * list of conditions and the following disclaimer.
11  *
12  * 2. Redistributions in binary form must reproduce the above copyright notice,
13  * this list of conditions and the following disclaimer in the documentation
14  * and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #ifndef CHECKASM_CPU_H
29 #define CHECKASM_CPU_H
30 
31 #include "checkasm_config.h"
32 #include <stddef.h>
33 #include <stdint.h>
34 
35 #include "checkasm/attributes.h"
36 #include "checkasm/checkasm.h"
37 #include "internal.h"
38 
39 #if ARCH_X86
40 
41 PACKED(typedef struct { uint32_t eax, ebx, ecx, edx; }) CpuidRegisters;
42 
44 checkasm_cpu_cpuid(CpuidRegisters *regs, unsigned leaf, unsigned subleaf);
45 CHECKASM_SELF_API uint64_t checkasm_cpu_xgetbv(unsigned xcr);
46 
47 /* Initializes internal state for checkasm_checked_call(). */
48 void checkasm_init_x86(void);
49 
50 /* Returns whether the vzeroupper state check is active. Exported only for use
51  * inside the selftest. */
52 CHECKASM_SELF_API int checkasm_get_check_vzeroupper(void);
53 
54 /* Returns cpuid and model name. */
55 char *checkasm_get_x86_cpuid(char *buf, size_t buflen);
56 
57 /* YMM and ZMM registers on x86 are turned off to save power when they haven't
58  * been used for some period of time. When they are used there will be a
59  * "warmup" period during which performance will be reduced and inconsistent
60  * which is problematic when trying to benchmark individual functions. We can
61  * work around this by periodically issuing "dummy" instructions that uses
62  * those registers to keep them powered on. */
63 void checkasm_simd_warmup(void);
64 
65 #elif ARCH_RISCV
66 
67 /* Gets the CPU identification registers. */
68 int checkasm_get_cpuids(uint32_t *vendor, uintptr_t *arch, uintptr_t *imp);
69 const char *checkasm_get_riscv_vendor_name(uint32_t vendorid);
70 const char *checkasm_get_riscv_arch_name(char *buf, size_t len,
71  uint32_t vendorid, uintptr_t archid);
72 
73 /* Checks if floating point registers are supported. */
74 CHECKASM_SELF_API int checkasm_has_float(void);
75 
76 /* Checks if vector registers are supported. */
77 CHECKASM_SELF_API int checkasm_has_vector(void);
78 
79 /* Returns the vector length in bits, 0 if unavailable. */
80 unsigned long checkasm_get_vlen(void);
81 
82 void checkasm_checked_call_i(void);
83 void checkasm_checked_call_if(void);
84 void checkasm_checked_call_iv(void);
85 void checkasm_checked_call_ifv(void);
86 
87 #elif ARCH_AARCH64
88 
89 /* Returns a nonzero value if SVE is available, 0 otherwise */
90 int checkasm_has_sve(void);
91 /* Returns a nonzero value if SME is available, 0 otherwise */
92 int checkasm_has_sme(void);
93 
94  #if HAVE_SVE
95 
96 /* Returns the SVE vector length in bits */
97 int checkasm_sve_length(void);
98 
99  #endif
100 
101  #if HAVE_SME
102 
103 /* Returns the SME vector length in bits */
104 int checkasm_sme_length(void);
105 
106  #endif
107 
108 #elif ARCH_ARM
109 
110 void checkasm_init_arm(void);
111 
112 void checkasm_checked_call_vfp(void *func, int dummy, ...);
113 void checkasm_checked_call_novfp(void *func, int dummy, ...);
114 
115 /* Returns a nonzero value if VFP is available, 0 otherwise */
116 CHECKASM_SELF_API int checkasm_has_vfp(void);
117 /* Returns a nonzero value if VFP has 32 registers, 0 otherwise */
118 CHECKASM_SELF_API int checkasm_has_vfpd32(void);
119 
120 #endif
121 
122 void checkasm_init_cpu(void);
123 unsigned long checkasm_getauxval(unsigned long);
124 const char *checkasm_get_jedec_vendor_name(unsigned bank, unsigned offset);
125 
126 #if (ARCH_ARM || ARCH_AARCH64) && defined(__linux__)
127 const char *checkasm_get_arm_cpuinfo(char *buf, size_t buflen, int affinity);
128 #endif
129 
130 #if (ARCH_ARM || ARCH_AARCH64) && defined(_WIN32)
131 const char *checkasm_get_arm_win32_reg(char *buf, size_t buflen, int affinity);
132 #endif
133 
134 /* Iterate over all known CPU information and run the callback on each line */
135 void checkasm_cpu_info(void (*info_cb)(void *priv, const char *fmt, ...), void *priv,
136  const CheckasmConfig *config);
137 
138 #endif /* CHECKASM_CPU_H */
func
int(* func)(AVBPrint *dst, const char *in, const char *arg)
Definition: jacosubdec.c:66
checkasm_config.h
checkasm_get_jedec_vendor_name
const char * checkasm_get_jedec_vendor_name(unsigned bank, unsigned offset)
Definition: cpu.c:159
tf_sess_config.config
config
Definition: tf_sess_config.py:33
dummy
static int dummy
Definition: ffplay.c:3751
attributes.h
Platform and compiler attribute macros.
checkasm_init_cpu
void checkasm_init_cpu(void)
Definition: cpu.c:42
checkasm_getauxval
unsigned long checkasm_getauxval(unsigned long)
Definition: cpu.c:51
CheckasmConfig
Configuration structure for the checkasm test suite.
Definition: checkasm.h:158
offset
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
Definition: writing_filters.txt:86
checkasm_cpu_info
void checkasm_cpu_info(void(*info_cb)(void *priv, const char *fmt,...), void *priv, const CheckasmConfig *config)
Definition: cpu.c:83
len
int len
Definition: vorbis_enc_data.h:426
CHECKASM_SELF_API
#define CHECKASM_SELF_API
Exports symbols for internal use inside the checkasm self-tests.
Definition: checkasm_config.h:254
internal.h
PACKED
#define PACKED(...)
Definition: internal.h:86