mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2024-11-25 15:15:40 +00:00
common/BitField: Support sign extension
This commit is contained in:
parent
004c22f031
commit
e7d68ba304
|
@ -112,11 +112,19 @@ struct BitField
|
||||||
|
|
||||||
DataType GetValue() const
|
DataType GetValue() const
|
||||||
{
|
{
|
||||||
// TODO: Handle signed types
|
if constexpr (std::is_same_v<DataType, bool>)
|
||||||
if (std::is_same<DataType, bool>::value)
|
{
|
||||||
return static_cast<DataType>(!!((data & GetMask()) >> BitIndex));
|
return static_cast<DataType>(!!((data & GetMask()) >> BitIndex));
|
||||||
|
}
|
||||||
|
else if constexpr (std::is_signed_v<DataType>)
|
||||||
|
{
|
||||||
|
constexpr int shift = 8 * sizeof(DataType) - BitCount;
|
||||||
|
return (static_cast<DataType>((data & GetMask()) >> BitIndex) << shift) >> shift;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
return static_cast<DataType>((data & GetMask()) >> BitIndex);
|
return static_cast<DataType>((data & GetMask()) >> BitIndex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetValue(DataType value)
|
void SetValue(DataType value)
|
||||||
|
|
Loading…
Reference in a new issue