]> git.sesse.net Git - casparcg/blob - common/memshfl.h
Fix a few Clang warnings.
[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 #ifdef _MSC_VER
25 #include <intrin.h>
26 #else
27 #include <tmmintrin.h>
28 #endif
29
30 namespace caspar {
31         
32 static void* aligned_memshfl(void* dest, const void* source, size_t count, int m1, int m2, int m3, int m4)
33 {    
34         __m128i*           dest128 = reinterpret_cast<__m128i*>(dest);  
35         const __m128i* source128 = reinterpret_cast<const __m128i*>(source);
36
37         count /= 16; // 128 bit
38
39         __m128i xmm0, xmm1, xmm2, xmm3;
40
41         const __m128i mask128 = _mm_set_epi32(m1, m2, m3, m4);
42         for(size_t n = 0; n < count/4; ++n)
43         {
44                 xmm0 = _mm_load_si128(source128++);     
45                 xmm1 = _mm_load_si128(source128++);     
46                 xmm2 = _mm_load_si128(source128++);     
47                 xmm3 = _mm_load_si128(source128++);     
48
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));
53         }
54         return dest;
55 }
56
57
58 }