Skip to content

Commit

Permalink
filter: fixed fir_filter_with_buffer and added QA code to check.
Browse files Browse the repository at this point in the history
  • Loading branch information
trondeau committed Jun 18, 2012
1 parent 765d82d commit 6b2dbab
Show file tree
Hide file tree
Showing 7 changed files with 604 additions and 43 deletions.
6 changes: 3 additions & 3 deletions gr-filter/include/filter/fir_filter_with_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace gr {
unsigned int d_ntaps;
float *d_buffer;
unsigned int d_idx;
float *d_aligned_taps;
float **d_aligned_taps;
float *d_output;
int d_align;
int d_naligned;
Expand Down Expand Up @@ -138,7 +138,7 @@ namespace gr {
unsigned int d_ntaps;
gr_complex *d_buffer;
unsigned int d_idx;
gr_complex *d_aligned_taps;
gr_complex **d_aligned_taps;
gr_complex *d_output;
int d_align;
int d_naligned;
Expand Down Expand Up @@ -234,7 +234,7 @@ namespace gr {
unsigned int d_ntaps;
gr_complex *d_buffer;
unsigned int d_idx;
float *d_aligned_taps;
float **d_aligned_taps;
gr_complex *d_output;
int d_align;
int d_naligned;
Expand Down
1 change: 1 addition & 0 deletions gr-filter/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ list(APPEND test_gr_filter_sources
${CMAKE_CURRENT_SOURCE_DIR}/test_gr_filter.cc
${CMAKE_CURRENT_SOURCE_DIR}/qa_filter.cc
${CMAKE_CURRENT_SOURCE_DIR}/qa_firdes.cc
${CMAKE_CURRENT_SOURCE_DIR}/qa_fir_filter_with_buffer.cc
${CMAKE_CURRENT_SOURCE_DIR}/qa_mmse_fir_interpolator_cc.cc
${CMAKE_CURRENT_SOURCE_DIR}/qa_mmse_fir_interpolator_ff.cc
)
Expand Down
1 change: 0 additions & 1 deletion gr-filter/lib/fir_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include <fft/fft.h>
#include <volk/volk.h>
#include <cstdio>
#include <float_dotprod_x86.h>

namespace gr {
namespace filter {
Expand Down
133 changes: 94 additions & 39 deletions gr-filter/lib/fir_filter_with_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <fft/fft.h>
#include <volk/volk.h>
#include <algorithm>
#include <cstdio>

namespace gr {
namespace filter {
Expand All @@ -54,8 +55,13 @@ namespace gr {
}

// Free aligned taps
fft::free(d_aligned_taps);
d_aligned_taps = NULL;
if(d_aligned_taps != NULL) {
for(int i = 0; i < d_naligned; i++) {
fft::free(d_aligned_taps[i]);
}
fft::free(d_aligned_taps);
d_aligned_taps = NULL;
}

// Free output sample
fft::free(d_output);
Expand All @@ -71,20 +77,27 @@ namespace gr {

// Free the taps if already allocated
if(d_aligned_taps != NULL) {
for(int i = 0; i < d_naligned; i++) {
fft::free(d_aligned_taps[i]);
}
fft::free(d_aligned_taps);
d_aligned_taps = NULL;
}

d_buffer = fft::malloc_float(d_ntaps);

d_ntaps = (int)taps.size();
d_taps = taps;
std::reverse(d_taps.begin(), d_taps.end());

d_buffer = fft::malloc_float(2*d_ntaps);
memset(d_buffer, 0, 2*d_ntaps*sizeof(float));

// Allocate aligned taps
d_aligned_taps = fft::malloc_float(d_ntaps);
for(unsigned int i = 0; i < d_ntaps; i++) {
d_aligned_taps[i] = d_taps[i];
d_aligned_taps = (float**)malloc(d_naligned*sizeof(float**));
for(int i = 0; i < d_naligned; i++) {
d_aligned_taps[i] = fft::malloc_float(d_ntaps+d_naligned-1);
memset(d_aligned_taps[i], 0, sizeof(float)*(d_ntaps+d_naligned-1));
for(unsigned int j = 0; j < d_ntaps; j++)
d_aligned_taps[i][i+j] = d_taps[j];
}

d_idx = 0;
Expand All @@ -108,9 +121,12 @@ namespace gr {
if(d_idx >= ntaps())
d_idx = 0;

volk_32f_x2_dot_prod_32f_a(d_output, d_buffer,
d_aligned_taps,
ntaps());
const float *ar = (float*)((unsigned long)(&d_buffer[d_idx]) & ~(d_align-1));
unsigned al = (&d_buffer[d_idx]) - ar;

volk_32f_x2_dot_prod_32f_a(d_output, ar,
d_aligned_taps[al],
ntaps()+al);
return *d_output;
}

Expand All @@ -128,9 +144,12 @@ namespace gr {
d_idx = 0;
}

volk_32f_x2_dot_prod_32f_a(d_output, d_buffer,
d_aligned_taps,
ntaps());
const float *ar = (float*)((unsigned long)(&d_buffer[d_idx]) & ~(d_align-1));
unsigned al = (&d_buffer[d_idx]) - ar;

volk_32f_x2_dot_prod_32f_a(d_output, ar,
d_aligned_taps[al],
ntaps()+al);
return *d_output;
}

Expand Down Expand Up @@ -182,8 +201,13 @@ namespace gr {
}

// Free aligned taps
fft::free(d_aligned_taps);
d_aligned_taps = NULL;
if(d_aligned_taps != NULL) {
for(int i = 0; i < d_naligned; i++) {
fft::free(d_aligned_taps[i]);
}
fft::free(d_aligned_taps);
d_aligned_taps = NULL;
}

// Free output sample
fft::free(d_output);
Expand All @@ -199,20 +223,27 @@ namespace gr {

// Free the taps if already allocated
if(d_aligned_taps != NULL) {
for(int i = 0; i < d_naligned; i++) {
fft::free(d_aligned_taps[i]);
}
fft::free(d_aligned_taps);
d_aligned_taps = NULL;
}

d_buffer = fft::malloc_complex(d_ntaps);

d_ntaps = (int)taps.size();
d_taps = taps;
std::reverse(d_taps.begin(), d_taps.end());

d_buffer = fft::malloc_complex(2*d_ntaps);
memset(d_buffer, 0, 2*d_ntaps*sizeof(gr_complex));

// Allocate aligned taps
d_aligned_taps = fft::malloc_complex(d_ntaps);
for(unsigned int i = 0; i < d_ntaps; i++) {
d_aligned_taps[i] = d_taps[i];
d_aligned_taps = (gr_complex**)malloc(d_naligned*sizeof(gr_complex**));
for(int i = 0; i < d_naligned; i++) {
d_aligned_taps[i] = fft::malloc_complex(d_ntaps+d_naligned-1);
memset(d_aligned_taps[i], 0, sizeof(gr_complex)*(d_ntaps+d_naligned-1));
for(unsigned int j = 0; j < d_ntaps; j++)
d_aligned_taps[i][i+j] = d_taps[j];
}

d_idx = 0;
Expand All @@ -236,9 +267,12 @@ namespace gr {
if(d_idx >= ntaps())
d_idx = 0;

volk_32fc_x2_dot_prod_32fc_a(d_output, d_buffer,
d_aligned_taps,
ntaps());
const gr_complex *ar = (gr_complex *)((unsigned long)(&d_buffer[d_idx]) & ~(d_align-1));
unsigned al = (&d_buffer[d_idx]) - ar;

volk_32fc_x2_dot_prod_32fc_a(d_output, ar,
d_aligned_taps[al],
(ntaps()+al)*sizeof(gr_complex));
return *d_output;
}

Expand All @@ -256,9 +290,12 @@ namespace gr {
d_idx = 0;
}

volk_32fc_x2_dot_prod_32fc_a(d_output, d_buffer,
d_aligned_taps,
ntaps());
const gr_complex *ar = (gr_complex *)((unsigned long)(&d_buffer[d_idx]) & ~(d_align-1));
unsigned al = (&d_buffer[d_idx]) - ar;

volk_32fc_x2_dot_prod_32fc_a(d_output, ar,
d_aligned_taps[al],
(ntaps()+al)*sizeof(gr_complex));
return *d_output;
}

Expand Down Expand Up @@ -310,8 +347,13 @@ namespace gr {
}

// Free aligned taps
fft::free(d_aligned_taps);
d_aligned_taps = NULL;
if(d_aligned_taps != NULL) {
for(int i = 0; i < d_naligned; i++) {
fft::free(d_aligned_taps[i]);
}
fft::free(d_aligned_taps);
d_aligned_taps = NULL;
}

// Free output sample
fft::free(d_output);
Expand All @@ -327,20 +369,27 @@ namespace gr {

// Free the taps if already allocated
if(d_aligned_taps != NULL) {
for(int i = 0; i < d_naligned; i++) {
fft::free(d_aligned_taps[i]);
}
fft::free(d_aligned_taps);
d_aligned_taps = NULL;
}

d_buffer = fft::malloc_complex(d_ntaps);

d_ntaps = (int)taps.size();
d_taps = taps;
std::reverse(d_taps.begin(), d_taps.end());

d_buffer = fft::malloc_complex(2*d_ntaps);
memset(d_buffer, 0, 2*d_ntaps*sizeof(gr_complex));

// Allocate aligned taps
d_aligned_taps = fft::malloc_float(d_ntaps);
for(unsigned int i = 0; i < d_ntaps; i++) {
d_aligned_taps[i] = d_taps[i];
d_aligned_taps = (float**)malloc(d_naligned*sizeof(float**));
for(int i = 0; i < d_naligned; i++) {
d_aligned_taps[i] = fft::malloc_float(d_ntaps+d_naligned-1);
memset(d_aligned_taps[i], 0, sizeof(float)*(d_ntaps+d_naligned-1));
for(unsigned int j = 0; j < d_ntaps; j++)
d_aligned_taps[i][i+j] = d_taps[j];
}

d_idx = 0;
Expand All @@ -364,9 +413,12 @@ namespace gr {
if(d_idx >= ntaps())
d_idx = 0;

volk_32fc_32f_dot_prod_32fc_a(d_output, d_buffer,
d_aligned_taps,
ntaps());
const gr_complex *ar = (gr_complex *)((unsigned long)(&d_buffer[d_idx]) & ~(d_align-1));
unsigned al = (&d_buffer[d_idx]) - ar;

volk_32fc_32f_dot_prod_32fc_a(d_output, ar,
d_aligned_taps[al],
ntaps()+al);
return *d_output;
}

Expand All @@ -384,9 +436,12 @@ namespace gr {
d_idx = 0;
}

volk_32fc_32f_dot_prod_32fc_a(d_output, d_buffer,
d_aligned_taps,
ntaps());
const gr_complex *ar = (gr_complex *)((unsigned long)(&d_buffer[d_idx]) & ~(d_align-1));
unsigned al = (&d_buffer[d_idx]) - ar;

volk_32fc_32f_dot_prod_32fc_a(d_output, ar,
d_aligned_taps[al],
ntaps()+al);
return *d_output;
}

Expand Down
4 changes: 4 additions & 0 deletions gr-filter/lib/qa_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include <qa_filter.h>
#include <qa_firdes.h>
#include <qa_fir_filter_with_buffer.h>
#include <qa_mmse_fir_interpolator_cc.h>
#include <qa_mmse_fir_interpolator_ff.h>

Expand All @@ -36,6 +37,9 @@ qa_gr_filter::suite ()
CppUnit::TestSuite *s = new CppUnit::TestSuite ("gr-filter");

s->addTest(gr::filter::qa_firdes::suite());
s->addTest(gr::filter::fff::qa_fir_filter_with_buffer_fff::suite());
s->addTest(gr::filter::ccc::qa_fir_filter_with_buffer_ccc::suite());
s->addTest(gr::filter::ccf::qa_fir_filter_with_buffer_ccf::suite());
s->addTest(gr::filter::qa_mmse_fir_interpolator_cc::suite());
s->addTest(gr::filter::qa_mmse_fir_interpolator_ff::suite());

Expand Down

0 comments on commit 6b2dbab

Please sign in to comment.