34 #ifndef __INCLUDE_RTE_LRU_X86_H__
35 #define __INCLUDE_RTE_LRU_X86_H__
43 #include <rte_config.h>
45 #ifndef RTE_TABLE_HASH_LRU_STRATEGY
46 #define RTE_TABLE_HASH_LRU_STRATEGY 2
49 #if RTE_TABLE_HASH_LRU_STRATEGY == 2
51 #if defined(RTE_TOOLCHAIN_GCC) && (GCC_VERSION > 40306)
52 #include <x86intrin.h>
54 #include <emmintrin.h>
55 #include <smmintrin.h>
56 #include <xmmintrin.h>
59 #define lru_init(bucket) \
60 { bucket->lru_list = 0x0000000100020003LLU; }
62 #define lru_pos(bucket) (bucket->lru_list & 0xFFFFLLU)
64 #define lru_update(bucket, mru_val) \
67 static uint64_t masks[10] = { \
69 0x0100070605040302, 0x8080808080808080, \
70 0x0302070605040100, 0x8080808080808080, \
71 0x0504070603020100, 0x8080808080808080, \
72 0x0706050403020100, 0x8080808080808080, \
73 0x0706050403020100, 0x8080808080808080}; \
75 uint64_t mru2 = mru_val; \
76 uint64_t mru3 = mru2 | (mru2 << 16); \
77 uint64_t lru = bucket->lru_list; \
79 uint64_t mru = lru ^ ((mru3 << 32) | mru3); \
80 __m128i c = _mm_cvtsi64_si128(mru); \
81 __m128i b = _mm_cvtsi64_si128(lru); \
83 __m128i d = _mm_minpos_epu16(c); \
85 unsigned int pos = _mm_extract_epi16(d, 1); \
87 __m128i k = _mm_shuffle_epi8(b, *((__m128i *) &masks[2 * pos]));\
89 bucket->lru_list = _mm_extract_epi64(k, 0); \
93 #elif RTE_TABLE_HASH_LRU_STRATEGY == 3
95 #if defined(RTE_TOOLCHAIN_GCC) && (GCC_VERSION > 40306)
96 #include <x86intrin.h>
98 #include <emmintrin.h>
99 #include <smmintrin.h>
100 #include <xmmintrin.h>
103 #define lru_init(bucket) \
104 { bucket->lru_list = ~0LLU; }
107 f_lru_pos(uint64_t lru_list)
109 __m128i lst = _mm_set_epi64x((uint64_t)-1, lru_list);
110 __m128i min = _mm_minpos_epu16(lst);
111 return _mm_extract_epi16(min, 1);
113 #define lru_pos(bucket) f_lru_pos(bucket->lru_list)
115 #define lru_update(bucket, mru_val) \
117 const uint64_t orvals[] = {0xFFFFLLU, 0xFFFFLLU << 16, \
118 0xFFFFLLU << 32, 0xFFFFLLU << 48, 0LLU}; \
119 const uint64_t decs[] = {0x1000100010001LLU, 0}; \
120 __m128i lru = _mm_cvtsi64_si128(bucket->lru_list); \
121 __m128i vdec = _mm_cvtsi64_si128(decs[mru_val>>2]); \
122 lru = _mm_subs_epu16(lru, vdec); \
123 bucket->lru_list = _mm_extract_epi64(lru, 0) | orvals[mru_val]; \