eigen2_first_aligned.cpp
Go to the documentation of this file.
00001 // This file is part of Eigen, a lightweight C++ template library
00002 // for linear algebra.
00003 //
00004 // Copyright (C) 2009 Benoit Jacob <jacob.benoit.1@gmail.com>
00005 //
00006 // Eigen is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 3 of the License, or (at your option) any later version.
00010 //
00011 // Alternatively, you can redistribute it and/or
00012 // modify it under the terms of the GNU General Public License as
00013 // published by the Free Software Foundation; either version 2 of
00014 // the License, or (at your option) any later version.
00015 //
00016 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
00017 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00018 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
00019 // GNU General Public License for more details.
00020 //
00021 // You should have received a copy of the GNU Lesser General Public
00022 // License and a copy of the GNU General Public License along with
00023 // Eigen. If not, see <http://www.gnu.org/licenses/>.
00024 
00025 #include "main.h"
00026 
00027 template<typename Scalar>
00028 void test_eigen2_first_aligned_helper(Scalar *array, int size)
00029 {
00030   const int packet_size = sizeof(Scalar) * ei_packet_traits<Scalar>::size;
00031   VERIFY(((std::size_t(array) + sizeof(Scalar) * ei_alignmentOffset(array, size)) % packet_size) == 0);
00032 }
00033 
00034 template<typename Scalar>
00035 void test_eigen2_none_aligned_helper(Scalar *array, int size)
00036 {
00037   VERIFY(ei_packet_traits<Scalar>::size == 1 || ei_alignmentOffset(array, size) == size);
00038 }
00039 
00040 struct some_non_vectorizable_type { float x; };
00041 
00042 void test_eigen2_first_aligned()
00043 {
00044   EIGEN_ALIGN_128 float array_float[100];
00045   test_first_aligned_helper(array_float, 50);
00046   test_first_aligned_helper(array_float+1, 50);
00047   test_first_aligned_helper(array_float+2, 50);
00048   test_first_aligned_helper(array_float+3, 50);
00049   test_first_aligned_helper(array_float+4, 50);
00050   test_first_aligned_helper(array_float+5, 50);
00051   
00052   EIGEN_ALIGN_128 double array_double[100];
00053   test_first_aligned_helper(array_double, 50);
00054   test_first_aligned_helper(array_double+1, 50);
00055   test_first_aligned_helper(array_double+2, 50);
00056   
00057   double *array_double_plus_4_bytes = (double*)(std::size_t(array_double)+4);
00058   test_none_aligned_helper(array_double_plus_4_bytes, 50);
00059   test_none_aligned_helper(array_double_plus_4_bytes+1, 50);
00060   
00061   some_non_vectorizable_type array_nonvec[100];
00062   test_first_aligned_helper(array_nonvec, 100);
00063   test_none_aligned_helper(array_nonvec, 100);
00064 }


libicr
Author(s): Robert Krug
autogenerated on Mon Jan 6 2014 11:32:38