From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id 34832DE0 for ; Mon, 8 Jun 2015 12:41:41 +0200 (CEST) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga103.jf.intel.com with ESMTP; 08 Jun 2015 03:41:39 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.13,573,1427785200"; d="scan'208";a="583972353" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by orsmga003.jf.intel.com with ESMTP; 08 Jun 2015 03:41:37 -0700 Received: from sivswdev02.ir.intel.com (sivswdev02.ir.intel.com [10.237.217.46]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id t58AfbWe029639; Mon, 8 Jun 2015 11:41:37 +0100 Received: from sivswdev02.ir.intel.com (localhost [127.0.0.1]) by sivswdev02.ir.intel.com with ESMTP id t58AfbPu017580; Mon, 8 Jun 2015 11:41:37 +0100 Received: (from kananye1@localhost) by sivswdev02.ir.intel.com with id t58AfbwA017575; Mon, 8 Jun 2015 11:41:37 +0100 From: Konstantin Ananyev To: dev@dpdk.org Date: Mon, 8 Jun 2015 11:41:27 +0100 Message-Id: <1433760090-17110-6-git-send-email-konstantin.ananyev@intel.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1433760090-17110-1-git-send-email-konstantin.ananyev@intel.com> References: <1433373024-5558-2-git-send-email-konstantin.ananyev@intel.com> <1433760090-17110-1-git-send-email-konstantin.ananyev@intel.com> Subject: [dpdk-dev] [PATCHv2 5/8] acl: code dedup - introduce a new macro X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 08 Jun 2015 10:41:41 -0000 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 --- 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 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. */ -- 2.4.2