diff options
author | Lioncash <mathew1800@gmail.com> | 2016-05-09 05:21:44 +0200 |
---|---|---|
committer | Lioncash <mathew1800@gmail.com> | 2016-05-09 05:21:47 +0200 |
commit | 47ca79ba4bc7e5c18cf9427c975a789efd65a414 (patch) | |
tree | f54015b536c5fc10f784e7264eedc7488ddc91b1 /src/common | |
parent | swap: Remove unused methods (diff) | |
download | yuzu-47ca79ba4bc7e5c18cf9427c975a789efd65a414.tar yuzu-47ca79ba4bc7e5c18cf9427c975a789efd65a414.tar.gz yuzu-47ca79ba4bc7e5c18cf9427c975a789efd65a414.tar.bz2 yuzu-47ca79ba4bc7e5c18cf9427c975a789efd65a414.tar.lz yuzu-47ca79ba4bc7e5c18cf9427c975a789efd65a414.tar.xz yuzu-47ca79ba4bc7e5c18cf9427c975a789efd65a414.tar.zst yuzu-47ca79ba4bc7e5c18cf9427c975a789efd65a414.zip |
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/swap.h | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/src/common/swap.h b/src/common/swap.h index f51751d29..beedd6c7e 100644 --- a/src/common/swap.h +++ b/src/common/swap.h @@ -25,6 +25,8 @@ #include <sys/endian.h> #endif +#include <cstring> + #include "common/common_types.h" // GCC 4.6+ @@ -89,27 +91,29 @@ inline u64 swap64(u64 data) {return ((u64)swap32(data) << 32) | swap32(data >> 3 #endif inline float swapf(float f) { - union { - float f; - unsigned int u32; - } dat1, dat2; + static_assert(sizeof(u32) == sizeof(float), + "float must be the same size as uint32_t."); + + u32 value; + std::memcpy(&value, &f, sizeof(u32)); - dat1.f = f; - dat2.u32 = swap32(dat1.u32); + value = swap32(value); + std::memcpy(&f, &value, sizeof(u32)); - return dat2.f; + return f; } inline double swapd(double f) { - union { - double f; - unsigned long long u64; - } dat1, dat2; + static_assert(sizeof(u64) == sizeof(double), + "double must be the same size as uint64_t."); + + u64 value; + std::memcpy(&value, &f, sizeof(u64)); - dat1.f = f; - dat2.u64 = swap64(dat1.u64); + value = swap64(value); + std::memcpy(&f, &value, sizeof(u64)); - return dat2.f; + return f; } } // Namespace Common |