]> git.sesse.net Git - casparcg/blob - common/memshfl.h
Updated changelog for 2.1
[casparcg] / common / memshfl.h
1 /*
2 * Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
3 *
4 * This file is part of CasparCG (www.casparcg.com).
5 *
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.
10 *
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.
15 *
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/>.
18 *
19 * Author: Robert Nagy, ronag89@gmail.com
20 */
21
22 #pragma once
23
24 #include <intrin.h>
25
26 namespace caspar {
27         
28 static void* aligned_memshfl(void* dest, const void* source, size_t count, int m1, int m2, int m3, int m4)
29 {    
30         __m128i*           dest128 = reinterpret_cast<__m128i*>(dest);  
31         const __m128i* source128 = reinterpret_cast<const __m128i*>(source);
32
33         count /= 16; // 128 bit
34
35         __m128i xmm0, xmm1, xmm2, xmm3;
36
37         const __m128i mask128 = _mm_set_epi32(m1, m2, m3, m4);
38         for(size_t n = 0; n < count/4; ++n)
39         {
40                 xmm0 = _mm_load_si128(source128++);     
41                 xmm1 = _mm_load_si128(source128++);     
42                 xmm2 = _mm_load_si128(source128++);     
43                 xmm3 = _mm_load_si128(source128++);     
44
45                 _mm_stream_si128(dest128++, _mm_shuffle_epi8(xmm0, mask128));
46                 _mm_stream_si128(dest128++, _mm_shuffle_epi8(xmm1, mask128));
47                 _mm_stream_si128(dest128++, _mm_shuffle_epi8(xmm2, mask128));
48                 _mm_stream_si128(dest128++, _mm_shuffle_epi8(xmm3, mask128));
49         }
50         return dest;
51 }
52
53
54 }