From 49d4effeea9107d18f6897255139d30fc80204df Mon Sep 17 00:00:00 2001
From: Rudi Heitbaum <rudi@heitbaum.com>
Date: Wed, 6 Mar 2024 11:21:07 +0000
Subject: [PATCH] fix arm asm meson source build

meson does mot support output with paths; add a meson.build file in the arm
directory. The output files were being incorrectly placed in the celt/ directory.

Program arm/arm2gnu.pl found: YES (/var/media/DATA/home-rudi/LibreELEC.kernel11/build.LibreELEC-H3.arm-12.0-devel/build/opus-v1.5.1/celt/arm/arm2gnu.pl)
Configuring celt_pitch_xcorr_arm-gnu.S with command

../celt/meson.build:51:25: ERROR: configure_file keyword argument "output" Output 'arm/armopts.s' must not contain a path segment.

before:
celt/celt_pitch_xcorr_arm-gnu.S

after:
celt/arm/celt_pitch_xcorr_arm-gnu.S
celt/arm/armopts.s
celt/arm/armopts-gnu.S

Signed-off-by: Rudi Heitbaum <rudi@heitbaum.com>
Signed-off-by: Jean-Marc Valin <jmvalin@jmvalin.ca>
---
 celt/arm/meson.build | 12 ++++++++++++
 celt/meson.build     |  9 +--------
 2 files changed, 13 insertions(+), 8 deletions(-)
 create mode 100644 celt/arm/meson.build

--- /dev/null
+++ b/celt/arm/meson.build
@@ -0,0 +1,12 @@
+arm2gnu = [find_program('arm2gnu.pl')] + arm2gnu_args
+celt_sources_arm_asm = configure_file(input: 'celt_pitch_xcorr_arm.s',
+  output: '@BASENAME@-gnu.S',
+  command: arm2gnu + ['@INPUT@'],
+  capture: true)
+celt_arm_armopts_s_in = configure_file(input: 'armopts.s.in',
+  output: 'armopts.s',
+  configuration: opus_conf)
+celt_arm_armopts_s = configure_file(input: [celt_arm_armopts_s_in],
+  output: '@BASENAME@-gnu.S',
+  command: arm2gnu + ['@INPUT@'],
+  capture: true)
--- a/celt/meson.build
+++ b/celt/meson.build
@@ -43,14 +43,7 @@ if host_cpu_family in ['arm', 'aarch64']
     celt_sources += sources['CELT_SOURCES_ARM_NE10']
   endif
   if opus_arm_external_asm
-    arm2gnu = [find_program('arm/arm2gnu.pl')] + arm2gnu_args
-    celt_sources_arm_asm = configure_file(input: 'arm/celt_pitch_xcorr_arm.s',
-      output: '@BASENAME@-gnu.S',
-      command: arm2gnu + ['@INPUT@'],
-      capture: true)
-    celt_arm_armopts_s = configure_file(input: 'arm/armopts.s.in',
-      output: 'arm/armopts.s',
-      configuration: opus_conf)
+    subdir('arm')
     celt_static_libs += static_library('celt-armasm',
       celt_arm_armopts_s, celt_sources_arm_asm,
       install: false)
--- a/meson.build
+++ b/meson.build
@@ -252,6 +252,13 @@ if not opt_asm.disabled()
         opus_conf.set('OPUS_ARM_INLINE_NEON', 1)
         inline_optimization += ['NEON']
       endif
+
+      # AS_ASM_ARM_DOTPROD
+      if cc.compiles(asm_tmpl.format('udot v0.4s,v1.16b,v2.16b'),
+                     name : 'assembler supports DOTPROD instructions on ARM')
+        opus_conf.set('OPUS_ARM_INLINE_DOTPROD', 1)
+        inline_optimization += ['DOTPROD']
+      endif
     endif
 
     # We need Perl to translate RVCT-syntax asm to gas syntax
@@ -273,21 +280,24 @@ if not opt_asm.disabled()
       opus_arm_may_have_neon = opus_conf.has('OPUS_ARM_INLINE_NEON')
       opus_arm_presume_neon = opus_arm_may_have_neon and opus_can_presume_simd
 
+      opus_arm_may_have_dotprod = opus_conf.has('OPUS_ARM_INLINE_DOTPROD')
+      opus_arm_presume_dotprod = opus_arm_may_have_dotprod and opus_can_presume_simd
+
       if not opt_rtcd.disabled()
         if not opus_arm_may_have_edsp
           message('Trying to force-enable armv5e EDSP instructions...')
           # AS_ASM_ARM_EDSP_FORCE
-          opus_arm_may_have_edsp = cc.compiles(asm_tmpl.format('.arch armv5te\n.object_arch armv4t\nqadd r3,r3,r3'),
+          opus_arm_may_have_edsp = cc.compiles(asm_tmpl.format('.arch armv5te;.object_arch armv4t;qadd r3,r3,r3'),
                                                name : 'Assembler supports EDSP instructions on ARM (forced)')
         endif
         if not opus_arm_may_have_media
           message('Trying to force-enable ARMv6 media instructions...')
-          opus_arm_may_have_media = cc.compiles(asm_tmpl.format('.arch armv6\n.object_arch armv4t\nshadd8 r3,r3,r3'),
+          opus_arm_may_have_media = cc.compiles(asm_tmpl.format('.arch armv6;.object_arch armv4t;shadd8 r3,r3,r3'),
                                                 name : 'Assembler supports ARMv6 media instructions on ARM (forced)')
         endif
         if not opus_arm_may_have_neon
           message('Trying to force-enable NEON instructions...')
-          opus_arm_may_have_neon = cc.compiles(asm_tmpl.format('.arch armv7-a\n.fpu neon\n.object_arch armv4t\nvorr d0,d0,d0'),
+          opus_arm_may_have_neon = cc.compiles(asm_tmpl.format('.arch armv7-a;.fpu neon;.object_arch armv4t;vorr d0,d0,d0'),
                                                name : 'Assembler supports NEON instructions on ARM (forced)')
         endif
       endif
