DPDK  17.11.10
rte_lru_arm64.h
1 /*
2  * BSD LICENSE
3  *
4  * Copyright (C) Cavium, Inc. 2017.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
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
15  * distribution.
16  * * Neither the name of Cavium, Inc 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.
19  *
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.
31  */
32 
33 #ifndef __RTE_LRU_ARM64_H__
34 #define __RTE_LRU_ARM64_H__
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
40 #include <stdint.h>
41 #include <rte_vect.h>
42 
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
48 #endif
49 #endif
50 
51 #if RTE_TABLE_HASH_LRU_STRATEGY == 3
52 
53 #define lru_init(bucket) \
54  { bucket->lru_list = ~0LLU; }
55 
56 static inline int
57 f_lru_pos(uint64_t lru_list)
58 {
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;
65 }
66 #define lru_pos(bucket) f_lru_pos(bucket->lru_list)
67 
68 #define lru_update(bucket, mru_val) \
69 do { \
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))), \
78  0); \
79  bucket->lru_list |= orvals[mru_val]; \
80 } while (0)
81 
82 #endif
83 
84 #ifdef __cplusplus
85 }
86 #endif
87 
88 #endif