unalignedcount.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. void test_unalignedcount()
  26. {
  27. #if defined(EIGEN_VECTORIZE_AVX)
  28. VectorXf a(40), b(40);
  29. VERIFY_ALIGNED_UNALIGNED_COUNT(a += b, 10, 0, 5, 0);
  30. VERIFY_ALIGNED_UNALIGNED_COUNT(a.segment(0,40) += b.segment(0,40), 5, 5, 5, 0);
  31. VERIFY_ALIGNED_UNALIGNED_COUNT(a.segment(0,40) -= b.segment(0,40), 5, 5, 5, 0);
  32. VERIFY_ALIGNED_UNALIGNED_COUNT(a.segment(0,40) *= 3.5, 5, 0, 5, 0);
  33. VERIFY_ALIGNED_UNALIGNED_COUNT(a.segment(0,40) /= 3.5, 5, 0, 5, 0);
  34. #elif defined(EIGEN_VECTORIZE_SSE)
  35. VectorXf a(40), b(40);
  36. VERIFY_ALIGNED_UNALIGNED_COUNT(a += b, 20, 0, 10, 0);
  37. VERIFY_ALIGNED_UNALIGNED_COUNT(a.segment(0,40) += b.segment(0,40), 10, 10, 10, 0);
  38. VERIFY_ALIGNED_UNALIGNED_COUNT(a.segment(0,40) -= b.segment(0,40), 10, 10, 10, 0);
  39. VERIFY_ALIGNED_UNALIGNED_COUNT(a.segment(0,40) *= 3.5, 10, 0, 10, 0);
  40. VERIFY_ALIGNED_UNALIGNED_COUNT(a.segment(0,40) /= 3.5, 10, 0, 10, 0);
  41. #else
  42. // The following line is to eliminate "variable not used" warnings
  43. nb_load = nb_loadu = nb_store = nb_storeu = 0;
  44. int a(0), b(0);
  45. VERIFY(a==b);
  46. #endif
  47. }