diff options
author | Mike Danes <onemihaid@hotmail.com> | 2015-11-14 10:46:20 +0200 |
---|---|---|
committer | Mike Danes <onemihaid@hotmail.com> | 2016-06-22 18:59:34 +0300 |
commit | 4286b4006c3c671d9d9cc1b6979498275b526775 (patch) | |
tree | 8533538d5a4d2b72721ea2e40bec591f486936e3 /tests/src/JIT/CodeGenBringUpTests/UModConst.cs | |
parent | b9f5ae88cc49836c8d31f07db7800707165cdb06 (diff) | |
download | coreclr-4286b4006c3c671d9d9cc1b6979498275b526775.tar.gz coreclr-4286b4006c3c671d9d9cc1b6979498275b526775.tar.bz2 coreclr-4286b4006c3c671d9d9cc1b6979498275b526775.zip |
Add tests for integer div/mod by const
Diffstat (limited to 'tests/src/JIT/CodeGenBringUpTests/UModConst.cs')
-rw-r--r-- | tests/src/JIT/CodeGenBringUpTests/UModConst.cs | 224 |
1 files changed, 224 insertions, 0 deletions
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; + } +} |