diff options
author | Tom Rondeau | 2012-02-02 16:36:47 -0500 |
---|---|---|
committer | Tom Rondeau | 2012-02-02 16:36:47 -0500 |
commit | e8089db25b2e28824f11d27c9d98a4adef191736 (patch) | |
tree | c129ba7c8dbf119e8a59f1e0ea3fde43eb7442aa /gnuradio-core/src | |
parent | 67d23bdecd3f15197bdf46f8c0cd66a6f754fea5 (diff) | |
download | gnuradio-e8089db25b2e28824f11d27c9d98a4adef191736.tar.gz gnuradio-e8089db25b2e28824f11d27c9d98a4adef191736.tar.bz2 gnuradio-e8089db25b2e28824f11d27c9d98a4adef191736.zip |
core: moving multiply_cc and multiply_const_cc out of gengen and into general so they can make use of volk calls.
QA code now explicitly tests the cc versions of these blocks.
Diffstat (limited to 'gnuradio-core/src')
-rw-r--r-- | gnuradio-core/src/lib/general/.gitignore | 6 | ||||
-rw-r--r-- | gnuradio-core/src/lib/general/CMakeLists.txt | 1 | ||||
-rw-r--r-- | gnuradio-core/src/lib/general/general.i | 2 | ||||
-rw-r--r-- | gnuradio-core/src/lib/general/gr_multiply_cc.cc | 69 | ||||
-rw-r--r-- | gnuradio-core/src/lib/general/gr_multiply_cc.h | 56 | ||||
-rw-r--r-- | gnuradio-core/src/lib/general/gr_multiply_cc.i | 32 | ||||
-rw-r--r-- | gnuradio-core/src/lib/general/gr_multiply_const_cc.cc | 82 | ||||
-rw-r--r-- | gnuradio-core/src/lib/general/gr_multiply_const_cc.h | 60 | ||||
-rw-r--r-- | gnuradio-core/src/lib/general/gr_multiply_const_cc.i | 33 | ||||
-rw-r--r-- | gnuradio-core/src/lib/gengen/.gitignore | 6 | ||||
-rw-r--r-- | gnuradio-core/src/lib/gengen/CMakeLists.txt | 4 | ||||
-rw-r--r-- | gnuradio-core/src/lib/gengen/Makefile.gen | 6 | ||||
-rwxr-xr-x | gnuradio-core/src/lib/gengen/generate_common.py | 6 | ||||
-rwxr-xr-x | gnuradio-core/src/python/gnuradio/gr/qa_add_and_friends.py | 20 |
14 files changed, 360 insertions, 23 deletions
diff --git a/gnuradio-core/src/lib/general/.gitignore b/gnuradio-core/src/lib/general/.gitignore index 4f3696f58..349651e0c 100644 --- a/gnuradio-core/src/lib/general/.gitignore +++ b/gnuradio-core/src/lib/general/.gitignore @@ -158,12 +158,6 @@ /gr_divide_ss.cc /gr_divide_ss.h /gr_divide_ss.i -/gr_multiply_cc.cc -/gr_multiply_cc.h -/gr_multiply_cc.i -/gr_multiply_const_cc.cc -/gr_multiply_const_cc.h -/gr_multiply_const_cc.i /gr_multiply_const_ff.cc /gr_multiply_const_ff.h /gr_multiply_const_ff.i diff --git a/gnuradio-core/src/lib/general/CMakeLists.txt b/gnuradio-core/src/lib/general/CMakeLists.txt index 6dc9d411d..6afdfe27c 100644 --- a/gnuradio-core/src/lib/general/CMakeLists.txt +++ b/gnuradio-core/src/lib/general/CMakeLists.txt @@ -231,6 +231,7 @@ set(gr_core_general_triple_threats gr_lfsr_32k_source_s gr_map_bb gr_multiply_cc + gr_multiply_const_cc gr_nlog10_ff gr_nop gr_null_sink diff --git a/gnuradio-core/src/lib/general/general.i b/gnuradio-core/src/lib/general/general.i index ec90e40e5..7de13258e 100644 --- a/gnuradio-core/src/lib/general/general.i +++ b/gnuradio-core/src/lib/general/general.i @@ -107,6 +107,7 @@ #include <gr_framer_sink_1.h> #include <gr_map_bb.h> #include <gr_multiply_cc.h> +#include <gr_multiply_const_cc.h> #include <gr_feval.h> #include <gr_pwr_squelch_cc.h> #include <gr_pwr_squelch_ff.h> @@ -224,6 +225,7 @@ %include "gr_framer_sink_1.i" %include "gr_map_bb.i" %include "gr_multiply_cc.i" +%include "gr_multiply_const_cc.i" %include "gr_feval.i" %include "gr_pwr_squelch_cc.i" %include "gr_pwr_squelch_ff.i" diff --git a/gnuradio-core/src/lib/general/gr_multiply_cc.cc b/gnuradio-core/src/lib/general/gr_multiply_cc.cc new file mode 100644 index 000000000..0d20e6257 --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_multiply_cc.cc @@ -0,0 +1,69 @@ +/* -*- c++ -*- */ +/* + * Copyright 2012 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <gr_multiply_cc.h> +#include <gr_io_signature.h> +#include <volk/volk.h> + +gr_multiply_cc_sptr +gr_make_multiply_cc (size_t vlen) +{ + return gnuradio::get_initial_sptr(new gr_multiply_cc (vlen)); +} + +gr_multiply_cc::gr_multiply_cc (size_t vlen) + : gr_sync_block ("gr_multiply_cc", + gr_make_io_signature (1, -1, sizeof (gr_complex)*vlen), + gr_make_io_signature (1, 1, sizeof (gr_complex)*vlen)), + d_vlen(vlen) +{ + const int alignment_multiple = + volk_get_alignment() / sizeof(gr_complex); + set_alignment(alignment_multiple); +} + +int +gr_multiply_cc::work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) +{ + gr_complex *out = (gr_complex *) output_items[0]; + int noi = d_vlen*noutput_items; + + memcpy(out, input_items[0], noi*sizeof(gr_complex)); + if(is_unaligned()) { + for(size_t i = 1; i < input_items.size(); i++) + volk_32fc_x2_multiply_32fc_u(out, out, (gr_complex*)input_items[i], noi); + } + else { + for(size_t i = 1; i < input_items.size(); i++) + volk_32fc_x2_multiply_32fc_a(out, out, (gr_complex*)input_items[i], noi); + } + return noutput_items; +} + + + diff --git a/gnuradio-core/src/lib/general/gr_multiply_cc.h b/gnuradio-core/src/lib/general/gr_multiply_cc.h new file mode 100644 index 000000000..f80ec8b25 --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_multiply_cc.h @@ -0,0 +1,56 @@ +/* -*- c++ -*- */ +/* + * Copyright 2012 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 INCLUDED_GR_MULTIPLY_CC_H +#define INCLUDED_GR_MULTIPLY_CC_H + +#include <gr_core_api.h> +#include <gr_sync_block.h> + +class gr_multiply_cc; +typedef boost::shared_ptr<gr_multiply_cc> gr_multiply_cc_sptr; + +GR_CORE_API gr_multiply_cc_sptr +gr_make_multiply_cc (size_t vlen=1); + +/*! + * \brief Multiply streams of complex values + * \ingroup math_blk + */ + +class GR_CORE_API gr_multiply_cc : public gr_sync_block +{ + private: + friend GR_CORE_API gr_multiply_cc_sptr + gr_make_multiply_cc (size_t vlen); + gr_multiply_cc (size_t vlen); + + size_t d_vlen; + + public: + virtual int work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); +}; + + +#endif /* INCLUDED_GR_MULTIPLY_CC_H */ diff --git a/gnuradio-core/src/lib/general/gr_multiply_cc.i b/gnuradio-core/src/lib/general/gr_multiply_cc.i new file mode 100644 index 000000000..61768c390 --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_multiply_cc.i @@ -0,0 +1,32 @@ +/* -*- c++ -*- */ +/* + * Copyright 2012 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. + */ + +GR_SWIG_BLOCK_MAGIC(gr,multiply_cc) + +gr_multiply_cc_sptr +gr_make_multiply_cc (size_t vlen=1); + +class gr_multiply_cc : public gr_sync_block +{ +public: + +}; diff --git a/gnuradio-core/src/lib/general/gr_multiply_const_cc.cc b/gnuradio-core/src/lib/general/gr_multiply_const_cc.cc new file mode 100644 index 000000000..e301ae8eb --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_multiply_const_cc.cc @@ -0,0 +1,82 @@ +/* -*- c++ -*- */ +/* + * Copyright 2012 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <gr_multiply_const_cc.h> +#include <gr_io_signature.h> +#include <volk/volk.h> + +gr_multiply_const_cc_sptr +gr_make_multiply_const_cc (gr_complex k, size_t vlen) +{ + return gnuradio::get_initial_sptr(new gr_multiply_const_cc (k, vlen)); +} + +gr_multiply_const_cc::gr_multiply_const_cc (gr_complex k, size_t vlen) + : gr_sync_block ("gr_multiply_const_cc", + gr_make_io_signature (1, 1, sizeof (gr_complex)*vlen), + gr_make_io_signature (1, 1, sizeof (gr_complex)*vlen)), + d_k(k), d_vlen(vlen) +{ + const int alignment_multiple = + volk_get_alignment() / sizeof(gr_complex); + set_alignment(alignment_multiple); +} + +gr_complex +gr_multiply_const_cc::k() const +{ + return d_k; +} + +void +gr_multiply_const_cc::set_k(gr_complex k) +{ + d_k = k; +} + +#include <cstdio> + +int +gr_multiply_const_cc::work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) +{ + const gr_complex *in = (const gr_complex *) input_items[0]; + gr_complex *out = (gr_complex *) output_items[0]; + int noi = d_vlen*noutput_items; + + if(is_unaligned()) { + volk_32fc_s32fc_multiply_32fc_u(out, in, d_k, noi); + } + else { + volk_32fc_s32fc_multiply_32fc_a(out, in, d_k, noi); + } + + return noutput_items; +} + + + diff --git a/gnuradio-core/src/lib/general/gr_multiply_const_cc.h b/gnuradio-core/src/lib/general/gr_multiply_const_cc.h new file mode 100644 index 000000000..1791d9160 --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_multiply_const_cc.h @@ -0,0 +1,60 @@ +/* -*- c++ -*- */ +/* + * Copyright 2012 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 INCLUDED_GR_MULTIPLY_CONST_CC_H +#define INCLUDED_GR_MULTIPLY_CONST_CC_H + +#include <gr_core_api.h> +#include <gr_sync_block.h> + +class gr_multiply_const_cc; +typedef boost::shared_ptr<gr_multiply_const_cc> gr_multiply_const_cc_sptr; + +GR_CORE_API gr_multiply_const_cc_sptr +gr_make_multiply_const_cc (gr_complex k, size_t vlen=1); + +/*! + * \brief Multiply stream of complex values with a constant \p k + * \ingroup math_blk + */ + +class GR_CORE_API gr_multiply_const_cc : public gr_sync_block +{ + private: + friend GR_CORE_API gr_multiply_const_cc_sptr + gr_make_multiply_const_cc (gr_complex k, size_t vlen); + gr_multiply_const_cc (gr_complex k, size_t vlen); + + gr_complex d_k; + size_t d_vlen; + + public: + gr_complex k() const; + void set_k(gr_complex k); + + virtual int work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); +}; + + +#endif /* INCLUDED_GR_MULTIPLY_CONST_CC_H */ diff --git a/gnuradio-core/src/lib/general/gr_multiply_const_cc.i b/gnuradio-core/src/lib/general/gr_multiply_const_cc.i new file mode 100644 index 000000000..be8d32b31 --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_multiply_const_cc.i @@ -0,0 +1,33 @@ +/* -*- c++ -*- */ +/* + * Copyright 2012 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. + */ + +GR_SWIG_BLOCK_MAGIC(gr,multiply_const_cc) + +gr_multiply_const_cc_sptr +gr_make_multiply_const_cc (gr_complex k, size_t vlen=1); + +class gr_multiply_const_cc : public gr_sync_block +{ +public: + gr_complex k() const; + void set_k(gr_complex k); +}; diff --git a/gnuradio-core/src/lib/gengen/.gitignore b/gnuradio-core/src/lib/gengen/.gitignore index ecd4cb0d5..4422ae0dd 100644 --- a/gnuradio-core/src/lib/gengen/.gitignore +++ b/gnuradio-core/src/lib/gengen/.gitignore @@ -202,12 +202,6 @@ /gr_max_ss.cc /gr_max_ss.h /gr_max_ss.i -/gr_multiply_cc.cc -/gr_multiply_cc.h -/gr_multiply_cc.i -/gr_multiply_const_cc.cc -/gr_multiply_const_cc.h -/gr_multiply_const_cc.i /gr_multiply_const_ff.cc /gr_multiply_const_ff.h /gr_multiply_const_ff.i diff --git a/gnuradio-core/src/lib/gengen/CMakeLists.txt b/gnuradio-core/src/lib/gengen/CMakeLists.txt index a7292f131..53dc9ce15 100644 --- a/gnuradio-core/src/lib/gengen/CMakeLists.txt +++ b/gnuradio-core/src/lib/gengen/CMakeLists.txt @@ -86,10 +86,10 @@ expand_h_cc_i(gr_noise_source_X s i f c) expand_h_cc_i(gr_sig_source_X s i f c) expand_h_cc_i(gr_add_const_XX ss ii ff cc sf) -expand_h_cc_i(gr_multiply_const_XX ss ii ff cc) +expand_h_cc_i(gr_multiply_const_XX ss ii ff) expand_h_cc_i(gr_add_XX ss ii ff cc) expand_h_cc_i(gr_sub_XX ss ii ff cc) -expand_h_cc_i(gr_multiply_XX ss ii ff cc) +expand_h_cc_i(gr_multiply_XX ss ii ff) expand_h_cc_i(gr_divide_XX ss ii ff cc) expand_h_cc_i(gr_mute_XX ss ii ff cc) expand_h_cc_i(gr_add_const_vXX ss ii ff cc) diff --git a/gnuradio-core/src/lib/gengen/Makefile.gen b/gnuradio-core/src/lib/gengen/Makefile.gen index 1c529803c..fb7b21e24 100644 --- a/gnuradio-core/src/lib/gengen/Makefile.gen +++ b/gnuradio-core/src/lib/gengen/Makefile.gen @@ -45,8 +45,6 @@ GENERATED_H = \ gr_moving_average_ff.h \ gr_moving_average_ii.h \ gr_moving_average_ss.h \ - gr_multiply_cc.h \ - gr_multiply_const_cc.h \ gr_multiply_const_ff.h \ gr_multiply_const_ii.h \ gr_multiply_const_ss.h \ @@ -150,8 +148,6 @@ GENERATED_I = \ gr_moving_average_ff.i \ gr_moving_average_ii.i \ gr_moving_average_ss.i \ - gr_multiply_cc.i \ - gr_multiply_const_cc.i \ gr_multiply_const_ff.i \ gr_multiply_const_ii.i \ gr_multiply_const_ss.i \ @@ -255,8 +251,6 @@ GENERATED_CC = \ gr_moving_average_ff.cc \ gr_moving_average_ii.cc \ gr_moving_average_ss.cc \ - gr_multiply_cc.cc \ - gr_multiply_const_cc.cc \ gr_multiply_const_ff.cc \ gr_multiply_const_ii.cc \ gr_multiply_const_ss.cc \ diff --git a/gnuradio-core/src/lib/gengen/generate_common.py b/gnuradio-core/src/lib/gengen/generate_common.py index 9bd6bcc9c..1c2c064c1 100755 --- a/gnuradio-core/src/lib/gengen/generate_common.py +++ b/gnuradio-core/src/lib/gengen/generate_common.py @@ -41,10 +41,8 @@ reg_signatures = ['ss', 'ii', 'ff', 'cc'] reg_roots = [ 'gr_add_const_XX', - 'gr_multiply_const_XX', 'gr_add_XX', 'gr_sub_XX', - 'gr_multiply_XX', 'gr_divide_XX', 'gr_mute_XX', 'gr_add_const_vXX', @@ -66,7 +64,9 @@ others = ( ('gr_sample_and_hold_XX', ('bb','ss','ii','ff')), ('gr_argmax_XX', ('fs','is','ss')), ('gr_max_XX', ('ff','ii','ss')), - ('gr_peak_detector_XX', ('fb','ib','sb')) + ('gr_peak_detector_XX', ('fb','ib','sb')), + ('gr_multiply_XX', ('ss','ii','ff')), + ('gr_multiply_const_XX', ('ss','ii','ff')) ) diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_add_and_friends.py b/gnuradio-core/src/python/gnuradio/gr/qa_add_and_friends.py index 8fb70fb3f..c1d8dafd1 100755 --- a/gnuradio-core/src/python/gnuradio/gr/qa_add_and_friends.py +++ b/gnuradio-core/src/python/gnuradio/gr/qa_add_and_friends.py @@ -78,6 +78,18 @@ class test_add_and_friends (gr_unittest.TestCase): op = gr.multiply_const_ii (5) self.help_ii ((src_data,), expected_result, op) + def test_mult_const_cc (self): + src_data = (-1-1j, 0+0j, 1+1j, 2+2j, 3+3j) + expected_result = (-5-5j, 0+0j, 5+5j, 10+10j, 15+15j) + op = gr.multiply_const_cc (5) + self.help_cc ((src_data,), expected_result, op) + + def test_mult_const_cc2 (self): + src_data = (-1-1j, 0+0j, 1+1j, 2+2j, 3+3j) + expected_result = (-3-7j, 0+0j, 3+7j, 6+14j, 9+21j) + op = gr.multiply_const_cc (5+2j) + self.help_cc ((src_data,), expected_result, op) + def test_add_ii (self): src1_data = (1, 2, 3, 4, 5) src2_data = (8, -3, 4, 8, 2) @@ -94,6 +106,14 @@ class test_add_and_friends (gr_unittest.TestCase): self.help_ii ((src1_data, src2_data), expected_result, op) + def test_mult_cc (self): + src1_data = (1+1j, 2+2j, 3+3j, 4+4j, 5+5j) + src2_data = (8, -3, 4, 8, 2) + expected_result = (8+8j, -6-6j, 12+12j, 32+32j, 10+10j) + op = gr.multiply_cc () + self.help_cc ((src1_data, src2_data), + expected_result, op) + def test_sub_ii_1 (self): src1_data = (1, 2, 3, 4, 5) expected_result = (-1, -2, -3, -4, -5) |