You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.7 KiB

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