2 * Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
4 * This file is part of CasparCG (www.casparcg.com).
6 * CasparCG is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * CasparCG is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with CasparCG. If not, see <http://www.gnu.org/licenses/>.
19 * Author: Robert Nagy, ronag89@gmail.com
27 #include <tmmintrin.h>
32 static void* aligned_memshfl(void* dest, const void* source, size_t count, int m1, int m2, int m3, int m4)
34 __m128i* dest128 = reinterpret_cast<__m128i*>(dest);
35 const __m128i* source128 = reinterpret_cast<const __m128i*>(source);
37 count /= 16; // 128 bit
39 __m128i xmm0, xmm1, xmm2, xmm3;
41 const __m128i mask128 = _mm_set_epi32(m1, m2, m3, m4);
42 for(size_t n = 0; n < count/4; ++n)
44 xmm0 = _mm_load_si128(source128++);
45 xmm1 = _mm_load_si128(source128++);
46 xmm2 = _mm_load_si128(source128++);
47 xmm3 = _mm_load_si128(source128++);
49 _mm_stream_si128(dest128++, _mm_shuffle_epi8(xmm0, mask128));
50 _mm_stream_si128(dest128++, _mm_shuffle_epi8(xmm1, mask128));
51 _mm_stream_si128(dest128++, _mm_shuffle_epi8(xmm2, mask128));
52 _mm_stream_si128(dest128++, _mm_shuffle_epi8(xmm3, mask128));