unalignedcount.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // This file is part of Eigen, a lightweight C++ template library
  2. // for linear algebra.
  3. //
  4. // Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr>
  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. static int nb_load;
  10. static int nb_loadu;
  11. static int nb_store;
  12. static int nb_storeu;
  13. #define EIGEN_DEBUG_ALIGNED_LOAD { nb_load++; }
  14. #define EIGEN_DEBUG_UNALIGNED_LOAD { nb_loadu++; }
  15. #define EIGEN_DEBUG_ALIGNED_STORE { nb_store++; }
  16. #define EIGEN_DEBUG_UNALIGNED_STORE { nb_storeu++; }
  17. #define VERIFY_ALIGNED_UNALIGNED_COUNT(XPR,AL,UL,AS,US) {\
  18. nb_load = nb_loadu = nb_store = nb_storeu = 0; \
  19. XPR; \
  20. if(!(nb_load==AL && nb_loadu==UL && nb_store==AS && nb_storeu==US)) \
  21. std::cerr << " >> " << nb_load << ", " << nb_loadu << ", " << nb_store << ", " << nb_storeu << "\n"; \
  22. VERIFY( (#XPR) && nb_load==AL && nb_loadu==UL && nb_store==AS && nb_storeu==US ); \
  23. }
  24. #include "main.h"
  25. EIGEN_DECLARE_TEST(unalignedcount)
  26. {
  27. #if defined(EIGEN_VECTORIZE_AVX512)
  28. VectorXf a(48), b(48);
  29. VERIFY_ALIGNED_UNALIGNED_COUNT(a += b, 6, 0, 3, 0);
  30. VERIFY_ALIGNED_UNALIGNED_COUNT(a.segment(0,48) += b.segment(0,48), 3, 3, 3, 0);
  31. VERIFY_ALIGNED_UNALIGNED_COUNT(a.segment(0,48) -= b.segment(0,48), 3, 3, 3, 0);
  32. VERIFY_ALIGNED_UNALIGNED_COUNT(a.segment(0,48) *= 3.5, 3, 0, 3, 0);
  33. VERIFY_ALIGNED_UNALIGNED_COUNT(a.segment(0,48) /= 3.5, 3, 0, 3, 0);
  34. #elif defined(EIGEN_VECTORIZE_AVX)
  35. VectorXf a(40), b(40);
  36. VERIFY_ALIGNED_UNALIGNED_COUNT(a += b, 10, 0, 5, 0);
  37. VERIFY_ALIGNED_UNALIGNED_COUNT(a.segment(0,40) += b.segment(0,40), 5, 5, 5, 0);
  38. VERIFY_ALIGNED_UNALIGNED_COUNT(a.segment(0,40) -= b.segment(0,40), 5, 5, 5, 0);
  39. VERIFY_ALIGNED_UNALIGNED_COUNT(a.segment(0,40) *= 3.5, 5, 0, 5, 0);
  40. VERIFY_ALIGNED_UNALIGNED_COUNT(a.segment(0,40) /= 3.5, 5, 0, 5, 0);
  41. #elif defined(EIGEN_VECTORIZE_SSE)
  42. VectorXf a(40), b(40);
  43. VERIFY_ALIGNED_UNALIGNED_COUNT(a += b, 20, 0, 10, 0);
  44. VERIFY_ALIGNED_UNALIGNED_COUNT(a.segment(0,40) += b.segment(0,40), 10, 10, 10, 0);
  45. VERIFY_ALIGNED_UNALIGNED_COUNT(a.segment(0,40) -= b.segment(0,40), 10, 10, 10, 0);
  46. VERIFY_ALIGNED_UNALIGNED_COUNT(a.segment(0,40) *= 3.5, 10, 0, 10, 0);
  47. VERIFY_ALIGNED_UNALIGNED_COUNT(a.segment(0,40) /= 3.5, 10, 0, 10, 0);
  48. #else
  49. // The following line is to eliminate "variable not used" warnings
  50. nb_load = nb_loadu = nb_store = nb_storeu = 0;
  51. int a(0), b(0);
  52. VERIFY(a==b);
  53. #endif
  54. }