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_first_aligned_helper(Scalar *array, int size)
00029 {
00030   const int packet_size = sizeof(Scalar) * internal::packet_traits<Scalar>::size;
00031   VERIFY(((size_t(array) + sizeof(Scalar) * internal::first_aligned(array, size)) % packet_size) == 0);
00032 }
00033 
00034 template<typename Scalar>
00035 void test_none_aligned_helper(Scalar *array, int size)
00036 {
00037   EIGEN_UNUSED_VARIABLE(array);
00038   EIGEN_UNUSED_VARIABLE(size);
00039   VERIFY(internal::packet_traits<Scalar>::size == 1 || internal::first_aligned(array, size) == size);
00040 }
00041 
00042 struct some_non_vectorizable_type { float x; };
00043 
00044 void test_first_aligned()
00045 {
00046   EIGEN_ALIGN16 float array_float[100];
00047   test_first_aligned_helper(array_float, 50);
00048   test_first_aligned_helper(array_float+1, 50);
00049   test_first_aligned_helper(array_float+2, 50);
00050   test_first_aligned_helper(array_float+3, 50);
00051   test_first_aligned_helper(array_float+4, 50);
00052   test_first_aligned_helper(array_float+5, 50);
00053   
00054   EIGEN_ALIGN16 double array_double[100];
00055   test_first_aligned_helper(array_double, 50);
00056   test_first_aligned_helper(array_double+1, 50);
00057   test_first_aligned_helper(array_double+2, 50);
00058   
00059   double *array_double_plus_4_bytes = (double*)(size_t(array_double)+4);
00060   test_none_aligned_helper(array_double_plus_4_bytes, 50);
00061   test_none_aligned_helper(array_double_plus_4_bytes+1, 50);
00062   
00063   some_non_vectorizable_type array_nonvec[100];
00064   test_first_aligned_helper(array_nonvec, 100);
00065   test_none_aligned_helper(array_nonvec, 100);
00066 }


re_vision
Author(s): Dorian Galvez-Lopez
autogenerated on Sun Jan 5 2014 11:31:08