diff options
Diffstat (limited to 'src/common')
-rwxr-xr-x | src/common/basic_utils.h | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/common/basic_utils.h b/src/common/basic_utils.h index 36f9db85..b715c4b7 100755 --- a/src/common/basic_utils.h +++ b/src/common/basic_utils.h @@ -22,6 +22,57 @@ limitations under the License. #include <string> /** + * return true if number of log2 + * + * @param num + * + * @return + */ +inline bool utl_islog2(uint32_t num){ + uint32_t mask=1; + int i; + for (i=0; i<31; i++) { + if (mask == num) { + return (true); + } + if (mask > num) { + return(false); + } + mask=mask<<1; + } + return (false); +} + +inline uint32_t utl_log2_shift(uint32_t num){ + uint32_t mask=1; + int i; + for (i=0; i<31; i++) { + if (mask == num) { + return ((uint32_t)i); + } + if (mask > num) { + return(false); + } + mask=mask<<1; + } + assert(0); + return (-1); +} + + +/** + * return mask for log2 number + * + * @param num + * + * @return + */ +inline uint32_t utl_mask_log2(uint32_t num){ + return (num-1); +} + + +/** * the round must be power 2 e.g 2,4,8... * * @param num |