common/BitField: Support sign extension
This commit is contained in:
parent
004c22f031
commit
e7d68ba304
|
@ -112,12 +112,20 @@ struct BitField
|
|||
|
||||
DataType GetValue() const
|
||||
{
|
||||
// TODO: Handle signed types
|
||||
if (std::is_same<DataType, bool>::value)
|
||||
if constexpr (std::is_same_v<DataType, bool>)
|
||||
{
|
||||
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
|
||||
{
|
||||
return static_cast<DataType>((data & GetMask()) >> BitIndex);
|
||||
}
|
||||
}
|
||||
|
||||
void SetValue(DataType value)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue