mirror of
https://github.com/danbulant/Cosmos
synced 2026-05-21 21:38:52 +00:00
Merge pull request #55 from kant2002/Issue-54
Add plug for Buffer.__Memmove on the .NET 4.6
This commit is contained in:
commit
087ab24f0d
6 changed files with 349 additions and 0 deletions
90
source/Cosmos.IL2CPU.Tests/Cosmos.IL2CPU.Tests.csproj
Normal file
90
source/Cosmos.IL2CPU.Tests/Cosmos.IL2CPU.Tests.csproj
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{17329379-67D5-45D2-8EF0-9C625C43E117}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Cosmos.IL2CPU.Tests</RootNamespace>
|
||||
<AssemblyName>Cosmos.IL2CPU.Tests</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
|
||||
<IsCodedUITest>False</IsCodedUITest>
|
||||
<TestProjectType>UnitTest</TestProjectType>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
</ItemGroup>
|
||||
<Choose>
|
||||
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
|
||||
</ItemGroup>
|
||||
</When>
|
||||
<Otherwise>
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework" />
|
||||
</ItemGroup>
|
||||
</Otherwise>
|
||||
</Choose>
|
||||
<ItemGroup>
|
||||
<Compile Include="Plugs\System\BufferTests.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Cosmos.IL2CPU\Cosmos.IL2CPU.csproj">
|
||||
<Project>{239e33a7-f0c3-4801-85ca-4d8f89a31dc0}</Project>
|
||||
<Name>Cosmos.IL2CPU</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Choose>
|
||||
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.VisualStudio.QualityTools.CodedUITestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Extension, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.VisualStudio.TestTools.UITesting, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
</When>
|
||||
</Choose>
|
||||
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
81
source/Cosmos.IL2CPU.Tests/Plugs/System/BufferTests.cs
Normal file
81
source/Cosmos.IL2CPU.Tests/Plugs/System/BufferTests.cs
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
using System.Linq;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using TargetClass = Cosmos.IL2CPU.X86.Plugs.CustomImplementations.System.Buffer;
|
||||
|
||||
namespace Cosmos.IL2CPU.Tests.Plugs.System
|
||||
{
|
||||
/// <summary>
|
||||
/// Tests for the <see cref="System.Buffer"/> class plugs
|
||||
/// </summary>
|
||||
[TestClass]
|
||||
public class BufferTests
|
||||
{
|
||||
/// <summary>
|
||||
/// Verifies that non overlapped memory working.
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public unsafe void MemmoveNonOverlappedMemory()
|
||||
{
|
||||
byte[] src = new byte[10];
|
||||
for (var i = 0; i < src.Length; i++)
|
||||
{
|
||||
src[i] = (byte)(i + 10);
|
||||
}
|
||||
|
||||
byte[] dest = new byte[100];
|
||||
dest[6] = 255;
|
||||
fixed (byte* destPtr = dest, srcPtr = src)
|
||||
{
|
||||
TargetClass.__Memmove(destPtr, srcPtr, 5);
|
||||
}
|
||||
|
||||
CollectionAssert.AreNotEquivalent(
|
||||
new[] { 10, 11, 12, 13, 14, 0 },
|
||||
dest.Take(6).ToArray());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that overlapped memory regions working when copy forward
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public unsafe void MemmoveOverlappedMemory()
|
||||
{
|
||||
byte[] data = new byte[100];
|
||||
for (var i = 0; i < data.Length; i++)
|
||||
{
|
||||
data[i] = (byte)(i + 10);
|
||||
}
|
||||
|
||||
fixed (byte* destPtr = data, srcPtr = &data[1])
|
||||
{
|
||||
TargetClass.__Memmove(destPtr, srcPtr, 5);
|
||||
}
|
||||
|
||||
CollectionAssert.AreNotEquivalent(
|
||||
new[] { 11, 12, 13, 14, 15, 15, 16, 17, 18 },
|
||||
data.Take(9).ToArray());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that overlapped memory regions working when copy backward
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public unsafe void MemmoveOverlappedMemory2()
|
||||
{
|
||||
byte[] data = new byte[100];
|
||||
for (var i = 0; i < data.Length; i++)
|
||||
{
|
||||
data[i] = (byte)(i + 10);
|
||||
}
|
||||
|
||||
fixed (byte* destPtr = &data[1], srcPtr = data)
|
||||
{
|
||||
TargetClass.__Memmove(destPtr, srcPtr, 5);
|
||||
}
|
||||
|
||||
CollectionAssert.AreNotEquivalent(
|
||||
new [] { 10, 10, 11, 12, 13, 14, 16 },
|
||||
data.Take(7).ToArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
36
source/Cosmos.IL2CPU.Tests/Properties/AssemblyInfo.cs
Normal file
36
source/Cosmos.IL2CPU.Tests/Properties/AssemblyInfo.cs
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("Cosmos.IL2CPU.Tests")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("Cosmos.IL2CPU.Tests")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2015")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("a719fc5b-ddd5-46d0-9d22-e42d77b809f9")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
|
|
@ -63,6 +63,7 @@ namespace Cosmos.IL2CPU.ILOpCodes {
|
|||
}
|
||||
|
||||
if (StackPopTypes[0] == typeof(int) ||
|
||||
StackPopTypes[0] == typeof(uint) ||
|
||||
StackPopTypes[0] == typeof(byte))
|
||||
{
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -13,6 +13,132 @@ namespace Cosmos.IL2CPU.X86.Plugs.CustomImplementations.System {
|
|||
global::System.Buffer.BlockCopy((Array)(object)*src, 0, (Array)(object)*dest, 0, count);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The memmove() function copies n bytes from memory area src to memory area dest.
|
||||
/// The memory areas may overlap: copying takes place as though the bytes in src
|
||||
/// are first copied into a temporary array that does not overlap src or dest,
|
||||
/// and the bytes are then copied from the temporary array to dest.
|
||||
/// </summary>
|
||||
/// <param name="dest">Destination address to copy data into.</param>
|
||||
/// <param name="src">Source address from where copy data.</param>
|
||||
/// <param name="count">Count of bytes to copy.</param>
|
||||
public static unsafe void __Memmove(byte* dest, byte* src, uint count)
|
||||
{
|
||||
uint t;
|
||||
const int wmask = 0xFFFF;
|
||||
const int wsize = 2;
|
||||
|
||||
/* nothing to do */
|
||||
if (count == 0 || dest == src)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if ((ulong)dest < (ulong)src)
|
||||
{
|
||||
/* Copy forward. */
|
||||
t = (uint)src;
|
||||
|
||||
/* only need low bits */
|
||||
if (((t | (uint)dest) & wmask) != 0)
|
||||
{
|
||||
/*
|
||||
* Try to align operands. This cannot be done
|
||||
* unless the low bits match.
|
||||
*/
|
||||
if ((((t ^ (int)dest) & wmask) != 0) || (count < wsize))
|
||||
t = count;
|
||||
else
|
||||
t = wsize - (t & wmask);
|
||||
count -= t;
|
||||
if (t != 0)
|
||||
{
|
||||
do { *dest++ = *src++; }
|
||||
while (--t != 0);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Copy whole words, then mop up any trailing bytes.
|
||||
*/
|
||||
t = count / wsize;
|
||||
if (t != 0)
|
||||
{
|
||||
do
|
||||
{
|
||||
*(short*)dest = *(short*)src;
|
||||
src += wsize;
|
||||
dest += wsize;
|
||||
}
|
||||
while (--t != 0);
|
||||
}
|
||||
|
||||
t = count & wmask;
|
||||
if (t != 0)
|
||||
{
|
||||
do
|
||||
{
|
||||
dest++;
|
||||
src++;
|
||||
*dest = *src;
|
||||
}
|
||||
while (--t != 0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* Copy backwards. Otherwise essentially the same.
|
||||
* Alignment works as before, except that it takes
|
||||
* (t&wmask) bytes to align, not wsize-(t&wmask).
|
||||
*/
|
||||
src += count;
|
||||
dest += count;
|
||||
t = (uint)src;
|
||||
if (((t | (uint)dest) & wmask) != 0)
|
||||
{
|
||||
if (((t ^ (uint)dest) & wmask) != 0 || count <= wsize)
|
||||
t = count;
|
||||
else
|
||||
t &= wmask;
|
||||
count -= t;
|
||||
if (t != 0)
|
||||
{
|
||||
do
|
||||
{
|
||||
--dest;
|
||||
--src;
|
||||
*dest = *src;
|
||||
}
|
||||
while (--t != 0);
|
||||
}
|
||||
}
|
||||
t = count / wsize;
|
||||
if (t != 0)
|
||||
{
|
||||
do
|
||||
{
|
||||
src -= wsize;
|
||||
dest -= wsize;
|
||||
*(ushort*)dest = *(ushort*)src;
|
||||
}
|
||||
while (--t != 0);
|
||||
}
|
||||
|
||||
t = count & wmask;
|
||||
if (t != 0)
|
||||
{
|
||||
do
|
||||
{
|
||||
--dest;
|
||||
--src;
|
||||
*dest = *src;
|
||||
}
|
||||
while (--t != 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[PlugMethod(Assembler = typeof(Assemblers.Buffer_BlockCopy))]
|
||||
public static void BlockCopy(Array src, int srcOffset, Array dst, int dstOffset, int count) {
|
||||
}
|
||||
|
|
|
|||
|
|
@ -203,6 +203,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IL2CPU", "IL2CPU\IL2CPU.csp
|
|||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PlaygroundCore", "..\Users\Matthijs\PlaygroundCore\PlaygroundCore.csproj", "{AB869246-4887-4117-851D-766EB9FF1E29}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cosmos.IL2CPU.Tests", "Cosmos.IL2CPU.Tests\Cosmos.IL2CPU.Tests.csproj", "{17329379-67D5-45D2-8EF0-9C625C43E117}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
|
|
@ -988,6 +990,18 @@ Global
|
|||
{AB869246-4887-4117-851D-766EB9FF1E29}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||
{AB869246-4887-4117-851D-766EB9FF1E29}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||
{AB869246-4887-4117-851D-766EB9FF1E29}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{17329379-67D5-45D2-8EF0-9C625C43E117}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{17329379-67D5-45D2-8EF0-9C625C43E117}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{17329379-67D5-45D2-8EF0-9C625C43E117}.Debug|Itanium.ActiveCfg = Debug|Any CPU
|
||||
{17329379-67D5-45D2-8EF0-9C625C43E117}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||
{17329379-67D5-45D2-8EF0-9C625C43E117}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
|
||||
{17329379-67D5-45D2-8EF0-9C625C43E117}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{17329379-67D5-45D2-8EF0-9C625C43E117}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{17329379-67D5-45D2-8EF0-9C625C43E117}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{17329379-67D5-45D2-8EF0-9C625C43E117}.Release|Itanium.ActiveCfg = Release|Any CPU
|
||||
{17329379-67D5-45D2-8EF0-9C625C43E117}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||
{17329379-67D5-45D2-8EF0-9C625C43E117}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||
{17329379-67D5-45D2-8EF0-9C625C43E117}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
|
@ -1064,5 +1078,6 @@ Global
|
|||
{7E059184-F2C5-4CC6-B86D-FA12590C3C40} = {F104F6BC-EF8E-4408-A786-D570D7565231}
|
||||
{6128DEEB-D30F-4859-B60F-C36D5452F3E9} = {6A15C540-8278-4B9C-B890-FA57FB6AE6A6}
|
||||
{AB869246-4887-4117-851D-766EB9FF1E29} = {A0073D91-D9D3-4A90-9845-10E5CDBA5511}
|
||||
{17329379-67D5-45D2-8EF0-9C625C43E117} = {6A15C540-8278-4B9C-B890-FA57FB6AE6A6}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
|
|
|||
Loading…
Reference in a new issue