1static inline __m128i
2enc_reshuffle (__m128i in)
3{
4 // Input, bytes MSB to LSB:
5 // 0 0 0 0 l k j i h g f e d c b a
6
7 in = _mm_shuffle_epi8(in, _mm_set_epi8(
8 10, 11, 9, 10,
9 7, 8, 6, 7,
10 4, 5, 3, 4,
11 1, 2, 0, 1));
12 // in, bytes MSB to LSB:
13 // k l j k
14 // h i g h
15 // e f d e
16 // b c a b
17
18 const __m128i t0 = _mm_and_si128(in, _mm_set1_epi32(0x0FC0FC00));
19 // bits, upper case are most significant bits, lower case are least significant bits
20 // 0000kkkk LL000000 JJJJJJ00 00000000
21 // 0000hhhh II000000 GGGGGG00 00000000
22 // 0000eeee FF000000 DDDDDD00 00000000
23 // 0000bbbb CC000000 AAAAAA00 00000000
24
25 const __m128i t1 = _mm_mulhi_epu16(t0, _mm_set1_epi32(0x04000040));
26 // 00000000 00kkkkLL 00000000 00JJJJJJ
27 // 00000000 00hhhhII 00000000 00GGGGGG
28 // 00000000 00eeeeFF 00000000 00DDDDDD
29 // 00000000 00bbbbCC 00000000 00AAAAAA
30
31 const __m128i t2 = _mm_and_si128(in, _mm_set1_epi32(0x003F03F0));
32 // 00000000 00llllll 000000jj KKKK0000
33 // 00000000 00iiiiii 000000gg HHHH0000
34 // 00000000 00ffffff 000000dd EEEE0000
35 // 00000000 00cccccc 000000aa BBBB0000
36
37 const __m128i t3 = _mm_mullo_epi16(t2, _mm_set1_epi32(0x01000010));
38 // 00llllll 00000000 00jjKKKK 00000000
39 // 00iiiiii 00000000 00ggHHHH 00000000
40 // 00ffffff 00000000 00ddEEEE 00000000
41 // 00cccccc 00000000 00aaBBBB 00000000
42
43 return _mm_or_si128(t1, t3);
44 // 00llllll 00kkkkLL 00jjKKKK 00JJJJJJ
45 // 00iiiiii 00hhhhII 00ggHHHH 00GGGGGG
46 // 00ffffff 00eeeeFF 00ddEEEE 00DDDDDD
47 // 00cccccc 00bbbbCC 00aaBBBB 00AAAAAA
48}
49