From 6c145193a955cfd6295b11bed3cc7cc9828feb9c Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Fri, 4 Feb 2011 22:49:23 -0800 Subject: uhd: various performance tweaks --- host/lib/types/time_spec.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'host/lib/types') diff --git a/host/lib/types/time_spec.cpp b/host/lib/types/time_spec.cpp index ece3b92f3..4a41f0fb9 100644 --- a/host/lib/types/time_spec.cpp +++ b/host/lib/types/time_spec.cpp @@ -99,7 +99,7 @@ time_spec_t::time_spec_t(time_t full_secs, double frac_secs): time_spec_t::time_spec_t(time_t full_secs, long tick_count, double tick_rate): _full_secs(full_secs), - _frac_secs(double(tick_count)/tick_rate) + _frac_secs(tick_count/tick_rate) { /* NOP */ } @@ -116,13 +116,11 @@ double time_spec_t::get_real_secs(void) const{ } time_t time_spec_t::get_full_secs(void) const{ - double intpart; - std::modf(this->_frac_secs, &intpart); - return this->_full_secs + time_t(intpart); + return this->_full_secs + time_t(this->_frac_secs); } double time_spec_t::get_frac_secs(void) const{ - return std::fmod(this->_frac_secs, 1.0); + return this->_frac_secs - time_t(this->_frac_secs); } /*********************************************************************** -- cgit v1.2.3 From 3e7284014cb04bc66ae50004267aed4e4ada2d14 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 10 Feb 2011 19:01:32 -0800 Subject: uhd: misc speedups w/ look up tables use a look up table for io type size (in the case its used in the fast-path) move the static const pred table in vrt unpacker to the global level, for some reason this was incurring a malloc (perhaps because there were 2 tables). --- host/lib/transport/gen_vrt_if_packet.py | 3 ++- host/lib/types/types.cpp | 19 ++++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) (limited to 'host/lib/types') diff --git a/host/lib/transport/gen_vrt_if_packet.py b/host/lib/transport/gen_vrt_if_packet.py index 3ba562d68..427217eb6 100755 --- a/host/lib/transport/gen_vrt_if_packet.py +++ b/host/lib/transport/gen_vrt_if_packet.py @@ -66,6 +66,8 @@ static pred_table_type get_pred_unpack_table(void){ return table; } +static const pred_table_type pred_unpack_table(get_pred_unpack_table()); + ######################################################################## #def gen_code($XE_MACRO, $suffix) ######################################################################## @@ -168,7 +170,6 @@ void vrt::if_hdr_unpack_$(suffix)( //if_packet_info.sob = bool(vrt_hdr_word & $hex(0x1 << 25)); //not implemented //if_packet_info.eob = bool(vrt_hdr_word & $hex(0x1 << 24)); //not implemented - static const pred_table_type pred_unpack_table(get_pred_unpack_table()); const pred_type pred = pred_unpack_table[pred_table_index(vrt_hdr_word)]; switch(pred){ diff --git a/host/lib/types/types.cpp b/host/lib/types/types.cpp index c1be2ff6d..bf308a0b3 100644 --- a/host/lib/types/types.cpp +++ b/host/lib/types/types.cpp @@ -22,6 +22,7 @@ #include #include #include +#include using namespace uhd; @@ -66,14 +67,18 @@ otw_type_t::otw_type_t(void): /*********************************************************************** * io type **********************************************************************/ +static std::vector get_tid_size_table(void){ + std::vector table(128, 0); + table[size_t(io_type_t::COMPLEX_FLOAT64)] = sizeof(std::complex); + table[size_t(io_type_t::COMPLEX_FLOAT32)] = sizeof(std::complex); + table[size_t(io_type_t::COMPLEX_INT16)] = sizeof(std::complex); + table[size_t(io_type_t::COMPLEX_INT8)] = sizeof(std::complex); + return table; +} + static size_t tid_to_size(io_type_t::tid_t tid){ - switch(tid){ - case io_type_t::COMPLEX_FLOAT64: return sizeof(std::complex); - case io_type_t::COMPLEX_FLOAT32: return sizeof(std::complex); - case io_type_t::COMPLEX_INT16: return sizeof(std::complex); - case io_type_t::COMPLEX_INT8: return sizeof(std::complex); - default: throw std::runtime_error("unknown io type tid"); - } + static const std::vector size_table(get_tid_size_table()); + return size_table[size_t(tid) & 0x7f]; } io_type_t::io_type_t(tid_t tid) -- cgit v1.2.3 From 68e4a34d4381ad4d75f1c75ee67a23c95d747986 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Fri, 11 Feb 2011 10:05:37 -0800 Subject: uhd: tweak for io type size table code --- host/lib/types/types.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'host/lib/types') diff --git a/host/lib/types/types.cpp b/host/lib/types/types.cpp index bf308a0b3..7c65d2997 100644 --- a/host/lib/types/types.cpp +++ b/host/lib/types/types.cpp @@ -76,17 +76,16 @@ static std::vector get_tid_size_table(void){ return table; } -static size_t tid_to_size(io_type_t::tid_t tid){ - static const std::vector size_table(get_tid_size_table()); - return size_table[size_t(tid) & 0x7f]; -} +static const std::vector tid_size_table(get_tid_size_table()); -io_type_t::io_type_t(tid_t tid) -: size(tid_to_size(tid)), tid(tid){ +io_type_t::io_type_t(tid_t tid): + size(tid_size_table[size_t(tid) & 0x7f]), tid(tid) +{ /* NOP */ } -io_type_t::io_type_t(size_t size) -: size(size), tid(CUSTOM_TYPE){ +io_type_t::io_type_t(size_t size): + size(size), tid(CUSTOM_TYPE) +{ /* NOP */ } -- cgit v1.2.3 From 4613f454c781d258d6d9b210ff1b9043a2125981 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Fri, 11 Feb 2011 21:52:13 -0800 Subject: uhd: added to_ calls to sensors to make it easy --- host/include/uhd/types/sensors.hpp | 19 +++++++++++-------- host/include/uhd/usrp/multi_usrp.hpp | 7 +++---- host/lib/types/sensors.cpp | 17 +++++++++++++++-- 3 files changed, 29 insertions(+), 14 deletions(-) (limited to 'host/lib/types') diff --git a/host/include/uhd/types/sensors.hpp b/host/include/uhd/types/sensors.hpp index 6f003bb40..b6215367f 100644 --- a/host/include/uhd/types/sensors.hpp +++ b/host/include/uhd/types/sensors.hpp @@ -37,12 +37,6 @@ namespace uhd{ */ struct UHD_API sensor_value_t{ - //! typedef for the signed integer type - typedef signed int_type; - - //! typedef for the real number type - typedef double real_type; - /*! * Create a sensor value from a boolean. * \param name the name of the sensor @@ -66,7 +60,7 @@ namespace uhd{ */ sensor_value_t( const std::string &name, - int_type value, + signed value, const std::string &unit, const std::string &formatter = "%d" ); @@ -80,7 +74,7 @@ namespace uhd{ */ sensor_value_t( const std::string &name, - real_type value, + double value, const std::string &unit, const std::string &formatter = "%f" ); @@ -97,6 +91,15 @@ namespace uhd{ const std::string &unit ); + //! convert the sensor value to a boolean + bool to_bool(void) const; + + //! convert the sensor value to an integer + signed to_int(void) const; + + //! convert the sensor value to real number + double to_real(void) const; + //! The name of the sensor value const std::string name; diff --git a/host/include/uhd/usrp/multi_usrp.hpp b/host/include/uhd/usrp/multi_usrp.hpp index da52e6dce..3c8dd5fac 100644 --- a/host/include/uhd/usrp/multi_usrp.hpp +++ b/host/include/uhd/usrp/multi_usrp.hpp @@ -28,7 +28,6 @@ #include #include #include -#include //needed until deprecated routines removed #include #include #include @@ -395,7 +394,7 @@ public: * \return true for locked */ UHD_DEPRECATED bool get_rx_lo_locked(size_t chan = 0){ - return this->get_rx_sensor("lo_locked", chan).value == "true"; + return this->get_rx_sensor("lo_locked", chan).to_bool(); } /*! @@ -419,7 +418,7 @@ public: * \throw exception if RSSI readback not supported */ UHD_DEPRECATED double read_rssi(size_t chan = 0){ - return boost::lexical_cast(this->get_rx_sensor("rssi", chan).value); + return this->get_rx_sensor("rssi", chan).to_real(); } /*! @@ -593,7 +592,7 @@ public: * \return true for locked */ UHD_DEPRECATED bool get_tx_lo_locked(size_t chan = 0){ - return this->get_tx_sensor("lo_locked", chan).value == "true"; + return this->get_tx_sensor("lo_locked", chan).to_bool(); } /*! diff --git a/host/lib/types/sensors.cpp b/host/lib/types/sensors.cpp index 2bff136a4..5f7115d70 100644 --- a/host/lib/types/sensors.cpp +++ b/host/lib/types/sensors.cpp @@ -17,6 +17,7 @@ #include #include +#include #include using namespace uhd; @@ -35,7 +36,7 @@ sensor_value_t::sensor_value_t( sensor_value_t::sensor_value_t( const std::string &name, - int_type value, + signed value, const std::string &unit, const std::string &formatter ): @@ -47,7 +48,7 @@ sensor_value_t::sensor_value_t( sensor_value_t::sensor_value_t( const std::string &name, - real_type value, + double value, const std::string &unit, const std::string &formatter ): @@ -79,3 +80,15 @@ std::string sensor_value_t::to_pp_string(void) const{ } UHD_THROW_INVALID_CODE_PATH(); } + +bool sensor_value_t::to_bool(void) const{ + return value == "true"; +} + +signed sensor_value_t::to_int(void) const{ + return boost::lexical_cast(value); +} + +double sensor_value_t::to_real(void) const{ + return boost::lexical_cast(value); +} -- cgit v1.2.3