-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix some warnings and start work on new vector library
- Loading branch information
1 parent
9ce45a3
commit db542de
Showing
7 changed files
with
133 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,51 @@ | ||
#ifndef LIBRAPID_MATH_VECTOR_HPP | ||
#define LIBRAPID_MATH_VECTOR_HPP | ||
#ifndef LIBRAPID_MATH_VECTOR_OLD_HPP | ||
#define LIBRAPID_MATH_VECTOR_OLD_HPP | ||
|
||
#include "genericVector.hpp" | ||
#include "simdVector.hpp" | ||
// #include "genericVector.hpp" | ||
// #include "simdVector.hpp" | ||
#include "vectorImpl.hpp" | ||
|
||
namespace librapid { | ||
namespace detail { | ||
template<typename Scalar, int64_t Dims> | ||
auto vectorTypeIdentifier() { | ||
if constexpr (typetraits::TypeInfo<Scalar>::packetWidth > 1) { | ||
return SIMDVector<Scalar, Dims> {}; | ||
} else { | ||
return GenericVector<Scalar, Dims> {}; | ||
} | ||
} | ||
} // namespace detail | ||
// namespace detail { | ||
// template<typename Scalar, int64_t Dims> | ||
// auto vectorTypeIdentifier() { | ||
// if constexpr (typetraits::TypeInfo<Scalar>::packetWidth > 1) { | ||
// return SIMDVector<Scalar, Dims> {}; | ||
// } else { | ||
// return GenericVector<Scalar, Dims> {}; | ||
// } | ||
// } | ||
// } // namespace detail | ||
// | ||
// /// A simplified interface to the GenericVector class, defaulting to Vc SimdArray storage | ||
// /// \tparam Scalar The scalar type of the vector | ||
// /// \tparam Dims The dimensionality of the vector | ||
// template<typename Scalar, int64_t Dims> | ||
// using Vec = decltype(detail::vectorTypeIdentifier<Scalar, Dims>()); | ||
// | ||
// using Vec2i = Vec<int32_t, 2>; | ||
// using Vec3i = Vec<int32_t, 3>; | ||
// using Vec4i = Vec<int32_t, 4>; | ||
// using Vec2f = Vec<float, 2>; | ||
// using Vec3f = Vec<float, 3>; | ||
// using Vec4f = Vec<float, 4>; | ||
// using Vec2d = Vec<double, 2>; | ||
// using Vec3d = Vec<double, 3>; | ||
// using Vec4d = Vec<double, 4>; | ||
// | ||
// using Vec2 = Vec2d; | ||
// using Vec3 = Vec3d; | ||
// using Vec4 = Vec4d; | ||
|
||
/// A simplified interface to the GenericVector class, defaulting to Vc SimdArray storage | ||
/// \tparam Scalar The scalar type of the vector | ||
/// \tparam Dims The dimensionality of the vector | ||
template<typename Scalar, int64_t Dims> | ||
using Vec = decltype(detail::vectorTypeIdentifier<Scalar, Dims>()); | ||
|
||
using Vec2i = Vec<int32_t, 2>; | ||
using Vec3i = Vec<int32_t, 3>; | ||
using Vec4i = Vec<int32_t, 4>; | ||
using Vec2f = Vec<float, 2>; | ||
using Vec3f = Vec<float, 3>; | ||
using Vec4f = Vec<float, 4>; | ||
using Vec2d = Vec<double, 2>; | ||
using Vec3d = Vec<double, 3>; | ||
using Vec4d = Vec<double, 4>; | ||
|
||
using Vec2 = Vec2d; | ||
using Vec3 = Vec3d; | ||
using Vec4 = Vec4d; | ||
using Vec2i = Vector<int32_t, 2>; | ||
using Vec3i = Vector<int32_t, 3>; | ||
using Vec4i = Vector<int32_t, 4>; | ||
using Vec2f = Vector<float, 2>; | ||
using Vec3f = Vector<float, 3>; | ||
using Vec4f = Vector<float, 4>; | ||
using Vec2d = Vector<double, 2>; | ||
using Vec3d = Vector<double, 3>; | ||
using Vec4d = Vector<double, 4>; | ||
} // namespace librapid | ||
|
||
#endif // LIBRAPID_MATH_VECTOR_HPP | ||
#endif // LIBRAPID_MATH_VECTOR_OLD_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#ifndef LIBRAPID_MATH_VECTOR_HPP | ||
#define LIBRAPID_MATH_VECTOR_HPP | ||
|
||
namespace librapid { | ||
namespace detail { | ||
template<typename T, size_t N, typename = void> | ||
struct VectorStorage; | ||
|
||
template<typename T, size_t N> | ||
struct VectorStorage<T, N, std::enable_if_t<(typetraits::TypeInfo<T>::packetWidth == 1)>> { | ||
static constexpr uint64_t length = N; | ||
T data[length]; | ||
|
||
LIBRAPID_NODISCARD LIBRAPID_ALWAYS_INLINE const auto &operator[](int64_t index) const { | ||
return data[index]; | ||
} | ||
|
||
LIBRAPID_NODISCARD LIBRAPID_ALWAYS_INLINE auto &operator[](int64_t index) { | ||
return data[index]; | ||
} | ||
}; | ||
|
||
template<typename T, size_t N> | ||
struct VectorStorage<T, N, std::enable_if_t<(typetraits::TypeInfo<T>::packetWidth > 1)>> { | ||
using Packet = typename typetraits::TypeInfo<T>::Packet; | ||
static constexpr uint64_t packetWidth = typetraits::TypeInfo<T>::packetWidth; | ||
static constexpr uint64_t length = | ||
(N + typetraits::TypeInfo<T>::packetWidth - 1) / typetraits::TypeInfo<T>::packetWidth; | ||
Packet data[length]; | ||
|
||
LIBRAPID_NODISCARD LIBRAPID_ALWAYS_INLINE auto operator[](int64_t index) const { | ||
const int64_t packetIndex = index / packetWidth; | ||
const int64_t elementIndex = index % packetWidth; | ||
return data[packetIndex][elementIndex]; | ||
} | ||
|
||
LIBRAPID_NODISCARD LIBRAPID_ALWAYS_INLINE auto operator[](int64_t index) { | ||
const int64_t packetIndex = index / packetWidth; | ||
const int64_t elementIndex = index % packetWidth; | ||
return data[packetIndex][elementIndex]; | ||
} | ||
}; | ||
|
||
template<typename T, size_t N, size_t... Indices> | ||
void vectorStorageAssigner(VectorStorage<T, N> &dst, const VectorStorage<T, N> &src, | ||
std::index_sequence<Indices...>) { | ||
((dst[Indices] = src[Indices]), ...); | ||
} | ||
} // namespace detail | ||
|
||
template<typename ScalarType, size_t NumDims> | ||
class Vector { | ||
public: | ||
using Scalar = ScalarType; | ||
static constexpr uint64_t Dims = NumDims; | ||
using StorageType = detail::VectorStorage<Scalar, NumDims>; | ||
static constexpr uint64_t length = StorageType::length; | ||
|
||
Vector() = default; | ||
Vector(const Vector &other) = default; | ||
Vector(Vector &&other) noexcept = default; | ||
|
||
auto operator=(const Vector &other) -> Vector & = default; | ||
auto operator=(Vector &&other) noexcept -> Vector & = default; | ||
|
||
// template<typename T, size_t N> | ||
// Vector(const Vector<T, N> &other) { | ||
// detail::vectorStorageAssigner(m_data, other.m_data, std::make_index_sequence<length>()); | ||
// } | ||
|
||
private: | ||
StorageType m_data; | ||
}; | ||
} // namespace librapid | ||
#endif // LIBRAPID_MATH_VECTOR_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters