Klement Sekera | 470a011 | 2017-03-08 05:21:24 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 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 | #undef CLIB_CUCKOO_TYPE |
| 16 | |
| 17 | #define CLIB_CUCKOO_TYPE _8_8 |
| 18 | #define CLIB_CUCKOO_KVP_PER_BUCKET (4) |
| 19 | #define CLIB_CUCKOO_LOG2_KVP_PER_BUCKET (2) |
| 20 | #define CLIB_CUCKOO_BFS_MAX_STEPS (2000) |
| 21 | #define CLIB_CUCKOO_BFS_MAX_PATH_LENGTH (8) |
| 22 | |
| 23 | #ifndef __included_cuckoo_8_8_h__ |
| 24 | #define __included_cuckoo_8_8_h__ |
| 25 | |
| 26 | #include <vppinfra/heap.h> |
| 27 | #include <vppinfra/format.h> |
| 28 | #include <vppinfra/pool.h> |
| 29 | #include <vppinfra/xxhash.h> |
| 30 | #include <vppinfra/cuckoo_debug.h> |
| 31 | #include <vppinfra/cuckoo_common.h> |
| 32 | |
| 33 | #undef CLIB_CUCKOO_OPTIMIZE_PREFETCH |
| 34 | #undef CLIB_CUCKOO_OPTIMIZE_CMP_REDUCED_HASH |
| 35 | #undef CLIB_CUCKOO_OPTIMIZE_UNROLL |
| 36 | #undef CLIB_CUCKOO_OPTIMIZE_USE_COUNT_LIMITS_SEARCH |
| 37 | #define CLIB_CUCKOO_OPTIMIZE_PREFETCH 1 |
| 38 | #define CLIB_CUCKOO_OPTIMIZE_CMP_REDUCED_HASH 1 |
| 39 | #define CLIB_CUCKOO_OPTIMIZE_UNROLL 1 |
| 40 | #define CLIB_CUCKOO_OPTIMIZE_USE_COUNT_LIMITS_SEARCH 1 |
| 41 | |
Gabriel Ganne | a19d7b8 | 2017-10-23 08:54:50 +0200 | [diff] [blame] | 42 | #if __SSE4_2__ && !defined (__i386__) |
Klement Sekera | 470a011 | 2017-03-08 05:21:24 +0100 | [diff] [blame] | 43 | #include <x86intrin.h> |
Gabriel Ganne | a19d7b8 | 2017-10-23 08:54:50 +0200 | [diff] [blame] | 44 | #endif |
Klement Sekera | 470a011 | 2017-03-08 05:21:24 +0100 | [diff] [blame] | 45 | |
| 46 | /** 8 octet key, 8 octet key value pair */ |
| 47 | typedef struct |
| 48 | { |
| 49 | u64 key; /**< the key */ |
| 50 | u64 value; /**< the value */ |
| 51 | } clib_cuckoo_kv_8_8_t; |
| 52 | |
| 53 | /** Decide if a clib_cuckoo_kv_8_8_t instance is free |
| 54 | @param v- pointer to the (key,value) pair |
| 55 | */ |
| 56 | always_inline int |
| 57 | clib_cuckoo_kv_is_free_8_8 (const clib_cuckoo_kv_8_8_t * v) |
| 58 | { |
| 59 | if (v->key == ~0ULL && v->value == ~0ULL) |
| 60 | return 1; |
| 61 | return 0; |
| 62 | } |
| 63 | |
| 64 | always_inline void |
| 65 | clib_cuckoo_kv_set_free_8_8 (clib_cuckoo_kv_8_8_t * v) |
| 66 | { |
| 67 | memset (v, 0xff, sizeof (*v)); |
| 68 | } |
| 69 | |
| 70 | /** Format a clib_cuckoo_kv_8_8_t instance |
| 71 | @param s - u8 * vector under construction |
| 72 | @param args (vararg) - the (key,value) pair to format |
| 73 | @return s - the u8 * vector under construction |
| 74 | */ |
| 75 | always_inline u8 * |
| 76 | format_cuckoo_kvp_8_8 (u8 * s, va_list * args) |
| 77 | { |
| 78 | clib_cuckoo_kv_8_8_t *v = va_arg (*args, clib_cuckoo_kv_8_8_t *); |
| 79 | |
| 80 | if (clib_cuckoo_kv_is_free_8_8 (v)) |
| 81 | { |
| 82 | s = format (s, " -- empty -- ", v->key, v->value); |
| 83 | } |
| 84 | else |
| 85 | { |
| 86 | s = format (s, "key %llu value %llu", v->key, v->value); |
| 87 | } |
| 88 | return s; |
| 89 | } |
| 90 | |
| 91 | always_inline u64 |
| 92 | clib_cuckoo_hash_8_8 (clib_cuckoo_kv_8_8_t * v) |
| 93 | { |
Gabriel Ganne | 8e66b9b | 2017-12-14 16:20:37 +0100 | [diff] [blame] | 94 | #if defined(clib_crc32c_uses_intrinsics) && !defined (__i386__) |
| 95 | return crc32_u64 (0, v->key); |
Klement Sekera | 470a011 | 2017-03-08 05:21:24 +0100 | [diff] [blame] | 96 | #else |
| 97 | return clib_xxhash (v->key); |
| 98 | #endif |
| 99 | } |
| 100 | |
| 101 | /** Compare two clib_cuckoo_kv_8_8_t instances |
| 102 | @param a - first key |
| 103 | @param b - second key |
| 104 | */ |
| 105 | always_inline int |
| 106 | clib_cuckoo_key_compare_8_8 (u64 a, u64 b) |
| 107 | { |
| 108 | return a == b; |
| 109 | } |
| 110 | |
| 111 | #if 0 |
| 112 | #undef __included_cuckoo_template_h__ |
| 113 | #include <vppinfra/cuckoo_template.h> |
| 114 | #endif |
| 115 | |
| 116 | #endif /* __included_cuckoo_8_8_h__ */ |
| 117 | |
| 118 | /* |
| 119 | * fd.io coding-style-patch-verification: ON |
| 120 | * |
| 121 | * Local Variables: |
| 122 | * eval: (c-set-style "gnu") |
| 123 | * End: |
| 124 | */ |