Skip to content

Commit

Permalink
meson: Use gas-preprocessor as generator, for targets that need it
Browse files Browse the repository at this point in the history
Don't pass the .S assembly sources as C source files in this case,
as e.g. MSVC doesn't support them (and meson knows it doesn't, so
it refuses to proceed with an MSVC/gas-preprocessor wrapper script, as
meson detects it as MSVC - unless meson is hacked to allow passing .S
files to MSVC).

This allows building dav1d with MSVC for ARM targets without
hacks to meson. (Building in a pure MSVC setup with no other
compilers available does require a few new patches to gas-preprocessor
though.)

This has been postponed for quite some time, as compiling with
MSVC for non-x86 targets in meson has been problematic, as meson
used to require a working compiler for the build system as well,
and MSVC for all targets are named cl.exe, and you can't have one
for the cross target and the build machine first in the path at
the same time. This was recently fixed though, see
mesonbuild/meson#4402 and
mesonbuild/meson#6512.

This matches how gas-preprocessor is hooked up for e.g. OpenH264 in
cisco/openh264@013c456.
  • Loading branch information
mstorsjo committed Sep 20, 2020
1 parent d85fdf5 commit d68a2fc
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 14 deletions.
22 changes: 22 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,28 @@ if is_asm_enabled and host_machine.cpu_family().startswith('x86')
])
endif

use_gaspp = false
if (is_asm_enabled and
(host_machine.cpu_family() == 'aarch64' or
host_machine.cpu_family().startswith('arm')) and
cc.get_argument_syntax() == 'msvc')
gaspp = find_program('gas-preprocessor.pl')
use_gaspp = true
gaspp_gen = generator(gaspp,
output: '@[email protected]',
arguments: [
'-as-type', 'armasm',
'-arch', host_machine.cpu_family(),
'--',
host_machine.cpu_family() == 'aarch64' ? 'armasm64' : 'armasm',
'-nologo',
'-I@0@'.format(dav1d_src_root),
'-I@0@/'.format(meson.current_build_dir()),
'@INPUT@',
'-c',
'-o', '@OUTPUT@'
])
endif

# Generate config.h
config_h_target = configure_file(output: 'config.h', configuration: cdata)
Expand Down
24 changes: 15 additions & 9 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ libdav1d_entrypoints_sources = files(
)

# ASM specific sources
libdav1d_nasm_objs = []
libdav1d_asm_objs = []
# Arch-specific flags
arch_flags = []
if is_asm_enabled
Expand All @@ -102,15 +102,15 @@ if is_asm_enabled
)
if (host_machine.cpu_family() == 'aarch64' or
host_machine.cpu() == 'arm64')
libdav1d_sources += files(
libdav1d_sources_asm = files(
# itx.S is used for both 8 and 16 bpc.
'arm/64/itx.S',
'arm/64/looprestoration_common.S',
'arm/64/msac.S',
)

if dav1d_bitdepths.contains('8')
libdav1d_sources += files(
libdav1d_sources_asm += files(
'arm/64/cdef.S',
'arm/64/ipred.S',
'arm/64/loopfilter.S',
Expand All @@ -120,7 +120,7 @@ if is_asm_enabled
endif

if dav1d_bitdepths.contains('16')
libdav1d_sources += files(
libdav1d_sources_asm += files(
'arm/64/cdef16.S',
'arm/64/ipred16.S',
'arm/64/itx16.S',
Expand All @@ -130,12 +130,12 @@ if is_asm_enabled
)
endif
elif host_machine.cpu_family().startswith('arm')
libdav1d_sources += files(
libdav1d_sources_asm = files(
'arm/32/msac.S',
)

if dav1d_bitdepths.contains('8')
libdav1d_sources += files(
libdav1d_sources_asm += files(
'arm/32/cdef.S',
'arm/32/ipred.S',
'arm/32/itx.S',
Expand All @@ -146,11 +146,17 @@ if is_asm_enabled
endif

if dav1d_bitdepths.contains('16')
libdav1d_sources += files(
libdav1d_sources_asm += files(
'arm/32/mc16.S',
)
endif
endif

if use_gaspp
libdav1d_asm_objs = gaspp_gen.process(libdav1d_sources_asm)
else
libdav1d_sources += libdav1d_sources_asm
endif
elif host_machine.cpu_family().startswith('x86')

libdav1d_sources += files(
Expand Down Expand Up @@ -201,7 +207,7 @@ if is_asm_enabled
endif

# Compile the ASM sources with NASM
libdav1d_nasm_objs = nasm_gen.process(libdav1d_sources_asm)
libdav1d_asm_objs = nasm_gen.process(libdav1d_sources_asm)
elif host_machine.cpu() == 'ppc64le'
arch_flags = ['-maltivec', '-mvsx']
libdav1d_sources += files(
Expand Down Expand Up @@ -291,7 +297,7 @@ endif

libdav1d = library('dav1d',
libdav1d_sources,
libdav1d_nasm_objs,
libdav1d_asm_objs,
libdav1d_rc_obj,

objects : [
Expand Down
17 changes: 12 additions & 5 deletions tests/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,27 @@ if is_asm_enabled
checkasm_bitdepth_objs += checkasm_bitdepth_lib.extract_all_objects()
endforeach

checkasm_nasm_objs = []
checkasm_asm_objs = []
checkasm_asm_sources = []
if host_machine.cpu_family() == 'aarch64' or host_machine.cpu() == 'arm64'
checkasm_sources += files('checkasm/arm/checkasm_64.S')
checkasm_asm_sources += files('checkasm/arm/checkasm_64.S')
elif host_machine.cpu_family().startswith('arm')
checkasm_sources += files('checkasm/arm/checkasm_32.S')
checkasm_asm_sources += files('checkasm/arm/checkasm_32.S')
elif host_machine.cpu_family().startswith('x86')
checkasm_nasm_objs = nasm_gen.process(files('checkasm/x86/checkasm.asm'))
checkasm_asm_objs += nasm_gen.process(files('checkasm/x86/checkasm.asm'))
endif

if use_gaspp
checkasm_asm_objs += gaspp_gen.process(checkasm_asm_sources)
else
checkasm_sources += checkasm_asm_sources
endif

m_lib = cc.find_library('m', required: false)

checkasm = executable('checkasm',
checkasm_sources,
checkasm_nasm_objs,
checkasm_asm_objs,

objects: [
checkasm_bitdepth_objs,
Expand Down

0 comments on commit d68a2fc

Please sign in to comment.