blob: f355515bce4f4dd930087307026115dc21151ae2 [file] [log] [blame]
Steven0d883012018-05-11 11:06:23 -07001/*
2 * Copyright (c) 2018 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16#ifndef __included_lb_hash_hash_h__
17#define __included_lb_hash_hash_h__
18
19#include <vppinfra/crc32.h>
20#include <vppinfra/xxhash.h>
21
22#if defined(clib_crc32c_uses_intrinsics) && !defined (__i386__)
23static_always_inline u32
24lb_hash_hash (u64 k0, u64 k1, u64 k2, u64 k3, u64 k4)
25{
26 u64 val = 0;
Damjan Marion271daab2021-11-12 16:00:24 +010027 val = clib_crc32c_u64 (val, k0);
28 val = clib_crc32c_u64 (val, k1);
29 val = clib_crc32c_u64 (val, k2);
30 val = clib_crc32c_u64 (val, k3);
31 val = clib_crc32c_u64 (val, k4);
Steven0d883012018-05-11 11:06:23 -070032 return (u32) val;
33}
34
35/* Note: k0 is u64 and k1 is u32 */
36static_always_inline u32
37lb_hash_hash_2_tuples (u64 k0, u32 k1)
38{
39 u64 val = 0;
Damjan Marion271daab2021-11-12 16:00:24 +010040 val = clib_crc32c_u64 (val, k0);
41 val = clib_crc32c_u32 (val, k1);
Steven0d883012018-05-11 11:06:23 -070042 return (u32) val;
43}
44#else
45static_always_inline u32
46lb_hash_hash (u64 k0, u64 k1, u64 k2, u64 k3, u64 k4)
47{
48 u64 tmp = k0 ^ k1 ^ k2 ^ k3 ^ k4;
49 return (u32) clib_xxhash (tmp);
50}
51
52/* Note: k0 is u64 and k1 is u32 */
53static_always_inline u32
54lb_hash_hash_2_tuples (u64 k0, u32 k1)
55{
56 u64 tmp = k0 ^ k1;
57 return (u32) clib_xxhash (tmp);
58}
59#endif
60
61#endif /* __included_lb_hash_hash_h__ */
62
63/*
64 * fd.io coding-style-patch-verification: ON
65 *
66 * Local Variables:
67 * eval: (c-set-style "gnu")
68 * End:
69 */