Skip to content

Commit 1b065d0

Browse files
committed
loading constructors
1 parent e725625 commit 1b065d0

17 files changed

Lines changed: 176 additions & 32 deletions

‎benchmark/xsimd_benchmark.hpp‎

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,7 @@ namespace xsimd
110110
auto start = std::chrono::steady_clock::now();
111111
for (std::size_t i = 0; i < s; i += B::size)
112112
{
113-
B blhs;
114-
blhs.load_aligned(&lhs[i]);
113+
B blhs(&lhs[i], aligned_mode());
115114
B bres = f(blhs);
116115
bres.store_aligned(&res[i]);
117116
}
@@ -136,11 +135,8 @@ namespace xsimd
136135
size_t j = i + B::size;
137136
size_t k = j + B::size;
138137
size_t l = k + B::size;
139-
B blhs, blhs2, blhs3, blhs4;
140-
blhs.load_aligned(&lhs[i]);
141-
blhs2.load_aligned(&lhs[j]);
142-
blhs3.load_aligned(&lhs[k]);
143-
blhs4.load_aligned(&lhs[l]);
138+
B blhs(&lhs[i], aligned_mode()), blhs2(&lhs[j], aligned_mode()),
139+
blhs3(&lhs[k], aligned_mode()), blhs4(&lhs[l], aligned_mode());
144140
B bres = f(blhs);
145141
B bres2 = f(blhs2);
146142
B bres3 = f(blhs3);
@@ -167,9 +163,7 @@ namespace xsimd
167163
auto start = std::chrono::steady_clock::now();
168164
for (std::size_t i = 0; i < s; i += B::size)
169165
{
170-
B blhs, brhs;
171-
blhs.load_aligned(&lhs[i]);
172-
brhs.load_aligned(&rhs[i]);
166+
B blhs(&lhs[i], aligned_mode()), brhs(&rhs[i], aligned_mode());
173167
B bres = f(blhs, brhs);
174168
bres.store_aligned(&res[i]);
175169
}
@@ -194,16 +188,10 @@ namespace xsimd
194188
size_t j = i + B::size;
195189
size_t k = j + B::size;
196190
size_t l = k + B::size;
197-
B blhs, brhs, blhs2, brhs2;
198-
B blhs3, brhs3, blhs4, brhs4;
199-
blhs.load_aligned(&lhs[i]);
200-
blhs2.load_aligned(&lhs[j]);
201-
blhs3.load_aligned(&lhs[k]);
202-
blhs4.load_aligned(&lhs[l]);
203-
brhs.load_aligned(&rhs[i]);
204-
brhs2.load_aligned(&rhs[j]);
205-
brhs3.load_aligned(&rhs[k]);
206-
brhs4.load_aligned(&rhs[l]);
191+
B blhs(&lhs[i], aligned_mode()), brhs(&rhs[i], aligned_mode()),
192+
blhs2(&lhs[j], aligned_mode()), brhs2(&rhs[j], aligned_mode());
193+
B blhs3(&lhs[k], aligned_mode()), brhs3(&rhs[k], aligned_mode()),
194+
blhs4(&lhs[l], aligned_mode()), brhs4(&rhs[l], aligned_mode());
207195
B bres = f(blhs, brhs);
208196
B bres2 = f(blhs2, brhs2);
209197
B bres3 = f(blhs3, brhs3);

‎include/xsimd/math/xsimd_fp_manipulation.hpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ namespace xsimd
6161
i_type r1 = m1f & bitwise_cast<i_type>(arg);
6262
b_type x = arg & bitwise_cast<b_type>(~m1f);
6363
exp = (r1 >> nmb<b_type>()) - maxexponentm1<b_type>();
64-
exp = select(bool_cast(arg != b_type(0.)), exp, i_type(0));
64+
exp = select(bool_cast(arg != b_type(0.)), exp, zero<i_type>());
6565
return select((arg != b_type(0.)), x | bitwise_cast<b_type>(mask2frexp<b_type>()), b_type(0.));
6666
}
6767

