summaryrefslogtreecommitdiff
path: root/volk
diff options
context:
space:
mode:
Diffstat (limited to 'volk')
-rw-r--r--volk/include/volk/Makefile.am3
-rw-r--r--volk/include/volk/volk_32fc_conjugate_dot_prod_unaligned.h144
-rw-r--r--volk/lib/Makefile.am2
-rw-r--r--volk/lib/qa_32fc_conjugate_dot_prod_unaligned.cc138
-rw-r--r--volk/lib/qa_32fc_conjugate_dot_prod_unaligned.h18
-rw-r--r--volk/lib/qa_volk.cc2
6 files changed, 306 insertions, 1 deletions
diff --git a/volk/include/volk/Makefile.am b/volk/include/volk/Makefile.am
index 658974d3a..00289be1e 100644
--- a/volk/include/volk/Makefile.am
+++ b/volk/include/volk/Makefile.am
@@ -66,6 +66,7 @@ volkinclude_HEADERS = \
volk_32f_calc_spectral_noise_floor_aligned16.h \
volk_32fc_atan2_32f_aligned16.h \
volk_32fc_conjugate_dot_prod_aligned16.h \
+ volk_32fc_conjugate_dot_prod_unaligned.h \
volk_32fc_deinterleave_32f_aligned16.h \
volk_32fc_deinterleave_64f_aligned16.h \
volk_32fc_deinterleave_real_16s_aligned16.h \
@@ -157,4 +158,4 @@ distclean-local:
rm -f Makefile.in
rm -f volk_environment_init.h
rm -f volk_mktables
- rm -f $(BUILT_SOURCES) \ No newline at end of file
+ rm -f $(BUILT_SOURCES)
diff --git a/volk/include/volk/volk_32fc_conjugate_dot_prod_unaligned.h b/volk/include/volk/volk_32fc_conjugate_dot_prod_unaligned.h
new file mode 100644
index 000000000..ead1573fe
--- /dev/null
+++ b/volk/include/volk/volk_32fc_conjugate_dot_prod_unaligned.h
@@ -0,0 +1,144 @@
+#ifndef INCLUDED_VOLK_32fc_CONJUGATE_DOT_PROD_UNALIGNED_H
+#define INCLUDED_VOLK_32fc_CONJUGATE_DOT_PROD_UNALIGNED_H
+
+
+#include<volk/volk_complex.h>
+
+
+#if LV_HAVE_GENERIC
+
+
+static inline void volk_32fc_conjugate_dot_prod_unaligned_generic(lv_32fc_t* result, const lv_32fc_t* input, const lv_32fc_t* taps, unsigned int num_bytes) {
+
+ float * res = (float*) result;
+ float * in = (float*) input;
+ float * tp = (float*) taps;
+ unsigned int n_2_ccomplex_blocks = num_bytes >> 4;
+ unsigned int isodd = (num_bytes >> 3) &1;
+
+
+
+ float sum0[2] = {0,0};
+ float sum1[2] = {0,0};
+ int i = 0;
+
+
+ for(i = 0; i < n_2_ccomplex_blocks; ++i) {
+
+ sum0[0] += in[0] * tp[0] + in[1] * tp[1];
+ sum0[1] += (-in[0] * tp[1]) + in[1] * tp[0];
+ sum1[0] += in[2] * tp[2] + in[3] * tp[3];
+ sum1[1] += (-in[2] * tp[3]) + in[3] * tp[2];
+
+
+ in += 4;
+ tp += 4;
+
+ }
+
+
+ res[0] = sum0[0] + sum1[0];
+ res[1] = sum0[1] + sum1[1];
+
+
+
+ for(i = 0; i < isodd; ++i) {
+
+
+ *result += input[(num_bytes >> 3) - 1] * lv_conj(taps[(num_bytes >> 3) - 1]);
+
+ }
+ /*
+ for(i = 0; i < num_bytes >> 3; ++i) {
+ *result += input[i] * conjf(taps[i]);
+ }
+ */
+}
+
+#endif /*LV_HAVE_GENERIC*/
+
+#if LV_HAVE_SSE3
+
+#include <xmmintrin.h>
+#include <pmmintrin.h>
+#include <mmintrin.h>
+
+
+static inline void volk_32fc_conjugate_dot_prod_unaligned_sse3(lv_32fc_t* result, const lv_32fc_t* input, const lv_32fc_t* taps, unsigned int num_bytes) {
+
+ static const uint32_t conjugator[4] __attribute__((aligned(16)))= {0x00000000, 0x80000000, 0x00000000, 0x80000000};
+
+ union HalfMask {
+ uint32_t intRep[4];
+ __m128 vec;
+ } halfMask;
+
+ union NegMask {
+ int intRep[4];
+ __m128 vec;
+ } negMask;
+
+ unsigned int offset = 0;
+ float Rsum=0, Isum=0;
+ float Im,Re;
+
+ __m128 in1, in2, Rv, fehg, Iv, Rs, Ivm, Is;
+ __m128 zv = {0,0,0,0};
+
+ halfMask.intRep[0] = halfMask.intRep[1] = 0xFFFFFFFF;
+ halfMask.intRep[2] = halfMask.intRep[3] = 0x00000000;
+
+ negMask.intRep[0] = negMask.intRep[2] = 0x80000000;
+ negMask.intRep[1] = negMask.intRep[3] = 0;
+
+ // main loop
+ while(num_bytes >= 4*sizeof(float)){
+
+ in1 = _mm_loadu_ps( (float*) (input+offset) );
+ in2 = _mm_loadu_ps( (float*) (taps+offset) );
+ Rv = in1*in2;
+ fehg = _mm_shuffle_ps(in2, in2, _MM_SHUFFLE(2,3,0,1));
+ Iv = in1*fehg;
+ Rs = _mm_hadd_ps( _mm_hadd_ps(Rv, zv) ,zv);
+ Ivm = _mm_xor_ps( negMask.vec, Iv );
+ Is = _mm_hadd_ps( _mm_hadd_ps(Ivm, zv) ,zv);
+ _mm_store_ss( &Im, Is );
+ _mm_store_ss( &Re, Rs );
+ num_bytes -= 4*sizeof(float);
+ offset += 2;
+ Rsum += Re;
+ Isum += Im;
+ }
+
+ // handle the last complex case ...
+ if(num_bytes > 0){
+
+ if(num_bytes != 4){
+ // bad things are happening
+ }
+
+ in1 = _mm_loadu_ps( (float*) (input+offset) );
+ in2 = _mm_loadu_ps( (float*) (taps+offset) );
+ Rv = _mm_and_ps(in1*in2, halfMask.vec);
+ fehg = _mm_shuffle_ps(in2, in2, _MM_SHUFFLE(2,3,0,1));
+ Iv = _mm_and_ps(in1*fehg, halfMask.vec);
+ Rs = _mm_hadd_ps(_mm_hadd_ps(Rv, zv),zv);
+ Ivm = _mm_xor_ps( negMask.vec, Iv );
+ Is = _mm_hadd_ps(_mm_hadd_ps(Ivm, zv),zv);
+ _mm_store_ss( &Im, Is );
+ _mm_store_ss( &Re, Rs );
+ Rsum += Re;
+ Isum += Im;
+ }
+
+ result[0] = lv_32fc_init(Rsum,Isum);
+ return;
+}
+
+#endif /*LV_HAVE_SSE3*/
+
+
+#endif /*INCLUDED_VOLK_32fc_CONJUGATE_DOT_PROD_UNALIGNED_H*/
+
+
+
diff --git a/volk/lib/Makefile.am b/volk/lib/Makefile.am
index 7a355e86a..beb815e63 100644
--- a/volk/lib/Makefile.am
+++ b/volk/lib/Makefile.am
@@ -93,6 +93,7 @@ libvolk_qa_la_SOURCES = \
qa_32fc_index_max_aligned16.cc \
qa_32f_index_max_aligned16.cc \
qa_32fc_conjugate_dot_prod_aligned16.cc \
+ qa_32fc_conjugate_dot_prod_unaligned.cc \
qa_16s_permute_and_scalar_add_aligned16.cc \
qa_16s_branch_4_state_8_aligned16.cc \
qa_16s_max_star_horizontal_aligned16.cc \
@@ -195,6 +196,7 @@ noinst_HEADERS = \
qa_32fc_index_max_aligned16.h \
qa_32f_index_max_aligned16.h \
qa_32fc_conjugate_dot_prod_aligned16.h \
+ qa_32fc_conjugate_dot_prod_unaligned.h \
qa_16s_permute_and_scalar_add_aligned16.h \
qa_16s_branch_4_state_8_aligned16.h \
qa_16s_max_star_horizontal_aligned16.h \
diff --git a/volk/lib/qa_32fc_conjugate_dot_prod_unaligned.cc b/volk/lib/qa_32fc_conjugate_dot_prod_unaligned.cc
new file mode 100644
index 000000000..a0680bab6
--- /dev/null
+++ b/volk/lib/qa_32fc_conjugate_dot_prod_unaligned.cc
@@ -0,0 +1,138 @@
+#include <volk/volk.h>
+#include <qa_32fc_conjugate_dot_prod_unaligned.h>
+#include <stdlib.h>
+#include <math.h>
+#include <time.h>
+
+
+#define assertcomplexEqual(expected, actual, delta) \
+ CPPUNIT_ASSERT_DOUBLES_EQUAL (std::real(expected), std::real(actual), fabs(std::real(expected)) * delta); \
+ CPPUNIT_ASSERT_DOUBLES_EQUAL (std::imag(expected), std::imag(actual), fabs(std::imag(expected))* delta);
+
+#define ERR_DELTA (1e-4)
+
+//test for sse
+
+#if LV_HAVE_SSE && LV_HAVE_64
+
+static float uniform() {
+ return 2.0 * ((float) rand() / RAND_MAX - 0.5); // uniformly (-1, 1)
+}
+
+static void
+random_floats (float *buf, unsigned n)
+{
+ for (unsigned i = 0; i < n; i++)
+ buf[i] = uniform () * 32767;
+}
+
+
+void qa_32fc_conjugate_dot_prod_unaligned::t1() {
+ const int vlen = 789743;
+
+ volk_environment_init();
+ int ret;
+
+ std::complex<float>* input;
+ std::complex<float>* taps;
+
+ std::complex<float>* result_generic;
+ std::complex<float>* result;
+
+ ret = posix_memalign((void**)&input, 16, vlen << 3);
+ ret = posix_memalign((void**)&taps, 16, vlen << 3);
+ ret = posix_memalign((void**)&result_generic, 16, 8);
+ ret = posix_memalign((void**)&result, 16, 8);
+
+
+ result_generic[0] = std::complex<float>(0,0);
+ result[0] = std::complex<float>(0,0);
+
+ random_floats((float*)input, vlen * 2);
+ random_floats((float*)taps, vlen * 2);
+
+
+
+ volk_32fc_conjugate_dot_prod_unaligned_manual(result_generic, input, taps, vlen * 8, "generic");
+
+
+ volk_32fc_conjugate_dot_prod_unaligned_manual(result, input, taps, vlen * 8, "sse");
+
+ printf("32fc_conjugate_dot_prod_unaligned\n");
+ printf("generic: %f +i%f ... sse: %f +i%f\n", std::real(result_generic[0]), std::imag(result_generic[0]), std::real(result[0]), std::imag(result[0]));
+
+ assertcomplexEqual(result_generic[0], result[0], ERR_DELTA);
+
+ free(input);
+ free(taps);
+ free(result_generic);
+ free(result);
+
+}
+
+
+#elif LV_HAVE_SSE && LV_HAVE_32
+
+static float uniform() {
+ return 2.0 * ((float) rand() / RAND_MAX - 0.5); // uniformly (-1, 1)
+}
+
+static void
+random_floats (float *buf, unsigned n)
+{
+ for (unsigned i = 0; i < n; i++)
+ buf[i] = uniform () * 32767;
+}
+
+
+void qa_32fc_conjugate_dot_prod_unaligned::t1() {
+ const int vlen = 789743;
+
+ volk_environment_init();
+ int ret;
+
+ std::complex<float>* input;
+ std::complex<float>* taps;
+
+ std::complex<float>* result_generic;
+ std::complex<float>* result;
+
+ ret = posix_memalign((void**)&input, 16, vlen << 3);
+ ret = posix_memalign((void**)&taps, 16, vlen << 3);
+ ret = posix_memalign((void**)&result_generic, 16, 8);
+ ret = posix_memalign((void**)&result, 16, 8);
+
+
+ result_generic[0] = std::complex<float>(0,0);
+ result[0] = std::complex<float>(0,0);
+
+ random_floats((float*)input, vlen * 2);
+ random_floats((float*)taps, vlen * 2);
+
+
+
+ volk_32fc_conjugate_dot_prod_unaligned_manual(result_generic, input, taps, vlen * 8, "generic");
+
+
+ volk_32fc_conjugate_dot_prod_unaligned_manual(result, input, taps, vlen * 8, "sse_32");
+
+ printf("32fc_conjugate_dot_prod_unaligned\n");
+ printf("generic: %f +i%f ... sse: %f +i%f\n", std::real(result_generic[0]), std::imag(result_generic[0]), std::real(result[0]), std::imag(result[0]));
+
+ assertcomplexEqual(result_generic[0], result[0], ERR_DELTA);
+
+ free(input);
+ free(taps);
+ free(result_generic);
+ free(result);
+
+}
+
+
+#else
+
+void qa_32fc_conjugate_dot_prod_unaligned::t1() {
+ printf("sse not available... no test performed\n");
+}
+
+#endif /*LV_HAVE_SSE*/
diff --git a/volk/lib/qa_32fc_conjugate_dot_prod_unaligned.h b/volk/lib/qa_32fc_conjugate_dot_prod_unaligned.h
new file mode 100644
index 000000000..7aead53a1
--- /dev/null
+++ b/volk/lib/qa_32fc_conjugate_dot_prod_unaligned.h
@@ -0,0 +1,18 @@
+#ifndef INCLUDED_QA_32FC_CONJUGATE_DOT_PROD_UNALIGNED_H
+#define INCLUDED_QA_32FC_CONJUGATE_DOT_PROD_UNALIGNED_H
+
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/TestCase.h>
+
+class qa_32fc_conjugate_dot_prod_unaligned : public CppUnit::TestCase {
+
+ CPPUNIT_TEST_SUITE (qa_32fc_conjugate_dot_prod_unaligned);
+ CPPUNIT_TEST (t1);
+ CPPUNIT_TEST_SUITE_END ();
+
+ private:
+ void t1 ();
+};
+
+
+#endif /* INCLUDED_QA_32FC_CONJUGATE_DOT_PROD_UNALIGNED_H */
diff --git a/volk/lib/qa_volk.cc b/volk/lib/qa_volk.cc
index c3c27b69b..98d3e9728 100644
--- a/volk/lib/qa_volk.cc
+++ b/volk/lib/qa_volk.cc
@@ -34,6 +34,7 @@
#include <qa_32fc_index_max_aligned16.h>
#include <qa_32f_index_max_aligned16.h>
#include <qa_32fc_conjugate_dot_prod_aligned16.h>
+#include <qa_32fc_conjugate_dot_prod_unaligned.h>
#include <qa_16s_permute_and_scalar_add_aligned16.h>
#include <qa_16s_branch_4_state_8_aligned16.h>
#include <qa_16s_max_star_horizontal_aligned16.h>
@@ -127,6 +128,7 @@ qa_volk::suite()
s->addTest(qa_32fc_index_max_aligned16::suite());
s->addTest(qa_32f_index_max_aligned16::suite());
s->addTest(qa_32fc_conjugate_dot_prod_aligned16::suite());
+ s->addTest(qa_32fc_conjugate_dot_prod_unaligned::suite());
s->addTest(qa_16s_permute_and_scalar_add_aligned16::suite());
s->addTest(qa_16s_branch_4_state_8_aligned16::suite());
s->addTest(qa_16s_max_star_horizontal_aligned16::suite());