mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2024-11-14 21:37:52 -07:00
BPMemory: Eliminate union type punning
This is undefined behavior in C++.
This commit is contained in:
parent
98311cd9f4
commit
1f596a23af
@ -4,6 +4,30 @@
|
||||
|
||||
#include "VideoCommon/BPMemory.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
// BP state
|
||||
// STATE_TO_SAVE
|
||||
BPMemory bpmem;
|
||||
|
||||
float FogParam0::GetA() const
|
||||
{
|
||||
// scale mantissa from 11 to 23 bits
|
||||
const u32 integral = (static_cast<u32>(sign) << 31) | (static_cast<u32>(exponent) << 23) |
|
||||
(static_cast<u32>(mantissa) << 12);
|
||||
|
||||
float real;
|
||||
std::memcpy(&real, &integral, sizeof(u32));
|
||||
return real;
|
||||
}
|
||||
|
||||
float FogParam3::GetC() const
|
||||
{
|
||||
// scale mantissa from 11 to 23 bits
|
||||
const u32 integral = (static_cast<u32>(c_sign) << 31) | (static_cast<u32>(c_exp) << 23) |
|
||||
(static_cast<u32>(c_mant) << 12);
|
||||
|
||||
float real;
|
||||
std::memcpy(&real, &integral, sizeof(u32));
|
||||
return real;
|
||||
}
|
||||
|
@ -674,17 +674,7 @@ union FogParam0
|
||||
u32 sign : 1;
|
||||
};
|
||||
|
||||
float GetA()
|
||||
{
|
||||
union
|
||||
{
|
||||
u32 i;
|
||||
float f;
|
||||
} dummy;
|
||||
dummy.i = ((u32)sign << 31) | ((u32)exponent << 23) |
|
||||
((u32)mantissa << 12); // scale mantissa from 11 to 23 bits
|
||||
return dummy.f;
|
||||
}
|
||||
float GetA() const;
|
||||
|
||||
u32 hex;
|
||||
};
|
||||
@ -701,17 +691,7 @@ union FogParam3
|
||||
};
|
||||
|
||||
// amount to subtract from eyespacez after range adjustment
|
||||
float GetC()
|
||||
{
|
||||
union
|
||||
{
|
||||
u32 i;
|
||||
float f;
|
||||
} dummy;
|
||||
dummy.i = ((u32)c_sign << 31) | ((u32)c_exp << 23) |
|
||||
((u32)c_mant << 12); // scale mantissa from 11 to 23 bits
|
||||
return dummy.f;
|
||||
}
|
||||
float GetC() const;
|
||||
|
||||
u32 hex;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user