gpu rewrite initial commit

This commit is contained in:
DH 2024-09-25 16:00:55 +03:00
parent 0d4ed51cd9
commit 4cf808facd
133 changed files with 35491 additions and 4 deletions

View file

@ -0,0 +1,37 @@
#pragma once
#include <compare>
#include <utility>
namespace rx {
template <typename> class FunctionRef;
template <typename RT, typename... ArgsT> class FunctionRef<RT(ArgsT...)> {
void *context = nullptr;
RT (*invoke)(void *, ArgsT...) = nullptr;
public:
constexpr FunctionRef() = default;
template <typename T>
constexpr FunctionRef(T &&object)
requires requires(ArgsT... args) { RT(object(args...)); }
: context(
const_cast<std::remove_const_t<std::remove_cvref_t<T>> *>(&object)),
invoke(+[](void *context, ArgsT... args) -> RT {
return (*reinterpret_cast<T *>(context))(std::move(args)...);
}) {}
template <typename... InvokeArgsT>
constexpr RT operator()(InvokeArgsT &&...args) const
requires requires(void *context) {
invoke(context, std::forward<InvokeArgsT>(args)...);
}
{
return invoke(context, std::forward<InvokeArgsT>(args)...);
}
constexpr explicit operator bool() const { return invoke != nullptr; }
constexpr bool operator==(std::nullptr_t) const { return invoke == nullptr; }
constexpr auto operator<=>(const FunctionRef &) const = default;
};
} // namespace rx

41
rx/include/rx/TypeId.hpp Normal file
View file

@ -0,0 +1,41 @@
#pragma once
#include <compare>
#include <cstddef>
#include <functional>
namespace rx {
namespace detail {
template <typename> char mRawTypeId = 0;
template <typename T> constexpr const void *getTypeIdImpl() {
return &mRawTypeId<T>;
}
} // namespace detail
class TypeId {
const void *mId = detail::getTypeIdImpl<void>();
public:
constexpr const void *getOpaque() const { return mId; }
constexpr static TypeId createFromOpaque(const void *id) {
TypeId result;
result.mId = id;
return result;
}
template <typename T> constexpr static TypeId get() {
return createFromOpaque(detail::getTypeIdImpl<T>());
}
constexpr auto operator<=>(const TypeId &other) const = default;
};
} // namespace rx
namespace std {
template <> struct hash<rx::TypeId> {
constexpr std::size_t operator()(const rx::TypeId &id) const noexcept {
return std::hash<const void *>{}(id.getOpaque());
}
};
} // namespace std

12
rx/include/rx/bits.hpp Normal file
View file

@ -0,0 +1,12 @@
#pragma once
namespace rx {
template <typename T>
inline constexpr T getBits(T value, unsigned end, unsigned begin) {
return (value >> begin) & ((1ull << (end - begin + 1)) - 1);
}
template <typename T> inline constexpr T getBit(T value, unsigned bit) {
return (value >> bit) & 1;
}
} // namespace rx