Skip to content

Commit becfc21

Browse files
arm64: Add bic(s) compact encoding (#111452)
Change-Id: Ief95d09c2f7bec412b2509e615f7c09e4d228986
1 parent ccd8c3d commit becfc21

File tree

5 files changed

+246
-1
lines changed

5 files changed

+246
-1
lines changed

src/coreclr/jit/codegenarm64.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2675,6 +2675,12 @@ void CodeGen::genCodeForBinary(GenTreeOp* tree)
26752675
break;
26762676
}
26772677

2678+
case GT_AND_NOT:
2679+
{
2680+
ins = INS_bics;
2681+
break;
2682+
}
2683+
26782684
default:
26792685
{
26802686
noway_assert(!"Unexpected BinaryOp with GTF_SET_FLAGS set");

src/coreclr/jit/gentree.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20020,7 +20020,7 @@ bool GenTree::SupportsSettingZeroFlag()
2002020020
}
2002120021
#endif
2002220022
#elif defined(TARGET_ARM64)
20023-
if (OperIs(GT_AND))
20023+
if (OperIs(GT_AND, GT_AND_NOT))
2002420024
{
2002520025
return true;
2002620026
}

src/coreclr/jit/lowerarmarch.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,11 @@ bool Lowering::IsContainableUnaryOrBinaryOp(GenTree* parentNode, GenTree* childN
304304
}
305305
}
306306

