1 /*  Copyright (C) 2014  Povilas Kanapickas <povilas@radix.lt>
2 
3     Distributed under the Boost Software License, Version 1.0.
4         (See accompanying file LICENSE_1_0.txt or copy at
5             http://www.boost.org/LICENSE_1_0.txt)
6 */
7 
8 #ifndef LIBSIMDPP_SIMDPP_CORE_MAKE_INT_H
9 #define LIBSIMDPP_SIMDPP_CORE_MAKE_INT_H
10 
11 #ifndef LIBSIMDPP_SIMD_H
12     #error "This file must be included through simd.h"
13 #endif
14 
15 #include <simdpp/types.h>
16 #include <simdpp/detail/insn/make_const.h>
17 
18 namespace simdpp {
19 namespace SIMDPP_ARCH_NAMESPACE {
20 
21 /** Creates a vector from signed integer values known at compile-time.
22     The result of this function may be assigned or converted to a vector of any
23     type: standard conversions are used to convert the arguments. All
24     conversions and other overhead is performed at compile-time thus even if the
25     minimal optimization level is selected, the function results in a simple
26     load from memory.
27 
28     The function is not guaranteed to have adequate performance if the
29     arguments are not known at compile-time.
30 
31     If the vector has fewer elements than the number of the parameters this
32     function accepts then the extra values are discarded.
33 
34     @par 1 parameter version
35     @code
36         | 0  1  2  3  ... n  |
37     r = [ v0 v0 v0 v0 ... v0 ]
38     @endcode
39 
40     @par 2 parameters version
41     @code
42         | 0  1  2  3  ... n  |
43     r = [ v0 v1 v0 v1 ... v1 ]
44     @endcode
45 
46     @par 4 parameters version
47     @code
48         | 0  1  2  3  ... n  |
49     r = [ v0 v1 v2 v3 ... v3 ]
50     @endcode
51 
52     @par 8 parameters version
53     @code
54         | 0  1  ..  7  8  ... n  |
55     r = [ v0 v1 .. v7 v0  ... v7 ]
56     @endcode
57 */
58 // FIXME: return empty expr
make_int(int64_t v0)59 SIMDPP_INL expr_vec_make_const<int64_t,1> make_int(int64_t v0)
60 {
61     expr_vec_make_const<int64_t,1> a;
62     a.a[0] = v0;
63     return a;
64 }
65 
66 static SIMDPP_INL
make_int(int64_t v0,int64_t v1)67 expr_vec_make_const<int64_t,2> make_int(int64_t v0, int64_t v1)
68 {
69     expr_vec_make_const<int64_t,2> a;
70     a.a[0] = v0;  a.a[1] = v1;
71     return a;
72 }
73 
74 static SIMDPP_INL
75 expr_vec_make_const<int64_t,4>
make_int(int64_t v0,int64_t v1,int64_t v2,int64_t v3)76     make_int(int64_t v0, int64_t v1, int64_t v2, int64_t v3)
77 {
78     expr_vec_make_const<int64_t,4> a;
79     a.a[0] = v0;  a.a[1] = v1;  a.a[2] = v2;  a.a[3] = v3;
80     return a;
81 }
82 
83 static SIMDPP_INL
84 expr_vec_make_const<int64_t,8>
make_int(int64_t v0,int64_t v1,int64_t v2,int64_t v3,int64_t v4,int64_t v5,int64_t v6,int64_t v7)85     make_int(int64_t v0, int64_t v1, int64_t v2, int64_t v3,
86              int64_t v4, int64_t v5, int64_t v6, int64_t v7)
87 {
88     expr_vec_make_const<int64_t,8> a;
89     a.a[0] = v0;  a.a[1] = v1;  a.a[2] = v2;  a.a[3] = v3;
90     a.a[4] = v4;  a.a[5] = v5;  a.a[6] = v6;  a.a[7] = v7;
91     return a;
92 }
93 
94 static SIMDPP_INL
95 expr_vec_make_const<int64_t,16>
make_int(int64_t v0,int64_t v1,int64_t v2,int64_t v3,int64_t v4,int64_t v5,int64_t v6,int64_t v7,int64_t v8,int64_t v9,int64_t v10,int64_t v11,int64_t v12,int64_t v13,int64_t v14,int64_t v15)96     make_int(int64_t v0,  int64_t v1,  int64_t v2,  int64_t v3,
97              int64_t v4,  int64_t v5,  int64_t v6,  int64_t v7,
98              int64_t v8,  int64_t v9,  int64_t v10, int64_t v11,
99              int64_t v12, int64_t v13, int64_t v14, int64_t v15)
100 {
101     expr_vec_make_const<int64_t,16> a;
102     a.a[0] = v0;    a.a[1] = v1;    a.a[2] = v2;    a.a[3] = v3;
103     a.a[4] = v4;    a.a[5] = v5;    a.a[6] = v6;    a.a[7] = v7;
104     a.a[8] = v8;    a.a[9] = v9;    a.a[10] = v10;  a.a[11] = v11;
105     a.a[12] = v12;  a.a[13] = v13;  a.a[14] = v14;  a.a[15] = v15;
106     return a;
107 }
108 
109 template<class V> SIMDPP_INL
make_int(int64_t v0)110 V make_int(int64_t v0)
111 {
112     static_assert(is_vector<V>::value && !is_mask<V>::value,
113                   "V must be a non-mask vector");
114     expr_vec_make_const<int64_t,1> a;
115     a.a[0] = v0;
116     return detail::insn::i_make_const_any<V>(a);
117 }
118 
119 template<class V> SIMDPP_INL
make_int(int64_t v0,int64_t v1)120 V make_int(int64_t v0, int64_t v1)
121 {
122     static_assert(is_vector<V>::value && !is_mask<V>::value,
123                   "V must be a non-mask vector");
124     expr_vec_make_const<int64_t,2> a;
125     a.a[0] = v0;  a.a[1] = v1;
126     return detail::insn::i_make_const_any<V>(a);
127 }
128 
129 template<class V> SIMDPP_INL
make_int(int64_t v0,int64_t v1,int64_t v2,int64_t v3)130 V make_int(int64_t v0, int64_t v1, int64_t v2, int64_t v3)
131 {
132     static_assert(is_vector<V>::value && !is_mask<V>::value,
133                   "V must be a non-mask vector");
134     expr_vec_make_const<int64_t,4> a;
135     a.a[0] = v0;  a.a[1] = v1;  a.a[2] = v2;  a.a[3] = v3;
136     return detail::insn::i_make_const_any<V>(a);
137 }
138 
139 template<class V> SIMDPP_INL
make_int(int64_t v0,int64_t v1,int64_t v2,int64_t v3,int64_t v4,int64_t v5,int64_t v6,int64_t v7)140 V make_int(int64_t v0, int64_t v1, int64_t v2, int64_t v3,
141            int64_t v4, int64_t v5, int64_t v6, int64_t v7)
142 {
143     static_assert(is_vector<V>::value && !is_mask<V>::value,
144                   "V must be a non-mask vector");
145     expr_vec_make_const<int64_t,8> a;
146     a.a[0] = v0;  a.a[1] = v1;  a.a[2] = v2;  a.a[3] = v3;
147     a.a[4] = v4;  a.a[5] = v5;  a.a[6] = v6;  a.a[7] = v7;
148     return detail::insn::i_make_const_any<V>(a);
149 }
150 
151 template<class V> SIMDPP_INL
make_int(int64_t v0,int64_t v1,int64_t v2,int64_t v3,int64_t v4,int64_t v5,int64_t v6,int64_t v7,int64_t v8,int64_t v9,int64_t v10,int64_t v11,int64_t v12,int64_t v13,int64_t v14,int64_t v15)152 V make_int(int64_t v0,  int64_t v1,  int64_t v2,  int64_t v3,
153            int64_t v4,  int64_t v5,  int64_t v6,  int64_t v7,
154            int64_t v8,  int64_t v9,  int64_t v10, int64_t v11,
155            int64_t v12, int64_t v13, int64_t v14, int64_t v15)
156 {
157     static_assert(is_vector<V>::value && !is_mask<V>::value,
158                   "V must be a non-mask vector");
159     expr_vec_make_const<int64_t,16> a;
160     a.a[0] = v0;    a.a[1] = v1;    a.a[2] = v2;    a.a[3] = v3;
161     a.a[4] = v4;    a.a[5] = v5;    a.a[6] = v6;    a.a[7] = v7;
162     a.a[8] = v8;    a.a[9] = v9;    a.a[10] = v10;  a.a[11] = v11;
163     a.a[12] = v12;  a.a[13] = v13;  a.a[14] = v14;  a.a[15] = v15;
164     return detail::insn::i_make_const_any<V>(a);
165 }
166 
167 } // namespace SIMDPP_ARCH_NAMESPACE
168 } // namespace simdpp
169 
170 #endif
171 
172