From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <xiaoyun.li@intel.com>
Received: from mga09.intel.com (mga09.intel.com [134.134.136.24])
 by dpdk.org (Postfix) with ESMTP id 2BE5B7D63
 for <dev@dpdk.org>; Fri, 25 Aug 2017 04:07:09 +0200 (CEST)
Received: from fmsmga001.fm.intel.com ([10.253.24.23])
 by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384;
 24 Aug 2017 19:07:08 -0700
X-ExtLoop1: 1
X-IronPort-AV: E=Sophos;i="5.41,423,1498546800"; d="scan'208";a="1187946334"
Received: from dpdk-lixiaoyun.sh.intel.com ([10.67.111.119])
 by fmsmga001.fm.intel.com with ESMTP; 24 Aug 2017 19:07:07 -0700
From: Xiaoyun Li <xiaoyun.li@intel.com>
To: bruce.richardson@intel.com
Cc: dev@dpdk.org, wenzhuo.lu@intel.com, zhihong.wang@intel.com,
 qi.z.zhang@intel.com, Xiaoyun Li <xiaoyun.li@intel.com>
Date: Fri, 25 Aug 2017 10:06:13 +0800
Message-Id: <1503626773-184682-4-git-send-email-xiaoyun.li@intel.com>
X-Mailer: git-send-email 2.7.4
In-Reply-To: <1503626773-184682-1-git-send-email-xiaoyun.li@intel.com>
References: <1503626773-184682-1-git-send-email-xiaoyun.li@intel.com>
Subject: [dpdk-dev] [PATCH 3/3] efd: run-time dispatch over x86 EFD functions
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <http://dpdk.org/ml/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://dpdk.org/ml/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <http://dpdk.org/ml/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
X-List-Received-Date: Fri, 25 Aug 2017 02:07:09 -0000

This patch dynamically selects x86 EFD functions at run-time.
This patch uses function pointer and binds it to the relative
function based on CPU flags at constructor time.

Signed-off-by: Xiaoyun Li <xiaoyun.li@intel.com>
---
 lib/librte_efd/rte_efd_x86.h | 35 ++++++++++++++++++++++++++++++++---
 1 file changed, 32 insertions(+), 3 deletions(-)

diff --git a/lib/librte_efd/rte_efd_x86.h b/lib/librte_efd/rte_efd_x86.h
index 34f37d7..9b632bb 100644
--- a/lib/librte_efd/rte_efd_x86.h
+++ b/lib/librte_efd/rte_efd_x86.h
@@ -43,12 +43,28 @@
 #define EFD_LOAD_SI128(val) _mm_lddqu_si128(val)
 #endif
 
+typedef efd_value_t
+(*efd_lookup_internal_avx2_t)(const efd_hashfunc_t *group_hash_idx,
+		const efd_lookuptbl_t *group_lookup_table,
+		const uint32_t hash_val_a, const uint32_t hash_val_b);
+
+static efd_lookup_internal_avx2_t efd_lookup_internal_avx2_ptr;
+
 static inline efd_value_t
 efd_lookup_internal_avx2(const efd_hashfunc_t *group_hash_idx,
 		const efd_lookuptbl_t *group_lookup_table,
 		const uint32_t hash_val_a, const uint32_t hash_val_b)
 {
-#ifdef RTE_MACHINE_CPUFLAG_AVX2
+	return (*efd_lookup_internal_avx2_ptr)(group_hash_idx,
+					       group_lookup_table,
+					       hash_val_a, hash_val_b);
+}
+
+static inline efd_value_t
+efd_lookup_internal_avx2_AVX2(const efd_hashfunc_t *group_hash_idx,
+		const efd_lookuptbl_t *group_lookup_table,
+		const uint32_t hash_val_a, const uint32_t hash_val_b)
+{
 	efd_value_t value = 0;
 	uint32_t i = 0;
 	__m256i vhash_val_a = _mm256_set1_epi32(hash_val_a);
@@ -74,13 +90,26 @@ efd_lookup_internal_avx2(const efd_hashfunc_t *group_hash_idx,
 	}
 
 	return value;
-#else
+}
+
+static inline efd_value_t
+efd_lookup_internal_avx2_DEFAULT(const efd_hashfunc_t *group_hash_idx,
+		const efd_lookuptbl_t *group_lookup_table,
+		const uint32_t hash_val_a, const uint32_t hash_val_b)
+{
 	RTE_SET_USED(group_hash_idx);
 	RTE_SET_USED(group_lookup_table);
 	RTE_SET_USED(hash_val_a);
 	RTE_SET_USED(hash_val_b);
 	/* Return dummy value, only to avoid compilation breakage */
 	return 0;
-#endif
+}
 
+static void __attribute__((constructor))
+rte_efd_x86_init(void)
+{
+	if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX2))
+		efd_lookup_internal_avx2_ptr = efd_lookup_internal_avx2_AVX2;
+	else
+		efd_lookup_internal_avx2_ptr = efd_lookup_internal_avx2_DEFAULT;
 }
-- 
2.7.4