mirror of
https://git.naxdy.org/Mirror/Ryujinx.git
synced 2025-03-20 12:00:17 +00:00
35 lines
No EOL
1.1 KiB
C#
35 lines
No EOL
1.1 KiB
C#
using System.Runtime.CompilerServices;
|
|
|
|
namespace Ryujinx.Horizon.Sdk.Sf.Hipc
|
|
{
|
|
static class BitfieldExtensions
|
|
{
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static bool Extract(this uint value, int lsb)
|
|
{
|
|
return ((value >> lsb) & 1) != 0;
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static uint Extract(this uint value, int lsb, int length)
|
|
{
|
|
return (value >> lsb) & (uint.MaxValue >> (32 - length));
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static uint Insert(this uint value, int lsb, bool toInsert)
|
|
{
|
|
uint mask = 1u << lsb;
|
|
|
|
return (value & ~mask) | (toInsert ? mask : 0);
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static uint Insert(this uint value, int lsb, int length, uint toInsert)
|
|
{
|
|
uint mask = (uint.MaxValue >> (32 - length)) << lsb;
|
|
|
|
return (value & ~mask) | ((toInsert << lsb) & mask);
|
|
}
|
|
}
|
|
} |