Skip to content

Commit 44b2339

Browse files
committed
Add dav1d as potential external project
To add the external source, run "git clone -b 1.5.0 https://code.videolan.org/videolan/dav1d.git" to clone the dav1d sources, e.g. in the llvm-test-suite/test-suite-externals directory (which may not exist but can be created manually), or configure with TEST_SUITE_DAV1D_ROOT pointing at a directory containing this source. This builds two targets; the dav1d command line executable (which isn't executed as a test) and the dav1d checkasm test executable (which runs compiler generated functions and compares them with handwritten assembly versions of them). The checkasm execuable can also be run manually to microbenchmark functions, e.g. "External/dav1d/dav1d_checkasm --bench --test=mc_8bpc --function=warp*". It is not very meaningful to benchmark the execution of the whole checkasm executable, as it runs a different numbers of functions depending on the number of SIMD extensions available on the target CPU. (Benchmarking on aarch64 currently requires direct access to the pmccntr_el0 register. To currently use a different timer register, edit dav1d/tests/checkasm/checkasm.h and change pmccntr_el0 into cntvct_el0.) This uses a static configuration of the project (when building the upstream project with their own build system, there's a number of build options that can be configured). Assembly is hooked up and enabled on i386, x86_64, arm and aarch64. For architectures other than those, the checkasm test won't have any reference for detecting e.g. miscompilations of functions, but building it can still be meaningful (for testing compilation, or benchmarking the execution of the C version of functions).
1 parent af2e6dc commit 44b2339

File tree

6 files changed

+553
-0
lines changed

6 files changed

+553
-0
lines changed

External/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ add_subdirectory(HeCBench)
55
add_subdirectory(Nurbs)
66
add_subdirectory(Povray)
77
add_subdirectory(SPEC)
8+
add_subdirectory(dav1d)
89
add_subdirectory(skidmarks10)
910
add_subdirectory(sollve_vv)
1011
add_subdirectory(smoke)

External/dav1d/CMakeLists.txt

