Skip to content

Commit c584d3f

Browse files
WIP
1 parent 74a98be commit c584d3f

File tree

1 file changed

+42
-66
lines changed

1 file changed

+42
-66
lines changed

test/test_bitwise_cast.cpp

Lines changed: 42 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -21,67 +21,46 @@ struct bitwise_cast_test
2121
static constexpr size_t N = CP::size;
2222

2323
using int32_batch = xsimd::batch<int32_t>;
24-
using float_batch = xsimd::batch<float>;
25-
26-
using int32_vector = std::vector<int32_t, xsimd::default_allocator<int32_t>>;
27-
using float_vector = std::vector<float, xsimd::default_allocator<float>>;
28-
29-
int32_vector ftoi32_res;
30-
float_vector i32tof_res;
31-
32-
#if !XSIMD_WITH_ALTIVEC
3324
using int64_batch = xsimd::batch<int64_t>;
25+
using float_batch = xsimd::batch<float>;
3426
using double_batch = xsimd::batch<double>;
3527

28+
using int32_vector = std::vector<int32_t, xsimd::default_allocator<int32_t>>;
3629
using int64_vector = std::vector<int64_t, xsimd::default_allocator<int64_t>>;
30+
using float_vector = std::vector<float, xsimd::default_allocator<float>>;
3731
using double_vector = std::vector<double, xsimd::default_allocator<double>>;
3832

33+
int32_vector ftoi32_res;
3934
int32_vector dtoi32_res;
40-
float_vector i64tof_res;
41-
float_vector dtof_res;
4235
int64_vector ftoi64_res;
4336
int64_vector dtoi64_res;
37+
float_vector i32tof_res;
38+
float_vector i64tof_res;
39+
float_vector dtof_res;
4440
double_vector i32tod_res;
4541
double_vector i64tod_res;
4642
double_vector ftod_res;
47-
#endif
4843

4944
bitwise_cast_test()
5045
: ftoi32_res(2 * N)
51-
, i32tof_res(2 * N)
52-
#if !XSIMD_WITH_ALTIVEC
5346
, dtoi32_res(2 * N)
54-
, i64tof_res(2 * N)
55-
, dtof_res(2 * N)
5647
, ftoi64_res(N)
5748
, dtoi64_res(N)
49+
, i32tof_res(2 * N)
50+
, i64tof_res(2 * N)
51+
, dtof_res(2 * N)
5852
, i32tod_res(N)
5953
, i64tod_res(N)
6054
, ftod_res(N)
61-
#endif
6255
{
6356
{
6457
int32_batch input = i32_input();
6558
bitcast b;
6659
b.i32[0] = input.get(0);
6760
b.i32[1] = input.get(1);
6861
std::fill(i32tof_res.begin(), i32tof_res.end(), b.f[0]);
69-
#if !XSIMD_WITH_ALTIVEC
7062
std::fill(i32tod_res.begin(), i32tod_res.end(), b.d);
71-
#endif
72-
}
73-
{
74-
float_batch input = f_input();
75-
bitcast b;
76-
b.f[0] = input.get(0);
77-
b.f[1] = input.get(1);
78-
std::fill(ftoi32_res.begin(), ftoi32_res.end(), b.i32[0]);
79-
#if !XSIMD_WITH_ALTIVEC
80-
std::fill(ftoi64_res.begin(), ftoi64_res.end(), b.i64);
81-
std::fill(ftod_res.begin(), ftod_res.end(), b.d);
82-
#endif
8363
}
84-
#if !XSIMD_WITH_ALTIVEC
8564
{
8665
int64_batch input = i64_input();
8766
bitcast b;
@@ -93,6 +72,15 @@ struct bitwise_cast_test
9372
i64tof_res[2 * i + 1] = b.f[1];
9473
}
9574
}
75+
{
76+
float_batch input = f_input();
77+
bitcast b;
78+
b.f[0] = input.get(0);
79+
b.f[1] = input.get(1);
80+
std::fill(ftoi32_res.begin(), ftoi32_res.end(), b.i32[0]);
81+
std::fill(ftoi64_res.begin(), ftoi64_res.end(), b.i64);
82+
std::fill(ftod_res.begin(), ftod_res.end(), b.d);
83+
}
9684
{
9785
double_batch input = d_input();
9886
bitcast b;
@@ -107,7 +95,6 @@ struct bitwise_cast_test
10795
dtof_res[2 * i + 1] = b.f[1];
10896
}
10997
}
110-
#endif
11198
}
11299