307+
if (childNode->OperIs(GT_LSH, GT_RSH, GT_RSZ) && parentNode->OperIs(GT_AND_NOT))
308+
{
309+
return true;
310+
}
311+
307312
// TODO: Handle CMN, NEG/NEGS, BIC/BICS, EON, MVN, ORN, TST
308313
return false;
309314
}
Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
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 TestBitwiseClearShift
9+
{
10+
public class Program
11+
{
12+
[MethodImpl(MethodImplOptions.NoInlining)]
13+
[Fact]
14+
public static int CheckBitwiseClearShift()
15+
{
16+
bool fail = false;
17+
18+
if (!Bic(0xFFFFFFFF, 0x12345678, 0xEDCBA987))
19+
{
20+
fail = true;
21+
}
22+
23+
if (!BicLSL(0xFFFFFFFF, 0x12345678, 0xDCBA987F))
24+
{
25+
fail = true;
26+
}
27+
28+
if (!BicLSR(0xFFFFFFFF, 0x12345678, 0xFFFEDCBA))
29+
{
30+
fail = true;
31+
}
32+
33+
if (!BicASR(0xFFFF, 0x8765, 0xFEF1))
34+
{
35+
fail = true;
36+
}
37+
38+
if (!BicLargeShift(0xFEFEFEFE, 1, 0xFEFCFEFE))
39+
{
40+
fail = true;
41+
}
42+
43+
if (!BicLargeShift64Bit(0xFEFEFEFEFEFEFE, 0xFEDCBA98765432, 0xFEFEFEFEF01234))
44+
{
45+
fail = true;
46+
}
47+
48+
if (Bics(0xFFFFFFFF, 0x100) != 1)
49+
{
50+
fail = true;
51+
}
52+
53+
if (BicsLSL(0xFFFFFFFF, 1) != 1)
54+
{
55+
fail = true;
56+
}
57+
58+
if (BicsLSR(0xFFFFFFFF, 0x87654321) != 1)
59+
{
60+
fail = true;
61+
}
62+
63+
if (BicsASR(0xFFFF, 0x8F6E) != 1)
64+
{
65+
fail = true;
66+
}
67+
68+
if (BicsLargeShift(0xFFFFFFFF, 0x87654321) != 1)
69+
{
70+
fail = true;
71+
}
72+
73+
if (BicsLargeShift64Bit(0xFFFFFFFFFFFFFFFF, 0xFEDCBA9876543210) != 1)
74+
{
75+
fail = true;
76+
}
77+
78+
if (fail)
79+
{
80+
return 101;
81+
}
82+
return 100;
83+
}
84+
85+
[MethodImpl(MethodImplOptions.NoInlining)]
86+
static bool Bic(uint a, uint b, uint c)
87+
{
88+
//ARM64-FULL-LINE: bic {{w[0-9]+}}, {{w[0-9]+}}, {{w[0-9]+}}
89+
if ((a & ~b) == c)
90+
{
91+
return true;
92+
}
93+
return false;
94+
}
95+
96+
[MethodImpl(MethodImplOptions.NoInlining)]
97+
static bool BicLSL(uint a, uint b, uint c)
98+
{
99+
//ARM64-FULL-LINE: bic {{w[0-9]+}}, {{w[0-9]+}}, {{w[0-9]+}}, LSL #4
100+
if ((a & ~(b<<4)) == c)
101+
{
102+
return true;
103+
}
104+
return false;
105+
}
106+
107+
[MethodImpl(MethodImplOptions.NoInlining)]
108+
static bool BicLSR(uint a, uint b, uint c)
109+
{
110+
//ARM64-FULL-LINE: bic {{w[0-9]+}}, {{w[0-9]+}}, {{w[0-9]+}}, LSR #12
111+
if ((a & ~(b>>12)) == c)
112+
{
113+
return true;
114+
}
115+
return false;
116+
}
117+
118+
[MethodImpl(MethodImplOptions.NoInlining)]
119+
static bool BicASR(int a, int b, int c)
120+
{
121+
//ARM64-FULL-LINE: bic {{w[0-9]+}}, {{w[0-9]+}}, {{w[0-9]+}}, ASR #7
122+
if ((a & ~(b>>7)) == c)
123+
{
124+
return true;
125+
}
126+
return false;
127+
}
128+
129+
[MethodImpl(MethodImplOptions.NoInlining)]
130+
static bool BicLargeShift(uint a, uint b, uint c)
131+
{
132+
//ARM64-FULL-LINE: bic {{w[0-9]+}}, {{w[0-9]+}}, {{w[0-9]+}}, LSL #17
133+
if ((a & ~(b<<145)) == c)
134+
{
135+
return true;
136+
}
137+
return false;
138+
}
139+
140+
[MethodImpl(MethodImplOptions.NoInlining)]
141+
static bool BicLargeShift64Bit(long a, long b, long c)
142+
{
143+
//ARM64-FULL-LINE: bic {{x[0-9]+}}, {{x[0-9]+}}, {{x[0-9]+}}, ASR #36
144+
if ((a & ~(b>>292)) == c)
145+
{
146+
return true;
147+
}
148+
return false;
149+
}
150+
151+
[MethodImpl(MethodImplOptions.NoInlining)]
152+
static int Bics(uint a, uint b)
153+
{
154+
//ARM64-FULL-LINE: bics {{w[0-9]+}}, {{w[0-9]+}}, {{w[0-9]+}}
155+
if ((a & ~b) == 0)
156+
{
157+
return -1;
158+
}
159+
return 1;
160+
}
161+
162+
[MethodImpl(MethodImplOptions.NoInlining)]
163+
static int BicsLSL(uint a, uint b)
164+
{
165+
//ARM64-FULL-LINE: bics {{w[0-9]+}}, {{w[0-9]+}}, {{w[0-9]+}}, LSL #31
166+
if ((a & ~(b<<31)) == 0)
167+
{
168+
return -1;
169+
}
170+
return 1;
171+
}
172+
173+
[MethodImpl(MethodImplOptions.NoInlining)]
174+
static int BicsLSR(uint a, uint b)
175+
{
176+
//ARM64-FULL-LINE: bics {{w[0-9]+}}, {{w[0-9]+}}, {{w[0-9]+}}, LSR #20
177+
if ((a & ~(b>>20)) == 0)
178+
{
179+
return -1;
180+
}
181+
return 1;
182+
}
183+
184+
[MethodImpl(MethodImplOptions.NoInlining)]
185+
static int BicsASR(int a, int b)
186+
{
187+
//ARM64-FULL-LINE: bics {{w[0-9]+}}, {{w[0-9]+}}, {{w[0-9]+}}, ASR #9
188+
if ((a & ~(b>>9)) == 0)
189+
{
190+
return -1;
191+
}
192+
return 1;
193+
}
194+
195+
[MethodImpl(MethodImplOptions.NoInlining)]
196+
static int BicsLargeShift(uint a, uint b)
197+
{
198+
//ARM64-FULL-LINE: bics {{w[0-9]+}}, {{w[0-9]+}}, {{w[0-9]+}}, LSR #3
199+
if ((a & ~(b>>99)) == 0)
200+
{
201+
return -1;
202+
}
203+
return 1;
204+
}
205+
206+
[MethodImpl(MethodImplOptions.NoInlining)]
207+
static int BicsLargeShift64Bit(ulong a, ulong b)
208+
{
209+
//ARM64-FULL-LINE: bics {{x[0-9]+}}, {{x[0-9]+}}, {{x[0-9]+}}, LSL #51
210+
if ((a & ~(b<<179)) == 0)
211+
{
212+
return -1;
213+
}
214+
return 1;
215+
}
216+
}
217+
}
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="BitwiseClearShift.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)