5#ifndef __INCLUDE_RTE_LRU_X86_H__
6#define __INCLUDE_RTE_LRU_X86_H__
10#include <rte_config.h>
13#ifndef RTE_TABLE_HASH_LRU_STRATEGY
14#define RTE_TABLE_HASH_LRU_STRATEGY 2
17#if RTE_TABLE_HASH_LRU_STRATEGY == 2
27#define lru_init(bucket) \
28 { bucket->lru_list = 0x0000000100020003LLU; }
30#define lru_pos(bucket) (bucket->lru_list & 0xFFFFLLU)
32#define lru_update(bucket, mru_val) \
35 static uint64_t masks[10] = { \
37 0x0100070605040302, 0x8080808080808080, \
38 0x0302070605040100, 0x8080808080808080, \
39 0x0504070603020100, 0x8080808080808080, \
40 0x0706050403020100, 0x8080808080808080, \
41 0x0706050403020100, 0x8080808080808080}; \
43 uint64_t mru2 = mru_val; \
44 uint64_t mru3 = mru2 | (mru2 << 16); \
45 uint64_t lru = bucket->lru_list; \
47 uint64_t mru = lru ^ ((mru3 << 32) | mru3); \
48 __m128i c = _mm_cvtsi64_si128(mru); \
49 __m128i b = _mm_cvtsi64_si128(lru); \
51 __m128i d = _mm_minpos_epu16(c); \
53 unsigned int pos = _mm_extract_epi16(d, 1); \
55 __m128i k = _mm_shuffle_epi8(b, *((__m128i *) &masks[2 * pos]));\
57 bucket->lru_list = _mm_extract_epi64(k, 0); \
61#elif RTE_TABLE_HASH_LRU_STRATEGY == 3
71#define lru_init(bucket) \
72 { bucket->lru_list = ~0LLU; }
75f_lru_pos(uint64_t lru_list)
77 __m128i lst = _mm_set_epi64x((uint64_t)-1, lru_list);
78 __m128i min = _mm_minpos_epu16(lst);
79 return _mm_extract_epi16(min, 1);
81#define lru_pos(bucket) f_lru_pos(bucket->lru_list)
83#define lru_update(bucket, mru_val) \
85 const uint64_t orvals[] = {0xFFFFLLU, 0xFFFFLLU << 16, \
86 0xFFFFLLU << 32, 0xFFFFLLU << 48, 0LLU}; \
87 const uint64_t decs[] = {0x1000100010001LLU, 0}; \
88 __m128i lru = _mm_cvtsi64_si128(bucket->lru_list); \
89 __m128i vdec = _mm_cvtsi64_si128(decs[mru_val>>2]); \
90 lru = _mm_subs_epu16(lru, vdec); \
91 bucket->lru_list = _mm_extract_epi64(lru, 0) | orvals[mru_val]; \