X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=examples%2Fip_pipeline%2Fpipeline%2Fhash_func.h;h=806ac22793fea89fbe40d7313eed1d5b2af347e9;hb=cdc37ca3d04b165a5e60aa1c29754385bbdeef90;hp=1953ad4706c5a6045c3fe63c17d189a11ba91cd4;hpb=28377375c6c08168d0e6d91e6ab15dd3646d5fcd;p=dpdk.git diff --git a/examples/ip_pipeline/pipeline/hash_func.h b/examples/ip_pipeline/pipeline/hash_func.h index 1953ad4706..806ac22793 100644 --- a/examples/ip_pipeline/pipeline/hash_func.h +++ b/examples/ip_pipeline/pipeline/hash_func.h @@ -1,81 +1,60 @@ -/*- - * BSD LICENSE - * - * Copyright(c) 2010-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. +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2010-2015 Intel Corporation */ #ifndef __INCLUDE_HASH_FUNC_H__ #define __INCLUDE_HASH_FUNC_H__ static inline uint64_t -hash_xor_key8(void *key, __rte_unused uint32_t key_size, uint64_t seed) +hash_xor_key8(void *key, void *mask, __rte_unused uint32_t key_size, + uint64_t seed) { uint64_t *k = key; + uint64_t *m = mask; uint64_t xor0; - xor0 = seed ^ k[0]; + xor0 = seed ^ (k[0] & m[0]); return (xor0 >> 32) ^ xor0; } static inline uint64_t -hash_xor_key16(void *key, __rte_unused uint32_t key_size, uint64_t seed) +hash_xor_key16(void *key, void *mask, __rte_unused uint32_t key_size, + uint64_t seed) { uint64_t *k = key; + uint64_t *m = mask; uint64_t xor0; - xor0 = (k[0] ^ seed) ^ k[1]; + xor0 = ((k[0] & m[0]) ^ seed) ^ (k[1] & m[1]); return (xor0 >> 32) ^ xor0; } static inline uint64_t -hash_xor_key24(void *key, __rte_unused uint32_t key_size, uint64_t seed) +hash_xor_key24(void *key, void *mask, __rte_unused uint32_t key_size, + uint64_t seed) { uint64_t *k = key; + uint64_t *m = mask; uint64_t xor0; - xor0 = (k[0] ^ seed) ^ k[1]; + xor0 = ((k[0] & m[0]) ^ seed) ^ (k[1] & m[1]); - xor0 ^= k[2]; + xor0 ^= k[2] & m[2]; return (xor0 >> 32) ^ xor0; } static inline uint64_t -hash_xor_key32(void *key, __rte_unused uint32_t key_size, uint64_t seed) +hash_xor_key32(void *key, void *mask, __rte_unused uint32_t key_size, + uint64_t seed) { uint64_t *k = key; + uint64_t *m = mask; uint64_t xor0, xor1; - xor0 = (k[0] ^ seed) ^ k[1]; - xor1 = k[2] ^ k[3]; + xor0 = ((k[0] & m[0]) ^ seed) ^ (k[1] & m[1]); + xor1 = (k[2] & m[2]) ^ (k[3] & m[3]); xor0 ^= xor1; @@ -83,30 +62,34 @@ hash_xor_key32(void *key, __rte_unused uint32_t key_size, uint64_t seed) } static inline uint64_t -hash_xor_key40(void *key, __rte_unused uint32_t key_size, uint64_t seed) +hash_xor_key40(void *key, void *mask, __rte_unused uint32_t key_size, + uint64_t seed) { uint64_t *k = key; + uint64_t *m = mask; uint64_t xor0, xor1; - xor0 = (k[0] ^ seed) ^ k[1]; - xor1 = k[2] ^ k[3]; + xor0 = ((k[0] & m[0]) ^ seed) ^ (k[1] & m[1]); + xor1 = (k[2] & m[2]) ^ (k[3] & m[3]); xor0 ^= xor1; - xor0 ^= k[4]; + xor0 ^= k[4] & m[4]; return (xor0 >> 32) ^ xor0; } static inline uint64_t -hash_xor_key48(void *key, __rte_unused uint32_t key_size, uint64_t seed) +hash_xor_key48(void *key, void *mask, __rte_unused uint32_t key_size, + uint64_t seed) { uint64_t *k = key; + uint64_t *m = mask; uint64_t xor0, xor1, xor2; - xor0 = (k[0] ^ seed) ^ k[1]; - xor1 = k[2] ^ k[3]; - xor2 = k[4] ^ k[5]; + xor0 = ((k[0] & m[0]) ^ seed) ^ (k[1] & m[1]); + xor1 = (k[2] & m[2]) ^ (k[3] & m[3]); + xor2 = (k[4] & m[4]) ^ (k[5] & m[5]); xor0 ^= xor1; @@ -116,17 +99,19 @@ hash_xor_key48(void *key, __rte_unused uint32_t key_size, uint64_t seed) } static inline uint64_t -hash_xor_key56(void *key, __rte_unused uint32_t key_size, uint64_t seed) +hash_xor_key56(void *key, void *mask, __rte_unused uint32_t key_size, + uint64_t seed) { uint64_t *k = key; + uint64_t *m = mask; uint64_t xor0, xor1, xor2; - xor0 = (k[0] ^ seed) ^ k[1]; - xor1 = k[2] ^ k[3]; - xor2 = k[4] ^ k[5]; + xor0 = ((k[0] & m[0]) ^ seed) ^ (k[1] & m[1]); + xor1 = (k[2] & m[2]) ^ (k[3] & m[3]); + xor2 = (k[4] & m[4]) ^ (k[5] & m[5]); xor0 ^= xor1; - xor2 ^= k[6]; + xor2 ^= k[6] & m[6]; xor0 ^= xor2; @@ -134,15 +119,17 @@ hash_xor_key56(void *key, __rte_unused uint32_t key_size, uint64_t seed) } static inline uint64_t -hash_xor_key64(void *key, __rte_unused uint32_t key_size, uint64_t seed) +hash_xor_key64(void *key, void *mask, __rte_unused uint32_t key_size, + uint64_t seed) { uint64_t *k = key; + uint64_t *m = mask; uint64_t xor0, xor1, xor2, xor3; - xor0 = (k[0] ^ seed) ^ k[1]; - xor1 = k[2] ^ k[3]; - xor2 = k[4] ^ k[5]; - xor3 = k[6] ^ k[7]; + xor0 = ((k[0] & m[0]) ^ seed) ^ (k[1] & m[1]); + xor1 = (k[2] & m[2]) ^ (k[3] & m[3]); + xor2 = (k[4] & m[4]) ^ (k[5] & m[5]); + xor3 = (k[6] & m[6]) ^ (k[7] & m[7]); xor0 ^= xor1; xor2 ^= xor3; @@ -152,31 +139,35 @@ hash_xor_key64(void *key, __rte_unused uint32_t key_size, uint64_t seed) return (xor0 >> 32) ^ xor0; } -#if defined(__x86_64__) && defined(RTE_CPUFLAG_SSE4_2) +#if defined(RTE_ARCH_X86_64) #include static inline uint64_t -hash_crc_key8(void *key, __rte_unused uint32_t key_size, uint64_t seed) +hash_crc_key8(void *key, void *mask, __rte_unused uint32_t key_size, + uint64_t seed) { uint64_t *k = key; + uint64_t *m = mask; uint64_t crc0; - crc0 = _mm_crc32_u64(seed, k[0]); + crc0 = _mm_crc32_u64(seed, k[0] & m[0]); return crc0; } static inline uint64_t -hash_crc_key16(void *key, __rte_unused uint32_t key_size, uint64_t seed) +hash_crc_key16(void *key, void *mask, __rte_unused uint32_t key_size, + uint64_t seed) { uint64_t *k = key; + uint64_t *m = mask; uint64_t k0, crc0, crc1; - k0 = k[0]; + k0 = k[0] & m[0]; crc0 = _mm_crc32_u64(k0, seed); - crc1 = _mm_crc32_u64(k0 >> 32, k[1]); + crc1 = _mm_crc32_u64(k0 >> 32, k[1] & m[1]); crc0 ^= crc1; @@ -184,16 +175,18 @@ hash_crc_key16(void *key, __rte_unused uint32_t key_size, uint64_t seed) } static inline uint64_t -hash_crc_key24(void *key, __rte_unused uint32_t key_size, uint64_t seed) +hash_crc_key24(void *key, void *mask, __rte_unused uint32_t key_size, + uint64_t seed) { uint64_t *k = key; + uint64_t *m = mask; uint64_t k0, k2, crc0, crc1; - k0 = k[0]; - k2 = k[2]; + k0 = k[0] & m[0]; + k2 = k[2] & m[2]; crc0 = _mm_crc32_u64(k0, seed); - crc1 = _mm_crc32_u64(k0 >> 32, k[1]); + crc1 = _mm_crc32_u64(k0 >> 32, k[1] & m[1]); crc0 = _mm_crc32_u64(crc0, k2); @@ -203,18 +196,20 @@ hash_crc_key24(void *key, __rte_unused uint32_t key_size, uint64_t seed) } static inline uint64_t -hash_crc_key32(void *key, __rte_unused uint32_t key_size, uint64_t seed) +hash_crc_key32(void *key, void *mask, __rte_unused uint32_t key_size, + uint64_t seed) { uint64_t *k = key; + uint64_t *m = mask; uint64_t k0, k2, crc0, crc1, crc2, crc3; - k0 = k[0]; - k2 = k[2]; + k0 = k[0] & m[0]; + k2 = k[2] & m[2]; crc0 = _mm_crc32_u64(k0, seed); - crc1 = _mm_crc32_u64(k0 >> 32, k[1]); + crc1 = _mm_crc32_u64(k0 >> 32, k[1] & m[1]); - crc2 = _mm_crc32_u64(k2, k[3]); + crc2 = _mm_crc32_u64(k2, k[3] & m[3]); crc3 = k2 >> 32; crc0 = _mm_crc32_u64(crc0, crc1); @@ -226,19 +221,21 @@ hash_crc_key32(void *key, __rte_unused uint32_t key_size, uint64_t seed) } static inline uint64_t -hash_crc_key40(void *key, __rte_unused uint32_t key_size, uint64_t seed) +hash_crc_key40(void *key, void *mask, __rte_unused uint32_t key_size, + uint64_t seed) { uint64_t *k = key; + uint64_t *m = mask; uint64_t k0, k2, crc0, crc1, crc2, crc3; - k0 = k[0]; - k2 = k[2]; + k0 = k[0] & m[0]; + k2 = k[2] & m[2]; crc0 = _mm_crc32_u64(k0, seed); - crc1 = _mm_crc32_u64(k0 >> 32, k[1]); + crc1 = _mm_crc32_u64(k0 >> 32, k[1] & m[1]); - crc2 = _mm_crc32_u64(k2, k[3]); - crc3 = _mm_crc32_u64(k2 >> 32, k[4]); + crc2 = _mm_crc32_u64(k2, k[3] & m[3]); + crc3 = _mm_crc32_u64(k2 >> 32, k[4] & m[4]); crc0 = _mm_crc32_u64(crc0, crc1); crc1 = _mm_crc32_u64(crc2, crc3); @@ -249,20 +246,22 @@ hash_crc_key40(void *key, __rte_unused uint32_t key_size, uint64_t seed) } static inline uint64_t -hash_crc_key48(void *key, __rte_unused uint32_t key_size, uint64_t seed) +hash_crc_key48(void *key, void *mask, __rte_unused uint32_t key_size, + uint64_t seed) { uint64_t *k = key; + uint64_t *m = mask; uint64_t k0, k2, k5, crc0, crc1, crc2, crc3; - k0 = k[0]; - k2 = k[2]; - k5 = k[5]; + k0 = k[0] & m[0]; + k2 = k[2] & m[2]; + k5 = k[5] & m[5]; crc0 = _mm_crc32_u64(k0, seed); - crc1 = _mm_crc32_u64(k0 >> 32, k[1]); + crc1 = _mm_crc32_u64(k0 >> 32, k[1] & m[1]); - crc2 = _mm_crc32_u64(k2, k[3]); - crc3 = _mm_crc32_u64(k2 >> 32, k[4]); + crc2 = _mm_crc32_u64(k2, k[3] & m[3]); + crc3 = _mm_crc32_u64(k2 >> 32, k[4] & m[4]); crc0 = _mm_crc32_u64(crc0, (crc1 << 32) ^ crc2); crc1 = _mm_crc32_u64(crc3, k5); @@ -273,22 +272,24 @@ hash_crc_key48(void *key, __rte_unused uint32_t key_size, uint64_t seed) } static inline uint64_t -hash_crc_key56(void *key, __rte_unused uint32_t key_size, uint64_t seed) +hash_crc_key56(void *key, void *mask, __rte_unused uint32_t key_size, + uint64_t seed) { uint64_t *k = key; + uint64_t *m = mask; uint64_t k0, k2, k5, crc0, crc1, crc2, crc3, crc4, crc5; - k0 = k[0]; - k2 = k[2]; - k5 = k[5]; + k0 = k[0] & m[0]; + k2 = k[2] & m[2]; + k5 = k[5] & m[5]; crc0 = _mm_crc32_u64(k0, seed); - crc1 = _mm_crc32_u64(k0 >> 32, k[1]); + crc1 = _mm_crc32_u64(k0 >> 32, k[1] & m[1]); - crc2 = _mm_crc32_u64(k2, k[3]); - crc3 = _mm_crc32_u64(k2 >> 32, k[4]); + crc2 = _mm_crc32_u64(k2, k[3] & m[3]); + crc3 = _mm_crc32_u64(k2 >> 32, k[4] & m[4]); - crc4 = _mm_crc32_u64(k5, k[6]); + crc4 = _mm_crc32_u64(k5, k[6] & m[6]); crc5 = k5 >> 32; crc0 = _mm_crc32_u64(crc0, (crc1 << 32) ^ crc2); @@ -300,23 +301,25 @@ hash_crc_key56(void *key, __rte_unused uint32_t key_size, uint64_t seed) } static inline uint64_t -hash_crc_key64(void *key, __rte_unused uint32_t key_size, uint64_t seed) +hash_crc_key64(void *key, void *mask, __rte_unused uint32_t key_size, + uint64_t seed) { uint64_t *k = key; + uint64_t *m = mask; uint64_t k0, k2, k5, crc0, crc1, crc2, crc3, crc4, crc5; - k0 = k[0]; - k2 = k[2]; - k5 = k[5]; + k0 = k[0] & m[0]; + k2 = k[2] & m[2]; + k5 = k[5] & m[5]; crc0 = _mm_crc32_u64(k0, seed); - crc1 = _mm_crc32_u64(k0 >> 32, k[1]); + crc1 = _mm_crc32_u64(k0 >> 32, k[1] & m[1]); - crc2 = _mm_crc32_u64(k2, k[3]); - crc3 = _mm_crc32_u64(k2 >> 32, k[4]); + crc2 = _mm_crc32_u64(k2, k[3] & m[3]); + crc3 = _mm_crc32_u64(k2 >> 32, k[4] & m[4]); - crc4 = _mm_crc32_u64(k5, k[6]); - crc5 = _mm_crc32_u64(k5 >> 32, k[7]); + crc4 = _mm_crc32_u64(k5, k[6] & m[6]); + crc5 = _mm_crc32_u64(k5 >> 32, k[7] & m[7]); crc0 = _mm_crc32_u64(crc0, (crc1 << 32) ^ crc2); crc1 = _mm_crc32_u64(crc3, (crc4 << 32) ^ crc5); @@ -335,6 +338,8 @@ hash_crc_key64(void *key, __rte_unused uint32_t key_size, uint64_t seed) #define hash_default_key56 hash_crc_key56 #define hash_default_key64 hash_crc_key64 +#elif defined(RTE_ARCH_ARM64) +#include "hash_func_arm64.h" #else #define hash_default_key8 hash_xor_key8