Guest User

Untitled

a guest
Mar 14th, 2020
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.83 KB | None | 0 0
  1. #ifndef GENERIC_SIMD
  2. #define GENERIC_SIMD
  3.  
  4. #include "preprocessor.hpp"
  5. #include "set.hpp"
  6. #include "add.hpp"
  7.  
  8. namespace simd
  9. {
  10.  
  11.     template <typename _Tx>
  12.     class vec
  13.     {
  14.     public:
  15.         using vec_t = _Tx;
  16.         using type = vec_t;
  17.  
  18.         // Disable any implicit conversions
  19.         explicit vec() = default;
  20.         explicit vec(const vec_t& reg) : _vec(reg) {}
  21.         explicit vec(const vec<vec_t>& copy) : _vec(copy._vec) {}
  22.         explicit vec(vec<vec_t>&& move) : _vec(move._vec) {}
  23.         vec<vec_t>& operator=(const vec<vec_t>& copy)
  24.         {
  25.             vec<vec_t> temp{};
  26.             temp._vec = copy._vec;
  27.  
  28.             return temp;
  29.         }
  30.         // Allow copy assignment with vec_t
  31.         vec<vec_t>& operator=(const vec_t& copy)
  32.         {
  33.             vec<vec_t> temp{};
  34.             temp._vec = copy;
  35.  
  36.             return temp;
  37.         }
  38.         vec<vec_t>& operator=(vec<vec_t>&& move)
  39.         {
  40.             vec<vec_t> temp{};
  41.             temp._vec = move._vec;
  42.  
  43.             return temp;
  44.         }
  45.         // Allow move assignment with vec_t
  46.         vec<vec_t>& operator=(vec_t&& move)
  47.         {
  48.             vec<vec_t> temp{};
  49.             temp._vec = move;
  50.  
  51.             return temp;
  52.         }
  53.  
  54.  
  55.         // 2d stencil specific operation
  56.         void set(float value)
  57.         {
  58.             static_assert(std::is_same<vec_t, simd::float4>::value);
  59.             simd::helper::set<vec_t>::compute(std::ref(_vec), std::ref(value));
  60.         }
  61.  
  62.         // 2d stencil specific operation
  63.         void add(vec<vec_t>& other)
  64.         {
  65.             static_assert(std::is_same<vec_t, simd::float4>::value);
  66.             simd::helper::add<vec_t>::compute(std::ref(_vec), std::ref(other._vec));
  67.         }
  68.  
  69.         vec<vec_t> operator+(vec<vec_t>& other)
  70.         {
  71.             static_assert(std::is_same<vec_t, simd::float4>::value);
  72.             vec_t res = simd::helper::add<vec_t>::compute(std::ref(_vec), std::ref(other._vec));
  73.  
  74.             vec<vec_t> temp{ res };
  75.  
  76.             return std::move(temp);
  77.         }
  78.  
  79.         // 2d stencil specific operation
  80.         void multiply()
  81.         {
  82.  
  83.         }
  84.  
  85.         // our stored simd float/double
  86.         vec_t _vec;
  87.     };
  88. }
  89.  
  90.  
  91. #endif // GENERIC_SIMD
Add Comment
Please, Sign In to add comment