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