main.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /* This file is part of the Vc project
  2. Copyright (C) 2009-2020 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/simdize>
  21. #include <Vc/IO>
  22. template <typename T> struct PointTemplate {
  23. T x, y, z;
  24. Vc_SIMDIZE_INTERFACE((x, y, z));
  25. };
  26. using Point = PointTemplate<float>;
  27. template <typename T> class Vectorizer
  28. {
  29. public:
  30. using value_type = Vc::simdize<T>;
  31. void append(const T &x) { decorate(data)[count++] = x; }
  32. bool isFull() const { return count == data.size(); }
  33. const value_type &contents() const { return data; }
  34. private:
  35. value_type data;
  36. int count = 0;
  37. };
  38. int Vc_CDECL main()
  39. {
  40. Vectorizer<Point> v;
  41. float x = 0.f;
  42. while (!v.isFull()) {
  43. v.append(Point{x, x + 1, x + 2});
  44. x += 10;
  45. }
  46. const auto &vec = v.contents();
  47. std::cout << vec.x << '\n' << vec.y << '\n' << vec.z << '\n';
  48. return 0;
  49. }