jack: add ARM NEON support for sample conversions
PATCH 1/2 jack: add ARM NEON support for sample conversions
Add a test application checking accurracy and performance win of accelerated code.
--- ...N-acceleration-for-all-non-dithering-samp.patch | 496 +++++++++++++++++++++ ...sts-add-application-checking-accurracy-an.patch | 433 ++++++++++++++++++ meta-oe/recipes-multimedia/jack/jack_git.bb | 6 +- 3 files changed, 934 insertions(+), 1 deletion(-) create mode 100644 meta-oe/recipes-multimedia/jack/jack/0001-Add-ARM-NEON-acceleration-for-all-non-dithering-samp.patch create mode 100644 meta-oe/recipes-multimedia/jack/jack/0002-jack_simdtests-add-application-checking-accurracy-an.patch
meta-oe/recipes-multimedia/jack/jack/0001-Add-ARM-NEON-acceleration-for-all-non-dithering-samp.patch new file +496 -0
@@ -0,0 +1,496 @@ +From 99785aabc685a94415fcd445345c093488e10350 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Andreas=20M=C3=BCller?= <[email protected]> +Date: Fri, 13 Jan 2017 22:42:11 +0100 +Subject: [PATCH 1/2] Add ARM-NEON acceleration for all non-dithering sample + conversion functions +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Upstream-Status: Submitted [1] + +[1] https://github.com/jackaudio/jack2/pull/250 + +Signed-off-by: Andreas Müller <[email protected]> +--- + common/memops.c | 356 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- + 1 file changed, 351 insertions(+), 5 deletions(-) + +diff --git a/common/memops.c b/common/memops.c +index 2ff0792..8f9ece2 100644 +--- a/common/memops.c ++++ b/common/memops.c +@@ -42,6 +42,10 @@ + #endif + #endif + ++#ifdef __ARM_NEON__ ++#include <arm_neon.h> ++#endif ++ + /* Notes about these *_SCALING values. + + the MAX_<N>BIT values are floating point. when multiplied by +@@ -193,6 +197,35 @@ static inline __m128i float_24_sse(__m128 s) + } + #endif + ++ ++#ifdef __ARM_NEON__ ++ ++static inline float32x4_t clip(float32x4_t s, float32x4_t min, float32x4_t max) ++{ ++ return vminq_f32(max, vmaxq_f32(s, min)); ++} ++ ++static inline int32x4_t float_24_neon(float32x4_t s) ++{ ++ const float32x4_t upper_bound = vdupq_n_f32(NORMALIZED_FLOAT_MAX); ++ const float32x4_t lower_bound = vdupq_n_f32(NORMALIZED_FLOAT_MIN); ++ ++ float32x4_t clipped = clip(s, lower_bound, upper_bound); ++ float32x4_t scaled = vmulq_f32(clipped, vdupq_n_f32(SAMPLE_24BIT_SCALING)); ++ return vcvtq_s32_f32(scaled); ++} ++ ++static inline int16x4_t float_16_neon(float32x4_t s) ++{ ++ const float32x4_t upper_bound = vdupq_n_f32(NORMALIZED_FLOAT_MAX); ++ const float32x4_t lower_bound = vdupq_n_f32(NORMALIZED_FLOAT_MIN); ++ ++ float32x4_t clipped = clip(s, lower_bound, upper_bound); ++ float32x4_t scaled = vmulq_f32(clipped, vdupq_n_f32(SAMPLE_16BIT_SCALING)); ++ return vmovn_s32(vcvtq_s32_f32(scaled)); ++} ++#endif ++ + /* Linear Congruential noise generator. From the music-dsp list + * less random than rand(), but good enough and 10x faster + */ +@@ -248,6 +281,32 @@ void sample_move_dS_floatLE (char *dst, jack_default_audio_sample_t *src, unsign + + void sample_move_d32u24_sSs (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state) + { ++#ifdef __ARM_NEON__ ++ unsigned long unrolled = nsamples / 4; ++ nsamples = nsamples & 3; ++ ++ while (unrolled--) { ++ float32x4_t samples = vld1q_f32(src); ++ int32x4_t converted = float_24_neon(samples); ++ int32x4_t shifted = vshlq_n_s32(converted, 8); ++ shifted = vreinterpretq_s32_u8(vrev32q_u8(vreinterpretq_u8_s32(shifted))); ++ ++ switch(dst_skip) { ++ case 4: ++ vst1q_s32((int32_t*)dst, shifted); ++ break; ++ default: ++ vst1q_lane_s32((int32_t*)(dst), shifted, 0); ++ vst1q_lane_s32((int32_t*)(dst+dst_skip), shifted, 1); ++ vst1q_lane_s32((int32_t*)(dst+2*dst_skip), shifted, 2); ++ vst1q_lane_s32((int32_t*)(dst+3*dst_skip), shifted, 3); ++ break; ++ } ++ dst += 4*dst_skip; ++ src+= 4; ++ } ++#endif ++ + int32_t z; + + while (nsamples--) { +@@ -321,7 +380,33 @@ void sample_move_d32u24_sS (char *dst, jack_default_audio_sample_t *src, unsigne + src++; + } + +-#else ++#elif defined(__ARM_NEON__) ++ unsigned long unrolled = nsamples / 4; ++ nsamples = nsamples & 3; ++ ++ while (unrolled--) { ++ float32x4_t samples = vld1q_f32(src); ++ int32x4_t converted = float_24_neon(samples); ++ int32x4_t shifted = vshlq_n_s32(converted, 8); ++ ++ switch(dst_skip) { ++ case 4: ++ vst1q_s32((int32_t*)dst, shifted); ++ break; ++ default: ++ vst1q_lane_s32((int32_t*)(dst), shifted, 0); ++ vst1q_lane_s32((int32_t*)(dst+dst_skip), shifted, 1); ++ vst1q_lane_s32((int32_t*)(dst+2*dst_skip), shifted, 2); ++ vst1q_lane_s32((int32_t*)(dst+3*dst_skip), shifted, 3); ++ break; ++ } ++ dst += 4*dst_skip; ++ ++ src+= 4; ++ } ++#endif ++ ++#if !defined (__SSE2__) + while (nsamples--) { + float_24u32 (*src, *((int32_t*) dst)); + dst += dst_skip; +@@ -332,6 +417,38 @@ void sample_move_d32u24_sS (char *dst, jack_default_audio_sample_t *src, unsigne + + void sample_move_dS_s32u24s (jack_default_audio_sample_t *dst, char *src, unsigned long nsamples, unsigned long src_skip) + { ++#ifdef __ARM_NEON__ ++ float32x4_t factor = vdupq_n_f32(1.0 / SAMPLE_24BIT_SCALING); ++ unsigned long unrolled = nsamples / 4; ++ while (unrolled--) { ++ int32x4_t src128; ++ switch(src_skip) ++ { ++ case 4: ++ src128 = vld1q_s32((int32_t*)src); ++ break; ++ case 8: ++ src128 = vld2q_s32((int32_t*)src).val[0]; ++ break; ++ default: ++ src128 = vld1q_lane_s32((int32_t*)src, src128, 0); ++ src128 = vld1q_lane_s32((int32_t*)(src+src_skip), src128, 1); ++ src128 = vld1q_lane_s32((int32_t*)(src+2*src_skip), src128, 2); ++ src128 = vld1q_lane_s32((int32_t*)(src+3*src_skip), src128, 3); ++ break; ++ } ++ src128 = vreinterpretq_s32_u8(vrev32q_u8(vreinterpretq_u8_s32(src128))); ++ int32x4_t shifted = vshrq_n_s32(src128, 8); ++ float32x4_t as_float = vcvtq_f32_s32(shifted); ++ float32x4_t divided = vmulq_f32(as_float, factor); ++ vst1q_f32(dst, divided); ++ ++ src += 4*src_skip; ++ dst += 4; ++ } ++ nsamples = nsamples & 3; ++#endif ++ + /* ALERT: signed sign-extension portability !!! */ + + const jack_default_audio_sample_t scaling = 1.0/SAMPLE_24BIT_SCALING; +@@ -389,6 +506,34 @@ void sample_move_dS_s32u24 (jack_default_audio_sample_t *dst, char *src, unsigne + dst += 4; + } + nsamples = nsamples & 3; ++#elif defined(__ARM_NEON__) ++ unsigned long unrolled = nsamples / 4; ++ float32x4_t factor = vdupq_n_f32(1.0 / SAMPLE_24BIT_SCALING); ++ while (unrolled--) { ++ int32x4_t src128; ++ switch(src_skip) { ++ case 4: ++ src128 = vld1q_s32((int32_t*)src); ++ break; ++ case 8: ++ src128 = vld2q_s32((int32_t*)src).val[0]; ++ break; ++ default: ++ src128 = vld1q_lane_s32((int32_t*)src, src128, 0); ++ src128 = vld1q_lane_s32((int32_t*)(src+src_skip), src128, 1); ++ src128 = vld1q_lane_s32((int32_t*)(src+2*src_skip), src128, 2); ++ src128 = vld1q_lane_s32((int32_t*)(src+3*src_skip), src128, 3); ++ break; ++ } ++ int32x4_t shifted = vshrq_n_s32(src128, 8); ++ float32x4_t as_float = vcvtq_f32_s32(shifted); ++ float32x4_t divided = vmulq_f32(as_float, factor); ++ vst1q_f32(dst, divided); ++ ++ src += 4*src_skip; ++ dst += 4; ++ } ++ nsamples = nsamples & 3; + #endif + + /* ALERT: signed sign-extension portability !!! */ +@@ -403,6 +548,24 @@ void sample_move_dS_s32u24 (jack_default_audio_sample_t *dst, char *src, unsigne + + void sample_move_d24_sSs (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state) + { ++#ifdef __ARM_NEON__ ++ unsigned long unrolled = nsamples / 4; ++ while (unrolled--) { ++ int32_t z[4]; ++ float32x4_t samples = vld1q_f32(src); ++ int32x4_t converted = float_24_neon(samples); ++ converted = vreinterpretq_s32_u8(vrev32q_u8(vreinterpretq_u8_s32(converted))); ++ vst1q_s32(z, converted); ++ ++ for (int i = 0; i != 4; ++i) { ++ memcpy (dst, ((char*)(z+i))+1, 3); ++ dst += dst_skip; ++ } ++ src += 4; ++ } ++ nsamples = nsamples & 3; ++#endif ++ + int32_t z; + + while (nsamples--) { +@@ -426,7 +589,6 @@ void sample_move_d24_sS (char *dst, jack_default_audio_sample_t *src, unsigned l + #if defined (__SSE2__) && !defined (__sun__) + _MM_SET_ROUNDING_MODE(_MM_ROUND_NEAREST); + while (nsamples >= 4) { +- int i; + int32_t z[4]; + __m128 samples = _mm_loadu_ps(src); + __m128i converted = float_24_sse(samples); +@@ -447,7 +609,7 @@ void sample_move_d24_sS (char *dst, jack_default_audio_sample_t *src, unsigned l + _mm_store_ss((float*)z+3, (__m128)shuffled3); + #endif + +- for (i = 0; i != 4; ++i) { ++ for (int i = 0; i != 4; ++i) { + memcpy (dst, z+i, 3); + dst += dst_skip; + } +@@ -455,6 +617,22 @@ void sample_move_d24_sS (char *dst, jack_default_audio_sample_t *src, unsigned l + nsamples -= 4; + src += 4; + } ++#elif defined(__ARM_NEON__) ++ unsigned long unrolled = nsamples / 4; ++ while (unrolled--) { ++ int i; ++ int32_t z[4]; ++ float32x4_t samples = vld1q_f32(src); ++ int32x4_t converted = float_24_neon(samples); ++ vst1q_s32(z, converted); ++ ++ for (i = 0; i != 4; ++i) { ++ memcpy (dst, z+i, 3); ++ dst += dst_skip; ++ } ++ src += 4; ++ } ++ nsamples = nsamples & 3; + #endif + + int32_t z; +@@ -473,9 +651,41 @@ void sample_move_d24_sS (char *dst, jack_default_audio_sample_t *src, unsigned l + + void sample_move_dS_s24s (jack_default_audio_sample_t *dst, char *src, unsigned long nsamples, unsigned long src_skip) + { ++ const jack_default_audio_sample_t scaling = 1.0/SAMPLE_24BIT_SCALING; ++ ++#ifdef __ARM_NEON__ ++ // we shift 8 to the right by dividing by 256.0 -> no sign extra handling ++ const float32x4_t vscaling = vdupq_n_f32(scaling/256.0); ++ int32_t x[4]; ++ memset(x, 0, sizeof(x)); ++ unsigned long unrolled = nsamples / 4; ++ while (unrolled--) { ++#if __BYTE_ORDER == __BIG_ENDIAN /* ARM big endian?? */ ++ // right aligned / inverse sequence below -> *256 ++ memcpy(((char*)&x[0])+1, src, 3); ++ memcpy(((char*)&x[1])+1, src+src_skip, 3); ++ memcpy(((char*)&x[2])+1, src+2*src_skip, 3); ++ memcpy(((char*)&x[3])+1, src+3*src_skip, 3); ++#else ++ memcpy(&x[0], src, 3); ++ memcpy(&x[1], src+src_skip, 3); ++ memcpy(&x[2], src+2*src_skip, 3); ++ memcpy(&x[3], src+3*src_skip, 3); ++#endif ++ src += 4 * src_skip; ++ ++ int32x4_t source = vld1q_s32(x); ++ source = vreinterpretq_s32_u8(vrev32q_u8(vreinterpretq_u8_s32(source))); ++ float32x4_t converted = vcvtq_f32_s32(source); ++ float32x4_t scaled = vmulq_f32(converted, vscaling); ++ vst1q_f32(dst, scaled); ++ dst += 4; ++ } ++ nsamples = nsamples & 3; ++#endif ++ + /* ALERT: signed sign-extension portability !!! */ + +- const jack_default_audio_sample_t scaling = 1.0/SAMPLE_24BIT_SCALING; + while (nsamples--) { + int x; + #if __BYTE_ORDER == __LITTLE_ENDIAN +@@ -528,6 +738,34 @@ void sample_move_dS_s24 (jack_default_audio_sample_t *dst, char *src, unsigned l + dst += 4; + nsamples -= 4; + } ++#elif defined(__ARM_NEON__) ++ // we shift 8 to the right by dividing by 256.0 -> no sign extra handling ++ const float32x4_t vscaling = vdupq_n_f32(scaling/256.0); ++ int32_t x[4]; ++ memset(x, 0, sizeof(x)); ++ unsigned long unrolled = nsamples / 4; ++ while (unrolled--) { ++#if __BYTE_ORDER == __BIG_ENDIAN /* ARM big endian?? */ ++ // left aligned -> *256 ++ memcpy(&x[0], src, 3); ++ memcpy(&x[1], src+src_skip, 3); ++ memcpy(&x[2], src+2*src_skip, 3); ++ memcpy(&x[3], src+3*src_skip, 3); ++#else ++ memcpy(((char*)&x[0])+1, src, 3); ++ memcpy(((char*)&x[1])+1, src+src_skip, 3); ++ memcpy(((char*)&x[2])+1, src+2*src_skip, 3); ++ memcpy(((char*)&x[3])+1, src+3*src_skip, 3); ++#endif ++ src += 4 * src_skip; ++ ++ int32x4_t source = vld1q_s32(x); ++ float32x4_t converted = vcvtq_f32_s32(source); ++ float32x4_t scaled = vmulq_f32(converted, vscaling); ++ vst1q_f32(dst, scaled); ++ dst += 4; ++ } ++ nsamples = nsamples & 3; + #endif + + while (nsamples--) { +@@ -547,6 +785,30 @@ void sample_move_dS_s24 (jack_default_audio_sample_t *dst, char *src, unsigned l + + void sample_move_d16_sSs (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state) + { ++#ifdef __ARM_NEON__ ++ unsigned long unrolled = nsamples / 4; ++ nsamples = nsamples & 3; ++ ++ while (unrolled--) { ++ float32x4_t samples = vld1q_f32(src); ++ int16x4_t converted = float_16_neon(samples); ++ converted = vreinterpret_s16_u8(vrev16_u8(vreinterpret_u8_s16(converted))); ++ ++ switch(dst_skip) { ++ case 2: ++ vst1_s16((int16_t*)dst, converted); ++ break; ++ default: ++ vst1_lane_s16((int16_t*)(dst), converted, 0); ++ vst1_lane_s16((int16_t*)(dst+dst_skip), converted, 1); ++ vst1_lane_s16((int16_t*)(dst+2*dst_skip), converted, 2); ++ vst1_lane_s16((int16_t*)(dst+3*dst_skip), converted, 3); ++ break; ++ } ++ dst += 4*dst_skip; ++ src+= 4; ++ } ++#endif + int16_t tmp; + + while (nsamples--) { +@@ -574,6 +836,29 @@ void sample_move_d16_sSs (char *dst, jack_default_audio_sample_t *src, unsigned + + void sample_move_d16_sS (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state) + { ++#ifdef __ARM_NEON__ ++ unsigned long unrolled = nsamples / 4; ++ nsamples = nsamples & 3; ++ ++ while (unrolled--) { ++ float32x4_t samples = vld1q_f32(src); ++ int16x4_t converted = float_16_neon(samples); ++ ++ switch(dst_skip) { ++ case 2: ++ vst1_s16((int16_t*)dst, converted); ++ break; ++ default: ++ vst1_lane_s16((int16_t*)(dst), converted, 0); ++ vst1_lane_s16((int16_t*)(dst+dst_skip), converted, 1); ++ vst1_lane_s16((int16_t*)(dst+2*dst_skip), converted, 2); ++ vst1_lane_s16((int16_t*)(dst+3*dst_skip), converted, 3); ++ break; ++ } ++ dst += 4*dst_skip; ++ src+= 4; ++ } ++#endif + while (nsamples--) { + float_16 (*src, *((int16_t*) dst)); + dst += dst_skip; +@@ -728,8 +1013,39 @@ void sample_move_dither_shaped_d16_sS (char *dst, jack_default_audio_sample_t * + + void sample_move_dS_s16s (jack_default_audio_sample_t *dst, char *src, unsigned long nsamples, unsigned long src_skip) + { +- short z; + const jack_default_audio_sample_t scaling = 1.0/SAMPLE_16BIT_SCALING; ++#ifdef __ARM_NEON__ ++ const float32x4_t vscaling = vdupq_n_f32(scaling); ++ unsigned long unrolled = nsamples / 4; ++ while (unrolled--) { ++ int16x4_t source16x4; ++ switch(src_skip) { ++ case 2: ++ source16x4 = vld1_s16((int16_t*)src); ++ break; ++ case 4: ++ source16x4 = vld2_s16((int16_t*)src).val[0]; ++ break; ++ default: ++ source16x4 = vld1_lane_s16((int16_t*)src, source16x4, 0); ++ source16x4 = vld1_lane_s16((int16_t*)(src+src_skip), source16x4, 1); ++ source16x4 = vld1_lane_s16((int16_t*)(src+2*src_skip), source16x4, 2); ++ source16x4 = vld1_lane_s16((int16_t*)(src+3*src_skip), source16x4, 3); ++ break; ++ } ++ source16x4 = vreinterpret_s16_u8(vrev16_u8(vreinterpret_u8_s16(source16x4))); ++ int32x4_t source32x4 = vmovl_s16(source16x4); ++ src += 4 * src_skip; ++ ++ float32x4_t converted = vcvtq_f32_s32(source32x4); ++ float32x4_t scaled = vmulq_f32(converted, vscaling); ++ vst1q_f32(dst, scaled); ++ dst += 4; ++ } ++ nsamples = nsamples & 3; ++#endif ++ ++ short z; + + /* ALERT: signed sign-extension portability !!! */ + while (nsamples--) { +@@ -752,6 +1068,36 @@ void sample_move_dS_s16 (jack_default_audio_sample_t *dst, char *src, unsigned l + { + /* ALERT: signed sign-extension portability !!! */ + const jack_default_audio_sample_t scaling = 1.0/SAMPLE_16BIT_SCALING; ++#ifdef __ARM_NEON__ ++ const float32x4_t vscaling = vdupq_n_f32(scaling); ++ unsigned long unrolled = nsamples / 4; ++ while (unrolled--) { ++ int16x4_t source16x4; ++ switch(src_skip) { ++ case 2: ++ source16x4 = vld1_s16((int16_t*)src); ++ break; ++ case 4: ++ source16x4 = vld2_s16((int16_t*)src).val[0]; ++ break; ++ default: ++ source16x4 = vld1_lane_s16((int16_t*)src, source16x4, 0); ++ source16x4 = vld1_lane_s16((int16_t*)(src+src_skip), source16x4, 1); ++ source16x4 = vld1_lane_s16((int16_t*)(src+2*src_skip), source16x4, 2); ++ source16x4 = vld1_lane_s16((int16_t*)(src+3*src_skip), source16x4, 3); ++ break; ++ } ++ int32x4_t source32x4 = vmovl_s16(source16x4); ++ src += 4 * src_skip; ++ ++ float32x4_t converted = vcvtq_f32_s32(source32x4); ++ float32x4_t scaled = vmulq_f32(converted, vscaling); ++ vst1q_f32(dst, scaled); ++ dst += 4; ++ } ++ nsamples = nsamples & 3; ++#endif ++ + while (nsamples--) { + *dst = (*((short *) src)) * scaling; + dst++; +-- +2.5.5 +
meta-oe/recipes-multimedia/jack/jack/0002-jack_simdtests-add-application-checking-accurracy-an.patch new file +433 -0
433 lines not on this page · raw message
meta-oe/recipes-multimedia/jack/jack_git.bb +5 -1
@@ -14,7 +14,11 @@ LIC_FILES_CHKSUM = " \ DEPENDS = "libsamplerate0 libsndfile1 readline" -SRC_URI = "git://github.com/jackaudio/jack2.git" +SRC_URI = " \ + git://github.com/jackaudio/jack2.git \ + file://0001-Add-ARM-NEON-acceleration-for-all-non-dithering-samp.patch \ + file://0002-jack_simdtests-add-application-checking-accurracy-an.patch \ +" SRCREV = "0279a2d65a36d1378f5bab56d95bf9e99cc8cefb" PV = "1.9.10+git${SRCPV}" S = "${WORKDIR}/git"
Signature · 1 line
2.5.5
PATCH 2/2 fluidsynth: add ARM NEON support for sample interpolation
--- ...e_dsp_interpolate_4th_order-make-use-of-A.patch | 158 +++++++++++++++++++++ .../fluidsynth/fluidsynth_1.1.6.bb | 5 +- 2 files changed, 162 insertions(+), 1 deletion(-) create mode 100644 meta-multimedia/recipes-multimedia/fluidsynth/files/0001-fluid_rvoice_dsp_interpolate_4th_order-make-use-of-A.patch
meta-multimedia/recipes-multimedia/fluidsynth/files/0001-fluid_rvoice_dsp_interpolate_4th_order-make-use-of-A.patch new file +158 -0
@@ -0,0 +1,158 @@ +From 6cf151bd571ab6288ab0bfa7bc4c854bef012183 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Andreas=20M=C3=BCller?= <[email protected]> +Date: Mon, 23 Jan 2017 19:32:06 +0100 +Subject: [PATCH] fluid_rvoice_dsp_interpolate_4th_order: make use of ARM NEON + intriniscs +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Upstream-Status: Pending + +Signed-off-by: Andreas Müller <[email protected]> +--- + src/rvoice/fluid_rvoice_dsp.c | 87 ++++++++++++++++++++++++++++++++++++++++++- + 1 file changed, 86 insertions(+), 1 deletion(-) + +diff --git a/src/rvoice/fluid_rvoice_dsp.c b/src/rvoice/fluid_rvoice_dsp.c +index df7da50..ca4a807 100644 +--- a/src/rvoice/fluid_rvoice_dsp.c ++++ b/src/rvoice/fluid_rvoice_dsp.c +@@ -22,6 +22,9 @@ + #include "fluid_phase.h" + #include "fluid_rvoice.h" + #include "fluid_sys.h" ++#ifdef __ARM_NEON__ ++#include <arm_neon.h> ++#endif + + /* Purpose: + * +@@ -279,13 +282,19 @@ fluid_rvoice_dsp_interpolate_4th_order (fluid_rvoice_dsp_t *voice) + fluid_phase_t dsp_phase_incr; + short int *dsp_data = voice->sample->data; + fluid_real_t *dsp_buf = voice->dsp_buf; ++#if defined(__ARM_NEON__) && defined(WITH_FLOAT) ++ float32x4_t dsp_amp = vdupq_n_f32(voice->amp); ++ float32x4_t dsp_amp_incr = vdupq_n_f32(voice->amp_incr); ++ float32x4_t coeffs; ++#else + fluid_real_t dsp_amp = voice->amp; + fluid_real_t dsp_amp_incr = voice->amp_incr; ++ fluid_real_t *coeffs; ++#endif + unsigned int dsp_i = 0; + unsigned int dsp_phase_index; + unsigned int start_index, end_index; + short int start_point, end_point1, end_point2; +- fluid_real_t *coeffs; + int looping; + + /* Convert playback "speed" floating point value to phase index/fract */ +@@ -327,11 +336,22 @@ fluid_rvoice_dsp_interpolate_4th_order (fluid_rvoice_dsp_t *voice) + /* interpolate first sample point (start or loop start) if needed */ + for ( ; dsp_phase_index == start_index && dsp_i < FLUID_BUFSIZE; dsp_i++) + { ++#if defined(__ARM_NEON__) && defined(WITH_FLOAT) ++ coeffs = vld1q_f32(interp_coeff[fluid_phase_fract_to_tablerow (dsp_phase)]); ++ int16x4_t vdsp_data_i16 = vld1_s16(&dsp_data[dsp_phase_index-1]); ++ vdsp_data_i16 = vld1_lane_s16(&start_point, vdsp_data_i16, 0); ++ float32x4_t vdsp_data = vcvtq_f32_s32(vmovl_s16(vdsp_data_i16)); ++ vdsp_data *= coeffs; ++ vdsp_data *= dsp_amp; ++ float32x2_t sum2 = vadd_f32(vget_high_f32(vdsp_data), vget_low_f32(vdsp_data)); ++ dsp_buf[dsp_i] = vget_lane_f32(vpadd_f32(sum2, sum2), 0); ++#else + coeffs = interp_coeff[fluid_phase_fract_to_tablerow (dsp_phase)]; + dsp_buf[dsp_i] = dsp_amp * (coeffs[0] * start_point + + coeffs[1] * dsp_data[dsp_phase_index] + + coeffs[2] * dsp_data[dsp_phase_index+1] + + coeffs[3] * dsp_data[dsp_phase_index+2]); ++#endif + + /* increment phase and amplitude */ + fluid_phase_incr (dsp_phase, dsp_phase_incr); +@@ -342,11 +362,21 @@ fluid_rvoice_dsp_interpolate_4th_order (fluid_rvoice_dsp_t *voice) + /* interpolate the sequence of sample points */ + for ( ; dsp_i < FLUID_BUFSIZE && dsp_phase_index <= end_index; dsp_i++) + { ++#if defined(__ARM_NEON__) && defined(WITH_FLOAT) ++ coeffs = vld1q_f32(interp_coeff[fluid_phase_fract_to_tablerow (dsp_phase)]); ++ int16x4_t vdsp_data_i16 = vld1_s16(&dsp_data[dsp_phase_index-1]); ++ float32x4_t vdsp_data = vcvtq_f32_s32(vmovl_s16(vdsp_data_i16)); ++ vdsp_data *= coeffs; ++ vdsp_data *= dsp_amp; ++ float32x2_t sum2 = vadd_f32(vget_high_f32(vdsp_data), vget_low_f32(vdsp_data)); ++ dsp_buf[dsp_i] = vget_lane_f32(vpadd_f32(sum2, sum2), 0); ++#else + coeffs = interp_coeff[fluid_phase_fract_to_tablerow (dsp_phase)]; + dsp_buf[dsp_i] = dsp_amp * (coeffs[0] * dsp_data[dsp_phase_index-1] + + coeffs[1] * dsp_data[dsp_phase_index] + + coeffs[2] * dsp_data[dsp_phase_index+1] + + coeffs[3] * dsp_data[dsp_phase_index+2]); ++#endif + + /* increment phase and amplitude */ + fluid_phase_incr (dsp_phase, dsp_phase_incr); +@@ -362,11 +392,22 @@ fluid_rvoice_dsp_interpolate_4th_order (fluid_rvoice_dsp_t *voice) + /* interpolate within 2nd to last point */ + for (; dsp_phase_index <= end_index && dsp_i < FLUID_BUFSIZE; dsp_i++) + { ++#if defined(__ARM_NEON__) && defined(WITH_FLOAT) ++ coeffs = vld1q_f32(interp_coeff[fluid_phase_fract_to_tablerow (dsp_phase)]); ++ int16x4_t vdsp_data_i16 = vld1_s16(&dsp_data[dsp_phase_index-1]); ++ vdsp_data_i16 = vld1_lane_s16(&end_point1, vdsp_data_i16, 3); ++ float32x4_t vdsp_data = vcvtq_f32_s32(vmovl_s16(vdsp_data_i16)); ++ vdsp_data *= coeffs; ++ vdsp_data *= dsp_amp; ++ float32x2_t sum2 = vadd_f32(vget_high_f32(vdsp_data), vget_low_f32(vdsp_data)); ++ dsp_buf[dsp_i] = vget_lane_f32(vpadd_f32(sum2, sum2), 0); ++#else + coeffs = interp_coeff[fluid_phase_fract_to_tablerow (dsp_phase)]; + dsp_buf[dsp_i] = dsp_amp * (coeffs[0] * dsp_data[dsp_phase_index-1] + + coeffs[1] * dsp_data[dsp_phase_index] + + coeffs[2] * dsp_data[dsp_phase_index+1] + + coeffs[3] * end_point1); ++#endif + + /* increment phase and amplitude */ + fluid_phase_incr (dsp_phase, dsp_phase_incr); +@@ -379,11 +420,23 @@ fluid_rvoice_dsp_interpolate_4th_order (fluid_rvoice_dsp_t *voice) + /* interpolate within the last point */ + for (; dsp_phase_index <= end_index && dsp_i < FLUID_BUFSIZE; dsp_i++) + { ++#if defined(__ARM_NEON__) && defined(WITH_FLOAT) ++ coeffs = vld1q_f32(interp_coeff[fluid_phase_fract_to_tablerow (dsp_phase)]); ++ int16x4_t vdsp_data_i16 = vld1_s16(&dsp_data[dsp_phase_index-1]); ++ vdsp_data_i16 = vld1_lane_s16(&end_point1, vdsp_data_i16, 2); ++ vdsp_data_i16 = vld1_lane_s16(&end_point2, vdsp_data_i16, 3); ++ float32x4_t vdsp_data = vcvtq_f32_s32(vmovl_s16(vdsp_data_i16)); ++ vdsp_data *= coeffs; ++ vdsp_data *= dsp_amp; ++ float32x2_t sum2 = vadd_f32(vget_high_f32(vdsp_data), vget_low_f32(vdsp_data)); ++ dsp_buf[dsp_i] = vget_lane_f32(vpadd_f32(sum2, sum2), 0); ++#else + coeffs = interp_coeff[fluid_phase_fract_to_tablerow (dsp_phase)]; + dsp_buf[dsp_i] = dsp_amp * (coeffs[0] * dsp_data[dsp_phase_index-1] + + coeffs[1] * dsp_data[dsp_phase_index] + + coeffs[2] * end_point1 + + coeffs[3] * end_point2); ++#endif + + /* increment phase and amplitude */ + fluid_phase_incr (dsp_phase, dsp_phase_incr); +@@ -413,7 +466,11 @@ fluid_rvoice_dsp_interpolate_4th_order (fluid_rvoice_dsp_t *voice) + } + + voice->phase = dsp_phase; ++#if defined(__ARM_NEON__) && defined(WITH_FLOAT) ++ vst1q_lane_f32(&voice->amp, dsp_amp, 0); ++#else + voice->amp = dsp_amp; ++#endif + + return (dsp_i); + } +-- +2.5.5 +
meta-multimedia/recipes-multimedia/fluidsynth/fluidsynth_1.1.6.bb +4 -1
@@ -6,7 +6,10 @@ LIC_FILES_CHKSUM = "file://COPYING;md5=e198e9aac94943d0ec29a7dae8c29416" DEPENDS = "alsa-lib ncurses glib-2.0" -SRC_URI = "${SOURCEFORGE_MIRROR}/project/${BPN}/${BP}/${BP}.tar.gz" +SRC_URI = " \ + ${SOURCEFORGE_MIRROR}/project/${BPN}/${BP}/${BP}.tar.gz \ + file://0001-fluid_rvoice_dsp_interpolate_4th_order-make-use-of-A.patch \ +" SRC_URI[md5sum] = "ae5aca6de824b4173667cbd3a310b263" SRC_URI[sha256sum] = "50853391d9ebeda9b4db787efb23f98b1e26b7296dd2bb5d0d96b5bccee2171c"
Signature · 1 line
2.5.5
Re: [PATCH 2/2] fluidsynth: add ARM NEON support for sample interpolation
Quoted 6 lines · Andreas Müller
Signed-off-by Andreas Müller <[email protected]>--- ...e_dsp_interpolate_4th_order-make-use-of-A.patch | 158 +++++++++++++++++++++ .../fluidsynth/fluidsynth_1.1.6.bb | 5 +- 2 files changed, 162 insertions(+), 1 deletion(-) create mode 100644 meta-multimedia/recipes-multimedia/fluidsynth/files/0001-fluid_rvoice_dsp_interpolate_4th_order-make-use-of-A.patch
Sorry but I get the feeling that this patch does not accelerate interpolation. I need to write some performance test to check (don't trust optimizations without performance numbers) So for please ignore this patch.
Andreas
Re: [PATCH 2/2] fluidsynth: add ARM NEON support for sample interpolation
Quoted 9 lines · Andreas Müller
Quoted 6 lines · Andreas Müller
Signed-off-by Andreas Müller <[email protected]>--- ...e_dsp_interpolate_4th_order-make-use-of-A.patch | 158 +++++++++++++++++++++ .../fluidsynth/fluidsynth_1.1.6.bb | 5 +- 2 files changed, 162 insertions(+), 1 deletion(-) create mode 100644 meta-multimedia/recipes-multimedia/fluidsynth/files/0001-fluid_rvoice_dsp_interpolate_4th_order-make-use-of-A.patch
Quoted 5 lines
Sorry but I get the feeling that this patch does not accelerate interpolation. I need to write some performance test to check (don't trust optimizations without performance numbers) So for please ignore this patch.
Just saw that this is still in master-next: Please take care that it won't be applied in master accidentally. I could create a test case
meanwhile: This patch is crap and slows things down instead of accelerating.
Andreas
Re: [PATCH 2/2] fluidsynth: add ARM NEON support for sample interpolation
Thanks, I've just dropped it from my local master-next, so I won't forget next time.
On Mon, Feb 6, 2017 at 6:40 PM, Andreas Müller <[email protected]
Quoted 28 lines
wrote:
Quoted 5 lines · Andreas Müller
Quoted 3 lines · Andreas Müller
Signed-off-by Andreas Müller <[email protected]>--- ...e_dsp_interpolate_4th_order-make-use-of-A.patch | 158+++++++++++++++++++++
Quoted 3 lines
Quoted 3 lines
.../fluidsynth/fluidsynth_1.1.6.bb | 5 +- 2 files changed, 162 insertions(+), 1 deletion(-) create mode 100644 meta-multimedia/recipes-multimedia/fluidsynth/files/0001-fluid_rvoice_dsp_ interpolate_4th_order-make-use-of-A.patch
Quoted 6 lines
Sorry but I get the feeling that this patch does not accelerate interpolation. I need to write some performance test to check (don't trust optimizations without performance numbers) So for please ignore this patch.
Just saw that this is still in master-next: Please take care that it won't be applied in master accidentally. I could create a test case
meanwhile: This patch is crap and slows things down instead of accelerating.Andreas