113100
void test_to_int32()
@@ -119,14 +106,29 @@ struct bitwise_cast_test
119106
INFO("to_int32(float)");
120107
CHECK_VECTOR_EQ(i32vres, ftoi32_res);
121108
}
122-
#if !XSIMD_WITH_ALTIVEC
123109
{
124110
int32_batch i32bres = xsimd::bitwise_cast<int32_t>(d_input());
125111
i32bres.store_aligned(i32vres.data());
126112
INFO("to_int32(double)");
127113
CHECK_VECTOR_EQ(i32vres, dtoi32_res);
128114
}
129-
#endif
115+
}
116+
117+
void test_to_int64()
118+
{
119+
int64_vector i64vres(int64_batch::size);
120+
{
121+
int64_batch i64bres = xsimd::bitwise_cast<int64_t>(f_input());
122+
i64bres.store_aligned(i64vres.data());
123+
INFO("to_int64(float)");
124+
CHECK_VECTOR_EQ(i64vres, ftoi64_res);
125+
}
126+
{
127+
int64_batch i64bres = xsimd::bitwise_cast<int64_t>(d_input());
128+
i64bres.store_aligned(i64vres.data());
129+
INFO("to_int64(double)");
130+
CHECK_VECTOR_EQ(i64vres, dtoi64_res);
131+
}
130132
}
131133

132134
void test_to_float()
@@ -138,7 +140,6 @@ struct bitwise_cast_test
138140
INFO("to_float(int32_t)");
139141
CHECK_VECTOR_EQ(fvres, i32tof_res);
140142
}
141-
#if !XSIMD_WITH_ALTIVEC
142143
{
143144
float_batch fbres = xsimd::bitwise_cast<float>(i64_input());
144145
fbres.store_aligned(fvres.data());
@@ -151,26 +152,6 @@ struct bitwise_cast_test
151152
INFO("to_float(double)");
152153
CHECK_VECTOR_EQ(fvres, dtof_res);
153154
}
154-
#endif
155-
}
156-
157-
#if !XSIMD_WITH_ALTIVEC
158-
159-
void test_to_int64()
160-
{
161-
int64_vector i64vres(int64_batch::size);
162-
{
163-
int64_batch i64bres = xsimd::bitwise_cast<int64_t>(f_input());
164-
i64bres.store_aligned(i64vres.data());
165-
INFO("to_int64(float)");
166-
CHECK_VECTOR_EQ(i64vres, ftoi64_res);
167-
}
168-
{
169-
int64_batch i64bres = xsimd::bitwise_cast<int64_t>(d_input());
170-
i64bres.store_aligned(i64vres.data());
171-
INFO("to_int64(double)");
172-
CHECK_VECTOR_EQ(i64vres, dtoi64_res);
173-
}
174155
}
175156

176157
void test_to_double()
@@ -195,30 +176,27 @@ struct bitwise_cast_test
195176
CHECK_VECTOR_EQ(dvres, ftod_res);
196177
}
197178
}
198-
#endif
199179

200180
private:
201181
int32_batch i32_input() const
202182
{
203183
return int32_batch(2);
204184
}
205185

206-
float_batch f_input() const
186+
int64_batch i64_input() const
207187
{
208-
return float_batch(3.);
188+
return int64_batch(2);
209189
}
210190

211-
#if !XSIMD_WITH_ALTIVEC
212-
int64_batch i64_input() const
191+
float_batch f_input() const
213192
{
214-
return int64_batch(2);
193+
return float_batch(3.);
215194
}
216195

217196
double_batch d_input() const
218197
{
219198
return double_batch(2.5e17);
220199
}
221-
#endif
222200

223201
union bitcast
224202
{
@@ -234,13 +212,11 @@ TEST_CASE_TEMPLATE("[bitwise cast]", B, CONVERSION_TYPES)
234212
bitwise_cast_test<B> Test;
235213
SUBCASE("to_int32") { Test.test_to_int32(); }
236214

237-
SUBCASE("to_float") { Test.test_to_float(); }
238-
239-
#if !XSIMD_WITH_ALTIVEC
240215
SUBCASE("to_int64") { Test.test_to_int64(); }
241216

217+
SUBCASE("to_float") { Test.test_to_float(); }
218+
242219
SUBCASE("to_double") { Test.test_to_double(); }
243-
#endif
244220
}
245221
#endif
246222
#endif

0 commit comments

Comments
 (0)