Skip to content

Conversation

@jonathandavies-arm
Copy link
Contributor

This PR remove unnecessary casts instructions. I've added some examples below taken from the Casts.cs test file but I've seen the same optimisations when I run the asmdiffs.

Example 1

[MethodImpl(MethodImplOptions.NoInlining)]
static sbyte CastIntLongSbyte(int x)
{
    //ARM64-FULL-LINE: sxtb {{w[0-9]+}}, {{w[0-9]+}}
    return (sbyte)(long)x;
}

Arm64 Instruction Diff

-sxtw    x0, w0
 sxtb    w0, w0

x64 Instruction Diff

-movsxd  rax, edi
-movsx   rax, al
 movsx   rax, dil

Example 2

[MethodImpl(MethodImplOptions.NoInlining)]
static ushort CastULongUShortULongUShort(ulong x)
{
    //ARM64-FULL-LINE: uxth {{w[0-9]+}}, {{w[0-9]+}}
    return (ushort)(ulong)(ushort)x;
}

Arm64 Instruction Diff

 uxth    w0, w0
-mov     w0, w0
-uxth    w0, w0

x64 Instruction Diff

-movzx    rdi, di
-mov      eax, edi
-movzx    rax, ax
 movzx    rax, di

@github-actions github-actions bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Jan 23, 2026
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Jan 23, 2026
@jonathandavies-arm
Copy link
Contributor Author

@dotnet/arm64-contrib


public static class Expect
{
public static void ExpectEqual<T>(Expression<Func<T>> expr, T expected, ref bool fail)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need these if we can use xunit's Assert.Equal and friends?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution Indicates that the PR has been added by a community member needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants