main.cpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*{{{
  2. Copyright (C) 2013 Matthias Kretz <kretz@kde.org>
  3. Permission to use, copy, modify, and distribute this software
  4. and its documentation for any purpose and without fee is hereby
  5. granted, provided that the above copyright notice appear in all
  6. copies and that both that the copyright notice and this
  7. permission notice and warranty disclaimer appear in supporting
  8. documentation, and that the name of the author not be used in
  9. advertising or publicity pertaining to distribution of the
  10. software without specific, written prior permission.
  11. The author disclaim all warranties with regard to this
  12. software, including all implied warranties of merchantability
  13. and fitness. In no event shall the author be liable for any
  14. special, indirect or consequential damages or any damages
  15. whatsoever resulting from loss of use, data or profits, whether
  16. in an action of contract, negligence or other tortious action,
  17. arising out of or in connection with the use or performance of
  18. this software.
  19. }}}*/
  20. #include <Vc/Vc>
  21. #include <array>
  22. #include <algorithm>
  23. #include "../tsc.h"
  24. using Vc::double_v;
  25. using Vc::double_m;
  26. constexpr size_t ArraySize = 10240;
  27. using Point = std::array<double_v, 3>;
  28. using PointArray = std::array<Point, ArraySize / double_v::Size>;
  29. static const std::array<double_v, 3> origin = {{ 0.2, 0.3, 0.4 }};
  30. static const std::array<double_v, 3> boxsize = {{ 0.5, 0.3, 0.1 }};
  31. double_m contains(const Point &point)
  32. {
  33. double_m inside[3];
  34. for (int dir = 0; dir < 3; ++dir) {
  35. inside[dir] = abs(point[dir] - origin[dir]) < boxsize[dir];
  36. }
  37. return inside[0] && inside[1] && inside[2];
  38. }
  39. std::array<bool, ArraySize> contains(const PointArray &points)
  40. {
  41. std::array<bool, ArraySize> inside;
  42. auto storeIt = inside.begin();
  43. for (const auto &p : points) {
  44. contains(p).store(&*storeIt);
  45. storeIt += double_v::Size;
  46. }
  47. return inside;
  48. }
  49. std::array<bool, ArraySize> g_inside;
  50. int Vc_CDECL main()
  51. {
  52. PointArray points;
  53. std::generate(points.begin(), points.end(), []() -> Point {
  54. return {{ double_v::Random(), double_v::Random(), double_v::Random() }};
  55. });
  56. TimeStampCounter tsc;
  57. tsc.start();
  58. const auto &tmp = contains(points);
  59. tsc.stop();
  60. g_inside = tmp;
  61. std::cout << tsc.cycles() << std::endl;
  62. return 0;
  63. }