Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vectorize audio downsampling. #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 41 additions & 2 deletions src/filterkit.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@

#include "filterkit.h"

#ifdef __SSE4_1__
#include <xmmintrin.h>
#endif

#include <stdlib.h>
#include <string.h>
#include <stdio.h>
Expand Down Expand Up @@ -202,14 +206,49 @@ float lrsFilterUD(float Imp[], /* impulse response */
Ho += dhb; /* IR step */
Xp += Inc; /* Input signal step. NO CHECK ON BOUNDS */
}
else
else {
#ifdef __SSE4_1__
__m128i vv = _mm_set1_ps(0.0f);
if (Inc == 1) {
while ((Hp = &Imp[(int)(Ho + 4*dhb)]) < End) {
/* Get IR sample */
__m128i vt = _mm_set_ps(Imp[(int)(Ho + 3 * dhb)],
Imp[(int)(Ho + 2*dhb)],
Imp[(int)(Ho + dhb)],
Imp[(int)(Ho)]);
vt = _mm_mul_ps(vt, _mm_loadu_ps(Xp));/* Mult coeff by input
sample */
vv = _mm_add_ps(vv, vt); /* The filter output */
Ho += 4*dhb; /* IR step */
Xp += 4; /* Input signal step. NO CHECK ON BOUNDS */
}
} else {
while ((Hp = &Imp[(int)(Ho + 4*dhb)]) < End) {
/* Get IR sample */
__m128i vt = _mm_set_ps(Imp[(int)(Ho)],
Imp[(int)(Ho + dhb)],
Imp[(int)(Ho + 2*dhb)],
Imp[(int)(Ho + 3*dhb)]);
vt = _mm_mul_ps(vt, _mm_loadu_ps(Xp - 3)); /* Mult coeff by input
sample */
vv = _mm_add_ps(vv, vt); /* The filter output */
Ho += 4*dhb; /* IR step */
Xp -= 4; /* Input signal step. NO CHECK ON BOUNDS */
}
}
float elems[4];
memcpy(elems, &vv, sizeof(vv));
v = elems[0] + elems[1] + elems[2] + elems[3];
// Fallthrough intended: the rest of the loop is done in a non-vectorized
// way.
#endif
while ((Hp = &Imp[(int)Ho]) < End) {
t = *Hp; /* Get IR sample */
t *= *Xp; /* Mult coeff by input sample */
v += t; /* The filter output */
Ho += dhb; /* IR step */
Xp += Inc; /* Input signal step. NO CHECK ON BOUNDS */
}

}
return v;
}