Trial fix for ticket:189, gr_mpsk_receiver_cc problem.
authoreb <eb@221aa14e-8319-0410-a670-987f0aec2ac5>
Tue, 2 Oct 2007 21:32:19 +0000 (21:32 +0000)
committereb <eb@221aa14e-8319-0410-a670-987f0aec2ac5>
Tue, 2 Oct 2007 21:32:19 +0000 (21:32 +0000)
Added checking for SIMD alignment requirement on gr_complex (must be
8-byte aligned) so that future violations will throw an exception.
Modified gr_mpsk_receiver_cc.h so that delay line being passed to
gri_mmse_fir_interpolator_cc is 8-byte aligned.  Added QA code for
gri_mmse_fir_interpolator_cc.

git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@6575 221aa14e-8319-0410-a670-987f0aec2ac5

gnuradio-core/src/lib/filter/Makefile.am
gnuradio-core/src/lib/filter/gr_fir_ccc_simd.cc
gnuradio-core/src/lib/filter/gr_fir_ccf_simd.cc
gnuradio-core/src/lib/filter/gri_mmse_fir_interpolator_cc.h
gnuradio-core/src/lib/filter/qa_filter.cc
gnuradio-core/src/lib/filter/qa_gri_mmse_fir_interpolator_cc.cc [new file with mode: 0644]
gnuradio-core/src/lib/filter/qa_gri_mmse_fir_interpolator_cc.h [new file with mode: 0644]
gnuradio-core/src/lib/general/gr_mpsk_receiver_cc.h

index 78c316fe53925306a2a1e7d487d7976f64369fe3..83474ffff8ae4ca958b44f38df421956ee83d533 100644 (file)
@@ -196,7 +196,8 @@ libfilter_qa_la_common_SOURCES =    \
        qa_gr_fir_fff.cc                \
        qa_gr_fir_ccc.cc                \
        qa_gr_fir_scc.cc                \
-       qa_gri_mmse_fir_interpolator.cc 
+       qa_gri_mmse_fir_interpolator.cc \
+       qa_gri_mmse_fir_interpolator_cc.cc      
 
 if MD_CPU_generic
 libfilter_la_SOURCES = $(libfilter_la_common_SOURCES) $(generic_CODE)
@@ -281,7 +282,8 @@ noinst_HEADERS =                    \
        qa_gr_fir_fff.h                 \
        qa_gr_fir_ccc.h                 \
        qa_gr_fir_scc.h                 \
-       qa_gri_mmse_fir_interpolator.h  
+       qa_gri_mmse_fir_interpolator.h  \
+       qa_gri_mmse_fir_interpolator_cc.h       
 
 
 
