dqily update on 20230423 by nitload youmu

This commit is contained in:
Nitload
2023-04-23 00:25:51 +08:00
parent 1cb78e9e8f
commit 7dba067146
45 changed files with 4698 additions and 43 deletions
+41 -12
View File
@@ -1,6 +1,7 @@
using StgSharp.Math;
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using static StgSharp.Optimization.CpuInfo;
@@ -10,6 +11,7 @@ namespace StgSharp.Optimization
public static unsafe partial class SSE
{
public static m128 sqrtssM128Cache = new m128();
public static m128* sqrtssM128CachePointer;
private static IntPtr sqrtssCodePointer;
@@ -18,7 +20,8 @@ namespace StgSharp.Optimization
private static byte[] sqrtssCodeBytes
= new byte[]
{
0x48,0xb8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // mov rax, [m128 location]
0x48,0xb8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // mov rax, [pointer location]
0x48,0x8b,0x00, // mov rax, [rax]
0xf3,0x0f,0x6f,0x00, // movqdu xmm0,xmmword ptr [rax]
0xf3,0x0f,0x51,0xc0, // sqrtss xmm0,xmm0
0xf3,0x0f,0x7f,0x00 // movdqu xmmword ptr [rax],xmm0
@@ -39,14 +42,37 @@ namespace StgSharp.Optimization
UInt32 dwFreeType
);
[Flags()]
protected enum AllocationType : uint
{
COMMIT = 0x1000,
RESERVE = 0x2000,
RESET = 0x80000,
LARGE_PAGES = 0x20000000,
PHYSICAL = 0x400000,
TOP_DOWN = 0x100000,
WRITE_WATCH = 0x200000
}
[Flags()]
protected enum MemoryProtection : uint
{
EXECUTE = 0x10,
EXECUTE_READ = 0x20,
EXECUTE_READWRITE = 0x40,
EXECUTE_WRITECOPY = 0x80,
NOACCESS = 0x01,
READONLY = 0x02,
READWRITE = 0x04,
WRITECOPY = 0x08,
GUARD_Modifierflag = 0x100,
NOCACHE_Modifierflag = 0x200,
WRITECOMBINE_Modifierflag = 0x400
}
private unsafe static void InitSqrtss()
{
var marshalPtr = Marshal.AllocHGlobal(32);
var m128ptr = new IntPtr(16*((long)marshalPtr/16+1));
m128* sqrtssCachePointer = (m128*)m128ptr.ToPointer();
sqrtssM128Cache = *sqrtssCachePointer;
byte[] sqrtssM128PointerBytes = BitConverter.GetBytes((ulong)sqrtssCachePointer);
byte[] sqrtssM128PointerBytes = BitConverter.GetBytes((ulong)sqrtssM128CachePointer);
for (int i = 0; i < sqrtssM128PointerBytes.Length; i++)
{
sqrtssCodeBytes[2+i] = sqrtssCodeBytes[7-i];
@@ -70,14 +96,17 @@ namespace StgSharp.Optimization
public static float Sqrtss(float a)
{
sqrtssM128Cache.float0 = a;
sqrtssDele();
return sqrtssM128Cache.float0;
fixed (m128* p = &sqrtssM128Cache)
{
sqrtssM128Cache.float0 = a;
sqrtssDele(sqrtssM128Cache);
return sqrtssM128Cache.float0;
}
}
}
[UnmanagedFunctionPointerAttribute(CallingConvention.StdCall)]
internal delegate void sqrtssDelegate();
[UnmanagedFunctionPointerAttribute(CallingConvention.ThisCall)]
internal delegate void sqrtssDelegate(m128 a);
}
+3
View File
@@ -9,7 +9,10 @@ namespace StgSharp.Optimization
static SSE()
{
//编译模拟Sqrtss指令
var sqrtssCachePointer = stackalloc ulong[1];
InitSqrtss();
}
}
+5
View File
@@ -62,4 +62,9 @@ namespace StgSharp.Optimization
};
}
}
[StructLayout(LayoutKind.Explicit,Size = 32)]
internal struct m128cache
{
}
}
-11
View File
@@ -1,11 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace StgSharp.Optimization
{
public static unsafe class x86
{
}
}