Merge pull request #6899 from lioncash/mem

MMU: Use Common::BitCast where applicable
This commit is contained in:
Léo Lam 2018-05-18 22:18:48 +02:00 committed by GitHub
commit 8af0f1bfc5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 22 deletions

View File

@ -489,20 +489,14 @@ double Read_F64(const u32 address)
{ {
const u64 integral = Read_U64(address); const u64 integral = Read_U64(address);
double real; return Common::BitCast<double>(integral);
std::memcpy(&real, &integral, sizeof(double));
return real;
} }
float Read_F32(const u32 address) float Read_F32(const u32 address)
{ {
const u32 integral = Read_U32(address); const u32 integral = Read_U32(address);
float real; return Common::BitCast<float>(integral);
std::memcpy(&real, &integral, sizeof(float));
return real;
} }
u32 Read_U8_ZX(const u32 address) u32 Read_U8_ZX(const u32 address)
@ -556,8 +550,7 @@ void Write_U64_Swap(const u64 var, const u32 address)
void Write_F64(const double var, const u32 address) void Write_F64(const double var, const u32 address)
{ {
u64 integral; const u64 integral = Common::BitCast<u64>(var);
std::memcpy(&integral, &var, sizeof(u64));
Write_U64(integral, address); Write_U64(integral, address);
} }
@ -586,20 +579,14 @@ float HostRead_F32(const u32 address)
{ {
const u32 integral = HostRead_U32(address); const u32 integral = HostRead_U32(address);
float real; return Common::BitCast<float>(integral);
std::memcpy(&real, &integral, sizeof(float));
return real;
} }
double HostRead_F64(const u32 address) double HostRead_F64(const u32 address)
{ {
const u64 integral = HostRead_U64(address); const u64 integral = HostRead_U64(address);
double real; return Common::BitCast<double>(integral);
std::memcpy(&real, &integral, sizeof(double));
return real;
} }
void HostWrite_U8(const u8 var, const u32 address) void HostWrite_U8(const u8 var, const u32 address)
@ -624,16 +611,14 @@ void HostWrite_U64(const u64 var, const u32 address)
void HostWrite_F32(const float var, const u32 address) void HostWrite_F32(const float var, const u32 address)
{ {
u32 integral; const u32 integral = Common::BitCast<u32>(var);
std::memcpy(&integral, &var, sizeof(u32));
HostWrite_U32(integral, address); HostWrite_U32(integral, address);
} }
void HostWrite_F64(const double var, const u32 address) void HostWrite_F64(const double var, const u32 address)
{ {
u64 integral; const u64 integral = Common::BitCast<u64>(var);
std::memcpy(&integral, &var, sizeof(u64));
HostWrite_U64(integral, address); HostWrite_U64(integral, address);
} }