‎include/xsimd/math/xsimd_fp_sign.hpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ namespace xsimd
6565
{
6666
static inline B compute(const B& a)
6767
{
68-
return select(a > B(0), B(1), B(0)) - select(a < B(0), B(1), B(0));
68+
return select(a > zero<B>(), B(1), zero<B>()) - select(a < zero<B>(), B(1), zero<B>());
6969
}
7070
};
7171

@@ -74,7 +74,7 @@ namespace xsimd
7474
{
7575
static inline B compute(const B& a)
7676
{
77-
B r = select(a > B(0), B(1), B(0)) - select(a < B(0), B(1), B(0));
77+
B r = select(a > B(0.), B(1.), B(0.)) - select(a < B(0.), B(1.), B(0.));
7878
#ifdef XSIMD_NO_NANS
7979
return r;
8080
#else

‎include/xsimd/math/xsimd_logarithm.hpp‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ namespace xsimd
102102

103103
B x = a;
104104
i_type hx = bitwise_cast<i_type>(x) >> 32;
105-
i_type k(0);
105+
i_type k = zero<i_type>();
106106
auto isnez = (a != B(0.));
107107
#ifndef XSIMD_NO_DENORMALS
108108
auto test = (a < smallestposval<B>()) && isnez;
@@ -234,7 +234,7 @@ namespace xsimd
234234
using i_type = as_integer_t<B>;
235235
B x = a;
236236
i_type hx = bitwise_cast<i_type>(x) >> 32;
237-
i_type k(0);
237+
i_type k = zero<i_type>();
238238
auto isnez = (a != B(0.));
239239
#ifndef XSIMD_NO_DENORMALS
240240
auto test = (a < smallestposval<B>()) && isnez;
@@ -388,7 +388,7 @@ namespace xsimd
388388
using i_type = as_integer_t<B>;
389389
B x = a;
390390
i_type hx = bitwise_cast<i_type>(x) >> 32;
391-
i_type k(0);
391+
i_type k = zero<i_type>();
392392
auto isnez = (a != B(0.));
393393
#ifndef XSIMD_NO_DENORMALS
394394
auto test = (a < smallestposval<B>()) && isnez;

‎include/xsimd/math/xsimd_numerical_constant.hpp‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ XSIMD_DEFINE_CONSTANT_HEX(twotonmbo3, 0x3ba14518, 0x3ed428a2f98d7286)
113113
template <class T>
114114
constexpr int32_t nmb() noexcept;
115115

116+
template <class T>
117+
constexpr T zero() noexcept;
118+
116119
/**************************
117120
* allbits implementation *
118121
**************************/
@@ -254,6 +257,15 @@ XSIMD_DEFINE_CONSTANT_HEX(twotonmbo3, 0x3ba14518, 0x3ed428a2f98d7286)
254257
return 52;
255258
}
256259

260+
/***********************
261+
* zero implementation *
262+
***********************/
263+
264+
template <class T>
265+
constexpr T zero() noexcept
266+
{
267+
return T(typename T::value_type(0));
268+
}
257269
}
258270

259271
#endif

‎include/xsimd/math/xsimd_power.hpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ namespace xsimd
148148
0x3fe17e1fc7e59d58ll,
149149
0xbfc13c93386fdff6ll
150150
>(x);
151-
auto flag = e >= i_type(0);
151+
auto flag = e >= zero<i_type>();
152152
i_type e1 = abs(e);
153153
i_type rem = e1;
154154
e1 /= i_type(3);

‎include/xsimd/types/xsimd_avx_double.hpp‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ namespace xsimd
7171
batch();
7272
explicit batch(double d);
7373
batch(double d0, double d1, double d2, double d3);
74+
explicit batch(const double* src);
75+
batch(const double* src, aligned_mode);
76+
batch(const double* src, unaligned_mode);
7477
batch(const __m256d& rhs);
7578
batch& operator=(const __m256d& rhs);
7679

@@ -225,6 +228,21 @@ namespace xsimd
225228
{
226229
}
227230

