summaryrefslogtreecommitdiffstats
path: root/src/common
diff options
context:
space:
mode:
authorHanoh Haim <hhaim@cisco.com>2016-12-07 15:24:38 +0200
committerHanoh Haim <hhaim@cisco.com>2016-12-21 13:01:05 +0200
commiteae78d4356b8834b78a91c52d869a7949f8f3e90 (patch)
tree184156f8e653adfa33eb0e70838f45d2a92355d0 /src/common
parent539de1c6af63071c1da9ed5db668c500f8993a03 (diff)
improve Stateful scheduler
Signed-off-by: Hanoh Haim <hhaim@cisco.com>
Diffstat (limited to 'src/common')
-rwxr-xr-xsrc/common/basic_utils.h51
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