Skip to content

Commit

Permalink
Fix asm compilation on arm64
Browse files Browse the repository at this point in the history
Unlike the x86 asm code, arm64 asm uses GNU asm.
  • Loading branch information
arch1t3cht committed Nov 20, 2023
1 parent 45363ae commit 5ef3cc9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 17 deletions.
12 changes: 10 additions & 2 deletions libass/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ src_c = files(
src_arm64 = files(
'aarch64/asm.S',
'aarch64/be_blur.S',
'aarch64/blur.S',
'aarch64/blend_bitmaps.S',
'aarch64/rasterizer.S',
)
Expand Down Expand Up @@ -67,10 +68,17 @@ if coretext
endif

if enable_asm
asm_sources = []
if cpu_family == 'x86'
libass_src += nasm_gen.process(src_x86)
asm_sources = src_x86
elif cpu_family == 'arm64'
libass_arc += nasm_gen.process(src_arm64)
asm_sources = src_arm64
endif

if use_nasm
libass_src += nasm_gen.process(asm_sources)
else
libass_src += asm_sources
endif
endif

Expand Down
39 changes: 24 additions & 15 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -162,31 +162,36 @@ endif

# ASM

nasm_args = []
asm_args = []

# Architecture check
if host_machine.cpu_family() == 'x86'
bittype = '32'
nasm_args += '-DARCH_X86_64=0'
asm_args += '-DARCH_X86_64=0'
cpu_family = 'x86'
elif host_machine.cpu_family() == 'x86_64'
bittype = '64'
nasm_args += '-DARCH_X86_64=1'
asm_args += '-DARCH_X86_64=1'
cpu_family = 'x86'
elif host_machine.cpu_family() == 'aarch64' and host_system == 'darwin'
bittype = '64'
cpu_family = 'arm64'
endif

if cpu_family == 'x86' or cpu_family == 'arm64'
if cpu_family == 'x86'
nasm = find_program('nasm', required: get_option('asm'))
enable_asm = nasm.found()
use_nasm = true
elif cpu_family == 'arm64'
enable_asm = true
use_nasm = false
else
enable_asm = false
use_nasm = false
endif

# NASM version check
if enable_asm
if use_nasm
# This can be cleaned up once 0.64 is available, see https://github.com/xclaesse/libass/commit/cfd3d9971bd585939b97409c0aac79cab3dd2da5
nasm_r = run_command(nasm, '-v', check: true)
out = nasm_r.stdout().strip().split()
Expand All @@ -203,27 +208,27 @@ endif

if get_option('asm').enabled() and (not enable_asm)
error('ASM functions were enabled but are unavailable.')
elif (not enable_asm) and (cpu_family == 'x86' or cpu_family == 'arm64') and (not get_option('asm').disabled())
elif (not enable_asm) and use_nasm and (not get_option('asm').disabled())
warning('Install nasm-2.10 or later for a significantly faster libass build.')
endif

# System check
if enable_asm
if host_system == 'windows'
nasm_args += ['-f', 'win' + bittype]
asm_args += ['-f', 'win' + bittype]
if bittype == '32'
nasm_args += '-DPREFIX'
asm_args += '-DPREFIX'
endif
elif host_system == 'darwin'
if cpu_family == 'arm64'
nasm_args += '-DPREFIX'
asm_args += '-DPREFIX'
else
nasm_args += ['-f', 'macho' + bittype, '-DPREFIX', '-DSTACK_ALIGNMENT=16']
asm_args += ['-f', 'macho' + bittype, '-DPREFIX', '-DSTACK_ALIGNMENT=16']
endif
elif host_system == 'linux' or host_system == 'sunos' or host_system == 'haiku' or host_system == 'gnu'
nasm_args += ['-f', 'elf' + bittype, '-DSTACK_ALIGNMENT=16']
asm_args += ['-f', 'elf' + bittype, '-DSTACK_ALIGNMENT=16']
elif host_system == 'dragonfly' or host_system.endswith('bsd')
nasm_args += ['-f', 'elf' + bittype]
asm_args += ['-f', 'elf' + bittype]
else
error('Please contact libass upstream to figure out if ASM support for your platform can be added. In the meantime, disabling.')
enable_asm = false
Expand All @@ -238,10 +243,14 @@ if enable_asm
conf.set('ARCH_AARCH64', 1)
endif

nasm_args += '-Dprivate_prefix=ass'
nasm_args += ['-I', meson.current_source_dir() / 'libass' + '/', '-DPIC=1', '-o', '@OUTPUT@', '@INPUT@']
if use_nasm
asm_args += '-Dprivate_prefix=ass'
asm_args += ['-I', meson.current_source_dir() / 'libass' + '/', '-DPIC=1', '-o', '@OUTPUT@', '@INPUT@']

nasm_gen = generator(nasm, output: '@[email protected]', arguments: nasm_args)
nasm_gen = generator(nasm, output: '@[email protected]', arguments: asm_args)
else
add_project_arguments(asm_args, language: 'c')
endif
endif

config_h_in = configure_file(output: 'config.h.in', configuration: conf)
Expand Down

0 comments on commit 5ef3cc9

Please sign in to comment.