Skip to content

Commit

Permalink
fix code style
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewKostousov committed Mar 11, 2021
1 parent b03eeaf commit 01e70b0
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 43 deletions.
10 changes: 7 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
# Changelog

## v1.3.20 - 2021.03.11
- Update GrEmit dependency to v3.4.1.
- Run tests against net5.0 tfm.

## v1.3.10 - 2019.11.21
- Update GrEmit to v3.2.2 supporting SourceLink
- Update GrEmit to v3.2.2 supporting SourceLink.

## v1.3.7 - 2019.11.21
- Use [SourceLink](https://github.com/dotnet/sourcelink) to help ReSharper decompiler show actual code.

## v1.3.2 - 2019.09.25
- Fix bug in `LambdaExpressionCreator`
- Update dependencies
- Fix bug in `LambdaExpressionCreator`.
- Update dependencies.

## v1.2.1 - 2018.09.15
- Use [Nerdbank.GitVersioning](https://github.com/AArnott/Nerdbank.GitVersioning) to automate generation of assembly
Expand Down
80 changes: 40 additions & 40 deletions GrobExp.Compiler.Tests/TestPerformance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -305,47 +305,47 @@ public unsafe void TestMarshal()
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
#endif
byte[] body;
if (IntPtr.Size == 4)
{
// x86
/*
* xor eax, eax // 0x31, 0xC0
* ret 8 // 0xC2, 0x08, 0x00
*/
body = new byte[]
{
0x31, 0xC0, // xor eax, eax
0xC2, 0x08, 0x00 // ret 8
};
}
else
{
body = new byte[]
{
0x48, 0x31, 0xC0, // xor rax, rax
0xC3 // ret
};
}
IntPtr p = NativeMethods.VirtualAlloc(
IntPtr.Zero,
new UIntPtr((uint)body.Length),
AllocationTypes.Commit | AllocationTypes.Reserve,
MemoryProtections.ExecuteReadWrite);
Marshal.Copy(body, 0, p, body.Length);
var func = (ZzzUnmanagedDelegate)Marshal.GetDelegateForFunctionPointer(p, typeof(ZzzUnmanagedDelegate));
var method = ((MulticastDelegate)func).Method;
var methodHandle = (RuntimeMethodHandle)method.GetType().GetProperty("MethodHandle", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public).GetGetMethod().Invoke(method, new object[0]);
var pointer = methodHandle.GetFunctionPointer();
var b = (byte*)pointer;
for (int i = 0; i < 20; ++i)
{
for (int j = 0; j < 10; ++j)
Console.Write(string.Format("{0:X2} ", *b++));
Console.WriteLine();
}
byte[] body;
if (IntPtr.Size == 4)
{
// x86
/*
* xor eax, eax // 0x31, 0xC0
* ret 8 // 0xC2, 0x08, 0x00
*/
body = new byte[]
{
0x31, 0xC0, // xor eax, eax
0xC2, 0x08, 0x00 // ret 8
};
}
else
{
body = new byte[]
{
0x48, 0x31, 0xC0, // xor rax, rax
0xC3 // ret
};
}
IntPtr p = NativeMethods.VirtualAlloc(
IntPtr.Zero,
new UIntPtr((uint)body.Length),
AllocationTypes.Commit | AllocationTypes.Reserve,
MemoryProtections.ExecuteReadWrite);
Marshal.Copy(body, 0, p, body.Length);
var func = (ZzzUnmanagedDelegate)Marshal.GetDelegateForFunctionPointer(p, typeof(ZzzUnmanagedDelegate));
var method = ((MulticastDelegate)func).Method;
var methodHandle = (RuntimeMethodHandle)method.GetType().GetProperty("MethodHandle", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public).GetGetMethod().Invoke(method, new object[0]);
var pointer = methodHandle.GetFunctionPointer();
var b = (byte*)pointer;
for (int i = 0; i < 20; ++i)
{
for (int j = 0; j < 10; ++j)
Console.Write(string.Format("{0:X2} ", *b++));
Console.WriteLine();
}

func(0, 1);
func(0, 1);

// var stopwatch = Stopwatch.StartNew();
// for (int i = 0; i < 1000000001; ++i)
Expand Down

0 comments on commit 01e70b0

Please sign in to comment.