From 4286b4006c3c671d9d9cc1b6979498275b526775 Mon Sep 17 00:00:00 2001 From: Mike Danes Date: Sat, 14 Nov 2015 10:46:20 +0200 Subject: Add tests for integer div/mod by const --- tests/src/JIT/CodeGenBringUpTests/DivConst.cs | 442 +++++++++++++++++++++ tests/src/JIT/CodeGenBringUpTests/DivConst.csproj | 43 ++ tests/src/JIT/CodeGenBringUpTests/ModConst.cs | 427 ++++++++++++++++++++ tests/src/JIT/CodeGenBringUpTests/ModConst.csproj | 43 ++ tests/src/JIT/CodeGenBringUpTests/UDivConst.cs | 219 ++++++++++ tests/src/JIT/CodeGenBringUpTests/UDivConst.csproj | 43 ++ tests/src/JIT/CodeGenBringUpTests/UModConst.cs | 224 +++++++++++ tests/src/JIT/CodeGenBringUpTests/UModConst.csproj | 43 ++ 8 files changed, 1484 insertions(+) create mode 100644 tests/src/JIT/CodeGenBringUpTests/DivConst.cs create mode 100644 tests/src/JIT/CodeGenBringUpTests/DivConst.csproj create mode 100644 tests/src/JIT/CodeGenBringUpTests/ModConst.cs create mode 100644 tests/src/JIT/CodeGenBringUpTests/ModConst.csproj create mode 100644 tests/src/JIT/CodeGenBringUpTests/UDivConst.cs create mode 100644 tests/src/JIT/CodeGenBringUpTests/UDivConst.csproj create mode 100644 tests/src/JIT/CodeGenBringUpTests/UModConst.cs create mode 100644 tests/src/JIT/CodeGenBringUpTests/UModConst.csproj (limited to 'tests') diff --git a/tests/src/JIT/CodeGenBringUpTests/DivConst.cs b/tests/src/JIT/CodeGenBringUpTests/DivConst.cs new file mode 100644 index 0000000000..38b15e9cdc --- /dev/null +++ b/tests/src/JIT/CodeGenBringUpTests/DivConst.cs @@ -0,0 +1,442 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.CompilerServices; + +static class DivConst +{ + // I4 + + [MethodImpl(MethodImplOptions.NoInlining)] + public static int I4_Div_0(int i4) + { + return i4 / 0; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static int I4_Div_1(int i4) + { + return i4 / 1; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static int I4_Div_Minus1(int i4) + { + return i4 / -1; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static int I4_Div_3(int i4) + { + return i4 / 3; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static int I4_DivRef_5(ref int i4) + { + return i4 / 5; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static int I4_Div_7(int i4) + { + return i4 / 7; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static int I4_Div_Minus3(int i4) + { + return i4 / -3; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static int I4_DivPow2_2(int i4) + { + return i4 / 2; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static int I4_DivPow2_Minus2(int i4) + { + return i4 / -2; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static int I4_DivPow2_8(ref int i4) + { + return i4 / 8; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static int I4_DivPow2_Minus4(int i4) + { + return i4 / -4; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static int I4_DivPow2_I4Min(int i4) + { + return i4 / int.MinValue; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static int I4_DivPow2Embedded_4(int x, int y) + { + return y * 2 + (x + 2) / 4 + (x * y >> 31); + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static int I4_DivPow2Embdedded_Point(Point p) + { + int a = p.X + 4; + int b = (a - p.Y) / 2; + return p.Y > p.X ? a : b; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static int I4_DivPow2Call_8(int i4) + { + return I4_DivPow2_2(i4 / 8) + I4_DivRef_5(ref i4) / 8; + } + + // I8 + + [MethodImpl(MethodImplOptions.NoInlining)] + public static long I8_Div_0(long i8) + { + return i8 / 0; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static long I8_Div_1(long i8) + { + return i8 / 1; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static long I8_Div_Minus1(long i8) + { + return i8 / -1; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static long I8_Div_3(long i8) + { + return i8 / 3; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static long I8_Div_5(long i8) + { + return i8 / 5; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static long I8_Div_7(ref long i8) + { + return i8 / 7; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static long I8_Div_Minus3(long i8) + { + return i8 / -3; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static long I8_DivPow2_4(long i8) + { + return i8 / 4; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static long I8_DivPow2_Minus8(long i8) + { + return i8 / -8; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static long I8_DivUncontainedPow2_1Shl32(long i8) + { + return i8 / (1L << 32); + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static long I8_DivUncontainedPow2_I8Min(long i8) + { + return i8 / long.MinValue; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static long I8_DivPow2Embedded_4(long x, long y) + { + return y * 2 + (x + 2) / 4 + (x * y >> 31); + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static long I8_DivPow2Call_8(long i8) + { + return I8_DivPow2_4(i8 / 8) + I8_Div_5(i8) / 8; + } +} + +class Point +{ + public int X; + public int Y; +} + +static class DivProgram +{ + public static int Main() + { + const int Pass = 100; + const int Fail = -1; + + // I4 + + try + { + DivConst.I4_Div_0(42); + return Fail; + } + catch (DivideByZeroException) + { + } + catch (Exception) + { + return Fail; + } + + if (DivConst.I4_Div_1(42) != 42) + { + return Fail; + } + + if (DivConst.I4_Div_Minus1(42) != -42) + { + return Fail; + } + + try + { + DivConst.I4_Div_Minus1(int.MinValue); + return Fail; + } + catch (OverflowException) + { + } + catch (Exception) + { + return Fail; + } + + if (DivConst.I4_Div_3(42) != 14) + { + return Fail; + } + + { + int dividend = 42; + + if (DivConst.I4_DivRef_5(ref dividend) != 8) + { + return Fail; + } + } + + if (DivConst.I4_Div_7(42) != 6) + { + return Fail; + } + + if (DivConst.I4_Div_Minus3(42) != -14) + { + return Fail; + } + + if (DivConst.I4_DivPow2_2(42) != 21) + { + return Fail; + } + + if (DivConst.I4_DivPow2_2(43) != 21) + { + return Fail; + } + + if (DivConst.I4_DivPow2_2(-42) != -21) + { + return Fail; + } + + if (DivConst.I4_DivPow2_2(-43) != -21) + { + return Fail; + } + + if (DivConst.I4_DivPow2_Minus2(43) != -21) + { + return Fail; + } + + { + int dividend = 42; + + if (DivConst.I4_DivPow2_8(ref dividend) != 5) + { + return Fail; + } + } + + { + int dividend = -42; + + if (DivConst.I4_DivPow2_8(ref dividend) != -5) + { + return Fail; + } + } + + if (DivConst.I4_DivPow2_Minus4(42) != -10) + { + return Fail; + } + + if (DivConst.I4_DivPow2_Minus4(-42) != 10) + { + return Fail; + } + + if (DivConst.I4_DivPow2_I4Min(-42) != 0) + { + return Fail; + } + + if (DivConst.I4_DivPow2_I4Min(int.MinValue) != 1) + { + return Fail; + } + + if (DivConst.I4_DivPow2Embedded_4(420, 938) != 1981) + { + return Fail; + } + + if (DivConst.I4_DivPow2Embdedded_Point(new Point { X = 513, Y = 412 }) != 52) + { + return Fail; + } + + if (DivConst.I4_DivPow2Call_8(420) != 36) + { + return Fail; + } + + // I8 + + try + { + DivConst.I8_Div_0(42); + return Fail; + } + catch (DivideByZeroException) + { + } + catch (Exception) + { + return Pass; + } + + if (DivConst.I8_Div_1(42) != 42) + { + return Fail; + } + + if (DivConst.I8_Div_Minus1(42) != -42) + { + return Fail; + } + + try + { + DivConst.I8_Div_Minus1(long.MinValue); + return Fail; + } + catch (OverflowException) + { + } + catch (Exception) + { + return Fail; + } + + if (DivConst.I8_Div_3(42) != 14) + { + return Fail; + } + + if (DivConst.I8_Div_5(42) != 8) + { + return Fail; + } + + { + long dividend = 45; + + if (DivConst.I8_Div_7(ref dividend) != 6) + { + return Fail; + } + } + + if (DivConst.I8_Div_Minus3(42) != -14) + { + return Fail; + } + + if (DivConst.I8_DivPow2_4(42) != 10) + { + return Fail; + } + + if (DivConst.I8_DivPow2_Minus8(42) != -5) + { + return Fail; + } + + if (DivConst.I8_DivPow2_Minus8(-42) != 5) + { + return Fail; + } + + if (DivConst.I8_DivUncontainedPow2_1Shl32(1L << 33) != 2) + { + return Fail; + } + + if (DivConst.I8_DivUncontainedPow2_I8Min(42) != 0) + { + return Fail; + } + + if (DivConst.I8_DivUncontainedPow2_I8Min(long.MinValue) != 1) + { + return Fail; + } + + if (DivConst.I8_DivPow2Embedded_4(420, 938) != 1981) + { + return Fail; + } + + if (DivConst.I8_DivPow2Call_8(420) != 23) + { + return Fail; + } + + return Pass; + } +} diff --git a/tests/src/JIT/CodeGenBringUpTests/DivConst.csproj b/tests/src/JIT/CodeGenBringUpTests/DivConst.csproj new file mode 100644 index 0000000000..58b6823bae --- /dev/null +++ b/tests/src/JIT/CodeGenBringUpTests/DivConst.csproj @@ -0,0 +1,43 @@ + + + + + Debug + AnyCPU + 2.0 + {EC6FD253-5247-4D8C-887E-453B5647A0A7} + Exe + Properties + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + $(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages + ..\..\ + 7a9bfb7d + + + + + + + + + False + + + + + + + + + + + + + $(JitPackagesConfigFileDirectory)threading+thread\project.json + $(JitPackagesConfigFileDirectory)threading+thread\project.lock.json + + + + + \ No newline at end of file diff --git a/tests/src/JIT/CodeGenBringUpTests/ModConst.cs b/tests/src/JIT/CodeGenBringUpTests/ModConst.cs new file mode 100644 index 0000000000..4552fed1b7 --- /dev/null +++ b/tests/src/JIT/CodeGenBringUpTests/ModConst.cs @@ -0,0 +1,427 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.CompilerServices; + +static class ModConst +{ + // I4 + + [MethodImpl(MethodImplOptions.NoInlining)] + public static int I4_Mod_0(int i4) + { + return i4 % 0; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static int I4_Mod_1(int i4) + { + return i4 % 1; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static int I4_Mod_Minus1(int i4) + { + return i4 % -1; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static int I4_Mod_3(int i4) + { + return i4 % 3; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static int I4_ModRef_5(ref int i4) + { + return i4 % 5; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static int I4_Mod_7(int i4) + { + return i4 % 7; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static int I4_Mod_Minus3(int i4) + { + return i4 % -3; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static int I4_ModPow2_2(int i4) + { + return i4 % 2; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static int I4_ModPow2_Minus2(int i4) + { + return i4 % -2; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static int I4_ModPow2_8(ref int i4) + { + return i4 % 8; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static int I4_ModPow2_Minus4(int i4) + { + return i4 % -4; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static int I4_ModPow2_I4Min(ref int i4) + { + return i4 % int.MinValue; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static int I4_ModPow2Embedded_4(int x, int y) + { + return y * 2 + (x + 2) % 4 + (x * y >> 31); + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static int I4_ModPow2Call_8(int i4) + { + return I4_ModPow2_2(i4 % 8) + I4_ModRef_5(ref i4) % 8; + } + + // I8 + + [MethodImpl(MethodImplOptions.NoInlining)] + public static long I8_Mod_0(long i8) + { + return i8 % 0; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static long I8_Mod_1(long i8) + { + return i8 % 1; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static long I8_Mod_Minus1(long i8) + { + return i8 % -1; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static long I8_Mod_3(long i8) + { + return i8 % 3; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static long I8_Mod_5(long i8) + { + return i8 % 5; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static long I8_Mod_7(long i8) + { + return i8 % 7; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static long I8_Mod_Minus3(long i8) + { + return i8 % -3; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static long I8_ModPow2_4(long i8) + { + return i8 % 4; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static long I8_ModPow2_Minus8(long i8) + { + return i8 % -8; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static long I8_ModUncontainedPow2_1Shl32(long i8) + { + return i8 % (1L << 32); + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static long I8_ModUncontainedPow2_I8Min(long i8) + { + return i8 % long.MinValue; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static long I8_ModPow2Embedded_4(long x, long y) + { + return y * 2 + (x + 2) % 4 + (x * y >> 31); + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static long I8_ModPow2Call_8(long i8) + { + return I8_ModPow2_4(i8 % 8) + I8_Mod_5(i8) % 8; + } +} + +static class ModProgram +{ + public static int Main() + { + const int Pass = 100; + const int Fail = -1; + + // I4 + + try + { + ModConst.I4_Mod_0(42); + return Fail; + } + catch (DivideByZeroException) + { + } + catch (Exception) + { + return Fail; + } + + if (ModConst.I4_Mod_1(42) != 0) + { + return Fail; + } + + if (ModConst.I4_Mod_Minus1(42) != 0) + { + return Fail; + } + + try + { + ModConst.I4_Mod_Minus1(int.MinValue); + return Fail; + } + catch (OverflowException) + { + } + catch (Exception) + { + return Fail; + } + + if (ModConst.I4_Mod_3(41) != 2) + { + return Fail; + } + + { + int dividend = 42; + + if (ModConst.I4_ModRef_5(ref dividend) != 2) + { + return Fail; + } + } + + if (ModConst.I4_Mod_7(42) != 0) + { + return Fail; + } + + if (ModConst.I4_Mod_Minus3(41) != 2) + { + return Fail; + } + + if (ModConst.I4_ModPow2_2(43) != 1) + { + return Fail; + } + + if (ModConst.I4_ModPow2_2(42) != 0) + { + return Fail; + } + + if (ModConst.I4_ModPow2_2(-43) != -1) + { + return Fail; + } + + if (ModConst.I4_ModPow2_2(-42) != 0) + { + return Fail; + } + + if (ModConst.I4_ModPow2_Minus2(43) != 1) + { + return Fail; + } + + { + int dividend = 42; + + if (ModConst.I4_ModPow2_8(ref dividend) != 2) + { + return Fail; + } + } + + { + int dividend = -42; + + if (ModConst.I4_ModPow2_8(ref dividend) != -2) + { + return Fail; + } + } + + if (ModConst.I4_ModPow2_Minus4(42) != 2) + { + return Fail; + } + + if (ModConst.I4_ModPow2_Minus4(-42) != -2) + { + return Fail; + } + + { + int dividend = -42; + + if (ModConst.I4_ModPow2_I4Min(ref dividend) != -42) + { + return Fail; + } + } + + { + int dividend = int.MinValue; + + if (ModConst.I4_ModPow2_I4Min(ref dividend) != 0) + { + return Fail; + } + } + + if (ModConst.I4_ModPow2Embedded_4(420, 938) != 1878) + { + return Fail; + } + + if (ModConst.I4_ModPow2Call_8(3674) != 4) + { + return Fail; + } + + // I8 + + try + { + ModConst.I8_Mod_0(42); + return Fail; + } + catch (DivideByZeroException) + { + } + catch (Exception) + { + return Pass; + } + + if (ModConst.I8_Mod_1(42) != 0) + { + return Fail; + } + + if (ModConst.I8_Mod_Minus1(42) != 0) + { + return Fail; + } + + try + { + ModConst.I8_Mod_Minus1(long.MinValue); + return Fail; + } + catch (OverflowException) + { + } + catch (Exception) + { + return Fail; + } + + if (ModConst.I8_Mod_3(43) != 1) + { + return Fail; + } + + if (ModConst.I8_Mod_5(42) != 2) + { + return Fail; + } + + if (ModConst.I8_Mod_7(45) != 3) + { + return Fail; + } + + if (ModConst.I8_Mod_Minus3(-43) != -1) + { + return Fail; + } + + if (ModConst.I8_ModPow2_4(42) != 2) + { + return Fail; + } + + if (ModConst.I8_ModPow2_Minus8(42) != 2) + { + return Fail; + } + + if (ModConst.I8_ModPow2_Minus8(-42) != -2) + { + return Fail; + } + + if (ModConst.I8_ModUncontainedPow2_1Shl32((1L << 33) + 42L) != 42) + { + return Fail; + } + + if (ModConst.I8_ModUncontainedPow2_I8Min(42) != 42) + { + return Fail; + } + + if (ModConst.I8_ModUncontainedPow2_I8Min(long.MinValue) != 0) + { + return Fail; + } + + if (ModConst.I8_ModPow2Embedded_4(420, 938) != 1878) + { + return Fail; + } + + if (ModConst.I8_ModPow2Call_8(3674) != 6) + { + return Fail; + } + + return Pass; + } +} diff --git a/tests/src/JIT/CodeGenBringUpTests/ModConst.csproj b/tests/src/JIT/CodeGenBringUpTests/ModConst.csproj new file mode 100644 index 0000000000..7e04c9223b --- /dev/null +++ b/tests/src/JIT/CodeGenBringUpTests/ModConst.csproj @@ -0,0 +1,43 @@ + + + + + Debug + AnyCPU + 2.0 + {314823E3-7BB2-4C19-BA04-5AC565215BA3} + Exe + Properties + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + $(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages + ..\..\ + 7a9bfb7d + + + + + + + + + False + + + + + + + + + + + + + $(JitPackagesConfigFileDirectory)threading+thread\project.json + $(JitPackagesConfigFileDirectory)threading+thread\project.lock.json + + + + + \ No newline at end of file diff --git a/tests/src/JIT/CodeGenBringUpTests/UDivConst.cs b/tests/src/JIT/CodeGenBringUpTests/UDivConst.cs new file mode 100644 index 0000000000..cd507fe554 --- /dev/null +++ b/tests/src/JIT/CodeGenBringUpTests/UDivConst.cs @@ -0,0 +1,219 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.CompilerServices; + +static class UDivConst +{ + // U4 + + [MethodImpl(MethodImplOptions.NoInlining)] + public static uint U4_Div_0(uint u4) + { + return u4 / 0; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static uint U4_Div_1(uint u4) + { + return u4 / 1; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static uint U4_Div_3(uint u4) + { + return u4 / 3; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static uint U4_Div_5(uint u4) + { + return u4 / 5; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static uint U4_Div_7(uint u4) + { + return u4 / 7; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static uint U4_DivPow2_16(uint u4) + { + return u4 / 16; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static uint U4_DivPow2_I4Min(uint u4) + { + return u4 / 0x80000000u; + } + + // U8 + + [MethodImpl(MethodImplOptions.NoInlining)] + public static ulong U8_Div_0(ulong u8) + { + return u8 / 0; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static ulong U8_Div_1(ulong u8) + { + return u8 / 1; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static ulong U8_Div_3(ulong u8) + { + return u8 / 3; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static ulong U8_Div_5(ulong u8) + { + return u8 / 5; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static ulong U8_Div_7(ulong u8) + { + return u8 / 7; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static ulong U8_DivUncontained_I8Max(ulong u8) + { + return u8 / ulong.MaxValue; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static ulong U8_DivPow2_2(ulong u8) + { + return u8 / 2; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static ulong U8_DivUncontainedPow2_1Shl32(ulong u8) + { + return u8 / (1UL << 32); + } +} + +static class UDivProgram +{ + public static int Main() + { + const int Pass = 100; + const int Fail = -1; + + // U4 + + try + { + UDivConst.U4_Div_0(42); + return Fail; + } + catch (DivideByZeroException) + { + } + catch (Exception) + { + return Fail; + } + + if (UDivConst.U4_Div_1(42) != 42) + { + return Fail; + } + + if (UDivConst.U4_Div_3(42) != 14) + { + return Fail; + } + + if (UDivConst.U4_Div_5(42) != 8) + { + return Fail; + } + + if (UDivConst.U4_Div_7(43) != 6) + { + return Fail; + } + + if (UDivConst.U4_DivPow2_16(42) != 2) + { + return Fail; + } + + if (UDivConst.U4_DivPow2_I4Min(3) != 0) + { + return Fail; + } + + if (UDivConst.U4_DivPow2_I4Min(0x80000001u) != 1) + { + return Fail; + } + + // U8 + + try + { + UDivConst.U8_Div_0(42); + return Fail; + } + catch (DivideByZeroException) + { + } + catch (Exception) + { + return Fail; + } + + if (UDivConst.U8_Div_1(42) != 42) + { + return Fail; + } + + if (UDivConst.U8_Div_3(42) != 14) + { + return Fail; + } + + if (UDivConst.U8_Div_5(42) != 8) + { + return Fail; + } + + if (UDivConst.U8_Div_7(420) != 60) + { + return Fail; + } + + if (UDivConst.U8_DivUncontained_I8Max(ulong.MaxValue - 1) != 0) + { + return Fail; + } + + if (UDivConst.U8_DivUncontained_I8Max(ulong.MaxValue) != 1) + { + return Fail; + } + + if (UDivConst.U8_DivPow2_2(42) != 21) + { + return Fail; + } + + if (UDivConst.U8_DivUncontainedPow2_1Shl32(1UL << 33) != 2) + { + return Fail; + } + + return Pass; + } +} diff --git a/tests/src/JIT/CodeGenBringUpTests/UDivConst.csproj b/tests/src/JIT/CodeGenBringUpTests/UDivConst.csproj new file mode 100644 index 0000000000..81a799ad87 --- /dev/null +++ b/tests/src/JIT/CodeGenBringUpTests/UDivConst.csproj @@ -0,0 +1,43 @@ + + + + + Debug + AnyCPU + 2.0 + {53C70B64-C175-43BF-A98A-719868D6D695} + Exe + Properties + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + $(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages + ..\..\ + 7a9bfb7d + + + + + + + + + False + + + + + + + + + + + + + $(JitPackagesConfigFileDirectory)threading+thread\project.json + $(JitPackagesConfigFileDirectory)threading+thread\project.lock.json + + + + + \ No newline at end of file diff --git a/tests/src/JIT/CodeGenBringUpTests/UModConst.cs b/tests/src/JIT/CodeGenBringUpTests/UModConst.cs new file mode 100644 index 0000000000..06cc28d8a8 --- /dev/null +++ b/tests/src/JIT/CodeGenBringUpTests/UModConst.cs @@ -0,0 +1,224 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.CompilerServices; + +static class UModConst +{ + // U4 + + [MethodImpl(MethodImplOptions.NoInlining)] + public static uint U4_Mod_0(uint u4) + { + return u4 % 0; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static uint U4_Mod_1(uint u4) + { + return u4 % 1; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static uint U4_Mod_3(uint u4) + { + return u4 % 3; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static uint U4_Mod_5(uint u4) + { + return u4 % 5; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static uint U4_Mod_7(uint u4) + { + return u4 % 7; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static uint U4_ModPow2_16(uint u4) + { + return u4 % 16; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static uint U4_ModPow2_0x80000000(uint u4) + { + return u4 % 0x80000000u; + } + + // U8 + + [MethodImpl(MethodImplOptions.NoInlining)] + public static ulong U8_Mod_0(ulong u8) + { + return u8 % 0; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static ulong U8_Mod_1(ulong u8) + { + return u8 % 1; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static ulong U8_Mod_3(ulong u8) + { + return u8 % 3; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static ulong U8_Mod_5(ulong u8) + { + return u8 % 5; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static ulong U8_Mod_7(ulong u8) + { + return u8 % 7; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static ulong U8_ModUncontained_I8Max(ulong u8) + { + return u8 % ulong.MaxValue; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static ulong U8_ModPow2_8(ulong u8) + { + return u8 % 8; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static ulong U8_ModUncontainedPow2_1Shl32(ulong u8) + { + return u8 % (1UL << 32); + } +} + +static class UModProgram +{ + public static int Main() + { + const int Pass = 100; + const int Fail = -1; + + // U4 + + try + { + UModConst.U4_Mod_0(42); + return Fail; + } + catch (DivideByZeroException) + { + } + catch (Exception) + { + return Fail; + } + + if (UModConst.U4_Mod_1(42) != 0) + { + return Fail; + } + + if (UModConst.U4_Mod_3(43) != 1) + { + return Fail; + } + + if (UModConst.U4_Mod_5(42) != 2) + { + return Fail; + } + + if (UModConst.U4_Mod_7(43) != 1) + { + return Fail; + } + + if (UModConst.U4_ModPow2_16(42) != 10) + { + return Fail; + } + + if (UModConst.U4_ModPow2_0x80000000(3) != 3) + { + return Fail; + } + + if (UModConst.U4_ModPow2_0x80000000(0x80000001u) != 1) + { + return Fail; + } + + // U8 + + try + { + UModConst.U8_Mod_0(42); + return Fail; + } + catch (DivideByZeroException) + { + } + catch (Exception) + { + return Fail; + } + + if (UModConst.U8_Mod_1(42) != 0) + { + return Fail; + } + + if (UModConst.U8_Mod_3(43) != 1) + { + return Fail; + } + + if (UModConst.U8_Mod_5(42) != 2) + { + return Fail; + } + + if (UModConst.U8_Mod_7(420) != 0) + { + return Fail; + } + + if (UModConst.U8_ModUncontained_I8Max(ulong.MaxValue - 1) != ulong.MaxValue - 1) + { + return Fail; + } + + if (UModConst.U8_ModUncontained_I8Max(ulong.MaxValue) != 0) + { + return Fail; + } + + if (UModConst.U8_ModPow2_8(42) != 2) + { + return Fail; + } + + if (UModConst.U8_ModPow2_8(43) != 3) + { + return Fail; + } + + if (UModConst.U8_ModUncontainedPow2_1Shl32((1UL << 33) + 42) != 42) + { + return Fail; + } + + return Pass; + } +} diff --git a/tests/src/JIT/CodeGenBringUpTests/UModConst.csproj b/tests/src/JIT/CodeGenBringUpTests/UModConst.csproj new file mode 100644 index 0000000000..942ffbe8cb --- /dev/null +++ b/tests/src/JIT/CodeGenBringUpTests/UModConst.csproj @@ -0,0 +1,43 @@ + + + + + Debug + AnyCPU + 2.0 + {D7512FD8-08E1-4BB6-8701-E3FEEAE4FF66} + Exe + Properties + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + $(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages + ..\..\ + 7a9bfb7d + + + + + + + + + False + + + + + + + + + + + + + $(JitPackagesConfigFileDirectory)threading+thread\project.json + $(JitPackagesConfigFileDirectory)threading+thread\project.lock.json + + + + + \ No newline at end of file -- cgit v1.2.3