1*bf2c3715SXin Li // This file is part of Eigen, a lightweight C++ template library
2*bf2c3715SXin Li // for linear algebra.
3*bf2c3715SXin Li //
4*bf2c3715SXin Li // Copyright (C) 2009 Benoit Jacob <[email protected]>
5*bf2c3715SXin Li //
6*bf2c3715SXin Li // This Source Code Form is subject to the terms of the Mozilla
7*bf2c3715SXin Li // Public License v. 2.0. If a copy of the MPL was not distributed
8*bf2c3715SXin Li // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9*bf2c3715SXin Li
10*bf2c3715SXin Li #include "main.h"
11*bf2c3715SXin Li
12*bf2c3715SXin Li template<typename Scalar>
test_first_aligned_helper(Scalar * array,int size)13*bf2c3715SXin Li void test_first_aligned_helper(Scalar *array, int size)
14*bf2c3715SXin Li {
15*bf2c3715SXin Li const int packet_size = sizeof(Scalar) * internal::packet_traits<Scalar>::size;
16*bf2c3715SXin Li VERIFY(((size_t(array) + sizeof(Scalar) * internal::first_default_aligned(array, size)) % packet_size) == 0);
17*bf2c3715SXin Li }
18*bf2c3715SXin Li
19*bf2c3715SXin Li template<typename Scalar>
test_none_aligned_helper(Scalar * array,int size)20*bf2c3715SXin Li void test_none_aligned_helper(Scalar *array, int size)
21*bf2c3715SXin Li {
22*bf2c3715SXin Li EIGEN_UNUSED_VARIABLE(array);
23*bf2c3715SXin Li EIGEN_UNUSED_VARIABLE(size);
24*bf2c3715SXin Li VERIFY(internal::packet_traits<Scalar>::size == 1 || internal::first_default_aligned(array, size) == size);
25*bf2c3715SXin Li }
26*bf2c3715SXin Li
27*bf2c3715SXin Li struct some_non_vectorizable_type { float x; };
28*bf2c3715SXin Li
EIGEN_DECLARE_TEST(first_aligned)29*bf2c3715SXin Li EIGEN_DECLARE_TEST(first_aligned)
30*bf2c3715SXin Li {
31*bf2c3715SXin Li EIGEN_ALIGN16 float array_float[100];
32*bf2c3715SXin Li test_first_aligned_helper(array_float, 50);
33*bf2c3715SXin Li test_first_aligned_helper(array_float+1, 50);
34*bf2c3715SXin Li test_first_aligned_helper(array_float+2, 50);
35*bf2c3715SXin Li test_first_aligned_helper(array_float+3, 50);
36*bf2c3715SXin Li test_first_aligned_helper(array_float+4, 50);
37*bf2c3715SXin Li test_first_aligned_helper(array_float+5, 50);
38*bf2c3715SXin Li
39*bf2c3715SXin Li EIGEN_ALIGN16 double array_double[100];
40*bf2c3715SXin Li test_first_aligned_helper(array_double, 50);
41*bf2c3715SXin Li test_first_aligned_helper(array_double+1, 50);
42*bf2c3715SXin Li test_first_aligned_helper(array_double+2, 50);
43*bf2c3715SXin Li
44*bf2c3715SXin Li double *array_double_plus_4_bytes = (double*)(internal::UIntPtr(array_double)+4);
45*bf2c3715SXin Li test_none_aligned_helper(array_double_plus_4_bytes, 50);
46*bf2c3715SXin Li test_none_aligned_helper(array_double_plus_4_bytes+1, 50);
47*bf2c3715SXin Li
48*bf2c3715SXin Li some_non_vectorizable_type array_nonvec[100];
49*bf2c3715SXin Li test_first_aligned_helper(array_nonvec, 100);
50*bf2c3715SXin Li test_none_aligned_helper(array_nonvec, 100);
51*bf2c3715SXin Li }
52