Skip to content

Conversation

@jonathandavies-arm
Copy link
Contributor

This patch adds support for the Arm BFI and BFX instructions. I've added a optimisation in lowering for bit packing and unpacking using each instruction respectively.

BFI

This is used when you pack 2 or more values into an integer. e.g.
return (a & 0xf) | ((b & 0x3) << 4);
This is the node pattern it is looking for

N009 (  9, 12) [000008] -----+-----                         *  OR        int    $103
N003 (  3,  4) [000002] -----+-----                         +--*  AND       int    $100
N001 (  1,  1) [000000] -----+-----                         |  +--*  LCL_VAR   int    V00 arg0         u:1 (last use) $80
N002 (  1,  2) [000001] -c---+-----                         |  \--*  CNS_INT   int    15 $43
N008 (  5,  7) [000007] -----+-----                         \--*  LSH       int    $102
N006 (  3,  4) [000005] -----+-----                            +--*  AND       int    $101
N004 (  1,  1) [000003] -----+-----                            |  +--*  LCL_VAR   int    V01 arg1         u:1 (last use) $81
N005 (  1,  2) [000004] -c---+-----                            |  \--*  CNS_INT   int    3 $44
N007 (  1,  2) [000006] -c---+-----                            \--*  CNS_INT   int    4 $45

and changes to

     (  9, 12) [000011] -----------                         \--*  BFI       int   
N003 (  3,  4) [000002] -----+-----                            +--*  AND       int    $100
N001 (  1,  1) [000000] -----+-----                            |  +--*  LCL_VAR   int    V00 arg0         u:1 (last use) $80
N002 (  1,  2) [000001] -c---+-----                            |  \--*  CNS_INT   int    15 $43
N004 (  1,  1) [000003] -----+-----                            \--*  LCL_VAR   int    V01 arg1         u:1 (last use) $81

BFX

When you extract a continuous range of bits from an integer. This is the inverse of above. e.g.
return (x >> 5) & 0x1F;

This is the node pattern it's looking for

N005 (  5,  7) [000004] -----+-----                         \--*  AND       int    $101
N003 (  3,  4) [000002] -----+-----                            +--*  RSH       int    $100
N001 (  1,  1) [000000] -----+-----                            |  +--*  LCL_VAR   int    V00 arg0         u:1 (last use) $80
N002 (  1,  2) [000001] -----+-----                            |  \--*  CNS_INT   int    6 $42
N004 (  1,  2) [000003] -----+-----                            \--*  CNS_INT   int    63 $43

and changes to

     (  5,  7) [000007] -----------                         \--*  BFX       int   
N001 (  1,  1) [000000] -----+-----                            \--*  LCL_VAR   int    V00 arg0         u:1 (last use) $80

@github-actions github-actions bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Jan 13, 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 13, 2026
@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

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

Labels

area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant