Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/4684/?format=api
https://patches.dpdk.org/api/patches/4684/?format=api", "web_url": "https://patches.dpdk.org/project/dpdk/patch/1431428560-25426-4-git-send-email-pablo.de.lara.guarch@intel.com/", "project": { "id": 1, "url": "https://patches.dpdk.org/api/projects/1/?format=api", "name": "DPDK", "link_name": "dpdk", "list_id": "dev.dpdk.org", "list_email": "dev@dpdk.org", "web_url": "http://core.dpdk.org", "scm_url": "git://dpdk.org/dpdk", "webscm_url": "http://git.dpdk.org/dpdk", "list_archive_url": "https://inbox.dpdk.org/dev", "list_archive_url_format": "https://inbox.dpdk.org/dev/{}", "commit_url_format": "" }, "msgid": "<1431428560-25426-4-git-send-email-pablo.de.lara.guarch@intel.com>", "list_archive_url": "https://inbox.dpdk.org/dev/1431428560-25426-4-git-send-email-pablo.de.lara.guarch@intel.com", "date": "2015-05-12T11:02:35", "name": "[dpdk-dev,v4,3/6] hash: update jhash function with the latest available", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": true, "hash": "7f719ade7bb8f1c3cd213bc5276d50a51bd8217f", "submitter": { "id": 9, "url": "https://patches.dpdk.org/api/people/9/?format=api", "name": "De Lara Guarch, Pablo", "email": "pablo.de.lara.guarch@intel.com" }, "delegate": null, "mbox": "https://patches.dpdk.org/project/dpdk/patch/1431428560-25426-4-git-send-email-pablo.de.lara.guarch@intel.com/mbox/", "series": [], "comments": "https://patches.dpdk.org/api/patches/4684/comments/", "check": "pending", "checks": "https://patches.dpdk.org/api/patches/4684/checks/", "tags": {}, "related": [], "headers": { "Return-Path": "<dev-bounces@dpdk.org>", "X-Original-To": "patchwork@dpdk.org", "Delivered-To": "patchwork@dpdk.org", "Received": [ "from [92.243.14.124] (localhost [IPv6:::1])\n\tby dpdk.org (Postfix) with ESMTP id 925A35A17;\n\tTue, 12 May 2015 13:03:51 +0200 (CEST)", "from mga01.intel.com (mga01.intel.com [192.55.52.88])\n\tby dpdk.org (Postfix) with ESMTP id 6AEE4376C\n\tfor <dev@dpdk.org>; Tue, 12 May 2015 13:03:47 +0200 (CEST)", "from fmsmga001.fm.intel.com ([10.253.24.23])\n\tby fmsmga101.fm.intel.com with ESMTP; 12 May 2015 04:03:29 -0700", "from irvmail001.ir.intel.com ([163.33.26.43])\n\tby fmsmga001.fm.intel.com with ESMTP; 12 May 2015 04:03:28 -0700", "from sivswdev02.ir.intel.com (sivswdev02.ir.intel.com\n\t[10.237.217.46])\n\tby irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id\n\tt4CB3RAW025733; Tue, 12 May 2015 12:03:27 +0100", "from sivswdev02.ir.intel.com (localhost [127.0.0.1])\n\tby sivswdev02.ir.intel.com with ESMTP id t4CB3Nc9028755;\n\tTue, 12 May 2015 12:03:23 +0100", "(from pdelarax@localhost)\n\tby sivswdev02.ir.intel.com with id t4CB3M09028748;\n\tTue, 12 May 2015 12:03:22 +0100" ], "X-ExtLoop1": "1", "X-IronPort-AV": "E=Sophos;i=\"5.13,414,1427785200\"; d=\"scan'208\";a=\"708915477\"", "From": "Pablo de Lara <pablo.de.lara.guarch@intel.com>", "To": "dev@dpdk.org", "Date": "Tue, 12 May 2015 12:02:35 +0100", "Message-Id": "<1431428560-25426-4-git-send-email-pablo.de.lara.guarch@intel.com>", "X-Mailer": "git-send-email 1.7.4.1", "In-Reply-To": "<1431428560-25426-1-git-send-email-pablo.de.lara.guarch@intel.com>", "References": "<1430837034-21031-1-git-send-email-pablo.de.lara.guarch@intel.com>\n\t<1431428560-25426-1-git-send-email-pablo.de.lara.guarch@intel.com>", "Subject": "[dpdk-dev] [PATCH v4 3/6] hash: update jhash function with the\n\tlatest available", "X-BeenThere": "dev@dpdk.org", "X-Mailman-Version": "2.1.15", "Precedence": "list", "List-Id": "patches and discussions about DPDK <dev.dpdk.org>", "List-Unsubscribe": "<http://dpdk.org/ml/options/dev>,\n\t<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>,\n\t<mailto:dev-request@dpdk.org?subject=subscribe>", "Errors-To": "dev-bounces@dpdk.org", "Sender": "\"dev\" <dev-bounces@dpdk.org>" }, "content": "Jenkins hash function was developed originally in 1996,\nand was integrated in first versions of DPDK.\nThe function has been improved in 2006,\nachieving up to 60% better performance, compared to the original one.\n\nThis patch integrates that code into the rte_jhash library.\n\nSigned-off-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>\n---\n lib/librte_hash/rte_jhash.h | 266 +++++++++++++++++++++++++++++++------------\n 1 files changed, 193 insertions(+), 73 deletions(-)", "diff": "diff --git a/lib/librte_hash/rte_jhash.h b/lib/librte_hash/rte_jhash.h\nindex a4bf5a1..41297ab 100644\n--- a/lib/librte_hash/rte_jhash.h\n+++ b/lib/librte_hash/rte_jhash.h\n@@ -1,7 +1,7 @@\n /*-\n * BSD LICENSE\n *\n- * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.\n+ * Copyright(c) 2010-2015 Intel Corporation. All rights reserved.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without\n@@ -45,38 +45,62 @@ extern \"C\" {\n #endif\n \n #include <stdint.h>\n+#include <string.h>\n+#include <rte_byteorder.h>\n \n /* jhash.h: Jenkins hash support.\n *\n- * Copyright (C) 1996 Bob Jenkins (bob_jenkins@burtleburtle.net)\n+ * Copyright (C) 2006 Bob Jenkins (bob_jenkins@burtleburtle.net)\n *\n * http://burtleburtle.net/bob/hash/\n *\n * These are the credits from Bob's sources:\n *\n- * lookup2.c, by Bob Jenkins, December 1996, Public Domain.\n- * hash(), hash2(), hash3, and mix() are externally useful functions.\n- * Routines to test the hash are included if SELF_TEST is defined.\n- * You can use this free for any purpose. It has no warranty.\n+ * lookup3.c, by Bob Jenkins, May 2006, Public Domain.\n+ *\n+ * These are functions for producing 32-bit hashes for hash table lookup.\n+ * hashword(), hashlittle(), hashlittle2(), hashbig(), mix(), and final()\n+ * are externally useful functions. Routines to test the hash are included\n+ * if SELF_TEST is defined. You can use this free for any purpose. It's in\n+ * the public domain. It has no warranty.\n *\n * $FreeBSD$\n */\n \n+#define rot(x, k) (((x) << (k)) | ((x) >> (32-(k))))\n+\n /** @internal Internal function. NOTE: Arguments are modified. */\n #define __rte_jhash_mix(a, b, c) do { \\\n-\ta -= b; a -= c; a ^= (c>>13); \\\n-\tb -= c; b -= a; b ^= (a<<8); \\\n-\tc -= a; c -= b; c ^= (b>>13); \\\n-\ta -= b; a -= c; a ^= (c>>12); \\\n-\tb -= c; b -= a; b ^= (a<<16); \\\n-\tc -= a; c -= b; c ^= (b>>5); \\\n-\ta -= b; a -= c; a ^= (c>>3); \\\n-\tb -= c; b -= a; b ^= (a<<10); \\\n-\tc -= a; c -= b; c ^= (b>>15); \\\n+\ta -= c; a ^= rot(c, 4); c += b; \\\n+\tb -= a; b ^= rot(a, 6); a += c; \\\n+\tc -= b; c ^= rot(b, 8); b += a; \\\n+\ta -= c; a ^= rot(c, 16); c += b; \\\n+\tb -= a; b ^= rot(a, 19); a += c; \\\n+\tc -= b; c ^= rot(b, 4); b += a; \\\n+} while (0)\n+\n+#define __rte_jhash_final(a, b, c) do { \\\n+\tc ^= b; c -= rot(b, 14); \\\n+\ta ^= c; a -= rot(c, 11); \\\n+\tb ^= a; b -= rot(a, 25); \\\n+\tc ^= b; c -= rot(b, 16); \\\n+\ta ^= c; a -= rot(c, 4); \\\n+\tb ^= a; b -= rot(a, 14); \\\n+\tc ^= b; c -= rot(b, 24); \\\n } while (0)\n \n /** The golden ratio: an arbitrary value. */\n-#define RTE_JHASH_GOLDEN_RATIO 0x9e3779b9\n+#define RTE_JHASH_GOLDEN_RATIO 0xdeadbeef\n+\n+#if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN\n+#define BIT_SHIFT(x, y, k) (((x) >> (k)) | ((uint64_t)(y) << (32-(k))))\n+#else\n+#define BIT_SHIFT(x, y, k) (((uint64_t)(x) << (k)) | ((y) >> (32-(k))))\n+#endif\n+\n+#define LOWER8b_MASK rte_le_to_cpu_32(0xff)\n+#define LOWER16b_MASK rte_le_to_cpu_32(0xffff)\n+#define LOWER24b_MASK rte_le_to_cpu_32(0xffffff)\n \n /**\n * The most generic version, hashes an arbitrary sequence\n@@ -95,42 +119,130 @@ extern \"C\" {\n static inline uint32_t\n rte_jhash(const void *key, uint32_t length, uint32_t initval)\n {\n-\tuint32_t a, b, c, len;\n-\tconst uint8_t *k = (const uint8_t *)key;\n-\tconst uint32_t *k32 = (const uint32_t *)key;\n+\tuint32_t a, b, c;\n \n-\tlen = length;\n-\ta = b = RTE_JHASH_GOLDEN_RATIO;\n-\tc = initval;\n+\t/* Set up the internal state */\n+\ta = b = c = RTE_JHASH_GOLDEN_RATIO + ((uint32_t)length) + initval;\n \n-\twhile (len >= 12) {\n-\t\ta += k32[0];\n-\t\tb += k32[1];\n-\t\tc += k32[2];\n+\t/* Check key alignment. For x86 architecture, first case is always optimal */\n+#if defined(RTE_ARCH_X86_64) || defined(RTE_ARCH_I686) || defined(RTE_ARCH_X86_X32)\n+\tconst uint32_t *k = key;\n+\tconst uint32_t s = 0;\n+#else\n+\tconst uint32_t *k = (uint32_t *)(uintptr_t)key & (uintptr_t)~3);\n+\tconst uint32_t s = ((uintptr_t)key & 3) * CHAR_BIT;\n+#endif\n \n-\t\t__rte_jhash_mix(a,b,c);\n+\tif (s == 0) {\n+\t\twhile (length > 12) {\n+\t\t\ta += k[0];\n+\t\t\tb += k[1];\n+\t\t\tc += k[2];\n \n-\t\tk += (3 * sizeof(uint32_t)), k32 += 3;\n-\t\tlen -= (3 * sizeof(uint32_t));\n-\t}\n+\t\t\t__rte_jhash_mix(a, b, c);\n \n-\tc += length;\n-\tswitch (len) {\n-\t\tcase 11: c += ((uint32_t)k[10] << 24);\n-\t\tcase 10: c += ((uint32_t)k[9] << 16);\n-\t\tcase 9 : c += ((uint32_t)k[8] << 8);\n-\t\tcase 8 : b += ((uint32_t)k[7] << 24);\n-\t\tcase 7 : b += ((uint32_t)k[6] << 16);\n-\t\tcase 6 : b += ((uint32_t)k[5] << 8);\n-\t\tcase 5 : b += k[4];\n-\t\tcase 4 : a += ((uint32_t)k[3] << 24);\n-\t\tcase 3 : a += ((uint32_t)k[2] << 16);\n-\t\tcase 2 : a += ((uint32_t)k[1] << 8);\n-\t\tcase 1 : a += k[0];\n-\t\tdefault: break;\n-\t};\n+\t\t\tk += 3;\n+\t\t\tlength -= 12;\n+\t\t}\n \n-\t__rte_jhash_mix(a,b,c);\n+\t\tswitch (length) {\n+\t\tcase 12:\n+\t\t\tc += k[2]; b += k[1]; a += k[0]; break;\n+\t\tcase 11:\n+\t\t\tc += k[2] & LOWER24b_MASK; b += k[1]; a += k[0]; break;\n+\t\tcase 10:\n+\t\t\tc += k[2] & LOWER16b_MASK; b += k[1]; a += k[0]; break;\n+\t\tcase 9:\n+\t\t\tc += k[2] & LOWER8b_MASK; b += k[1]; a += k[0]; break;\n+\t\tcase 8:\n+\t\t\tb += k[1]; a += k[0]; break;\n+\t\tcase 7:\n+\t\t\tb += k[1] & LOWER24b_MASK; a += k[0]; break;\n+\t\tcase 6:\n+\t\t\tb += k[1] & LOWER16b_MASK; a += k[0]; break;\n+\t\tcase 5:\n+\t\t\tb += k[1] & LOWER8b_MASK; a += k[0]; break;\n+\t\tcase 4:\n+\t\t\ta += k[0]; break;\n+\t\tcase 3:\n+\t\t\ta += k[0] & LOWER24b_MASK; break;\n+\t\tcase 2:\n+\t\t\ta += k[0] & LOWER16b_MASK; break;\n+\t\tcase 1:\n+\t\t\ta += k[0] & LOWER8b_MASK; break;\n+\t\t/* zero length strings require no mixing */\n+\t\tcase 0:\n+\t\t\treturn c;\n+\t\t};\n+\t} else {\n+\t\t/* all but the last block: affect some 32 bits of (a, b, c) */\n+\t\twhile (length > 12) {\n+\t\t\ta += BIT_SHIFT(k[0], k[1], s);\n+\t\t\tb += BIT_SHIFT(k[1], k[2], s);\n+\t\t\tc += BIT_SHIFT(k[2], k[3], s);\n+\t\t\t__rte_jhash_mix(a, b, c);\n+\n+\t\t\tk += 3;\n+\t\t\tlength -= 12;\n+\t\t}\n+\n+\t\t/* last block: affect all 32 bits of (c) */\n+\t\tswitch (length) {\n+\t\tcase 12:\n+\t\t\ta += BIT_SHIFT(k[0], k[1], s);\n+\t\t\tb += BIT_SHIFT(k[1], k[2], s);\n+\t\t\tc += BIT_SHIFT(k[2], k[3], s);\n+\t\t\tbreak;\n+\t\tcase 11:\n+\t\t\ta += BIT_SHIFT(k[0], k[1], s);\n+\t\t\tb += BIT_SHIFT(k[1], k[2], s);\n+\t\t\tc += BIT_SHIFT(k[2], k[3], s) & LOWER24b_MASK;\n+\t\t\tbreak;\n+\t\tcase 10:\n+\t\t\ta += BIT_SHIFT(k[0], k[1], s);\n+\t\t\tb += BIT_SHIFT(k[1], k[2], s);\n+\t\t\tc += BIT_SHIFT(k[2], k[3], s) & LOWER16b_MASK;\n+\t\t\tbreak;\n+\t\tcase 9:\n+\t\t\ta += BIT_SHIFT(k[0], k[1], s);\n+\t\t\tb += BIT_SHIFT(k[1], k[2], s);\n+\t\t\tc += BIT_SHIFT(k[2], k[3], s) & LOWER8b_MASK;\n+\t\t\tbreak;\n+\t\tcase 8:\n+\t\t\ta += BIT_SHIFT(k[0], k[1], s);\n+\t\t\tb += BIT_SHIFT(k[1], k[2], s);\n+\t\t\tbreak;\n+\t\tcase 7:\n+\t\t\ta += BIT_SHIFT(k[0], k[1], s);\n+\t\t\tb += BIT_SHIFT(k[1], k[2], s) & LOWER24b_MASK;\n+\t\t\tbreak;\n+\t\tcase 6:\n+\t\t\ta += BIT_SHIFT(k[0], k[1], s);\n+\t\t\tb += BIT_SHIFT(k[1], k[2], s) & LOWER16b_MASK;\n+\t\t\tbreak;\n+\t\tcase 5:\n+\t\t\ta += BIT_SHIFT(k[0], k[1], s);\n+\t\t\tb += BIT_SHIFT(k[1], k[2], s) & LOWER8b_MASK;\n+\t\t\tbreak;\n+\t\tcase 4:\n+\t\t\ta += BIT_SHIFT(k[0], k[1], s);\n+\t\t\tbreak;\n+\t\tcase 3:\n+\t\t\ta += BIT_SHIFT(k[0], k[1], s) & LOWER24b_MASK;\n+\t\t\tbreak;\n+\t\tcase 2:\n+\t\t\ta += BIT_SHIFT(k[0], k[1], s) & LOWER16b_MASK;\n+\t\t\tbreak;\n+\t\tcase 1:\n+\t\t\ta += BIT_SHIFT(k[0], k[1], s) & LOWER8b_MASK;\n+\t\t\tbreak;\n+\t\t/* zero length strings require no mixing */\n+\t\tcase 0:\n+\t\t\treturn c;\n+\t\t}\n+\t}\n+\n+\t__rte_jhash_final(a, b, c);\n \n \treturn c;\n }\n@@ -151,33 +263,51 @@ rte_jhash(const void *key, uint32_t length, uint32_t initval)\n static inline uint32_t\n rte_jhash2(const uint32_t *k, uint32_t length, uint32_t initval)\n {\n-\tuint32_t a, b, c, len;\n+\tuint32_t a, b, c;\n \n-\ta = b = RTE_JHASH_GOLDEN_RATIO;\n-\tc = initval;\n-\tlen = length;\n+\t/* Set up the internal state */\n+\ta = b = c = RTE_JHASH_GOLDEN_RATIO + (((uint32_t)length) << 2) + initval;\n \n-\twhile (len >= 3) {\n+\t/* Handle most of the key */\n+\twhile (length > 3) {\n \t\ta += k[0];\n \t\tb += k[1];\n \t\tc += k[2];\n+\n \t\t__rte_jhash_mix(a, b, c);\n-\t\tk += 3; len -= 3;\n-\t}\n \n-\tc += length * 4;\n+\t\tk += 3;\n+\t\tlength -= 3;\n+\t}\n \n-\tswitch (len) {\n-\t\tcase 2 : b += k[1];\n-\t\tcase 1 : a += k[0];\n-\t\tdefault: break;\n+\t/* Handle the last 3 uint32_t's */\n+\tswitch (length) {\n+\tcase 3:\n+\t\tc += k[2];\n+\tcase 2:\n+\t\tb += k[1];\n+\tcase 1:\n+\t\ta += k[0];\n+\t\t__rte_jhash_final(a, b, c);\n+\t/* case 0: nothing left to add */\n+\tcase 0:\n+\t\tbreak;\n \t};\n \n-\t__rte_jhash_mix(a,b,c);\n-\n \treturn c;\n }\n \n+static inline uint32_t\n+__rte_jhash_3words(uint32_t a, uint32_t b, uint32_t c, uint32_t initval)\n+{\n+\ta += RTE_JHASH_GOLDEN_RATIO + initval;\n+\tb += RTE_JHASH_GOLDEN_RATIO + initval;\n+\tc += RTE_JHASH_GOLDEN_RATIO + initval;\n+\n+\t__rte_jhash_final(a, b, c);\n+\n+\treturn c;\n+}\n \n /**\n * A special ultra-optimized versions that knows it is hashing exactly\n@@ -197,17 +327,7 @@ rte_jhash2(const uint32_t *k, uint32_t length, uint32_t initval)\n static inline uint32_t\n rte_jhash_3words(uint32_t a, uint32_t b, uint32_t c, uint32_t initval)\n {\n-\ta += RTE_JHASH_GOLDEN_RATIO;\n-\tb += RTE_JHASH_GOLDEN_RATIO;\n-\tc += initval;\n-\n-\t__rte_jhash_mix(a, b, c);\n-\n-\t/*\n-\t * NOTE: In particular the \"c += length; __rte_jhash_mix(a,b,c);\"\n-\t * normally done at the end is not done here.\n-\t */\n-\treturn c;\n+\treturn __rte_jhash_3words(a + 12, b + 12, c + 12, initval);\n }\n \n /**\n@@ -226,7 +346,7 @@ rte_jhash_3words(uint32_t a, uint32_t b, uint32_t c, uint32_t initval)\n static inline uint32_t\n rte_jhash_2words(uint32_t a, uint32_t b, uint32_t initval)\n {\n-\treturn rte_jhash_3words(a, b, 0, initval);\n+\treturn __rte_jhash_3words(a + 8, b + 8, 8, initval);\n }\n \n /**\n@@ -243,7 +363,7 @@ rte_jhash_2words(uint32_t a, uint32_t b, uint32_t initval)\n static inline uint32_t\n rte_jhash_1word(uint32_t a, uint32_t initval)\n {\n-\treturn rte_jhash_3words(a, 0, 0, initval);\n+\treturn __rte_jhash_3words(a + 4, 4, 4, initval);\n }\n \n #ifdef __cplusplus\n", "prefixes": [ "dpdk-dev", "v4", "3/6" ] }{ "id": 4684, "url": "