Skip to content

Commit 90be4b7

Browse files
authored
Add dav1d as potential external project (#182)
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 d9dd17a commit 90be4b7

File tree

7 files changed

+811
-0
lines changed

7 files changed

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

0 commit comments

Comments
 (0)