diff options
author | Hanoh Haim <hhaim@cisco.com> | 2016-12-07 15:24:38 +0200 |
---|---|---|
committer | Hanoh Haim <hhaim@cisco.com> | 2016-12-21 13:01:05 +0200 |
commit | eae78d4356b8834b78a91c52d869a7949f8f3e90 (patch) | |
tree | 184156f8e653adfa33eb0e70838f45d2a92355d0 /src/common | |
parent | 539de1c6af63071c1da9ed5db668c500f8993a03 (diff) |
improve Stateful scheduler
Signed-off-by: Hanoh Haim <hhaim@cisco.com>
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 |