- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
void decode_chunk(const char* s, uint8_t* out)
{
__m128i a = _mm_loadu_si128((const __m128i*)s);
__m128i u = _mm_and_si128(a, _mm_set1_epi8(0x74));
u = _mm_add_epi8(u, _mm_set1_epi8(0x04));
u = _mm_srli_epi32(u, 0x03);
u = _mm_and_si128(u, _mm_set1_epi8(0x0F));
u = _mm_shuffle_epi8(_mm_set_epi32(0xB9B9B9B9, 0xBFBFBFBF, 0x04041013, 0x00000000), u);
a = _mm_add_epi8(a, u);
__m128i m1 = _mm_set1_epi32(0xFF00FF00);
__m128i m2 = _mm_set1_epi32(0xFFFF0000);
a = _mm_shuffle_epi8(a, _mm_set_epi32(0x00010203, 0x04050607, 0x08090A0B, 0x0C0D0E0F));
a = _mm_or_si128(_mm_srli_epi32(_mm_and_si128(m1, a), 2), _mm_andnot_si128(m1, a));
a = _mm_or_si128(_mm_srli_epi32(_mm_and_si128(m2, a), 4), _mm_andnot_si128(m2, a));
a = _mm_shuffle_epi8(a, _mm_set_epi32(0x80808080, 0x00010204, 0x05060809, 0x0A0C0D0E));
_mm_storeu_si128((__m128i*)out, a);
}
Байтоёбский парсинг base64 (16 символов → 12 байт).
По мотивам http://govnokod.ru/12822#comment173404