mirror of
https://github.com/doitsujin/dxvk.git
synced 2025-01-19 05:52:11 +01:00
[util] Implement bit cast.
This commit is contained in:
parent
fc91fe1d34
commit
a3f74b5eda
@ -15,8 +15,21 @@
|
|||||||
|
|
||||||
#include "util_likely.h"
|
#include "util_likely.h"
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
namespace dxvk::bit {
|
namespace dxvk::bit {
|
||||||
|
|
||||||
|
template<typename T, typename J>
|
||||||
|
T cast(const J& src) {
|
||||||
|
static_assert(sizeof(T) == sizeof(J));
|
||||||
|
static_assert(std::is_trivially_copyable<J>::value && std::is_trivial<T>::value);
|
||||||
|
|
||||||
|
T dst;
|
||||||
|
std::memcpy(&dst, &src, sizeof(T));
|
||||||
|
return dst;
|
||||||
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
T extract(T value, uint32_t fst, uint32_t lst) {
|
T extract(T value, uint32_t fst, uint32_t lst) {
|
||||||
return (value >> fst) & ~(~T(0) << (lst - fst + 1));
|
return (value >> fst) & ~(~T(0) << (lst - fst + 1));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user