Exemple #1
0
 static AsmCode <T> AddCode <T>()
     where T : unmanaged
 {
     if (typeof(T) == typeof(sbyte))
     {
         return(AsmCode.FromBytes <T>(add8iBytes));
     }
     else if (typeof(T) == typeof(byte))
     {
         return(AsmCode.FromBytes <T>(add8uBytes));
     }
     else if (typeof(T) == typeof(short))
     {
         return(AsmCode.FromBytes <T>(add16iBytes));
     }
     else if (typeof(T) == typeof(ushort))
     {
         return(AsmCode.FromBytes <T>(add16uBytes));
     }
     else if (typeof(T) == typeof(int))
     {
         return(AsmCode.FromBytes <T>(add32iBytes));
     }
     else if (typeof(T) == typeof(uint))
     {
         return(AsmCode.FromBytes <T>(add32uBytes));
     }
     else if (typeof(T) == typeof(long))
     {
         return(AsmCode.FromBytes <T>(add64iBytes));
     }
     else if (typeof(T) == typeof(ulong))
     {
         return(AsmCode.FromBytes <T>(add64uBytes));
     }
     else if (typeof(T) == typeof(float))
     {
         return(AsmCode.FromBytes <T>(add32fBytes));
     }
     else if (typeof(T) == typeof(double))
     {
         return(AsmCode.FromBytes <T>(add64fBytes));
     }
     else
     {
         throw unsupported <T>();
     }
 }
Exemple #2
0
 static AsmCode <T> SqrtCode <T>()
     where T : unmanaged
 {
     if (typeof(T) == typeof(float))
     {
         return(AsmCode.FromBytes <T>(SqrtF32Bytes));
     }
     else if (typeof(T) == typeof(double))
     {
         return(AsmCode.FromBytes <T>(SqrtF64Bytes));
     }
     else
     {
         throw unsupported <T>();
     }
 }
Exemple #3
0
 public static AsmCode <T> Add128Code <T>()
     where T : unmanaged
 {
     if (typeof(T) == typeof(sbyte) || typeof(T) == typeof(byte))
     {
         return(AsmCode.FromBytes <T>(vpaddbBytes));
     }
     else if (typeof(T) == typeof(short) || typeof(T) == typeof(ushort))
     {
         return(AsmCode.FromBytes <T>(vpaddwBytes));
     }
     else if (typeof(T) == typeof(int) || typeof(T) == typeof(uint))
     {
         return(AsmCode.FromBytes <T>(vpadddBytes));
     }
     else
     {
         throw unsupported <T>();
     }
 }
Exemple #4
0
        static AsmRdRand()
        {
            var rdrand = new byte[]
            {
                0x0f, 0xc7, 0xf0,  // rdrand eax
                0x0f, 0x92, 0x01,  // setc byte ptr [rcx]
                0xc3               // ret
            };

            Marshal.Copy(rdrand, 0, methodPtr <AsmRdRand>(nameof(RandNative)), rdrand.Length);


            var code    = AsmCode.FromBytes <uint>(rdrand);
            var emitter = code.CreateEmitter();

            emitter();

            //var il = code.CreateEmitter().Method.GetMethodBody().GetILAsByteArray();
            //var emitter = code.CreateEmitter();
            //var il = emitter.Method.GetMethodBody().GetILAsByteArray();
            //var dst = methodPtr<AsmRdRand>(nameof(Next));
            //Marshal.Copy(il, 0, dst, il.Length);
        }