index 8868b1a59b6988a4072281519a100d3051799d08..44fdeacdf6a3b36fce03dd633f88af45761fe173 100644 (file)
@@ -1,6 +1,6 @@
 /* -*- c++ -*- */
 /*
- * Copyright 2002 Free Software Foundation, Inc.
+ * Copyright 2002,2007 Free Software Foundation, Inc.
  * 
  * This file is part of GNU Radio
  * 
@@ -28,6 +28,7 @@
 #include <assert.h>
 #include <malloc16.h>
 #include <iostream>
+#include <stdexcept>
 
 using std::cerr;
 using std::endl;
@@ -105,6 +106,8 @@ gr_fir_ccc_simd::filter (const gr_complex input[])
   if (ntaps () == 0)
     return 0.0;
 
+  if (((intptr_t) input & 0x7) != 0)
+    throw std::invalid_argument("gr_complex must be 8-byte aligned");
 
   // Round input data address down to 16 byte boundary
   // NB: depending on the alignment of input[], memory
index 0862ba1f0b75dc64e479b5e1389475abb8f5a6c0..c20cd4e623fc3e6d3b91aa2d56433a7263051dac 100644 (file)
@@ -1,6 +1,6 @@
 /* -*- c++ -*- */
 /*
- * Copyright 2002 Free Software Foundation, Inc.
+ * Copyright 2002,2007 Free Software Foundation, Inc.
  * 
  * This file is part of GNU Radio
  * 
@@ -28,6 +28,7 @@
 #include <assert.h>
 #include <malloc16.h>
 #include <iostream>
+#include <stdexcept>
 
 using std::cerr;
 using std::endl;
@@ -103,6 +104,8 @@ gr_fir_ccf_simd::filter (const gr_complex input[])
   if (ntaps () == 0)
     return 0.0;
 
+  if (((intptr_t) input & 0x7) != 0)
+    throw std::invalid_argument("gr_complex must be 8-byte aligned");
 
   // Round input data address down to 16 byte boundary
   // NB: depending on the alignment of input[], memory
index 527c3ec3bef6e5f1014c2b7b901ad851fc8de75b..687498c3b4e0fca164cba31a48b93f1508db374c 100644 (file)
@@ -1,6 +1,6 @@
 /* -*- c++ -*- */
 /*
- * Copyright 2002 Free Software Foundation, Inc.
+ * Copyright 2002,2007 Free Software Foundation, Inc.
  * 
  * This file is part of GNU Radio
  * 
@@ -49,8 +49,10 @@ public:
 
   /*!
    * \brief compute a single interpolated output value.
-   * \p input must have ntaps() valid entries.
+   *
+   * \p input must have ntaps() valid entries and be 8-byte aligned.
    * input[0] .. input[ntaps() - 1] are referenced to compute the output value.
+   * \throws std::invalid_argument if input is not 8-byte aligned.
    *
    * \p mu must be in the range [0, 1] and specifies the fractional delay.
    *
index 2a48636f680129fc62243f4e8cfe5cad8bbe1e28..e36fca45d46febca0a728236a4c7c84215f321a1 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2002 Free Software Foundation, Inc.
+ * Copyright 2002,2007 Free Software Foundation, Inc.
  * 
  * This file is part of GNU Radio
  * 
@@ -34,6 +34,7 @@
 #include <qa_gr_firdes.h>
 #include <qa_dotprod.h>
 #include <qa_gri_mmse_fir_interpolator.h>
+#include <qa_gri_mmse_fir_interpolator_cc.h>
 
 CppUnit::TestSuite *
 qa_filter::suite ()
@@ -42,6 +43,7 @@ qa_filter::suite ()
 
   s->addTest (qa_dotprod_suite ());
   s->addTest (qa_gri_mmse_fir_interpolator::suite ());
+  s->addTest (qa_gri_mmse_fir_interpolator_cc::suite ());
   s->addTest (qa_gr_fir_fff::suite ());
   s->addTest (qa_gr_fir_ccc::suite ());
   s->addTest (qa_gr_fir_fcc::suite ());
diff --git a/gnuradio-core/src/lib/filter/qa_gri_mmse_fir_interpolator_cc.cc b/gnuradio-core/src/lib/filter/qa_gri_mmse_fir_interpolator_cc.cc
new file mode 100644 (file)
index 0000000..8695b4f
--- /dev/null
@@ -0,0 +1,118 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2002,2007 Free Software Foundation, Inc.
+ * 
+ * This file is part of GNU Radio
+ * 
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ * 
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include <cppunit/TestAssert.h>
+#include <qa_gri_mmse_fir_interpolator_cc.h>
+#include <gri_mmse_fir_interpolator_cc.h>
+#include <stdio.h>
+#include <cmath>
+#include <stdexcept>
+
+#define        NELEM(x) (sizeof (x) / sizeof (x[0]))
+
+
+static float
+test_fcn_sin(double index)
+{
+  return (2 * sin (index * 0.25 * 2 * M_PI + 0.125 * M_PI)
+         + 3 * sin (index * 0.077 * 2 * M_PI + 0.3 * M_PI));
+}
+
+static float
+test_fcn_cos(double index)
+{
+  return (2 * cos (index * 0.25 * 2 * M_PI + 0.125 * M_PI)
+         + 3 * cos (index * 0.077 * 2 * M_PI + 0.3 * M_PI));
+}
+
+static gr_complex
+test_fcn(double index)
+{
+  return gr_complex(test_fcn_cos(index), test_fcn_sin(index));
+}
+
+
+void
+qa_gri_mmse_fir_interpolator_cc::t1()
+{
+  static const unsigned        N = 100;
+  gr_complex input[N + 10];
+
+  for (unsigned i = 0; i < NELEM(input); i++)
+    input[i] = test_fcn ((double) i);
+
+  gri_mmse_fir_interpolator_cc intr;
+  float inv_nsteps = 1.0 / intr.nsteps ();
+
+  for (unsigned i = 0; i < N; i++){
+    for (unsigned imu = 0; imu <= intr.nsteps (); imu += 1){
+      gr_complex expected = test_fcn ((i + 3) + imu * inv_nsteps);
+      gr_complex actual = intr.interpolate (&input[i], imu * inv_nsteps);
+
+      CPPUNIT_ASSERT_COMPLEXES_EQUAL (expected, actual, 0.004);
+      // printf ("%9.6f  %9.6f  %9.6f\n", expected, actual, expected - actual);
+    }
+  }
+}
+
+
+/*
+ * Force bad alignment and confirm that it raises an exception
+ */
+void
+qa_gri_mmse_fir_interpolator_cc::t2_body()
+{
+  static const unsigned        N = 100;
+  float float_input[2*(N+10) + 1];
+  gr_complex *input;
+
+  // We require that gr_complex be aligned on an 8-byte boundary.
+  // Ensure that we ARE NOT ;)
+
+  if (((intptr_t) float_input & 0x7) == 0)
+    input = reinterpret_cast<gr_complex *>(&float_input[1]);
+  else
+    input = reinterpret_cast<gr_complex *>(&float_input[0]);
+
+
+  for (unsigned i = 0; i < (N+10); i++)
+    input[i] = test_fcn ((double) i);
+
+  gri_mmse_fir_interpolator_cc intr;
+  float inv_nsteps = 1.0 / intr.nsteps ();
+
+  for (unsigned i = 0; i < N; i++){
+    for (unsigned imu = 0; imu <= intr.nsteps (); imu += 1){
+      gr_complex expected = test_fcn ((i + 3) + imu * inv_nsteps);
+      gr_complex actual = intr.interpolate (&input[i], imu * inv_nsteps);
+
+      CPPUNIT_ASSERT_COMPLEXES_EQUAL (expected, actual, 0.004);
+      // printf ("%9.6f  %9.6f  %9.6f\n", expected, actual, expected - actual);
+    }
+  }
+}
+
+void
+qa_gri_mmse_fir_interpolator_cc::t2()
+{
+  CPPUNIT_ASSERT_THROW(t2_body(), std::invalid_argument);
+}
diff --git a/gnuradio-core/src/lib/filter/qa_gri_mmse_fir_interpolator_cc.h b/gnuradio-core/src/lib/filter/qa_gri_mmse_fir_interpolator_cc.h
new file mode 100644 (file)
index 0000000..496f397
--- /dev/null
@@ -0,0 +1,42 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2002,2007 Free Software Foundation, Inc.
+ * 
+ * This file is part of GNU Radio
+ * 
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ * 
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+#ifndef _QA_GRI_MMSE_FIR_INTERPOLATOR_CC_H_
+#define _QA_GRI_MMSE_FIR_INTERPOLATOR_CC_H_
+
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/TestCase.h>
+
+class qa_gri_mmse_fir_interpolator_cc : public CppUnit::TestCase {
+
+  CPPUNIT_TEST_SUITE(qa_gri_mmse_fir_interpolator_cc);
+  CPPUNIT_TEST(t1);
+  // CPPUNIT_TEST(t2);
+  CPPUNIT_TEST_SUITE_END();
+
+ private:
+  void t1();
+  void t2();
+  void t2_body();
+
+};
+
+#endif /* _QA_GRI_MMSE_FIR_INTERPOLATOR_CC_H_ */
index f718b541e34064146434bb760d4949ff311ded7e..b0ecb7c93ed551f10aacdddeb85df1474f389149 100644 (file)
@@ -1,6 +1,6 @@
 /* -*- c++ -*- */
 /*
- * Copyright 2004 Free Software Foundation, Inc.
+ * Copyright 2004,2007 Free Software Foundation, Inc.
  *
  * This file is part of GNU Radio
  *
@@ -297,7 +297,7 @@ protected:
   static const unsigned int DLLEN = 8;
   
   //! delay line plus some length for overflow protection
-  gr_complex d_dl[2*DLLEN];
+  gr_complex d_dl[2*DLLEN] __attribute__ ((aligned(8)));
   
   //! index to delay line
   unsigned int d_dl_idx;