Warning, /graphics/krita/3rdparty/ext_ffmpeg/0011-theora-Add-Arm-support.patch is written in an unsupported language. File is not indexed.

0001 From cc2af79c5c19555dadf337f309b1a400c5ba476e Mon Sep 17 00:00:00 2001
0002 From: "L. E. Segovia" <amy@amyspark.me>
0003 Date: Fri, 2 Dec 2022 15:59:17 +0000
0004 Subject: [PATCH 11/11] theora: Add Arm support
0005 
0006 ---
0007  lib/arm/arm2gnu-wrapper.py | 13 +++++++++
0008  lib/meson.build            | 51 +++++++++++++++++++++++++++++---
0009  meson.build                | 59 ++++++++++++++++++++++++++++++++++++++
0010  meson_options.txt          |  1 +
0011  4 files changed, 120 insertions(+), 4 deletions(-)
0012  create mode 100644 lib/arm/arm2gnu-wrapper.py
0013 
0014 diff --git a/lib/arm/arm2gnu-wrapper.py b/lib/arm/arm2gnu-wrapper.py
0015 new file mode 100644
0016 index 0000000..bb4ca25
0017 --- /dev/null
0018 +++ b/lib/arm/arm2gnu-wrapper.py
0019 @@ -0,0 +1,13 @@
0020 +#!/usr/bin/env python3
0021 +
0022 +from argparse import ArgumentParser
0023 +from pathlib import Path
0024 +from subprocess import run
0025 +
0026 +if __name__ == '__main__':
0027 +    parser = ArgumentParser(description='Wraps around the Perl script to pipe input and output')
0028 +    parser.add_argument('--program', help="Line to feed to subprocess.run as program")
0029 +    parser.add_argument('infile', type=Path, help='Source file')
0030 +    args = parser.parse_args()
0031 +
0032 +    run(args.program.split(), stdin=args.infile.open(), check=True)
0033 diff --git a/lib/meson.build b/lib/meson.build
0034 index 5f15375..da89dba 100644
0035 --- a/lib/meson.build
0036 +++ b/lib/meson.build
0037 @@ -38,6 +38,8 @@ decoder_sources = files(
0038    'state.c',
0039  )
0040  
0041 +common_arm_sources = files()
0042 +
0043  if asm
0044    if conf.get('CPU_x86_64', false)
0045      if cc.get_argument_syntax() != 'msvc'
0046 @@ -105,6 +107,47 @@ if asm
0047          'x86_vc/x86state.c',
0048        )
0049      endif
0050 +  elif cc.get_id() == 'gcc' and conf.get('CPU_arm', false)
0051 +    # The Arm bits require the Arm -> GNU conversion script
0052 +
0053 +    arm2gnu_pl = find_program('arm/arm2gnu.pl', required: true)
0054 +    arm2gnu_py = find_program('arm/arm2gnu-wrapper.py', required: true)
0055 +
0056 +    arm2gnu_gen = generator(
0057 +      arm2gnu_py,
0058 +      arguments: ['--program', arm2gnu_pl.full_path(), '@INPUT@'],
0059 +      capture: true,
0060 +      output: '@BASENAME@-gnu.S',
0061 +    )
0062 +
0063 +    arm_opts_s = configure_file(
0064 +      input: 'arm/armopts.s.in',
0065 +      configuration: conf,
0066 +      output: 'armopts.S',
0067 +    )
0068 +
0069 +    common_arm_sources += arm2gnu_gen.process(
0070 +      files('arm/armbits.s', 'arm/armfrag.s', 'arm/armidct.s', 'arm/armloop.s'),
0071 +      arm_opts_s,
0072 +    )
0073 +
0074 +    encoder_sources += arm2gnu_gen.process(
0075 +      files(
0076 +        'arm/armencfrag.s',
0077 +        'arm/armenquant.s',
0078 +      ),
0079 +    )
0080 +
0081 +    encoder_sources += files(
0082 +      'arm/armcpu.c',
0083 +      'arm/armenc.c',
0084 +      'arm/armstate.c',
0085 +    )
0086 +
0087 +    decoder_sources += files(
0088 +      'arm/armcpu.c',
0089 +      'arm/armstate.c',
0090 +    )
0091    endif
0092  endif
0093  
0094 @@ -177,7 +220,7 @@ endif
0095  
0096  libtheoradec = library(
0097    'theoradec',
0098 -  decoder_sources + decoder_res,
0099 +  decoder_sources + common_arm_sources + decoder_res,
0100    dependencies: [m_dep, libpng_dep, ogg_dep, cairo_dep, config_dep],
0101    include_directories: incdir,
0102    vs_module_defs: '../win32/xmingw32/libtheoradec-all.def',
0103 @@ -202,8 +245,8 @@ theoradec_dep = declare_dependency(
0104  
0105  libtheoraenc = library(
0106    'theoraenc',
0107 -  encoder_sources + encoder_res,
0108 -  dependencies: [m_dep, libpng_dep, ogg_dep, config_dep],
0109 +  encoder_sources + common_arm_sources + encoder_res,
0110 +  dependencies: [m_dep, ogg_dep, config_dep],
0111    include_directories: incdir,
0112    vs_module_defs: '../win32/xmingw32/libtheoraenc-all.def',
0113    c_args: compile_args,
0114 @@ -232,7 +275,7 @@ theoraenc_dep = declare_dependency(
0115  
0116  libtheora = library(
0117    'theora',
0118 -  encoder_sources + decoder_sources,
0119 +  encoder_sources + common_arm_sources + decoder_sources,
0120    dependencies: [m_dep, libpng_dep, ogg_dep, config_dep],
0121    include_directories: incdir,
0122    c_args: compile_args,
0123 diff --git a/meson.build b/meson.build
0124 index e9152c3..d9e3414 100644
0125 --- a/meson.build
0126 +++ b/meson.build
0127 @@ -118,6 +118,7 @@ if mem_constraint.enabled()
0128  endif
0129  
0130  asm = not get_option('asm').disabled()
0131 +enable_asflag_probe = not get_option('asflag-probe').disabled()
0132  if asm
0133    if host_machine.cpu_family() == 'x86_64'
0134      conf.set('CPU_x86_64', true)
0135 @@ -128,6 +129,64 @@ if asm
0136    elif host_machine.cpu_family() == 'x86'
0137      conf.set('CPU_x86_32', true)
0138      conf.set('OC_X86_ASM', true)
0139 +  elif host_machine.cpu_family() == 'arm' or host_machine.cpu_family() == 'aarch64'
0140 +    conf.set('CPU_arm', true)
0141 +    if cc.get_id() == 'gcc'
0142 +      conf.set('OC_ARM_ASM', true)
0143 +    endif
0144 +  endif
0145 +
0146 +  if cc.get_id() == 'gcc' and conf.get('CPU_arm', false)
0147 +    # The following checks were only designed for GNU AS.
0148 +    # Perl is needed for the arm2gnu reformatter.
0149 +    perl_exe = find_program('perl', required: false, disabler: true)
0150 +
0151 +    if not perl_exe.found()
0152 +      warning('*** ARM assembly requires perl -- disabling optimizations')
0153 +    endif
0154 +
0155 +    if enable_asflag_probe and perl_exe.found()
0156 +      assembler_checks = [
0157 +        [
0158 +          ['HAVE_ARM_ASM_NEON', 'OC_ARM_ASM_NEON'],
0159 +          '''.file "configure"
0160 +              vorr d0,d0,d0
0161 +          ''',
0162 +          ['-mfpu=neon', '-march=armv7-a'],
0163 +          'assembler supports NEON instructions on ARM'
0164 +        ],
0165 +        [
0166 +          ['HAVE_ARM_ASM_MEDIA', 'OC_ARM_ASM_MEDIA'],
0167 +          '''.file "configure"
0168 +              shadd8 r3,r3,r3
0169 +          ''',
0170 +          ['-march=armv6j'],
0171 +          'assembler supports ARMv6 media instructions on ARM'],
0172 +        [
0173 +          ['HAVE_ARM_ASM_EDSP', 'OC_ARM_ASM_EDSP'],
0174 +          '''.file "configure"
0175 +              qadd r3,r3,r3
0176 +          ''',
0177 +          ['-march=armv5e'],
0178 +          'assembler supports EDSP instructions on ARM'
0179 +        ]
0180 +      ]
0181 +
0182 +      foreach check : assembler_checks
0183 +        pass = cc.compiles(check[1],
0184 +          args: ['-x', 'assembler'],
0185 +          name: check[3]
0186 +        ) or cc.compiles(check[1],
0187 +            args: ['-x', 'assembler'] + check[2],
0188 +            name: check[3]
0189 +          )
0190 +
0191 +        foreach define : check[0]
0192 +          conf.set(define, pass)
0193 +          conf.set(define, pass)
0194 +        endforeach
0195 +      endforeach
0196 +    endif
0197    endif
0198  endif
0199  
0200 diff --git a/meson_options.txt b/meson_options.txt
0201 index b791623..cf2f628 100644
0202 --- a/meson_options.txt
0203 +++ b/meson_options.txt
0204 @@ -2,6 +2,7 @@ option('doc', type: 'feature', value: 'auto', description: 'Build API documentat
0205  option('spec', type: 'feature', value: 'auto', description: 'Build the specification')
0206  option('valgrind-testing', type: 'feature', value: 'disabled', description: 'Enable running of tests inside Valgrind')
0207  option('asm', type: 'feature', value: 'enabled', description: 'Enable assembly optimizations')
0208 +option('asflag-probe', type: 'feature', value: 'enabled', description: 'Enable instructions not supported by the default assembler flags (Arm only).')
0209  option('telemetry', type: 'feature', value: 'disabled', description: 'Enable debugging output controls')
0210  option('mem-constraint', type: 'feature', value: 'disabled', description: 'Abort if size exceeds 16384x16384 (for fuzzing only)')
0211  option('examples', type: 'feature', value: 'disabled', description: 'Enable examples')
0212 -- 
0213 2.40.1.windows.1
0214