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_FLOAT_H
9#define LIBSIMDPP_SIMDPP_CORE_MAKE_FLOAT_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
18namespace simdpp {
19namespace SIMDPP_ARCH_NAMESPACE {
20
21/** Creates a vector from floating-point 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*/
58SIMDPP_INL expr_vec_make_const<double,1> make_float(double v0)
59{
60 expr_vec_make_const<double,1> a;
61 a.a[0] = v0;
62 return a;
63}
64
65SIMDPP_INL expr_vec_make_const<double,2> make_float(double v0, double v1)
66{
67 expr_vec_make_const<double,2> a;
68 a.a[0] = v0; a.a[1] = v1;
69 return a;
70}
71
72SIMDPP_INL expr_vec_make_const<double,4>
73 make_float(double v0, double v1, double v2, double v3)
74{
75 expr_vec_make_const<double,4> a;
76 a.a[0] = v0; a.a[1] = v1; a.a[2] = v2; a.a[3] = v3;
77 return a;
78}
79
80SIMDPP_INL expr_vec_make_const<double,8>
81 make_float(double v0, double v1, double v2, double v3,
82 double v4, double v5, double v6, double v7)
83{
84 expr_vec_make_const<double,8> a;
85 a.a[0] = v0; a.a[1] = v1; a.a[2] = v2; a.a[3] = v3;
86 a.a[4] = v4; a.a[5] = v5; a.a[6] = v6; a.a[7] = v7;
87 return a;
88}
89
90SIMDPP_INL expr_vec_make_const<double,16>
91 make_float(double v0, double v1, double v2, double v3,
92 double v4, double v5, double v6, double v7,
93 double v8, double v9, double v10, double v11,
94 double v12, double v13, double v14, double v15)
95{
96 expr_vec_make_const<double,16> a;
97 a.a[0] = v0; a.a[1] = v1; a.a[2] = v2; a.a[3] = v3;
98 a.a[4] = v4; a.a[5] = v5; a.a[6] = v6; a.a[7] = v7;
99 a.a[8] = v8; a.a[9] = v9; a.a[10] = v10; a.a[11] = v11;
100 a.a[12] = v12; a.a[13] = v13; a.a[14] = v14; a.a[15] = v15;
101 return a;
102}
103
104template<class V> SIMDPP_INL
105V make_float(double v0)
106{
107 static_assert(is_vector<V>::value && !is_mask<V>::value,
108 "V must be a non-mask vector");
109 expr_vec_make_const<double,1> a;
110 a.a[0] = v0;
111 return detail::insn::i_make_const_any<V>(a);
112}
113
114template<class V> SIMDPP_INL
115V make_float(double v0, double v1)
116{
117 static_assert(is_vector<V>::value && !is_mask<V>::value,
118 "V must be a non-mask vector");
119 expr_vec_make_const<double,2> a;
120 a.a[0] = v0; a.a[1] = v1;
121 return detail::insn::i_make_const_any<V>(a);
122}
123
124template<class V> SIMDPP_INL
125V make_float(double v0, double v1, double v2, double v3)
126{
127 static_assert(is_vector<V>::value && !is_mask<V>::value,
128 "V must be a non-mask vector");
129 expr_vec_make_const<double,4> a;
130 a.a[0] = v0; a.a[1] = v1; a.a[2] = v2; a.a[3] = v3;
131 return detail::insn::i_make_const_any<V>(a);
132}
133
134template<class V> SIMDPP_INL
135V make_float(double v0, double v1, double v2, double v3,
136 double v4, double v5, double v6, double v7)
137{
138 static_assert(is_vector<V>::value && !is_mask<V>::value,
139 "V must be a non-mask vector");
140 expr_vec_make_const<double,8> a;
141 a.a[0] = v0; a.a[1] = v1; a.a[2] = v2; a.a[3] = v3;
142 a.a[4] = v4; a.a[5] = v5; a.a[6] = v6; a.a[7] = v7;
143 return detail::insn::i_make_const_any<V>(a);
144}
145
146template<class V> SIMDPP_INL
147V make_float(double v0, double v1, double v2, double v3,
148 double v4, double v5, double v6, double v7,
149 double v8, double v9, double v10, double v11,
150 double v12, double v13, double v14, double v15)
151{
152 static_assert(is_vector<V>::value && !is_mask<V>::value,
153 "V must be a non-mask vector");
154 expr_vec_make_const<double,16> a;
155 a.a[0] = v0; a.a[1] = v1; a.a[2] = v2; a.a[3] = v3;
156 a.a[4] = v4; a.a[5] = v5; a.a[6] = v6; a.a[7] = v7;
157 a.a[8] = v8; a.a[9] = v9; a.a[10] = v10; a.a[11] = v11;
158 a.a[12] = v12; a.a[13] = v13; a.a[14] = v14; a.a[15] = v15;
159 return detail::insn::i_make_const_any<V>(a);
160}
161
162} // namespace SIMDPP_ARCH_NAMESPACE
163} // namespace simdpp
164
165#endif
166
167