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 (at) 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 12 template<typename Scalar> 13 void test_eigen2_first_aligned_helper(Scalar *array, int size) 14 { 15 const int packet_size = sizeof(Scalar) * ei_packet_traits<Scalar>::size; 16 VERIFY(((std::size_t(array) + sizeof(Scalar) * ei_alignmentOffset(array, size)) % packet_size) == 0); 17 } 18 19 template<typename Scalar> 20 void test_eigen2_none_aligned_helper(Scalar *array, int size) 21 { 22 VERIFY(ei_packet_traits<Scalar>::size == 1 || ei_alignmentOffset(array, size) == size); 23 } 24 25 struct some_non_vectorizable_type { float x; }; 26 27 void test_eigen2_first_aligned() 28 { 29 EIGEN_ALIGN_128 float array_float[100]; 30 test_first_aligned_helper(array_float, 50); 31 test_first_aligned_helper(array_float+1, 50); 32 test_first_aligned_helper(array_float+2, 50); 33 test_first_aligned_helper(array_float+3, 50); 34 test_first_aligned_helper(array_float+4, 50); 35 test_first_aligned_helper(array_float+5, 50); 36 37 EIGEN_ALIGN_128 double array_double[100]; 38 test_first_aligned_helper(array_double, 50); 39 test_first_aligned_helper(array_double+1, 50); 40 test_first_aligned_helper(array_double+2, 50); 41 42 double *array_double_plus_4_bytes = (double*)(std::size_t(array_double)+4); 43 test_none_aligned_helper(array_double_plus_4_bytes, 50); 44 test_none_aligned_helper(array_double_plus_4_bytes+1, 50); 45 46 some_non_vectorizable_type array_nonvec[100]; 47 test_first_aligned_helper(array_nonvec, 100); 48 test_none_aligned_helper(array_nonvec, 100); 49 } 50