From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from emea01-db3-obe.outbound.protection.outlook.com (mail-db3on0077.outbound.protection.outlook.com [157.55.234.77]) by dpdk.org (Postfix) with ESMTP id 534E1255 for ; Fri, 17 Jul 2015 16:42:25 +0200 (CEST) Authentication-Results: dpdk.org; dkim=none (message not signed) header.d=none; Received: from zhigangTHINK (123.120.121.217) by DB5PR02MB0806.eurprd02.prod.outlook.com (10.161.243.152) with Microsoft SMTP Server (TLS) id 15.1.219.17; Fri, 17 Jul 2015 14:42:21 +0000 From: Tony Lu To: 'Pablo de Lara' , References: <1437124678-24915-1-git-send-email-pablo.de.lara.guarch@intel.com> In-Reply-To: <1437124678-24915-1-git-send-email-pablo.de.lara.guarch@intel.com> Date: Fri, 17 Jul 2015 22:41:59 +0800 Message-ID: <001501d0c09e$cf739a50$6e5acef0$@com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook 12.0 Thread-Index: AdDAcX6BSJe7RQrhQ2+XCoNBYyAhXAALOkrw Content-Language: zh-cn X-Originating-IP: [123.120.121.217] X-ClientProxiedBy: SG2PR06CA0025.apcprd06.prod.outlook.com (25.163.105.35) To DB5PR02MB0806.eurprd02.prod.outlook.com (25.161.243.152) X-Microsoft-Exchange-Diagnostics: 1; DB5PR02MB0806; 2:VmjwvbnzEvHX0Mh7YlQDjigVPHFyq2rG6P9mdiiNNLSVsMq+PYWJjasMwYXglwyv; 3:YuZUb+tH0+pGIuWeYnvznUC5WM0zr/xinK4o0KziPniTXV2U7v8PVmODyY6QqZ9SUmCCOw3smmZLKhMctggYJqIKQcro41pgbfCt2FKy3jr1PcSSTx0EehTIggHREmaYsu/9FwXL588Kwqocr0mkVg==; 25:lEI8xqS1BM/sc1rDD9z7PzEyi04+wniIHR8LpCrH/hWWEHi+K7S4TaaGxHxQBRlAiOfRam6r0Bis1juv95iivVbC3eCLCpr7bv5g6Ih7Ov3z3ke1b6S7e5sbAISTspzp8bqW1t3kluxBDdDU1ickBr/jKGvmGRw69gumdpgxg8CNtfC76BkFdCPWDj3vrP+NnBsj913o1lkk0sv1IccKZHcAEy3/Xho089F8S9JGykLDHufvaDHj3nOqAe9vDqZW; 20:k60BGSziyKLl+CYBmvj3OYhZe/Q5qzHcrslfEglqw9yXm/nSHJpCAa+rNDWkarxCVdhP4xSm0fEb5n8sfEfTLraiv79OsVcazAsmhDMiGp6sKTwvnInZtdS3bZ2fMEU0GiS4J39lfsmp/tUrQqXxpr44cShU2DKPPxGPt2p4geU=; 4:yPco+RxlK3HJzHb+y5+wbmMQpVOa8AchvTc99lUpO4pD1VLSOw5DXsg19aKhXa80BltuZdUlARw0iXno7U2BQZxaY0UmqRfs30gtE5NY92A2/K69WmvE62v/k30El1mddIw9bpLjiV/26Lfv+/e3dvkIVeq8EKWh3LL6L74pN3QWNQeA0cPaqrrsyzGPYRuIo0Z+e+nt5eDS1N0TMZHSYT7PhKwkgAm/vthRJ59uyn020+Czmpwm4xHyQIhSc0MjP83GFmVVvRFizH/5KQPBC7kJ9L2JjBlWfnjNMqzoHwQ= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:DB5PR02MB0806; DB5PR02MB0806: X-MS-Exchange-Organization-RulesExecuted X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(5005006)(3002001); SRVR:DB5PR02MB0806; BCL:0; PCL:0; RULEID:; SRVR:DB5PR02MB0806; X-Forefront-PRVS: 06400060E1 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6009001)(377454003)(13464003)(59696002)(66066001)(61296003)(19580395003)(86362001)(107886002)(50226001)(62966003)(33716001)(189998001)(50466002)(47776003)(5001960100002)(23726002)(42186005)(14726001)(97756001)(40100003)(96836002)(19580405001)(2950100001)(84116002)(46406003)(77156002)(92566002)(2656002)(76176999)(5001920100001)(50986999)(5001770100001)(46102003)(122386002)(102836002)(33646002)(77096005)(7099028); DIR:OUT; SFP:1101; SCL:1; SRVR:DB5PR02MB0806; H:zhigangTHINK; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DB5PR02MB0806; 23:2zHtwkAXpnc3n7w4kVwCnbntQ9s4KYsyeMs+35fhR?= =?us-ascii?Q?A35WSW4G1gOqvvfsXeI1N97W7Oul7mQsz+OD3w44AITeqF0yixVB2IelvLwk?= =?us-ascii?Q?wEwN/CGcYqkUGliVW2HiaMcuuk+mx22yq7+7H8Ku/ONzLLku3qiqZ7mJi/f+?= =?us-ascii?Q?S4RIXRH/6cV9fw9q5V4m9+dHo0AUW29bciVDqakyFjTYsmTWdLvr/r+4Xfr0?= =?us-ascii?Q?pKR7HHsKAfw0n35b7I+D5UsJZofLIfB7oJfrTVprwqIY3xUjwtTFYCr5Ov85?= =?us-ascii?Q?dpa4mKowqkBjdLhjGeaGidDayJjMoIELopKkcfdN4U+/z/0Wha/arGfsSdZa?= =?us-ascii?Q?9OJT3hyJvlx/pzaEk/p/vRWsEDG8grdLCLdZ9s7Zuy8G/sj/YnERPGqIDPCb?= =?us-ascii?Q?idCaUcBHjJE5p8f57WOADDPHJJvnAFXcgWAIGlzJ+UhFgXE+ftJ9gSvO+KtE?= =?us-ascii?Q?6JeyoagoF7e187UzA0GZ2nbfz7nia4E2s1JunIaD6f+d6CGh2AJLq2JOkCnp?= =?us-ascii?Q?sil7pXBXRWXk4piqqjuc6AEUv0MiYtx2W6aJH1xa8w0HyjwOJwBPHvj/xGOm?= =?us-ascii?Q?qZEs00dLN17x1AM3YYzNaDIGQXWa1C5LL/AN4yKrIO6CRyCXJ1w1hq1lp4OB?= =?us-ascii?Q?20h+0RY7gkDTckCnlGmPcDaiV1OrLalyFGohxQTr6P4Lc37EfxhtZxGPQd3q?= =?us-ascii?Q?8Yw4FIJMmYewbR99QvHSQVFVc6knLP8ggRHqkV4ZnbsKjs6OZHivuEkeyLrn?= =?us-ascii?Q?GP+f6rH3JtTylsnbUBlHRcPdHUdPnOTzGgG5YyoNpxF+UTSIrgaDswJfF/bn?= =?us-ascii?Q?FkA4j7CL82J1+PmGpVUHCNeqHFjhkNv1ImQGJhGdjYKDxS7x2o7Cc1385wD/?= =?us-ascii?Q?0UuqxZLjYiYe7KF1mTTJ+1UffixzST1VXi/DNRN/06fFwynFZXnJdoELAtt0?= =?us-ascii?Q?yHE7os7kfXV/EgnrSoQAKIGdy3Yw03fzFcBc69vew2KYucWgCUh8/7eqj01G?= =?us-ascii?Q?oHQ/1g9WTe1/kLROw0EKi16Gff7rEC0h04/wxhDAdNO0A=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1; DB5PR02MB0806; 5:Iq97xxBkM/xoZ+5PaXYEDxvpRs9FWqoq3EYpMarLTTbpp6VQGiJfw420SKFEk6On/j7BLVz7e7Gt4cBGQoFsJyZV1yp17OZrhXgYBl36ctw/n8o5I5iaAD7bnqjexMhFGyPjo+Hld49UO0FqHoJt4A==; 24:2v0RZuXZw1C+89V7t6YWc56BC1hOpxeGlBxQEOMuv/uSdXRO6NF2tDH6dI3JgySeQerJZFLhpVpFARweW/mYK3zn7e1WyJ1Tv/wjXPqndCM=; 20:f87dr+3k1uLAZNB2EJUWd0cCy3PXv16goe3SkdHrExfb1h3sW/mCLCYrQNdpKDF4EeVEZTRDLedlaqdZ1WXKyQ== SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: ezchip.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jul 2015 14:42:21.8091 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB5PR02MB0806 Subject: Re: [dpdk-dev] [PATCH v2] hash: fix compilation for non-x86 systems 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: Fri, 17 Jul 2015 14:42:25 -0000 >-----Original Message----- >From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Pablo de Lara >Sent: Friday, July 17, 2015 5:18 PM >To: dev@dpdk.org >Subject: [dpdk-dev] [PATCH v2] hash: fix compilation for non-x86 systems > >From: "Pablo de Lara" > >Hash library uses optimized compare functions that use >x86 intrinsics, therefore non-x86 systems could not build >the library. In that case, the compare function is set >to the generic memcmp. > >Fixes: 48a399119619 ("hash: replace with cuckoo hash implementation") > >Reported-by: Tony Lu >Signed-off-by: Pablo de Lara >--- >Changes in v2: >- Renamed new file rte_cmp_fns.h to rte_cmp_x86.h >- Removed blank line > > lib/librte_hash/rte_cmp_x86.h | 109 >++++++++++++++++++++++++++++++++++++++ > lib/librte_hash/rte_cuckoo_hash.c | 96 ++++----------------------------- > 2 files changed, 120 insertions(+), 85 deletions(-) > create mode 100644 lib/librte_hash/rte_cmp_x86.h > >diff --git a/lib/librte_hash/rte_cmp_x86.h b/lib/librte_hash/rte_cmp_x86.h >new file mode 100644 >index 0000000..7f79bac >--- /dev/null >+++ b/lib/librte_hash/rte_cmp_x86.h >@@ -0,0 +1,109 @@ >+/*- >+ * BSD LICENSE >+ * >+ * Copyright(c) 2015 Intel Corporation. All rights reserved. >+ * All rights reserved. >+ * >+ * Redistribution and use in source and binary forms, with or without >+ * modification, are permitted provided that the following conditions >+ * are met: >+ * >+ * * Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * * Redistributions in binary form must reproduce the above copyright >+ * notice, this list of conditions and the following disclaimer in >+ * the documentation and/or other materials provided with the >+ * distribution. >+ * * Neither the name of Intel Corporation nor the names of its >+ * contributors may be used to endorse or promote products derived >+ * from this software without specific prior written permission. >+ * >+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND >CONTRIBUTORS >+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT >NOT >+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND >FITNESS FOR >+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE >COPYRIGHT >+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, >INCIDENTAL, >+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT >NOT >+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS >OF USE, >+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED >AND ON ANY >+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR >TORT >+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF >THE USE >+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH >DAMAGE. >+ */ >+ >+/* Functions to compare multiple of 16 byte keys (up to 128 bytes) */ >+static int >+rte_hash_k16_cmp_eq(const void *key1, const void *key2, size_t key_len >__rte_unused) >+{ >+ const __m128i k1 = _mm_loadu_si128((const __m128i *) key1); >+ const __m128i k2 = _mm_loadu_si128((const __m128i *) key2); >+#ifdef RTE_MACHINE_CPUFLAG_SSE4_1 >+ const __m128i x = _mm_xor_si128(k1, k2); >+ >+ return !_mm_test_all_zeros(x, x); >+#else >+ const __m128i x = _mm_cmpeq_epi32(k1, k2); >+ >+ return (_mm_movemask_epi8(x) != 0xffff); >+#endif >+} >+ >+static int >+rte_hash_k32_cmp_eq(const void *key1, const void *key2, size_t key_len) >+{ >+ return rte_hash_k16_cmp_eq(key1, key2, key_len) || >+ rte_hash_k16_cmp_eq((const char *) key1 + 16, >+ (const char *) key2 + 16, key_len); >+} >+ >+static int >+rte_hash_k48_cmp_eq(const void *key1, const void *key2, size_t key_len) >+{ >+ return rte_hash_k16_cmp_eq(key1, key2, key_len) || >+ rte_hash_k16_cmp_eq((const char *) key1 + 16, >+ (const char *) key2 + 16, key_len) || >+ rte_hash_k16_cmp_eq((const char *) key1 + 32, >+ (const char *) key2 + 32, key_len); >+} >+ >+static int >+rte_hash_k64_cmp_eq(const void *key1, const void *key2, size_t key_len) >+{ >+ return rte_hash_k32_cmp_eq(key1, key2, key_len) || >+ rte_hash_k32_cmp_eq((const char *) key1 + 32, >+ (const char *) key2 + 32, key_len); >+} >+ >+static int >+rte_hash_k80_cmp_eq(const void *key1, const void *key2, size_t key_len) >+{ >+ return rte_hash_k64_cmp_eq(key1, key2, key_len) || >+ rte_hash_k16_cmp_eq((const char *) key1 + 64, >+ (const char *) key2 + 64, key_len); >+} >+ >+static int >+rte_hash_k96_cmp_eq(const void *key1, const void *key2, size_t key_len) >+{ >+ return rte_hash_k64_cmp_eq(key1, key2, key_len) || >+ rte_hash_k32_cmp_eq((const char *) key1 + 64, >+ (const char *) key2 + 64, key_len); >+} >+ >+static int >+rte_hash_k112_cmp_eq(const void *key1, const void *key2, size_t key_len) >+{ >+ return rte_hash_k64_cmp_eq(key1, key2, key_len) || >+ rte_hash_k32_cmp_eq((const char *) key1 + 64, >+ (const char *) key2 + 64, key_len) || >+ rte_hash_k16_cmp_eq((const char *) key1 + 96, >+ (const char *) key2 + 96, key_len); >+} >+ >+static int >+rte_hash_k128_cmp_eq(const void *key1, const void *key2, size_t key_len) >+{ >+ return rte_hash_k64_cmp_eq(key1, key2, key_len) || >+ rte_hash_k64_cmp_eq((const char *) key1 + 64, >+ (const char *) key2 + 64, key_len); >+} >diff --git a/lib/librte_hash/rte_cuckoo_hash.c >b/lib/librte_hash/rte_cuckoo_hash.c >index d9ba066..dec18ce 100644 >--- a/lib/librte_hash/rte_cuckoo_hash.c >+++ b/lib/librte_hash/rte_cuckoo_hash.c >@@ -59,6 +59,9 @@ > #include > > #include "rte_hash.h" >+#if defined(RTE_ARCH_X86_64) || defined(RTE_ARCH_I686) || >defined(RTE_ARCH_X86_X32) >+#include "rte_cmp_x86.h" >+#endif > > TAILQ_HEAD(rte_hash_list, rte_tailq_entry); > >@@ -94,14 +97,6 @@ EAL_REGISTER_TAILQ(rte_hash_tailq) > #define KEY_ALIGNMENT 16 > > typedef int (*rte_hash_cmp_eq_t)(const void *key1, const void *key2, size_t >key_len); >-static int rte_hash_k16_cmp_eq(const void *key1, const void *key2, size_t >key_len); >-static int rte_hash_k32_cmp_eq(const void *key1, const void *key2, size_t >key_len); >-static int rte_hash_k48_cmp_eq(const void *key1, const void *key2, size_t >key_len); >-static int rte_hash_k64_cmp_eq(const void *key1, const void *key2, size_t >key_len); >-static int rte_hash_k80_cmp_eq(const void *key1, const void *key2, size_t >key_len); >-static int rte_hash_k96_cmp_eq(const void *key1, const void *key2, size_t >key_len); >-static int rte_hash_k112_cmp_eq(const void *key1, const void *key2, size_t >key_len); >-static int rte_hash_k128_cmp_eq(const void *key1, const void *key2, size_t >key_len); > > /** A hash table structure. */ > struct rte_hash { >@@ -253,6 +248,11 @@ rte_hash_create(const struct rte_hash_parameters >*params) > goto err; > } > >+/* >+ * If x86 architecture is used, select appropriate compare function, >+ * which may use x86 instrinsics, otherwise use memcmp >+ */ >+#if defined(RTE_ARCH_X86_64) || defined(RTE_ARCH_I686) || >defined(RTE_ARCH_X86_X32) > /* Select function to compare keys */ > switch (params->key_len) { > case 16: >@@ -283,6 +283,9 @@ rte_hash_create(const struct rte_hash_parameters >*params) > /* If key is not multiple of 16, use generic memcmp */ > h->rte_hash_cmp_eq = memcmp; > } >+#else >+ h->rte_hash_cmp_eq = memcmp; >+#endif > > snprintf(ring_name, sizeof(ring_name), "HT_%s", params->name); > r = rte_ring_lookup(ring_name); >@@ -1118,80 +1121,3 @@ rte_hash_iterate(const struct rte_hash *h, const >void **key, void **data, uint32 > > return (position - 1); > } >- >-/* Functions to compare multiple of 16 byte keys (up to 128 bytes) */ >-static int >-rte_hash_k16_cmp_eq(const void *key1, const void *key2, size_t key_len >__rte_unused) >-{ >- const __m128i k1 = _mm_loadu_si128((const __m128i *) key1); >- const __m128i k2 = _mm_loadu_si128((const __m128i *) key2); >-#ifdef RTE_MACHINE_CPUFLAG_SSE4_1 >- const __m128i x = _mm_xor_si128(k1, k2); >- >- return !_mm_test_all_zeros(x, x); >-#else >- const __m128i x = _mm_cmpeq_epi32(k1, k2); >- >- return (_mm_movemask_epi8(x) != 0xffff); >-#endif >-} >- >-static int >-rte_hash_k32_cmp_eq(const void *key1, const void *key2, size_t key_len) >-{ >- return rte_hash_k16_cmp_eq(key1, key2, key_len) || >- rte_hash_k16_cmp_eq((const char *) key1 + 16, >- (const char *) key2 + 16, key_len); >-} >- >-static int >-rte_hash_k48_cmp_eq(const void *key1, const void *key2, size_t key_len) >-{ >- return rte_hash_k16_cmp_eq(key1, key2, key_len) || >- rte_hash_k16_cmp_eq((const char *) key1 + 16, >- (const char *) key2 + 16, key_len) || >- rte_hash_k16_cmp_eq((const char *) key1 + 32, >- (const char *) key2 + 32, key_len); >-} >- >-static int >-rte_hash_k64_cmp_eq(const void *key1, const void *key2, size_t key_len) >-{ >- return rte_hash_k32_cmp_eq(key1, key2, key_len) || >- rte_hash_k32_cmp_eq((const char *) key1 + 32, >- (const char *) key2 + 32, key_len); >-} >- >-static int >-rte_hash_k80_cmp_eq(const void *key1, const void *key2, size_t key_len) >-{ >- return rte_hash_k64_cmp_eq(key1, key2, key_len) || >- rte_hash_k16_cmp_eq((const char *) key1 + 64, >- (const char *) key2 + 64, key_len); >-} >- >-static int >-rte_hash_k96_cmp_eq(const void *key1, const void *key2, size_t key_len) >-{ >- return rte_hash_k64_cmp_eq(key1, key2, key_len) || >- rte_hash_k32_cmp_eq((const char *) key1 + 64, >- (const char *) key2 + 64, key_len); >-} >- >-static int >-rte_hash_k112_cmp_eq(const void *key1, const void *key2, size_t key_len) >-{ >- return rte_hash_k64_cmp_eq(key1, key2, key_len) || >- rte_hash_k32_cmp_eq((const char *) key1 + 64, >- (const char *) key2 + 64, key_len) || >- rte_hash_k16_cmp_eq((const char *) key1 + 96, >- (const char *) key2 + 96, key_len); >-} >- >-static int >-rte_hash_k128_cmp_eq(const void *key1, const void *key2, size_t key_len) >-{ >- return rte_hash_k64_cmp_eq(key1, key2, key_len) || >- rte_hash_k64_cmp_eq((const char *) key1 + 64, >- (const char *) key2 + 64, key_len); >-} >-- >2.4.2 Acked-by: Zhigang Lu