From mboxrd@z Thu Jan 1 00:00:00 1970 From: Konstantin Ananyev Subject: [PATCH 5/8] ACL: introduce RTE_ACL_MASKLEN_TO_BITMASK macro Date: Thu, 4 Jun 2015 00:10:21 +0100 Message-ID: <1433373024-5558-6-git-send-email-konstantin.ananyev@intel.com> References: <1433373024-5558-1-git-send-email-konstantin.ananyev@intel.com> To: dev@dpdk.org Return-path: Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id 6A2E55A8B for ; Thu, 4 Jun 2015 01:10:30 +0200 (CEST) In-Reply-To: <1433373024-5558-1-git-send-email-konstantin.ananyev@intel.com> List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Introduce new RTE_ACL_MASKLEN_TO_BITMASK macro, that will be used in several places inside librte_acl and it's UT. Simplify iand cleanup build_trie() code a bit. Signed-off-by: Konstantin Ananyev --- lib/librte_acl/acl_bld.c | 16 +++------------- lib/librte_acl/rte_acl.h | 3 +++ 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/lib/librte_acl/acl_bld.c b/lib/librte_acl/acl_bld.c index 4bcf637..e144503 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. */ -- 1.8.5.3