Line | Branch | Exec | Source |
---|---|---|---|
1 | /* | ||
2 | * This file is part of FFmpeg. | ||
3 | * | ||
4 | * FFmpeg is free software; you can redistribute it and/or | ||
5 | * modify it under the terms of the GNU Lesser General Public | ||
6 | * License as published by the Free Software Foundation; either | ||
7 | * version 2.1 of the License, or (at your option) any later version. | ||
8 | * | ||
9 | * FFmpeg is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
12 | * Lesser General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU Lesser General Public | ||
15 | * License along with FFmpeg; if not, write to the Free Software | ||
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
17 | */ | ||
18 | |||
19 | #include <stdio.h> | ||
20 | |||
21 | #include "config.h" | ||
22 | |||
23 | #include "libavutil/cpu.h" | ||
24 | #include "libavutil/avstring.h" | ||
25 | |||
26 | #if ARCH_AARCH64 | ||
27 | #include "libavutil/aarch64/cpu.h" | ||
28 | #elif ARCH_RISCV | ||
29 | #include "libavutil/riscv/cpu.h" | ||
30 | #endif | ||
31 | |||
32 | #if HAVE_UNISTD_H | ||
33 | #include <unistd.h> | ||
34 | #endif | ||
35 | #if !HAVE_GETOPT | ||
36 | #include "compat/getopt.c" | ||
37 | #endif | ||
38 | |||
39 | static const struct { | ||
40 | int flag; | ||
41 | const char *name; | ||
42 | } cpu_flag_tab[] = { | ||
43 | #if ARCH_AARCH64 | ||
44 | { AV_CPU_FLAG_ARMV8, "armv8" }, | ||
45 | { AV_CPU_FLAG_NEON, "neon" }, | ||
46 | { AV_CPU_FLAG_VFP, "vfp" }, | ||
47 | { AV_CPU_FLAG_DOTPROD, "dotprod" }, | ||
48 | { AV_CPU_FLAG_I8MM, "i8mm" }, | ||
49 | { AV_CPU_FLAG_SVE, "sve" }, | ||
50 | { AV_CPU_FLAG_SVE2, "sve2" }, | ||
51 | #elif ARCH_ARM | ||
52 | { AV_CPU_FLAG_ARMV5TE, "armv5te" }, | ||
53 | { AV_CPU_FLAG_ARMV6, "armv6" }, | ||
54 | { AV_CPU_FLAG_ARMV6T2, "armv6t2" }, | ||
55 | { AV_CPU_FLAG_VFP, "vfp" }, | ||
56 | { AV_CPU_FLAG_VFP_VM, "vfp_vm" }, | ||
57 | { AV_CPU_FLAG_VFPV3, "vfpv3" }, | ||
58 | { AV_CPU_FLAG_NEON, "neon" }, | ||
59 | { AV_CPU_FLAG_SETEND, "setend" }, | ||
60 | #elif ARCH_PPC | ||
61 | { AV_CPU_FLAG_ALTIVEC, "altivec" }, | ||
62 | { AV_CPU_FLAG_VSX, "vsx" }, | ||
63 | { AV_CPU_FLAG_POWER8, "power8" }, | ||
64 | #elif ARCH_MIPS | ||
65 | { AV_CPU_FLAG_MMI, "mmi" }, | ||
66 | { AV_CPU_FLAG_MSA, "msa" }, | ||
67 | #elif ARCH_X86 | ||
68 | { AV_CPU_FLAG_MMX, "mmx" }, | ||
69 | { AV_CPU_FLAG_MMXEXT, "mmxext" }, | ||
70 | { AV_CPU_FLAG_SSE, "sse" }, | ||
71 | { AV_CPU_FLAG_SSE2, "sse2" }, | ||
72 | { AV_CPU_FLAG_SSE2SLOW, "sse2slow" }, | ||
73 | { AV_CPU_FLAG_SSE3, "sse3" }, | ||
74 | { AV_CPU_FLAG_SSE3SLOW, "sse3slow" }, | ||
75 | { AV_CPU_FLAG_SSSE3, "ssse3" }, | ||
76 | { AV_CPU_FLAG_ATOM, "atom" }, | ||
77 | { AV_CPU_FLAG_SSE4, "sse4.1" }, | ||
78 | { AV_CPU_FLAG_SSE42, "sse4.2" }, | ||
79 | { AV_CPU_FLAG_AVX, "avx" }, | ||
80 | { AV_CPU_FLAG_AVXSLOW, "avxslow" }, | ||
81 | { AV_CPU_FLAG_XOP, "xop" }, | ||
82 | { AV_CPU_FLAG_FMA3, "fma3" }, | ||
83 | { AV_CPU_FLAG_FMA4, "fma4" }, | ||
84 | { AV_CPU_FLAG_3DNOW, "3dnow" }, | ||
85 | { AV_CPU_FLAG_3DNOWEXT, "3dnowext" }, | ||
86 | { AV_CPU_FLAG_CMOV, "cmov" }, | ||
87 | { AV_CPU_FLAG_AVX2, "avx2" }, | ||
88 | { AV_CPU_FLAG_BMI1, "bmi1" }, | ||
89 | { AV_CPU_FLAG_BMI2, "bmi2" }, | ||
90 | { AV_CPU_FLAG_AESNI, "aesni" }, | ||
91 | { AV_CPU_FLAG_AVX512, "avx512" }, | ||
92 | { AV_CPU_FLAG_AVX512ICL, "avx512icl" }, | ||
93 | { AV_CPU_FLAG_SLOW_GATHER, "slowgather" }, | ||
94 | #elif ARCH_LOONGARCH | ||
95 | { AV_CPU_FLAG_LSX, "lsx" }, | ||
96 | { AV_CPU_FLAG_LASX, "lasx" }, | ||
97 | #elif ARCH_RISCV | ||
98 | { AV_CPU_FLAG_RVI, "rvi" }, | ||
99 | { AV_CPU_FLAG_RVB_BASIC, "zbb" }, | ||
100 | { AV_CPU_FLAG_RVB, "rvb" }, | ||
101 | { AV_CPU_FLAG_RVV_I32, "zve32x" }, | ||
102 | { AV_CPU_FLAG_RVV_F32, "zve32f" }, | ||
103 | { AV_CPU_FLAG_RVV_I64, "zve64x" }, | ||
104 | { AV_CPU_FLAG_RVV_F64, "zve64d" }, | ||
105 | { AV_CPU_FLAG_RV_ZVBB, "zvbb" }, | ||
106 | { AV_CPU_FLAG_RV_MISALIGNED, "misaligned" }, | ||
107 | #endif | ||
108 | { 0 } | ||
109 | }; | ||
110 | |||
111 | 2 | static void print_cpu_flags(int cpu_flags, const char *type) | |
112 | { | ||
113 | int i; | ||
114 | |||
115 | 2 | printf("cpu_flags(%s) = 0x%08X\n", type, cpu_flags); | |
116 | 2 | printf("cpu_flags_str(%s) =", type); | |
117 |
2/2✓ Branch 0 taken 52 times.
✓ Branch 1 taken 2 times.
|
54 | for (i = 0; cpu_flag_tab[i].flag; i++) |
118 |
2/2✓ Branch 0 taken 15 times.
✓ Branch 1 taken 37 times.
|
52 | if (cpu_flags & cpu_flag_tab[i].flag) |
119 | 15 | printf(" %s", cpu_flag_tab[i].name); | |
120 | 2 | printf("\n"); | |
121 | 2 | } | |
122 | |||
123 | |||
124 | 1 | int main(int argc, char **argv) | |
125 | { | ||
126 | 1 | int cpu_flags_raw = av_get_cpu_flags(); | |
127 | int cpu_flags_eff; | ||
128 | 1 | int cpu_count = av_cpu_count(); | |
129 | 1 | const char *threads = "auto"; | |
130 | int i; | ||
131 | |||
132 |
2/2✓ Branch 0 taken 26 times.
✓ Branch 1 taken 1 times.
|
27 | for(i = 0; cpu_flag_tab[i].flag; i++) { |
133 | 26 | unsigned tmp = 0; | |
134 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 26 times.
|
26 | if (av_parse_cpu_caps(&tmp, cpu_flag_tab[i].name) < 0) { |
135 | ✗ | fprintf(stderr, "Table missing %s\n", cpu_flag_tab[i].name); | |
136 | ✗ | return 4; | |
137 | } | ||
138 | } | ||
139 | |||
140 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (cpu_flags_raw < 0) |
141 | ✗ | return 1; | |
142 | |||
143 | 2 | for (;;) { | |
144 | 3 | int c = getopt(argc, argv, "c:t:"); | |
145 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
|
3 | if (c == -1) |
146 | 1 | break; | |
147 |
2/3✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | switch (c) { |
148 | 1 | case 'c': | |
149 | { | ||
150 | 1 | unsigned flags = av_get_cpu_flags(); | |
151 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if (av_parse_cpu_caps(&flags, optarg) < 0) |
152 | ✗ | return 2; | |
153 | |||
154 | 1 | av_force_cpu_flags(flags); | |
155 | 1 | break; | |
156 | } | ||
157 | 1 | case 't': | |
158 | { | ||
159 | 1 | threads = optarg; | |
160 | } | ||
161 | } | ||
162 | } | ||
163 | |||
164 | 1 | cpu_flags_eff = av_get_cpu_flags(); | |
165 | |||
166 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (cpu_flags_eff < 0) |
167 | ✗ | return 3; | |
168 | |||
169 | 1 | print_cpu_flags(cpu_flags_raw, "raw"); | |
170 | 1 | print_cpu_flags(cpu_flags_eff, "effective"); | |
171 | 1 | printf("threads = %s (cpu_count = %d)\n", threads, cpu_count); | |
172 | #if ARCH_AARCH64 && HAVE_SVE | ||
173 | if (cpu_flags_raw & AV_CPU_FLAG_SVE) | ||
174 | printf("sve_vector_length = %d\n", 8 * ff_aarch64_sve_length()); | ||
175 | #elif ARCH_RISCV && HAVE_RVV | ||
176 | if (cpu_flags_raw & AV_CPU_FLAG_RVV_I32) { | ||
177 | size_t bytes = ff_get_rv_vlenb(); | ||
178 | |||
179 | printf("rv_vlenb = %zu (%zu bits)\n", bytes, 8 * bytes); | ||
180 | } | ||
181 | #endif | ||
182 | |||
183 | 1 | return 0; | |
184 | } | ||
185 |