summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gnuradio-core/src/lib/runtime/gr_block.cc76
-rw-r--r--gnuradio-core/src/lib/runtime/gr_block.h46
-rw-r--r--gnuradio-core/src/lib/runtime/gr_sync_block.cc14
-rw-r--r--gnuradio-core/src/lib/runtime/gr_sync_block.h14
4 files changed, 71 insertions, 79 deletions
diff --git a/gnuradio-core/src/lib/runtime/gr_block.cc b/gnuradio-core/src/lib/runtime/gr_block.cc
index 53d9d20c4..c243ff8d6 100644
--- a/gnuradio-core/src/lib/runtime/gr_block.cc
+++ b/gnuradio-core/src/lib/runtime/gr_block.cc
@@ -122,37 +122,29 @@ void gr_block::work(
//------------------------------------------------------------------
//-- initialize input buffers before work
//------------------------------------------------------------------
- size_t num_input_items = REALLY_BIG; //so big that it must std::min
+ size_t num_input_items = input_items.min();
+ if (_enable_fixed_rate) num_input_items -= _input_history_items;
for (size_t i = 0; i < num_inputs; i++)
{
_work_ninput_items[i] = input_items[i].size();
_work_input_items[i] = input_items[i].get();
_work_io_ptr_mask |= ptrdiff_t(_work_input_items[i]);
- size_t items = input_items[i].size();
- if (_enable_fixed_rate)
+ if GRAS_UNLIKELY(_enable_fixed_rate and input_items[i].size() <= _input_history_items)
{
- if (items <= _input_history_items)
- {
- return this->mark_input_fail(i);
- }
- items -= _input_history_items;
+ return this->mark_input_fail(i);
}
-
- num_input_items = std::min(num_input_items, items);
}
//------------------------------------------------------------------
//-- initialize output buffers before work
//------------------------------------------------------------------
- size_t num_output_items = REALLY_BIG; //so big that it must std::min
+ size_t num_output_items = output_items.min();
+ num_output_items /= _output_multiple_items;
+ num_output_items *= _output_multiple_items;
for (size_t i = 0; i < num_outputs; i++)
{
_work_output_items[i] = output_items[i].get();
_work_io_ptr_mask |= ptrdiff_t(_work_output_items[i]);
- size_t items = output_items[i].size();
- items /= _output_multiple_items;
- items *= _output_multiple_items;
- num_output_items = std::min(num_output_items, items);
}
//------------------------------------------------------------------
@@ -182,10 +174,10 @@ void gr_block::work(
this->forecast(work_noutput_items, _fcast_ninput_items);
for (size_t i = 0; i < input_items.size(); i++)
{
- if (_fcast_ninput_items[i] <= _work_ninput_items[i]) continue;
+ if GRAS_LIKELY(_fcast_ninput_items[i] <= _work_ninput_items[i]) continue;
//handle the case of forecast failing
- if (work_noutput_items <= _output_multiple_items)
+ if GRAS_UNLIKELY(work_noutput_items <= _output_multiple_items)
{
return this->mark_input_fail(i);
}
@@ -205,12 +197,12 @@ void gr_block::work(
_work_output_items
);
- if (work_ret > 0) for (size_t i = 0; i < num_outputs; i++)
+ if GRAS_LIKELY(work_ret > 0) for (size_t i = 0; i < num_outputs; i++)
{
this->produce(i, work_ret);
}
- if (work_ret == -1) this->mark_done();
+ if GRAS_UNLIKELY(work_ret == -1) this->mark_done();
}
static inline unsigned long long myullround(const double x)
@@ -265,34 +257,6 @@ int gr_block::general_work(
throw std::runtime_error("gr_block subclasses must overload general_work!");
}
-void gr_block::consume_each(const int how_many_items)
-{
- if (how_many_items < 0) return;
- gras::Block::consume(size_t(how_many_items));
-}
-
-void gr_block::consume(const size_t i, const int how_many_items)
-{
- if (how_many_items < 0) return;
- gras::Block::consume(i, size_t(how_many_items));
-}
-
-void gr_block::produce(const size_t o, const int how_many_items)
-{
- if (how_many_items < 0) return;
- gras::Block::produce(o, size_t(how_many_items));
-}
-
-uint64_t gr_block::nitems_read(const size_t which_input)
-{
- return Block::get_consumed(which_input);
-}
-
-uint64_t gr_block::nitems_written(const size_t which_output)
-{
- return Block::get_produced(which_output);
-}
-
void gr_block::set_alignment(const size_t)
{
//TODO
@@ -300,24 +264,11 @@ void gr_block::set_alignment(const size_t)
//and therefore alignment is always re-acheived
}
-bool gr_block::is_unaligned(void)
-{
- //TODO
- //probably dont need this since volk dispatcher checks alignment
- //32 byte aligned is good enough for you
- return (_work_io_ptr_mask & ptrdiff_t(GRAS_MAX_ALIGNMENT-1)) != 0;
-}
-
size_t gr_block::fixed_rate_noutput_to_ninput(const size_t noutput_items)
{
return ((decimation()*noutput_items)/interpolation()) + _input_history_items;
}
-size_t gr_block::interpolation(void) const
-{
- return _interp;
-}
-
void gr_block::set_interpolation(const size_t interp)
{
_interp = interp;
@@ -325,11 +276,6 @@ void gr_block::set_interpolation(const size_t interp)
this->set_output_multiple(interp);
}
-size_t gr_block::decimation(void) const
-{
- return _decim;
-}
-
void gr_block::set_decimation(const size_t decim)
{
_decim = decim;
diff --git a/gnuradio-core/src/lib/runtime/gr_block.h b/gnuradio-core/src/lib/runtime/gr_block.h
index c3898a5c0..44faa313a 100644
--- a/gnuradio-core/src/lib/runtime/gr_block.h
+++ b/gnuradio-core/src/lib/runtime/gr_block.h
@@ -388,4 +388,50 @@ struct GR_CORE_API gr_block : gras::Block
typedef boost::shared_ptr<gr_block> gr_block_sptr;
+GRAS_FORCE_INLINE void gr_block::consume_each(const int how_many_items)
+{
+ if GRAS_UNLIKELY(how_many_items < 0) return;
+ gras::Block::consume(size_t(how_many_items));
+}
+
+GRAS_FORCE_INLINE void gr_block::consume(const size_t i, const int how_many_items)
+{
+ if GRAS_UNLIKELY(how_many_items < 0) return;
+ gras::Block::consume(i, size_t(how_many_items));
+}
+
+GRAS_FORCE_INLINE void gr_block::produce(const size_t o, const int how_many_items)
+{
+ if GRAS_UNLIKELY(how_many_items < 0) return;
+ gras::Block::produce(o, size_t(how_many_items));
+}
+
+GRAS_FORCE_INLINE uint64_t gr_block::nitems_read(const size_t which_input)
+{
+ return Block::get_consumed(which_input);
+}
+
+GRAS_FORCE_INLINE uint64_t gr_block::nitems_written(const size_t which_output)
+{
+ return Block::get_produced(which_output);
+}
+
+GRAS_FORCE_INLINE size_t gr_block::interpolation(void) const
+{
+ return _interp;
+}
+
+GRAS_FORCE_INLINE size_t gr_block::decimation(void) const
+{
+ return _decim;
+}
+
+GRAS_FORCE_INLINE bool gr_block::is_unaligned(void)
+{
+ //TODO
+ //probably dont need this since volk dispatcher checks alignment
+ //32 byte aligned is good enough for you
+ return (_work_io_ptr_mask & ptrdiff_t(GRAS_MAX_ALIGNMENT-1)) != 0;
+}
+
#endif /*INCLUDED_GNURADIO_GR_BLOCK_H*/
diff --git a/gnuradio-core/src/lib/runtime/gr_sync_block.cc b/gnuradio-core/src/lib/runtime/gr_sync_block.cc
index 96b5e6253..3c79e630d 100644
--- a/gnuradio-core/src/lib/runtime/gr_sync_block.cc
+++ b/gnuradio-core/src/lib/runtime/gr_sync_block.cc
@@ -53,17 +53,3 @@ int gr_sync_block::work(
){
throw std::runtime_error("gr_block subclasses must overload general_work!");
}
-
-int gr_sync_block::general_work(
- int noutput_items,
- gr_vector_int &ninput_items,
- gr_vector_const_void_star &input_items,
- gr_vector_void_star &output_items
-){
- const int work_ret = this->work(noutput_items, input_items, output_items);
- if (work_ret > 0)
- {
- this->consume_each((decimation()*size_t(work_ret))/interpolation());
- }
- return work_ret;
-}
diff --git a/gnuradio-core/src/lib/runtime/gr_sync_block.h b/gnuradio-core/src/lib/runtime/gr_sync_block.h
index 90370dd2b..1d2aef802 100644
--- a/gnuradio-core/src/lib/runtime/gr_sync_block.h
+++ b/gnuradio-core/src/lib/runtime/gr_sync_block.h
@@ -52,4 +52,18 @@ struct GR_CORE_API gr_sync_block : public gr_block
};
+GRAS_FORCE_INLINE int gr_sync_block::general_work(
+ int noutput_items,
+ gr_vector_int &ninput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items
+){
+ const int work_ret = this->work(noutput_items, input_items, output_items);
+ if (work_ret > 0)
+ {
+ this->consume_each((decimation()*size_t(work_ret))/interpolation());
+ }
+ return work_ret;
+}
+
#endif /*INCLUDED_GNURADIO_GR_SYNC_BLOCK_H*/