5 #ifndef __INCLUDE_RTE_LRU_X86_H__ 6 #define __INCLUDE_RTE_LRU_X86_H__ 14 #include <rte_config.h> 16 #ifndef RTE_TABLE_HASH_LRU_STRATEGY 17 #define RTE_TABLE_HASH_LRU_STRATEGY 2 20 #if RTE_TABLE_HASH_LRU_STRATEGY == 2 22 #if defined(RTE_TOOLCHAIN_GCC) && (GCC_VERSION > 40306) 23 #include <x86intrin.h> 25 #include <emmintrin.h> 26 #include <smmintrin.h> 27 #include <xmmintrin.h> 30 #define lru_init(bucket) \ 31 { bucket->lru_list = 0x0000000100020003LLU; } 33 #define lru_pos(bucket) (bucket->lru_list & 0xFFFFLLU) 35 #define lru_update(bucket, mru_val) \ 38 static uint64_t masks[10] = { \ 40 0x0100070605040302, 0x8080808080808080, \ 41 0x0302070605040100, 0x8080808080808080, \ 42 0x0504070603020100, 0x8080808080808080, \ 43 0x0706050403020100, 0x8080808080808080, \ 44 0x0706050403020100, 0x8080808080808080}; \ 46 uint64_t mru2 = mru_val; \ 47 uint64_t mru3 = mru2 | (mru2 << 16); \ 48 uint64_t lru = bucket->lru_list; \ 50 uint64_t mru = lru ^ ((mru3 << 32) | mru3); \ 51 __m128i c = _mm_cvtsi64_si128(mru); \ 52 __m128i b = _mm_cvtsi64_si128(lru); \ 54 __m128i d = _mm_minpos_epu16(c); \ 56 unsigned int pos = _mm_extract_epi16(d, 1); \ 58 __m128i k = _mm_shuffle_epi8(b, *((__m128i *) &masks[2 * pos]));\ 60 bucket->lru_list = _mm_extract_epi64(k, 0); \ 64 #elif RTE_TABLE_HASH_LRU_STRATEGY == 3 66 #if defined(RTE_TOOLCHAIN_GCC) && (GCC_VERSION > 40306) 67 #include <x86intrin.h> 69 #include <emmintrin.h> 70 #include <smmintrin.h> 71 #include <xmmintrin.h> 74 #define lru_init(bucket) \ 75 { bucket->lru_list = ~0LLU; } 78 f_lru_pos(uint64_t lru_list)
80 __m128i lst = _mm_set_epi64x((uint64_t)-1, lru_list);
81 __m128i min = _mm_minpos_epu16(lst);
82 return _mm_extract_epi16(min, 1);
84 #define lru_pos(bucket) f_lru_pos(bucket->lru_list) 86 #define lru_update(bucket, mru_val) \ 88 const uint64_t orvals[] = {0xFFFFLLU, 0xFFFFLLU << 16, \ 89 0xFFFFLLU << 32, 0xFFFFLLU << 48, 0LLU}; \ 90 const uint64_t decs[] = {0x1000100010001LLU, 0}; \ 91 __m128i lru = _mm_cvtsi64_si128(bucket->lru_list); \ 92 __m128i vdec = _mm_cvtsi64_si128(decs[mru_val>>2]); \ 93 lru = _mm_subs_epu16(lru, vdec); \ 94 bucket->lru_list = _mm_extract_epi64(lru, 0) | orvals[mru_val]; \