29 typedef typename Vec::IndexType IndexType;
38 for (
int perm = 0; perm < maxPerm; ++perm) {
42 for (
int j = 0; j < i; ++j) {
48 a[i] += rest % (Vec::Size - i);
49 rest /= (Vec::Size - i);
50 for (
int j = 0; j < i; ++j) {
58 COMPARE(ref, a.sorted()) <<
", a: " << a;
61 for (
int repetition = 0; repetition < 1000; ++repetition) {
64 reference.
vector(0) = test;
65 std::sort(&reference[0], &reference[
Vec::Size]);
71 template<
typename T,
typename Mem>
struct Foo
74 void reset() { i = 0; }
82 typedef typename V::EntryType
T;
83 typedef typename V::IndexType
I;
84 typedef typename V::Mask M;
85 typedef typename I::Mask MI;
87 const MI _odd = (_indexes &
I(
One)) > 0;
90 Foo<T, typename V::Memory>
f;
91 a.callWithValuesSorted(f);
97 a.callWithValuesSorted(f);
99 for (
int i = 0; i <
V::Size / 2; ++i) {
109 typedef typename V::EntryType
T;
110 typedef typename V::IndexType
I;
143 V negative = -positive;
144 COMPARE(v, v.copySign(positive));
145 COMPARE(-v, v.copySign(negative));
149 void bzero(
void *p,
size_t n) { memset(p, 0, n); }
156 typedef typename V::EntryType
T;
160 TotalBits =
sizeof(
T) * 8,
161 RightShift = TotalBits - NBits,
162 NHistograms = TotalBits - NBits + 1,
163 LeftShift = (RightShift + 1) / NHistograms,
165 MinGood = Mean - Mean/10,
166 MaxGood = Mean + Mean/10
168 const V mask((1 << NBits) - 1);
169 int histogram[NHistograms][NBins];
170 bzero(&histogram[0][0],
sizeof(histogram));
171 for (
size_t i = 0; i < NBins *
Mean /
V::Size; ++i) {
173 for (
size_t hist = 0; hist < NHistograms; ++hist) {
174 const V bin = ((rand << (hist * LeftShift)) >> RightShift) & mask;
175 for (
size_t k = 0; k <
V::Size; ++k) {
176 ++histogram[hist][bin[k]];
181 #ifdef PRINT_RANDOM_HISTOGRAM
182 for (
size_t hist = 0; hist < NHistograms; ++hist) {
183 std::cout <<
"histogram[" << std::setw(2) << hist <<
"]: ";
184 for (
size_t bin = 0; bin < NBins; ++bin) {
185 std::cout << std::setw(3) << (histogram[hist][bin] -
Mean) * 1000 /
Mean <<
"|";
187 std::cout << std::endl;
190 for (
size_t hist = 0; hist < NHistograms; ++hist) {
191 for (
size_t bin = 0; bin < NBins; ++bin) {
192 VERIFY(histogram[hist][bin] > MinGood)
193 <<
" bin = " << bin <<
" is " << histogram[0][bin];
194 VERIFY(histogram[hist][bin] < MaxGood)
195 <<
" bin = " << bin <<
" is " << histogram[0][bin];
202 typedef typename V::EntryType
T;
210 int histogram[NHistograms][NBins];
211 bzero(&histogram[0][0],
sizeof(histogram));
212 for (
size_t i = 0; i < NBins *
Mean /
V::Size; ++i) {
214 const I bin =
static_cast<I>(rand *
T(NBins));
215 for (
size_t k = 0; k <
V::Size; ++k) {
216 ++histogram[0][bin[k]];
219 #ifdef PRINT_RANDOM_HISTOGRAM
220 for (
size_t hist = 0; hist < NHistograms; ++hist) {
221 std::cout <<
"histogram[" << std::setw(2) << hist <<
"]: ";
222 for (
size_t bin = 0; bin < NBins; ++bin) {
223 std::cout << std::setw(3) << (histogram[hist][bin] -
Mean) * 1000 /
Mean <<
"|";
225 std::cout << std::endl;
228 for (
size_t hist = 0; hist < NHistograms; ++hist) {
229 for (
size_t bin = 0; bin < NBins; ++bin) {
230 VERIFY(histogram[hist][bin] > MinGood)
231 <<
" bin = " << bin <<
" is " << histogram[0][bin];
232 VERIFY(histogram[hist][bin] < MaxGood)
233 <<
" bin = " << bin <<
" is " << histogram[0][bin];
242 template<
typename T>
T add2(
T x) {
return x +
T(2); }
244 template<
typename T,
typename V>
248 CallTester() :
v(
Vc::
Zero), i(0) {}
255 void reset() {
v.setZero(); i = 0; }
257 int callCount()
const {
return i; }
258 V callValues()
const {
return v; }
265 #if __cplusplus >= 201103 && (!defined(VC_CLANG) || VC_CLANG > 0x30000)
266 #define DO_LAMBDA_TESTS 1
272 typedef typename V::EntryType
T;
275 for (
int i = 0; i < 1000; ++i) {
277 COMPARE(rand.apply(add2<T>), rand + two);
278 #ifdef DO_LAMBDA_TESTS
279 COMPARE(rand.apply([](T
x) { return x + T(2); }), rand + two);
282 CallTester<T, V> callTester;
283 rand.call(callTester);
285 COMPARE(callTester.callValues(), rand);
292 COMPARE(copy2(mask).apply(add2<T>), copy1) << mask;
293 COMPARE(rand.apply(add2<T>, mask), copy1) << mask;
294 #ifdef DO_LAMBDA_TESTS
295 COMPARE(copy2(mask).apply([](T x) {
return x +
T(2); }), copy1) << mask;
296 COMPARE(rand.apply([](T x) { return x + T(2); }, mask), copy1) << mask;
300 copy2(mask).call(callTester);
301 COMPARE(callTester.callCount(), mask.count());
304 rand.call(callTester, mask);
305 COMPARE(callTester.callCount(), mask.count());
314 template<
typename V>
void fill()
316 typedef typename V::EntryType
T;
317 typedef typename V::IndexType
I;
319 test.fill(returnConstant<T, 2>);
323 test.fill(returnConstantOffset<T, 0>);
327 test.fill(returnConstantOffset2<T, 0>);
333 typedef typename V::EntryType
T;
336 const V
test = reference.shifted(shift);
337 for (
int i = 0; i <
V::Size; ++i) {
338 if (i + shift >= 0 && i + shift < V::Size) {
339 COMPARE(test[i], reference[i + shift]) <<
"shift: " << shift <<
", i: " << i <<
", test: " << test <<
", reference: " << reference;
341 COMPARE(test[i],
T(0)) <<
"shift: " << shift <<
", i: " << i <<
", test: " << test <<
", reference: " << reference;
352 const V
test = reference.rotated(shift);
353 for (
int i = 0; i <
V::Size; ++i) {
354 unsigned int refShift = i + shift;
355 COMPARE(test[i], reference[refShift % V::Size]) <<
"shift: " << shift <<
", i: " << i <<
", test: " << test <<
", reference: " << reference;
362 int_v *
a = Vc::malloc<int_v, Vc::AlignOnVector>(10);
365 for (
int i = 0; i < 10; ++i) {
366 VERIFY((reinterpret_cast<unsigned long>(&a[i]) & mask) == 0);
368 const char *data =
reinterpret_cast<const char *
>(&a[0]);
369 for (
int i = 0; i < 10; ++i) {
370 VERIFY(&data[i *
int_v::Size *
sizeof(int_v::EntryType)] == reinterpret_cast<const char *>(&a[i]));
373 a = Vc::malloc<int_v, Vc::AlignOnCacheline>(10);
375 COMPARE((reinterpret_cast<unsigned long>(&a[0]) & mask), 0ul);
379 a = Vc::malloc<int_v, Vc::AlignOnPage>(10);
381 COMPARE((reinterpret_cast<unsigned long>(&a[0]) & mask), 0ul);
void Random< sfloat_v >()
T returnConstantOffset(int i)
#define foreach_bit(_it_, _mask_)
#define testRealTypes(name)
#define testAllTypes(name)
Vc_ALWAYS_INLINE Vc_PURE VectorPointerHelper< V, AlignedFlag > vector(size_t i)
#define for_all_masks(VecType, _mask_)
VECTOR_NAMESPACE::int_v int_v
Double_t Mean(Long64_t n, const T *a, const Double_t *w=0)
A helper class for fixed-size two-dimensional arrays.
TRObject operator()(const T1 &t1) const
void Random< double_v >()
static ushort cacheLineSize()
Return the cache line size in bits.
T returnConstantOffset2(unsigned short i)
void testMallocAlignment()