-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fold some HW nodes for constant input (#78929)
- Loading branch information
Showing
5 changed files
with
130 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/tests/JIT/HardwareIntrinsics/General/ConstantFolding/ScalarConstantFoldings.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// 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; | ||
using System.Runtime.Intrinsics.Arm; | ||
using System.Runtime.Intrinsics.X86; | ||
using Xunit; | ||
|
||
public class ScalarConstantFoldings | ||
{ | ||
[Fact] | ||
public static void LeadingZeroCountTests() | ||
{ | ||
if (Lzcnt.IsSupported) | ||
{ | ||
Assert.Equal(32U, Lzcnt.LeadingZeroCount(0)); | ||
Assert.Equal(31U, Lzcnt.LeadingZeroCount(1)); | ||
Assert.Equal(17U, Lzcnt.LeadingZeroCount(31400)); | ||
Assert.Equal(0U, Lzcnt.LeadingZeroCount(1U << 31)); | ||
Assert.Equal(0U, Lzcnt.LeadingZeroCount(uint.MaxValue)); | ||
Assert.Equal(0U, Lzcnt.LeadingZeroCount(uint.MaxValue - 1)); | ||
} | ||
if (Lzcnt.X64.IsSupported) | ||
{ | ||
Assert.Equal(64UL, Lzcnt.X64.LeadingZeroCount(0)); | ||
Assert.Equal(63UL, Lzcnt.X64.LeadingZeroCount(1)); | ||
Assert.Equal(49UL, Lzcnt.X64.LeadingZeroCount(31400)); | ||
Assert.Equal(32UL, Lzcnt.X64.LeadingZeroCount(1UL << 31)); | ||
Assert.Equal(0UL, Lzcnt.X64.LeadingZeroCount(1UL << 63)); | ||
Assert.Equal(0UL, Lzcnt.X64.LeadingZeroCount(ulong.MaxValue)); | ||
Assert.Equal(0UL, Lzcnt.X64.LeadingZeroCount(ulong.MaxValue - 1)); | ||
} | ||
if (ArmBase.IsSupported) | ||
{ | ||
Assert.Equal(32, ArmBase.LeadingZeroCount(0)); | ||
Assert.Equal(31, ArmBase.LeadingZeroCount(1)); | ||
Assert.Equal(17, ArmBase.LeadingZeroCount(31400)); | ||
Assert.Equal(0, ArmBase.LeadingZeroCount(1U << 31)); | ||
Assert.Equal(0, ArmBase.LeadingZeroCount(uint.MaxValue)); | ||
Assert.Equal(0, ArmBase.LeadingZeroCount(uint.MaxValue - 1)); | ||
} | ||
if (ArmBase.Arm64.IsSupported) | ||
{ | ||
Assert.Equal(64, ArmBase.Arm64.LeadingZeroCount(0)); | ||
Assert.Equal(63, ArmBase.Arm64.LeadingZeroCount(1)); | ||
Assert.Equal(49, ArmBase.Arm64.LeadingZeroCount(31400)); | ||
Assert.Equal(32, ArmBase.Arm64.LeadingZeroCount(1UL << 31)); | ||
Assert.Equal(0, ArmBase.Arm64.LeadingZeroCount(1UL << 63)); | ||
Assert.Equal(0, ArmBase.Arm64.LeadingZeroCount(ulong.MaxValue)); | ||
Assert.Equal(0, ArmBase.Arm64.LeadingZeroCount(ulong.MaxValue - 1)); | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/tests/JIT/HardwareIntrinsics/General/ConstantFolding/ScalarConstantFoldings.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<BuildAsStandalone>false</BuildAsStandalone> | ||
<Optimize>True</Optimize> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="$(MSBuildProjectName).cs" /> | ||
</ItemGroup> | ||
</Project> |