Skip to content

Commit bcc0e89

Browse files
arm64: Add tests for add(s), and(s), sub(s), cmp, cmn, eor, neg & orr (#111796)
* arm64: Add tests for add(s), and(s), sub(s), cmp, cmn, eor, neg & orr * Add swap tests with operands in opposite order
1 parent bfa0276 commit bcc0e89

File tree

16 files changed

+1345
-0
lines changed

16 files changed

+1345
-0
lines changed
Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System;
5+
using System.Runtime.CompilerServices;
6+
using Xunit;
7+
8+
namespace TestAdd
9+
{
10+
public class Program
11+
{
12+
[MethodImpl(MethodImplOptions.NoInlining)]
13+
[Fact]
14+
public static int CheckAdd()
15+
{
16+
bool fail = false;
17+
18+
if (Add(1, 2) != 3)
19+
{
20+
fail = true;
21+
}
22+
23+
if (AddLSL(5, 5) != 85)
24+
{
25+
fail = true;
26+
}
27+
28+
if (AddLSLSwap(5, 5) != 85)
29+
{
30+
fail = true;
31+
}
32+
33+
if (AddLSR(1, 0x20000000) != 2)
34+
{
35+
fail = true;
36+
}
37+
38+
if (AddASR(-2, 0x4000) != -1)
39+
{
40+
fail = true;
41+
}
42+
43+
if (AddLargeShift(0x100000, 1) != 0x900000)
44+
{
45+
fail = true;
46+
}
47+
48+
if (AddLargeShift64Bit(0xAB, 0x19a0000000000) != 0x178)
49+
{
50+
fail = true;
51+
}
52+
53+
if (Adds(-5, 5) != 1)
54+
{
55+
fail = true;
56+
}
57+
58+
if (AddsLSL(-0x78000, 0xF) != 1)
59+
{
60+
fail = true;
61+
}
62+
63+
if (AddsLSLSwap(-0x78000, 0xF) != 1)
64+
{
65+
fail = true;
66+
}
67+
68+
if (AddsLSR(0, 0x3c0) != 1)
69+
{
70+
fail = true;
71+
}
72+
73+
if (AddsASR(-1, 0x800) != 1)
74+
{
75+
fail = true;
76+
}
77+
78+
if (AddsLargeShift(-0xFF, 0x1fe0) != 1)
79+
{
80+
fail = true;
81+
}
82+
83+
if (AddsLargeShift64Bit(-0x40000000000, 1) != 1)
84+
{
85+
fail = true;
86+
}
87+
88+
if (fail)
89+
{
90+
return 101;
91+
}
92+
return 100;
93+
}
94+
95+
[MethodImpl(MethodImplOptions.NoInlining)]
96+
static int Add(int a, int b)
97+
{
98+
//ARM64-FULL-LINE: add {{w[0-9]+}}, {{w[0-9]+}}, {{w[0-9]+}}
99+
return a + b;
100+
}
101+
102+
[MethodImpl(MethodImplOptions.NoInlining)]
103+
static int AddLSL(int a, int b)
104+
{
105+
//ARM64-FULL-LINE: add {{w[0-9]+}}, {{w[0-9]+}}, {{w[0-9]+}}, LSL #4
106+
return a + (b<<4);
107+
}
108+
109+
[MethodImpl(MethodImplOptions.NoInlining)]
110+
static int AddLSLSwap(int a, int b)
111+
{
112+
//ARM64-FULL-LINE: add {{w[0-9]+}}, {{w[0-9]+}}, {{w[0-9]+}}, LSL #4
113+
return (b<<4) + a;
114+
}
115+
116+
[MethodImpl(MethodImplOptions.NoInlining)]
117+
static uint AddLSR(uint a, uint b)
118+
{
119+
//ARM64-FULL-LINE: add {{w[0-9]+}}, {{w[0-9]+}}, {{w[0-9]+}}, LSR #29
120+
return a + (b>>29);
121+
}
122+
123+
[MethodImpl(MethodImplOptions.NoInlining)]
124+
static int AddASR(int a, int b)
125+
{
126+
//ARM64-FULL-LINE: add {{w[0-9]+}}, {{w[0-9]+}}, {{w[0-9]+}}, ASR #14
127+
return a + (b>>14);
128+
}
129+
130+
[MethodImpl(MethodImplOptions.NoInlining)]
131+
static int AddLargeShift(int a, int b)
132+
{
133+
//ARM64-FULL-LINE: add {{w[0-9]+}}, {{w[0-9]+}}, {{w[0-9]+}}, LSL #23
134+
return a + (b<<183);
135+
}
136+
137+
[MethodImpl(MethodImplOptions.NoInlining)]
138+
static long AddLargeShift64Bit(long a, long b)
139+
{
140+
//ARM64-FULL-LINE: add {{x[0-9]+}}, {{x[0-9]+}}, {{x[0-9]+}}, ASR #41
141+
return a + (b>>169);
142+
}
143+
144+
[MethodImpl(MethodImplOptions.NoInlining)]
145+
static int Adds(int a, int b)
146+
{
147+
//ARM64-FULL-LINE: adds {{w[0-9]+}}, {{w[0-9]+}}, {{w[0-9]+}}
148+
if (a + b == 0) {
149+
return 1;
150+
}
151+
return -1;
152+
}
153+
154+
[MethodImpl(MethodImplOptions.NoInlining)]
155+
static int AddsLSL(int a, int b)
156+
{
157+
//ARM64-FULL-LINE: adds {{w[0-9]+}}, {{w[0-9]+}}, {{w[0-9]+}}, LSL #15
158+
if (a + (b<<15) == 0) {
159+
return 1;
160+
}
161+
return -1;
162+
}
163+
164+
[MethodImpl(MethodImplOptions.NoInlining)]
165+
static int AddsLSLSwap(int a, int b)
166+
{
167+
//ARM64-FULL-LINE: adds {{w[0-9]+}}, {{w[0-9]+}}, {{w[0-9]+}}, LSL #15
168+
if ((b<<15) + a == 0) {
169+
return 1;
170+
}
171+
return -1;
172+
}
173+
174+
[MethodImpl(MethodImplOptions.NoInlining)]
175+
static int AddsLSR(uint a, uint b)
176+
{
177+
//ARM64-FULL-LINE: adds {{w[0-9]+}}, {{w[0-9]+}}, {{w[0-9]+}}, LSR #6
178+
if (a + (b>>6) != 0) {
179+
return 1;
180+
}
181+
return -1;
182+
}
183+
184+
[MethodImpl(MethodImplOptions.NoInlining)]
185+
static int AddsASR(int a, int b)
186+
{
187+
//ARM64-FULL-LINE: adds {{w[0-9]+}}, {{w[0-9]+}}, {{w[0-9]+}}, ASR #11
188+
if (a + (b>>11) == 0) {
189+
return 1;
190+
}
191+
return -1;
192+
}
193+
194+
195+
[MethodImpl(MethodImplOptions.NoInlining)]
196+
static int AddsLargeShift(int a, int b)
197+
{
198+
//ARM64-FULL-LINE: adds {{w[0-9]+}}, {{w[0-9]+}}, {{w[0-9]+}}, ASR #5
199+
if (a + (b>>133) == 0) {
200+
return 1;
201+
}
202+
return -1;
203+
}
204+
205+
[MethodImpl(MethodImplOptions.NoInlining)]
206+
static long AddsLargeShift64Bit(long a, long b)
207+
{
208+
//ARM64-FULL-LINE: adds {{x[0-9]+}}, {{x[0-9]+}}, {{x[0-9]+}}, LSL #42
209+
if (a + (b<<106) == 0) {
210+
return 1;
211+
}
212+
return -1;
213+
}
214+
}
215+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<!-- Needed for CLRTestEnvironmentVariable -->
4+
<RequiresProcessIsolation>true</RequiresProcessIsolation>
5+
</PropertyGroup>
6+
<PropertyGroup>
7+
<DebugType>None</DebugType>
8+
<Optimize>True</Optimize>
9+
</PropertyGroup>
10+
<ItemGroup>
11+
<Compile Include="Add.cs">
12+
<HasDisasmCheck>true</HasDisasmCheck>
13+
</Compile>
14+
<CLRTestEnvironmentVariable Include="DOTNET_TieredCompilation" Value="0" />
15+
<CLRTestEnvironmentVariable Include="DOTNET_JITMinOpts" Value="0" />
16+
</ItemGroup>
17+
</Project>

0 commit comments

Comments
 (0)