summaryrefslogtreecommitdiff
path: root/lib/librte_acl
diff options
context:
space:
mode:
authorKonstantin Ananyev <konstantin.ananyev@intel.com>2015-06-08 11:41:27 +0100
committerThomas Monjalon <thomas.monjalon@6wind.com>2015-06-18 18:08:34 +0200
commitcd40cd919540489e9da57863ac88136a89ac8759 (patch)
tree74eace9933b801de224ecb3e0e6da213db36519a /lib/librte_acl
parent4a6ce751ace3708ed33248582cf24f808933e957 (diff)
downloaddpdk-cd40cd919540489e9da57863ac88136a89ac8759.zip
dpdk-cd40cd919540489e9da57863ac88136a89ac8759.tar.gz
dpdk-cd40cd919540489e9da57863ac88136a89ac8759.tar.xz
acl: introduce a macro for bitmask conversion
Introduce new RTE_ACL_MASKLEN_TO_BITMASK macro, that will be used in several places inside librte_acl and it's UT. Simplify and cleanup build_trie() code a bit. Signed-off-by: Konstantin Ananyev <konstantin.ananyev@intel.com>
Diffstat (limited to 'lib/librte_acl')
-rw-r--r--lib/librte_acl/acl_bld.c16
-rw-r--r--lib/librte_acl/rte_acl.h3
2 files changed, 6 insertions, 13 deletions
diff --git a/lib/librte_acl/acl_bld.c b/lib/librte_acl/acl_bld.c
index d89c66a..4d8a62f 100644
--- a/lib/librte_acl/acl_bld.c
+++ b/lib/librte_acl/acl_bld.c
@@ -1262,19 +1262,9 @@ build_trie(struct acl_build_context *context, struct rte_acl_build_rule *head,
* all higher bits.
*/
uint64_t mask;
-
- if (fld->mask_range.u32 == 0) {
- mask = 0;
-
- /*
- * arithmetic right shift for the length of
- * the mask less the msb.
- */
- } else {
- mask = -1 <<
- (rule->config->defs[n].size *
- CHAR_BIT - fld->mask_range.u32);
- }
+ mask = RTE_ACL_MASKLEN_TO_BITMASK(
+ fld->mask_range.u32,
+ rule->config->defs[n].size);
/* gen a mini-trie for this field */
merge = acl_gen_mask_trie(context,
diff --git a/lib/librte_acl/rte_acl.h b/lib/librte_acl/rte_acl.h
index 8d9bbe5..bd8f892 100644
--- a/lib/librte_acl/rte_acl.h
+++ b/lib/librte_acl/rte_acl.h
@@ -122,6 +122,9 @@ enum {
#define RTE_ACL_INVALID_USERDATA 0
+#define RTE_ACL_MASKLEN_TO_BITMASK(v, s) \
+((v) == 0 ? (v) : (typeof(v))((uint64_t)-1 << ((s) * CHAR_BIT - (v))))
+
/**
* Miscellaneous data for ACL rule.
*/