Skip to content

Conversation

@jandupej
Copy link
Contributor

@jandupej jandupej commented Oct 17, 2023

This implements a subset of https://developer.arm.com/documentation/ddi0596/2020-12/Base-Instructions/AND--immediate---Bitwise-AND--immediate-- (incl. ands, eor, orr). If the immediate value can be expressed as (1<<n) - 1, the new codegen is used. Although this covers only a few of the cases supported by the instruction, the instances where we are trying to mask away some of the upper bits seem prevalent (in our codebase) and are handled here.

E.g. clamping the shift amount in long shifts:

0000000000000018        mov     x30, #0x3f
000000000000001c        and     w1, w0, w30

becomes

0000000000000018        and     w1, w0, #0x3f

EDIT: The recognized bit pattern is now expanded to 0*1+0*. A plain-ish HelloWorld build revealed almost 400 instances of this pattern.

@jandupej jandupej self-assigned this Oct 17, 2023
@jandupej jandupej added this to the 9.0.0 milestone Oct 17, 2023
Copy link
Member

@lambdageek lambdageek left a comment

Choose a reason for hiding this comment

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

ctz is for 32-bit inputs



static int
num_trailing_zeros (guint64 imm)
Copy link
Member

Choose a reason for hiding this comment

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

Can we put this in a header in mono/utils (or in minipal) so we can use it in more places

@jandupej jandupej requested a review from matouskozak October 18, 2023 10:43
@jandupej
Copy link
Contributor Author

CI failures are not related. Merging.

@jandupej jandupej merged commit 7a5f0c2 into dotnet:main Oct 19, 2023
@jandupej jandupej deleted the arm64-logical-imm branch October 19, 2023 12:48
@ghost ghost locked as resolved and limited conversation to collaborators Nov 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants