FFmpeg
Loading...
Searching...
No Matches
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
41PACKED(typedef struct { uint32_t eax, ebx, ecx, edx; }) CpuidRegisters;
42
44checkasm_cpu_cpuid(CpuidRegisters *regs, unsigned leaf, unsigned subleaf);
45CHECKASM_SELF_API uint64_t checkasm_cpu_xgetbv(unsigned xcr);
46
47/* Initializes internal state for checkasm_checked_call(). */
48void checkasm_init_x86(void);
49
50/* Returns whether the vzeroupper state check is active. Exported only for use
51 * inside the selftest. */
52CHECKASM_SELF_API int checkasm_get_check_vzeroupper(void);
53
54/* Returns cpuid and model name. */
55char *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. */
63void checkasm_simd_warmup(void);
64
65#elif ARCH_RISCV
66
67/* Gets the CPU identification registers. */
68int checkasm_get_cpuids(uint32_t *vendor, uintptr_t *arch, uintptr_t *imp);
69const char *checkasm_get_riscv_vendor_name(uint32_t vendorid);
70const 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. */
74CHECKASM_SELF_API int checkasm_has_float(void);
75
76/* Checks if vector registers are supported. */
77CHECKASM_SELF_API int checkasm_has_vector(void);
78
79/* Returns the vector length in bits, 0 if unavailable. */
80unsigned long checkasm_get_vlen(void);
81
82void checkasm_checked_call_i(void);
83void checkasm_checked_call_if(void);
84void checkasm_checked_call_iv(void);
85void checkasm_checked_call_ifv(void);
86
87#elif ARCH_AARCH64
88
89/* Returns a nonzero value if SVE is available, 0 otherwise */
90int checkasm_has_sve(void);
91/* Returns a nonzero value if SME is available, 0 otherwise */
92int checkasm_has_sme(void);
93
94 #if HAVE_SVE
95
96/* Returns the SVE vector length in bits */
97int checkasm_sve_length(void);
98
99 #endif
100
101 #if HAVE_SME
102
103/* Returns the SME vector length in bits */
104int checkasm_sme_length(void);
105
106 #endif
107
108#elif ARCH_ARM
109
110void checkasm_init_arm(void);
111
112void checkasm_checked_call_vfp(void *func, int dummy, ...);
113void checkasm_checked_call_novfp(void *func, int dummy, ...);
114
115/* Returns a nonzero value if VFP is available, 0 otherwise */
116CHECKASM_SELF_API int checkasm_has_vfp(void);
117/* Returns a nonzero value if VFP has 32 registers, 0 otherwise */
118CHECKASM_SELF_API int checkasm_has_vfpd32(void);
119
120#endif
121
122void checkasm_init_cpu(void);
123unsigned long checkasm_getauxval(unsigned long);
124const char *checkasm_get_jedec_vendor_name(unsigned bank, unsigned offset);
125
126#if (ARCH_ARM || ARCH_AARCH64) && defined(__linux__)
127const char *checkasm_get_arm_cpuinfo(char *buf, size_t buflen, int affinity);
128#endif
129
130#if (ARCH_ARM || ARCH_AARCH64) && defined(_WIN32)
131const 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 */
135void checkasm_cpu_info(void (*info_cb)(void *priv, const char *fmt, ...), void *priv,
136 const CheckasmConfig *config);
137
138#endif /* CHECKASM_CPU_H */
#define CHECKASM_SELF_API
Exports symbols for internal use inside the checkasm self-tests.
static int dummy
Definition ffplay.c:3754
unsigned offset
Definition libaomenc.c:763
int(* func)(AVBPrint *dst, const char *in, const char *arg)
Definition jacosubdec.c:66
Configuration structure for the checkasm test suite.
Definition checkasm.h:182
Platform and compiler attribute macros.
void checkasm_init_cpu(void)
Definition cpu.c:42
void checkasm_cpu_info(void(*info_cb)(void *priv, const char *fmt,...), void *priv, const CheckasmConfig *config)
Definition cpu.c:83
unsigned long checkasm_getauxval(unsigned long)
Definition cpu.c:51
const char * checkasm_get_jedec_vendor_name(unsigned bank, unsigned offset)
Definition cpu.c:159
#define PACKED(...)
Definition internal.h:86
int len