diff options
author | Martin Braun <martin.braun@ettus.com> | 2018-07-10 22:24:49 -0700 |
---|---|---|
committer | Martin Braun <martin.braun@ettus.com> | 2018-07-11 10:11:28 -0700 |
commit | b185c9447a4a33bff14fd697dc294b9ee5d298b3 (patch) | |
tree | bda446edfd03f0b32d12fbbc121597bfdf7487c6 /host/include | |
parent | 826279754529f76a0eb617cf02ade75a4145904f (diff) | |
download | uhd-b185c9447a4a33bff14fd697dc294b9ee5d298b3.tar.gz uhd-b185c9447a4a33bff14fd697dc294b9ee5d298b3.tar.bz2 uhd-b185c9447a4a33bff14fd697dc294b9ee5d298b3.zip |
soft_register: Remove compiler warning, add unit test
Diffstat (limited to 'host/include')
-rw-r--r-- | host/include/uhd/utils/soft_register.hpp | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/host/include/uhd/utils/soft_register.hpp b/host/include/uhd/utils/soft_register.hpp index ac6ad4b35..fea4c0791 100644 --- a/host/include/uhd/utils/soft_register.hpp +++ b/host/include/uhd/utils/soft_register.hpp @@ -85,14 +85,16 @@ namespace soft_reg_field { template<typename data_t> UHD_INLINE data_t mask(const soft_reg_field_t field) { - static const data_t ONE = static_cast<data_t>(1); + constexpr data_t ONE = static_cast<data_t>(1); + constexpr data_t ALL_ONES = ~static_cast<data_t>(0); //Behavior for the left shift operation is undefined in C++ //if the shift amount is >= bitwidth of the datatype //So we treat that as a special case with a branch predicition hint - if (likely((sizeof(data_t)*8) != width(field))) + if (likely((sizeof(data_t)*8) != width(field))) { return ((ONE<<width(field))-ONE)<<shift(field); - else - return (0-ONE)<<shift(field); + } else { + return ALL_ONES<<shift(field); + } } } |