Lines changed: 368 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,368 @@
1+
include(External)
2+
3+
# git clone -b 1.5.0 https://code.videolan.org/videolan/dav1d.git
4+
# in llvm-test-suite/test-suite-externals.
5+
6+
llvm_externals_find(TEST_SUITE_DAV1D_ROOT "dav1d" "dav1d 1.5.0")
7+
8+
if (NOT TEST_SUITE_DAV1D_ROOT)
9+
return()
10+
endif()
11+
12+
include(CheckCCompilerFlag)
13+
include(CheckFunctionExists)
14+
include(CheckLanguage)
15+
include(CheckLibraryExists)
16+
include(CheckLinkerFlag)
17+
18+
set(CMAKE_C_STANDARD 17)
19+
20+
include_directories(.)
21+
include_directories(${TEST_SUITE_DAV1D_ROOT}/include)
22+
include_directories(${TEST_SUITE_DAV1D_ROOT}/include/dav1d)
23+
include_directories(${TEST_SUITE_DAV1D_ROOT})
24+
include_directories(${TEST_SUITE_DAV1D_ROOT}/src)
25+
26+
if (WIN32)
27+
include_directories(${TEST_SUITE_DAV1D_ROOT}/include/compat)
28+
endif()
29+
30+
function(check_enable_option option)
31+
string(REGEX REPLACE "^--*" "" option_name ${option})
32+
string(TOUPPER ${option_name} option_name)
33+
string(REGEX REPLACE "[-=]" "_" option_name ${option_name})
34+
set(varname "SUPPORTS_${option_name}")
35+
check_c_compiler_flag(${option} ${varname})
36+
if (${varname})
37+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${option}" PARENT_SCOPE)
38+
endif()
39+
endfunction()
40+
41+
function(check_disable_warning warning)
42+
string(REGEX REPLACE "^-Wno-" "" warning ${warning})
43+
string(TOUPPER ${warning} warning_name)
44+
string(REGEX REPLACE "[-=]" "_" warning_name ${warning_name})
45+
set(varname "SUPPORTS_W${warning_name}")
46+
check_c_compiler_flag(-W${warning} ${varname})
47+
if (${varname})
48+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-${warning}" PARENT_SCOPE)
49+
endif()
50+
endfunction()
51+
52+
if (NOT MSVC)
53+
# clang-cl supports -Wall, but it corresponds to -Weverything
54+
check_enable_option(-Wall)
55+
endif()
56+
57+
check_enable_option(-Wundef)
58+
check_enable_option(-Werror=vla)
59+
check_disable_warning(-Wno-maybe-uninitialized)
60+
check_disable_warning(-Wno-missing-field-initializers)
61+
check_disable_warning(-Wno-unused-parameter)
62+
check_enable_option(-Wstrict-prototypes)
63+
check_enable_option(-Werror=missing-prototypes)
64+
check_enable_option(-Wshorten-64-to-32)
65+
66+
check_function_exists(sin HAVE_DEFAULT_MATH)
67+
if (NOT HAVE_DEFAULT_MATH)
68+
check_library_exists(m sin "" HAVE_LIBM)
69+
if (HAVE_LIBM)
70+
link_libraries(m)
71+
endif()
72+
endif()
73+
check_library_exists(atomic __atomic_load_8 "" HAVE_LIBATOMIC)
74+
if (HAVE_LIBATOMIC)
75+
link_libraries(atomic)
76+
endif()
77+
if (NOT WIN32)
78+
find_package(Threads)
79+
if (Threads_FOUND)
80+
link_libraries(${CMAKE_THREAD_LIBS_INIT})
81+
endif()
82+
endif()
83+
84+
if (WIN32)
85+
add_compile_definitions(WIN32_LEAN_AND_MEAN)
86+
if (MSVC)
87+
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
88+
add_compile_definitions(_CRT_NONSTDC_NO_DEPRECATE)
89+
endif()
90+
endif()
91+
92+
if (CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64")
93+
enable_language(ASM)
94+
set(CMAKE_SYSTEM_PROCESSOR "aarch64")
95+
message(STATUS "dav1d: Enabling aarch64 assembly")
96+
elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "^arm")
97+
enable_language(ASM)
98+
set(CMAKE_SYSTEM_PROCESSOR "arm")
99+
message(STATUS "dav1d: Enabling arm assembly")
100+
elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "^i.86$" OR CMAKE_SYSTEM_PROCESSOR MATCHES "^[Xx]86$")
101+
check_language(ASM_NASM)
102+
if (CMAKE_ASM_NASM_COMPILER)
103+
enable_language(ASM_NASM)
104+
message(STATUS "dav1d: Enabling i386 nasm assembly")
105+
else()
106+
add_compile_definitions(NO_X86ASM)
107+
message(STATUS "dav1d: Not enabling i386 nasm assembly")
108+
endif()
109+
set(CMAKE_SYSTEM_PROCESSOR "i386")
110+
if (CMAKE_SYSTEM_NAME STREQUAL "Darwin" OR CMAKE_SYSTEM_NAME STREQUAL "Windows")
111+
set(CMAKE_ASM_NASM_FLAGS "${CMAKE_ASM_NASM_FLAGS} -DPREFIX")
112+
endif()
113+
elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "amd64")
114+
add_compile_definitions(PIC)
115+
check_language(ASM_NASM)
116+
if (CMAKE_ASM_NASM_COMPILER)
117+
enable_language(ASM_NASM)
118+
message(STATUS "dav1d: Enabling x86_64 nasm assembly")
119+
else()
120+
add_compile_definitions(NO_X86ASM)
121+
message(STATUS "dav1d: Not enabling x86_64 nasm assembly")
122+
endif()
123+
set(CMAKE_SYSTEM_PROCESSOR "x86_64")
124+
set(CMAKE_ASM_NASM_FLAGS "${CMAKE_ASM_NASM_FLAGS} -DARCH_X86_64=1")
125+
if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
126+
set(CMAKE_ASM_NASM_FLAGS "${CMAKE_ASM_NASM_FLAGS} -DPREFIX")
127+
endif()
128+
else()
129+
message(STATUS "Not enabling any assembly optimizations for ${CMAKE_SYSTEM_PROCESSOR}")
130+
endif()
131+
132+
# src
133+
134+
set(dav1d_src
135+
cdf.c
136+
cpu.c
137+
ctx.c
138+
data.c
139+
decode.c
140+
dequant_tables.c
141+
getbits.c
142+
intra_edge.c
143+
itx_1d.c
144+
lf_mask.c
145+
lib.c
146+
log.c
147+
mem.c
148+
msac.c
149+
obu.c
150+
pal.c
151+
picture.c
152+
qm.c
153+
ref.c
154+
refmvs.c
155+
scan.c
156+
tables.c
157+
thread_task.c
158+
warpmv.c
159+
wedge.c)
160+
161+
if (WIN32)
162+
list(APPEND dav1d_src
163+
win32/thread.c)
164+
endif()
165+
166+
set(dav1d_tmpl_src
167+
cdef_apply_tmpl.c
168+
cdef_tmpl.c
169+
fg_apply_tmpl.c
170+
filmgrain_tmpl.c
171+
ipred_prepare_tmpl.c
172+
ipred_tmpl.c
173+
itx_tmpl.c
174+
lf_apply_tmpl.c
175+
loopfilter_tmpl.c
176+
looprestoration_tmpl.c
177+
lr_apply_tmpl.c
178+
mc_tmpl.c
179+
recon_tmpl.c)
180+
181+
if (CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")
182+
list(APPEND dav1d_src
183+
arm/cpu.c
184+
arm/64/itx.S
185+
arm/64/looprestoration_common.S
186+
arm/64/msac.S
187+
arm/64/refmvs.S
188+
arm/64/cdef.S
189+
arm/64/filmgrain.S
190+
arm/64/ipred.S
191+
arm/64/loopfilter.S
192+
arm/64/looprestoration.S
193+
arm/64/mc.S
194+
arm/64/mc_dotprod.S
195+
arm/64/cdef16.S
196+
arm/64/filmgrain16.S
197+
arm/64/ipred16.S
198+
arm/64/itx16.S
199+
arm/64/loopfilter16.S
200+
arm/64/looprestoration16.S
201+
arm/64/mc16.S
202+
arm/64/mc16_sve.S)
203+
elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "arm")
204+
list(APPEND dav1d_src
205+
arm/cpu.c
206+
arm/32/itx.S
207+
arm/32/looprestoration_common.S
208+
arm/32/msac.S
209+
arm/32/refmvs.S
210+
arm/32/cdef.S
211+
arm/32/filmgrain.S
212+
arm/32/ipred.S
213+
arm/32/loopfilter.S
214+
arm/32/looprestoration.S
215+
arm/32/mc.S
216+
arm/32/cdef16.S
217+
arm/32/filmgrain16.S
218+
arm/32/ipred16.S
219+
arm/32/itx16.S
220+
arm/32/loopfilter16.S
221+
arm/32/looprestoration16.S
222+
arm/32/mc16.S)
223+
elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "i386")
224+
list(APPEND dav1d_src
225+
x86/cpu.c)
226+
if (CMAKE_ASM_NASM_COMPILER)
227+
set(x86_nasm_sources
228+
x86/cpuid.asm
229+
x86/msac.asm
230+
x86/pal.asm
231+
x86/refmvs.asm
232+
x86/itx_avx512.asm
233+
x86/cdef_avx2.asm
234+
x86/itx_avx2.asm
235+
x86/cdef_sse.asm
236+
x86/itx_sse.asm
237+
x86/cdef_avx512.asm
238+
x86/filmgrain_avx512.asm
239+
x86/ipred_avx512.asm
240+
x86/loopfilter_avx512.asm
241+
x86/looprestoration_avx512.asm
242+
x86/mc_avx512.asm
243+
x86/filmgrain_avx2.asm
244+
x86/ipred_avx2.asm
245+
x86/loopfilter_avx2.asm
246+
x86/looprestoration_avx2.asm
247+
x86/mc_avx2.asm
248+
x86/filmgrain_sse.asm
249+
x86/ipred_sse.asm
250+
x86/loopfilter_sse.asm
251+
x86/looprestoration_sse.asm
252+
x86/mc_sse.asm
253+
x86/cdef16_avx512.asm
254+
x86/filmgrain16_avx512.asm
255+
x86/ipred16_avx512.asm
256+
x86/itx16_avx512.asm
257+
x86/loopfilter16_avx512.asm
258+
x86/looprestoration16_avx512.asm
259+
x86/mc16_avx512.asm
260+
x86/cdef16_avx2.asm
261+
x86/filmgrain16_avx2.asm
262+
x86/ipred16_avx2.asm
263+
x86/itx16_avx2.asm
264+
x86/loopfilter16_avx2.asm
265+
x86/looprestoration16_avx2.asm
266+
x86/mc16_avx2.asm
267+
x86/cdef16_sse.asm
268+
x86/filmgrain16_sse.asm
269+
x86/ipred16_sse.asm
270+
x86/itx16_sse.asm
271+
x86/loopfilter16_sse.asm
272+
x86/looprestoration16_sse.asm
273+
x86/mc16_sse.asm)
274+
list(APPEND dav1d_src
275+
${x86_nasm_sources})
276+
list(TRANSFORM x86_nasm_sources PREPEND ${TEST_SUITE_DAV1D_ROOT}/src/)
277+
set_source_files_properties(${x86_nasm_sources} PROPERTIES LANGUAGE ASM_NASM)
278+
endif()
279+
endif()
280+
281+
list(TRANSFORM dav1d_tmpl_src PREPEND ${TEST_SUITE_DAV1D_ROOT}/src/)
282+
list(TRANSFORM dav1d_src PREPEND ${TEST_SUITE_DAV1D_ROOT}/src/)
283+
284+
foreach(bitdepth 8 16)
285+
llvm_test_library(dav1d_bitdepth_${bitdepth} OBJECT ${dav1d_tmpl_src})
286+
target_compile_definitions(dav1d_bitdepth_${bitdepth} PRIVATE -DBITDEPTH=${bitdepth})
287+
list(APPEND bitdepth_libraries dav1d_bitdepth_${bitdepth})
288+
endforeach()
289+
290+
llvm_test_library(dav1d_lib ${dav1d_src})
291+
target_link_libraries(dav1d_lib LINK_PRIVATE ${bitdepth_libraries})
292+
293+
294+
# tools
295+
296+
set(dav1d_cli_src
297+
dav1d.c
298+
dav1d_cli_parse.c
299+
input/input.c
300+
input/annexb.c
301+
input/ivf.c
302+
input/section5.c
303+
output/md5.c
304+
output/null.c
305+
output/output.c
306+
output/y4m2.c
307+
output/yuv.c)
308+
309+
if (WIN32)
310+
list(APPEND dav1d_cli_src
311+
compat/getopt.c)
312+
endif()
313+
314+
list(TRANSFORM dav1d_cli_src PREPEND ${TEST_SUITE_DAV1D_ROOT}/tools/)
315+
316+
llvm_test_executable_no_test(dav1d ${dav1d_cli_src})
317+
318+
target_include_directories(dav1d PRIVATE ${TEST_SUITE_DAV1D_ROOT}/tools)
319+
target_link_libraries(dav1d PRIVATE dav1d_lib)
320+
321+
322+
# checkasm
323+
324+
set(checkasm_src
325+
checkasm.c
326+
msac.c
327+
pal.c
328+
refmvs.c)
329+
330+
set(checkasm_tmpl_src
331+
cdef.c
332+
filmgrain.c
333+
ipred.c
334+
itx.c
335+
loopfilter.c
336+
looprestoration.c
337+
mc.c)
338+
339+
if (CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")
340+
list(APPEND checkasm_src
341+
arm/checkasm_64.S)
342+
elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "arm")
343+
list(APPEND checkasm_src
344+
arm/checkasm_32.S)
345+
elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "i386")
346+
if (CMAKE_ASM_NASM_COMPILER)
347+
set(x86_nasm_sources
348+
x86/checkasm.asm)
349+
list(APPEND checkasm_src
350+
${x86_nasm_sources})
351+
list(TRANSFORM x86_nasm_sources PREPEND ${TEST_SUITE_DAV1D_ROOT}/tests/checkasm/)
352+
set_source_files_properties(${x86_nasm_sources} PROPERTIES LANGUAGE ASM_NASM)
353+
endif()
354+
endif()
355+
356+
list(TRANSFORM checkasm_tmpl_src PREPEND ${TEST_SUITE_DAV1D_ROOT}/tests/checkasm/)
357+
list(TRANSFORM checkasm_src PREPEND ${TEST_SUITE_DAV1D_ROOT}/tests/checkasm/)
358+
359+
foreach(bitdepth 8 16)
360+
llvm_test_library(checkasm_bitdepth_${bitdepth} OBJECT ${checkasm_tmpl_src})
361+
target_compile_definitions(checkasm_bitdepth_${bitdepth} PRIVATE -DBITDEPTH=${bitdepth})
362+
list(APPEND bitdepth_libraries checkasm_bitdepth_${bitdepth})
363+
endforeach()
364+
365+
llvm_test_run()
366+
llvm_test_executable(dav1d_checkasm ${checkasm_src})
367+
target_link_libraries(dav1d_checkasm LINK_PRIVATE ${bitdepth_libraries})
368+
target_link_libraries(dav1d_checkasm PRIVATE dav1d_lib)

External/dav1d/cli_config.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#pragma once
2+
3+
#define HAVE_XXHASH_H 0

External/dav1d/config.asm

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
%ifdef ARCH_X86_64
2+
%define ARCH_X86_32 0
3+
%define STACK_ALIGNMENT 16
4+
%else
5+
%define ARCH_X86_32 1
6+
%define ARCH_X86_64 0
7+
%define STACK_ALIGNMENT 4
8+
%endif
9+
%define FORCE_VEX_ENCODING 0
10+
%define PIC 1
11+
%define private_prefix dav1d

0 commit comments

Comments
 (0)