-
Notifications
You must be signed in to change notification settings - Fork 4.8k
/
Copy pathIntAdd.cs
150 lines (111 loc) · 3.46 KB
/
IntAdd.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.Runtime.CompilerServices;
namespace CodeGenTests
{
static class IntAdd
{
[MethodImpl(MethodImplOptions.NoInlining)]
static sbyte Int8_Add(sbyte x, sbyte y)
{
// X64-NOT: movsx
// X64: add
// X64-NEXT: movsx
return (sbyte)(x + y);
}
[MethodImpl(MethodImplOptions.NoInlining)]
static byte UInt8_Add(byte x, byte y)
{
// X64-NOT: movzx
// X64: add
// X64-NEXT: movzx
return (byte)(x + y);
}
[MethodImpl(MethodImplOptions.NoInlining)]
static short Int16_Add(short x, short y)
{
// X64-NOT: movsx
// X64: add
// X64-NEXT: movsx
// X64-NOT: cwde
return (short)(x + y);
}
[MethodImpl(MethodImplOptions.NoInlining)]
static ushort UInt16_Add(ushort x, ushort y)
{
// X64-NOT: movzx
// X64: add
// X64-NEXT: movzx
return (ushort)(x + y);
}
[MethodImpl(MethodImplOptions.NoInlining)]
static int Int32_Add(int x, int y)
{
// X64: lea
return x + y;
}
[MethodImpl(MethodImplOptions.NoInlining)]
static uint UInt32_Add(uint x, uint y)
{
// X64: lea
return x + y;
}
[MethodImpl(MethodImplOptions.NoInlining)]
static long Int64_Add(long x, long y)
{
// X64: lea
return x + y;
}
[MethodImpl(MethodImplOptions.NoInlining)]
static ulong UInt64_Add(ulong x, ulong y)
{
// X64: lea
return x + y;
}
static int Main()
{
// Int8
if (Int8_Add(SByte.MaxValue, 15) != -114)
return 0;
if (Int8_Add(15, SByte.MaxValue) != -114)
return 0;
// UInt8
if (UInt8_Add(Byte.MaxValue, 15) != 14)
return 0;
if (UInt8_Add(15, Byte.MaxValue) != 14)
return 0;
// Int16
if (Int16_Add(Int16.MaxValue, 15) != -32754)
return 0;
if (Int16_Add(15, Int16.MaxValue) != -32754)
return 0;
// UInt16
if (UInt16_Add(UInt16.MaxValue, 15) != 14)
return 0;
if (UInt16_Add(15, UInt16.MaxValue) != 14)
return 0;
// Int32
if (Int32_Add(Int32.MaxValue, 15) != -2147483634)
return 0;
if (Int32_Add(15, Int32.MaxValue) != -2147483634)
return 0;
// UInt32
if (UInt32_Add(UInt32.MaxValue, 15) != 14)
return 0;
if (UInt32_Add(15, UInt32.MaxValue) != 14)
return 0;
// Int64
if (Int64_Add(Int64.MaxValue, 15) != -9223372036854775794)
return 0;
if (Int64_Add(15, Int64.MaxValue) != -9223372036854775794)
return 0;
// UInt64
if (UInt64_Add(UInt64.MaxValue, 15) != 14)
return 0;
if (UInt64_Add(15, UInt64.MaxValue) != 14)
return 0;
return 100;
}
}
}