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.

51 lines
1.8 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_first_aligned_helper(Scalar *array, int size)
  12. {
  13. const int packet_size = sizeof(Scalar) * internal::packet_traits<Scalar>::size;
  14. VERIFY(((size_t(array) + sizeof(Scalar) * internal::first_default_aligned(array, size)) % packet_size) == 0);
  15. }
  16. template<typename Scalar>
  17. void test_none_aligned_helper(Scalar *array, int size)
  18. {
  19. EIGEN_UNUSED_VARIABLE(array);
  20. EIGEN_UNUSED_VARIABLE(size);
  21. VERIFY(internal::packet_traits<Scalar>::size == 1 || internal::first_default_aligned(array, size) == size);
  22. }
  23. struct some_non_vectorizable_type { float x; };
  24. void test_first_aligned()
  25. {
  26. EIGEN_ALIGN16 float array_float[100];
  27. test_first_aligned_helper(array_float, 50);
  28. test_first_aligned_helper(array_float+1, 50);
  29. test_first_aligned_helper(array_float+2, 50);
  30. test_first_aligned_helper(array_float+3, 50);
  31. test_first_aligned_helper(array_float+4, 50);
  32. test_first_aligned_helper(array_float+5, 50);
  33. EIGEN_ALIGN16 double array_double[100];
  34. test_first_aligned_helper(array_double, 50);
  35. test_first_aligned_helper(array_double+1, 50);
  36. test_first_aligned_helper(array_double+2, 50);
  37. double *array_double_plus_4_bytes = (double*)(size_t(array_double)+4);
  38. test_none_aligned_helper(array_double_plus_4_bytes, 50);
  39. test_none_aligned_helper(array_double_plus_4_bytes+1, 50);
  40. some_non_vectorizable_type array_nonvec[100];
  41. test_first_aligned_helper(array_nonvec, 100);
  42. test_none_aligned_helper(array_nonvec, 100);
  43. }