4 * Copyright (C) Cavium networks Ltd. 2017.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
16 * * Neither the name of Cavium networks nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #ifndef __RTE_LRU_ARM64_H__
34 #define __RTE_LRU_ARM64_H__
43 #ifndef RTE_TABLE_HASH_LRU_STRATEGY
44 #ifdef RTE_MACHINE_CPUFLAG_NEON
45 #define RTE_TABLE_HASH_LRU_STRATEGY 3
46 #else /* if no NEON, use simple scalar version */
47 #define RTE_TABLE_HASH_LRU_STRATEGY 1
51 #if RTE_TABLE_HASH_LRU_STRATEGY == 3
53 #define lru_init(bucket) \
54 { bucket->lru_list = ~0LLU; }
57 f_lru_pos(uint64_t lru_list)
59 /* Compare the vector to zero vector */
60 uint16x4_t lru_vec = vld1_u16((uint16_t *)&lru_list);
61 uint16x4_t min_vec = vmov_n_u16(vminv_u16(lru_vec));
62 uint64_t mask = vget_lane_u64(vreinterpret_u64_u16(
63 vceq_u16(min_vec, lru_vec)), 0);
64 return __builtin_clzl(mask) >> 4;
66 #define lru_pos(bucket) f_lru_pos(bucket->lru_list)
68 #define lru_update(bucket, mru_val) \
70 const uint64_t orvals[] = {0xFFFFLLU, 0xFFFFLLU << 16, \
71 0xFFFFLLU << 32, 0xFFFFLLU << 48, 0LLU}; \
72 const uint64_t decs[] = {0x1000100010001LLU, 0}; \
73 uint64x1_t lru = vdup_n_u64(bucket->lru_list); \
74 uint64x1_t vdec = vdup_n_u64(decs[mru_val>>2]); \
75 bucket->lru_list = vget_lane_u64(vreinterpret_u64_u16( \
76 vsub_u16(vreinterpret_u16_u64(lru), \
77 vreinterpret_u16_u64(vdec))), \
79 bucket->lru_list |= orvals[mru_val]; \