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