Bug 1842193 - Vendor libspeex_resampler using `mach vendor` r=padenot

Renames patches to force ordering.

simd-detect-runtime.patch was not applying cleanly, so slightly update
its context. No impact on the final source.

Differential Revision: https://phabricator.services.mozilla.com/D182993
This commit is contained in:
serge-sans-paille 2023-07-07 13:34:56 +00:00
Родитель 5ca3c8346a
Коммит b7c9e42880
10 изменённых файлов: 126 добавлений и 158 удалений

Просмотреть файл

@ -1,6 +1,6 @@
diff --git a/media/libspeex_resampler/src/speex_resampler.h b/media/libspeex_resampler/src/speex_resampler.h
--- a/media/libspeex_resampler/src/speex_resampler.h
+++ b/media/libspeex_resampler/src/speex_resampler.h
diff --git a/src/speex_resampler.h b/src/speex_resampler.h
--- a/src/speex_resampler.h
+++ b/src/speex_resampler.h
@@ -34,24 +34,25 @@
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.

Просмотреть файл

@ -1,13 +1,8 @@
diff --git a/media/libspeex_resampler/src/resample.c b/media/libspeex_resampler/src/resample.c
--- a/media/libspeex_resampler/src/resample.c
+++ b/media/libspeex_resampler/src/resample.c
@@ -92,23 +92,17 @@ static void speex_free (void *ptr) {free
#define IMAX(a,b) ((a) > (b) ? (a) : (b))
#define IMIN(a,b) ((a) < (b) ? (a) : (b))
#ifndef NULL
#define NULL 0
diff --git a/src/resample.c b/src/resample.c
--- a/src/resample.c
+++ b/src/resample.c
@@ -94,13 +94,7 @@ static void speex_free (void *ptr) {free(ptr);}
#define UINT32_MAX 4294967296U
#endif
-#ifdef _USE_SSE
@ -21,17 +16,7 @@ diff --git a/media/libspeex_resampler/src/resample.c b/media/libspeex_resampler/
/* Numer of elements to allocate on the stack */
#ifdef VAR_ARRAYS
#define FIXED_STACK_ALLOC 8192
#else
#define FIXED_STACK_ALLOC 1024
#endif
@@ -344,17 +338,19 @@ static int resampler_basic_direct_single
const spx_uint32_t den_rate = st->den_rate;
spx_word32_t sum;
while (!(last_sample >= (spx_int32_t)*in_len || out_sample >= (spx_int32_t)*out_len))
{
@@ -346,7 +340,9 @@ static int resampler_basic_direct_single(SpeexResamplerState *st, spx_uint32_t c
const spx_word16_t *sinct = & sinc_table[samp_frac_num*N];
const spx_word16_t *iptr = & in[last_sample];
@ -42,17 +27,7 @@ diff --git a/media/libspeex_resampler/src/resample.c b/media/libspeex_resampler/
int j;
sum = 0;
for(j=0;j<N;j++) sum += MULT16_16(sinct[j], iptr[j]);
/* This code is slower on most DSPs which have only 2 accumulators.
Plus this this forces truncation to 32 bits and you lose the HW guard bits.
I think we can trust the compiler and let it vectorize and/or unroll itself.
spx_word32_t accum[4] = {0,0,0,0};
@@ -362,18 +358,20 @@ static int resampler_basic_direct_single
accum[0] += MULT16_16(sinct[j], iptr[j]);
accum[1] += MULT16_16(sinct[j+1], iptr[j+1]);
accum[2] += MULT16_16(sinct[j+2], iptr[j+2]);
accum[3] += MULT16_16(sinct[j+3], iptr[j+3]);
}
@@ -364,8 +360,10 @@ static int resampler_basic_direct_single(SpeexResamplerState *st, spx_uint32_t c
sum = accum[0] + accum[1] + accum[2] + accum[3];
*/
sum = SATURATE32PSHR(sum, 15, 32767);
@ -64,17 +39,7 @@ diff --git a/media/libspeex_resampler/src/resample.c b/media/libspeex_resampler/
#endif
out[out_stride * out_sample++] = sum;
last_sample += int_advance;
samp_frac_num += frac_advance;
if (samp_frac_num >= den_rate)
{
samp_frac_num -= den_rate;
@@ -402,29 +400,33 @@ static int resampler_basic_direct_double
const spx_uint32_t den_rate = st->den_rate;
double sum;
while (!(last_sample >= (spx_int32_t)*in_len || out_sample >= (spx_int32_t)*out_len))
{
@@ -404,7 +402,9 @@ static int resampler_basic_direct_double(SpeexResamplerState *st, spx_uint32_t c
const spx_word16_t *sinct = & sinc_table[samp_frac_num*N];
const spx_word16_t *iptr = & in[last_sample];
@ -85,10 +50,7 @@ diff --git a/media/libspeex_resampler/src/resample.c b/media/libspeex_resampler/
int j;
double accum[4] = {0,0,0,0};
for(j=0;j<N;j+=4) {
accum[0] += sinct[j]*iptr[j];
accum[1] += sinct[j+1]*iptr[j+1];
accum[2] += sinct[j+2]*iptr[j+2];
@@ -415,8 +415,10 @@ static int resampler_basic_direct_double(SpeexResamplerState *st, spx_uint32_t c
accum[3] += sinct[j+3]*iptr[j+3];
}
sum = accum[0] + accum[1] + accum[2] + accum[3];
@ -100,17 +62,7 @@ diff --git a/media/libspeex_resampler/src/resample.c b/media/libspeex_resampler/
#endif
out[out_stride * out_sample++] = PSHR32(sum, 15);
last_sample += int_advance;
samp_frac_num += frac_advance;
if (samp_frac_num >= den_rate)
{
samp_frac_num -= den_rate;
@@ -458,34 +460,38 @@ static int resampler_basic_interpolate_s
#ifdef FIXED_POINT
const spx_word16_t frac = PDIV32(SHL32((samp_frac_num*st->oversample) % st->den_rate,15),st->den_rate);
#else
const spx_word16_t frac = ((float)((samp_frac_num*st->oversample) % st->den_rate))/st->den_rate;
#endif
@@ -460,7 +462,9 @@ static int resampler_basic_interpolate_single(SpeexResamplerState *st, spx_uint3
spx_word16_t interp[4];
@ -121,14 +73,7 @@ diff --git a/media/libspeex_resampler/src/resample.c b/media/libspeex_resampler/
int j;
spx_word32_t accum[4] = {0,0,0,0};
for(j=0;j<N;j++) {
const spx_word16_t curr_in=iptr[j];
accum[0] += MULT16_16(curr_in,st->sinc_table[4+(j+1)*st->oversample-offset-2]);
accum[1] += MULT16_16(curr_in,st->sinc_table[4+(j+1)*st->oversample-offset-1]);
accum[2] += MULT16_16(curr_in,st->sinc_table[4+(j+1)*st->oversample-offset]);
accum[3] += MULT16_16(curr_in,st->sinc_table[4+(j+1)*st->oversample-offset+1]);
}
@@ -475,9 +479,11 @@ static int resampler_basic_interpolate_single(SpeexResamplerState *st, spx_uint3
cubic_coef(frac, interp);
sum = MULT16_32_Q15(interp[0],SHR32(accum[0], 1)) + MULT16_32_Q15(interp[1],SHR32(accum[1], 1)) + MULT16_32_Q15(interp[2],SHR32(accum[2], 1)) + MULT16_32_Q15(interp[3],SHR32(accum[3], 1));
sum = SATURATE32PSHR(sum, 15, 32767);
@ -139,19 +84,9 @@ diff --git a/media/libspeex_resampler/src/resample.c b/media/libspeex_resampler/
sum = interpolate_product_single(iptr, st->sinc_table + st->oversample + 4 - offset - 2, N, st->oversample, interp);
+ }
#endif
out[out_stride * out_sample++] = sum;
last_sample += int_advance;
samp_frac_num += frac_advance;
if (samp_frac_num >= den_rate)
{
samp_frac_num -= den_rate;
@@ -521,33 +527,37 @@ static int resampler_basic_interpolate_d
#ifdef FIXED_POINT
const spx_word16_t frac = PDIV32(SHL32((samp_frac_num*st->oversample) % st->den_rate,15),st->den_rate);
#else
const spx_word16_t frac = ((float)((samp_frac_num*st->oversample) % st->den_rate))/st->den_rate;
#endif
@@ -523,7 +529,9 @@ static int resampler_basic_interpolate_double(SpeexResamplerState *st, spx_uint3
spx_word16_t interp[4];
@ -162,13 +97,7 @@ diff --git a/media/libspeex_resampler/src/resample.c b/media/libspeex_resampler/
int j;
double accum[4] = {0,0,0,0};
for(j=0;j<N;j++) {
const double curr_in=iptr[j];
accum[0] += MULT16_16(curr_in,st->sinc_table[4+(j+1)*st->oversample-offset-2]);
accum[1] += MULT16_16(curr_in,st->sinc_table[4+(j+1)*st->oversample-offset-1]);
accum[2] += MULT16_16(curr_in,st->sinc_table[4+(j+1)*st->oversample-offset]);
accum[3] += MULT16_16(curr_in,st->sinc_table[4+(j+1)*st->oversample-offset+1]);
}
@@ -537,9 +545,11 @@ static int resampler_basic_interpolate_double(SpeexResamplerState *st, spx_uint3
cubic_coef(frac, interp);
sum = MULT16_32_Q15(interp[0],accum[0]) + MULT16_32_Q15(interp[1],accum[1]) + MULT16_32_Q15(interp[2],accum[2]) + MULT16_32_Q15(interp[3],accum[3]);
@ -179,16 +108,11 @@ diff --git a/media/libspeex_resampler/src/resample.c b/media/libspeex_resampler/
sum = interpolate_product_double(iptr, st->sinc_table + st->oversample + 4 - offset - 2, N, st->oversample, interp);
+ }
#endif
out[out_stride * out_sample++] = PSHR32(sum,15);
last_sample += int_advance;
samp_frac_num += frac_advance;
if (samp_frac_num >= den_rate)
{
samp_frac_num -= den_rate;
diff --git a/media/libspeex_resampler/src/resample_neon.c b/media/libspeex_resampler/src/resample_neon.c
--- a/media/libspeex_resampler/src/resample_neon.c
+++ b/media/libspeex_resampler/src/resample_neon.c
diff --git a/src/resample_neon.c b/src/resample_neon.c
--- a/src/resample_neon.c
+++ b/src/resample_neon.c
@@ -31,16 +31,18 @@
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
@ -246,9 +170,9 @@ diff --git a/media/libspeex_resampler/src/resample_neon.c b/media/libspeex_resam
asm volatile (" cmp %[len], #0\n"
" bne 1f\n"
" vld1.32 {q4}, [%[b]]!\n"
diff --git a/media/libspeex_resampler/src/resample_sse.c b/media/libspeex_resampler/src/resample_sse.c
--- a/media/libspeex_resampler/src/resample_sse.c
+++ b/media/libspeex_resampler/src/resample_sse.c
diff --git a/src/resample_sse.c b/src/resample_sse.c
--- a/src/resample_sse.c
+++ b/src/resample_sse.c
@@ -29,37 +29,39 @@
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR

Просмотреть файл

@ -5,9 +5,9 @@ b=913854 add speex_resampler_set_skip_frac_num r=jmspeex
This allows a client to align output samples consistently for independent
resampling of contiguous input buffers.
diff --git a/media/libspeex_resampler/src/resample.c b/media/libspeex_resampler/src/resample.c
--- a/media/libspeex_resampler/src/resample.c
+++ b/media/libspeex_resampler/src/resample.c
diff --git a/src/resample.c b/src/resample.c
--- a/src/resample.c
+++ b/src/resample.c
@@ -1128,16 +1128,28 @@ EXPORT int speex_resampler_get_output_la
EXPORT int speex_resampler_skip_zeros(SpeexResamplerState *st)
{
@ -37,9 +37,9 @@ diff --git a/media/libspeex_resampler/src/resample.c b/media/libspeex_resampler/
st->last_sample[i] = 0;
st->magic_samples[i] = 0;
st->samp_frac_num[i] = 0;
diff --git a/media/libspeex_resampler/src/speex_resampler.h b/media/libspeex_resampler/src/speex_resampler.h
--- a/media/libspeex_resampler/src/speex_resampler.h
+++ b/media/libspeex_resampler/src/speex_resampler.h
diff --git a/src/speex_resampler.h b/src/speex_resampler.h
--- a/src/speex_resampler.h
+++ b/src/speex_resampler.h
@@ -69,16 +69,17 @@
#define speex_resampler_get_quality CAT_PREFIX(RANDOM_PREFIX,_resampler_get_quality)
#define speex_resampler_set_input_stride CAT_PREFIX(RANDOM_PREFIX,_resampler_set_input_stride)

Просмотреть файл

@ -1,6 +1,6 @@
diff --git a/media/libspeex_resampler/src/resample.c b/media/libspeex_resampler/src/resample.c
--- a/media/libspeex_resampler/src/resample.c
+++ b/media/libspeex_resampler/src/resample.c
diff --git a/src/resample.c b/src/resample.c
--- a/src/resample.c
+++ b/src/resample.c
@@ -56,16 +56,18 @@
(e.g. 2/3), and get rid of the rounding operations in the inner loop.
The latter both reduces CPU time and makes the algorithm more SIMD-friendly.

Просмотреть файл

@ -8,9 +8,9 @@ the gcc used for b2g_try_emulator_dep builds says
resample_neon.c: In function 'saturate_32bit_to_16bit':
resample_neon.c:50: error: expected string literal before ')' token
diff --git a/media/libspeex_resampler/src/resample_neon.c b/media/libspeex_resampler/src/resample_neon.c
--- a/media/libspeex_resampler/src/resample_neon.c
+++ b/media/libspeex_resampler/src/resample_neon.c
diff --git a/src/resample_neon.c b/src/resample_neon.c
--- a/src/resample_neon.c
+++ b/src/resample_neon.c
@@ -41,18 +41,17 @@
#include <arm_neon.h>

Просмотреть файл

@ -1,6 +1,6 @@
diff --git a/media/libspeex_resampler/src/resample.c b/media/libspeex_resampler/src/resample.c
--- a/media/libspeex_resampler/src/resample.c
+++ b/media/libspeex_resampler/src/resample.c
diff --git a/src/resample.c b/src/resample.c
--- a/src/resample.c
+++ b/src/resample.c
@@ -1141,18 +1141,19 @@ EXPORT int speex_resampler_set_rate_frac
st->num_rate /= fact;

Просмотреть файл

@ -1,6 +1,6 @@
diff --git a/media/libspeex_resampler/src/arch.h b/media/libspeex_resampler/src/arch.h
--- a/media/libspeex_resampler/src/arch.h
+++ b/media/libspeex_resampler/src/arch.h
diff --git a/src/arch.h b/src/arch.h
--- a/src/arch.h
+++ b/src/arch.h
@@ -172,26 +172,23 @@ typedef float spx_word32_t;
#define SHL(a,shift) (a)
#define SATURATE(x,a) (x)
@ -29,9 +29,9 @@ diff --git a/media/libspeex_resampler/src/arch.h b/media/libspeex_resampler/src/
#define MULT16_16_Q11_32(a,b) ((a)*(b))
#define MULT16_16_Q13(a,b) ((a)*(b))
#define MULT16_16_Q14(a,b) ((a)*(b))
diff --git a/media/libspeex_resampler/src/fixed_generic.h b/media/libspeex_resampler/src/fixed_generic.h
--- a/media/libspeex_resampler/src/fixed_generic.h
+++ b/media/libspeex_resampler/src/fixed_generic.h
diff --git a/src/fixed_generic.h b/src/fixed_generic.h
--- a/src/fixed_generic.h
+++ b/src/fixed_generic.h
@@ -64,32 +64,27 @@
#define ADD16(a,b) ((spx_word16_t)((spx_word16_t)(a)+(spx_word16_t)(b)))
@ -71,9 +71,9 @@ diff --git a/media/libspeex_resampler/src/fixed_generic.h b/media/libspeex_resam
#define MULT16_16_Q11_32(a,b) (SHR(MULT16_16((a),(b)),11))
#define MULT16_16_Q13(a,b) (SHR(MULT16_16((a),(b)),13))
diff --git a/media/libspeex_resampler/src/resample.c b/media/libspeex_resampler/src/resample.c
--- a/media/libspeex_resampler/src/resample.c
+++ b/media/libspeex_resampler/src/resample.c
diff --git a/src/resample.c b/src/resample.c
--- a/src/resample.c
+++ b/src/resample.c
@@ -474,17 +474,17 @@ static int resampler_basic_interpolate_s
const spx_word16_t curr_in=iptr[j];
accum[0] += MULT16_16(curr_in,st->sinc_table[4+(j+1)*st->oversample-offset-2]);

Просмотреть файл

@ -1,5 +0,0 @@
This source is from the Speex DSP library
(http://git.xiph.org/?p=speexdsp.git), from commit 79822c.
It consists in the audio resampling code (resampler.c) and its header files
dependancies, imported into the tree using the update.sh script.

Просмотреть файл

@ -0,0 +1,78 @@
schema: 1
bugzilla:
product: Core
component: "Web Audio"
origin:
name: speexdsp
description: DSP library derived from speex
url: https://speex.org/
release: 79822c8fb79d202cbe7e899f7406acf17beb247c (2017-01-22T14:16:02.000-05:00).
revision: 79822c8fb79d202cbe7e899f7406acf17beb247c
license: BSD-3-Clause
license-file: COPYING
vendoring:
url: https://gitlab.xiph.org/xiph/speexdsp
source-hosting: gitlab
tracking: commit
exclude:
- ".*"
- "*"
- "**"
keep:
- src/simd_detect.h
- src/simd_detect.cpp
include:
- libspeexdsp/resample.c
- libspeexdsp/resample_sse.h
- libspeexdsp/resample_neon.h
- libspeexdsp/arch.h
- libspeexdsp/stack_alloc.h
- libspeexdsp/fixed_generic.h
- include/speex/speex_resampler.h
- AUTHORS
- COPYING
update-actions:
- action: delete-path
path: '{vendor_dir}/doc'
- action: delete-path
path: '{vendor_dir}/libspeexdsp/.cvsignore'
- action: move-file
from: '{vendor_dir}/libspeexdsp/resample.c'
to: '{vendor_dir}/src/resample.c'
- action: move-file
from: '{vendor_dir}/libspeexdsp/resample_sse.h'
to: '{vendor_dir}/src/resample_sse.c'
- action: move-file
from: '{vendor_dir}/libspeexdsp/resample_neon.h'
to: '{vendor_dir}/src/resample_neon.c'
- action: move-file
from: '{vendor_dir}/libspeexdsp/arch.h'
to: '{vendor_dir}/src/arch.h'
- action: move-file
from: '{vendor_dir}/libspeexdsp/stack_alloc.h'
to: '{vendor_dir}/src/stack_alloc.h'
- action: move-file
from: '{vendor_dir}/libspeexdsp/fixed_generic.h'
to: '{vendor_dir}/src/fixed_generic.h'
- action: move-file
from: '{vendor_dir}/include/speex/speex_resampler.h'
to: '{vendor_dir}/src/speex_resampler.h'
patches:
- 01_outside-speex.patch
- 02_simd-detect-runtime.patch
- 03_set-skip-frac.patch
- 04_hugemem.patch
- 05_remove-empty-asm-clobber.patch
- 06_set-rate-overflow-no-return.patch
- 07_integer-halving.patch

Просмотреть файл

@ -1,29 +0,0 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# Usage: ./update.sh <speexdsp_directory>
#
# Copies the needed files from a directory containing the original
# speexdsp sources.
set -e -x
cp $1/libspeexdsp/resample.c src
cp $1/libspeexdsp/resample_sse.h src/resample_sse.c
cp $1/libspeexdsp/resample_neon.h src/resample_neon.c
cp $1/libspeexdsp/arch.h src
cp $1/libspeexdsp/stack_alloc.h src
cp $1/libspeexdsp/fixed_generic.h src
cp $1/include/speex/speex_resampler.h src
cp $1/AUTHORS .
cp $1/COPYING .
# apply outstanding local patches
patch -p3 < outside-speex.patch
patch -p3 < simd-detect-runtime.patch
patch -p3 < set-skip-frac.patch
patch -p3 < hugemem.patch
patch -p3 < remove-empty-asm-clobber.patch
patch -p3 < set-rate-overflow-no-return.patch
patch -p3 < integer-halving.patch