5 #ifndef __INCLUDE_RTE_LRU_X86_H__
6 #define __INCLUDE_RTE_LRU_X86_H__
14 #include <rte_config.h>
17 #ifndef RTE_TABLE_HASH_LRU_STRATEGY
18 #define RTE_TABLE_HASH_LRU_STRATEGY 2
21 #if RTE_TABLE_HASH_LRU_STRATEGY == 2
23 #if RTE_CC_IS_GNU && (GCC_VERSION > 40306)
24 #include <x86intrin.h>
26 #include <emmintrin.h>
27 #include <smmintrin.h>
28 #include <xmmintrin.h>
31 #define lru_init(bucket) \
32 { bucket->lru_list = 0x0000000100020003LLU; }
34 #define lru_pos(bucket) (bucket->lru_list & 0xFFFFLLU)
36 #define lru_update(bucket, mru_val) \
39 static uint64_t masks[10] = { \
41 0x0100070605040302, 0x8080808080808080, \
42 0x0302070605040100, 0x8080808080808080, \
43 0x0504070603020100, 0x8080808080808080, \
44 0x0706050403020100, 0x8080808080808080, \
45 0x0706050403020100, 0x8080808080808080}; \
47 uint64_t mru2 = mru_val; \
48 uint64_t mru3 = mru2 | (mru2 << 16); \
49 uint64_t lru = bucket->lru_list; \
51 uint64_t mru = lru ^ ((mru3 << 32) | mru3); \
52 __m128i c = _mm_cvtsi64_si128(mru); \
53 __m128i b = _mm_cvtsi64_si128(lru); \
55 __m128i d = _mm_minpos_epu16(c); \
57 unsigned int pos = _mm_extract_epi16(d, 1); \
59 __m128i k = _mm_shuffle_epi8(b, *((__m128i *) &masks[2 * pos]));\
61 bucket->lru_list = _mm_extract_epi64(k, 0); \
65 #elif RTE_TABLE_HASH_LRU_STRATEGY == 3
67 #if RTE_CC_IS_GNU && (GCC_VERSION > 40306)
68 #include <x86intrin.h>
70 #include <emmintrin.h>
71 #include <smmintrin.h>
72 #include <xmmintrin.h>
75 #define lru_init(bucket) \
76 { bucket->lru_list = ~0LLU; }
79 f_lru_pos(uint64_t lru_list)
81 __m128i lst = _mm_set_epi64x((uint64_t)-1, lru_list);
82 __m128i min = _mm_minpos_epu16(lst);
83 return _mm_extract_epi16(min, 1);
85 #define lru_pos(bucket) f_lru_pos(bucket->lru_list)
87 #define lru_update(bucket, mru_val) \
89 const uint64_t orvals[] = {0xFFFFLLU, 0xFFFFLLU << 16, \
90 0xFFFFLLU << 32, 0xFFFFLLU << 48, 0LLU}; \
91 const uint64_t decs[] = {0x1000100010001LLU, 0}; \
92 __m128i lru = _mm_cvtsi64_si128(bucket->lru_list); \
93 __m128i vdec = _mm_cvtsi64_si128(decs[mru_val>>2]); \
94 lru = _mm_subs_epu16(lru, vdec); \
95 bucket->lru_list = _mm_extract_epi64(lru, 0) | orvals[mru_val]; \