mirror of
https://github.com/Thealexbarney/LibHac.git
synced 2024-11-14 10:49:41 +01:00
Add memory fence functions
This commit is contained in:
parent
3a05e779f9
commit
4e5e9a4627
2 changed files with 147 additions and 0 deletions
128
src/LibHac/Os/Impl/MemoryFence.cs
Normal file
128
src/LibHac/Os/Impl/MemoryFence.cs
Normal file
|
@ -0,0 +1,128 @@
|
|||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.Intrinsics.X86;
|
||||
|
||||
namespace LibHac.Os.Impl;
|
||||
|
||||
public static class MemoryFence
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void FenceMemoryStoreStore()
|
||||
{
|
||||
if (Sse.IsSupported)
|
||||
{
|
||||
Sse.StoreFence();
|
||||
}
|
||||
else
|
||||
{
|
||||
// This only needs to be a store barrier on aarch64
|
||||
System.Threading.Thread.MemoryBarrier();
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void FenceMemoryStoreLoad()
|
||||
{
|
||||
if (Sse2.IsSupported)
|
||||
{
|
||||
Sse2.MemoryFence();
|
||||
}
|
||||
else
|
||||
{
|
||||
System.Threading.Thread.MemoryBarrier();
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void FenceMemoryStoreAny()
|
||||
{
|
||||
if (Sse2.IsSupported)
|
||||
{
|
||||
Sse2.MemoryFence();
|
||||
}
|
||||
else
|
||||
{
|
||||
System.Threading.Thread.MemoryBarrier();
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void FenceMemoryLoadStore()
|
||||
{
|
||||
if (Sse2.IsSupported)
|
||||
{
|
||||
Sse2.MemoryFence();
|
||||
}
|
||||
else
|
||||
{
|
||||
// This only needs to be a load barrier on aarch64
|
||||
System.Threading.Thread.MemoryBarrier();
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void FenceMemoryLoadLoad()
|
||||
{
|
||||
if (Sse2.IsSupported)
|
||||
{
|
||||
Sse2.LoadFence();
|
||||
}
|
||||
else
|
||||
{
|
||||
// This only needs to be a load barrier on aarch64
|
||||
System.Threading.Thread.MemoryBarrier();
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void FenceMemoryLoadAny()
|
||||
{
|
||||
if (Sse2.IsSupported)
|
||||
{
|
||||
Sse2.MemoryFence();
|
||||
}
|
||||
else
|
||||
{
|
||||
// This only needs to be a load barrier on aarch64
|
||||
System.Threading.Thread.MemoryBarrier();
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void FenceMemoryAnyStore()
|
||||
{
|
||||
if (Sse2.IsSupported)
|
||||
{
|
||||
Sse2.MemoryFence();
|
||||
}
|
||||
else
|
||||
{
|
||||
System.Threading.Thread.MemoryBarrier();
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void FenceMemoryAnyLoad()
|
||||
{
|
||||
if (Sse2.IsSupported)
|
||||
{
|
||||
Sse2.MemoryFence();
|
||||
}
|
||||
else
|
||||
{
|
||||
System.Threading.Thread.MemoryBarrier();
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void FenceMemoryAnyAny()
|
||||
{
|
||||
if (Sse2.IsSupported)
|
||||
{
|
||||
Sse2.MemoryFence();
|
||||
}
|
||||
else
|
||||
{
|
||||
System.Threading.Thread.MemoryBarrier();
|
||||
}
|
||||
}
|
||||
}
|
19
src/LibHac/Os/MemoryFenceApi.cs
Normal file
19
src/LibHac/Os/MemoryFenceApi.cs
Normal file
|
@ -0,0 +1,19 @@
|
|||
using System.Runtime.CompilerServices;
|
||||
using LibHac.Os.Impl;
|
||||
|
||||
namespace LibHac.Os;
|
||||
|
||||
public static class MemoryFenceApi
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static void FenceMemoryStoreStore() => MemoryFence.FenceMemoryStoreStore();
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static void FenceMemoryStoreLoad() => MemoryFence.FenceMemoryStoreLoad();
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static void FenceMemoryStoreAny() => MemoryFence.FenceMemoryStoreAny();
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static void FenceMemoryLoadStore() => MemoryFence.FenceMemoryLoadStore();
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static void FenceMemoryLoadLoad() => MemoryFence.FenceMemoryLoadLoad();
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static void FenceMemoryLoadAny() => MemoryFence.FenceMemoryLoadAny();
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static void FenceMemoryAnyStore() => MemoryFence.FenceMemoryAnyStore();
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static void FenceMemoryAnyLoad() => MemoryFence.FenceMemoryAnyLoad();
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static void FenceMemoryAnyAny() => MemoryFence.FenceMemoryAnyAny();
|
||||
}
|
Loading…
Reference in a new issue