diff options
Diffstat (limited to 'tests/src/JIT/Directed/intrinsic/interlocked')
10 files changed, 517 insertions, 0 deletions
diff --git a/tests/src/JIT/Directed/intrinsic/interlocked/IntrinsicTest_Overflow.cs b/tests/src/JIT/Directed/intrinsic/interlocked/IntrinsicTest_Overflow.cs new file mode 100644 index 0000000000..21d87f12d4 --- /dev/null +++ b/tests/src/JIT/Directed/intrinsic/interlocked/IntrinsicTest_Overflow.cs @@ -0,0 +1,147 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +// Checks that there are no overflows for the interlocked intrinsics generated. + +using System; +using System.Threading; +using System.Runtime.CompilerServices; +public class IntrinsicTest +{ + private static int s_counter = 3245; + private int _instanceCounter; + private static long s_counter64 = 3245; + private long _instanceCounter64; + private static int s_id_counter = 3245; + private int _id_instanceCounter; + private static long s_id_counter64 = 3245; + private long _id_instanceCounter64; + private static long s_temp = 1111; + + private static long s_idmp = 1111; + private static long s_idjunk = 0; + [MethodImpl(MethodImplOptions.NoInlining)] + + private IntrinsicTest() { _instanceCounter = 3245; _instanceCounter64 = 3245; _id_instanceCounter = 3245; _id_instanceCounter64 = 3245; } + public int GetValue() { s_temp++; return (int)0x1ceddeed; } + + [MethodImpl(MethodImplOptions.NoInlining)] + + public int id_GetValue() { s_idmp++; return (int)0x1ceddeed; } + + public static bool MainTest() + { + int te0 = Int32.MaxValue, te1 = 4325, te2 = 4325, te3 = 2134; + long te064 = 454562, te164 = 345653, te264 = 345653, te364 = 345564; + int dummy = 4355; + long dummy64 = 656342; + int id0 = -1, id1 = 4325, id2 = 4325, id3 = 2134; + long id064 = 454562, id164 = 345653, id264 = 345653, id364 = 345564; + int idummy = 4355; + long idummy64 = 656342; + bool fail = false; + IntrinsicTest Dummy = new IntrinsicTest(); + + + te0 = Interlocked.Increment(ref te0); + id0 = Int32.MinValue; + Console.WriteLine("------------------------------------INC 0 0 0 0"); + if (te0 != id0) { fail = true; Console.WriteLine("te0 check failed {0} {1}", te0, id0); } + if (te1 != id1) { fail = true; Console.WriteLine("te1 check failed {0} {1}", te1, id1); } + if (te2 != id2) { fail = true; Console.WriteLine("te2 check failed {0} {1}", te2, id2); } + if (te3 != id3) { fail = true; Console.WriteLine("te3 check failed {0} {1}", te3, id3); } + if (te064 != id064) { fail = true; Console.WriteLine("te064 check failed {0} {1}", te064, id064); } + if (te164 != id164) { fail = true; Console.WriteLine("te164 check failed {0} {1}", te164, id164); } + if (te264 != id264) { fail = true; Console.WriteLine("te264 check failed {0} {1}", te264, id264); } + if (te364 != id364) { fail = true; Console.WriteLine("te364 check failed {0} {1}", te364, id364); } + if (dummy != idummy) { fail = true; Console.WriteLine("dummy check failed {0} {1}", dummy, idummy); } + if (dummy64 != idummy64) { fail = true; Console.WriteLine("dummy64 check failed {0} {1}", dummy64, idummy64); } + + if (s_counter != s_id_counter) { Console.WriteLine("counter mismatch {0} {1}", s_counter, s_id_counter); fail = true; } + if (s_counter64 != s_id_counter64) { Console.WriteLine("counter64 mismatch {0} {1}", s_counter64, s_id_counter64); fail = true; } + if (Dummy._instanceCounter != Dummy._id_instanceCounter) { Console.WriteLine("instanceCounter mismatch {0} {1}", Dummy._instanceCounter, Dummy._id_instanceCounter); fail = true; } + if (Dummy._instanceCounter64 != Dummy._id_instanceCounter64) { Console.WriteLine("instanceCounter64 mismatch {0} {1}", Dummy._instanceCounter64, Dummy._id_instanceCounter64); fail = true; } + if (s_temp != s_idmp) { Console.WriteLine("temp mismatch {0} {1}", s_temp, s_idmp); fail = true; } + + te0 = Interlocked.Decrement(ref te0); + id0 = Int32.MaxValue; + Console.WriteLine("------------------------------------DEC 0 0 0 0"); + if (te0 != id0) { fail = true; Console.WriteLine("te0 check failed {0} {1}", te0, id0); } + if (te1 != id1) { fail = true; Console.WriteLine("te1 check failed {0} {1}", te1, id1); } + if (te2 != id2) { fail = true; Console.WriteLine("te2 check failed {0} {1}", te2, id2); } + if (te3 != id3) { fail = true; Console.WriteLine("te3 check failed {0} {1}", te3, id3); } + if (te064 != id064) { fail = true; Console.WriteLine("te064 check failed {0} {1}", te064, id064); } + if (te164 != id164) { fail = true; Console.WriteLine("te164 check failed {0} {1}", te164, id164); } + if (te264 != id264) { fail = true; Console.WriteLine("te264 check failed {0} {1}", te264, id264); } + if (te364 != id364) { fail = true; Console.WriteLine("te364 check failed {0} {1}", te364, id364); } + if (dummy != idummy) { fail = true; Console.WriteLine("dummy check failed {0} {1}", dummy, idummy); } + if (dummy64 != idummy64) { fail = true; Console.WriteLine("dummy64 check failed {0} {1}", dummy64, idummy64); } + + if (s_counter != s_id_counter) { Console.WriteLine("counter mismatch {0} {1}", s_counter, s_id_counter); fail = true; } + if (s_counter64 != s_id_counter64) { Console.WriteLine("counter64 mismatch {0} {1}", s_counter64, s_id_counter64); fail = true; } + if (Dummy._instanceCounter != Dummy._id_instanceCounter) { Console.WriteLine("instanceCounter mismatch {0} {1}", Dummy._instanceCounter, Dummy._id_instanceCounter); fail = true; } + if (Dummy._instanceCounter64 != Dummy._id_instanceCounter64) { Console.WriteLine("instanceCounter64 mismatch {0} {1}", Dummy._instanceCounter64, Dummy._id_instanceCounter64); fail = true; } + if (s_temp != s_idmp) { Console.WriteLine("temp mismatch {0} {1}", s_temp, s_idmp); fail = true; } + + te0 = Int32.MaxValue; + id0 = Int32.MinValue; + te0 = Interlocked.Add(ref te0, 1); + Console.WriteLine("------------------------------------XADD 0 0 0 0"); + if (te0 != id0) { fail = true; Console.WriteLine("te0 check failed {0} {1}", te0, id0); } + if (te1 != id1) { fail = true; Console.WriteLine("te1 check failed {0} {1}", te1, id1); } + if (te2 != id2) { fail = true; Console.WriteLine("te2 check failed {0} {1}", te2, id2); } + if (te3 != id3) { fail = true; Console.WriteLine("te3 check failed {0} {1}", te3, id3); } + if (te064 != id064) { fail = true; Console.WriteLine("te064 check failed {0} {1}", te064, id064); } + if (te164 != id164) { fail = true; Console.WriteLine("te164 check failed {0} {1}", te164, id164); } + if (te264 != id264) { fail = true; Console.WriteLine("te264 check failed {0} {1}", te264, id264); } + if (te364 != id364) { fail = true; Console.WriteLine("te364 check failed {0} {1}", te364, id364); } + if (dummy != idummy) { fail = true; Console.WriteLine("dummy check failed {0} {1}", dummy, idummy); } + if (dummy64 != idummy64) { fail = true; Console.WriteLine("dummy64 check failed {0} {1}", dummy64, idummy64); } + + if (s_counter != s_id_counter) { Console.WriteLine("counter mismatch {0} {1}", s_counter, s_id_counter); fail = true; } + if (s_counter64 != s_id_counter64) { Console.WriteLine("counter64 mismatch {0} {1}", s_counter64, s_id_counter64); fail = true; } + if (Dummy._instanceCounter != Dummy._id_instanceCounter) { Console.WriteLine("instanceCounter mismatch {0} {1}", Dummy._instanceCounter, Dummy._id_instanceCounter); fail = true; } + if (Dummy._instanceCounter64 != Dummy._id_instanceCounter64) { Console.WriteLine("instanceCounter64 mismatch {0} {1}", Dummy._instanceCounter64, Dummy._id_instanceCounter64); fail = true; } + if (s_temp != s_idmp) { Console.WriteLine("temp mismatch {0} {1}", s_temp, s_idmp); fail = true; } + + te0 = Int32.MinValue; + id0 = Int32.MaxValue; + te0 = Interlocked.Add(ref te0, -1); + Console.WriteLine("------------------------------------XADD 0 0 0 0"); + if (te0 != id0) { fail = true; Console.WriteLine("te0 check failed {0} {1}", te0, id0); } + if (te1 != id1) { fail = true; Console.WriteLine("te1 check failed {0} {1}", te1, id1); } + if (te2 != id2) { fail = true; Console.WriteLine("te2 check failed {0} {1}", te2, id2); } + if (te3 != id3) { fail = true; Console.WriteLine("te3 check failed {0} {1}", te3, id3); } + if (te064 != id064) { fail = true; Console.WriteLine("te064 check failed {0} {1}", te064, id064); } + if (te164 != id164) { fail = true; Console.WriteLine("te164 check failed {0} {1}", te164, id164); } + if (te264 != id264) { fail = true; Console.WriteLine("te264 check failed {0} {1}", te264, id264); } + if (te364 != id364) { fail = true; Console.WriteLine("te364 check failed {0} {1}", te364, id364); } + if (dummy != idummy) { fail = true; Console.WriteLine("dummy check failed {0} {1}", dummy, idummy); } + if (dummy64 != idummy64) { fail = true; Console.WriteLine("dummy64 check failed {0} {1}", dummy64, idummy64); } + + if (s_counter != s_id_counter) { Console.WriteLine("counter mismatch {0} {1}", s_counter, s_id_counter); fail = true; } + if (s_counter64 != s_id_counter64) { Console.WriteLine("counter64 mismatch {0} {1}", s_counter64, s_id_counter64); fail = true; } + if (Dummy._instanceCounter != Dummy._id_instanceCounter) { Console.WriteLine("instanceCounter mismatch {0} {1}", Dummy._instanceCounter, Dummy._id_instanceCounter); fail = true; } + if (Dummy._instanceCounter64 != Dummy._id_instanceCounter64) { Console.WriteLine("instanceCounter64 mismatch {0} {1}", Dummy._instanceCounter64, Dummy._id_instanceCounter64); fail = true; } + if (s_temp != s_idmp) { Console.WriteLine("temp mismatch {0} {1}", s_temp, s_idmp); fail = true; } + + return fail; + } + + private static int Main() + { + if (MainTest()) + { + Console.WriteLine("Test Failed"); + return 101; + } + else + { + Console.WriteLine("Test Passed"); + return 100; + } + } +} +; + diff --git a/tests/src/JIT/Directed/intrinsic/interlocked/app.config b/tests/src/JIT/Directed/intrinsic/interlocked/app.config new file mode 100644 index 0000000000..62803f5972 --- /dev/null +++ b/tests/src/JIT/Directed/intrinsic/interlocked/app.config @@ -0,0 +1,27 @@ +<?xml version="1.0" encoding="utf-8"?> +<configuration> + <runtime> + <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> + <dependentAssembly> + <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> + <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" /> + </dependentAssembly> + <dependentAssembly> + <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> + <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" /> + </dependentAssembly> + <dependentAssembly> + <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> + <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" /> + </dependentAssembly> + <dependentAssembly> + <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> + <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" /> + </dependentAssembly> + <dependentAssembly> + <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> + <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" /> + </dependentAssembly> + </assemblyBinding> + </runtime> +</configuration>
\ No newline at end of file diff --git a/tests/src/JIT/Directed/intrinsic/interlocked/cmpxchg.cs b/tests/src/JIT/Directed/intrinsic/interlocked/cmpxchg.cs new file mode 100644 index 0000000000..99ab9cb9ee --- /dev/null +++ b/tests/src/JIT/Directed/intrinsic/interlocked/cmpxchg.cs @@ -0,0 +1,54 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using System; +using System.Threading; +using System.Runtime.CompilerServices; +public class CMPXCHG +{ + public static int g_static = -1; + public static void Function(int bit, bool value) + { + for (; ;) + { + int oldData = g_static; + int newData; + if (value) + { + newData = oldData | bit; + } + else + { + newData = oldData & ~bit; + } + +#pragma warning disable 0420 + int result = Interlocked.CompareExchange(ref g_static, newData, oldData); +#pragma warning restore 0420 + + if (result == oldData) + { + return; + } + } + } + public static int Main() + { + for (int i = 0; i < 10; ++i) + { + if (g_static < 10) + { + Function(7, true); + } + if (g_static < 9) + { + Function(11, false); + } + if (g_static < 8) + Function(12, false); + } + return 100; + //If we dont reach here, we have a problem! + } +} diff --git a/tests/src/JIT/Directed/intrinsic/interlocked/cs_template.proj b/tests/src/JIT/Directed/intrinsic/interlocked/cs_template.proj new file mode 100644 index 0000000000..adc2f21e14 --- /dev/null +++ b/tests/src/JIT/Directed/intrinsic/interlocked/cs_template.proj @@ -0,0 +1,42 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" /> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <AssemblyName>$(AssemblyName1)</AssemblyName> + <SchemaVersion>2.0</SchemaVersion> + <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid> + <OutputType>Exe</OutputType> + <AppDesignerFolder>Properties</AppDesignerFolder> + <FileAlignment>512</FileAlignment> + <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> + <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath> + <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir> + <RestorePackages>true</RestorePackages> + <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp> + </PropertyGroup> + <!-- Default configurations to help VS understand the configurations --> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> + </PropertyGroup> + <ItemGroup> + <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies"> + <Visible>False</Visible> + </CodeAnalysisDependentAssemblyPaths> + </ItemGroup> + <ItemGroup> + <Compile Include="$(AssemblyName1).cs" /> + </ItemGroup> + <ItemGroup> + <None Include="packages.config" /> + <None Include="app.config" /> + </ItemGroup> + <ItemGroup> + <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> + </ItemGroup> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> + <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "> + </PropertyGroup> +</Project> diff --git a/tests/src/JIT/Directed/intrinsic/interlocked/cse_cmpxchg.cs b/tests/src/JIT/Directed/intrinsic/interlocked/cse_cmpxchg.cs new file mode 100644 index 0000000000..d8f609cacf --- /dev/null +++ b/tests/src/JIT/Directed/intrinsic/interlocked/cse_cmpxchg.cs @@ -0,0 +1,26 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using System; +using System.Threading; +using System.Runtime.CompilerServices; +internal class Foo +{ + private static int s_taskIdCounter; + private int _taskId = 0; + [MethodImpl(MethodImplOptions.NoInlining)] + public int Function() + { + if (_taskId == 0) + { + int newId = Interlocked.Increment(ref s_taskIdCounter); + Interlocked.CompareExchange(ref _taskId, newId, 0); + } + return _taskId; + } + public static int Main() + { + if (new Foo().Function() == 1) return 100; else return 101; + } +} diff --git a/tests/src/JIT/Directed/intrinsic/interlocked/interlocked.csproj b/tests/src/JIT/Directed/intrinsic/interlocked/interlocked.csproj new file mode 100644 index 0000000000..33b2928ebc --- /dev/null +++ b/tests/src/JIT/Directed/intrinsic/interlocked/interlocked.csproj @@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" /> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> + <!-- Default configurations to help VS understand the configurations --> + <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'"> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'"> + </PropertyGroup> + <Target Name="Build"> + <ItemGroup> + <AllSourceFiles Include="$(MSBuildProjectDirectory)\*.cs" /> + </ItemGroup> + <PropertyGroup> + <GenerateRunScript>false</GenerateRunScript> + </PropertyGroup> + <MSBuild Projects="cs_template.proj" Properties="AssemblyName1=%(AllSourceFiles.FileName);AllowUnsafeBlocks=True;IntermediateOutputPath=$(IntermediateOutputPath)\%(AllSourceFiles.FileName)\" /> + </Target> +</Project> diff --git a/tests/src/JIT/Directed/intrinsic/interlocked/nullchecksuppress.cs b/tests/src/JIT/Directed/intrinsic/interlocked/nullchecksuppress.cs new file mode 100644 index 0000000000..3d6c133957 --- /dev/null +++ b/tests/src/JIT/Directed/intrinsic/interlocked/nullchecksuppress.cs @@ -0,0 +1,40 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using System; +using System.Threading; +using System.Runtime.CompilerServices; +public class NCS +{ + public int field; + + [MethodImpl(MethodImplOptions.NoInlining)] + public static int Increment(ref int value) + { + return Interlocked.Increment(ref value); + } + public static int Decrement(ref int value) + { + return Interlocked.Decrement(ref value); + } + public static int Add(ref int value, int other) + { + return Interlocked.Add(ref value, other); + } + public static int CompareExchange(ref int value, int newData, int oldData) + { + return Interlocked.CompareExchange(ref value, newData, oldData); + } + + public static int Main() + { + NCS ncs = new NCS(); + ncs.field = 99; + CompareExchange(ref ncs.field, 105, 99); + Decrement(ref ncs.field); + Add(ref ncs.field, -5); + Increment(ref ncs.field); + return ncs.field; + } +} diff --git a/tests/src/JIT/Directed/intrinsic/interlocked/packages.config b/tests/src/JIT/Directed/intrinsic/interlocked/packages.config new file mode 100644 index 0000000000..c530dff390 --- /dev/null +++ b/tests/src/JIT/Directed/intrinsic/interlocked/packages.config @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="utf-8"?> +<packages> + <package id="System.Console" version="4.0.0-beta-22405" /> + <package id="System.Runtime" version="4.0.20-beta-22405" /> + <package id="System.Runtime.Extensions" version="4.0.10-beta-22412" /> + <package id="System.Threading" version="4.0.0-beta-22412" /> +</packages> diff --git a/tests/src/JIT/Directed/intrinsic/interlocked/regalloc1.cs b/tests/src/JIT/Directed/intrinsic/interlocked/regalloc1.cs new file mode 100644 index 0000000000..c82fef30fb --- /dev/null +++ b/tests/src/JIT/Directed/intrinsic/interlocked/regalloc1.cs @@ -0,0 +1,77 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using System; +using System.Threading; +using System.Runtime.CompilerServices; +public class IntrinsicTest +{ + private static int s_counter; + private int _instanceCounter; + private static long s_counter64; + private long _instanceCounter64; + private static int s_id_counter; + private int _id_instanceCounter; + private static long s_id_counter64; + private long _id_instanceCounter64; + private static long s_temp = 1111; + + private static long s_idmp = 1111;[MethodImpl(MethodImplOptions.NoInlining)] + + public int GetValue() { s_temp++; return (int)0x1ceddeed; } + + [MethodImpl(MethodImplOptions.NoInlining)] + + public int id_GetValue() { s_idmp++; return (int)0x1ceddeed; } + + public static bool MainTest() + { + int te0 = 3245, te1 = 4325, te2 = 4325, te3 = 2134; + long te064 = 454562, te164 = 345653, te264 = 345653, te364 = 345564; + int dummy = 4355; + long dummy64 = 656342; + int id0 = 3245, id1 = 4325, id2 = 4325, id3 = 2134; + long id064 = 454562, id164 = 345653, id264 = 345653, id364 = 345564; + int idummy = 4355; + long idummy64 = 656342; + bool fail = false; + IntrinsicTest Dummy = new IntrinsicTest(); + + te0 = Interlocked.CompareExchange(ref s_counter, te0, Dummy.GetValue()); + id0 = s_id_counter; s_id_counter = (s_id_counter == Dummy.id_GetValue()) ? id0 : s_id_counter; + Console.WriteLine("------------------------------------CMPXCHG 1 0 3 0"); + if (te0 != id0) { fail = true; Console.WriteLine("te0 check failed {0} {1}", te0, id0); } + if (te1 != id1) { fail = true; Console.WriteLine("te1 check failed {0} {1}", te1, id1); } + if (te2 != id2) { fail = true; Console.WriteLine("te2 check failed {0} {1}", te2, id2); } + if (te3 != id3) { fail = true; Console.WriteLine("te3 check failed {0} {1}", te3, id3); } + if (te064 != id064) { fail = true; Console.WriteLine("te064 check failed {0} {1}", te064, id064); } + if (te164 != id164) { fail = true; Console.WriteLine("te164 check failed {0} {1}", te164, id164); } + if (te264 != id264) { fail = true; Console.WriteLine("te264 check failed {0} {1}", te264, id264); } + if (te364 != id364) { fail = true; Console.WriteLine("te364 check failed {0} {1}", te364, id364); } + if (dummy != idummy) { fail = true; Console.WriteLine("dummy check failed {0} {1}", dummy, idummy); } + if (dummy64 != idummy64) { fail = true; Console.WriteLine("dummy64 check failed {0} {1}", dummy64, idummy64); } + + if (s_counter != s_id_counter) { Console.WriteLine("counter mismatch {0} {1}", s_counter, s_id_counter); fail = true; } + if (s_counter64 != s_id_counter64) { Console.WriteLine("counter64 mismatch {0} {1}", s_counter64, s_id_counter64); fail = true; } + if (Dummy._instanceCounter != Dummy._id_instanceCounter) { Console.WriteLine("instanceCounter mismatch {0} {1}", Dummy._instanceCounter, Dummy._id_instanceCounter); fail = true; } + if (Dummy._instanceCounter64 != Dummy._id_instanceCounter64) { Console.WriteLine("instanceCounter64 mismatch {0} {1}", Dummy._instanceCounter64, Dummy._id_instanceCounter64); fail = true; } + if (s_temp != s_idmp) { Console.WriteLine("temp mismatch {0} {1}", s_temp, s_idmp); fail = true; } + return fail; + } + + private static int Main() + { + if (MainTest()) + { + Console.WriteLine("Test Failed"); + return 101; + } + else + { + Console.WriteLine("Test Passed"); + return 100; + } + } +} + diff --git a/tests/src/JIT/Directed/intrinsic/interlocked/regalloc2.cs b/tests/src/JIT/Directed/intrinsic/interlocked/regalloc2.cs new file mode 100644 index 0000000000..096e6ee246 --- /dev/null +++ b/tests/src/JIT/Directed/intrinsic/interlocked/regalloc2.cs @@ -0,0 +1,78 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using System; +using System.Threading; +using System.Runtime.CompilerServices; +public class IntrinsicTest +{ + private static int s_counter; + private int _instanceCounter; + private static long s_counter64; + private long _instanceCounter64; + private static int s_id_counter; + private int _id_instanceCounter; + private static long s_id_counter64; + private long _id_instanceCounter64; + private static long s_temp = 1111; + + private static long s_idmp = 1111; + private static long s_idjunk = 0; + [MethodImpl(MethodImplOptions.NoInlining)] + + public int GetValue() { s_temp++; return (int)0x1ceddeed; } + + [MethodImpl(MethodImplOptions.NoInlining)] + + public int id_GetValue() { s_idmp++; return (int)0x1ceddeed; } + + public static bool MainTest() + { + int te0 = 3245, te1 = 4325, te2 = 4325, te3 = 2134; + long te064 = 454562, te164 = 345653, te264 = 345653, te364 = 345564; + int dummy = 4355; + long dummy64 = 656342; + int id0 = 3245, id1 = 4325, id2 = 4325, id3 = 2134; + long id064 = 454562, id164 = 345653, id264 = 345653, id364 = 345564; + int idummy = 4355; + long idummy64 = 656342; + bool fail = false; + IntrinsicTest Dummy = new IntrinsicTest(); + te0 = Interlocked.CompareExchange(ref te0, Dummy.GetValue(), te0); + id0 = id0; if ((id0 == id0)) s_idjunk = Dummy.id_GetValue(); else s_idjunk = Dummy.id_GetValue(); + Console.WriteLine("------------------------------------CMPXCHG 0 3 0 0"); + if (te0 != id0) { fail = true; Console.WriteLine("te0 check failed {0} {1}", te0, id0); } + if (te1 != id1) { fail = true; Console.WriteLine("te1 check failed {0} {1}", te1, id1); } + if (te2 != id2) { fail = true; Console.WriteLine("te2 check failed {0} {1}", te2, id2); } + if (te3 != id3) { fail = true; Console.WriteLine("te3 check failed {0} {1}", te3, id3); } + if (te064 != id064) { fail = true; Console.WriteLine("te064 check failed {0} {1}", te064, id064); } + if (te164 != id164) { fail = true; Console.WriteLine("te164 check failed {0} {1}", te164, id164); } + if (te264 != id264) { fail = true; Console.WriteLine("te264 check failed {0} {1}", te264, id264); } + if (te364 != id364) { fail = true; Console.WriteLine("te364 check failed {0} {1}", te364, id364); } + if (dummy != idummy) { fail = true; Console.WriteLine("dummy check failed {0} {1}", dummy, idummy); } + if (dummy64 != idummy64) { fail = true; Console.WriteLine("dummy64 check failed {0} {1}", dummy64, idummy64); } + + if (s_counter != s_id_counter) { Console.WriteLine("counter mismatch {0} {1}", s_counter, s_id_counter); fail = true; } + if (s_counter64 != s_id_counter64) { Console.WriteLine("counter64 mismatch {0} {1}", s_counter64, s_id_counter64); fail = true; } + if (Dummy._instanceCounter != Dummy._id_instanceCounter) { Console.WriteLine("instanceCounter mismatch {0} {1}", Dummy._instanceCounter, Dummy._id_instanceCounter); fail = true; } + if (Dummy._instanceCounter64 != Dummy._id_instanceCounter64) { Console.WriteLine("instanceCounter64 mismatch {0} {1}", Dummy._instanceCounter64, Dummy._id_instanceCounter64); fail = true; } + if (s_temp != s_idmp) { Console.WriteLine("temp mismatch {0} {1}", s_temp, s_idmp); fail = true; } + return fail; + } + + private static int Main() + { + if (MainTest()) + { + Console.WriteLine("Test Failed"); + return 101; + } + else + { + Console.WriteLine("Test Passed"); + return 100; + } + } +} + |