34 #ifndef __INCLUDE_RTE_LRU_X86_H__
35 #define __INCLUDE_RTE_LRU_X86_H__
43 #ifndef RTE_TABLE_HASH_LRU_STRATEGY
44 #define RTE_TABLE_HASH_LRU_STRATEGY 2
47 #if RTE_TABLE_HASH_LRU_STRATEGY == 2
49 #if defined(RTE_TOOLCHAIN_GCC) && (GCC_VERSION > 40306)
50 #include <x86intrin.h>
52 #include <emmintrin.h>
53 #include <smmintrin.h>
54 #include <xmmintrin.h>
57 #define lru_init(bucket) \
58 { bucket->lru_list = 0x0000000100020003LLU; }
60 #define lru_pos(bucket) (bucket->lru_list & 0xFFFFLLU)
62 #define lru_update(bucket, mru_val) \
65 static uint64_t masks[10] = { \
67 0x0100070605040302, 0x8080808080808080, \
68 0x0302070605040100, 0x8080808080808080, \
69 0x0504070603020100, 0x8080808080808080, \
70 0x0706050403020100, 0x8080808080808080, \
71 0x0706050403020100, 0x8080808080808080}; \
73 uint64_t mru2 = mru_val; \
74 uint64_t mru3 = mru2 | (mru2 << 16); \
75 uint64_t lru = bucket->lru_list; \
77 uint64_t mru = lru ^ ((mru3 << 32) | mru3); \
78 __m128i c = _mm_cvtsi64_si128(mru); \
79 __m128i b = _mm_cvtsi64_si128(lru); \
81 __m128i d = _mm_minpos_epu16(c); \
83 unsigned int pos = _mm_extract_epi16(d, 1); \
85 __m128i k = _mm_shuffle_epi8(b, *((__m128i *) &masks[2 * pos]));\
87 bucket->lru_list = _mm_extract_epi64(k, 0); \
91 #elif RTE_TABLE_HASH_LRU_STRATEGY == 3
93 #if defined(RTE_TOOLCHAIN_GCC) && (GCC_VERSION > 40306)
94 #include <x86intrin.h>
96 #include <emmintrin.h>
97 #include <smmintrin.h>
98 #include <xmmintrin.h>
101 #define lru_init(bucket) \
102 { bucket->lru_list = ~0LLU; }
105 f_lru_pos(uint64_t lru_list)
107 __m128i lst = _mm_set_epi64x((uint64_t)-1, lru_list);
108 __m128i min = _mm_minpos_epu16(lst);
109 return _mm_extract_epi16(min, 1);
111 #define lru_pos(bucket) f_lru_pos(bucket->lru_list)
113 #define lru_update(bucket, mru_val) \
115 const uint64_t orvals[] = {0xFFFFLLU, 0xFFFFLLU << 16, \
116 0xFFFFLLU << 32, 0xFFFFLLU << 48, 0LLU}; \
117 const uint64_t decs[] = {0x1000100010001LLU, 0}; \
118 __m128i lru = _mm_cvtsi64_si128(bucket->lru_list); \
119 __m128i vdec = _mm_cvtsi64_si128(decs[mru_val>>2]); \
120 lru = _mm_subs_epu16(lru, vdec); \
121 bucket->lru_list = _mm_extract_epi64(lru, 0) | orvals[mru_val]; \