Vc  1.3.2-dev
SIMD Vector Classes for C++
set.h
1 /* This file is part of the Vc library. {{{
2 Copyright © 2013-2015 Matthias Kretz <kretz@kde.org>
3 
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions are met:
6  * Redistributions of source code must retain the above copyright
7  notice, this list of conditions and the following disclaimer.
8  * Redistributions in binary form must reproduce the above copyright
9  notice, this list of conditions and the following disclaimer in the
10  documentation and/or other materials provided with the distribution.
11  * Neither the names of contributing organizations nor the
12  names of its contributors may be used to endorse or promote products
13  derived from this software without specific prior written permission.
14 
15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
19 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 
26 }}}*/
27 
28 #ifndef VC_COMMON_SET_H_
29 #define VC_COMMON_SET_H_
30 
31 #include "macros.h"
32 namespace Vc_VERSIONED_NAMESPACE
33 {
34 namespace
35 {
36  static Vc_INTRINSIC Vc_CONST __m128i set(unsigned short x0, unsigned short x1, unsigned short x2, unsigned short x3,
37  unsigned short x4, unsigned short x5, unsigned short x6, unsigned short x7)
38  {
39 #if defined(Vc_GNU_ASM)
40 #if 0 // defined(__x86_64__)
41  // it appears that the 32bit variant is always faster
42  __m128i r;
43  unsigned long long tmp0 = x3; tmp0 = (tmp0 << 16) | x2;
44  unsigned long long tmp1 = x1; tmp1 = (tmp1 << 16) | x0;
45  asm("vmovq %1,%0" : "=x"(r) : "r"((tmp0 << 32) | tmp1));
46  unsigned long long tmp2 = x7; tmp2 = (tmp2 << 16) | x6;
47  unsigned long long tmp3 = x5; tmp3 = (tmp3 << 16) | x4;
48  asm("vpinsrq $1,%1,%0,%0" : "+x"(r) : "r"((tmp2 << 32) | tmp3));
49  return r;
50 #elif defined(Vc_USE_VEX_CODING)
51  __m128i r0, r1;
52  unsigned int tmp0 = x1; tmp0 = (tmp0 << 16) | x0;
53  unsigned int tmp1 = x3; tmp1 = (tmp1 << 16) | x2;
54  unsigned int tmp2 = x5; tmp2 = (tmp2 << 16) | x4;
55  unsigned int tmp3 = x7; tmp3 = (tmp3 << 16) | x6;
56  asm("vmovd %1,%0" : "=x"(r0) : "r"(tmp0));
57  asm("vpinsrd $1,%1,%0,%0" : "+x"(r0) : "r"(tmp1));
58  asm("vmovd %1,%0" : "=x"(r1) : "r"(tmp2));
59  asm("vpinsrd $1,%1,%0,%0" : "+x"(r1) : "r"(tmp3));
60  asm("vpunpcklqdq %1,%0,%0" : "+x"(r0) : "x"(r1));
61  return r0;
62 #else
63  __m128i r0, r1;
64  unsigned int tmp0 = x1; tmp0 = (tmp0 << 16) | x0;
65  unsigned int tmp1 = x3; tmp1 = (tmp1 << 16) | x2;
66  unsigned int tmp2 = x5; tmp2 = (tmp2 << 16) | x4;
67  unsigned int tmp3 = x7; tmp3 = (tmp3 << 16) | x6;
68  asm("movd %1,%0" : "=x"(r0) : "r"(tmp0));
69  asm("pinsrd $1,%1,%0" : "+x"(r0) : "r"(tmp1));
70  asm("movd %1,%0" : "=x"(r1) : "r"(tmp2));
71  asm("pinsrd $1,%1,%0" : "+x"(r1) : "r"(tmp3));
72  asm("punpcklqdq %1,%0" : "+x"(r0) : "x"(r1));
73  return r0;
74 #endif
75 #else
76  unsigned int tmp0 = x1; tmp0 = (tmp0 << 16) | x0;
77  unsigned int tmp1 = x3; tmp1 = (tmp1 << 16) | x2;
78  unsigned int tmp2 = x5; tmp2 = (tmp2 << 16) | x4;
79  unsigned int tmp3 = x7; tmp3 = (tmp3 << 16) | x6;
80  return _mm_setr_epi32(tmp0, tmp1, tmp2, tmp3);
81 #endif
82  }
83  static Vc_INTRINSIC Vc_CONST __m128i set(short x0, short x1, short x2, short x3, short x4, short x5, short x6, short x7)
84  {
85  return set(static_cast<unsigned short>(x0), static_cast<unsigned short>(x1), static_cast<unsigned short>(x2),
86  static_cast<unsigned short>(x3), static_cast<unsigned short>(x4), static_cast<unsigned short>(x5),
87  static_cast<unsigned short>(x6), static_cast<unsigned short>(x7));
88  }
89 } // anonymous namespace
90 } // namespace Vc
91 
92 #endif // VC_COMMON_SET_H_