231+
inline batch<double, 4>::batch(const double* src)
232+
: m_value(_mm256_loadu_pd(src))
233+
{
234+
}
235+
236+
inline batch<double, 4>::batch(const double* src, aligned_mode)
237+
: m_value(_mm256_load_pd(src))
238+
{
239+
}
240+
241+
inline batch<double, 4>::batch(const double* src, unaligned_mode)
242+
: m_value(_mm256_loadu_pd(src))
243+
{
244+
}
245+
228246
inline batch<double, 4>::batch(const __m256d& rhs)
229247
: m_value(rhs)
230248
{

‎include/xsimd/types/xsimd_avx_float.hpp‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ namespace xsimd
7272
explicit batch(float f);
7373
batch(float f0, float f1, float f2, float f3,
7474
float f4, float f5, float f6, float f7);
75+
explicit batch(const float* src);
76+
batch(const float* src, aligned_mode);
77+
batch(const float* src, unaligned_mode);
7578
batch(const __m256& rhs);
7679
batch& operator=(const __m256& rhs);
7780

@@ -228,6 +231,21 @@ namespace xsimd
228231
{
229232
}
230233

234+
inline batch<float, 8>::batch(const float* src)
235+
: m_value(_mm256_loadu_ps(src))
236+
{
237+
}
238+
239+
inline batch<float, 8>::batch(const float* src, aligned_mode)
240+
: m_value(_mm256_load_ps(src))
241+
{
242+
}
243+
244+
inline batch<float, 8>::batch(const float* src, unaligned_mode)
245+
: m_value(_mm256_loadu_ps(src))
246+
{
247+
248+
}
231249
inline batch<float, 8>::batch(const __m256& rhs)
232250
: m_value(rhs)
233251
{

‎include/xsimd/types/xsimd_avx_int32.hpp‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ namespace xsimd
7171
batch();
7272
explicit batch(int32_t i);
7373
batch(int32_t i0, int32_t i1, int32_t i2, int32_t i3, int32_t i4, int32_t i5, int32_t i6, int32_t i7);
74+
explicit batch(const int32_t* src);
75+
batch(const int32_t* src, aligned_mode);
76+
batch(const int32_t* src, unaligned_mode);
7477
batch(const __m256i& rhs);
7578
batch& operator=(const __m256i& rhs);
7679

@@ -265,6 +268,21 @@ namespace xsimd
265268
{
266269
}
267270

271+
inline batch<int32_t, 8>::batch(const int32_t* src)
272+
: m_value(_mm256_loadu_si256((__m256i const*)src))
273+
{
274+
}
275+
276+
inline batch<int32_t, 8>::batch(const int32_t* src, aligned_mode)
277+
: m_value(_mm256_load_si256((__m256i const*)src))
278+
{
279+
}
280+
281+
inline batch<int32_t, 8>::batch(const int32_t* src, unaligned_mode)
282+
: m_value(_mm256_loadu_si256((__m256i const*)src))
283+
{
284+
}
285+
268286
inline batch<int32_t, 8>::batch(const __m256i& rhs)
269287
: m_value(rhs)
270288
{

‎include/xsimd/types/xsimd_avx_int64.hpp‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ namespace xsimd
7171
batch();
7272
explicit batch(int64_t i);
7373
batch(int64_t i0, int64_t i1, int64_t i2, int64_t i3);
74+
explicit batch(const int64_t* src);
75+
batch(const int64_t* src, aligned_mode);
76+
batch(const int64_t* src, unaligned_mode);
7477
batch(const __m256i& rhs);
7578
batch& operator=(const __m256i& rhs);
7679

@@ -265,6 +268,21 @@ namespace xsimd
265268
{
266269
}
267270

271+
inline batch<int64_t, 4>::batch(const int64_t* src)
272+
: m_value(_mm256_loadu_si256((__m256i const*)src))
273+
{
274+
}
275+
276+
inline batch<int64_t, 4>::batch(const int64_t* src, aligned_mode)
277+
: m_value(_mm256_load_si256((__m256i const*)src))
278+
{
279+
}
280+
281+
inline batch<int64_t, 4>::batch(const int64_t* src, unaligned_mode)
282+
: m_value(_mm256_loadu_si256((__m256i const*)src))
283+
{
284+
}
285+
268286
inline batch<int64_t, 4>::batch(const __m256i& rhs)
269287
: m_value(rhs)
270288
{

0 commit comments

Comments
 (0)