using StgSharp.Math; using System; using System.Collections.Generic; using System.IO.Pipes; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Text; namespace StgSharp.Optimization { public static unsafe partial class SSE { internal static readonly byte[] SqrtssCodeBytes = new byte[] { 0x48, 0x89, 0xc8, //mov rax,rcx 0xf3, 0x0f, 0x6f, 0x00, //movdqu xmm0,xmmword ptr [rax] //0x66, 0x0f, 0x6f, 0x00, //movdqa xmm0,xmmword ptr [rax] 0xf3,0x0f, 0x51, 0xc0, //sqrtss xmm0,xmm0 0xf3, 0x0f, 0x7f, 0x00, //movdqu xmmqord ptr [rax],xmm0 //0x66, 0x0f, 0x7f, 0x00, //movdqa xmmword ptr [rax],xmm0 0xc3, //ret }; static asmfuncDelegate sqrtssDelegate; private static IntPtr sqrtssHandle = VirtualAlloc( IntPtr.Zero, SqrtssCodeBytes.Length, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE); private static void InitSqrtss() { Marshal.Copy(SqrtssCodeBytes,0,sqrtssHandle,SqrtssCodeBytes.Length); sqrtssDelegate = Marshal.GetDelegateForFunctionPointer(sqrtssHandle,typeof(asmfuncDelegate)) as asmfuncDelegate; } public unsafe static m128 Sqrtss(m128* m) { sqrtssDelegate((ulong)m); return *m; } } /// /// A delegate for asm sse functions /// /// The m128* pointer to the target m128 transformed in ulong form [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)] internal delegate void asmfuncDelegate(ulong m128Pointrter); }