Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 3 additions & 59 deletions src/r3d.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,73 +82,17 @@ constexpr R3D_INLINE T square(T x) {
return x * x;
}

template <typename T, Int n>
class Few {
using UninitT = typename std::aligned_storage<sizeof(T), alignof(T)>::type;
UninitT array_[n];

public:
enum { size = n };
R3D_INLINE T* data() { return reinterpret_cast<T*>(array_); }
R3D_INLINE T const* data() const {
return reinterpret_cast<T const*>(array_);
}
R3D_INLINE T volatile* data() volatile {
return reinterpret_cast<T volatile*>(array_);
}
R3D_INLINE T const volatile* data() const volatile {
return reinterpret_cast<T const volatile*>(array_);
}
R3D_INLINE T& operator[](Int i) { return data()[i]; }
R3D_INLINE T const& operator[](Int i) const { return data()[i]; }
R3D_INLINE T volatile& operator[](Int i) volatile { return data()[i]; }
R3D_INLINE T const volatile& operator[](Int i) const volatile {
return data()[i];
}
Few(std::initializer_list<T> l) {
Int i = 0;
for (auto it = l.begin(); it != l.end(); ++it) {
new (data() + (i++)) T(*it);
}
}
R3D_INLINE Few() {
for (Int i = 0; i < n; ++i) new (data() + i) T();
}
#ifdef OMPTARGET
#pragma omp declare target
#endif
R3D_INLINE ~Few() {
for (Int i = 0; i < n; ++i) (data()[i]).~T();
}
#ifdef OMPTARGET
#pragma omp end declare target
#endif
R3D_INLINE void operator=(Few<T, n> const& rhs) volatile {
for (Int i = 0; i < n; ++i) data()[i] = rhs[i];
}
R3D_INLINE void operator=(Few<T, n> const& rhs) {
for (Int i = 0; i < n; ++i) data()[i] = rhs[i];
}
R3D_INLINE void operator=(Few<T, n> const volatile& rhs) {
for (Int i = 0; i < n; ++i) data()[i] = rhs[i];
}
R3D_INLINE Few(Few<T, n> const& rhs) {
for (Int i = 0; i < n; ++i) new (data() + i) T(rhs[i]);
}
R3D_INLINE Few(Few<T, n> const volatile& rhs) {
for (Int i = 0; i < n; ++i) new (data() + i) T(rhs[i]);
}
};
template<typename T, int N>
using Few = Omega_h::Few<T, N>;

template <Int n>
struct Vector : public Few<Real, n> {
R3D_INLINE Vector() {}
inline Vector(std::initializer_list<Real> l) : Few<Real, n>(l) {}
R3D_INLINE void operator=(Vector<n> const& rhs) volatile {
R3D_INLINE void operator=(Vector<n> const& rhs) {
Few<Real, n>::operator=(rhs);
}
R3D_INLINE Vector(Vector<n> const& rhs) : Few<Real, n>(rhs) {}
R3D_INLINE Vector(const volatile Vector<n>& rhs) : Few<Real, n>(rhs) {}
};

R3D_INLINE Vector<2> vector_2(Real x, Real y) {
Expand Down